Sub topic 7
Fitting a smooth curve with Nelson-Siegel
This chapter assumes you know what a spot rate is, how bootstrapping produces spot rates from par rates, and the level, slope and curvature description of curve movements. Basic familiarity with Python and linear regression helps for the code.
Why fit a curve at all
Bootstrapping gives spot rates only at maturities where you observe a par bond or swap rate, such as 1, 2, 3, 5, 7, 10 and 30 years. Valuation often needs a rate at 4.3 years, or a curve that does not wiggle because of noise in a single quote.
Two options exist:
- Interpolate between observed points. The curve passes through every quote exactly, so any bad quote shows up as a kink.
- Fit a parametric model. A function with a few parameters is fitted to all the quotes at once. The result is smooth, defined at every maturity, and cheap to store and compare over time.
Nelson-Siegel is the standard parametric choice, and the CFA curriculum uses it to connect curve fitting to the level, slope and curvature factors.
The Nelson-Siegel formula
The model gives the spot rate for maturity τ (in years) as:
r(τ) = β0 + β1 · L1(τ) + β2 · L2(τ)
with the two loadings:
- L1(τ) = (1 − e^(−τ/λ)) / (τ/λ)
- L2(τ) = L1(τ) − e^(−τ/λ)
The model has four parameters: β0, β1, β2 and λ (lambda, which must be positive). Rates are usually treated as continuously compounded. Convert them before using them as annual-compounded spot rates in a discount factor formula.
What each parameter does
| Parameter | Factor | Effect on the curve |
|---|---|---|
| β0 | Level | Long-maturity rate. As τ grows, both loadings go to 0, so r(∞) = β0. |
| β1 | Slope | Short-maturity rate minus long-maturity rate. As τ goes to 0, L1 goes to 1 and L2 goes to 0, so r(0) = β0 + β1. |
| β2 | Curvature | Size and direction of a hump (β2 > 0) or trough (β2 < 0) at medium maturities. |
| λ | Decay | How fast the slope and curvature effects fade. It sets where the hump sits. |
Some points to keep straight:
- A negative β1 means the curve slopes upward, because the short rate β0 + β1 is below the long rate β0. A positive β1 means an inverted curve.
- L1 starts at 1 and decays smoothly toward 0, so it controls the short end.
- L2 starts at 0, rises, then decays back to 0. Its maximum is near τ ≈ 1.79 · λ, so a small λ puts the hump at short maturities and a large λ pushes it out.
- The loadings are fixed shapes. The betas scale them, which is why this is a factor model of the curve.
Computing the curve
This code evaluates the curve. It uses only the standard library.
import math
def ns_rate(tau, b0, b1, b2, lam):
"""Nelson-Siegel spot rate for maturity tau > 0 (continuously compounded)."""
x = tau / lam
l1 = (1 - math.exp(-x)) / x
l2 = l1 - math.exp(-x)
return b0 + b1 * l1 + b2 * l2
params = (0.045, -0.02, 0.01, 2.0) # b0, b1, b2, lambda
for tau in [0.25, 1, 2, 5, 10, 30]:
print(tau, round(ns_rate(tau, *params), 5))With these parameters, the 2-year rate is 3.5000%. The 10-year rate is about 4.29%. Short maturities start near β0 + β1 = 2.5%, and the 30-year rate is close to the 4.5% level. The curve is upward sloping and smooth.
Estimating the parameters
Given observed spot rates, you choose parameters that minimize squared errors. Note two structural facts:
- For a fixed λ, the model is linear in β0, β1 and β2, so ordinary least squares finds them exactly.
- λ enters nonlinearly, so it is found by a search.
A common practical method is therefore a grid search over λ with least squares at each step.
import numpy as np
def loadings(tau, lam):
x = tau / lam
l1 = (1 - np.exp(-x)) / x
l2 = l1 - np.exp(-x)
return l1, l2
def fit_ns(taus, rates, lam_grid):
taus, rates = np.asarray(taus, float), np.asarray(rates, float)
best = None
for lam in lam_grid:
l1, l2 = loadings(taus, lam)
X = np.column_stack([np.ones_like(taus), l1, l2])
betas, *_ = np.linalg.lstsq(X, rates, rcond=None)
sse = float(np.sum((X @ betas - rates) ** 2))
if best is None or sse < best[0]:
best = (sse, betas, lam)
return best
taus = [0.25, 0.5, 1, 2, 3, 5, 7, 10, 20, 30]
l1, l2 = loadings(np.array(taus), 2.0)
rates = 0.045 - 0.02 * l1 + 0.01 * l2 # synthetic "market" rates
sse, betas, lam = fit_ns(taus, rates, np.arange(0.25, 10.01, 0.25))
print([round(float(b), 4) for b in betas], lam)The synthetic data come from known parameters, so the fit recovers them: betas of 0.045, -0.02 and 0.01, and λ of 2.0. With real quotes the fit is not exact, and the residuals show which maturities the model cannot explain.
Using the fitted curve
Once fitted, the curve feeds the rest of the valuation toolkit:
- Evaluate r(τ) at every cash flow date, including dates between quoted maturities.
- Convert each rate to a discount factor, for example DF = e^(−r·τ) for continuous compounding.
- Price bonds as sums of discounted cash flows, as in arbitrage-free valuation.
- Derive forward rates from the discount factors.
Because the curve is continuous, the implied forward rate has a closed form and no jumps. This avoids the sawtooth forwards that raw interpolation of noisy spot rates often produces.
The parameters also give a compact time series. Tracking β0, β1 and β2 daily shows level, slope and curvature moves directly, which is the link to the previous discussion of curve movements.
Limits and common errors
- Too few parameters. Four parameters cannot match every kink. If the market curve has two humps, Nelson-Siegel will miss one. Extensions such as Svensson add a second curvature term and a second decay parameter.
- Not arbitrage-free by construction. The model fits today's curve, but it does not guarantee a tree or a dynamic model consistent with no-arbitrage. Do not confuse it with Vasicek, CIR or Ho-Lee, which describe how rates evolve over time.
- Unstable parameters. If λ is allowed to vary freely, β1 and β2 can become large and offsetting. Restricting λ to a plausible range, or fixing it, gives steadier estimates.
- Compounding mismatch. Using a continuously compounded fitted rate as an annual-pay spot rate misprices every bond slightly.
- Extrapolation. Rates beyond the longest quoted maturity are determined by the functional form and tend toward β0, not by market data.
Exercise
A fitted Nelson-Siegel curve has β0 = 4.5%, β1 = -2.0%, β2 = 1.0% and λ = 2. Compute the spot rate for a 2-year maturity. Then state the rates that the curve approaches as maturity goes to 0 and to infinity.
Show answer
With τ = 2 and λ = 2, x = 1. L1 = (1 − e^(−1)) / 1 = 0.6321 and L2 = 0.6321 − e^(−1) = 0.2642. The rate is 4.5% − 2.0% × 0.6321 + 1.0% × 0.2642 = 4.5% − 1.2642% + 0.2642% = 3.50%. As maturity goes to 0 the rate approaches β0 + β1 = 2.5%. As maturity goes to infinity it approaches β0 = 4.5%.
Exercise
Why is it practical to estimate Nelson-Siegel by a grid search over λ with least squares for the betas, and what does a larger λ do to the curvature hump?
Show answer
For a fixed λ the spot rate is a linear function of β0, β1 and β2, so ordinary least squares solves for them exactly. Only λ needs a search, which is a one-dimensional grid. A larger λ makes the loadings decay more slowly, so the hump in the curvature loading (near τ ≈ 1.79 × λ) moves to longer maturities.