public HedgingMonitor monitorHedging(Integer id) { Hedging hedging = hedgingRepo.findOne(id); Formula formula = Formula.parse(hedging.getExpression()); List<Price> realtimePrices = this.calculateUnitData(formula, realTimePriceBuss.queryAllAsc()); List<Price> klinePrices = this.calculateKLine(formula, dailyPriceBuss.queryAllGroup()); return new HedgingMonitor( id, hedging.getName(), formula.toString(), hedging.getStartDt(), hedging.getEndDt(), hedging.getDown(), hedging.getUp(), realtimePrices, klinePrices); }
public List<HedgingView> queryHedging() { UnitDataGroup realTime = realTimePriceBuss.queryLatest(); KLineGroup kline = dailyPriceBuss.queryLatest(); return hedgingRepo .findAll() .stream() .map( hedging -> { Formula f = Formula.parse(hedging.getExpression()); BigDecimal diffKline = this.calculate(f, kline); BigDecimal diffRealtime = this.calculate(f, realTime); BigDecimal diff = diffRealtime == null ? diffKline : diffRealtime; int mid = hedging.getMid(); int down = hedging.getDown(); int up = hedging.getUp(); BigDecimal complete = null; if (diff.compareTo(new BigDecimal(mid)) > 0) { complete = diff.subtract(new BigDecimal(mid)) .divide(new BigDecimal(up - mid), 4, RoundingMode.FLOOR); } else { complete = new BigDecimal(mid) .subtract(diff) .divide(new BigDecimal(mid - down), 4, RoundingMode.FLOOR); } return new HedgingView( hedging.getId(), hedging.getName(), f.toString(), complete, diffKline, diffRealtime, hedging.getUp(), hedging.getDown(), hedging.getMid(), hedging.getQ1(), hedging.getQ3()); }) .collect(Collectors.toList()); }
public List<Price> calculateUnitData(String expression, List<UnitDataGroup> groupList) { return calculateUnitData(Formula.parse(expression), groupList); }
public List<Price> calculateKLine(String expression, List<KLineGroup> groupList) { return calculateKLine(Formula.parse(expression), groupList); }