Posted by
John Maiden on
URL: http://quantlib.414.s1.nabble.com/how-to-get-discretely-compounded-zero-rates-tp1090p1092.html
I'm working on creating a yield curve myself, and had a problem
just copying and pasting the code from CompoundForward.cpp in the
test suite. If this is what you did, then when you are loading
the rates and dates vectors, use pushback, i.e.
Size i;
for (i=0; i<deposits; i++) {
rates.push_back(depositData[i].rate/100);
dates.push_back(calendar.advance(settlement,
Period(depositData[i].n,
depositData[i].units),
convention));
}
Hopefully this was your problem.
I'm new to calculating yield curves, and am having
trouble calculating the forward rates myself. I tried using the
code below, and couldn't get rates beyond the ones I loaded.
How do you get the program to extrapolate future rates?
struct Datum {
Integer n;
TimeUnit units;
Rate rate;
};
int _tmain(int argc, _TCHAR* argv[])
{
try{
Datum depositData[] = {
{ 3, Months, 4.813194 },
{ 6, Months, 4.914039 },
{ 12, Months, 4.958746 }
};
Calendar calendar;
Natural settlementDays;
Date today, settlement;
BusinessDayConvention convention;
DayCounter dayCounter;
Frequency frequency;
Size deposits;
std::vector<Rate> rates;
std::vector<Date> dates;
boost::shared_ptr<CompoundForward> termStructure;
deposits = LENGTH(depositData);
calendar = UnitedStates();
settlementDays = 0;
today = calendar.adjust(Date::todaysDate());
Settings::instance().evaluationDate() = today;
settlement = calendar.advance(today,settlementDays,Days);
convention = ModifiedFollowing;
dayCounter = Actual365Fixed();
frequency = Semiannual;
Size i;
for (i=0; i<deposits; i++) {
rates.push_back(depositData[i].rate/100);
dates.push_back(calendar.advance(settlement,
Period(depositData[i].n,
depositData[i].units),
convention));
}
termStructure = boost::shared_ptr<CompoundForward>(
new CompoundForward(settlement,dates,rates,
calendar,convention,
frequency,dayCounter));
Date tty = calendar.advance(today, 18, Months, convention);
cout << termStructure->forwardRate(today, tty, dayCounter, Continuous,
frequency) << endl;
} catch (std::exception& e) {
cout << e.what() << endl;
}
system("PAUSE");
return 0;
}
-------------------------------------------------------------------------
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