NormalPriceFunction implements OptionPriceFunction<NormalFunctionData> { @Override public Function1D<NormalFunctionData, Double> getPriceFunction(final EuropeanVanillaOption option) { Validate.notNull(option, "option"); final double strike = option.getStrike(); final double t = option.getTimeToExpiry(); return new Function1D<NormalFunctionData, Double>() { @SuppressWarnings("synthetic-access") @Override public final Double evaluate(final NormalFunctionData data) { Validate.notNull(data, "data"); final double forward = data.getForward(); final double numeraire = data.getNumeraire(); final double sigma = data.getNormalVolatility(); final double sigmaRootT = sigma * Math.sqrt(t); final int sign = option.isCall() ? 1 : -1; if (sigmaRootT < 1e-16) { final double x = sign * (forward - strike); return (x > 0 ? numeraire * x : 0.0); } final double arg = sign * (forward - strike) / sigmaRootT; return numeraire * (sign * (forward - strike) * NORMAL.getCDF(arg) + sigmaRootT * NORMAL.getPDF(arg)); } }; }  @Override Function1D<NormalFunctionData, Double> getPriceFunction(final EuropeanVanillaOption option); double getPriceAdjoint(final EuropeanVanillaOption option, final NormalFunctionData data, double[] priceDerivative); double getDelta(EuropeanVanillaOption option, NormalFunctionData data); double getGamma(EuropeanVanillaOption option, NormalFunctionData data); double getVega(EuropeanVanillaOption option, NormalFunctionData data); double getTheta(EuropeanVanillaOption option, NormalFunctionData data);  }
@Test(expectedExceptions = IllegalArgumentException.class) public void testNullOption1() { FUNCTION.getPriceFunction(null); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testNullOption2() { FUNCTION.getPriceFunction(null); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testNullData1() { FUNCTION.getPriceFunction(ITM_CALL).evaluate((NormalFunctionData) null); }
@Test public void testZeroVolPrice() { assertEquals(DF * DELTA, FUNCTION.getPriceFunction(ITM_CALL).evaluate(ZERO_VOL_DATA), 1e-15); assertEquals(0, FUNCTION.getPriceFunction(OTM_CALL).evaluate(ZERO_VOL_DATA), 1e-15); assertEquals(DF * DELTA, FUNCTION.getPriceFunction(ITM_PUT).evaluate(ZERO_VOL_DATA), 1e-15); assertEquals(0, FUNCTION.getPriceFunction(OTM_PUT).evaluate(ZERO_VOL_DATA), 1e-15); }