Re: forward rates calculated dont match

Posted by Luigi Ballabio on
URL: http://quantlib.414.s1.nabble.com/Re-forward-rates-calculated-dont-match-tp889.html


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