예제 #1
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);
 }
예제 #2
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);
 }
예제 #3
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());
 }