This guide explains how pairs trading works, how to find pairs using cointegration, the trading rules, a worked example, how to implement it in Indian markets and the risks.
How pairs trading works
Some stocks move together because they share drivers: two large private banks, two IT services companies, two cement makers. Their prices rarely move in lockstep, but the gap between them may stay within a range over time.
When the gap stretches far from its usual level, a pairs trader:
- Buys the stock that has fallen behind, and
- Sells the stock that has run ahead,
then closes both when the gap returns to normal. If the whole market falls, the long loses and the short gains, roughly offsetting. The trade depends on the spread, not the market.
Correlation is not enough: cointegration
Two stocks can be highly correlated in their daily moves and still drift apart for years. Correlation measures how returns move together; it says nothing about whether the price gap will return to a stable level.
Cointegration is the property pairs traders need. Two prices are cointegrated if a combination of them, such as stock A minus a multiple of stock B, tends to return to a stable average. Engle and Granger formalised this in 1987, work recognised with the 2003 Nobel prize in economics.
Testing for cointegration
The Engle–Granger method:
- Regress the price of stock A on the price of stock B over a formation period, such as one year. The slope is the hedge ratio, β.
- Compute the spread: A − β × B.
- Test the spread for stationarity with an Augmented Dickey–Fuller (ADF) test. A low p-value, such as below 0.05, suggests the spread tends to revert.
The pairs cointegration tester runs these steps for two NSE stocks.
The trading rules
- Formation: test candidate pairs from the same sector on a year of data and keep those that pass the cointegration test.
- Standardise: convert the spread into a z-score: (spread − its average) ÷ its standard deviation.
- Entry: when the z-score rises above +2, sell A and buy β units of B. When it falls below −2, buy A and sell β units of B.
- Exit: close both legs when the z-score returns to 0.
- Stop: close both legs if the z-score reaches ±3.5, or after a maximum holding period.
- Re-test: repeat the formation step regularly, because relationships change.
A worked example
This is a hypothetical example.
- Two private bank stocks, A and B, pass the cointegration test with a hedge ratio of 0.8. The spread A − 0.8 × B averages ₹120 with a standard deviation of ₹15.
- One day the spread reaches ₹153, a z-score of 2.2. The trader sells stock A and buys 0.8 times as many shares of B in rupee-matched terms.
- Over the next nine trading days, the spread narrows to ₹121, close to its average.
- The trader closes both legs. The profit comes from the spread narrowing by about ₹32 per unit of A, before costs, regardless of whether the banking sector rose or fell.
Pairs trading in Indian markets
Holding short positions overnight in stocks is not possible in the cash market for most traders, because intraday short sales must be closed the same day. Common approaches:
- Stock futures: use futures for both legs, which allows overnight shorts. Lot sizes rarely match the hedge ratio exactly, so the trader picks the combination of lots closest to it.
- Securities lending and borrowing (SLB): borrow shares to short in the cash market, for an additional fee.
- Intraday pairs: trade the spread on intraday data and close both legs each day.
Futures also carry margin requirements and expire monthly, so positions held across expiry must be rolled.
Risks
- The relationship breaks. A merger, a regulatory change or a company-specific event can permanently change one stock. The spread then keeps widening.
- Leg mismatch. Lot sizes and rounding leave some net market exposure.
- Execution risk. Both legs must be traded together; a delay on one leg changes the position.
- Costs. Two legs to enter and two to exit, plus rolling and borrowing costs.
- Crowding. Popular pairs can attract many traders, reducing the edge.
Automating pairs trading
Pairs trading needs a running calculation of the spread and z-score and simultaneous orders on two instruments, which suits automation. QuantPower's strategy builder and backtesting engine let you test and run rule-based strategies; check that both legs and your hedge ratio are supported for the instruments you choose before relying on a pairs strategy. Our guide on how to backtest trading strategies explains how to test it fairly.
Start your free trial
Connect your broker, build a strategy and test it on paper before a single live order goes out.
Backtesting tips
- Separate formation and trading periods. Choose pairs on one period, then trade them on the next.
- Avoid survivorship bias. Include stocks that were later delisted or merged.
- Model both legs' costs and futures rolls.
- Track how often pairs break and how much a broken pair costs.
Frequently asked questions
What is pairs trading?
Buying one stock and selling a related one when the gap between them is unusually wide, and closing both when it returns to normal.
What is the difference between correlation and cointegration?
Correlation measures whether returns move together. Cointegration measures whether the price gap tends to return to a stable level, which is what pairs trading needs.
Can I short stocks overnight for pairs trading in India?
Not in the regular cash market. Traders use stock futures or securities lending and borrowing for overnight short positions.
Is pairs trading risk-free?
No. If the relationship between the stocks breaks, the spread can keep widening and cause large losses.
Sources
- Engle, R. F. and Granger, C. W. J. (1987). Co-Integration and Error Correction: Representation, Estimation, and Testing. Econometrica, 55(2), 251–276
- Gatev, E., Goetzmann, W. N. and Rouwenhorst, K. G. (2006). Pairs Trading: Performance of a Relative-Value Arbitrage Rule. Review of Financial Studies, 19(3), 797–827
- Vidyamurthy, G. (2004). Pairs Trading: Quantitative Methods and Analysis. Wiley
