final BlackVolTermStructure volTS = Utilities.flatVol(today, vol, dc);
final BlackScholesMertonProcess stochProcess = new BlackScholesMertonProcess(
new Handle<Quote>(spot), new Handle<YieldTermStructure>(qTS),
new Handle<YieldTermStructure>(rTS), new Handle<BlackVolTermStructure>(volTS));
final PricingEngine engine = new AnalyticContinuousGeometricAveragePriceAsianEngine(stochProcess);
final AverageType averageType = AverageType.Geometric;
final Option.Type type = Option.Type.Put;
/* @Real */final double strike = 85.0;
final Date exerciseDate = today.clone().addAssign(90);
/* @Size */int pastFixings = Integer.MAX_VALUE;
/* @Real */double runningAccumulator = Double.NaN;
final StrikedTypePayoff payoff = new PlainVanillaPayoff(type, strike);
final Exercise exercise = new EuropeanExercise(exerciseDate);
final ContinuousAveragingAsianOption option = new ContinuousAveragingAsianOption(averageType, payoff, exercise);
option.setPricingEngine(engine);
/* @Real */double calculated = option.NPV();
/* @Real */final double expected = 4.6922;
/* @Real */double tolerance = 1.0e-4;
if (Math.abs(calculated - expected) > tolerance) {
reportFailure("value", averageType, runningAccumulator, pastFixings, new ArrayList<Date>(), payoff, exercise, spot
.value(), qRate.value(), rRate.value(), today, vol.value(), expected, calculated, tolerance);
}
// trying to approximate the continuous version with the discrete version
runningAccumulator = 1.0;
pastFixings = 0;
final List<Date> fixingDates = new ArrayList<Date>(91);
for (/* @Size */int i = 0; i < 91; i++) {
fixingDates.add(today.clone().addAssign(i));
}
final PricingEngine engine2 = new AnalyticDiscreteGeometricAveragePriceAsianEngine(stochProcess);
final DiscreteAveragingAsianOption option2 = new DiscreteAveragingAsianOption(
averageType, runningAccumulator, pastFixings, fixingDates, payoff, exercise);
option2.setPricingEngine(engine2);
calculated = option2.NPV();