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 **********************************
#include <juliant.hpp>
using namespace julian;
int main() {
RunTimeMeasurment timer;
//
// Setting date and calendar
//
Date today(2016, SEP, 30);
PLNHoliday plnHoli;
.withSpotLag(2)
.addHoliday(plnHoli);
//
// Creating interest rate object that encapsulates interest rate conventions
//
SimpleRate comp1;
ExponentialRate comp2;
ACT365 yf1;
ActActISDA yf2;
InterestRate rate1(comp1, yf1);
InterestRate rate2(comp1, yf2);
InterestRate rate(comp2, yf1);
//
// Building benchmark instruments
//
BuildLinearInstrument builder;
builder.usingCalendar(calendar);
builder.withInterestRate(rate1);
builder.withTradeDate(today);
builder.withInterestRateForFixedLeg(rate2);
builder.withInterestRateForFloatingLeg(rate1);
builder.withFixedLegFrequency(ANNUALLY);
builder.withFloatingLegFrequency(SEMIANNUALLY);
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
//
LinearInterpolation interp1;
AKIMA interp2;
ir::InterpolateZCRate inputs;
ir::CompoundedInterpolator interpolator1(interp1, inputs);
ir::CompoundedInterpolator interpolator2(interp2, inputs);
ir::ExtrapolateFlatZCR extrapolator;
//
// Creating bootstrappers
//
ir::SecondDerivativeCostFunction cf1(cf0);
SmartPointer<ir::SmootherCostFunction> cost_function = cf1;
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)
.withInterestRate(rate)
.withInterpolator(interpolator2)
.withExtrapolator(extrapolator)
.usingEstimator(algebraic_bootstrapper)
.withSetOfInstruments(instruments);
SHOW(curve_algebraic);
algebraic_data.printToCsv("algebraic", ';');
ir::InterpolatedCurve curve_rf = ir::BuildCurve()
.asOfDate(today)
.withCalendar(calendar)
.withInterestRate(rate)
.withInterpolator(interpolator1)
.withExtrapolator(extrapolator)
.usingEstimator(nr_bootstrapper)
.withSetOfInstruments(instruments);
SHOW(curve_rf);
algebraic_data.printToCsv("rootfinding", ';');
ir::InterpolatedCurve curve_ucs = ir::BuildCurve()
.asOfDate(today)
.withCalendar(calendar)
.withInterestRate(rate)
.withInterpolator(interpolator1)
.withExtrapolator(extrapolator)
.usingEstimator(ucs_bootstrapper)
.withSetOfInstruments(instruments);
SHOW(curve_ucs);
usmoothed_data.printToCsv("usmoothed", ';');
}