Statistical Arbitrage in Crypto — Pairs Trading and Mean Reversion
Statistical arbitrage exploits temporary deviations from equilibrium prices. When two assets that normally move together diverge, a stat arb trader buys the underperformer and shorts the outperformer, betting on convergence. In crypto, this is especially powerful because assets are correlated but not perfectly, creating profitable pockets.
Example: BTC and ETH correlation is 0.85. When ETH underperforms BTC by 3% over a 1-hour period (unusual), a stat arb trader shorts BTC and longs ETH.
Pairs Trading Basics
Selecting Pairs
Not all pairs work. You need:
- High correlation: >0.8 (use Pearson correlation coefficient)
- Economic relationship: Layer 2s to L1, stablecoins to each other
- Sufficient volume: Both pairs must be liquid
- Cointegration: Long-term equilibrium exists (tests with Johansen test)
import pandas as pd
from scipy.stats import pearsonr
def find_cointegrated_pairs(symbols, data):
candidates = []
for i, sym1 in enumerate(symbols):
for sym2 in symbols[i+1:]:
corr, p_value = pearsonr(data[sym1], data[sym2])
if corr > 0.75:
residuals = data[sym1] - (data[sym2] * corr)
adf_stat = adf_test(residuals)
if adf_stat < 0.05:
candidates.append((sym1, sym2, corr))
return candidates
Cointegration Analysis
What is Cointegration?
Two non-stationary series are cointegrated if their linear combination is stationary. In plain English: they move together over time, and deviations from that relationship eventually revert.
For BTC and ETH:
- BTC price: $42,000 (non-stationary — trends up/down)
- ETH price: $2,300 (non-stationary — trends up/down)
- Spread: BTC - (18 × ETH) = $40 (stationary — oscillates around mean)
Finding the Hedge Ratio
Use ordinary least squares regression to find the optimal ratio:
from sklearn.linear_model import LinearRegression
def get_hedge_ratio(price1, price2):
X = price2.reshape(-1, 1)
y = price1
model = LinearRegression().fit(X, y)
hedge_ratio = model.coef_[0]
intercept = model.intercept_
return hedge_ratio, intercept
beta, alpha = get_hedge_ratio(btc_prices, eth_prices)
spread = btc - (beta * eth)
Mean Reversion Strategies
Using Z-Scores
Standardize the spread to detect extremes. When z-score > 2, the spread is unusually wide (trade opportunity):
def mean_reversion_signal(spread, lookback=20):
mean = spread.rolling(window=lookback).mean()
std = spread.rolling(window=lookback).std()
z_score = (spread - mean) / std
if z_score[-1] > 2.0:
return "LONG_SPREAD"
elif z_score[-1] < -2.0:
return "SHORT_SPREAD"
else:
return "NEUTRAL"
Exit Rules
Close when spread returns to mean (z-score → 0) or loss threshold (stop at z-score reversal):
def check_exit(entry_z_score, current_z_score, entry_price):
if abs(current_z_score) < abs(entry_z_score) * 0.5:
return "EXIT", "profit_target"
if (entry_z_score > 0 and current_z_score < entry_z_score + 1.0):
return "EXIT", "stop_loss"
elif (entry_z_score < 0 and current_z_score > entry_z_score - 1.0):
return "EXIT", "stop_loss"
return "HOLD", None
Backtesting Stat Arb Strategies
Key metrics for stat arb:
- Win rate: >55% (you're catching reversions consistently)
- Avg win/loss ratio: >1.2 (gains outweigh losses)
- Sharpe ratio: >0.8 (returns per unit of risk)
- Max drawdown: <-15% (system stays safe)
def backtest_pairs_strategy(price1, price2, hedge_ratio):
spread = price1 - (hedge_ratio * price2)
mean = spread.rolling(20).mean()
std = spread.rolling(20).std()
z_score = (spread - mean) / std
trades = []
position = None
for i in range(len(z_score)):
if position is None:
if z_score[i] > 2.0:
position = {"entry": spread[i], "z_entry": z_score[i], "idx": i}
else:
exit_reason = check_exit(position["z_entry"], z_score[i], spread[i])[1]
if exit_reason:
pnl = position["entry"] - spread[i]
trades.append({"pnl": pnl, "reason": exit_reason})
position = None
return pd.DataFrame(trades)
Adding Smart Money Intelligence
Enhance pairs trading by filtering trades with Smart Money confirmation:
def smart_money_pairs_strategy(symbol1, symbol2, z_score):
sm1 = get_smart_money_signal(symbol1)
sm2 = get_smart_money_signal(symbol2)
divergence_score = abs(sm1["composite"] - sm2["composite"])
if z_score > 2.0 and divergence_score > 0.3 and sm1["confidence"] != "VETO":
return "TRADE"
else:
return "SKIP"
Supercharge stat arb with Smart Money pairs signals
Filter mean reversion trades with whale consensus and derivatives data.
Start Trading Pairs →