Package org.springframework.nanotrader.data.domain

Examples of org.springframework.nanotrader.data.domain.HoldingSummary


    marketSummary.setTopGainers(gainingQuotes);
    return marketSummary;
  }

  public HoldingSummary holdingSummary() {
    HoldingSummary holdingSummary = new HoldingSummary();
    List<HoldingAggregate> holdings = new ArrayList<HoldingAggregate>();
    holdingSummary.setHoldingsTotalGains(HOLDING_SUMMARY_GAINS.setScale(2, RoundingMode.HALF_UP));
    HoldingAggregate holding1 = new HoldingAggregate();
    holding1.setSymbol(SYMBOL);
    holding1.setGain(GAIN1.setScale(2, RoundingMode.HALF_UP));
    holding1.setPercent(FinancialUtils.calculateGainPercentage(holding1.getGain(), holdingSummary.getHoldingsTotalGains()).setScale(2, RoundingMode.HALF_UP));
    holdings.add(holding1);
    HoldingAggregate holding2 = new HoldingAggregate();
    holding2.setSymbol(SYMBOL2);
    holding2.setGain(GAIN2.setScale(2, RoundingMode.HALF_UP));
    holding2.setPercent(FinancialUtils.calculateGainPercentage(holding2.getGain(), holdingSummary.getHoldingsTotalGains()).setScale(2, RoundingMode.HALF_UP));
    holdings.add(holding2);
    holdingSummary.setHoldingRollups(holdings);
    return holdingSummary;
  }
View Full Code Here


 
  @SuppressWarnings("unchecked")
  @Override
  public HoldingSummary findHoldingAggregated(Integer accountId) {
 
    HoldingSummary holdingSummary = new HoldingSummary();
    List<HoldingAggregate> holdingRollups = new ArrayList<HoldingAggregate>();
    // Filter out the losers (gains =< 0)
    Query query = em.createQuery("SELECT  h.quoteSymbol, sum(q.price * h.quantity) - SUM(h.purchaseprice * h.quantity) as gain FROM Holding h, Quote q Where h.accountAccountid =:accountId and h.quoteSymbol=q.symbol GROUP BY  h.quoteSymbol HAVING  SUM(q.price * h.quantity) - SUM(h.purchaseprice * h.quantity) > 0 ORDER BY gain desc");
    query.setParameter("accountId", accountId);
    BigDecimal totalGains = BigDecimal.ZERO;
    totalGains = totalGains.setScale(FinancialUtils.SCALE, FinancialUtils.ROUND);
    List<Object[]> result = query.getResultList();
    int counter = 0;
    // Need to loop over all the aggregated symbols to calculate the totalGain of all the stocks
    // but only want the top N stocks returned.
    for (Object[] o : result) {
      HoldingAggregate summary = new HoldingAggregate();
      String symbol = (String) o[0];
      BigDecimal gain = (BigDecimal) o[1];
      gain = gain.setScale(FinancialUtils.SCALE, FinancialUtils.ROUND);
      totalGains = totalGains.add(gain);
      if (counter < TOP_N) {
        summary.setSymbol(symbol);
        summary.setGain(gain);
        holdingRollups.add(summary);
      }
      counter++;
    }
    holdingSummary.setHoldingsTotalGains(totalGains);
    HoldingSummary summary = calculatePercentages(holdingSummary, holdingRollups);
    return summary;
  }
View Full Code Here

TOP

Related Classes of org.springframework.nanotrader.data.domain.HoldingSummary

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.