EmpiricalDistributionVaRCalculator implements VaRCalculator<EmpiricalDistributionVaRParameters, DoubleTimeSeries<?>> { @Override public VaRCalculationResult evaluate(final EmpiricalDistributionVaRParameters parameters, final DoubleTimeSeries<?>... returns) { ArgumentChecker.notNull(parameters, "parameters"); ArgumentChecker.notNull(returns, "time series"); ArgumentChecker.notNull(returns, "returns"); ArgumentChecker.isTrue(returns.length > 0, "No return series data"); final double[] data = returns[0].valuesArrayFast(); Arrays.sort(data); final double result = -parameters.getMult() * parameters.getPercentileCalculator().evaluate(data); return new VaRCalculationResult(result, null); }  @Override VaRCalculationResult evaluate(final EmpiricalDistributionVaRParameters parameters, final DoubleTimeSeries<?>... returns);  }
@Test(expectedExceptions = IllegalArgumentException.class) public void testNullTS1() { CALCULATOR.evaluate(PARAMETERS, (DoubleTimeSeries<?>[]) null); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testNullParameters() { CALCULATOR.evaluate(null, ImmutableInstantDoubleTimeSeries.of(new long[] {1, 2}, new double[] {0.06, 0.07})); }
@Test public void test() { final int n = 10; final long[] t = new long[n]; final double[] pnl = new double[n]; for (int i = 0; i < 10; i++) { t[i] = i; pnl[i] = i / 10. - 0.5; } final DoubleTimeSeries<?> ts = ImmutableInstantDoubleTimeSeries.of(t, pnl); assertEquals(CALCULATOR.evaluate(PARAMETERS, ts).getVaRValue(), 0.082, 1e-7); }