Re: forward rates calculated dont match

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Re: forward rates calculated dont match

Luigi Ballabio

Hi,
        may you retrieve from the curve the discount factors at the relevant
dates and see whether they're the ones you expect?

Luigi


On Thu, 2011-07-14 at 05:19 -0700, d0tc0mguy wrote:

> Hi,
>
> I was trying to code various examples in John C Hull "Options, futures and
> other derivatives".
>
> While calculating the forward rates from zero rates. I see a discrepancy in
> the values
>
> The program calculates the forward rates and prints
> 5.199103%
> 5.801799%
> 6.200000%
> 6.500000%
>
> the values i am expecting are ( as per the john hull textbook)
> 5.0%
> 5.8%
> 6.2%
> 6.5%
>
> Am I doing something wrong in the code ?
>
>
> The Program follows:
>
> #include <ql/quantlib.hpp>
> #include <boost/timer.hpp>
> #include <iostream>
>
> using namespace std;
> using namespace QuantLib;
>
> #if defined(QL_ENABLE_SESSIONS)
> namespace QuantLib {
>
>     Integer sessionId() { return 0; }
>
> }
> #endif
>
> int main(int, char* []) {
>
>     try {
>
>         boost::timer timer;
>         std::cout << std::endl;
>
>
>         RelinkableHandle<YieldTermStructure> euriborTermStructure;
>
>
>         Date todaysDate = Date(15, June, 2001);
>         Settings::instance().evaluationDate() = todaysDate;
>
> Calendar calendar = NullCalendar();
>
>         Date settlementDate = calendar.advance(todaysDate, 0, Days);
>
>         std::cout << "Today: " << todaysDate.weekday()
>                   << ", " << todaysDate << std::endl;
>
>         std::cout << "Settlement date: " << settlementDate.weekday()
>                   << ", " << settlementDate << std::endl;
>
>        DayCounter termStructureDayCounter = ActualActual();
>
>
>         double tolerance = 1.0e-15;
>
> std::vector<Date> ircdates;
>     std::vector<Rate> ircrates;
>    
> Date settlement = settlementDate;
>         Date Date1 = calendar.advance(settlement, 12, Months); //13
>         Date Date2 = calendar.advance(settlement, 24, Months); //14
>         Date Date3 = calendar.advance(settlement, 36, Months); //14
> Date Date4 = calendar.advance(settlement, 48, Months); //14
> Date Date5 = calendar.advance(settlement, 60, Months); //14
>
>
> ircdates.push_back(Date1); ircrates.push_back(0.03);
>     ircdates.push_back(Date2); ircrates.push_back(0.04);
>     ircdates.push_back(Date3); ircrates.push_back(0.046);
>     ircdates.push_back(Date4); ircrates.push_back(0.05);
> ircdates.push_back(Date5); ircrates.push_back(0.053);
>
>    
> boost::shared_ptr<YieldTermStructure> ForecastingTermStructure(
>                                     new ZeroCurve(ircdates,
> ircrates,termStructureDayCounter));
>
> boost::shared_ptr<IborIndex> index(new IborIndex("IRC",
>                                                    Period(Daily),
>                                                    0,
>                                                    USDCurrency(),
>                                                    calendar,
>                                                    Unadjusted,
>                                                    true,
>                                                    termStructureDayCounter,
>   euriborTermStructure));
> euriborTermStructure.linkTo(ForecastingTermStructure);
> euriborTermStructure->enableExtrapolation();
>
> std::cout<<"2
> :"<<euriborTermStructure->forwardRate(Date2,Period(Annual),termStructureDayCounter,
> Continuous) << std::endl;
> std::cout<<"3 :"<<
> euriborTermStructure->forwardRate(Date3,Period(Annual),termStructureDayCounter,
> Continuous) << std::endl;
> std::cout<<"4 :"<<
> euriborTermStructure->forwardRate(Date4,Period(Annual),termStructureDayCounter,
> Continuous) << std::endl;
> std::cout<<"5 :"<<
> euriborTermStructure->forwardRate(Date5,Period(Annual),termStructureDayCounter,
> Continuous) << std::endl;
>         return 0;
>
>     } catch (exception& e) {
>         cerr << e.what() << endl;
>         return 1;
>     } catch (...) {
>         cerr << "unknown error" << endl;
>         return 1;
>     }
> }
>
>
>
> Thanks,
> d0tc0mguy
>  
> --
> View this message in context: http://old.nabble.com/forward-rates-calculated-dont-match-tp32060733p32060733.html
> Sent from the quantlib-users mailing list archive at Nabble.com.
>
>
> ------------------------------------------------------------------------------
> AppSumo Presents a FREE Video for the SourceForge Community by Eric
> Ries, the creator of the Lean Startup Methodology on "Lean Startup
> Secrets Revealed." This video shows you how to validate your ideas,
> optimize your ideas and identify your business strategy.
> http://p.sf.net/sfu/appsumosfdev2dev
> _______________________________________________
> QuantLib-users mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/quantlib-users

--

All generalizations are false, including this one.
-- Mark Twain



------------------------------------------------------------------------------
AppSumo Presents a FREE Video for the SourceForge Community by Eric
Ries, the creator of the Lean Startup Methodology on "Lean Startup
Secrets Revealed." This video shows you how to validate your ideas,
optimize your ideas and identify your business strategy.
http://p.sf.net/sfu/appsumosfdev2dev
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users
Reply | Threaded
Open this post in threaded view
|

Re: forward rates calculated dont match

Dexter Moser
d0tc0mguy,

 while working through your code, i think the results of the code are the 
 5.199103% - 2 yr forward rate on a 1 yr bond
 5.801799% - 3 yr forward rate on a 1 yr bond 
 6.200000% - 4yr forward rate on a 1 yr bond
 6.500000% - 5yr forward rate on a 1 yr bond

as opposed to the John C hull book results:

5.0% - 1 yr forward rate on a 1 yr bond
5.8% - 2 yr forward rate on a 1 yr bond
6.2% - 3 yr forward rate on a 1 yr bond
6.5% - 4yr forward rate on a 1 yr bond


This you can observe from the another function definition of the forward rate:

forwardRate (const Date &d1, const Date &d2, const DayCounter &resultDayCounter, Compounding comp,Frequency freq=Annual, bool extrapolate=false) const

when i try to find out the 1 yr forward rate on a 1yr bond with the above function definition,  i see that the Date1, Date 2 are taken as the same date!!! and it gives me spot rate at year 1.


i am still working to find out the reason, but let me know what you think about it!!!!


Thanks,

dmoser

 









On Fri, Jul 15, 2011 at 8:12 AM, Luigi Ballabio <[hidden email]> wrote:

Hi,
       may you retrieve from the curve the discount factors at the relevant
dates and see whether they're the ones you expect?

Luigi


On Thu, 2011-07-14 at 05:19 -0700, d0tc0mguy wrote:
> Hi,
>
> I was trying to code various examples in John C Hull "Options, futures and
> other derivatives".
>
> While calculating the forward rates from zero rates. I see a discrepancy in
> the values
>
> The program calculates the forward rates and prints
> 5.199103%
> 5.801799%
> 6.200000%
> 6.500000%
>
> the values i am expecting are ( as per the john hull textbook)
> 5.0%
> 5.8%
> 6.2%
> 6.5%
>
> Am I doing something wrong in the code ?
>
>
> The Program follows:
>
> #include <ql/quantlib.hpp>
> #include <boost/timer.hpp>
> #include <iostream>
>
> using namespace std;
> using namespace QuantLib;
>
> #if defined(QL_ENABLE_SESSIONS)
> namespace QuantLib {
>
>     Integer sessionId() { return 0; }
>
> }
> #endif
>
> int main(int, char* []) {
>
>     try {
>
>         boost::timer timer;
>         std::cout << std::endl;
>
>
>         RelinkableHandle<YieldTermStructure> euriborTermStructure;
>
>
>         Date todaysDate = Date(15, June, 2001);
>         Settings::instance().evaluationDate() = todaysDate;
>
>               Calendar calendar = NullCalendar();
>
>         Date settlementDate = calendar.advance(todaysDate, 0, Days);
>
>         std::cout << "Today: " << todaysDate.weekday()
>                   << ", " << todaysDate << std::endl;
>
>         std::cout << "Settlement date: " << settlementDate.weekday()
>                   << ", " << settlementDate << std::endl;
>
>                       DayCounter termStructureDayCounter = ActualActual();
>
>
>         double tolerance = 1.0e-15;
>
>       std::vector<Date> ircdates;
>     std::vector<Rate> ircrates;
>
>               Date settlement = settlementDate;
>         Date Date1 = calendar.advance(settlement, 12, Months); //13
>         Date Date2 = calendar.advance(settlement, 24, Months); //14
>         Date Date3 = calendar.advance(settlement, 36, Months); //14
>               Date Date4 = calendar.advance(settlement, 48, Months); //14
>               Date Date5 = calendar.advance(settlement, 60, Months); //14
>
>
>       ircdates.push_back(Date1); ircrates.push_back(0.03);
>     ircdates.push_back(Date2); ircrates.push_back(0.04);
>     ircdates.push_back(Date3); ircrates.push_back(0.046);
>     ircdates.push_back(Date4); ircrates.push_back(0.05);
>       ircdates.push_back(Date5); ircrates.push_back(0.053);
>
>
>       boost::shared_ptr<YieldTermStructure> ForecastingTermStructure(
>                                     new ZeroCurve(ircdates,
> ircrates,termStructureDayCounter));
>
>       boost::shared_ptr<IborIndex> index(new IborIndex("IRC",
>                                                    Period(Daily),
>                                                    0,
>                                                    USDCurrency(),
>                                                    calendar,
>                                                    Unadjusted,
>                                                    true,
>                                                    termStructureDayCounter,
>                                                                                                  euriborTermStructure));
>               euriborTermStructure.linkTo(ForecastingTermStructure);
>               euriborTermStructure->enableExtrapolation();
>
>               std::cout<<"2
> :"<<euriborTermStructure->forwardRate(Date2,Period(Annual),termStructureDayCounter,
>                                                                                       Continuous) << std::endl;
>               std::cout<<"3 :"<<
> euriborTermStructure->forwardRate(Date3,Period(Annual),termStructureDayCounter,
>                                                                                       Continuous) << std::endl;
>               std::cout<<"4 :"<<
> euriborTermStructure->forwardRate(Date4,Period(Annual),termStructureDayCounter,
>                                                                                       Continuous) << std::endl;
>               std::cout<<"5 :"<<
> euriborTermStructure->forwardRate(Date5,Period(Annual),termStructureDayCounter,
>                                                                                       Continuous) << std::endl;
>         return 0;
>
>     } catch (exception& e) {
>         cerr << e.what() << endl;
>         return 1;
>     } catch (...) {
>         cerr << "unknown error" << endl;
>         return 1;
>     }
> }
>
>
>
> Thanks,
> d0tc0mguy
>
> --
> View this message in context: http://old.nabble.com/forward-rates-calculated-dont-match-tp32060733p32060733.html
> Sent from the quantlib-users mailing list archive at Nabble.com.
>
>
> ------------------------------------------------------------------------------
> AppSumo Presents a FREE Video for the SourceForge Community by Eric
> Ries, the creator of the Lean Startup Methodology on "Lean Startup
> Secrets Revealed." This video shows you how to validate your ideas,
> optimize your ideas and identify your business strategy.
> http://p.sf.net/sfu/appsumosfdev2dev
> _______________________________________________
> QuantLib-users mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/quantlib-users

--

All generalizations are false, including this one.
-- Mark Twain



------------------------------------------------------------------------------
AppSumo Presents a FREE Video for the SourceForge Community by Eric
Ries, the creator of the Lean Startup Methodology on "Lean Startup
Secrets Revealed." This video shows you how to validate your ideas,
optimize your ideas and identify your business strategy.
http://p.sf.net/sfu/appsumosfdev2dev
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users


------------------------------------------------------------------------------
10 Tips for Better Web Security
Learn 10 ways to better secure your business today. Topics covered include:
Web security, SSL, hacker attacks & Denial of Service (DoS), private keys,
security Microsoft Exchange, secure Instant Messaging, and much more.
http://www.accelacomm.com/jaw/sfnl/114/51426210/
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users