The hedge ratio, four ways

The hedge ratio says how much of asset B to hold against each unit of asset A so that the combination is neutral to their shared moves. Get it wrong and you are not trading the spread; you are trading one of the legs with extra steps.

1. Regression (OLS)

Regress log A on log B; the slope is β. It is the textbook method and the one every cointegration test uses internally. Its weakness is that it is a full-sample average. If the true ratio drifts, a fixed β leaves you with a spread that trends. Spread Trading Lab re-estimates it on a trailing window in the backtest and shows how much it has moved over time. A rolling standard deviation above half the value of β is a warning.

2. Total least squares

Ordinary regression assumes B is measured without noise and all the error sits in A. In a pair both legs are noisy, so the slope is biased toward zero. Total least squares minimises the perpendicular distance instead and gives a symmetric answer whichever way round you write the pair. Spread Trading Lab does not compute it, but it is a useful cross-check if you replicate an analysis yourself: if OLS and TLS differ a lot, the relationship is noisy.

3. Kalman filter

A Kalman filter treats β as a hidden state that evolves slowly and updates it every bar as new prices arrive. It adapts to drift, which is its appeal. Its risk is over-adaptation: with the parameters tuned loosely it will chase noise and generate far more trades. Ernest Chan's well-known EWA/EWC example reported a Sharpe of 2.4; an independent replication with realistic costs got about 0.65. Spread Trading Lab uses the filter only (never the smoother, which would use future data) and the standard Chan parameters.

4. The simple ratio

Practitioners often skip the regression entirely. Set β to 1, trade the log ratio of the two prices, and size the legs so each carries the same risk, using recent volatility. Kris Longmore of Robot Wealth argues this is more robust than any estimated ratio precisely because there is nothing to estimate badly. It is the "ratio, equal-risk legs" mode in the lab.

Which to use

In the lab, run rolling OLS, the Kalman filter and the simple ratio on the same pair and compare the out-of-sample results. If the conclusion changes depending on the method, the pair's edge is fragile and the method is doing the work. If they all agree, the relationship is doing the work, which is what you want.

Compare the methods on KO / PEP