Skip to main content
Kalman pairs spread on a BTC chart

BTC on 1-hour bars in the 0xArchive Terminal, 2026-10-25.

Open on a chart

Load it on BTC 1h in the terminal, then change its settings or open it in the script editor.
The spread of a pair trade, in standard deviations: the chart’s market (in logs) less the hedge ratio times the other’s, less a drifting intercept. Past ±2, the spread has stretched further from the hedge than usual, and the background says so.

How it works

ml.kalmanBeta treats the pair as y = α + βx with α and β drifting slowly, and updates both on every bar. Its spread is the bar’s surprise against the estimates from before the bar, so it never uses the bar to explain itself; stats.zscore puts it in standard deviations of its last 200 bars. (spreadZ scales it by the filter’s own noise setting instead, which suits daily bars at the default noiseVar and reads small on hourly ones.) Drift (delta) sets how fast the hedge ratio may move: larger follows the pair faster and leaves a flatter spread. The ratio itself is a hidden line, in the legend.

The script

kalman-pairs.ts

Next step

See the next example, Basket residual.
Last modified on October 25, 2026