SupershareOptionModel extends AnalyticOptionModel<SupershareOptionDefinition, StandardOptionDataBundle> { @Override public Function1D<StandardOptionDataBundle, Double> getPricingFunction(final SupershareOptionDefinition 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 t = definition.getTimeToExpiry(data.getDate()); final double r = data.getInterestRate(t); final double b = data.getCostOfCarry(); final double lower = definition.getLowerBound(); final double upper = definition.getUpperBound(); final double sigma = data.getVolatility(t, lower); final double d1 = getD1(s, lower, t, sigma, b); final double d2 = getD1(s, upper, t, sigma, b); return s * Math.exp(t * (b - r)) * (NORMAL.getCDF(d1) - NORMAL.getCDF(d2)) / lower; } }; }  @Override Function1D<StandardOptionDataBundle, Double> getPricingFunction(final SupershareOptionDefinition definition);  }
@Test(expectedExceptions = IllegalArgumentException.class) public void testNullDefinition() { MODEL.getPricingFunction(null); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testNullData() { MODEL.getPricingFunction(OPTION).evaluate((StandardOptionDataBundle) null); }
@Test public void testZeroVol() { StandardOptionDataBundle data = DATA.withVolatilitySurface(new VolatilitySurface(ConstantDoublesSurface.from(1e-15))).withSpot(LOWER - 1); assertEquals(MODEL.getPricingFunction(OPTION).evaluate(data), 0, 0); data = data.withSpot(UPPER + 1); assertEquals(MODEL.getPricingFunction(OPTION).evaluate(data), 0, 0); }
@Test public void test() { assertEquals(MODEL.getPricingFunction(OPTION).evaluate(DATA), 0.7389, 1e-4); }