BlackPriceFunction implements OptionPriceFunction<BlackFunctionData> { @Override public Function1D<BlackFunctionData, Double> getPriceFunction(final EuropeanVanillaOption option) { Validate.notNull(option, "option"); final double k = option.getStrike(); final double t = option.getTimeToExpiry(); final boolean isCall = option.isCall(); return new Function1D<BlackFunctionData, Double>() { @Override public Double evaluate(final BlackFunctionData data) { Validate.notNull(data, "data"); final double forward = data.getForward(); final double sigma = data.getBlackVolatility(); final double df = data.getDiscountFactor(); return df * BlackFormulaRepository.price(forward, k, t, sigma, isCall); } }; }  @Override Function1D<BlackFunctionData, Double> getPriceFunction(final EuropeanVanillaOption option); double[] getPriceAdjoint(final EuropeanVanillaOption option, final BlackFunctionData data); double getPriceAdjoint2(final EuropeanVanillaOption option, final BlackFunctionData data, double[] bsD, double[][] bsD2); Function1D<BlackFunctionData, Double> getVegaFunction(final EuropeanVanillaOption option);  }
@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(ATM_CALL).evaluate((BlackFunctionData) null); }
@Test public void testATMPrice() { final double sigmaRootT = ATM_DATA.getBlackVolatility() * Math.sqrt(ATM_CALL.getTimeToExpiry()); assertEquals(DF * F * (2 * NORMAL.getCDF(sigmaRootT / 2) - 1), FUNCTION.getPriceFunction(ATM_CALL).evaluate(ATM_DATA), 1e-14); }
@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); }