JarrowRuddSkewnessKurtosisModel extends AnalyticOptionModel<OptionDefinition, SkewKurtosisOptionDataBundle> { @Override public Function1D<SkewKurtosisOptionDataBundle, Double> getPricingFunction(final OptionDefinition definition) { Validate.notNull(definition); final Function1D<SkewKurtosisOptionDataBundle, Double> pricingFunction = new Function1D<SkewKurtosisOptionDataBundle, Double>() { @SuppressWarnings("synthetic-access") @Override public Double evaluate(final SkewKurtosisOptionDataBundle data) { Validate.notNull(data); final double s = data.getSpot(); final double k = definition.getStrike(); final double t = definition.getTimeToExpiry(data.getDate()); final double sigma = data.getVolatility(t, k); final double r = data.getInterestRate(t); final double b = data.getCostOfCarry(); final double skew = data.getAnnualizedSkew(); final double kurtosis = data.getAnnualizedPearsonKurtosis(); final OptionDefinition callDefinition = definition.isCall() ? definition : new EuropeanVanillaOptionDefinition(k, definition.getExpiry(), true); final Function1D<StandardOptionDataBundle, Double> bsm = BSM.getPricingFunction(callDefinition); final double bsmCall = bsm.evaluate(data); final double d2 = getD2(getD1(s, k, t, sigma, b), sigma, t); final double sigmaT = sigma * Math.sqrt(t); final double a = getA(d2, k, sigmaT); final double call = bsmCall + getLambda1(sigma, t, skew) * getQ3(s, k, sigmaT, t, r, a, d2) + getLambda2(sigma, t, kurtosis) * getQ4(s, k, sigmaT, t, r, a, d2); if (!definition.isCall()) { return call - s * Math.exp((b - r) * t) + k * Math.exp(-r * t); } return call; } }; return pricingFunction; }  @Override Function1D<SkewKurtosisOptionDataBundle, Double> getPricingFunction(final OptionDefinition definition);  }
@Test(expectedExceptions = IllegalArgumentException.class) public void testNullDefinition() { MODEL.getPricingFunction(null); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testNullData() { MODEL.getPricingFunction(CALL).evaluate((SkewKurtosisOptionDataBundle) null); }
@Test public void testNormal() { assertEquals(MODEL.getPricingFunction(CALL).evaluate(NORMAL_DATA), BSM.getPricingFunction(CALL).evaluate(NORMAL_DATA), 1e-9); assertEquals(MODEL.getPricingFunction(PUT).evaluate(NORMAL_DATA), BSM.getPricingFunction(PUT).evaluate(NORMAL_DATA), 1e-9); }