Hello Zhou,
Below is my Eonia yield curve code (using the same paper) . I was in your situation few months ago, I got help from quantlib especially from luigi. Also you can consider the book C# for Financial markets Daniel and andrea (very nice book in curve).
#include <ql/quantlib.hpp>
#include <iostream>
#include <boost/assign/std/vector.hpp>
#include <boost/make_shared.hpp>
#include <iomanip>
using namespace QuantLib;
using namespace boost::assign;
int main(int, char **) {
try {
std::cout << "EONIA curve test ... " << std::endl;
// set evalulation date
//Date evalDate = Date(4, February, 2014); // for the 1st set of data
Date evalDate = Date(11, December, 2012); // for the 2nd set of data
Date settlDate = TARGET().advance(evalDate, 2 * Days);
Settings::instance().evaluationDate() = evalDate;
DayCounter dayCounterOIS = Actual360();
double tolerance = 1.0e-15;
// set up the interest rate curve
// 1st set of data
/*Real eoniaquotes[] = {
0.0013, 0.00156, 0.00163, 0.0016, 0.00163, 0.00147, 0.00139, 0.00131,
0.00125, 0.0012, 0.00117, 0.00114, 0.00112, 0.0011, 0.00111, 0.0011,
0.00111, 0.00117, 0.00127, 0.00143, 0.00264, 0.0045, 0.00656, 0.00866,
0.01065, 0.01247, 0.01411, 0.01558, 0.01687, 0.01799, 0.02051, 0.02238,
0.02302, 0.02322 , 0.02322, 0.02322
};*/
//2nd set of data
Real eoniaquotes[] ={
0.00040, 0.00070, 0.00069, 0.00078, 0.00074, 0.00061, 0.00047, 0.00033,
0.00024, 0.00018, 0.00013, 0.00009, 0.00005, 0.00003, 0.00001, 0.00000,
0.00002, 0.00008, 0.00021, 0.00036, 0.00127, 0.00274, 0.00456, 0.00647,
0.00827, 0.00996, 0.01147, 0.01280, 0.01404, 0.01516, 0.01764, 0.01939,
0.02003, 0.02038, 0.00046, 0.00016, -0.00007, -0.00013, -0.00014,-0.00016};
boost::shared_ptr<RateHelper> rhon = boost::make_shared<DepositRateHelper>(
eoniaquotes[0], 1 * Days, 0, TARGET(), Following, false, Actual360());
boost::shared_ptr<OvernightIndex> eoniaBt = boost::make_shared<Eonia>();
boost::shared_ptr<RateHelper> rhe1w = boost::make_shared<OISRateHelper>(
2, 1 * Weeks,
Handle<Quote>(boost::make_shared<SimpleQuote>(eoniaquotes[1])),
eoniaBt);
boost::shared_ptr<RateHelper> rhe2w = boost::make_shared<OISRateHelper>(
2, 2 * Weeks,
Handle<Quote>(boost::make_shared<SimpleQuote>(eoniaquotes[2])),
eoniaBt);
boost::shared_ptr<RateHelper> rhe3w = boost::make_shared<OISRateHelper>(
2, 3 * Weeks,
Handle<Quote>(boost::make_shared<SimpleQuote>(eoniaquotes[3])),
eoniaBt);
boost::shared_ptr<RateHelper> rhe1m = boost::make_shared<OISRateHelper>(
2, 1 * Months,
Handle<Quote>(boost::make_shared<SimpleQuote>(eoniaquotes[4])),
eoniaBt);
boost::shared_ptr<RateHelper> rhe2m = boost::make_shared<OISRateHelper>(
2, 2 * Months,
Handle<Quote>(boost::make_shared<SimpleQuote>(eoniaquotes[5])),
eoniaBt);
boost::shared_ptr<RateHelper> rhe3m = boost::make_shared<OISRateHelper>(
2, 3 * Months,
Handle<Quote>(boost::make_shared<SimpleQuote>(eoniaquotes[6])),
eoniaBt);
boost::shared_ptr<RateHelper> rhe4m = boost::make_shared<OISRateHelper>(
2, 4 * Months,
Handle<Quote>(boost::make_shared<SimpleQuote>(eoniaquotes[7])),
eoniaBt);
boost::shared_ptr<RateHelper> rhe5m = boost::make_shared<OISRateHelper>(
2, 5 * Months,
Handle<Quote>(boost::make_shared<SimpleQuote>(eoniaquotes[8])),
eoniaBt);
boost::shared_ptr<RateHelper> rhe6m = boost::make_shared<OISRateHelper>(
2, 6 * Months,
Handle<Quote>(boost::make_shared<SimpleQuote>(eoniaquotes[9])),
eoniaBt);
boost::shared_ptr<RateHelper> rhe7m = boost::make_shared<OISRateHelper>(
2, 7 * Months,
Handle<Quote>(boost::make_shared<SimpleQuote>(eoniaquotes[10])),
eoniaBt);
boost::shared_ptr<RateHelper> rhe8m = boost::make_shared<OISRateHelper>(
2, 8 * Months,
Handle<Quote>(boost::make_shared<SimpleQuote>(eoniaquotes[11])),
eoniaBt);
boost::shared_ptr<RateHelper> rhe9m = boost::make_shared<OISRateHelper>(
2, 9 * Months,
Handle<Quote>(boost::make_shared<SimpleQuote>(eoniaquotes[12])),
eoniaBt);
boost::shared_ptr<RateHelper> rhe10m = boost::make_shared<OISRateHelper>(
2, 10 * Months,
Handle<Quote>(boost::make_shared<SimpleQuote>(eoniaquotes[13])),
eoniaBt);
boost::shared_ptr<RateHelper> rhe11m = boost::make_shared<OISRateHelper>(
2, 11 * Months,
Handle<Quote>(boost::make_shared<SimpleQuote>(eoniaquotes[14])),
eoniaBt);
boost::shared_ptr<RateHelper> rhe1y = boost::make_shared<OISRateHelper>(
2, 1 * Years,
Handle<Quote>(boost::make_shared<SimpleQuote>(eoniaquotes[15])),
eoniaBt);
boost::shared_ptr<RateHelper> rhe15m = boost::make_shared<OISRateHelper>(
2, 15 * Months,
Handle<Quote>(boost::make_shared<SimpleQuote>(eoniaquotes[16])),
eoniaBt);
boost::shared_ptr<RateHelper> rhe18m = boost::make_shared<OISRateHelper>(
2, 18 * Months,
Handle<Quote>(boost::make_shared<SimpleQuote>(eoniaquotes[17])),
eoniaBt);
boost::shared_ptr<RateHelper> rhe21m = boost::make_shared<OISRateHelper>(
2, 21 * Months,
Handle<Quote>(boost::make_shared<SimpleQuote>(eoniaquotes[18])),
eoniaBt);
boost::shared_ptr<RateHelper> rhe2y = boost::make_shared<OISRateHelper>(
2, 2 * Years,
Handle<Quote>(boost::make_shared<SimpleQuote>(eoniaquotes[19])),
eoniaBt);
boost::shared_ptr<RateHelper> rhe3y = boost::make_shared<OISRateHelper>(
2, 3 * Years,
Handle<Quote>(boost::make_shared<SimpleQuote>(eoniaquotes[20])),
eoniaBt);
boost::shared_ptr<RateHelper> rhe4y = boost::make_shared<OISRateHelper>(
2, 4 * Years,
Handle<Quote>(boost::make_shared<SimpleQuote>(eoniaquotes[21])),
eoniaBt);
boost::shared_ptr<RateHelper> rhe5y = boost::make_shared<OISRateHelper>(
2, 5 * Years,
Handle<Quote>(boost::make_shared<SimpleQuote>(eoniaquotes[22])),
eoniaBt);
boost::shared_ptr<RateHelper> rhe6y = boost::make_shared<OISRateHelper>(
2, 6 * Years,
Handle<Quote>(boost::make_shared<SimpleQuote>(eoniaquotes[23])),
eoniaBt);
boost::shared_ptr<RateHelper> rhe7y = boost::make_shared<OISRateHelper>(
2, 7 * Years,
Handle<Quote>(boost::make_shared<SimpleQuote>(eoniaquotes[24])),
eoniaBt);
boost::shared_ptr<RateHelper> rhe8y = boost::make_shared<OISRateHelper>(
2, 8 * Years,
Handle<Quote>(boost::make_shared<SimpleQuote>(eoniaquotes[25])),
eoniaBt);
boost::shared_ptr<RateHelper> rhe9y = boost::make_shared<OISRateHelper>(
2, 9 * Years,
Handle<Quote>(boost::make_shared<SimpleQuote>(eoniaquotes[26])),
eoniaBt);
boost::shared_ptr<RateHelper> rhe10y = boost::make_shared<OISRateHelper>(
2, 10 * Years,
Handle<Quote>(boost::make_shared<SimpleQuote>(eoniaquotes[27])),
eoniaBt);
boost::shared_ptr<RateHelper> rhe11y = boost::make_shared<OISRateHelper>(
2, 11 * Years,
Handle<Quote>(boost::make_shared<SimpleQuote>(eoniaquotes[28])),
eoniaBt);
boost::shared_ptr<RateHelper> rhe12y = boost::make_shared<OISRateHelper>(
2, 12 * Years,
Handle<Quote>(boost::make_shared<SimpleQuote>(eoniaquotes[29])),
eoniaBt);
boost::shared_ptr<RateHelper> rhe15y = boost::make_shared<OISRateHelper>(
2, 15 * Years,
Handle<Quote>(boost::make_shared<SimpleQuote>(eoniaquotes[30])),
eoniaBt);
boost::shared_ptr<RateHelper> rhe20y = boost::make_shared<OISRateHelper>(
2, 20 * Years,
Handle<Quote>(boost::make_shared<SimpleQuote>(eoniaquotes[31])),
eoniaBt);
boost::shared_ptr<RateHelper> rhe25y = boost::make_shared<OISRateHelper>(
2, 25 * Years,
Handle<Quote>(boost::make_shared<SimpleQuote>(eoniaquotes[32])),
eoniaBt);
boost::shared_ptr<RateHelper> rhe30y = boost::make_shared<OISRateHelper>(
2, 30 * Years,
Handle<Quote>(boost::make_shared<SimpleQuote>(eoniaquotes[33])),
eoniaBt);
boost::shared_ptr<RateHelper> rhefeb13 =
boost::make_shared<DatedOISRateHelper>(
Date(16, January, 2013), Date(13, February, 2013),
Handle<Quote>(boost::make_shared<SimpleQuote>(eoniaquotes[34])),
eoniaBt);
boost::shared_ptr<RateHelper> rhemar13 =
boost::make_shared<DatedOISRateHelper>(
Date(13, February, 2013), Date(13, March, 2013),
Handle<Quote>(boost::make_shared<SimpleQuote>(eoniaquotes[35])),
eoniaBt);
boost::shared_ptr<RateHelper> rheapr13 =
boost::make_shared<DatedOISRateHelper>(
Date(13, March, 2013), Date(10, April, 2013),
Handle<Quote>(boost::make_shared<SimpleQuote>(eoniaquotes[36])),
eoniaBt);
boost::shared_ptr<RateHelper> rhemay13 =
boost::make_shared<DatedOISRateHelper>(
Date(10, April, 2013), Date(8, May, 2013),
Handle<Quote>(boost::make_shared<SimpleQuote>(eoniaquotes[37])),
eoniaBt);
boost::shared_ptr<RateHelper> rhejun13 =
boost::make_shared<DatedOISRateHelper>(
Date(8, May, 2013), Date(12, June, 2013),
Handle<Quote>(boost::make_shared<SimpleQuote>(eoniaquotes[38])),
eoniaBt);
boost::shared_ptr<RateHelper> rhejul13 =
boost::make_shared<DatedOISRateHelper>(
Date(12, June, 2013), Date(10, July, 2013),
Handle<Quote>(boost::make_shared<SimpleQuote>(eoniaquotes[39])),
eoniaBt);
std::vector<boost::shared_ptr<RateHelper> > eoniaratehelpers;
eoniaratehelpers += rhon, rhe1w, rhe2w, rhe3w, rhe1m,
rhefeb13, rhemar13, rheapr13, rhemay13, rhejun13, rhejul13,
/*rhe2m, rhe3m, rhe4m, rhe5m, rhe6m, rhe7m,*/ // replaced by forwards
rhe8m, rhe9m, rhe10m, rhe11m, rhe1y, rhe15m,
rhe18m, rhe21m, rhe2y, rhe3y, rhe4y, rhe5y, rhe6y, rhe7y, rhe8y, rhe9y,
rhe10y, rhe11y, rhe12y, rhe15y, rhe20y, rhe30y;
PiecewiseYieldCurve<Discount, LogLinear> curve(0, TARGET(), eoniaratehelpers, Actual365Fixed(), tolerance);
curve.recalculate();
std::vector<Rate> spotRates, discountFactors, forwardRates;
Period forwardTenor(3, Months); // 3 month forward
// Construct spot curve, forward curve and discount curve
for(Size i=0;i<eoniaratehelpers.size();i++) {
Rate rate;
Date d = eoniaratehelpers[i]->latestDate();
// spot rate
rate = curve.zeroRate(d, Actual365Fixed(), Continuous, Annual, true);
spotRates.push_back(rate);
// forward rate
rate = curve.forwardRate(d, TARGET().advance(d, forwardTenor),dayCounterOIS, Simple, Annual, true);
forwardRates.push_back(rate);
// discount rate
rate = curve.discount(d, true);
discountFactors.push_back(rate);
}
/////////////////////// Print out four sets of rates //////////////////////////////////
std::cout << std::setw(20) << std::left << "Spot Rate"<< std::setw(20)
<< std::left << "Forward Rate" << std::setw(20)
<< std::left << "Discount"<< std::endl;
for (int i = 0; i < spotRates.size(); i++) {
std::cout.precision(5);
std::cout << std::setw(20) << std::left << spotRates[i]*100
<< std::setw(20) << std::left << forwardRates[i]*100
<< std::setw(20) << std::left << discountFactors[i]
<< std::endl;
}
return 0;
} catch (std::exception& e) {
std::cerr << e.what() << std::endl;
return 1;
} catch (...) {
std::cerr << "unknown error" << std::endl;
return 1;
}
}
Jeffrey
Hello Everybody,
I am very interested in multi-curve construction in the QuantLib
framework, and I came across the paper "Bootstrapping the Illiquidity"
on the QuantLib website. The paper mentions that the source code used
for the multi-curve fitting study is available open source, but I have
been unable to find it in the QuantLib repo and elsewhere on the
internet. Would it be possible for somebody to help out and point me to
the exact location of the source code?
Alternatively, is there any other open-source QuantLib code that does
multi-curve fitting available?
Thanks,
Haonan
------------------------------------------------------------------------------
Slashdot TV.
Video for Nerds. Stuff that matters.
http://tv.slashdot.org/_______________________________________________
QuantLib-users mailing list
[hidden email]https://lists.sourceforge.net/lists/listinfo/quantlib-users