QuantLib::DayCounter dc = QuantLib::Actual360();
QuantLib::Date today = QuantLib::Date::todaysDate();
boost::shared_ptr<QuantLib::SimpleQuote> spot(new QuantLib::SimpleQuote(0.0));
boost::shared_ptr<QuantLib::SimpleQuote> qRate(new QuantLib::SimpleQuote(0.0));
boost::shared_ptr<QuantLib::YieldTermStructure> qTS = flatRate(today, qRate, dc);
boost::shared_ptr<QuantLib::SimpleQuote> rRate(new QuantLib::SimpleQuote(0.0));
boost::shared_ptr<QuantLib::YieldTermStructure> rTS = flatRate(today, rRate, dc);
boost::shared_ptr<QuantLib::SimpleQuote> vol(new QuantLib::SimpleQuote(0.0));
boost::shared_ptr<QuantLib::BlackVolTermStructure> volTS = flatVol(today, vol, dc);
boost::shared_ptr<QuantLib::StrikedTypePayoff> payoff1(new
QuantLib::PlainVanillaPayoff(type, strike));
QuantLib::Date exDate = today + timeToDays(time);
boost::shared_ptr<QuantLib::Exercise> exercise(new QuantLib::EuropeanExercise(exDate));
spot ->setValue(strike);
qRate->setValue(dividendYield);
rRate->setValue(riskFreeRate);
vol ->setValue(volatility);
boost::shared_ptr<QuantLib::BlackScholesMertonProcess> stochProcess(new
QuantLib::BlackScholesMertonProcess(QuantLib::Handle<QuantLib::Quote>(spot),
QuantLib::Handle<QuantLib::YieldTermStructure>(qTS),
QuantLib::Handle<QuantLib::YieldTermStructure>(rTS),
QuantLib::Handle<QuantLib::BlackVolTermStructure>(volTS)));
boost::shared_ptr<QuantLib::PricingEngine> engine(
new QuantLib::AnalyticEuropeanEngine(stochProcess));
QuantLib::EuropeanOption option(payoff1, exercise);
option.setPricingEngine(engine);
QuantLib::Real calculated = option.NPV();
.............................
boost::shared_ptr<QuantLib::YieldTermStructure>
flatRate(const QuantLib::Date& today,
const boost::shared_ptr<QuantLib::Quote>& forward,
const QuantLib::DayCounter& dc) {
return boost::shared_ptr<QuantLib::YieldTermStructure>(
new QuantLib::FlatForward(today, QuantLib::Handle<QuantLib::Quote>(forward), dc));
}
Regards
Ray