SimpleChooserOptionModel extends AnalyticOptionModel<SimpleChooserOptionDefinition, StandardOptionDataBundle> { @Override public Function1D<StandardOptionDataBundle, Double> getPricingFunction(final SimpleChooserOptionDefinition definition) { Validate.notNull(definition); final Function1D<StandardOptionDataBundle, Double> pricingFunction = new Function1D<StandardOptionDataBundle, Double>() { @SuppressWarnings("synthetic-access") @Override public Double evaluate(final StandardOptionDataBundle data) { Validate.notNull(data); final double s = data.getSpot(); final double k = definition.getUnderlyingStrike(); final double t1 = definition.getTimeToExpiry(data.getDate()); final double t2 = DateUtils.getDifferenceInYears(data.getDate(), definition.getUnderlyingExpiry().getExpiry()); final double b = data.getCostOfCarry(); final double r = data.getInterestRate(t1); final double sigma = data.getVolatility(t1, k); final double sigmaT1 = sigma * Math.sqrt(t1); final double sigmaT2 = sigma * Math.sqrt(t2); final double sigmaSq = sigma * sigma / 2.; final double logSK = Math.log(s / k); final double bT2 = b * t2; final double d = getD(logSK, bT2, sigmaSq * t2, sigmaT2); final double y = getD(logSK, bT2, sigmaSq * t1, sigmaT1); final double df1 = getDF(r, b, t2); final double df2 = getDF(r, 0, t2); return s * df1 * (NORMAL.getCDF(d) - NORMAL.getCDF(-y)) - k * df2 * (NORMAL.getCDF(d - sigmaT2) - NORMAL.getCDF(-y + sigmaT1)); } }; return pricingFunction; }  @Override Function1D<StandardOptionDataBundle, Double> getPricingFunction(final SimpleChooserOptionDefinition definition);  }
@Test(expectedExceptions = IllegalArgumentException.class) public void testNullDefinition() { MODEL.getPricingFunction(null); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testNullData() { MODEL.getPricingFunction(DEFINITION).evaluate((StandardOptionDataBundle) null); }
@Test public void test() { double strike = SPOT; final StandardOptionDataBundle data = DATA.withVolatilitySurface(new VolatilitySurface(ConstantDoublesSurface.from(0))); SimpleChooserOptionDefinition chooser = new SimpleChooserOptionDefinition(new Expiry(DATE), strike, UNDERLYING_EXPIRY); OptionDefinition vanilla = new EuropeanVanillaOptionDefinition(strike, UNDERLYING_EXPIRY, true); assertEquals(MODEL.getPricingFunction(chooser).evaluate(DATA), BSM.getPricingFunction(vanilla).evaluate(DATA), 1e-9); strike = SPOT / 2; chooser = new SimpleChooserOptionDefinition(new Expiry(DATE), strike, UNDERLYING_EXPIRY); vanilla = new EuropeanVanillaOptionDefinition(strike, UNDERLYING_EXPIRY, true); assertEquals(MODEL.getPricingFunction(chooser).evaluate(DATA), BSM.getPricingFunction(vanilla).evaluate(DATA), 1e-9); chooser = new SimpleChooserOptionDefinition(CHOOSE_DATE, strike, UNDERLYING_EXPIRY); assertEquals(MODEL.getPricingFunction(chooser).evaluate(data), BSM.getPricingFunction(vanilla).evaluate(data), 1e-9); strike = SPOT * 2; chooser = new SimpleChooserOptionDefinition(new Expiry(DATE), strike, UNDERLYING_EXPIRY); vanilla = new EuropeanVanillaOptionDefinition(strike, UNDERLYING_EXPIRY, false); assertEquals(MODEL.getPricingFunction(chooser).evaluate(DATA), BSM.getPricingFunction(vanilla).evaluate(DATA), 1e-9); chooser = new SimpleChooserOptionDefinition(CHOOSE_DATE, strike, UNDERLYING_EXPIRY); assertEquals(MODEL.getPricingFunction(chooser).evaluate(data), BSM.getPricingFunction(vanilla).evaluate(data), 1e-9); assertEquals(MODEL.getGreeks(DEFINITION, DATA, Sets.newHashSet(Greek.FAIR_PRICE)).get(Greek.FAIR_PRICE), 6.1071, EPS); }