SharpeRatioCalculator implements Function<DoubleTimeSeries<?>, Double> { @Override public Double evaluate(final DoubleTimeSeries<?>... ts) { Validate.notNull(ts, "ts array"); TimeSeriesDataTestUtils.testNotNullOrEmpty(ts[0]); TimeSeriesDataTestUtils.testNotNullOrEmpty(ts[1]); final DoubleTimeSeries<?> excessReturn = ts[0].subtract(ts[1]); final double assetExcessReturn = _expectedExcessReturnCalculator.evaluate(excessReturn) * _returnPeriodsPerYear; final double standardDeviation = _standardDeviationCalculator.evaluate(excessReturn) * Math.sqrt(_returnPeriodsPerYear); return assetExcessReturn / standardDeviation; } SharpeRatioCalculator(final double returnPeriodsPerYear, final DoubleTimeSeriesStatisticsCalculator expectedExcessReturnCalculator,
      final DoubleTimeSeriesStatisticsCalculator standardDeviationCalculator); @Override Double evaluate(final DoubleTimeSeries<?>... ts);  }
@Test(expectedExceptions = IllegalArgumentException.class) public void testNullTSArray() { SHARPE.evaluate(null, null); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testNullFirstElement() { SHARPE.evaluate(null, RISK_FREE); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testNullSecondElement() { SHARPE.evaluate(ASSET_RETURN, null); }
@Test public void test() { assertEquals(SHARPE.evaluate(ASSET_RETURN, RISK_FREE), 0.6, 0); }