Repository Public
1# pairs_coint_perp / 123**Hypothesis.** BTC and ETH share a common stochastic trend: `log ETH − β · log BTC` is stationary over a couple of4weeks, so a stretched spread comes back. Holding the spread (one leg long, the other short) removes most of the5market direction; what is left is the bet on the spread. The spot version (`pairs_rotation/1`) could only tilt6between two long positions and kept the full market risk.78**Mechanism.** At each bar, ordinary least squares of `log ETH` on `log BTC` over the **336 bars ending at that9bar** gives the hedge ratio β, the z-score of the last residual and the Dickey–Fuller t-statistic of the residuals.10Enter when the residuals look stationary (t < −3.04, the 10 % Engle–Granger critical value for two series) and11`|z| > 2`: short the spread if `z > 0` (short ETH, long BTC), long it if `z < 0`. Exit when `z` is back inside ±0.5.12**Stop** when `|z| > 4` or β turns non-positive, and stay out until `z` is back inside ±0.5. Notional weights:13ETH `± gross / (1 + β)`, BTC `∓ gross · β / (1 + β)` — β-weighted, so the position is neutral to a common move of14the two logs (and close to dollar-neutral when β ≈ 1). The rule is replayed over the last 96 bars, each with its15own window, because the function keeps no memory.1617**What would refute it.** The stationarity test failing most of the time (then the strategy barely trades and18says nothing), or losses on the trades it does take: a spread that looked stationary in-sample and then drifts is19the standard failure of pairs trading, and the stop turns it into a realised loss. Both legs pay fee and slippage20(four fills per round trip) and each leg pays or receives its own funding: the funding differential between ETH21and BTC is a carry the z-score knows nothing about. β is estimated on 336 points with strongly autocorrelated22residuals; the t-statistic is only an indication.2324Parameters were written before any backtest on the Hyperliquid data and are not tuned on the test split.25