13A.9Hedge ratios: OLS, total least squares and the Kalman filter
Advanced about 25 min
Motivation
The hedge ratio decides what spread you hold. Three static estimators can give materially different answers on the same data, and a dynamic one can either fix a drifting relationship or quietly absorb the mean reversion you wanted to trade.
it is the slope of the first principal component of (x,y), it satisfies β^TLS(y on x)⋅β^TLS(x on y)=1, and for Sxy>0, β^y∣x≤β^TLS≤1/β^x∣y.
Proof
The squared perpendicular distance from (xi,yi) to the line y=α+βx is (yi−α−βxi)2/(1+β2). Minimising over α gives α=yˉ−βxˉ, leaving f(β)=(Syy−2βSxy+β2Sxx)/(1+β2). Then f′(β)=0 reduces (multiply out and cancel the β3 terms) to
Sxyβ2+(Sxx−Syy)β−Sxy=0.
The two roots have product −1 (perpendicular directions); the "+" root has the sign of Sxy and is the minimum, the other the maximum. This is (13A.30). f(β) is the Rayleigh quotient of the covariance matrix in direction (−β,1), so the minimiser is orthogonal to the smallest eigenvector, i.e. along the first principal component. Swapping x and y swaps Sxx and Syy; substituting shows the new root is the reciprocal. For the ordering, differentiate: f′(β)=2q(β)/(1+β2)2 with q(β)=Sxyβ2+(Sxx−Syy)β−Sxy. Direct substitution gives q(Sxy/Sxx)=Sxy(Sxy2−SxxSyy)/Sxx2≤0 and q(Syy/Sxy)=(SxxSyy−Sxy2)/Sxy≥0, both by Cauchy–Schwarz. With Sxy>0, q is a convex parabola with q(0)=−Sxy<0, so on the positive axis it is negative to the left of its positive root and positive to the right. Hence the positive root lies between the two OLS slopes.∎
Also, β^y∣x⋅β^x∣y=Sxy2/(SxxSyy)=ρ^2: the two OLS slopes agree only if the fit is perfect. TLS is not invariant to rescaling one variable, so apply it to log prices (or standardised series), never to rupee prices of very different magnitudes.
If the pair is truly cointegrated, all three estimators are superconsistent for the same β; their differences are a finite-sample matter. They are large precisely when the residual spread is wide relative to the common trend, which is the case worth trading. Problem 13A.10 has numbers.
13A.9.2A time-varying hedge ratio: the state-space model#
with ε,η independent of each other and over time, and prior β0∼N(b0,P0). For a pair, xt=pt2 (scalar) or xt=(1,pt2)′ with a time-varying intercept. Write Ft for the information in y1,…,yt (the xt are treated as known).
Update. For jointly normal (U,V), U∣V∼N(EU+ΣUVΣVV−1(V−EV),ΣUU−ΣUVΣVV−1ΣVU). With U=βt, V=yt this is (13A.34). Conditioning on yt in addition to Ft−1 is conditioning on Ft, which completes the induction.∎
Likelihood The innovations et are independent N(0,Ft) given the past, so by the prediction-error decomposition
lnL(Q,R)=−21t∑[ln(2πFt)+Ftet2].(13A.35)
Maximise over (Q,R) numerically. Two facts help. First, scaling Q, R and P0 by the same constant leaves Kt and bt∣t unchanged (every P and F scales by it), so the filtered hedge ratio depends only on the signal-to-noise ratioδ=Q/R. Second, with a diffuse prior the first few Ft are huge; drop them from (13A.35) (kalman_loglik(burn=...)).
Proposition 13A.14steady state and exponential smoothing
For scalar β and constant xt=x=0, Pt∣t−1→Pˉ with
Pˉ=21(Q+Q2+4QR/x2),Kˉ=x2Pˉ+RPˉx,(13A.36)
and in steady state bt∣t=(1−λ)bt−1∣t−1+λ(yt/x) with λ=Kˉx∈(0,1): an exponentially weighted moving average of the ratio yt/x.
Proof
Combining (13A.32) and (13A.34), Pt+1∣t=Pt∣t−1−x2Pt∣t−1+Rx2Pt∣t−12+Q=x2Pt∣t−1+RPt∣t−1R+Q. A fixed point satisfies Pˉ(x2Pˉ+R)=PˉR+Q(x2Pˉ+R), i.e. x2Pˉ2−Qx2Pˉ−QR=0, whose positive root is (13A.36). The map P↦PR/(x2P+R)+Q is increasing and concave with derivative R2/(x2P+R)2<1 on [0,∞), so iteration converges to Pˉ from any P≥0. Then bt∣t=bt−1∣t−1+Kˉ(yt−xbt−1∣t−1)=(1−Kˉx)bt−1∣t−1+Kˉx(yt/x).∎
So the "Kalman hedge ratio" with a random-walk state is exponential smoothing with a smoothing constant chosen by maximum likelihood, the observation Muth (1960) made for forecasting.
Worked example
Q=10−5, R=10−3, x=1: Pˉ=1.0512×10−4, Kˉ=λ=0.0951. The weight on an observation halves after ln0.5/ln(1−0.0951)=6.93 steps. A one-step update by hand is Problem 13A.12.
13A.9.3Using the filter for a pairs trade, and its trap#
The natural signal is the standardised innovation zt=et/Ft, the surprise in yt given the hedge ratio predicted from the past (Chan 2013, ch. 3). Trade when ∣zt∣ is large.
Use bt∣t−1, not bt∣t, to form the spread you trade at t. bt∣t already uses yt. The smoothed estimates bt∣T use the whole sample and are look-ahead (the same trap as M13 · 13.5 for regime probabilities).
The trap. A large δ lets βt chase every move in yt/xt. The innovation then shrinks, the spread yt−xtbt∣t is close to zero by construction, and the mean reversion you wanted to trade has been absorbed into the "hedge ratio". A drifting βt is also an admission that the relationship is not cointegrated with a fixed vector. Choose δ by likelihood or out-of-sample, and check the economic plausibility of the path of βt.
Exercise linkm13a_kalman.py checks the one-step update by hand, the steady state (13A.36), that the filter tracks a simulated random-walk βt with lower RMSE than a 120-day rolling OLS, that the standardised innovations have unit variance, and that the likelihood (13A.35) picks the true Q on a grid. With Q=0 the filter is recursive least squares and its final state equals full-sample OLS.