@Override
  public void retrieveResult(AnalysisOutput analysisOutput) {
    if (finalTimeSeriesPoint != null && highestTimeSeriesPoint != null) {
      double finalPriceClose = finalTimeSeriesPoint.getClose();
      double highestPrice = highestTimeSeriesPoint.getHigh();

      double totalDrawdown = Math.max(0, highestPrice - finalPriceClose);
      logger.debug("Total drawdown is: " + totalDrawdown);
      logger.debug(
          "Total drawdown period is from "
              + highestTimeSeriesPoint.getDate()
              + " to "
              + finalTimeSeriesPoint.getDate());

      analysisOutput.setTotalDrawdown(totalDrawdown);
    } else {
      throw new UnsupportedOperationException();
    }
  }
  @Test
  public void testBetaRegressionValueExtractor() {

    BetaRegressionValueCalculator betaRegressionValueCalculator =
        new BetaRegressionStandardValueCalculator();

    BetaRegressionValueExtractor betaRegressionValueExtractor =
        new BetaRegressionValueExtractor(betaRegressionValueCalculator);

    int elementsCount = 9;
    int assetCount = 3;

    double[] Y = new double[elementsCount];
    double[][] X = new double[elementsCount][assetCount + 1];

    LocalDate now = LocalDate.now();
    LocalDate[] dates =
        new LocalDate[] {now, now.minusMonths(1), now.minusMonths(2), now.minusMonths(3)};
    double[][] periodReturns = new double[][] {{1, 1, 2, 3}, {1, 4, 5, 6}, {1, 5, 6, 7}};
    double[][] volatilities =
        new double[][] {{1, 0.15, 0.25, 0.35}, {1, 0.45, 0.55, 0.65}, {1, 0.55, 0.65, 0.75}};

    List<AnalysisOutput> analysisOutputList = new ArrayList<AnalysisOutput>();
    for (int i = 0; i < periodReturns.length; ++i) {
      Map<LocalDate, Double> instrumentVolatilityMap = new HashMap<LocalDate, Double>();
      Map<LocalDate, Double> periodReturnsMap = new HashMap<LocalDate, Double>();

      for (int j = 0; j < dates.length; ++j) {
        periodReturnsMap.put(dates[j], periodReturns[i][j]);
        instrumentVolatilityMap.put(dates[j], volatilities[i][j]);
      }

      AnalysisOutput analysisOutput = new AnalysisOutput();
      analysisOutput.setInstrumentVolatilityMap(instrumentVolatilityMap);
      analysisOutput.setPeriodReturns(periodReturnsMap);

      analysisOutputList.add(analysisOutput);
    }

    betaRegressionValueExtractor.extractData(Y, X, analysisOutputList, dates.length - 1, 0);

    double[][] expectedX =
        new double[][] {
          {1.0, 6.666666666666667, 0.0, 0.0},
          {1.0, 0.0, 8.0, 0.0},
          {1.0, 0.0, 0.0, 8.571428571428571},
          {1.0, 8.88888888888889, 0.0, 0.0},
          {1.0, 0.0, 9.09090909090909, 0.0},
          {1.0, 0.0, 0.0, 9.23076923076923},
          {1.0, 9.09090909090909, 0.0, 0.0},
          {1.0, 0.0, 9.23076923076923, 0.0},
          {1.0, 0.0, 0.0, 9.333333333333334}
        };

    for (int i = 0; i < expectedX.length; ++i) {

      assertEquals(expectedX[i].length, X[i].length);

      System.out.println(Arrays.toString(X[i]));
      for (int j = 0; j < expectedX[i].length; ++j) {
        assertEquals(expectedX[i][j], X[i][j]);
      }
    }

    for (double y : Y) {
      assertEquals(1.0, y);
    }
  }