Fixed Rate Bond with QuantLib

Fixed Rate Bond With QuantLib

Introduction

We started off with building interest rate term structure due to the fundamental aspect of finance - time value of money and is crucial to valuation and risk management. In this article we will look at a capital market product - debt, namely a fixed rate bond. It will be a very basic introduction to ql.FixedRateBond class and the aim is to view the coupon or cash flow structure of the bond.

The Process

The initial requirement as usual is the import of the relevant library and setting of the value date as shown below.

Defining The Bond

In the event that a country's calendar is not in the list supported by QuantLib, a customs calendar can be created using ql.BespokeCalendar(country_name). This will create a calendar with all dates considered as business days. For standard weekends we can join the newly created calendar with ql.WeekendsOnly() using ql.JoinCalendar(calendar1, calendar2). Then we can add the country's holidays using addHoliday(). This will gives us a custom calendar with holidays including weekends.

The next step is to defined the bond - issue date, maturity date, day count convention, business day convention and the likes. The information are required in generating the date structure of the bond using ql.Schedule. We have not used ql.Schedule prior to this and the documentation on the class is here for references.

To be able to view the content of schedule, one need to convert it to a list which can then be printed to the console/terminal. You will notice that the list is filled with ql.Date classes - the dates for the bonds whih includes the issue, maturity and coupon dates.

Viewing The Structure

With the ql.Schedule object we can find out the coupon/cash flow structure of the bond. First we need to create a ql.FixedRateBond class using the schedule. Then we will iterate through the schedule and retrieve the relevant information using ql.BondFunctions class. There are plenty of public member functions for the class and is best left to its own documentation for description.

In the above snippet, we defined the face value of the bond, get the length of schedule and do the looping. Within the loop we reset the ql.Settings.instance().evaluationDate to the date in the schedule and among other things use the public member functions of ql.BondFunctions to retrieve the required information except for the coupon interest for the period. The coupon interest is calculated using ql.FixedRateCoupon class and we called its member, 'amount' to retrieve the value.

Once the loop is finished, we reset the ql.Settings.instance().evaluationDate to its original value and transferred the information to the DataFrame for viewing. The retrieved values are in the following table.

Other Values

There are other values which are of concern to us and can be derived from the library. These include the clean price, accrued interest and risk statistics such as duration. The following snippet illustrate how this can be done.

ql.BondFunctions is the main class used to obtain our required values. The documentation however does not provide much description to the various public member functions, presumably due the self-explanatory name given to the functions.

Summary

Defining the bond is the first step in using the library. Subsequent codes simply use the definition to create the schedule for our review and calculated the varios values required. These steps is sufficiently simple and only requires some understanding of the relevant classes and their member functions.