Example #1
0
 public BigDecimal calculate(Formula fomular, UnitDataGroup unitDataGroup) {
   BigDecimal result = fomular.getConstant();
   for (Multinomial multinomial : fomular.getMultinomials()) {
     UnitData unit = unitDataGroup.getUnitData(multinomial.getCode());
     if (unit == null || unit == UnitData.DUMMY) {
       return null;
     } else {
       result = result.add(multinomial.getCoefficient().multiply(unit.getPrice()));
     }
   }
   return result.setScale(2, RoundingMode.FLOOR);
 }
Example #2
0
 public BigDecimal calculate(Formula fomular, KLineGroup group) {
   BigDecimal result = fomular.getConstant();
   for (Multinomial multinomial : fomular.getMultinomials()) {
     KLine kLine = group.getkLineMap().get(multinomial.getCode());
     if (kLine == null) {
       return null;
     } else {
       result = result.add(multinomial.getCoefficient().multiply(kLine.getEndPrice()));
     }
   }
   return result.setScale(2, RoundingMode.FLOOR);
 }
Example #3
0
 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);
 }
 @Override
 protected void execute() throws Exception {
   Formula formula =
       Formula.create()
           .putConstant("162.31")
           .putMultinomial(ProdEnum.JiaoTan, "1")
           .putMultinomial(ProdEnum.JiaoMei, "-1.60584");
   dataProcessor.testEndPriceFormula("2014-01-01", "2016-09-02", formula);
 }
Example #5
0
 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());
 }
Example #6
0
 public List<Series> compareProd(Futures f1, Futures f2) {
   Series s1 = dailyPriceBuss.querySeriesByCode(f1.getCode(), -1);
   Series s2 = dailyPriceBuss.querySeriesByCode(f2.getCode(), -1);
   Formula formula =
       Formula.create()
           .putConstant(BigDecimal.ZERO)
           .putMultinomial(f1.getCode(), "1")
           .putMultinomial(f2.getCode(), "-1");
   List<Price> diffPriceList = this.calculateKLine(formula, dailyPriceBuss.queryAllGroup());
   String diffName = f1.getName() + "-" + f2.getName();
   Series diffSeries = new Series("", diffName, diffPriceList);
   return Arrays.asList(s1, s2, diffSeries);
 }
Example #7
0
 public List<Price> calculateUnitData(String expression, List<UnitDataGroup> groupList) {
   return calculateUnitData(Formula.parse(expression), groupList);
 }
Example #8
0
 public List<Price> calculateKLine(String expression, List<KLineGroup> groupList) {
   return calculateKLine(Formula.parse(expression), groupList);
 }