Examples of HoldingSummary


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

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

 
  @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

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

  @RequestMapping(value = "/account/{accountId}/holdingSummary", method = RequestMethod.GET)
  public ResponseEntity<HoldingSummary> find(
      @PathVariable("accountId") final Integer accountId) {
    this.getSecurityUtil().checkAccount(accountId);
    HoldingSummary holdingSummary = getTradingServiceFacade()
        .findHoldingSummary(accountId);
    return new ResponseEntity<HoldingSummary>(holdingSummary,
        getNoCacheHeaders(), HttpStatus.OK);

  }
View Full Code Here

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

    public HoldingSummary findHoldingSummary(Integer accountId) {
        if (log.isDebugEnabled()) {
            log.debug("TradingServiceFacade.findHoldingSummary: Start accountId=" + accountId );
        }
        org.springframework.nanotrader.data.domain.HoldingSummary holdingSummary = tradingService.findHoldingSummary(accountId);
        HoldingSummary holdingSummaryResponse = new HoldingSummary();
        mapper.map(holdingSummary, holdingSummaryResponse, HOLDING_SUMMARY_MAPPING);
        if (log.isDebugEnabled()) {
            log.debug("TradingServiceFacade.findHoldingSummary: completed successfully.");
        }
        return holdingSummaryResponse;
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.