I am interested in calculating the forward curve for different swap tenors. I have the below code in Python, but I believe that this only calculates the forward discount curve. Are we able to modify the code below to produce the forward curve for the 10Y swap rate for instance?

import pandas as pd
import QuantLib as ql
import matplotlib.pyplot as plt

terms =['1','3','6', '12', '24', '36', '60', '84', '120', '180', '360']
rate = [4.3565, 4.5900, 4.8005, 4.9005,  4.4460, 4.0688,  3.7457, 3.6243,  3.5575,  3.5320, 3.2085]

index = ql.USDLibor(ql.Period('120M'))
helpers = []
dc = ql.Actual360()

for term, r in zip(terms, rate):
    swapIndex = ql.UsdLiborSwapIsdaFixAm(ql.Period(int(term), ql.Months))
    helpers.append(ql.SwapRateHelper(r/100, swapIndex))
curve = ql.PiecewiseLogCubicDiscount(0, ql.TARGET(), helpers, dc)

days = ql.MakeSchedule(curve.referenceDate(), curve.maxDate(), ql.Period('1M'))
fwds = [
    curve.forwardRate(d, ql.UnitedStates(m=0).advance(d,0,ql.Days), dc, ql.Simple).rate()
    for d in days

plt.plot([dt.to_date() for dt in days], fwds)


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.