class CAPMFromRegressionCalculator implements Function<DoubleTimeSeries<?>, LeastSquaresRegressionResult> {

  @Override
  public LeastSquaresRegressionResult evaluate(final DoubleTimeSeries<?>... ts) {
    Validate.notNull(ts, "ts");
    final int n = ts.length;
    Validate.isTrue(n > 1);
    if (n > 2) {
      s_logger.warn("Found more than two time series; will only use the first two");
    }
    final DoubleTimeSeries<?> assetTS = ts[0];
    final DoubleTimeSeries<?> marketTS = ts[1];
    testNotNullOrEmpty(assetTS);
    testNotNullOrEmpty(marketTS);
    testTimeSeriesSize(assetTS, 2);
    testTimeSeriesSize(marketTS, 2);
    testTimeSeriesDates(assetTS, marketTS);
    final double[] asset = assetTS.valuesArrayFast();
    final double[][] market = new double[asset.length][1];
    for (int i = 0; i < asset.length; i++) {
      market[i][0] = marketTS.getValueAtIndex(i);
    }
    //final double[][] market = new double[][] {marketTS.toFastLongDoubleTimeSeries().valuesArrayFast()}; //TODO change when [ANA-254] is completed
    final LeastSquaresRegressionResult result = OLS.regress(market, asset, true);
    return result;
  }

}