// testing delta 1
i++;
payoff = new PlainVanillaPayoff(values[i].type, values[i].strike);
exDate = today.add(timeToDays(values[i].t));
exercise = new EuropeanExercise(exDate);
spot.setValue(values[i].s);
qRate.setValue(values[i].q);
rRate.setValue(values[i].r);
vol.setValue(values[i].v);
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 AnalyticEuropeanEngine(stochProcess);
VanillaOption option = new EuropeanOption(payoff, exercise);
option.setPricingEngine(engine);
calculated = option.delta();
error = Math.abs(calculated - values[i].result);
if (error > tolerance) {
REPORT_FAILURE("delta", payoff, exercise, values[i].s, values[i].q, values[i].r, today, values[i].v,
values[i].result, calculated, error, tolerance);
}
//testing delta 2
i++;
payoff = new PlainVanillaPayoff(values[i].type, values[i].strike);
exDate = today.add(timeToDays(values[i].t));
exercise = new EuropeanExercise(exDate);
spot.setValue(values[i].s);
qRate.setValue(values[i].q);
rRate.setValue(values[i].r);
vol.setValue(values[i].v);
option = new EuropeanOption(payoff, exercise);
option.setPricingEngine(engine);
calculated = option.delta();
error = Math.abs(calculated - values[i].result);
if(error>tolerance) {
REPORT_FAILURE("delta", payoff, exercise, values[i].s, values[i].q, values[i].r, today, values[i].v,
values[i].result, calculated, error, tolerance);
}
//testing elasticity
i++;
payoff = new PlainVanillaPayoff(values[i].type, values[i].strike);
exDate = today.add(timeToDays(values[i].t));
exercise = new EuropeanExercise(exDate);
spot.setValue(values[i].s);
qRate.setValue(values[i].q);
rRate.setValue(values[i].r);
vol.setValue(values[i].v);
option = new EuropeanOption(payoff, exercise);
option.setPricingEngine(engine);
calculated = option.elasticity();
error = Math.abs(Math.abs(calculated - values[i].result));
if(error>tolerance) {
REPORT_FAILURE("elasticity", payoff, exercise, values[i].s, values[i].q, values[i].r, today, values[i].v,
values[i].result, calculated, error, tolerance);
}
// testing gamma 1
i++;
payoff = new PlainVanillaPayoff(values[i].type, values[i].strike);
exDate = today.add(timeToDays(values[i].t));
exercise = new EuropeanExercise(exDate);
spot.setValue(values[i].s);
qRate.setValue(values[i].q);
rRate.setValue(values[i].r);
vol.setValue(values[i].v);
option = new EuropeanOption(payoff, exercise);
option.setPricingEngine(engine);
calculated = option.gamma();
error = Math.abs(Math.abs(calculated - values[i].result));
if(error>tolerance) {
REPORT_FAILURE("gamma", payoff, exercise, values[i].s, values[i].q, values[i].r, today, values[i].v,
values[i].result, calculated, error, tolerance);
}
// testing gamma 2
i++;
payoff = new PlainVanillaPayoff(values[i].type, values[i].strike);
exDate = today.add(timeToDays(values[i].t));
exercise = new EuropeanExercise(exDate);
spot.setValue(values[i].s);
qRate.setValue(values[i].q);
rRate.setValue(values[i].r);
vol.setValue(values[i].v);
option = new EuropeanOption(payoff, exercise);
option.setPricingEngine(engine);
calculated = option.gamma();
error = Math.abs(Math.abs(calculated - values[i].result));
if(error>tolerance) {
REPORT_FAILURE("gamma", payoff, exercise, values[i].s, values[i].q, values[i].r, today, values[i].v,
values[i].result, calculated, error, tolerance);
}
//testing vega 1
i++;
payoff = new PlainVanillaPayoff(values[i].type, values[i].strike);
exDate = today.add(timeToDays(values[i].t));
exercise = new EuropeanExercise(exDate);
spot.setValue(values[i].s);
qRate.setValue(values[i].q);
rRate.setValue(values[i].r);
vol.setValue(values[i].v);
option = new EuropeanOption(payoff, exercise);
option.setPricingEngine(engine);
calculated = option.vega();
error = Math.abs(Math.abs(calculated - values[i].result));
if(error>tolerance) {
REPORT_FAILURE("vega", payoff, exercise, values[i].s, values[i].q, values[i].r, today, values[i].v,
values[i].result, calculated, error, tolerance);
}
//testing vega 2
i++;
payoff = new PlainVanillaPayoff(values[i].type, values[i].strike);
exDate = today.add(timeToDays(values[i].t));
exercise = new EuropeanExercise(exDate);
spot.setValue(values[i].s);
qRate.setValue(values[i].q);
rRate.setValue(values[i].r);
vol.setValue(values[i].v);
option = new EuropeanOption(payoff, exercise);
option.setPricingEngine(engine);
calculated = option.vega();
error = Math.abs(Math.abs(calculated - values[i].result));
if(error>tolerance) {
REPORT_FAILURE("vega", payoff, exercise, values[i].s, values[i].q, values[i].r, today, values[i].v,
values[i].result, calculated, error, tolerance);
}
//testing theta
i++;
payoff = new PlainVanillaPayoff(values[i].type, values[i].strike);
exDate = today.add(timeToDays(values[i].t));
exercise = new EuropeanExercise(exDate);
spot.setValue(values[i].s);
qRate.setValue(values[i].q);
rRate.setValue(values[i].r);
vol.setValue(values[i].v);
option = new EuropeanOption(payoff, exercise);
option.setPricingEngine(engine);
calculated = option.theta();
error = Math.abs(Math.abs(calculated - values[i].result));
if(error>tolerance) {
REPORT_FAILURE("theta", payoff, exercise, values[i].s, values[i].q, values[i].r, today, values[i].v,
values[i].result, calculated, error, tolerance);
}
//testing theta per day
i++;
payoff = new PlainVanillaPayoff(values[i].type, values[i].strike);
exDate = today.add(timeToDays(values[i].t));
exercise = new EuropeanExercise(exDate);
spot.setValue(values[i].s);
qRate.setValue(values[i].q);
rRate.setValue(values[i].r);
vol.setValue(values[i].v);
option = new EuropeanOption(payoff, exercise);
option.setPricingEngine(engine);
calculated = option.thetaPerDay();
error = Math.abs(Math.abs(calculated - values[i].result));
if(error>tolerance) {
REPORT_FAILURE("theta per day", payoff, exercise, values[i].s, values[i].q, values[i].r, today, values[i].v,
values[i].result, calculated, error, tolerance);
}
//testing rho
i++;
payoff = new PlainVanillaPayoff(values[i].type, values[i].strike);
exDate = today.add(timeToDays(values[i].t));
exercise = new EuropeanExercise(exDate);
spot.setValue(values[i].s);
qRate.setValue(values[i].q);
rRate.setValue(values[i].r);
vol.setValue(values[i].v);
option = new EuropeanOption(payoff, exercise);
option.setPricingEngine(engine);
calculated = option.rho();
error = Math.abs(Math.abs(calculated - values[i].result));
if(error>tolerance) {
REPORT_FAILURE("rho", payoff, exercise, values[i].s, values[i].q, values[i].r, today, values[i].v,
values[i].result, calculated, error, tolerance);
}
//testing dividend rho
i++;
payoff = new PlainVanillaPayoff(values[i].type, values[i].strike);
exDate = today.add(timeToDays(values[i].t));
exercise = new EuropeanExercise(exDate);
spot.setValue(values[i].s);
qRate.setValue(values[i].q);
rRate.setValue(values[i].r);
vol.setValue(values[i].v);