Last active
June 11, 2018 15:30
-
-
Save tomwhoiscontrary/6a2e196a733b816990d41f2ae46773bf to your computer and use it in GitHub Desktop.
Simple attempt to build a Euribor curve
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <vector> | |
#include <boost/make_shared.hpp> | |
#include <ql/indexes/ibor/euribor.hpp> | |
#include <ql/math/interpolations/all.hpp> | |
#include <ql/termstructures/yield/piecewiseyieldcurve.hpp> | |
#include <ql/termstructures/yield/ratehelpers.hpp> | |
#include <ql/time/daycounters/actual360.hpp> | |
#include <ql/time/daycounters/thirty360.hpp> | |
#include <ql/types.hpp> | |
using QuantLib::Abcd; | |
using QuantLib::Actual360; | |
using QuantLib::BusinessDayConvention; | |
using QuantLib::ConvexMonotone; | |
using QuantLib::Cubic; | |
using QuantLib::Date; | |
using QuantLib::DayCounter; | |
using QuantLib::Euribor; | |
using QuantLib::ForwardRate; | |
using QuantLib::Frequency; | |
using QuantLib::FuturesRateHelper; | |
using QuantLib::Handle; | |
using QuantLib::IborIndex; | |
using QuantLib::InterpolatedForwardCurve; | |
using QuantLib::Linear; | |
using QuantLib::Month; | |
using QuantLib::Period; | |
using QuantLib::PiecewiseYieldCurve; | |
using QuantLib::Quote; | |
using QuantLib::RateHelper; | |
using QuantLib::SABR; | |
using QuantLib::Settings; | |
using QuantLib::SwapRateHelper; | |
using QuantLib::Thirty360; | |
using QuantLib::TimeUnit; | |
using QuantLib::YieldTermStructure; | |
// typedef ConvexMonotone CurveInterpolator; | |
// typedef Cubic CurveInterpolator; | |
typedef Linear CurveInterpolator; | |
Month mth(unsigned int monthNumber) { return static_cast<Month>(monthNumber); } | |
int main(int argc, char** argv) { | |
Date today = Date(11, Month::June, 2018); | |
Settings::instance().evaluationDate() = today; | |
DayCounter curveDayCounter = Actual360(); | |
// DISCOUNTING CURVE | |
std::map<Date, double> discountingCurveNodes = | |
{{Date(11, mth(6), 2018), -0.00355584210537288}, {Date(20, mth(6), 2018), -0.00355584210537288}, | |
{Date(13, mth(7), 2018), -0.00354847355117201}, {Date(13, mth(9), 2018), -0.00347811838208307}, | |
{Date(13, mth(12), 2018), -0.0035046853117356}, {Date(13, mth(3), 2019), -0.00359597753246646}, | |
{Date(13, mth(6), 2019), -0.00336488221017208}, {Date(13, mth(9), 2019), -0.00283900803118639}, | |
{Date(13, mth(12), 2019), -0.00226724478999542}, {Date(13, mth(3), 2020), -0.00126475754837997}, | |
{Date(15, mth(6), 2020), -4.04082576520525E-4}, {Date(14, mth(6), 2021), 0.00193549877791657}, | |
{Date(13, mth(6), 2022), 0.00541515029337548}, {Date(13, mth(6), 2023), 0.00834596171638419}, | |
{Date(13, mth(6), 2024), 0.0105506898899723}, {Date(13, mth(6), 2025), 0.0127289184432656}, | |
{Date(15, mth(6), 2026), 0.0146859781244856}, {Date(14, mth(6), 2027), 0.0160839038520465}, | |
{Date(13, mth(6), 2028), 0.0171039813057311}, {Date(13, mth(6), 2033), 0.0190037548450844}, | |
{Date(14, mth(6), 2038), 0.0188138594071705}, {Date(15, mth(6), 2043), 0.0162799102512021}, | |
{Date(15, mth(6), 2048), 0.0147848694988243}, {Date(13, mth(6), 2058), 0.0140576373915513}, | |
{Date(13, mth(6), 2068), 0.0120862578337932}}; | |
std::vector<Date> discountingCurveDates; | |
std::vector<double> discountingCurveRates; | |
for (std::pair<const Date, double> dateAndRate : discountingCurveNodes) { | |
discountingCurveDates.push_back(dateAndRate.first); | |
discountingCurveRates.push_back(dateAndRate.second); | |
} | |
boost::shared_ptr<YieldTermStructure> discountingCurve = | |
boost::make_shared<InterpolatedForwardCurve<CurveInterpolator>>(discountingCurveDates, | |
discountingCurveRates, | |
curveDayCounter, | |
CurveInterpolator()); | |
Handle<YieldTermStructure> discountingCurveHandle(discountingCurve); | |
// FORWARD CURVES | |
boost::shared_ptr<IborIndex> index = | |
boost::make_shared<Euribor>(Period(3, TimeUnit::Months), Handle<YieldTermStructure>()); | |
std::vector<boost::shared_ptr<RateHelper>> swapsCurveHelpers; | |
// SWAPS | |
std::map<Period, double> swapRates = {{Period(1, TimeUnit::Years), -0.002873}, | |
{Period(2, TimeUnit::Years), -0.001762}, | |
{Period(3, TimeUnit::Years), -1.45E-4}, | |
{Period(4, TimeUnit::Years), 0.001585}, | |
{Period(5, TimeUnit::Years), 0.0032175}, | |
{Period(6, TimeUnit::Years), 0.004705}, | |
{Period(7, TimeUnit::Years), 0.0060575}, | |
{Period(8, TimeUnit::Years), 0.007295}, | |
{Period(9, TimeUnit::Years), 0.008395}, | |
{Period(10, TimeUnit::Years), 0.0093975}, | |
{Period(12, TimeUnit::Years), 0.0110675}, | |
{Period(15, TimeUnit::Years), 0.012865}, | |
{Period(20, TimeUnit::Years), 0.014465}, | |
{Period(25, TimeUnit::Years), 0.014995}, | |
{Period(30, TimeUnit::Years), 0.015135}, | |
{Period(40, TimeUnit::Years), 0.01509}, | |
{Period(50, TimeUnit::Years), 0.0148}}; | |
for (std::pair<const Period, double> tenorAndRate : swapRates) { | |
Period tenor = tenorAndRate.first; | |
double rate = tenorAndRate.second; | |
boost::shared_ptr<SwapRateHelper> swapHelper = | |
boost::make_shared<SwapRateHelper>(rate, | |
tenor, | |
index->fixingCalendar(), | |
Frequency::Annual, | |
BusinessDayConvention::ModifiedFollowing, | |
Thirty360(), | |
index, | |
Handle<Quote>(), | |
Period(0, TimeUnit::Days), | |
discountingCurveHandle); | |
swapsCurveHelpers.push_back(swapHelper); | |
} | |
boost::shared_ptr<PiecewiseYieldCurve<ForwardRate, CurveInterpolator>> swapsCurve = | |
boost::make_shared<PiecewiseYieldCurve<ForwardRate, CurveInterpolator>>(today, | |
swapsCurveHelpers, | |
curveDayCounter); | |
// READOUT | |
std::cout << "date, forward" << '\n'; | |
for (Date date = today; date <= today + Period(30, TimeUnit::Years); | |
date = index->fixingCalendar().advance(date, 1, TimeUnit::Days)) { | |
std::cout << QuantLib::io::iso_date(date) // | |
<< ", " << swapsCurve->forwardRate(date, date, curveDayCounter, QuantLib::Compounding::Simple).rate() // | |
<< '\n'; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment