Duration and convexity calculator
Measure how sensitive a bond's price is to yields, and see how good the duration and convexity approximation really is.
How it works
Macaulay duration is the present-value-weighted average time to the bond's cash flows. Modified duration turns that into a sensitivity: the percentage price change per unit change in yield. DV01 is the same thing in money, per one basis point.
Duration is a straight-line approximation of a curved price-yield relationship. Adding convexity (the second derivative) captures the curve, so the estimate stays close to the exact repricing for larger moves. The chart shows all three.
Assumptions
- Valued on a coupon date: maturity is a whole number of coupon periods away.
- Yield compounded at the coupon frequency; the shock is a parallel change in that yield.
- No embedded options, so this is not effective duration for callable bonds.
Show the codePython, runs in the playground
import numpy as np
def duration_convexity(face, coupon, ytm, years, freq=2):
n = int(round(years * freq))
k = np.arange(1, n + 1)
cf = np.full(n, face * coupon / freq)
cf[-1] += face
y = ytm / freq
pv = cf / (1 + y) ** k
price = pv.sum()
macaulay = (k / freq * pv).sum() / price
modified = macaulay / (1 + y)
convexity = (cf * k * (k + 1) / (1 + y) ** (k + 2)).sum() / (price * freq**2)
return price, macaulay, modified, convexity
price, mac, mod, conv = duration_convexity(100, 0.05, 0.05, 10)
print(f"Price: {price:.6f}")
print(f"Macaulay duration: {mac:.6f}")
print(f"Modified duration: {mod:.6f}")
print(f"Convexity: {conv:.6f}")
print(f"DV01: {mod * price * 1e-4:.6f}")
Questions
What is the difference between Macaulay and modified duration?
Macaulay duration is measured in years: the weighted average time until you are paid. Modified duration divides it by one plus the periodic yield and is the price sensitivity you use for risk.
What does a duration of 7.8 mean?
A 1 percentage point rise in yield lowers the price by about 7.8%. For a 100bp move the convexity term adds back a little, so the true fall is slightly smaller.
Why does a zero-coupon bond's Macaulay duration equal its maturity?
It has one cash flow, at maturity, so the weighted average time is simply that date.
What is DV01 used for?
Hedging. To hedge one bond with another, hold them in the ratio of their DV01s so that a 1bp move changes both by the same amount.
Educational use only, not investment advice. Results depend on the model's assumptions listed above and on your inputs. Calculations run in your browser and nothing you enter is sent to a server.