DepositRateHelper Inconsistency

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

DepositRateHelper Inconsistency

mudcrab
Hi again,

I am trying to set the stub rate (connecting the deposits and futures
portion of my yield curve) and am experiencing an inconsistency with the
DepositRateHelper class.

My method of setting the stub rate is to
a) find the number of business days between the settlement date and the
   immDate via

Integer daysToIMMdate = calendar.businessDaysBetween(settlement,imm);

b) construct an associated DepositRateHelper using a period of
   daysToIMMdate*Days

So far this works perfectly except in the case where daysToIMMDate equals
the number of days in the current month.  Please see some example code at
the end of this email (based on piecewiseyieldcurve.cpp in the test
suite).  The output from it should be as follows:


  Settlement Date is February 5th, 2009
  1 Weeks from then is: February 12th, 2009
  1 Months from then is: March 5th, 2009
  29 (business) Days from then is:        March 18th, 2009

  Settlement Date is February 6th, 2009
  1 Weeks from then is: February 13th, 2009
  1 Months from then is: March 6th, 2009
  28 (business) Days from then is:        March 6th, 2009


Basically, the DepositRateHelper interprets the 28 days as a monthly rate
and, of course, the yield curve bootstrapping crashes.

Can someone suggest a fix or an alternative approach?

Many thanks,

- Troy

------------------- EXAMPLE CODE -------------------

#include <ql/quantlib.hpp>
#include <boost/timer.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/config.hpp>
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
#include <vector>
#include <ql/time/imm.hpp>
#include <ql/math/interpolations/linearinterpolation.hpp>
#define LENGTH(a) (sizeof(a)/sizeof(a[0]))

using namespace QuantLib;
using namespace std;


struct Datum {
        Integer n;
        TimeUnit units;
        Rate rate;
};


struct CommonVars2 {
       // global variables
        Calendar calendar;
        Natural settlementDays;
        Date settlement;

        Size deposits;
        std::vector<boost::shared_ptr<SimpleQuote> > rates;
        std::vector<boost::shared_ptr<RateHelper> > instruments;
        std::vector<Schedule> schedules;
        boost::shared_ptr<YieldTermStructure> termStructure;

        // cleanup
        SavedSettings backup;

        // setup
        CommonVars2(Date today) {
                // data
                        Datum depositData[] = {
                                { 1, Weeks,  4.559 },
                                { 1, Months, 4.581 }
                        };

                        calendar = UnitedKingdom();
                        settlementDays = 0;
                        Settings::instance().evaluationDate() = today;
                        settlement = calendar.advance(today,settlementDays,Days);

                        deposits = LENGTH(depositData)+1;

        // market elements
                        rates = std::vector<boost::shared_ptr<SimpleQuote> >(deposits);
                        for (Size i=0; i<deposits-1; i++) {
                                rates[i] = boost::shared_ptr<SimpleQuote>(
                                    new
SimpleQuote(depositData[i].rate/100));
                        }

                        Rate stubRate = 3.0;
                        for (Size i=0; i<deposits-1; i++) {
                                rates[i] = boost::shared_ptr<SimpleQuote>(
                                    new
SimpleQuote(depositData[i].rate/100));
                        }

                        // rate helpers
                        instruments = std::vector<boost::shared_ptr<RateHelper> >(deposits);

                         boost::shared_ptr<IborIndex> LIBORIndex(new GBPLibor(Period(3,Months)));
                        for (Size i=0; i<deposits-1; i++) {
                Handle<Quote> r(rates[i]);
                instruments[i] = boost::shared_ptr<RateHelper>(new
                    DepositRateHelper(r,
depositData[i].n*depositData[i].units,
                                      LIBORIndex->fixingDays(), calendar,
                                      LIBORIndex->businessDayConvention(),
                                      LIBORIndex->endOfMonth(),
                                      LIBORIndex->dayCounter()));
                        }
                        Date imm = IMM::nextDate(settlement);
                        Integer daysToIMMdate = calendar.businessDaysBetween(settlement,imm);
                        Handle<Quote> r(rates[deposits-1]);
                                instruments[deposits-1] = boost::shared_ptr<RateHelper>(new
                    DepositRateHelper(r, daysToIMMdate*Days,
                                                                          LIBORIndex->fixingDays(), calendar,
                                      LIBORIndex->businessDayConvention(),
                                      LIBORIndex->endOfMonth(),
                                      LIBORIndex->dayCounter()));
                        cout << "Settlement Date is " << settlement << endl;
                        for (Size j=0;j<instruments.size()-1;j++)
                                cout << depositData[j].n << " "
                                        << depositData[j].units << " from then is: \t\t\t"
                                        << instruments[j]->latestDate() << endl;
                                Size j = instruments.size()-1;
                                cout << daysToIMMdate << " (business) "
                                         << Days << " from then is: \t"
                                        << instruments[j]->latestDate() << endl;
                }

};


int main(){
        CommonVars2 vars2(Date(5,February,2009));
        cout << endl;
        CommonVars2 vars3(Date(6,February,2009));
        return 0;
}



------------------------------------------------------------------------------
Come build with us! The BlackBerry&reg; Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9&#45;12, 2009. Register now&#33;
http://p.sf.net/sfu/devconf
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users
Reply | Threaded
Open this post in threaded view
|

Re: DepositRateHelper Inconsistency

mudcrab
Unsurprisingly, there was no inconsistency at all -- the 'problem'
concerned just my limited understanding of the interestrateindex class.

As perhaps you all know, the normalize() function in the Period class
changes any multiple of 7 days into the corresponding number of weeks.  I
found this to be problematic in the setting of my stub rate via the
DepositRateHelper class.

Do you think a case could be made for a StubRateHelper class for
connecting the deposits and futures portions of the curve in yield curve
bootstapping?  If so, we would want to avoid using the tenor_.normalize()
function in the instantiation of the interestratehelper class.

Has anyone else came across this issue and/or thought about this at all?

Thanks,

- Troy

> Hi again,
>
> I am trying to set the stub rate (connecting the deposits and futures
> portion of my yield curve) and am experiencing an inconsistency with the
> DepositRateHelper class.
>
> My method of setting the stub rate is to
> a) find the number of business days between the settlement date and the
>    immDate via
>
> Integer daysToIMMdate = calendar.businessDaysBetween(settlement,imm);
>
> b) construct an associated DepositRateHelper using a period of
>    daysToIMMdate*Days
>
> So far this works perfectly except in the case where daysToIMMDate equals
> the number of days in the current month.  Please see some example code at
> the end of this email (based on piecewiseyieldcurve.cpp in the test
> suite).  The output from it should be as follows:
>
>
>   Settlement Date is February 5th, 2009
>   1 Weeks from then is: February 12th, 2009
>   1 Months from then is: March 5th, 2009
>   29 (business) Days from then is:        March 18th, 2009
>
>   Settlement Date is February 6th, 2009
>   1 Weeks from then is: February 13th, 2009
>   1 Months from then is: March 6th, 2009
>   28 (business) Days from then is:        March 6th, 2009
>
>
> Basically, the DepositRateHelper interprets the 28 days as a monthly rate
> and, of course, the yield curve bootstrapping crashes.
>
> Can someone suggest a fix or an alternative approach?
>
> Many thanks,
>
> - Troy
>
> ------------------- EXAMPLE CODE -------------------
>
> #include <ql/quantlib.hpp>
> #include <boost/timer.hpp>
> #include <boost/shared_ptr.hpp>
> #include <boost/config.hpp>
> #include <iostream>
> #include <iomanip>
> #include <fstream>
> #include <string>
> #include <vector>
> #include <ql/time/imm.hpp>
> #include <ql/math/interpolations/linearinterpolation.hpp>
> #define LENGTH(a) (sizeof(a)/sizeof(a[0]))
>
> using namespace QuantLib;
> using namespace std;
>
>
> struct Datum {
>         Integer n;
>         TimeUnit units;
>         Rate rate;
> };
>
>
> struct CommonVars2 {
>        // global variables
>         Calendar calendar;
>         Natural settlementDays;
>         Date settlement;
>
>         Size deposits;
>         std::vector<boost::shared_ptr<SimpleQuote> > rates;
>         std::vector<boost::shared_ptr<RateHelper> > instruments;
>         std::vector<Schedule> schedules;
>         boost::shared_ptr<YieldTermStructure> termStructure;
>
>         // cleanup
>         SavedSettings backup;
>
>         // setup
>         CommonVars2(Date today) {
> // data
> Datum depositData[] = {
> { 1, Weeks,  4.559 },
> { 1, Months, 4.581 }
> };
>
> calendar = UnitedKingdom();
> settlementDays = 0;
> Settings::instance().evaluationDate() = today;
> settlement = calendar.advance(today,settlementDays,Days);
>
> deposits = LENGTH(depositData)+1;
>
>         // market elements
> rates = std::vector<boost::shared_ptr<SimpleQuote> >(deposits);
> for (Size i=0; i<deposits-1; i++) {
> rates[i] = boost::shared_ptr<SimpleQuote>(
>                                     new
> SimpleQuote(depositData[i].rate/100));
> }
>
> Rate stubRate = 3.0;
> for (Size i=0; i<deposits-1; i++) {
> rates[i] = boost::shared_ptr<SimpleQuote>(
>                                     new
> SimpleQuote(depositData[i].rate/100));
> }
>
> // rate helpers
> instruments = std::vector<boost::shared_ptr<RateHelper> >(deposits);
>
> boost::shared_ptr<IborIndex> LIBORIndex(new
> GBPLibor(Period(3,Months)));
> for (Size i=0; i<deposits-1; i++) {
>                 Handle<Quote> r(rates[i]);
>                 instruments[i] = boost::shared_ptr<RateHelper>(new
>                     DepositRateHelper(r,
> depositData[i].n*depositData[i].units,
>                                       LIBORIndex->fixingDays(), calendar,
>                                       LIBORIndex->businessDayConvention(),
>                                       LIBORIndex->endOfMonth(),
>                                       LIBORIndex->dayCounter()));
> }
> Date imm = IMM::nextDate(settlement);
> Integer daysToIMMdate = calendar.businessDaysBetween(settlement,imm);
> Handle<Quote> r(rates[deposits-1]);
> instruments[deposits-1] = boost::shared_ptr<RateHelper>(new
>                     DepositRateHelper(r, daysToIMMdate*Days,
>  LIBORIndex->fixingDays(), calendar,
>                                       LIBORIndex->businessDayConvention(),
>                                       LIBORIndex->endOfMonth(),
>                                       LIBORIndex->dayCounter()));
> cout << "Settlement Date is " << settlement << endl;
> for (Size j=0;j<instruments.size()-1;j++)
> cout << depositData[j].n << " "
> << depositData[j].units << " from then is: \t\t\t"
> << instruments[j]->latestDate() << endl;
> Size j = instruments.size()-1;
> cout << daysToIMMdate << " (business) "
> << Days << " from then is: \t"
> << instruments[j]->latestDate() << endl;
> }
>
> };
>
>
> int main(){
> CommonVars2 vars2(Date(5,February,2009));
> cout << endl;
> CommonVars2 vars3(Date(6,February,2009));
> return 0;
> }
>
>



------------------------------------------------------------------------------
Come build with us! The BlackBerry&reg; Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9&#45;12, 2009. Register now&#33;
http://p.sf.net/sfu/devconf
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users
Reply | Threaded
Open this post in threaded view
|

Re: DepositRateHelper Inconsistency

Luigi Ballabio
On Fri, 2009-09-18 at 18:03 -0700, [hidden email] wrote:
> As perhaps you all know, the normalize() function in the Period class
> changes any multiple of 7 days into the corresponding number of weeks.

Does it now? Hmm. We should have some way to distinguish between
calendar days and business days. We'll have to think about it in some
future release...

Luigi


--

Hanlon's Razor:
Never attribute to malice that which is adequately explained
by stupidity.



------------------------------------------------------------------------------
Come build with us! The BlackBerry&reg; Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9&#45;12, 2009. Register now&#33;
http://p.sf.net/sfu/devconf
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users