This lead-lag model was my first real venture into algorithmic trading. Inspired by a good friend and ex-Cantor broker, the model uses real-time data collected from three distinct exchanges to continuously assess the potential for BTC lead-lag arbitrage. The model is connected to a live and information-heavy dashboard, while all trades are automatically stored in log files. Best practices were understood and used as this project matured, and my own skills developed. For example, understanding geographical latency issues led to the removal of WebSocket implementation and the adoption of a Rust framework, and those milliseconds saved by efficient code yielded significant returns relative to the workload.
This model is a live arbitrage detector that receives order-book ticks from Binance, Coinbase, Bybit, and OKX over Rust and runs both a reactive and a predictive strategy side by side.
The reactive strategy looks for fee-adjusted spreads between the lead exchange (Binance) and the lag exchanges that are large enough to exploit before they close.
The predictive strategy models the lead-lag relationship seen between Bitcoin and alt-coins, using a rolling-beta regression and a Z-score signal anchored to an Ornstein–Uhlenbeck mean-reversion process. This is to say that the model sends a positive signal when an altcoin’s expected response to a BTC move has not yet been priced in.
The mathematics:
- Ornstein–Uhlenbeck process —
dXₜ = μ(θ − Xₜ)dt + σdWₜ— the mean-reverting baseline for the BTC–altcoin return spread, whereθis the long-run mean,μis the rate of mean reversion, andσdWₜis the random-walk innovation. - Rolling beta —
β = Cov(R_alt, R_btc) / Var(R_btc)— the live estimate of how much an altcoin moves per unit of BTC move. Computed via Welford’s online algorithm so the estimate updates in O(1) per tick without recomputing the full window. - Z-score signal —
Z = (R − μ) / σ— fires when a BTC return is more than ~2 standard deviations from the rolling mean. - Half-life —
t_½ = ln(2) / |λ|— derived from the OU process. Bounds the maximum holding time for a signal; if the predicted altcoin response hasn’t materialised withint_½, the signal expires.
The model assumes BTC returns lead altcoin returns by tens of seconds — empirically, the research literature finds BTC leads altcoins by 16–118s (mean 57s), with betas of roughly SOL 1.98×, DOGE 1.5×, ETH 0.85×, XRP 1.0×. When BTC moves significantly (|Z| > 2), the model predicts the altcoin’s expected response (β × R_btc); if the altcoin has not yet moved proportionally and the rolling-correlation confidence is high enough, a signal is emitted.
As this was largely an educational endeavour, model transparency was crucial. Every calculation is exposed in a live dashboard, with specific panels for Z-scores, the current rolling beta, its half-life, and its confidence.