final DayCounter dc = new Actual360();
final Date today = Date.todaysDate();
new Settings().setEvaluationDate(today);
final SimpleQuote spot = new SimpleQuote(0.0);
final SimpleQuote qRate = new SimpleQuote(0.0);
final Handle<YieldTermStructure> qTS = new Handle<YieldTermStructure>(Utilities.flatRate(qRate, dc));
final SimpleQuote rRate = new SimpleQuote(0.0);
final Handle<YieldTermStructure> rTS = new Handle<YieldTermStructure>(Utilities.flatRate(rRate, dc));
final SimpleQuote vol = new SimpleQuote(0.0);
final Handle<BlackVolTermStructure> volTS = new Handle<BlackVolTermStructure>(Utilities.flatVol(vol, dc));
for (final Type type : types)
for (final double strike : strikes)
for (final int length : lengths) {
final Date exDate = today.add(new Period(length, TimeUnit.Years));
final Exercise exercise = new EuropeanExercise(exDate);
final List<Date> dividendDates = new ArrayList<Date>();
final List</* @Real */ Double> dividends = new ArrayList<Double>();
for (final Date d = today.add(new Period(3, TimeUnit.Months));
d.lt(exercise.lastDate());
d.addAssign(new Period(6, TimeUnit.Months))) {
dividendDates.add(d.clone());
dividends.add(5.0);
}
final StrikedTypePayoff payoff = new PlainVanillaPayoff(type, strike);
final BlackScholesMertonProcess stochProcess = new BlackScholesMertonProcess(new Handle<Quote>(spot), qTS, rTS, volTS);
final PricingEngine engine = new FDDividendEuropeanEngine(stochProcess, timeSteps, gridPoints);
final PricingEngine ref_engine = new AnalyticDividendEuropeanEngine(stochProcess);
final DividendVanillaOption option = new DividendVanillaOption(payoff, exercise, dividendDates, dividends);
option.setPricingEngine(engine);
final DividendVanillaOption ref_option = new DividendVanillaOption(payoff, exercise, dividendDates, dividends);
ref_option.setPricingEngine(ref_engine);
for (final double u : underlyings)
for (final double q : qRates)
for (final double r : rRates)
for (final double v : vols) {
spot.setValue(u);
qRate.setValue(q);
rRate.setValue(r);
vol.setValue(v);
// FLOATING_POINT_EXCEPTION
/* @Real */ final double calculated = option.NPV();
if (calculated > spot.value()*1.0e-5) {
/* @Real */ final double expected = ref_option.NPV();
/* @Real */ final double error = Math.abs(calculated-expected);