Strategy lab
Every strategy from 151 Trading Strategies and all 101 Formulaic Alphas as formulas you can edit and backtest on ten years of daily stocks, ETFs, futures, forex and crypto data. Free, in your browser.
3.8StocksBacktest
Pairs trading
Two stocks that usually move together drift apart; short the one that rose more and buy the one that rose less, betting they reconverge. Here the classic Coca-Cola and PepsiCo pair.
Note. Pick any two stocks from the asset filter to test another pair.
Edit anything; the result updates as you type. Lines like window = 20 become sliders.
AssetsLoading…
Hypothetical backtests on daily closes with no slippage unless you add costs. Survivorship bias applies: the stock list is today’s large caps. For learning, not investment advice. Data: Yahoo Finance via yfinance.
- Source
- 151 Trading Strategies
- Section
- 3.8 · Stocks
- Asset class
- Stocks
- In the lab
- Full backtest
Pairs trading (3.8)
Two stocks that usually move together drift apart; short the one that rose more and buy the one that rose less, betting they reconverge. Here the classic Coca-Cola and PepsiCo pair.
Key equation
Lab formula
// Short the relative winner of the pair over the past week
lookback = 5
r = log(close / delay(close, lookback))
-(r - market(r))Pick any two stocks from the asset filter to test another pair.
How the backtest works
The formula is evaluated for every asset on every day. Its values become positions at that day’s close, using the portfolio rule you pick, and earn the next day’s close-to-close return. Costs are charged in basis points on the amount traded. Everything runs in your browser on daily data from Yahoo Finance, adjusted for splits and dividends.
More in Stocks
- 3.1 Price momentum
- 3.2 Earnings momentum
- 3.3 Value
- 3.4 Low-volatility anomaly
- 3.5 Implied volatility
- 3.6 Multifactor portfolio
Source: Kakushadze, Z. and Serur, J. A. (2018). 151 Trading Strategies. Palgrave Macmillan. SSRN 3247865. Summaries are our own.