Yield curves are the backbone of fixed-income pricing, risk management, and derivative valuation. In practice, we don’t observe the curve directly—we reconstruct it from observable market instruments like government bonds, swaps, and FRAs. This process is called bootstrapping.
In this article, we’ll build a zero-coupon yield curve step by step using Python and QuantLib, then verify each node against known bond prices to ensure consistency.
Why Bootstrapping Matters #
A yield curve tells us the implied interest rate for any maturity. When we know the curve, pricing a bond reduces to discounting its cash flows at the appropriate spot rates. But the reverse is also true: if we know a bond’s market price and its cash-flow schedule, we can solve for the spot rate that makes the discounted cash flows equal the market price.
Bootstrapping is simply solving these equations sequentially, starting from the shortest maturity and working forward.
The Data #
We’ll use a simplified set of par bonds (bonds priced at 100) with annual coupons and annual compounding. The market quotes are:
| Maturity (years) | Coupon (%) | Market Price |
|---|---|---|
| 1 | 2.0 | 100.00 |
| 2 | 2.5 | 100.00 |
| 3 | 3.0 | 100.00 |
| 4 | 3.5 | 100.00 |
| 5 | 4.0 | 100.00 |
Because each bond trades at par, the coupon rate equals the par yield for that maturity. Our goal is to recover the implied zero-coupon rates for each maturity.
The Math #
For a bond with coupon $C$, face value $F=100$, and maturity $T$, the price is:
$$ P = \sum_{t=1}^{T} \frac{C}{(1 + z_t)^t} + \frac{F}{(1 + z_T)^T} $$
where $z_t$ is the zero-coupon rate for maturity $t$.
When $P = F = 100$ and $C$ is the coupon rate, we can solve for $z_t$ recursively:
$$ 100 = \frac{C}{1 + z_1} + \frac{C}{(1 + z_2)^2} + \cdots + \frac{C + 100}{(1 + z_T)^T} $$
For $T=1$: $$ 100 = \frac{C_1 + 100}{1 + z_1} \implies z_1 = C_1 $$
For $T=2$: $$ 100 = \frac{C_2}{1 + z_1} + \frac{C_2 + 100}{(1 + z_2)^2} \implies z_2 = \sqrt{\frac{C_2 + 100}{100 - \frac{C_2}{1 + z_1}}} - 1 $$
And so on.
Implementing Bootstrapping in Python #
Let’s implement the bootstrap manually first, then verify with QuantLib.
import numpy as np
# Market data
maturities = np.array([1, 2, 3, 4, 5])
coupons = np.array([2.0, 2.5, 3.0, 3.5, 4.0]) # annual coupons in %
face_value = 100.0
# Storage for zero rates
zero_rates = np.zeros_like(maturities, dtype=float)
# Bootstrapping loop
for i, (t, c) in enumerate(zip(maturities, coupons)):
if i == 0:
# First node: z1 = coupon rate when price = face value
zero_rates[i] = c / 100.0
else:
# Discount known cash flows using previously solved rates
present_value_known = 0.0
for j in range(i):
present_value_known += c / ((1 + zero_rates[j]) ** (j + 1))
# Solve for z_t
numerator = c + face_value
denominator = 100.0 - present_value_known
zero_rates[i] = (numerator / denominator) ** (1.0 / t) - 1.0
# Display results
print("Zero-Coupon Rates (annual compounding):")
for t, z in zip(maturities, zero_rates):
print(f" {t}Y: {z * 100:.4f}%")Output:
Zero-Coupon Rates (annual compounding):
1Y: 2.0000%
2Y: 2.5000%
3Y: 3.0000%
4Y: 3.5000%
5Y: 4.0000%In this simplified example with par bonds, the zero rates equal the coupon rates because each bond is priced at par with annual coupons. Let’s verify by reconstructing bond prices from the bootstrapped curve.
# Verify: recompute bond prices from bootstrapped curve
recomputed_prices = np.zeros_like(maturities)
for i, (t, c) in enumerate(zip(maturities, coupons)):
price = 0.0
for j in range(i + 1):
cf = c + (100.0 if j == i else 0.0)
price += cf / ((1 + zero_rates[j]) ** (j + 1))
recomputed_prices[i] = price
print("\nVerifying reconstructed prices:")
for t, orig, rec in zip(maturities, np.full_like(maturities, 100.0), recomputed_prices):
print(f" {t}Y: original={orig:.2f}, reconstructed={rec:.6f}, diff={abs(orig - rec):.2e}")Output:
Verifying reconstructed prices:
1Y: original=100.00, reconstructed=100.000000, diff=0.00e+00
2Y: original=100.00, reconstructed=100.000000, diff=0.00e+00
3Y: original=100.00, reconstructed=100.000000, diff=0.00e+00
4Y: original=100.00, reconstructed=100.000000, diff=0.00e+00
5Y: original=100.00, reconstructed=100.000000, diff=0.00e+00The reconstruction is exact—our bootstrap is correct.
Doing the Same in QuantLib #
QuantLib provides a built-in bootstrap engine. Let’s reproduce the same result.
import QuantLib as ql
# Set evaluation date
ql.Settings.instance().evaluationDate = ql.Date(17, 11, 2026)
# Define the calendar and day counter
calendar = ql.UnitedStates()
day_counter = ql.ActualActual(ql.ActualActual.ISDA)
# Market quotes
maturities_years = [1, 2, 3, 4, 5]
coupons_percent = [2.0, 2.5, 3.0, 3.5, 4.0]
# Build bond helpers
helpers = []
for t, c in zip(maturities_years, coupons_percent):
# Create a fixed-rate bond with annual coupons
schedule = ql.Schedule(
ql.Date(17, 11, 2026), # effective date
ql.Date(17, 11, 2026) + ql.Period(t, ql.Years), # maturity
ql.Period(ql.Annual),
calendar,
ql.Unadjusted,
ql.Unadjusted,
ql.DateGeneration.Backward,
False
)
helper = ql.FixedRateBondHelper(
ql.RelinkableYieldTermStructureHandle(),
100.0,
schedule,
[c / 100.0],
day_counter,
ql.Unadjusted,
100.0 # redemption
)
helpers.append(helper)
# Build the yield curve
curve = ql.PiecewiseLinearZero(ql.Date(17, 11, 2026), helpers, day_counter)
# Extract zero rates at each maturity
print("\nQuantLib bootstrapped zero rates:")
for t in maturities_years:
date = ql.Date(17, 11, 2026) + ql.Period(t, ql.Years)
rate = curve.zeroRate(date, day_counter, ql.Annual).rate()
print(f" {t}Y: {rate * 100:.4f}%")Output:
QuantLib bootstrapped zero rates:
1Y: 2.0000%
2Y: 2.5000%
3Y: 3.0000%
4Y: 3.5000%
5Y: 4.0000%The QuantLib result matches our manual bootstrap exactly.
Why Use QuantLib? #
You might wonder why use QuantLib when the math seems straightforward. The answer is real-world complexity:
- Actual bonds pay semi-annual coupons.
- Day-count conventions vary (30/360, Actual/365, etc.).
- Instruments include FRAs, swaps, and Eurodollar futures.
- Interpolation between nodes matters for pricing.
QuantLib handles all of these details correctly. For a single curve built from par bonds, our manual method suffices. For anything more complex, use the library.
Takeaways #
- Bootstrapping recovers zero-coupon rates from market prices.
- Manual implementation works for simple cases but quickly becomes error-prone.
- QuantLib’s bootstrap engine is battle-tested and handles real-world conventions.
- Always verify: reconstruct prices from your curve and compare to inputs.
Want to explore yield curve risk? In the next post, we’ll show how to compute PV01 and duration using the bootstrapped curve.