Computing Zero Rates from Curve

ONce you have constructed a curve, you can extract what the individual zero coupon rates would be for each date. In the following sample code, we extract the continuously compounded zero rate for a range of dates.

Sample Script

import contracts as ct def get_zero_rate(curve, cdate, day_counter = None): target_date = ql.Date(int(cdate.split('-')[2]), int(cdate.split('-')[1]), int(cdate.split('-')[0])) if day_counter == None: day_counter = curve.dayCounter() day_counter = ct.translate_daycount(day_counter) continuous_rate = curve.zeroRate( target_date, day_counter, ql.Continuous ).rate() return continuous_rate def isodate(dt): def wrap(text): if len(text) == 1:return '0'+text return text return str(dt.year())+'-'+wrap(str(dt.month()))+'-'+wrap(str(dt.dayOfMonth())) def get_zero_curve(curve): day = curve.referenceDate() results = [] for i in range(360*10): results.append(get_zero_rate(curve, isodate(day))) day = day + ql.Period(1, ql.Days) return results test = get_zero_curve(curve) rate = get_zero_rate(curve, '2026-10-10')