algebraicBootstrapperExample.cpp

This example show how to build curve using Algebraic bootstrapper. Programme uses data files stored as csv in ./data directory

Name: df_instruments

Object: DataFrame
Size: 9 col 25 rows
--------------------------------------------------------------------------------------------------------
      Type      Rate   FRAstart   Tenor          YF1      YF2   RateConvention    FreqFix        FreqFlo
--------------------------------------------------------------------------------------------------------
   Deposit    0.0487          .      ON       ACT365        .           simple          .              .
   Deposit    0.0487          .      TN       ACT365        .           simple          .              .
   Deposit    0.0483          .      1W       ACT365        .           simple          .              .
   Deposit    0.0485          .      2W       ACT365        .           simple          .              .
   Deposit    0.0491          .      1M       ACT365        .           simple          .              .
   Deposit    0.0494          .      2M       ACT365        .           simple          .              .
   Deposit    0.0513          .      3M       ACT365        .           simple          .              .
   Deposit    0.0514          .      6M       ACT365        .           simple          .              .
       FRA   0.05115         1M      7M       ACT365        .           simple          .              .
       FRA   0.05105         2M      8M       ACT365        .           simple          .              .
       FRA    0.0508         3M      9M       ACT365        .           simple          .              .
       FRA   0.04865         6M     12M       ACT365        .           simple          .              .
       FRA   0.04415        12M     18M       ACT365        .           simple          .              .
       IRS   0.04734          .      2Y   ActActISDA   ACT365           simple   annually   semiannually
       IRS   0.04659          .      3Y   ActActISDA   ACT365           simple   annually   semiannually
       IRS   0.04662          .      4Y   ActActISDA   ACT365           simple   annually   semiannually
       IRS   0.04678          .      5Y   ActActISDA   ACT365           simple   annually   semiannually
       IRS   0.04699          .      6Y   ActActISDA   ACT365           simple   annually   semiannually
       IRS   0.04722          .      7Y   ActActISDA   ACT365           simple   annually   semiannually
       IRS   0.04744          .      8Y   ActActISDA   ACT365           simple   annually   semiannually
       IRS   0.04761          .      9Y   ActActISDA   ACT365           simple   annually   semiannually
       IRS   0.04765          .     10Y   ActActISDA   ACT365           simple   annually   semiannually
       IRS   0.04717          .     12Y   ActActISDA   ACT365           simple   annually   semiannually
       IRS   0.04550          .     15Y   ActActISDA   ACT365           simple   annually   semiannually
       IRS   0.04262          .     20Y   ActActISDA   ACT365           simple   annually   semiannually
--------------------------------------------------------------------------------------------------------


Name: df_settings

Object: DataFrame
Size: 11 col 7 rows
--------------------------------------------------------------------------------------------------------------------------------------------------------------------
      Id   Interpolation   InterpolationInput   Compounding       YF   Estimator   SmoothingParam   Iterations   SmoothingInput   FirstDerivative   SecondDerivative
--------------------------------------------------------------------------------------------------------------------------------------------------------------------
   Set22          linear                  ZCR        simple   ACT365   algebraic                .            .                .                 .                  .
   Set23    cubic_spline                  ZCR        simple   ACT365   algebraic                .            .                .                 .                  .
   Set24           AKIMA                  ZCR        simple   ACT365   algebraic                .            .                .                 .                  .
   Set25         Steffen                  ZCR        simple   ACT365   algebraic                .            .                .                 .                  .
   Set26          linear                   DF        simple   ACT365   algebraic                .            .                .                 .                  .
   Set27          linear                invDF        simple   ACT365   algebraic                .            .                .                 .                  .
   Set28          linear                logDF        simple   ACT365   algebraic                .            .                .                 .                  .
--------------------------------------------------------------------------------------------------------------------------------------------------------------------





**********************************
ProgrammeRunTime:1s451ms
**********************************

Plots below presents the interest rate curves build using different interpolation type

algebraic_curves_interpolation.png

Plots below presents the interest rate curves build using different interpolation inputs

algebraic_curves_inputs.png

Here we present the calibration of the curve. We see perfect match between market quotings and curve implied par rates.

algebraic_curves_calibration.png
#include <juliant.hpp>
#include "factoryInit.hpp"
#include <algorithm>
#include <vector>
#include <set>
using namespace julian;
int main(int argc, char *argv[]) {
//
// Setting the calendar and the today date
//
Date today(2018, JUN, 20);
PLNHoliday holiday;
Calendar calendar = BuildCalendar()
.addHoliday(holiday)
//
// Reading the command line arguments; If not provided, program uses default names
//
auto args = catchDataAndSettingFileNames(argc, argv);
auto data_file = args.first.empty() ? "../data/curve_data.csv" : args.first;
auto settings_file = args.second.empty() ? "../data/curve_settings.csv" : args.second;
//
// Creating benchmark instruments
//
DataFrame df_instruments(data_file, ';', true);
auto df_depo = df_instruments.filter("Type", [](std::string x)->bool{return x == "Deposit";} );
auto df_fra = df_instruments.filter("Type", [](std::string x)->bool{return x == "FRA";} );
auto df_irs = df_instruments.filter("Type", [](std::string x)->bool{return x == "IRS";} );
//
// Printing instruments set
//
SHOW(df_instruments);
std::vector<Deposit> deposits = ir::readDeposit(df_depo, today, calendar);
std::vector<FRA> fras = ir::readFRA(df_fra, today, calendar);
std::vector<IRS> swaps = ir::readIRS(df_irs, today, calendar);
std::vector<SmartPointer<ir::BuildingBlock> > instruments;
instruments.insert(instruments.end(), deposits.begin(), deposits.end());
instruments.insert(instruments.end(), fras.begin(), fras.end());
instruments.insert(instruments.end(), swaps.begin(), swaps.end());
//
// Reading data settings
//
DataFrame df_settings(settings_file, ';', true);
df_settings = df_settings.filter("Estimator", [](std::string x)->bool{return x == "algebraic";} );
//
// Printing curves' settings
//
SHOW(df_settings);
//
// Constructing the curve
//
DataFrame estimation_resuts;
DataFrame calibration_results;
for (int r = 1; r <=df_settings.getNumberOfRows(); r++) {
auto set_name = df_settings("Id", r);
auto interpolation = df_settings.getObject<Interpolation>("Interpolation", r);
auto inputs = df_settings.getObject<ir::InterpolationInput>("InterpolationInput", r);
auto compounding = df_settings.getObject<Compounding>("Compounding", r);
auto yf = df_settings.getObject<YearFraction>("YF", r);
InterestRate rate(compounding, yf);
ir::CompoundedInterpolator interpolator(interpolation, inputs);
.asOfDate(today)
.withCalendar(calendar)
.withInterpolator(interpolator)
.withSetOfInstruments(instruments)
.usingEstimator(estimator);
auto calib = ir::getCalibration(curve, instruments, set_name);
auto curve_data = ir::getCurves(curve, 1*WEEK, 15*YEAR, set_name);
calibration_results.append(calib);
estimation_resuts.append(curve_data);
}
//
// Saving results
//
calibration_results.printToCsv("algebraic_bootstrapper_calibration");
estimation_resuts.printToCsv("algebraic_bootstrapper_results");
}