Posted by
mudcrab on
URL: http://quantlib.414.s1.nabble.com/DepositRateHelper-Inconsistency-tp7991.html
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® 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-12, 2009. Register now!
http://p.sf.net/sfu/devconf_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users