Level, slope, curvature: PCA on the yield curve
A government yield curve has a rate for every maturity, from three months to thirty years. Day to day they don’t move independently. Most days the whole curve shifts up or down together; some days it steepens or flattens; occasionally the middle moves against the ends. Principal component analysis turns that observation into numbers you can hedge with.
Find the directions the curve actually moves in
Stack each day’s yield changes at M maturities into a vector . PCA asks: which single direction (a unit vector, a shape across maturities) captures as much of the day-to-day variance as possible? The variance of moves along is , and maximising it subject to gives : the top eigenvector. The second PC is the best direction orthogonal to the first, and so on.
The eigenvectors are orthogonal, and the daily PC scores are uncorrelated with each other. So the PCs split the curve’s risk into separate, non-overlapping pieces.
Litterman and Scheinkman (1991) found that three factors explain about 96% of the variance of US Treasury returns, with roughly 89% from the first, 8.5% from the second and 2% from the third, and gave them names from their shapes:
- PC1, level: all loadings about the same sign and size. Every rate moves up or down together.
- PC2, slope: loadings go from negative at the short end to positive at the long end. The curve steepens or flattens.
- PC3, curvature: positive in the middle and negative at both ends (or the reverse). The belly moves against the wings.
Loadings of the first three PCs
Share of variance explained
The data here are simulated from a three-factor Nelson–Siegel model with a little noise, so the PCs come out clean. On real data the shapes look much the same, with noisier loadings at the very short end, where central bank policy adds its own dynamics. Use the sliders to push the curve along each PC: PC1 shifts it, PC2 twists it, and PC3 bends it.
Hedging against the first two PCs
A trader who thinks the 5-year is cheap relative to the 2-year and 10-year wants to buy the 5-year and sell the other two, without betting on the curve shifting or twisting. A duration-neutral trade (equal DV01 long and short) only removes exposure to a parallel shift. With PCA, you can make it neutral to both level and slope.
Take PC loadings at those maturities, e.g. PC1 = (0.32, 0.31, 0.30) and PC2 = (−0.14, 0.14, 0.30) for 2y, 5y and 10y. Buy 1 unit of 5-year DV01 and sell of 2-year and of 10-year. Neutrality to both PCs requires:
What’s left is mostly a curvature bet, plus the small unexplained noise, which is exactly the view. This is a PCA-weighted butterfly. Note it isn’t 50/50 on the wings: the 10-year leg is bigger because the slope factor moves the 10-year more than the 2-year.
import numpy as np
def yield_pca(dy, k=3):
"""dy: T x M array of daily yield changes. Returns explained-variance shares, loadings (M x k), scores (T x k)."""
dy = dy - dy.mean(axis=0)
Sigma = np.cov(dy, rowvar=False)
vals, vecs = np.linalg.eigh(Sigma) # ascending order
order = np.argsort(vals)[::-1]
vals, vecs = vals[order], vecs[:, order]
vecs *= np.sign(vecs.sum(axis=0)) # fix sign: mostly-positive loadings
return vals[:k] / vals.sum(), vecs[:, :k], dy @ vecs[:, :k]
# PCA-neutral butterfly weights: solve loadings[wings].T @ w = loadings[belly]
L = np.array([[0.32, -0.14], [0.31, 0.14], [0.30, 0.30]]) # rows 2y, 5y, 10y; cols PC1, PC2
a, b = np.linalg.solve(L[[0, 2]].T, L[1])
print(a, b) # ≈ 0.37, 0.64Practical notes
- Changes, not levels. PCA on yield levels finds the same shapes but mixes in slow trends; risk and hedging care about changes.
- Covariance or correlation? Covariance (bp moves) weights the volatile maturities more. Correlation treats each maturity equally. Use covariance for P&L.
- Stability. The first two PCs are very stable over time; the third and higher ones move around and are partly noise.
- Signs are arbitrary. An eigenvector times −1 is still an eigenvector. Fix a convention before comparing across samples.
Where people slip in interviews
- Duration-neutral = risk-free. It only hedges parallel moves. A slope move still hits a duration-neutral steepener.
- Reading PCs as economic factors. They are statistical directions. “Level” and “slope” are names for shapes that happen to show up.
- Assuming the PCs are uncorrelated in the future. They’re uncorrelated in-sample by construction; out of sample, a bit of correlation creeps back.
- Forgetting to demean. PCA needs centred data, or the first PC partly picks up the mean.
Try these before you open the answer
Warm-upTwo rates each have daily vol 5bp and correlation 0.9. What are the two PCs and the share of variance each explains?Show answer
The covariance matrix is . Its eigenvectors are with eigenvalue and with eigenvalue . So level explains 95% and spread 5%.
OrthogonalWhy are the PC scores uncorrelated with each other?Show answer
for , because eigenvectors of a symmetric matrix are orthogonal.
HedgeA position has DV01 exposures (in $ per bp) of +100 at 2y, −50 at 5y and −40 at 10y. Using the loadings above, what is its exposure to PC1 and PC2?Show answer
PC1: . PC2: . It’s nearly level-neutral but has a big short-slope exposure: it gains if the curve flattens.
VariancePC1 has eigenvalue 64 (bp²) and PC2 has 9. What's the daily s.d. of a portfolio with PC1 exposure 2 and PC2 exposure 5 (per bp), ignoring higher PCs?Show answer
Scores are uncorrelated, so variances add: dollars.
StretchShow that the first PC maximises v⊤Σv subject to ‖v‖ = 1.Show answer
Lagrangian . Setting the gradient to zero: , so v is an eigenvector and the objective equals . The maximum is the largest eigenvalue, attained at its eigenvector.
The figure simulates 2,000 days of yield changes and computes the eigenvectors in your browser. The butterfly weights were solved with numpy.