# Monotonic Cubic Spline interpolation QuantLib python

I am new to QuantLib-Python and I am trying to replicate the implementation of a Dual Curve bootstrap using QuantLib-Python. I have followed the steps in Chapter 9 of the QuantLib Python Cookbook. That is, I have initialized the helpers for Deposits+OIS to build the Eonia Curve and subsequently passed this to the helpers for the Tenor Curve (Euribor 6M).

My understanding is that in QuantLib the choice of the interpolation methods is given by the objects called, for example, PiecewiseLogCubicDiscount. In this case the cubic interpolation is performed on Log Discount Factors.

I would like to interpolate using Monotonic Cubic Spline on Log Discount Factor. I saw that in this file some interpolation are exported. I saw in the interpolation.i file that other interpolation methods are available. I just do not know how to access those. Thank you.

• So what exactly is your question? – Hamish Gibson May 6 at 20:16
• I edited my question. Sorry for being unclear. – Alepo May 7 at 7:13

You are correct. In QuantLib python you should choose the appropriate class to get the interpolation method and variable you want.

Here is an example with some of the methods:

import QuantLib as ql

market_data = [
('DEPOSIT', '6M', -0.114),
('FRA', '6M', -0.252),
('FRA', '12M', -0.306),
('SWAP', '2Y', -0.325),
('SWAP', '3Y', -0.347)
]

helpers = ql.RateHelperVector()
index = ql.Euribor6M()
for instrument, tenor, rate in market_data:
rate /= 100
if instrument == 'DEPOSIT':
helpers.append(ql.DepositRateHelper(rate, index))
if instrument == 'FRA':
monthsToStart = ql.Period(tenor).length()
helpers.append(ql.FraRateHelper(rate, monthsToStart, index))
if instrument == 'SWAP':
helpers.append(
ql.SwapRateHelper(
rate, ql.Period(tenor), ql.TARGET(), ql.Annual,
ql.Following, ql.Thirty360(), index
)
)

params = [2, ql.TARGET(), helpers, ql.ActualActual()]
curves = {
"PiecewiseFlatForward": ql.PiecewiseFlatForward(*params),
"LogLinearDiscount": ql.PiecewiseLogLinearDiscount(*params),
"LogCubicDiscount": ql.PiecewiseLogCubicDiscount(*params),
"LinearZero": ql.PiecewiseLinearZero(*params),
"CubicZero": ql.PiecewiseCubicZero(*params),
"LinearForward": ql.PiecewiseLinearForward(*params),
"SplineCubicDiscount": ql.PiecewiseSplineCubicDiscount(*params)
}


If you inspect the discount factors for the curve nodes, they will be identical:

import pandas as pd

df = pd.DataFrame(index=[row[0] for row in curves['LogLinearDiscount'].nodes()])
for curve in curves:
dfs = [curves[curve].discount(idx) for idx in df.index]
df[curve] = dfs


But if you get discount factors from dates that are not given by the instruments used to build the curve, you will get diferent values because you are using diferent interpolation methods on different variables:

new_df = pd.DataFrame(index=[idx + ql.Period('15d') for idx in df.index])
for curve in curves:
curves[curve].enableExtrapolation()
dfs = [curves[curve].discount(idx) for idx in new_df.index]
new_df[curve] = dfs


• Thank you very much for the answer. One follow up question, I was wondering whether there are also other interpolation methods available when constructing the helpers. In the piecewisecurve.i file I see the ones that you have used, is it possible to export other methods than the ones you have used? – Alepo May 10 at 18:58