AssetOrNothingOptionModel extends AnalyticOptionModel<AssetOrNothingOptionDefinition, StandardOptionDataBundle> { @Override public Function1D<StandardOptionDataBundle, Double> getPricingFunction(final AssetOrNothingOptionDefinition definition) { Validate.notNull(definition, "definition"); return new Function1D<StandardOptionDataBundle, Double>() { @SuppressWarnings("synthetic-access") @Override public Double evaluate(final StandardOptionDataBundle data) { Validate.notNull(data, "data"); final double s = data.getSpot(); final double k = definition.getStrike(); final double t = definition.getTimeToExpiry(data.getDate()); final double r = data.getInterestRate(t); final double sigma = data.getVolatility(t, k); final double b = data.getCostOfCarry(); final double d = getD1(s, k, t, sigma, b); return s * Math.exp(t * (b - r)) * NORMAL.getCDF(definition.isCall() ? d : -d); } }; }  @Override Function1D<StandardOptionDataBundle, Double> getPricingFunction(final AssetOrNothingOptionDefinition definition);  }
@Test(expectedExceptions = IllegalArgumentException.class) public void testNullDefinition() { MODEL.getPricingFunction(null); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testNullData() { MODEL.getPricingFunction(PUT).evaluate((StandardOptionDataBundle) null); }
@Test public void testZeroVol() { StandardOptionDataBundle data = DATA.withVolatilitySurface(new VolatilitySurface(ConstantDoublesSurface.from(0))); final double df = Math.exp(T * (B - R)); assertEquals(MODEL.getPricingFunction(CALL).evaluate(data), df * SPOT, EPS); assertEquals(MODEL.getPricingFunction(PUT).evaluate(data), 0, 0); data = data.withSpot(60); assertEquals(MODEL.getPricingFunction(CALL).evaluate(data), 0, 0); assertEquals(MODEL.getPricingFunction(PUT).evaluate(data), df * 60, EPS); }
@Test public void test() { assertEquals(MODEL.getPricingFunction(PUT).evaluate(DATA), 20.2069, 1e-4); }