How can I extract the piecewise linear forward rates given a term structure of zero rates for a given trade date in Py QuantLib. This is used to price an ir swap.
My attempt is to create a ZeroCurve object with the dates, rates, and day count convention, pass this to a YieldTermStructureHandle, pass this to USDLibor object, and lastly pass it to NonstandardSwap object.
This is what I did for the zero rates.
import QuantLib as ql
calendar = ql.UnitedKingdom()
curve_date = ql.Date(5, 12, 2019)
zcr = [ (calendar.advance(curve_date, 365, ql.Days), 0.02),
(calendar.advance(curve_date, 730, ql.Days), 0.03),
(calendar.advance(curve_date, 365, ql.Days), 0.05) ]
dates, rates = zip(*zcr)
forward_term_structure = ql.YieldTermStructureHandle(ql.ZeroCurve(dates, rates, ql.Actual360()))
libor_index = ql.USDLibor(ql.Period(1, ql.Months), forward_term_structure)
Is this correct way to do it? Note that there are more nodes in the zcr but for illustration I made up three coordinates. Thank you.