TwoAssetAnalyticOptionModel implements OptionModel<T, U> { @Override public GreekResultCollection getGreeks(final T definition, final U data, final Set<Greek> requiredGreeks) { Validate.notNull(definition, "definition"); Validate.notNull(data, "data"); Validate.notNull(requiredGreeks, "required greeks"); Validate.notEmpty(requiredGreeks, "required greeks"); final Function1D<U, Double> pricingFunction = getPricingFunction(definition); final GreekResultCollection results = new GreekResultCollection(); for (final Greek greek : requiredGreeks) { if (greek != Greek.FAIR_PRICE) { s_logger.warn("Can only calculate price for two-asset options, not calculating " + greek); } else { results.put(greek, pricingFunction.evaluate(data)); } } return results; }  abstract Function1D<U, Double> getPricingFunction(T definition); @Override GreekResultCollection getGreeks(final T definition, final U data, final Set<Greek> requiredGreeks);  }
@Test(expectedExceptions = IllegalArgumentException.class) public void testNullDefinition() { DUMMY.getGreeks(null, DATA, REQUIRED_GREEKS); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testNullData() { DUMMY.getGreeks(OPTION, null, REQUIRED_GREEKS); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testNullGreeks() { DUMMY.getGreeks(OPTION, DATA, null); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testEmptyGreeks() { DUMMY.getGreeks(OPTION, DATA, Collections.<Greek> emptySet()); }
@Test public void test() { final GreekResultCollection result = DUMMY.getGreeks(OPTION, DATA, REQUIRED_GREEKS); assertEquals(result.size(), 1); assertEquals(result.get(Greek.FAIR_PRICE), RESULT, 0); }