Quant techniques · fixed income

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.

1Σ=Cov(Δyt)\Sigma = \mathrm{Cov}(\Delta y_t) Covariance matrix of daily changes in yields across the M maturities (changes, not levels: levels are close to non-stationary).
2Σ=VΛV⊤\Sigma = V\Lambda V^\top Eigendecomposition. Column vkv_k is the k-th principal component’s loadings; λk\lambda_k is the variance of daily moves along it.
3λk∑jλj\dfrac{\lambda_k}{\sum_j \lambda_j} Share of variance explained. For US Treasuries the first three PCs typically explain 95–99% between them.
4Δyt≈∑k=13fk,t vk,fk,t=vk⊤Δyt\Delta y_t \approx \sum_{k=1}^{3} f_{k,t}\, v_k, \qquad f_{k,t} = v_k^\top \Delta y_t Each day’s move is approximately three numbers: how much level, slope and curvature moved.
The method

Find the directions the curve actually moves in

Stack each day’s yield changes at M maturities into a vector Δyt\Delta y_t. PCA asks: which single direction vv (a unit vector, a shape across maturities) captures as much of the day-to-day variance as possible? The variance of moves along vv is v⊤Σvv^\top\Sigma v, and maximising it subject to ∥v∥=1\lVert v\rVert = 1 gives Σv=λv\Sigma v = \lambda v: 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 fk,t=vk⊤Δytf_{k,t} = v_k^\top\Delta y_t 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

PC1 “level”PC2 “slope”PC3 “curvature”
move the curve: PC1PC2PC3

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.

Using 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 aa of 2-year and bb of 10-year. Neutrality to both PCs requires:

0.32 a+0.30 b=0.31(level)−0.14 a+0.30 b=0.14(slope)⟹a≈0.37,  b≈0.64\begin{aligned} 0.32\,a + 0.30\,b &= 0.31 \quad (\text{level}) \\ -0.14\,a + 0.30\,b &= 0.14 \quad (\text{slope}) \end{aligned} \quad\Longrightarrow\quad a \approx 0.37,\ \ b \approx 0.64

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.64

Practical 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.
Practice

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 25(10.90.91)25\begin{pmatrix}1 & 0.9\\ 0.9 & 1\end{pmatrix}. Its eigenvectors are (1,1)/2(1, 1)/\sqrt2 with eigenvalue 25×1.925 \times 1.9 and (1,−1)/2(1, -1)/\sqrt2 with eigenvalue 25×0.125 \times 0.1. So level explains 95% and spread 5%.

OrthogonalWhy are the PC scores uncorrelated with each other?
Show answer

Cov(vj⊤Δy, vk⊤Δy)=vj⊤Σvk=λkvj⊤vk=0\mathrm{Cov}(v_j^\top\Delta y,\ v_k^\top\Delta y) = v_j^\top\Sigma v_k = \lambda_k v_j^\top v_k = 0 for j≠kj \ne k, 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: 100(0.32)−50(0.31)−40(0.30)=32−15.5−12=4.5100(0.32) - 50(0.31) - 40(0.30) = 32 - 15.5 - 12 = 4.5. PC2: 100(−0.14)−50(0.14)−40(0.30)=−14−7−12=−33100(-0.14) - 50(0.14) - 40(0.30) = -14 - 7 - 12 = -33. 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: 22×64+52×9=256+225≈21.9\sqrt{2^2 \times 64 + 5^2 \times 9} = \sqrt{256 + 225} \approx 21.9 dollars.

StretchShow that the first PC maximises v⊤Σv subject to ‖v‖ = 1.
Show answer

Lagrangian v⊤Σv−λ(v⊤v−1)v^\top\Sigma v - \lambda(v^\top v - 1). Setting the gradient to zero: 2Σv−2λv=02\Sigma v - 2\lambda v = 0, so v is an eigenvector and the objective equals v⊤Σv=λv^\top\Sigma v = \lambda. 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.