Markets: A Rigorous Course

13A.9 Hedge 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.

13A.9.1Three static estimators#

With centred sums Sxx,Syy,SxyS_{xx}, S_{yy}, S_{xy} of log prices:

  • OLS of yy on xx: β^y∣x=Sxy/Sxx\hat\beta_{y|x} = S_{xy}/S_{xx} (minimises vertical distances).
  • Reverse OLS, inverted: 1/β^x∣y=Syy/Sxy1/\hat\beta_{x|y} = S_{yy}/S_{xy} (minimises horizontal distances).
  • Total least squares (orthogonal regression): minimises perpendicular distances.

Proposition 13A.12TLS slope

The TLS slope is

β^TLS=(Syy−Sxx)+(Syy−Sxx)2+4Sxy22Sxy,(13A.30)\hat\beta_{\text{TLS}} = \frac{(S_{yy}-S_{xx}) + \sqrt{(S_{yy}-S_{xx})^2 + 4S_{xy}^2}}{2S_{xy}}, \tag{13A.30}

it is the slope of the first principal component of (x,y)(x,y), it satisfies β^TLS(y on x)⋅β^TLS(x on y)=1\hat\beta_{\text{TLS}}(y\text{ on }x)\cdot\hat\beta_{\text{TLS}}(x\text{ on }y) = 1, and for Sxy>0S_{xy}>0, β^y∣x≤β^TLS≤1/β^x∣y\hat\beta_{y|x}\le\hat\beta_{\text{TLS}}\le1/\hat\beta_{x|y}.

Proof

The squared perpendicular distance from (xi,yi)(x_i,y_i) to the line y=α+βxy = \alpha+\beta x is (yi−α−βxi)2/(1+β2)(y_i-\alpha-\beta x_i)^2/(1+\beta^2). Minimising over α\alpha gives α=yˉ−βxˉ\alpha = \bar y - \beta\bar x, leaving f(β)=(Syy−2βSxy+β2Sxx)/(1+β2)f(\beta) = (S_{yy}-2\beta S_{xy}+\beta^2S_{xx})/(1+\beta^2). Then f′(β)=0f'(\beta) = 0 reduces (multiply out and cancel the β3\beta^3 terms) to

Sxyβ2+(Sxx−Syy)β−Sxy=0.S_{xy}\beta^2 + (S_{xx}-S_{yy})\beta - S_{xy} = 0.

The two roots have product −1-1 (perpendicular directions); the "+" root has the sign of SxyS_{xy} and is the minimum, the other the maximum. This is (13A.30). f(β)f(\beta) is the Rayleigh quotient of the covariance matrix in direction (−β,1)(-\beta, 1), so the minimiser is orthogonal to the smallest eigenvector, i.e. along the first principal component. Swapping xx and yy swaps SxxS_{xx} and SyyS_{yy}; substituting shows the new root is the reciprocal. For the ordering, differentiate: f′(β)=2q(β)/(1+β2)2f'(\beta) = 2q(\beta)/(1+\beta^2)^2 with q(β)=Sxyβ2+(Sxx−Syy)β−Sxyq(\beta) = S_{xy}\beta^2+(S_{xx}-S_{yy})\beta-S_{xy}. Direct substitution gives q(Sxy/Sxx)=Sxy(Sxy2−SxxSyy)/Sxx2≤0q(S_{xy}/S_{xx}) = S_{xy}(S_{xy}^2 - S_{xx}S_{yy})/S_{xx}^2 \le 0 and q(Syy/Sxy)=(SxxSyy−Sxy2)/Sxy≥0q(S_{yy}/S_{xy}) = (S_{xx}S_{yy}-S_{xy}^2)/S_{xy}\ge0, both by Cauchy–Schwarz. With Sxy>0S_{xy}>0, qq is a convex parabola with q(0)=−Sxy<0q(0) = -S_{xy}<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\hat\beta_{y|x}\cdot\hat\beta_{x|y} = S_{xy}^2/(S_{xx}S_{yy}) = \hat\rho^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 β\beta; 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#

yt=xt′βt+εt,  εt∼N(0,R);βt=βt−1+ηt,  ηt∼N(0,Q),(13A.31)y_t = x_t'\beta_t + \varepsilon_t,\ \ \varepsilon_t\sim N(0,R);\qquad \beta_t = \beta_{t-1} + \eta_t,\ \ \eta_t\sim N(0,Q), \tag{13A.31}

with ε,η\varepsilon,\eta independent of each other and over time, and prior β0∼N(b0,P0)\beta_0\sim N(b_0, P_0). For a pair, xt=pt2x_t = p^2_t (scalar) or xt=(1,pt2)′x_t = (1, p^2_t)' with a time-varying intercept. Write Ft\mathcal F_t for the information in y1,…,yty_1,\dots,y_t (the xtx_t are treated as known).

Proposition 13A.13Kalman filter

βt∣Ft∼N(bt∣t,Pt∣t)\beta_t\mid\mathcal F_t\sim N(b_{t|t},P_{t|t}), computed recursively by

bt∣t−1=bt−1∣t−1,Pt∣t−1=Pt−1∣t−1+Q,(13A.32)b_{t|t-1} = b_{t-1|t-1},\qquad P_{t|t-1} = P_{t-1|t-1} + Q, \tag{13A.32}
et=yt−xt′bt∣t−1,Ft=xt′Pt∣t−1xt+R,(13A.33)e_t = y_t - x_t'b_{t|t-1},\qquad F_t = x_t'P_{t|t-1}x_t + R, \tag{13A.33}
Kt=Pt∣t−1xt/Ft,bt∣t=bt∣t−1+Ktet,Pt∣t=Pt∣t−1−Ktxt′Pt∣t−1.(13A.34)K_t = P_{t|t-1}x_t/F_t,\qquad b_{t|t} = b_{t|t-1} + K_te_t,\qquad P_{t|t} = P_{t|t-1} - K_tx_t'P_{t|t-1}. \tag{13A.34}
Proof

By induction. Suppose βt−1∣Ft−1∼N(bt−1∣t−1,Pt−1∣t−1)\beta_{t-1}\mid\mathcal F_{t-1}\sim N(b_{t-1|t-1},P_{t-1|t-1}) (true at t=1t=1 by the prior).

Predict. βt=βt−1+ηt\beta_t = \beta_{t-1}+\eta_t with ηt\eta_t independent of Ft−1\mathcal F_{t-1} and βt−1\beta_{t-1}, so βt∣Ft−1\beta_t\mid\mathcal F_{t-1} is normal with mean bt−1∣t−1b_{t-1|t-1} and variance Pt−1∣t−1+QP_{t-1|t-1}+Q: (13A.32).

Joint law. Given Ft−1\mathcal F_{t-1}, yt=xt′βt+εty_t = x_t'\beta_t+\varepsilon_t is a linear function of the Gaussian pair (βt,εt)(\beta_t,\varepsilon_t), so (βt,yt)(\beta_t, y_t) is jointly normal with

E[yt∣Ft−1]=xt′bt∣t−1,Var⁡(yt∣Ft−1)=xt′Pt∣t−1xt+R=Ft,Cov⁡(βt,yt∣Ft−1)=Pt∣t−1xt.\begin{aligned} \mathbb E[y_t\mid\mathcal F_{t-1}] &= x_t'b_{t|t-1}, \\ \operatorname{Var}(y_t\mid\mathcal F_{t-1}) &= x_t'P_{t|t-1}x_t+R = F_t, \\ \operatorname{Cov}(\beta_t,y_t\mid\mathcal F_{t-1}) &= P_{t|t-1}x_t. \end{aligned}

Update. For jointly normal (U,V)(U,V), U∣V∼N(EU+ΣUVΣVV−1(V−EV), ΣUU−ΣUVΣVV−1ΣVU)U\mid V\sim N\big(\mathbb EU + \Sigma_{UV}\Sigma_{VV}^{-1}(V-\mathbb EV),\ \Sigma_{UU}-\Sigma_{UV}\Sigma_{VV}^{-1}\Sigma_{VU}\big). With U=βtU = \beta_t, V=ytV = y_t this is (13A.34). Conditioning on yty_t in addition to Ft−1\mathcal F_{t-1} is conditioning on Ft\mathcal F_t, which completes the induction.∎

Likelihood The innovations ete_t are independent N(0,Ft)N(0,F_t) given the past, so by the prediction-error decomposition

ln⁡L(Q,R)=−12∑t[ln⁡(2πFt)+et2Ft].(13A.35)\ln L(Q,R) = -\frac12\sum_t\Big[\ln(2\pi F_t) + \frac{e_t^2}{F_t}\Big]. \tag{13A.35}

Maximise over (Q,R)(Q,R) numerically. Two facts help. First, scaling QQ, RR and P0P_0 by the same constant leaves KtK_t and bt∣tb_{t|t} unchanged (every PP and FF scales by it), so the filtered hedge ratio depends only on the signal-to-noise ratio δ=Q/R\delta = Q/R. Second, with a diffuse prior the first few FtF_t are huge; drop them from (13A.35) (kalman_loglik(burn=...)).

Proposition 13A.14steady state and exponential smoothing

For scalar β\beta and constant xt=x≠0x_t = x\ne0, Pt∣t−1→PˉP_{t|t-1}\to\bar P with

Pˉ=12(Q+Q2+4QR/x2),Kˉ=Pˉxx2Pˉ+R,(13A.36)\bar P = \tfrac12\Big(Q + \sqrt{Q^2 + 4QR/x^2}\Big),\qquad \bar K = \frac{\bar Px}{x^2\bar P + R}, \tag{13A.36}

and in steady state bt∣t=(1−λ)bt−1∣t−1+λ (yt/x)b_{t|t} = (1-\lambda)b_{t-1|t-1} + \lambda\,(y_t/x) with λ=Kˉx∈(0,1)\lambda = \bar Kx\in(0,1): an exponentially weighted moving average of the ratio yt/xy_t/x.

Proof

Combining (13A.32) and (13A.34), Pt+1∣t=Pt∣t−1−x2Pt∣t−12x2Pt∣t−1+R+Q=Pt∣t−1Rx2Pt∣t−1+R+QP_{t+1|t} = P_{t|t-1} - \frac{x^2P_{t|t-1}^2}{x^2P_{t|t-1}+R} + Q = \frac{P_{t|t-1}R}{x^2P_{t|t-1}+R} + Q. A fixed point satisfies Pˉ(x2Pˉ+R)=PˉR+Q(x2Pˉ+R)\bar P(x^2\bar P + R) = \bar PR + Q(x^2\bar P+R), i.e. x2Pˉ2−Qx2Pˉ−QR=0x^2\bar P^2 - Qx^2\bar P - QR = 0, whose positive root is (13A.36). The map P↦PR/(x2P+R)+QP\mapsto PR/(x^2P+R)+Q is increasing and concave with derivative R2/(x2P+R)2<1R^2/(x^2P+R)^2<1 on [0,∞)[0,\infty), so iteration converges to Pˉ\bar P from any P≥0P\ge0. Then bt∣t=bt−1∣t−1+Kˉ(yt−xbt−1∣t−1)=(1−Kˉx)bt−1∣t−1+Kˉx (yt/x)b_{t|t} = b_{t-1|t-1} + \bar K(y_t - xb_{t-1|t-1}) = (1-\bar Kx)b_{t-1|t-1} + \bar Kx\,(y_t/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−5Q = 10^{-5}, R=10−3R = 10^{-3}, x=1x = 1: Pˉ=1.0512×10−4\bar P = 1.0512\times10^{-4}, Kˉ=λ=0.0951\bar K = \lambda = 0.0951. The weight on an observation halves after ln⁡0.5/ln⁡(1−0.0951)=6.93\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/Ftz_t = e_t/\sqrt{F_t}, the surprise in yty_t given the hedge ratio predicted from the past (Chan 2013, ch. 3). Trade when ∣zt∣|z_t| is large.

  • Use bt∣t−1b_{t|t-1}, not bt∣tb_{t|t}, to form the spread you trade at tt. bt∣tb_{t|t} already uses yty_t. The smoothed estimates bt∣Tb_{t|T} use the whole sample and are look-ahead (the same trap as M13 · 13.5 for regime probabilities).
  • The trap. A large δ\delta lets βt\beta_t chase every move in yt/xty_t/x_t. The innovation then shrinks, the spread yt−xtbt∣ty_t - x_tb_{t|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\beta_t is also an admission that the relationship is not cointegrated with a fixed vector. Choose δ\delta by likelihood or out-of-sample, and check the economic plausibility of the path of βt\beta_t.

Exercise link m13a_kalman.py checks the one-step update by hand, the steady state (13A.36), that the filter tracks a simulated random-walk βt\beta_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 QQ on a grid. With Q=0Q = 0 the filter is recursive least squares and its final state equals full-sample OLS.

Create a free account

Reading is open to everyone. An account keeps your progress, answers, notes and code drafts, and gives you the study plan, the journals and the simulator. Running code needs an account approved for it.