Skip to main content
Blog home
Newsletter
News
Video
Podcast
Reading list
Wright Brief
Sign In

Pairs Trading Strategy - Nifty & Bank Nifty | Statistical Arbitrage

Explains pairs trading: correlation, co-integration, stationarity, the spread equation, a Nifty and Bank Nifty example, and the main risks.

Listen to this article
Audio · ~8 min
Add as a preferred source on Google
Pairs Trading Strategy - Nifty & Bank Nifty

What is Pairs Trading?

Pairs trading is a market-neutral, statistical arbitrage technique. It pairs a long position in one security with a short position in another security that has historically moved with it. The aim is to capture the change in the relative price of the two, rather than the direction of the market as a whole.

This article explains the core concepts, the mathematics behind the method, how pairs are commonly selected, and a worked example using the Nifty 50 and Bank Nifty indices. It describes how the method works; it does not say that it will work in any given period.

Free tool

See what markets are pricing in

Live indices, sector moves and market breadth — the backdrop to every story we publish.

Open Market Tracker

The Idea Behind Pairs Trading

The premise is that the spread between two related securities fluctuates around a long-run average. When the spread moves unusually far from that average, the strategy takes a long position in the relatively cheaper leg and a short position in the relatively richer leg. It then closes both when the spread returns toward its average.

Nifty 50 and Bank Nifty are a convenient illustration because banking is a large weight in the Nifty 50, so the two indices share a common driver. Their co-movement is high but not perfect, and the gap between them changes over time.

Mathematics Behind Pairs Trading

Four statistical ideas are used.

  • Correlation measures how closely the returns or prices of two securities move together, on a scale from -1 to +1.
  • Co-integration looks at the long-term relationship. Two price series can each wander without limit, yet a particular linear combination of them can stay bounded. That is co-integration.
  • Stationarity means a series has a roughly constant mean and variance over time. Only a stationary series can be described as mean reverting.
  • Mean reversion is the tendency of a stationary series to return toward its average after a deviation.

The Engle-Granger two-step method is a common co-integration test. First, regress one price series on the other. Second, test the regression residuals for a unit root using the Augmented Dickey-Fuller (ADF) test. If the residuals are stationary, the pair is said to be co-integrated.

How Pair Trading Works

The usual workflow has five steps.

  1. Universe and pair selection. Candidates are often grouped by sector or business similarity. Statistical grouping such as hierarchical clustering, which builds a dendrogram from the distance between price histories, is another common approach.
  2. Testing. Candidate pairs are checked for correlation and co-integration over a look-back window.
  3. Spread construction. A hedge ratio is estimated, normally by regression, and the spread is defined as the residual.
  4. Signals. The spread is standardised (a z-score) and entry and exit thresholds are set.
  5. Risk controls. Position size, stop levels and periodic re-testing of the relationship are specified.

The flowchart below summarises the process.

How Pair Trading Works

The Pair Trading Equation

The spread can be written as a linear combination of the two prices:

Spread = P1 - β × P2 - α

  • P1 is the price of the first asset and P2 the price of the second.
  • β is the hedge ratio, the coefficient of the second asset in the linear combination. It is typically estimated by linear regression.
  • α is a constant that centres the spread on its historical average.

When the spread is far above its mean, the rule goes short P1 and long β units of P2. When it is far below, the position is reversed. The position gains if the spread moves back toward its mean and loses if it moves further away.

Explore the best quant strategies using deep machine learning & AI to predict market movements in Indian stock markets.
Explore Portfolios
The Wright Brief · free weekly

Get research like this in your inbox

The week’s research that mattered, in five minutes. Joined by 2L+ investors.

Worked Example: Correlation and Co-integration

The first step in the Nifty and Bank Nifty example is to compare the price data of the two indices.

Pairs Trading

In the sample used for this illustration the two series showed a correlation of about 80%. Correlation alone is not enough, because two trending series can look correlated without any lasting link. A co-integration test addresses that gap by testing whether a stable long-run relationship exists.

Stationarity and mean reversion

Running the standard co-integration test from Python's statsmodels library on the sample indicated that the two series were co-integrated. The next step is to find a stationary relationship to trade. A plot of the raw spread between the two series shows no obvious tendency to return to a mean.

Pairs Trading

The regression residuals between the two series, however, look stationary, and the ADF test on them agrees. This is why the hedge ratio is estimated by regression rather than by simply taking the price difference or ratio.

Pairs Trading

A stationary residual means that large deviations have, historically, been followed by a drift back toward the average. That is a statement about the sample, and relationships can change.

Pair Trading Stock List

A pair trading stock list is a set of securities that tend to move together because they share an industry, customer base or macro driver. Such lists are usually built from sector classification first and then screened statistically. The pairs below are widely used textbook examples of similar businesses. Their inclusion is illustrative and is not a recommendation, and a pair's statistical relationship must be re-tested before use.

Stock AStock BCommon link
Coca-ColaPepsiCoBeverages
ShellBPIntegrated oil and gas
WalmartCostcoLarge-format retail
VisaMastercardCard payment networks
Exxon MobilChevronIntegrated oil and gas
FordGeneral MotorsAutomobiles

In India, banks, IT services companies, FMCG firms and oil marketing companies are examples of groups with shared drivers. In the Indian cash market, short positions in delivery trades are generally not available to retail participants, so short legs are usually taken through single-stock or index futures. Margin, lot size and cost rules for those contracts are set by the exchanges and SEBI and change from time to time, so the current circulars should be checked.

Implementing the Strategy in Code

The example was written with the Zipline backtesting library. The first step is an initialisation function that defines the global variables. In the example, commission and slippage were set to zero, which is a simplification that real trading does not share.

Implementing Pairs Trading Strategy

Next, a handler function receives incoming data at every minute bar and updates the spread.

Pairs Trading

Finally, the model produces a trading signal and places orders. In the example the rule is to buy the relatively undervalued index and sell the relatively overvalued one when the standardised spread is beyond 1.5 in either direction, and to close both positions when it falls inside 0.5. Order weights depend on the signal and a constant. The thresholds are parameters, not fixed values, and different choices produce different results.

Pairs Trading

Pairs Trading

Characteristics and Risks of Pairs Trading

Characteristics

  • The position is designed to be market neutral, so its result depends mainly on the relative performance of the two legs rather than on the market direction.
  • Offsetting long and short legs are intended to reduce exposure to broad market (systematic) risk.
  • The method relies on statistical regularities in historical data, which are assumptions, not guarantees.

Risks

  • Relationship breakdown. Corporate events, regulation, mergers or economic shifts can permanently change how two securities relate, and the spread may not revert.
  • Divergence before convergence. A spread can widen well beyond its historical range before it narrows, creating losses on open positions.
  • Execution risk. Two legs must be traded at the same time, so timing gaps and slippage matter.
  • Leverage and margin. Short positions and futures require margin, which magnifies gains and losses.
  • Costs. Frequent trading adds brokerage, taxes, impact cost and financing costs, which can erode small spread gains.
  • Model risk. Results from a backtest depend on the sample period, parameters, and cost assumptions; the example above used zero costs and does not represent live results.

Past results in a backtest do not indicate what a live strategy will earn, so no performance figures are quoted here.

Further Reading

  1. Best Quantitative Investment Strategies
  2. Types of Quant Investment Strategies
  3. Best Quant Funds That Beat The Stock Market
  4. Artificial Intelligence in Investing
  5. Trade to Trade (T2T) Stocks: What It Is & How to Trade?
Explore the best quant strategies using deep machine learning & AI to predict market movements in Indian stock markets.
Explore Portfolios
Free tool

Track the factors behind this research

Momentum, value, quality and low-vol — updated factor performance for Indian markets.

Open the factor heatmap

FAQ

What are the key components of pairs trading?

Pair selection, co-integration analysis, spread measurement, entry and exit signals, and risk management.

What criteria are used when selecting pairs?

High historical correlation, similar sector or business drivers, and a statistically stable co-integrating relationship.

What are typical entry and exit rules?

A position is opened when the standardised spread moves beyond a chosen threshold and closed when it returns toward the mean or hits a predefined limit.

How is risk managed in pairs trading?

Common tools are stop levels on the spread, limits on position size relative to volatility, and periodic re-testing of the pair.

What analysis techniques are used?

Co-integration tests such as Engle-Granger with ADF, correlation analysis, historical backtesting and risk modelling.

This article is for educational purposes only and is not investment advice.

Frequently asked questions

What is covered in Pairs Trading Strategy - Nifty & Bank Nifty | Statistical Arbitrage?

Pairs trading is a market-neutral, statistical arbitrage technique. It pairs a long position in one security with a short position in another security that has historically moved with it. The aim is to capture the change in the relative price of the two, rather than the direction of the market as a whole.

What is Pairs Trading?

Pairs trading is a market-neutral, statistical arbitrage technique. It pairs a long position in one security with a short position in another security that has historically moved with it. The aim is to capture the change in the relative price of the two, rather than the direction of the market as a whole.

What does this article say about The Idea Behind Pairs Trading?

The premise is that the spread between two related securities fluctuates around a long-run average. When the spread moves unusually far from that average, the strategy takes a long position in the relatively cheaper leg and a short position in the relatively richer leg.

What does this article say about Mathematics Behind Pairs Trading?

Correlation measures how closely the returns or prices of two securities move together, on a scale from -1 to +1; Co-integration looks at the long-term relationship. Two price series can each wander without limit, yet a particular linear combination of them can stay bounded. That is co-integration.

What does this article say about The Pair Trading Equation?

P 1 is the price of the first asset and P 2 the price of the second; β is the hedge ratio, the coefficient of the second asset in the linear combination. It is typically estimated by linear regression; α is a constant that centres the spread on its historical average.

Disclaimer: Investment in securities market are subject to market risks. Read all the related documents carefully before investing. Registration granted by SEBI, membership of a SEBI recognized supervisory body (if any) and certification from NISM in no way guarantee performance of the intermediary or provide any assurance of returns to investors.

The content in these posts/articles is for informational and educational purposes only and should not be construed as professional financial advice and nor to be construed as an offer to buy/sell or the solicitation of an offer to buy/sell any security or financial products. Users must make their own investment decisions based on their specific investment objective and financial position and using such independent advisors as they believe necessary.

Wryght Research & Capital Pvt (Brand name: Wright Research) is a SEBI Registered Portfolio Manager Reg No: INP000007979 (Validity: Apr 03, 2023 – Perpetual) and a SEBI Registered Research Analyst No: INH000017295 (Validity: Jul 03, 2024 – Perpetual), with its registered office at 103, Shagun Vatika Prag Narayan Road, Lucknow, UP, 226001 India and CIN: U67100UP2019PTC123244. Past performance may or may not be sustained in future. Performance provided there in is not verified by SEBI. Investment in securities is subject to market and other risks, and there is no assurance or guarantee that the objectives of any of the strategies of the Portfolio Management Services will be achieved. Registration granted by SEBI, enlistment as RA with Exchange and certification from National Institute of Securities Markets (NISM) in no way guarantee performance of the intermediary or provide any assurance of returns to investors. Please read the Disclosure document carefully before investing. Securities quoted are for illustration only and are not recommendatory. Charts shown are for illustration only. For more information and disclosures, visit our disclosures page here.

Found this useful? Share it.
Explore related topics
Akashdeep Bhateja
About the author
Akashdeep Bhateja
Quantitative Developer | Wright Research, Wright Research

I Quantify uncertainty through Data

About the author
Himanshu Agrawal
Wright Research
Wright PMS · Portfolio Management Service

Put this research to work

The same 300+ factor research engine behind this article — applied to a professionally managed portfolio, end to end.

300+
Factors tracked
2L+
Investors
₹1,200+ Cr
Invested
SEBI
Registered PMS