Image Source: https://www.pexels.com/photo/computer-screen-turned-on-159299/

Bond Risk Sensitivities with Python (Part 1)

Ameya Abhyankar

--

Background

Bonds happen to be one of the most popular products that banks and other financial institutions trade and invest in as a part of their portfolio. For banks, generally bond positions happen to be a part of their trading book. Just like any other product on a portfolio, bonds are also exposed to a set of risk factors. Interest rates (also called yields) are the most important risk factor affecting a bond position. There are a variety of measures used by market participants for measuring risk of a bond position namely duration, convexity, value at risk etc. and further combining them with allied measures including stress testing, scenario analysis etc.

Many of the above mentioned risk measures happen to be a part of daily portfolio monitoring, internal MIS and also for compliance and regulatory reporting purposes. Every market participant on a daily basis closely tracks the risk of their bond positions and accordingly takes appropriate action be it for — profit booking, staying with risk limits, asset-liability management etc.

Interest rate risk sensitivity measurement:

In this article we will focus on duration and its popular varieties. The article talks about the concept of duration and also the Python implementation of the same.

The article covers following three items along-with their Python implementation:

a. Macaulay duration

b. Modified duration

c. Dollar duration

The article shows the pure-Python way of model implementation of the above measures. The below codes can be easily tweaked to apply them to a portfolio of bonds. Further, these models can also be automated by wrapping it in a .exe file which may be triggered as a part of the batch process at a pre-specified time.

What is duration?

Duration is a measure of interest rate risk of a bond. Further, duration is a linear measure of interest rate risk as represented below:

P = f(y)

D = dP / dy

Where, D: duration; dP: change in bond price; dy: is the change in the market yield

A linear measure can be imagined as a metric that can be represented by a straight line. Linear measure is represented functionally as a first order differential as shown above.

Macaulay duration (MacD)

Macaulay duration gives a measure of interest rate sensitivity of the bond. MacD is often measured in years indicates the time it would take for us to get back the investment from the bond in present value terms using the current yields. As the market yields fluctuate, so does the MacD number.

Below given is a equation that is used to calculate MacD:

Where, D: MacD; B: present value of the bond; c(i): periodic cash flows on the bond; t(i): time points of at which cash flows are received; and the exponential term represents the discount factor

The Python implementation for the above formula can be done as below:

For a coupon bearing bond: the MacD is lower than the time to maturity of the bond. The reason being, the promised coupon payments are received at specific time points during the life of the bond.

For a zero coupon bond: the MacD is equal to the maturity of the bond. The reason being, no cashflows are received prior to maturity, and therefore the entire investment is exposed to interest rate risk.

From interest rate risk sensitivity perspective, a zero coupon bond is more sensitive as compared to a similar coupon paying bond of same maturity.

Modified duration (ModD)

Modified duration is another measure of interest rate sensitivity that is popularly used by market participants. This is also the metric that is used as a part of capital charge calculation under Basel III. ModD can be extracted easily from the MacD calculated earlier using the relation below:

where, D*: ModD; D: MacD; y: yield and m: frequency

The above can be implemented in Python as given

Dollar Duration (DD)

Dollar Duration is another popular measure of interest rate risk sensitivity which can be calculated from ModD above. It is defined as below:

DD = ModD * Dollar price * Δy

Generally, Δy is chosen as 1 bps. This relates to another metric called as the PV01 for bonds.

The DD can be implemented in Python using the ModD and dollar price both of which can be implied from the two function above i.e., dollar price can be extracted from the MacD function whereas the ModD is the output from the ModD function above.

Dollar Duration gives a quick approximation of the expected change in the value assuming a small change of 1 bps in yields. 1 bps makes sense because of two things:

a. Bond yields seldom move beyond a couple of basis points day-over-day except in extreme market conditions

b. Duration is a linear metric, so using a change of greater than 1bps in the calculation will expose the duration calculator to handle the non-linear nature of the bond price and yield relationship. Duration cannot understand the non-linearity because it’s a first order measure i.e., linear measure. Thus assuming a change in yield greater than 1 bps will give a poor approximation of risk sensitivity.

Application of duration:

A few common applications of duration metric include:

Daily risk monitoring

Internal MIS reporting

Limits monitoring in sync with board approved policies

Partial revaluation models for Value at Risk (VaR) measurement

Regulatory reporting — e.g. In India, the Reserve Bank of India requires banks to submit quarterly Risk Based Supervision (RBS) reports. Duration happens to be one of the points in the RBS reporting

Regulatory capital charge calculation

Asset liability management (ALM)

Decision on trading actions to take etc.

Way forward

This article discussed duration, its key features and a few varieties. In the next article of this article series on bond risk sensitivity we will discuss the concepts of convexity, key rate duration, forward bucket PV01 etc. along-with their implementation in Python.

Further, while all the above calculations can be implemented in MS Excel, Python provides its own benefits including- rapid prototyping, ease in model management, a ‘neat’ way of handling duration calculation of a portfolio of bonds etc. Further, with big data technologies including machine learning, deep learning and off late, GenAI being adopted more and more by the industry, using Python for such duration calculations also allows one to consistently use Python everywhere.

From a job interviews perspective too, bond risk measures happen to be key concepts that are frequently tested. Subsequently, in industry projects too, these are highly relevant concepts to apply.

Happy learning!

***********

--

--