NormalLinearVaRCalculator implements VaRCalculator<NormalVaRParameters, T> { @SuppressWarnings("unchecked") @Override public VaRCalculationResult evaluate(final NormalVaRParameters parameters, final T... data) { ArgumentChecker.notNull(parameters, "parameters"); ArgumentChecker.notNull(data, "data"); final double z = parameters.getZ(); final double mult = parameters.getTimeScaling(); final double mean = _meanCalculator.evaluate(data); final double stddev = _stdCalculator.evaluate(data); final double result = z * mult * stddev - mult * mult * mean; return new VaRCalculationResult(result, stddev); } NormalLinearVaRCalculator(final Function<T, Double> meanCalculator, final Function<T, Double> stdCalculator); Function<T, Double> getMeanCalculator(); Function<T, Double> getStandardDeviationCalculator(); @SuppressWarnings("unchecked") @Override VaRCalculationResult evaluate(final NormalVaRParameters parameters, final T... data); @Override int hashCode(); @Override boolean equals(final Object obj);  }
@Test(expectedExceptions = IllegalArgumentException.class) public void testNullParameters() { CALCULATOR.evaluate(null, 0.); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testNullData() { CALCULATOR.evaluate(PARAMETERS, (Double[]) null); }
@Test public void test() { final VaRCalculationResult calcResult = CALCULATOR.evaluate(PARAMETERS, 0.); assertEquals(calcResult.getVaRValue(), 3 * 0.2 - 0.016, 1e-9); assertEquals(calcResult.getStdDev(), 1., 1e-9); }