EuropeanExchangeAssetOptionModel extends TwoAssetAnalyticOptionModel<EuropeanExchangeAssetOptionDefinition, StandardTwoAssetOptionDataBundle> { @Override public Function1D<StandardTwoAssetOptionDataBundle, Double> getPricingFunction(final EuropeanExchangeAssetOptionDefinition 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 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, s1); final double sigma2 = data.getSecondVolatility(t, s2); final double rho = data.getCorrelation(); final double q1 = definition.getFirstQuantity(); final double q2 = definition.getSecondQuantity(); final double sigma = Math.sqrt(sigma1 * sigma1 + sigma2 * sigma2 - 2 * rho * sigma1 * sigma2); final double sigmaT = sigma * Math.sqrt(t); final double d1 = (Math.log(q1 * s1 / q2 / s2) + t * (b1 - b2 + sigma * sigma / 2)) / sigmaT; final double d2 = d1 - sigmaT; return q1 * s1 * Math.exp(t * (b1 - r)) * NORMAL.getCDF(d1) - q2 * s2 * Math.exp(t * (b2 - r)) * NORMAL.getCDF(d2); } }; }  @Override Function1D<StandardTwoAssetOptionDataBundle, Double> getPricingFunction(final EuropeanExchangeAssetOptionDefinition definition);  }
@Test(expectedExceptions = IllegalArgumentException.class) public void testNullDefinition() { MODEL.getPricingFunction(null); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testNullData() { MODEL.getPricingFunction(new EuropeanExchangeAssetOptionDefinition(EXPIRY1, Q1, Q2)).evaluate((StandardTwoAssetOptionDataBundle) null); }
@Test public void test() { final double eps = 1e-4; StandardTwoAssetOptionDataBundle data = new StandardTwoAssetOptionDataBundle(R, B1, B2, SIGMA1, new VolatilitySurface(ConstantDoublesSurface.from(0.15)), S1, S2, -0.5, DATE); assertEquals(MODEL.getPricingFunction(OPTION1).evaluate(data), 2.1251, eps); assertEquals(MODEL.getPricingFunction(OPTION2).evaluate(data), 2.7619, eps); data = data.withCorrelation(0); assertEquals(MODEL.getPricingFunction(OPTION1).evaluate(data), 2.0446, eps); assertEquals(MODEL.getPricingFunction(OPTION2).evaluate(data), 2.4793, eps); data = data.withCorrelation(0.5); assertEquals(MODEL.getPricingFunction(OPTION1).evaluate(data), 1.9736, eps); assertEquals(MODEL.getPricingFunction(OPTION2).evaluate(data), 2.1378, eps); data = data.withSecondVolatilitySurface(new VolatilitySurface(ConstantDoublesSurface.from(0.2))); data = data.withCorrelation(-0.5); assertEquals(MODEL.getPricingFunction(OPTION1).evaluate(data), 2.1986, eps); assertEquals(MODEL.getPricingFunction(OPTION2).evaluate(data), 2.9881, eps); data = data.withCorrelation(0.); assertEquals(MODEL.getPricingFunction(OPTION1).evaluate(data), 2.0913, eps); assertEquals(MODEL.getPricingFunction(OPTION2).evaluate(data), 2.6496, eps); data = data.withCorrelation(0.5); assertEquals(MODEL.getPricingFunction(OPTION1).evaluate(data), 1.9891, eps); assertEquals(MODEL.getPricingFunction(OPTION2).evaluate(data), 2.2306, eps); data = data.withSecondVolatilitySurface(new VolatilitySurface(ConstantDoublesSurface.from(0.25))); data = data.withCorrelation(-0.5); assertEquals(MODEL.getPricingFunction(OPTION1).evaluate(data), 2.2827, eps); assertEquals(MODEL.getPricingFunction(OPTION2).evaluate(data), 3.2272, eps); data = data.withCorrelation(0.); assertEquals(MODEL.getPricingFunction(OPTION1).evaluate(data), 2.1520, eps); assertEquals(MODEL.getPricingFunction(OPTION2).evaluate(data), 2.8472, eps); data = data.withCorrelation(0.5); assertEquals(MODEL.getPricingFunction(OPTION1).evaluate(data), 2.0189, eps); assertEquals(MODEL.getPricingFunction(OPTION2).evaluate(data), 2.3736, eps); }