Lesson 9 of 15
Pairs Trading (Spread & Entry)
Pairs Trading
Pairs trading is a market-neutral strategy that exploits the co-movement of two related assets. When the spread between them deviates from its historical norm, you bet on reversion.
Spread
The spread is the difference between two price series, adjusted by a hedge ratio:
spread[i] = series_a[i] - hedge_ratio * series_b[i]
Entry Signal
To generate signals, compute the z-score of the entire spread series and use an entry threshold:
mean = mean(spread)
std = population std(spread)
entry_z = entry_threshold * std
- +1 (short spread):
spread[i] > entry_z(spread too wide, expect reversion) - -1 (long spread):
spread[i] < -entry_z(spread too narrow, expect expansion) - 0: otherwise
Task
Implement:
spread(series_a, series_b, hedge_ratio)pairs_signal(spread_series, entry_threshold=1.5)
Python runtime loading...
Loading...
Click "Run" to execute your code.