bootstrapperComparison.cpp

Comparing different bootstrappers.

Name: curve_algebraic
Object: InterpolatedCurve
AsOfDate: 2016-09-30
InterestRate: ACT365_Exponential
Interpolation: AKIMA_interpolation_of_Zero_Coupon_Rates
Extrapolation: Flat_zero_coupon_rates
Date 		DF 		ZCR		Forwards
2016-10-03	0.9998685104	1.599895%	2.674338%	
2016-10-04	0.9998244086	1.602412%	1.609964%	
2017-01-04	0.9956834566	1.644738%	1.646578%	
2017-04-04	0.9915637131	1.662531%	1.681509%	
2017-07-04	0.9874940742	1.658284%	1.649603%	
2017-10-04	0.9834461559	1.651144%	1.629648%	
2018-01-04	0.9794394168	1.644867%	1.619689%	
2018-04-04	0.9755306127	1.641092%	1.621753%	
2018-07-04	0.9715388391	1.641592%	1.644624%	
2018-10-04	0.9674713245	1.644464%	1.664503%	
2019-10-04	0.9484021023	1.759463%	1.990721%	
2020-10-05	0.9288046117	1.838865%	2.076639%	
2021-10-04	0.9078628812	1.927956%	2.286769%	
2022-10-04	0.8861564749	2.009774%	2.419981%	
2023-10-04	0.8640164476	2.083971%	2.530174%	
2024-10-04	0.8414747281	2.153067%	2.636359%	
2025-10-06	0.8187252475	2.216898%	2.725807%	
2026-10-05	0.7959012547	2.278432%	2.835110%	
2027-10-04	0.7723752621	2.344540%	3.008703%	
2028-10-04	0.7483948988	2.411350%	3.145357%	
2029-10-04	0.7252849911	2.467058%	3.136611%	
2030-10-04	0.7020044489	2.523797%	3.262493%	
2031-10-06	0.6784801341	2.581757%	3.389879%	
2032-10-04	0.6594162172	2.598942%	2.857857%	
2033-10-04	0.6405330733	2.616947%	2.905417%	
2034-10-04	0.6219004945	2.635542%	2.952065%	
2035-10-04	0.6035337407	2.654587%	2.997816%	
2036-10-06	0.5853266130	2.673897%	0.000000%	


Name: curve_rf
Object: InterpolatedCurve
AsOfDate: 2016-09-30
InterestRate: ACT365_Exponential
Interpolation: Linear_interpolation_of_Zero_Coupon_Rates
Extrapolation: Flat_zero_coupon_rates
Date 		DF 		ZCR		Forwards
2016-10-03	0.9998685104	1.599895%	2.674188%	
2016-10-04	0.9998244086	1.602412%	1.609964%	
2017-01-04	0.9956834566	1.644738%	1.646578%	
2017-04-04	0.9915637131	1.662531%	1.681509%	
2017-07-04	0.9874940742	1.658284%	1.649603%	
2017-10-04	0.9834461559	1.651144%	1.629648%	
2018-01-04	0.9794394168	1.644867%	1.619689%	
2018-04-04	0.9755306127	1.641092%	1.621753%	
2018-07-04	0.9715388391	1.641592%	1.644624%	
2018-10-04	0.9674713245	1.644464%	1.664503%	
2019-10-04	0.9484021023	1.759463%	1.990721%	
2020-10-05	0.9288046117	1.838865%	2.076639%	
2021-10-04	0.9078628812	1.927956%	2.286769%	
2022-10-04	0.8861564749	2.009774%	2.419981%	
2023-10-04	0.8640164476	2.083971%	2.530174%	
2024-10-04	0.8414747281	2.153067%	2.636359%	
2025-10-06	0.8187252475	2.216898%	2.725807%	
2026-10-05	0.7959012547	2.278432%	2.835110%	
2028-10-04	0.7483952326	2.411347%	3.077195%	
2031-10-06	0.6784850186	2.581709%	3.263001%	
2036-10-06	0.5853442173	2.673747%	0.000000%	


Name: curve_ucs
Object: InterpolatedCurve
AsOfDate: 2016-09-30
InterestRate: ACT365_Exponential
Interpolation: Linear_interpolation_of_Zero_Coupon_Rates
Extrapolation: Flat_zero_coupon_rates
Date 		DF 		ZCR		Forwards
2016-10-03	0.9998683405	1.601962%	2.670711%	
2016-10-04	0.9998244796	1.601764%	1.601170%	
2017-01-04	0.9957014863	1.637853%	1.639423%	
2017-04-04	0.9916140079	1.652577%	1.668283%	
2017-07-04	0.9875753335	1.647441%	1.636943%	
2017-10-04	0.9835588456	1.639810%	1.616836%	
2018-01-04	0.9795824701	1.633304%	1.607206%	
2018-04-04	0.9757034594	1.629355%	1.609132%	
2018-07-04	0.9717404351	1.629796%	1.632465%	
2018-10-04	0.9677007350	1.632674%	1.652754%	
2019-10-04	0.9487607067	1.746907%	1.976627%	
2020-10-05	0.9288928964	1.836499%	2.104784%	
2021-10-04	0.9081314344	1.922057%	2.266642%	
2022-10-04	0.8864953564	2.003416%	2.411323%	
2023-10-04	0.8641703032	2.081433%	2.550603%	
2024-10-04	0.8412536072	2.156346%	2.680326%	
2025-10-06	0.8179118418	2.227916%	2.798527%	
2026-10-05	0.7945538974	2.295343%	2.905333%	
2028-10-04	0.7484368004	2.410885%	2.989703%	
2031-10-06	0.6821400550	2.545950%	3.086089%	
2036-10-06	0.5857517670	2.670272%	0.000000%	





**********************************
ProgrammeRunTime:1s474ms
**********************************

curves_comparison.png
#include <juliant.hpp>
using namespace julian;
int main() {
//
// Setting date and calendar
//
Date today(2016, SEP, 30);
PLNHoliday plnHoli;
Calendar calendar = BuildCalendar()
.addHoliday(plnHoli);
//
// Creating interest rate object that encapsulates interest rate conventions
//
SimpleRate comp1;
ACT365 yf1;
InterestRate rate1(comp1, yf1);
InterestRate rate2(comp1, yf2);
InterestRate rate(comp2, yf1);
//
// Building benchmark instruments
//
builder.usingCalendar(calendar);
builder.withInterestRate(rate1);
builder.withTradeDate(today);
Deposit depo_ON = builder.withTenor(OVERNIGHT).withQuote(0.016);
Deposit depo_TN = builder.withTenor(TOMORROWNEXT).withQuote(0.0161);
Deposit depo_3M = builder.withTenor(3 * MONTH).withQuote(0.0165);
FRA FRA_3x6 = builder.withForwardTenors(3 * MONTH, 6 * MONTH).withQuote(0.01685);
FRA FRA_6x9 = builder.withForwardTenors(6 * MONTH, 9 * MONTH).withQuote(0.01653);
FRA FRA_9x12 = builder.withForwardTenors(9 * MONTH, 12 * MONTH).withQuote(0.01633);
FRA FRA_12x15 = builder.withForwardTenors(12 * MONTH, 15 * MONTH).withQuote(0.01623);
FRA FRA_15x18 = builder.withForwardTenors(15 * MONTH, 18 * MONTH).withQuote(0.01625);
FRA FRA_18x21 = builder.withForwardTenors(18 * MONTH, 21 * MONTH).withQuote(0.01648);
FRA FRA_21x24 = builder.withForwardTenors(21 * MONTH, 24 * MONTH).withQuote(0.01668);
builder.withFixedLegFrequency(ANNUALLY);
builder.withFloatingLegFrequency(SEMIANNUALLY);
IRS IRS_3Y = builder.withTenor(3*YEAR).withQuote(0.01774);
IRS IRS_4Y = builder.withTenor(4*YEAR).withQuote(0.01854);
IRS IRS_5Y = builder.withTenor(5*YEAR).withQuote(0.01942);
IRS IRS_6Y = builder.withTenor(6*YEAR).withQuote(0.02022);
IRS IRS_7Y = builder.withTenor(7*YEAR).withQuote(0.02094);
IRS IRS_8Y = builder.withTenor(8*YEAR).withQuote(0.02161);
IRS IRS_9Y = builder.withTenor(9*YEAR).withQuote(0.02222);
IRS IRS_10Y = builder.withTenor(10*YEAR).withQuote(0.02280);
IRS IRS_12Y = builder.withTenor(12*YEAR).withQuote(0.02403);
IRS IRS_15Y = builder.withTenor(15*YEAR).withQuote(0.02556);
IRS IRS_20Y = builder.withTenor(20*YEAR).withQuote(0.02643);
std::vector<SmartPointer<ir::BuildingBlock> > instruments;
instruments.push_back(depo_ON);
instruments.push_back(depo_TN);
instruments.push_back(depo_3M);
instruments.push_back(FRA_3x6);
instruments.push_back(FRA_6x9);
instruments.push_back(FRA_9x12);
instruments.push_back(FRA_12x15);
instruments.push_back(FRA_15x18);
instruments.push_back(FRA_18x21);
instruments.push_back(FRA_21x24);
instruments.push_back(IRS_3Y);
instruments.push_back(IRS_4Y);
instruments.push_back(IRS_5Y);
instruments.push_back(IRS_6Y);
instruments.push_back(IRS_7Y);
instruments.push_back(IRS_8Y);
instruments.push_back(IRS_9Y);
instruments.push_back(IRS_10Y);
instruments.push_back(IRS_12Y);
instruments.push_back(IRS_15Y);
instruments.push_back(IRS_20Y);
//
// Creating curve settings
//
AKIMA interp2;
ir::CompoundedInterpolator interpolator1(interp1, inputs);
ir::CompoundedInterpolator interpolator2(interp2, inputs);
ir::ExtrapolateFlatZCR extrapolator;
//
// Creating bootstrappers
//
ir::AlgebraicBootstrapper algebraic_bootstrapper;
ir::RootFindingBootstrapper nr_bootstrapper;
ir::UnconstrainedSmoother ucs_bootstrapper(cost_function, 1.0);
//
// Building curves and printing them
//
.asOfDate(today)
.withCalendar(calendar)
.withInterpolator(interpolator2)
.withExtrapolator(extrapolator)
.usingEstimator(algebraic_bootstrapper)
.withSetOfInstruments(instruments);
SHOW(curve_algebraic);
auto algebraic_data = getCurves(curve_algebraic, 2*WEEK, 20*YEAR, "algebraic");
algebraic_data.printToCsv("algebraic", ';');
.asOfDate(today)
.withCalendar(calendar)
.withInterpolator(interpolator1)
.withExtrapolator(extrapolator)
.usingEstimator(nr_bootstrapper)
.withSetOfInstruments(instruments);
SHOW(curve_rf);
auto rf_data = getCurves(curve_rf, 2*WEEK, 20*YEAR, "rf");
algebraic_data.printToCsv("rootfinding", ';');
.asOfDate(today)
.withCalendar(calendar)
.withInterpolator(interpolator1)
.withExtrapolator(extrapolator)
.usingEstimator(ucs_bootstrapper)
.withSetOfInstruments(instruments);
SHOW(curve_ucs);
auto usmoothed_data = getCurves(curve_ucs, 2*WEEK, 20*YEAR,"usmooth");
usmoothed_data.printToCsv("usmoothed", ';');
}