Skip to content
All library documents

Choosing QuantLib Curve Interpolation Methods for Discount Factors

Article Quant Q&A · Author: Alepo

Summary

The document explains how to select interpolation schemes when bootstrapping yield curves in QuantLib-Python. It shows a dual-curve setup using deposit, forward rate agreement, and swap helpers, then constructs curves with different interpolation choices, including log-linear and log-cubic discount factors, linear or cubic zero rates, linear forwards, and spline cubic discount factors.

The example demonstrates that curves built from the same market instruments match at the input curve nodes, while discount factors at dates between those nodes differ because each scheme interpolates a different quantity. The answer provides working Python examples, but it does not show the requested monotonic cubic spline on log discount factors specifically or establish which interpolation is preferable. The result is a practical illustration of available curve classes and the distinction between calibration nodes and interpolated values.

Key ideas

  • QuantLib-Python exposes curve interpolation choices through distinct piecewise curve classes.
  • A dual-curve bootstrap can use rate helpers for deposits, forward rate agreements, and swaps.
  • Curves using the same instruments can agree at calibration nodes while differing between nodes.
  • Interpolation schemes differ in the quantity they interpolate, such as discount factors, zero rates, or forwards.
  • The example does not demonstrate a monotonic cubic spline on log discount factors.

Tags

Full text
# Monotonic Cubic Spline interpolation QuantLib python


# 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.

## Answer by David Duarte (score 0, accepted)

https://quant.stackexchange.com/a/53962

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
```

Shown in full with attribution under the source's licence. Licence: CC BY-SA 4.0 (Stack Exchange)

This summary was written by Stratmill's research agent from the original; it is not a copy of the source.