Hello All, I am new to Quantlib community and I am trying to build a theoretical zero curve using spot(deposite) rates just like what is done in termstructure.cpp under test-suite/ Here is my code. However the output zero rates are not the exact numbers as I set (0.03,0.04...) Are the deposite rates I set up the same as zero rates for today? Could anyone help to solve the inconsistency. Thanks a lot Jing int main(int, char* []) { Calendar calendar = NullCalendar(); Date settlementDate(1, January, 2004); settlementDate = calendar.adjust(settlementDate); Integer fixingDays = 0; Date todaysDate = calendar.advance(settlementDate, -fixingDays, Days); Settings::instance().evaluationDate() = todaysDate; // deposits Rate d1yQuote=0.03; Rate d2yQuote=0.04; Rate d3yQuote=0.046; Rate d4yQuote=0.05; Rate d5yQuote=0.053; boost::shared_ptr<Quote> d1yRate(new SimpleQuote(d1yQuote)); boost::shared_ptr<Quote> d2yRate(new SimpleQuote(d2yQuote)); boost::shared_ptr<Quote> d3yRate(new SimpleQuote(d3yQuote)); boost::shared_ptr<Quote> d4yRate(new SimpleQuote(d4yQuote)); boost::shared_ptr<Quote> d5yRate(new SimpleQuote(d5yQuote)); DayCounter depositDayCounter = SimpleDayCounter() ; boost::shared_ptr<RateHelper> d1y(new DepositRateHelper( Handle<Quote>(d1yRate), 1*Years, fixingDays, calendar, Unadjusted, false, fixingDays, depositDayCounter)); boost::shared_ptr<RateHelper> d2y(new DepositRateHelper( Handle<Quote>(d2yRate), 2*Years, fixingDays, calendar, Unadjusted, false, fixingDays, depositDayCounter)); boost::shared_ptr<RateHelper> d3y(new DepositRateHelper( Handle<Quote>(d3yRate), 3*Years, fixingDays, calendar, Unadjusted, false, fixingDays, depositDayCounter)); boost::shared_ptr<RateHelper> d4y(new DepositRateHelper( Handle<Quote>(d4yRate), 4*Years, fixingDays, calendar, Unadjusted, false, fixingDays, depositDayCounter)); boost::shared_ptr<RateHelper> d5y(new DepositRateHelper( Handle<Quote>(d5yRate), 5*Years, fixingDays, calendar, Unadjusted, false, fixingDays, depositDayCounter)); double tolerance = 1.0e-15; DayCounter termStructureDayCounter = SimpleDayCounter() ; // A depo curve std::vector<boost::shared_ptr<RateHelper> > depoInstruments; depoInstruments.push_back(d1y); depoInstruments.push_back(d2y); depoInstruments.push_back(d3y); depoInstruments.push_back(d4y); depoInstruments.push_back(d5y); boost::shared_ptr<YieldTermStructure> depoTermStructure (new PiecewiseYieldCurve<ZeroYield,Linear>(settlementDate, depoInstruments,termStructureDayCounter, tolerance)); Date testDate1 = depoTermStructure->referenceDate()+ 1*Years; DayCounter rfdc = depoTermStructure->dayCounter(); Rate zero1 = depoTermStructure->zeroRate(testDate1, rfdc,Continuous, NoFrequency); std::cout <<"1-year zero rate now:"<<zero1<< std::endl; Date testDate2 = depoTermStructure->referenceDate()+ 2*Years; Rate zero2 = depoTermStructure->zeroRate(testDate2, rfdc,Continuous, NoFrequency); std::cout <<"2-year zero rate now:"<<zero2<< std::endl; Date testDate3 = depoTermStructure->referenceDate()+ 3*Years; Rate zero3 = depoTermStructure->zeroRate(testDate3, rfdc,Continuous, NoFrequency); std::cout <<"3-year zero rate now:"<<zero3<< std::endl; }
Choose the right car based on your needs. Check out Yahoo! Autos new Car Finder tool. ------------------------------------------------------------------------- This SF.net email is sponsored by DB2 Express Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now. http://sourceforge.net/powerbar/db2/ _______________________________________________ QuantLib-users mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/quantlib-users |
Hi Jing,
Dposit rate and zero rates are not the same thing. Also, you requested continously compounded zero rates in your example. Deposit rates are not normally compounded continously. As a rough guide, PiecewiseYieldCurve<ZeroYield,Linear> object really means that internally, zero rates will be constructed (aided via an internal solver to solve for an appropriate zero rate) such that when one queries for the same DEPOSIT rates entered into the yieldcurve constructor, the constructed zero rates, are able to generate the correct discount factors needed to recreate the deposit rate. In a nutshell, specifying <ZeroYield,Linear> means that the deposit rates (or any other market rates for that matter) will be converted to Zero rates internally and it is these rates that will be manipulated (linearly interpolated) when any request is asked of the yieldcurve. If you want to enter zero rates, then you must use one of the ZeroCurve yield termstructure objects. Hope that helps... Toyin Akin, www.QuantTools.com >From: jing lu <[hidden email]> >To: [hidden email] >Subject: [Quantlib-users] use DepositRateHelper to build a termstructure >Date: Sat, 16 Jun 2007 19:51:39 -0700 (PDT) > >Hello All, > > I am new to Quantlib community and I am trying to build a theoretical >zero curve using spot(deposite) rates just like what is done in >termstructure.cpp under test-suite/ Here is my code. However the output >zero rates are not the exact numbers as I set (0.03,0.04...) > Are the deposite rates I set up the same as zero rates for today? Could >anyone help to > solve the inconsistency. > > Thanks a lot > > Jing > > int main(int, char* []) >{ > Calendar calendar = NullCalendar(); > Date settlementDate(1, January, 2004); > settlementDate = calendar.adjust(settlementDate); > Integer fixingDays = 0; > Date todaysDate = calendar.advance(settlementDate, -fixingDays, >Days); > > Settings::instance().evaluationDate() = todaysDate; > // deposits > Rate d1yQuote=0.03; > Rate d2yQuote=0.04; > Rate d3yQuote=0.046; > Rate d4yQuote=0.05; > Rate d5yQuote=0.053; > boost::shared_ptr<Quote> d1yRate(new SimpleQuote(d1yQuote)); > boost::shared_ptr<Quote> d2yRate(new SimpleQuote(d2yQuote)); > boost::shared_ptr<Quote> d3yRate(new SimpleQuote(d3yQuote)); > boost::shared_ptr<Quote> d4yRate(new SimpleQuote(d4yQuote)); > boost::shared_ptr<Quote> d5yRate(new SimpleQuote(d5yQuote)); > > DayCounter depositDayCounter = SimpleDayCounter() ; > boost::shared_ptr<RateHelper> d1y(new DepositRateHelper( > Handle<Quote>(d1yRate), > 1*Years, fixingDays, > calendar, Unadjusted, > false, fixingDays, depositDayCounter)); > > boost::shared_ptr<RateHelper> d2y(new DepositRateHelper( > Handle<Quote>(d2yRate), > 2*Years, fixingDays, > calendar, Unadjusted, > false, fixingDays, depositDayCounter)); > boost::shared_ptr<RateHelper> d3y(new DepositRateHelper( > Handle<Quote>(d3yRate), > 3*Years, fixingDays, > calendar, Unadjusted, > false, fixingDays, depositDayCounter)); > boost::shared_ptr<RateHelper> d4y(new DepositRateHelper( > Handle<Quote>(d4yRate), > 4*Years, fixingDays, > calendar, Unadjusted, > false, fixingDays, depositDayCounter)); > boost::shared_ptr<RateHelper> d5y(new DepositRateHelper( > Handle<Quote>(d5yRate), > 5*Years, fixingDays, > calendar, Unadjusted, > false, fixingDays, depositDayCounter)); > > > double tolerance = 1.0e-15; > DayCounter termStructureDayCounter = SimpleDayCounter() ; > > // A depo curve > std::vector<boost::shared_ptr<RateHelper> > depoInstruments; > > depoInstruments.push_back(d1y); > depoInstruments.push_back(d2y); > depoInstruments.push_back(d3y); > depoInstruments.push_back(d4y); > depoInstruments.push_back(d5y); > > boost::shared_ptr<YieldTermStructure> depoTermStructure (new >PiecewiseYieldCurve<ZeroYield,Linear>(settlementDate, >depoInstruments,termStructureDayCounter, tolerance)); > > Date testDate1 = depoTermStructure->referenceDate()+ 1*Years; > DayCounter rfdc = depoTermStructure->dayCounter(); > Rate zero1 = depoTermStructure->zeroRate(testDate1, >rfdc,Continuous, NoFrequency); > std::cout <<"1-year zero rate now:"<<zero1<< std::endl; > > Date testDate2 = depoTermStructure->referenceDate()+ 2*Years; > Rate zero2 = depoTermStructure->zeroRate(testDate2, >rfdc,Continuous, NoFrequency); > std::cout <<"2-year zero rate now:"<<zero2<< std::endl; > > Date testDate3 = depoTermStructure->referenceDate()+ 3*Years; > Rate zero3 = depoTermStructure->zeroRate(testDate3, >rfdc,Continuous, NoFrequency); > std::cout <<"3-year zero rate now:"<<zero3<< std::endl; >} > > >--------------------------------- >Choose the right car based on your needs. Check out Yahoo! Autos new Car >Finder tool. >------------------------------------------------------------------------- >This SF.net email is sponsored by DB2 Express >Download DB2 Express C - the FREE version of DB2 express and take >control of your XML. No limits. Just data. Click to get it now. >http://sourceforge.net/powerbar/db2/ >_______________________________________________ >QuantLib-users mailing list >[hidden email] >https://lists.sourceforge.net/lists/listinfo/quantlib-users _________________________________________________________________ The next generation of Hotmail is here! http://www.newhotmail.co.uk ------------------------------------------------------------------------- This SF.net email is sponsored by DB2 Express Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now. http://sourceforge.net/powerbar/db2/ _______________________________________________ QuantLib-users mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/quantlib-users |
On Mon, 2007-06-18 at 14:50 +0100, Toyin Akin wrote:
> Dposit rate and zero rates are not the same thing. True. You can look at the testCurveConsistency function in test-suite/piecewiseyieldcurve.cpp to see how deposit rates can be retrieved. Luigi ---------------------------------------- Ninety percent of everything is crap. --- Theodore Sturgeon ------------------------------------------------------------------------- This SF.net email is sponsored by DB2 Express Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now. http://sourceforge.net/powerbar/db2/ _______________________________________________ QuantLib-users mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/quantlib-users |
Hello Luigi and Toyin,
Thanks for the note. I did get the deposite rates back by creating USDLibor index(tenor,curvehandle) object and then call the fixing(date) method of it. BTW I am not familiar with Unit Test Framework of Boost but I did build the test-suites executable with visual studio 2003. Could you tell me how do I run a specific test in piecewiseyieldcurve.cpp like testCurveConsistency(...) Best, Jing Luigi Ballabio <[hidden email]> wrote: On Mon, 2007-06-18 at 14:50 +0100, Toyin Akin wrote:
Get the Yahoo! toolbar and be alerted to new email wherever you're surfing. ------------------------------------------------------------------------- This SF.net email is sponsored by DB2 Express Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now. http://sourceforge.net/powerbar/db2/ _______________________________________________ QuantLib-users mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/quantlib-users |
On Jun 19, 2007, at 5:03 PM, jing lu wrote: > BTW I am not familiar > with Unit Test Framework of Boost but I did build the test-suites > executable with visual studio 2003. Could you tell me how do I > run a specific test in piecewiseyieldcurve.cpp like > testCurveConsistency(...) You'll have to edit quantlibtestsuite.cpp and comment out any test-suite you don't want to run. Same for piecewiseyieldcurve.cpp---comment out the unwanted test cases at the end. Luigi ------------------------------------------------------------------------- This SF.net email is sponsored by DB2 Express Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now. http://sourceforge.net/powerbar/db2/ _______________________________________________ QuantLib-users mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/quantlib-users |
Free forum by Nabble | Edit this page |