# Python yield curve bootstrapping equivalent to Matlab IRDataCurve.bootstrap

I want to bootstrap the yield curve of multiple currencies using 3M futures. I have it implemented in Matlab, but need to transfer to Python. I have a vector of dates and a vector of future prices.

Could somebody help me finding the python equivalent to Matlab's:

IRDataCurve.bootstrap('Zero', quote_date, instrument_types, instruments,'InterpMethod','spline','Basis',2,'Compounding',-1,'IRBootstrapOptions', IRBootstrapOptions('ConvexityAdjustment',@(t) .5*sigma^2.*t.^2));

Is it possible to replicate?

I found some options with QuantLib:

• PiecewiseLogLinearDiscount
• PiecewiseLogCubicDiscount
• PiecewiseLinearZero
• PiecewiseCubicZero
• PiecewiseLinearForward
• PiecewiseSplineCubicDiscount

But there is very little documentation.

Help would be very much appreciated

• Students sometimes ask for project ideaa. Publishing lots of QuantLib reference implementations such as this would make gteat student projects. Mar 28 at 14:34
• I just released a python library called rateslib. The documentation for it is available here (rateslib.readthedocs.io/en/latest/g_curves.html). I expect it can accomplish what you want.
– Attack68
May 1 at 9:33

You can bootstrap a yield curve using the QuantLib library in Python. First, you need to install QuantLib for Python by running:

pip install QuantLib-Python


This is an example of how to bootstrap a yield curve using QuantLib (Python equivalent code of the Matlab code you've published):

import QuantLib as ql

# Set up parameters
quote_date = ql.Date(28, 3, 2023)
yield_curve_basis = ql.Actual365Fixed()
compounding = ql.Simple
day_count = ql.Actual365Fixed()

# Set up your dates and future prices
dates = [ql.Date(30, 6, 2023), ql.Date(30, 9, 2023), ql.Date(31, 12, 2023)]  # Replace with your dates
future_prices = [0.01, 0.015, 0.02]  # Replace with your future prices

time_to_maturities = [(date - quote_date) / 365.0 for date in dates]
convexity_adjustments = [0.5 * sigma ** 2 * t ** 2 for t in time_to_maturities]

# Create instruments
ql.Period(3, ql.Months),
2,
ql.TARGET(),
ql.ModifiedFollowing,
False,

# Bootstrap yield curve
curve = ql.PiecewiseSplineZero(quote_date, instrument_types, yield_curve_basis, compounding)

# Print zero rates
for date, t in zip(dates, time_to_maturities):
zero_rate = curve.zeroRate(t, compounding).rate()
print(f"Zero rate for {date}: {zero_rate * 100:.2f}%")


This code sets up the required instruments and bootstraps the yield curve using a cubic spline interpolation method. The curve object is a PiecewiseSplineZero instance representing the bootstrapped yield curve. You can use this object to obtain zero rates, discount factors, or forward rates as needed.

Please note that you might need to adjust the parameters and input data to match your specific requirements.

• Thanks for your help. It seems that QuantLib does not have the attribute 'PiecewiseSplineZero' Also, trying the same code with 'PiecewiseCubicZero' will result in the errer "Wrong number or type of arguments for overloaded function". (I ran the code as is, without changing inputs) Mar 30 at 10:23