Term Structure with QuantLib

Interest Rate Term Structure With QuantLib - Part 2

The Basic Curve

We left off after successfully created a QuantLib YieldTermStructure object for the short term curve. In this article we will merge the short term and long term curves to form a single curve. The curve are reproduced here for convenience.

Subsequent codes in this article is meant to be in the same module as the one shown in the previous exercise. As in the case for the short term curve, a helper function is also required for long term curve. ql.FixedrateBondHelper is required and takes the following parameters:

  1. price - is a ql.QuoteHandle class. Price is set at 100 since we assumed that it is a par curve
  2. settlementDays - an integer reflecting number of days from our value date or ql.Settings.instance().evaluationDate
  3. faceAmount - face value of the bond. 100 is assumed.
  4. schedule - the coupon date schedule of the bond. A ql.Schedule class
  5. coupons - the coupon rate of the bond passed as a list.
  6. dayCounter - day count convention.
  7. paymentConv - payment date convention - in most cases this is ql.Following.
There are other paramaters which are not listed here since we will be using the default values. The documentation for the ql.FixedRateBondHelper can be found here. The following parameters are required by ql.Schedule copied from the documentation for ease of reference.
  1. effectiveDate, terminationDate - Date, the start and end date of the calendar list, such as the value date and expiration date of the bond.
  2. tenor - Period object, the interval between two adjacent dates, such as the bond frequency (1 year or 6 months) or interest rate swap rate (3 months).
  3. calendar - A calendar table that generates a specific calendar of dates to follow.
  4. convention - integer, how to adjust the non-working day (except the last date), the value range is some reserved variables of quantlib-python.
  5. terminationDateConvention - Integer, if the last date is a non-working day, how to adjust it, the value range is some reserved variables of quantlib-python.
  6. Rule - A member of DateGeneration that generates the rules for the date.
  7. endOfMonth - If the start date is at the end of the month, whether other dates are required to be scheduled at the end of the month (except the last date).
  8. firstDate - nextToLastDate (optional): Date, the start and end date (not commonly used) provided for the generated method rule.

Each helper is a point on the long term curve. Since we have multiple points, a list is used to keep all the helper. The code is shown below:

Combining The Curve

The next step is to combined the helpers i.e. .st_helpers and lt_helpers. Only then we can use ql.PiecewiseLogCubicDiscount as we did in our previous exercise.

yieldcurve is now a ql.YieldTermStructure class which we can derived other values from. The following is example codes on how to retrieve date, discount factor, time, spot rate and continuous rate stored in a list of dictionary.

You may then print rate_info to the console/terminal, return JSON as a respond to a request or create a DataFrame to view the data. Data in the rate_info list are tabulated below.


The full codes for part 1 & 2 are shown below: