|
From: ray 1. <ra...@gm...> - 2013-01-08 20:12:39
|
I am new to Quantlib code base, but I have a basic question,
I tried to calculate a basic European option using the below but having
difficulty to validate the results against my spreadsheet
[Call] = *blsprice*(100, 97, 0.1, 0.25, 0.5) returns a C*all *price of *$12.61
via* spreadsheet
but, via *Quantlib *I am getting value *$10.77*
can you advice,
I hope you don't mind that I posted the code below,
QuantLib::Option::Type type(QuantLib::Option::Call);
QuantLib::Real stock = 100;
QuantLib::Real strike = 97;
QuantLib::Real time = 0.25;
QuantLib::Spread dividendYield = 0.00;
QuantLib::Rate riskFreeRate = 0.1;
QuantLib::Volatility volatility = 0.5;
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
|