How do duration and convexity measure a bond’s price risk?

Solve for a bond’s yield to maturity with brentq, compute its Macaulay and modified duration, DV01 and convexity with NumPy, and compare the duration and convexity approximations with the exact price change.

After this lesson, you can estimate a bond’s price change for a yield move and check the estimate by repricing.

How do I find the bond’s yield?

The yield to maturity is the single annual rate that discounts a bond’s payments to its price, and brentq finds it as the rate where the price minus the market price is zero. BBB’s bond from the lesson on credit spreads, which pays 6, 6 and 106 and costs 98.6682 per 100 of face value, yields 6.5029%.

\[ P(y) = \sum_{t=1}^{3} \frac{CF_t}{(1+y)^t} \]

Here \(CF_t\) is the payment at the end of year \(t\) and \(y\) the yield.

The following box solves for the yield.

import numpy as np
from scipy.optimize import brentq

years = np.arange(1, 4)
payments = np.array([6.0, 6.0, 106.0])
price = 98.6682

def price_at(y):
    return np.sum(payments / (1 + y) ** years)

ytm = brentq(lambda y: price_at(y) - price, 0, 0.20)
print(f"{ytm:.4%}", round(price_at(ytm), 4))
6.5029% 98.6682

How do the payment times give duration and DV01?

Macaulay duration is the average time of the payments, each weighted by its share of the price, here 2.8322 years, because the final payment holds 88.93% of the price. Modified duration, the Macaulay duration divided by \(1 + y\), is the price’s percentage sensitivity, 2.6593, and DV01, the loss for a rise of one basis point, is 0.02624 per 100 of face value.

\[ D = \sum_{t} t\,\frac{PV_t}{P}, \qquad D^* = \frac{D}{1+y}, \qquad \Delta P \approx -D^* P\,\Delta y, \qquad \text{DV01} = D^* P \times 0.0001 \]

Here \(PV_t\) is the present value of the payment in year \(t\), \(D\) the Macaulay and \(D^*\) the modified duration, and \(\Delta y\) the change in yield as a decimal.

The following box computes the weights, the two durations and DV01.

present_values = payments / (1 + ytm) ** years
weights = present_values / price
macaulay = np.sum(years * weights)
modified = macaulay / (1 + ytm)
print(weights.round(4), round(macaulay, 4), round(modified, 4), round(modified * price * 0.0001, 5))
[0.0571 0.0536 0.8893] 2.8322 2.6593 0.02624

The lesson on credit spreads found 0.02622 by shifting the whole spot curve, while 0.02624 shifts the single yield.

How much does convexity improve the estimate?

The price curve bends, so duration alone underestimates the price after any large move, and convexity, the second derivative of the price divided by the price, adds the bend. After a rise of 300 basis points, the exact loss is 7.4562, duration predicts 7.8716 and duration with convexity 7.4368.

\[ C = \frac{1}{P}\sum_{t} \frac{t(t+1)\,CF_t}{(1+y)^{t+2}}, \qquad \Delta P \approx P\Big(-D^*\Delta y + \tfrac{1}{2} C\,(\Delta y)^2\Big) \]

Price-yield curve with its tangent line at today's yield

BBB’s price at yields from 0% to 20% bends upward and lies above its tangent line at today’s yield of 6.50%, and the gap grows with the size of the move.

The loop reprices the bond at each yield move and compares the exact change with the two estimates.

The following box computes convexity and the three price changes.

convexity = np.sum(years * (years + 1) * present_values) / (price * (1 + ytm) ** 2)
print(round(convexity, 4))
for move_bp in [-300, -100, 100, 300]:
    move = move_bp / 10_000
    print(move_bp, round(price_at(ytm + move) - price, 4), round(-modified * price * move, 4), round(price * (-modified * move + 0.5 * convexity * move ** 2), 4))
9.7924
-300 8.3274 7.8716 8.3063
-100 2.6729 2.6239 2.6722
100 -2.5763 -2.6239 -2.5755
300 -7.4562 -7.8716 -7.4368

Duration gives too low a price on both sides of today’s yield.

Your turn

At the same yield, compute the price, Macaulay duration and modified duration of a bond that pays only 100 in year 3. You should see 82.7782, 3.0 and 2.8168.

All the weight sits on year 3, so the Macaulay duration is 3 years.

zero_values = np.array([0.0, 0.0, 100.0]) / (1 + ytm) ** years
zero_price = zero_values.sum()
zero_macaulay = np.sum(years * zero_values) / zero_price
print(round(zero_price, 4), round(zero_macaulay, 4), round(zero_macaulay / (1 + ytm), 4))
82.7782 3.0 2.8168