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 Call 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 ------------------------------------------------------------------------------ Master SQL Server Development, Administration, T-SQL, SSAS, SSIS, SSRS and more. Get SQL Server skills now (including 2012) with LearnDevNow - 200+ hours of step-by-step video tutorials by Microsoft MVPs and experts. SALE $99.99 this month only - learn more at: http://p.sf.net/sfu/learnmore_122512 _______________________________________________ QuantLib-dev mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/quantlib-dev |
I've tried the thing in QuantLib via Python and I get 12.6127. How
did you implement timeToDays? With the Actual/360 day counter you're using, the exercise date should be today's date plus 90 days to get the correct time. What date do you get? Luigi On Tue, Jan 8, 2013 at 9:12 PM, ray 176 <[hidden email]> wrote: > 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 Call 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 > > > ------------------------------------------------------------------------------ > Master SQL Server Development, Administration, T-SQL, SSAS, SSIS, SSRS > and more. Get SQL Server skills now (including 2012) with LearnDevNow - > 200+ hours of step-by-step video tutorials by Microsoft MVPs and experts. > SALE $99.99 this month only - learn more at: > http://p.sf.net/sfu/learnmore_122512 > _______________________________________________ > QuantLib-dev mailing list > [hidden email] > https://lists.sourceforge.net/lists/listinfo/quantlib-dev > ------------------------------------------------------------------------------ Master SQL Server Development, Administration, T-SQL, SSAS, SSIS, SSRS and more. Get SQL Server skills now (including 2012) with LearnDevNow - 200+ hours of step-by-step video tutorials by Microsoft MVPs and experts. SALE $99.99 this month only - learn more at: http://p.sf.net/sfu/learnmore_122512 _______________________________________________ QuantLib-dev mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/quantlib-dev |
Here's the transcript of my Python session.
Python 2.7.3 (default, Sep 26 2012, 21:53:58) [GCC 4.7.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> from QuantLib import * >>> >>> today = Date.todaysDate() >>> >>> spot = SimpleQuote(100.0) >>> q = SimpleQuote(0.0) >>> r = SimpleQuote(0.1) >>> vol = SimpleQuote(0.5) >>> >>> dc = Actual360() >>> rTS = FlatForward(today, QuoteHandle(r), dc) >>> qTS = FlatForward(today, QuoteHandle(q), dc) >>> volTS = BlackConstantVol(today, NullCalendar(), QuoteHandle(vol), dc) >>> >>> process = BlackScholesMertonProcess( ... YieldTermStructureHandle(qTS), ... YieldTermStructureHandle(rTS), ... BlackVolTermStructureHandle(volTS)) >>> >>> exerciseDate = today+90 >>> exercise = EuropeanExercise(exerciseDate) >>> >>> payoff = PlainVanillaPayoff(Option.Call, 97.0) >>> >>> option = EuropeanOption(payoff, exercise) >>> engine = AnalyticEuropeanEngine(process) >>> option.setPricingEngine(engine) >>> >>> option.NPV() >>> On Wed, Jan 9, 2013 at 6:13 AM, ray 176 <[hidden email]> wrote: > Can you post me your code. > > I still can't get it to give a valid results > DayCounter is Actual360 and today date is used for yield term structure as > per below. > > > QuantLib::DayCounter dc = QuantLib::Actual360(); > QuantLib::Date today = QuantLib::Date::todaysDate(); > > boost::shared_ptr<QuantLib::YieldTermStructure> rTS = flatRate(today, rRate, > dc); > > 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)); > } > > > > On 9 January 2013 00:47, Luigi Ballabio <[hidden email]> wrote: >> >> tried the thing in QuantLib via Pyt > > > ------------------------------------------------------------------------------ Master Java SE, Java EE, Eclipse, Spring, Hibernate, JavaScript, jQuery and much more. Keep your Java skills current with LearnJavaNow - 200+ hours of step-by-step video tutorials by Java experts. SALE $49.99 this month only -- learn more at: http://p.sf.net/sfu/learnmore_122612 _______________________________________________ QuantLib-dev mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/quantlib-dev |
Free forum by Nabble | Edit this page |