CornishFisherDeltaGammaVaRCalculator 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 zSq = z * z; final double mean = _meanCalculator.evaluate(data); final double std = _stdCalculator.evaluate(data); final double skew = _skewCalculator.evaluate(data); final double kurtosis = _kurtosisCalculator.evaluate(data); final double x = z + skew * (zSq - 1) / 6. + kurtosis * z * (zSq - 3) / 24. - skew * skew * z * (2 * zSq - 5) / 36.; final double value = x * std * mult + mean * mult * mult; return new VaRCalculationResult(value, null); } CornishFisherDeltaGammaVaRCalculator(final Function<T, Double> meanCalculator, final Function<T, Double> stdCalculator,
      final Function<T, Double> skewCalculator, final Function<T, Double> kurtosisCalculator); Function<T, Double> getMeanCalculator(); Function<T, Double> getStandardDeviationCalculator(); Function<T, Double> getSkewCalculator(); Function<T, Double> getKurtosisCalculator(); @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() { CF1.evaluate(null, 3.); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testNullData() { CF1.evaluate(CORNISH_FISHER_PARAMETERS, (Double[]) null); }
@Test public void testAgainstNormal() { final double eps = 1e-6; final Double data = 0.; assertEquals(NORMAL.evaluate(PARAMETERS, data).getVaRValue(), CF1.evaluate(PARAMETERS, data).getVaRValue(), eps); assertTrue(CF2.evaluate(PARAMETERS, data).getVaRValue() > NORMAL.evaluate(PARAMETERS, data).getVaRValue()); }