ProductOptionModel extends TwoAssetAnalyticOptionModel<ProductOptionDefinition, StandardTwoAssetOptionDataBundle> { @Override public Function1D<StandardTwoAssetOptionDataBundle, Double> getPricingFunction(final ProductOptionDefinition definition) { Validate.notNull(definition, "definition"); return new Function1D<StandardTwoAssetOptionDataBundle, Double>() { @SuppressWarnings("synthetic-access") @Override public Double evaluate(final StandardTwoAssetOptionDataBundle data) { Validate.notNull(data, "data"); final double s1 = data.getFirstSpot(); final double s2 = data.getSecondSpot(); final double k = definition.getStrike(); final double b1 = data.getFirstCostOfCarry(); final double b2 = data.getSecondCostOfCarry(); final double t = definition.getTimeToExpiry(data.getDate()); final double r = data.getInterestRate(t); final double sigma1 = data.getFirstVolatility(t, k); final double sigma2 = data.getSecondVolatility(t, k); final double rho = data.getCorrelation(); final double sigma = Math.sqrt(sigma1 * sigma1 + sigma2 * sigma2 + 2 * rho * sigma1 * sigma2); final double sigmaT = sigma * Math.sqrt(t); final double f = s1 * s2 * Math.exp(t * (b1 + b2 + rho * sigma1 * sigma2)); final double d1 = (Math.log(f / k) + t * sigma * sigma / 2) / sigmaT; final double d2 = d1 - sigmaT; final int sign = definition.isCall() ? 1 : -1; return Math.exp(-r * t) * sign * (f * NORMAL.getCDF(sign * d1) - k * NORMAL.getCDF(sign * d2)); } }; }  @Override Function1D<StandardTwoAssetOptionDataBundle, Double> getPricingFunction(final ProductOptionDefinition definition);  }
@Test(expectedExceptions = IllegalArgumentException.class) public void testNullDefinition() { MODEL.getPricingFunction(null); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testNullData() { MODEL.getPricingFunction(new ProductOptionDefinition(0.1, EXPIRY1, true)).evaluate((StandardTwoAssetOptionDataBundle) null); }
@Test public void test() { ProductOptionDefinition option = new ProductOptionDefinition(15000, EXPIRY1, true); StandardTwoAssetOptionDataBundle data = new StandardTwoAssetOptionDataBundle(R, B1, B2, new VolatilitySurface(ConstantDoublesSurface.from(0.2)), new VolatilitySurface( ConstantDoublesSurface.from(0.3)), S1, S2, -0.5, DATE); assertEquals(MODEL.getPricingFunction(option).evaluate(data), 0.0028, EPS); data = data.withFirstVolatilitySurface(new VolatilitySurface(ConstantDoublesSurface.from(0.3))).withCorrelation(0); assertEquals(MODEL.getPricingFunction(option).evaluate(data), 2.4026, EPS); option = new ProductOptionDefinition(15000, EXPIRY2, true); assertEquals(MODEL.getPricingFunction(option).evaluate(data), 266.1594, EPS); }