MonteCarloOptionModel 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"); if (requiredGreeks.contains(Greek.FAIR_PRICE)) { if (requiredGreeks.size() > 1) { s_logger.warn("Can only produce fair price"); } } else { throw new IllegalArgumentException("Can only produce fair price"); } final GreekResultCollection greeks = new GreekResultCollection(); final Function1D<U, Double> price = getPricingFunction(definition); greeks.put(Greek.FAIR_PRICE, price.evaluate(data)); return greeks; } MonteCarloOptionModel(final int n, final int steps, final StochasticProcess<T, U> process, final RandomNumberGenerator generator); @Override GreekResultCollection getGreeks(final T definition, final U data, final Set<Greek> requiredGreeks); abstract Function1D<U, Double> getPricingFunction(T definition);  }
@Test(expectedExceptions = IllegalArgumentException.class) public void testNullDefinition() { MODEL.getGreeks(null, new StandardOptionDataBundle(null, 0, null, 100, DateUtils.getUTCDate(2010, 1, 1)), Sets.newHashSet(Greek.FAIR_PRICE)); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testNullData() { MODEL.getGreeks(new EuropeanVanillaOptionDefinition(100, new Expiry(DateUtils.getUTCDate(2010, 1, 1)), true), null, Sets.newHashSet(Greek.FAIR_PRICE)); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testNullGreeks() { MODEL.getGreeks(new EuropeanVanillaOptionDefinition(100, new Expiry(DateUtils.getUTCDate(2010, 1, 1)), true), new StandardOptionDataBundle(null, 0, null, 100, DateUtils.getUTCDate(2010, 1, 1)), null); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testEmptyGreeks() { MODEL.getGreeks(new EuropeanVanillaOptionDefinition(100, new Expiry(DateUtils.getUTCDate(2010, 1, 1)), true), new StandardOptionDataBundle(null, 0, null, 100, DateUtils.getUTCDate(2010, 1, 1)), Collections.<Greek> emptySet()); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testWrongGreeks() { MODEL.getGreeks(new EuropeanVanillaOptionDefinition(100, new Expiry(DateUtils.getUTCDate(2010, 1, 1)), true), new StandardOptionDataBundle(null, 0, null, 100, DateUtils.getUTCDate(2010, 1, 1)), Sets.newHashSet(Greek.DELTA, Greek.GAMMA)); }
@Test public void testPriceOnly() { final GreekResultCollection result = MODEL.getGreeks(new EuropeanVanillaOptionDefinition(100, new Expiry(DateUtils.getUTCDate(2010, 1, 1)), true), new StandardOptionDataBundle(null, 0, null, 100, DateUtils.getUTCDate(2010, 1, 1)), Sets.newHashSet(Greek.FAIR_PRICE, Greek.DELTA, Greek.GAMMA)); assertEquals(result.size(), 1); assertEquals(result.keySet().iterator().next(), Greek.FAIR_PRICE); assertEquals(result.values().iterator().next(), 2., 0); }