Posted by
jing lu on
URL: http://quantlib.414.s1.nabble.com/use-DepositRateHelper-to-build-a-termstructure-tp1034.html
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