FourierOptionModel implements OptionModel<EuropeanVanillaOptionDefinition, BlackOptionDataBundle> { @Override public GreekResultCollection getGreeks(final EuropeanVanillaOptionDefinition definition, final BlackOptionDataBundle dataBundle, final Set<Greek> requiredGreeks) { Validate.notNull(definition, "definition"); Validate.notNull(dataBundle, "data bundle"); Validate.notNull(requiredGreeks, "required greeks"); if (!requiredGreeks.contains(Greek.FAIR_PRICE)) { throw new NotImplementedException("Can only calculate fair price at the moment: asked for " + requiredGreeks); } if (requiredGreeks.size() > 1) { s_logger.warn("Can only calculate fair price - ignoring other greeks"); } final ZonedDateTime date = dataBundle.getDate(); final EuropeanVanillaOption option = EuropeanVanillaOption.fromDefinition(definition, date); final BlackFunctionData data = BlackFunctionData.fromDataBundle(dataBundle, definition); final double price = _pricer.price(data, option, _characteristicExponent, _alpha, _limitTolerance, _useVarianceReduction); final GreekResultCollection result = new GreekResultCollection(); result.put(Greek.FAIR_PRICE, price); return result; } FourierOptionModel(final MartingaleCharacteristicExponent characteristicExponent);  FourierOptionModel(final MartingaleCharacteristicExponent characteristicExponent, final boolean useVarianceReduction);  FourierOptionModel(final MartingaleCharacteristicExponent characteristicExponent, final Integrator1D<Double, Double> integrator);  FourierOptionModel(final MartingaleCharacteristicExponent characteristicExponent, final Integrator1D<Double, Double> integrator, final boolean useVarianceReduction);  FourierOptionModel(final MartingaleCharacteristicExponent characteristicExponent, final double alpha, final double limitTolerance, final boolean useVarianceReduction);  FourierOptionModel(final MartingaleCharacteristicExponent characteristicExponent, final Integrator1D<Double, Double> integrator, final double alpha,
      final double limitTolerance, final boolean useVarianceReduction); @Override GreekResultCollection getGreeks(final EuropeanVanillaOptionDefinition definition, final BlackOptionDataBundle dataBundle, final Set<Greek> requiredGreeks);  }
@Test(expectedExceptions = IllegalArgumentException.class) public void testNullDefinition() { FOURIER_MODEL1.getGreeks(null, BLACK_DATA, GREEKS); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testNullData() { FOURIER_MODEL1.getGreeks(ITM_CALL, null, GREEKS); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testNullGreeks() { FOURIER_MODEL1.getGreeks(ITM_CALL, BLACK_DATA, null); }
@Test(expectedExceptions = NotImplementedException.class) public void testWrongGreeks() { FOURIER_MODEL1.getGreeks(ITM_CALL, BLACK_DATA, Sets.newHashSet(Greek.DELTA, Greek.GAMMA)); }
@Test public void testPricing() { GreekResultCollection fourierPrice = FOURIER_MODEL1.getGreeks(ITM_CALL, BLACK_DATA, GREEKS); double bsmPrice = BSM_MODEL.getGreeks(ITM_CALL, BSM_DATA, GREEKS).get(Greek.FAIR_PRICE); assertEquals(fourierPrice.size(), 1); assertEquals(fourierPrice.get(Greek.FAIR_PRICE), bsmPrice, EPS); fourierPrice = FOURIER_MODEL2.getGreeks(ITM_CALL, BLACK_DATA, GREEKS); assertEquals(fourierPrice.size(), 1); assertEquals(fourierPrice.get(Greek.FAIR_PRICE), bsmPrice, EPS); fourierPrice = FOURIER_MODEL3.getGreeks(ITM_CALL, BLACK_DATA, GREEKS); assertEquals(fourierPrice.size(), 1); assertEquals(fourierPrice.get(Greek.FAIR_PRICE), bsmPrice, EPS); fourierPrice = FOURIER_MODEL4.getGreeks(ITM_CALL, BLACK_DATA, GREEKS); assertEquals(fourierPrice.size(), 1); assertEquals(fourierPrice.get(Greek.FAIR_PRICE), bsmPrice, EPS); fourierPrice = FOURIER_MODEL1.getGreeks(OTM_CALL, BLACK_DATA, GREEKS); bsmPrice = BSM_MODEL.getGreeks(OTM_CALL, BSM_DATA, GREEKS).get(Greek.FAIR_PRICE); assertEquals(fourierPrice.size(), 1); assertEquals(fourierPrice.get(Greek.FAIR_PRICE), bsmPrice, EPS); fourierPrice = FOURIER_MODEL2.getGreeks(OTM_CALL, BLACK_DATA, GREEKS); assertEquals(fourierPrice.size(), 1); assertEquals(fourierPrice.get(Greek.FAIR_PRICE), bsmPrice, EPS); fourierPrice = FOURIER_MODEL3.getGreeks(OTM_CALL, BLACK_DATA, GREEKS); assertEquals(fourierPrice.size(), 1); assertEquals(fourierPrice.get(Greek.FAIR_PRICE), bsmPrice, EPS); fourierPrice = FOURIER_MODEL4.getGreeks(OTM_CALL, BLACK_DATA, GREEKS); assertEquals(fourierPrice.size(), 1); assertEquals(fourierPrice.get(Greek.FAIR_PRICE), bsmPrice, EPS); fourierPrice = FOURIER_MODEL1.getGreeks(ITM_PUT, BLACK_DATA, GREEKS); bsmPrice = BSM_MODEL.getGreeks(ITM_PUT, BSM_DATA, GREEKS).get(Greek.FAIR_PRICE); assertEquals(fourierPrice.size(), 1); assertEquals(fourierPrice.get(Greek.FAIR_PRICE), bsmPrice, EPS); fourierPrice = FOURIER_MODEL2.getGreeks(ITM_PUT, BLACK_DATA, GREEKS); assertEquals(fourierPrice.size(), 1); assertEquals(fourierPrice.get(Greek.FAIR_PRICE), bsmPrice, EPS); fourierPrice = FOURIER_MODEL3.getGreeks(ITM_PUT, BLACK_DATA, GREEKS); assertEquals(fourierPrice.size(), 1); assertEquals(fourierPrice.get(Greek.FAIR_PRICE), bsmPrice, EPS); fourierPrice = FOURIER_MODEL4.getGreeks(ITM_PUT, BLACK_DATA, GREEKS); assertEquals(fourierPrice.size(), 1); assertEquals(fourierPrice.get(Greek.FAIR_PRICE), bsmPrice, EPS); fourierPrice = FOURIER_MODEL1.getGreeks(OTM_PUT, BLACK_DATA, GREEKS); bsmPrice = BSM_MODEL.getGreeks(OTM_PUT, BSM_DATA, GREEKS).get(Greek.FAIR_PRICE); assertEquals(fourierPrice.size(), 1); assertEquals(fourierPrice.get(Greek.FAIR_PRICE), bsmPrice, EPS); fourierPrice = FOURIER_MODEL2.getGreeks(OTM_PUT, BLACK_DATA, GREEKS); assertEquals(fourierPrice.size(), 1); assertEquals(fourierPrice.get(Greek.FAIR_PRICE), bsmPrice, EPS); fourierPrice = FOURIER_MODEL3.getGreeks(OTM_PUT, BLACK_DATA, GREEKS); assertEquals(fourierPrice.size(), 1); assertEquals(fourierPrice.get(Greek.FAIR_PRICE), bsmPrice, EPS); fourierPrice = FOURIER_MODEL4.getGreeks(OTM_PUT, BLACK_DATA, GREEKS); assertEquals(fourierPrice.size(), 1); assertEquals(fourierPrice.get(Greek.FAIR_PRICE), bsmPrice, EPS); }