#include <ql/quantlib.hpp>
using namespace QuantLib;
boost::shared_ptr<YieldTermStructure> flatRate(const Date& today, const boost::shared_ptr<Quote>& forward, const DayCounter& dc)
{
return boost::shared_ptr<YieldTermStructure>(new FlatForward(today, Handle<Quote>(forward), dc));
}
boost::shared_ptr<YieldTermStructure> flatRate(const Date& today, Rate forward, const DayCounter& dc)
{
return flatRate(today, boost::shared_ptr<Quote>(new SimpleQuote(forward)), dc);
}
boost::shared_ptr<YieldTermStructure> flatRate(const boost::shared_ptr<Quote>& forward, const DayCounter& dc)
{
return boost::shared_ptr<YieldTermStructure>(new FlatForward(0, NullCalendar(), Handle<Quote>(forward), dc));
}
boost::shared_ptr<YieldTermStructure> flatRate(Rate forward, const DayCounter& dc)
{
return flatRate(boost::shared_ptr<Quote>(new SimpleQuote(forward)), dc);
}
boost::shared_ptr<GeneralizedBlackScholesProcess>
makeProcess(const boost::shared_ptr<Quote>& u,
const boost::shared_ptr<YieldTermStructure>& q,
const boost::shared_ptr<YieldTermStructure>& r,
const boost::shared_ptr<BlackVolTermStructure>& vol)
{
return boost::shared_ptr<BlackScholesMertonProcess>(
new BlackScholesMertonProcess(Handle<Quote>(u),
Handle<YieldTermStructure>(q),
Handle<YieldTermStructure>(r),
Handle<BlackVolTermStructure>(vol)));
}
boost::shared_ptr<BlackVolTermStructure> flatVol(const Date& today, const boost::shared_ptr<Quote>& vol, const DayCounter& dc)
{
return boost::shared_ptr<BlackVolTermStructure>(new BlackConstantVol(today, NullCalendar(), Handle<Quote>(vol), dc));
}
boost::shared_ptr<BlackVolTermStructure> flatVol(const Date& today, Volatility vol, const DayCounter& dc)
{
return flatVol(today, boost::shared_ptr<Quote>(new SimpleQuote(vol)), dc);
}
boost::shared_ptr<BlackVolTermStructure> flatVol(const boost::shared_ptr<Quote>& vol, const DayCounter& dc)
{
return boost::shared_ptr<BlackVolTermStructure>(new BlackConstantVol(0, NullCalendar(), Handle<Quote>(vol), dc));
}
boost::shared_ptr<BlackVolTermStructure> flatVol(Volatility vol, const DayCounter& dc)
{
return flatVol(boost::shared_ptr<Quote>(new SimpleQuote(vol)), dc);
}
int main(int argc, char ** argv)
{
Date today = Date(1, Jan, 2015);
Settings::instance().evaluationDate() = today;
boost::shared_ptr<SimpleQuote> spot(new SimpleQuote(100.0));
boost::shared_ptr<YieldTermStructure> qTS = flatRate(today, 0.05, Actual360());
boost::shared_ptr<YieldTermStructure> rTS = flatRate(today, 0.05, Actual360());
boost::shared_ptr<BlackVolTermStructure> vTS = flatVol (today, 0.05, Actual360());
boost::shared_ptr<GeneralizedBlackScholesProcess> stochProcess = makeProcess(spot, qTS, rTS, vTS);
boost::shared_ptr<PricingEngine> engine = boost::shared_ptr<PricingEngine>(
new FDEuropeanEngine<ExplicitEuler>(stochProcess, 1000, 1000));
boost::shared_ptr<StrikedTypePayoff> payoff(new PlainVanillaPayoff(Option::Call, 100.0));
boost::shared_ptr<Exercise> exercise(new EuropeanExercise(Date(1, Jan, 2016)));
EuropeanOption option(payoff, exercise);
option.setPricingEngine(engine);
std::cout << option.NPV() << std::endl;
}
Free forum by Nabble | Disable Popup Ads | Edit this page |