예제 #1
0
  public void calTrendMaMonitor(String code, List<Indicator> indicatorList) {
    List<ProdIndex> prodIndexList = prodIndexBuss.queryAscByCode(code);

    indicatorList
        .stream()
        .forEach(
            indicator -> {
              TrendMaMonitor trendMaMonitor1 =
                  trendMaMonitorRepos.findByCodeAndTrend(code, indicator.getName());
              TrendMaMonitor trendMaMonitor2 = new TrendMaMonitor();
              trendMaMonitor2.setTrend(indicator.getName());
              trendMaMonitor2.setCode(code);
              TrendMaMonitor trendMaMonitor =
                  trendMaMonitor1 == null ? trendMaMonitor2 : trendMaMonitor1;
              prodIndexList
                  .stream()
                  .forEach(
                      prodIndex -> {
                        indicator.push(prodIndex.getDt(), prodIndex.getPrice());
                        if (indicator.getLine().isEmpty()) {
                          return;
                        }
                        Price maPrice = indicator.getLine().get(indicator.getLine().size() - 1);
                        calTrendMaMonitor(
                            trendMaMonitor,
                            prodIndex.getDt(),
                            prodIndex.getPrice(),
                            maPrice.getP());
                      });
              trendMaMonitorRepos.save(trendMaMonitor);
            });
    trendMaMonitorRepos.flush();
  }
예제 #2
0
  public ProdMA calProdMovingAverage(String code, int month, List<Indicator> indicatorList) {
    List<ProdIndex> prodIndexList = prodIndexBuss.queryAscByCode(code);

    Date d = null;
    if (month > 0) {
      Calendar cal = Calendar.getInstance();
      cal.add(Calendar.MONTH, Math.negateExact(month));
      d = cal.getTime();
    }
    final Date start = d;

    List<Price> priceList = new ArrayList<>();
    List<Price> volList = new ArrayList<>();
    prodIndexList
        .stream()
        .filter(
            prodIndex -> {
              if (month > 0 && prodIndex.getDt().compareTo(start) < 0) {
                return false;
              } else {
                return true;
              }
            })
        .forEach(
            prodIndex -> {
              priceList.add(new Price(prodIndex.getDt(), prodIndex.getPrice()));
              volList.add(new Price(prodIndex.getDt(), new BigDecimal(prodIndex.getVol())));
            });
    Series prodIndexLine = new Series(code, code, priceList);
    Series volLine = new Series(code, code, volList);
    List<Series> mvAvgLineList =
        indicatorList
            .stream()
            .map(
                indicator -> {
                  prodIndexList
                      .stream()
                      .forEach(
                          prodIndex -> {
                            indicator.push(prodIndex.getDt(), prodIndex.getPrice());
                          });
                  if (month < 0) {
                    return new Series("", indicator.getName(), indicator.getLine());
                  } else {
                    return new Series(
                        "",
                        indicator.getName(),
                        indicator
                            .getLine()
                            .stream()
                            .filter(price -> price.getD().compareTo(start) >= 0)
                            .collect(Collectors.toList()));
                  }
                })
            .collect(Collectors.toList());
    return new ProdMA(code, prodIndexLine, volLine, mvAvgLineList);
  }