Pairs Trading - A Real-World Guide - AlgoTrading101 Blog (2024)

What is pairs trading? Pairs trading is a trading strategy that involves buying one asset and shorting another.

The aim of pairs trading is to bet that, if the prices of 2 assets diverge, they will converge eventually.

How to (Visually) Test a Pairs Trading Strategy?

Visual testing is one of the fastest and most efficient way to get started with pairs trading.

We scan the charts of 2 assets to see if they diverge and converge. This is called a visual test.

If you find potential in your visual test, you can then move on to testing the strategy using code.

Steps:

  1. Choose 2 assets
  2. Chart the 2 assets
  3. Visually backtest your assets

Step 1: Choose 2 assets

Let’s look at a pairs trading involving these 2 assets:

  • FTSE 100 Index Futures (aka Z)
  • iShares MSCI United Kingdom Index (aka EWU)

Z is an asset that tracks a group of popular UK stocks.

EWU is an asset that also tracks similar stocks.

You can read more about Z and EWU in the appendix.

Note that this example is just for educational purposes. I don’t recommend you run this strategy live unless you understand it very well.

Step 2: Chart the 2 assets

We will use TradingView for this.

Step A: Open TradingView.com. Search for our first asset, Z.

Pairs Trading - A Real-World Guide - AlgoTrading101 Blog (1)

In the drop down list, expand the line on FTSE 100 Index Futures.

Choose Z1!.

What is Z1!?

Futures are different from stocks in a way that they expire, usually every quarter. This makes it difficult for us to chart prices over years.

Fortunately for us, Z1! exists. Think of Z1! as a stitched together chart of all the most actively traded contracts.

More info on what futures are: https://algotrading101.com/wiki/futures-finance/

Step B: Choose “Full-featured chart”.

Pairs Trading - A Real-World Guide - AlgoTrading101 Blog (2)

This will open up the FTSE 100 Index Futures chart.

It should look something like the chart below.

Pairs Trading - A Real-World Guide - AlgoTrading101 Blog (3)

Step C: Add EWU.

Click on the plus sign at the top of the page.

Type EWU in the pop up box.

Choose “EWU ISHARES TRUST MSCI UTD KINDGOM ETF NEW”

Pairs Trading - A Real-World Guide - AlgoTrading101 Blog (4)

You should see something like the chart below.

Pairs Trading - A Real-World Guide - AlgoTrading101 Blog (5)

Things are looking better!

You have now overlaid the chart of Z (blue) on the chart of EWU (red).

Step D: Clean up the chart.

Let’s clean up our chart.

Remove the volume bars. Click on the cross on the “Vol” symbol.

Pairs Trading - A Real-World Guide - AlgoTrading101 Blog (6)

Convert the blue area chart to a line.

Click on the area symbol at the top. Click on “Line”.

Pairs Trading - A Real-World Guide - AlgoTrading101 Blog (7)

You should see something like this now:

Pairs Trading - A Real-World Guide - AlgoTrading101 Blog (8)

Understanding how TradingView overlaid charts work

The way TradingView charts 2 overlaid assets is by percentage change.

The chart will equalise the left most point visually. Then the number on the y-axis is the change in price since the left most point.

Pairs Trading - A Real-World Guide - AlgoTrading101 Blog (9)

Using the above chart as reference, we see that the blue and red lines have the same starting point on 28th Dec 2016.

Z (blue line) moved up by 2.41% between 28th Dec 2016 to early March 2017.

EWU (red line) moved up by 15.5% between 28th Dec 2016 to early March 2017.

Step 3: Visually backtest your assets

Step A: Scroll back. Zoom in.

Let’s arbitrarily start from the beginning of 2019.

Scroll your chart back to 1st Jan 2019.

Zoom in such that the length of the chart is about 2 months. Zooming in allows us to analyse the chart in more detail.

Pairs Trading - A Real-World Guide - AlgoTrading101 Blog (10)

Step B: Look for price divergences

This is where the real testing starts.

Visually scan for divergences.

Pairs Trading - A Real-World Guide - AlgoTrading101 Blog (11)

In this case, I see a small divergence (green line).

Let’s hypothetically enter a trade on 28th Jan 2019. We buy $100 worth of Z (blue line) and short $100 worth of EWU (red line).

Let’s call this Trade A.

I drew a green line to make things clearer to follow but you don’t have to.

Step C: Shift the trade starting point to the left.

We shift it to the left to see how Z and EWU perform from 28th Jan 2019 onwards.

Pairs Trading - A Real-World Guide - AlgoTrading101 Blog (12)

Step D: Look for a convergence to exit the trade

Recall that we had long the blue line and short the red line on 28th Jan 2019.

Now, we are looking to close the trade.

We are looking for the prices to converge so that we can take a profit, or we are looking for further price divergences so that we will take a loss on the trade.

In this case, the prices converged since the blue line went up more than the red line.

Pairs Trading - A Real-World Guide - AlgoTrading101 Blog (13)

We spotted a convergence on 13th Feb 2019. Thus, we closed our trade.

From 28th Jan to 13th Feb 2019, Z (blue) went up by 6.56% and EWU (red) went up by 3.62%.

We bought $100 worth of blue. That is now $106.56; a $6.56 profit.

We shorted $100 worth of red. That is now $96.38; a $3.62 loss.

In total, we made $6.56 – $3.62 = $2.94 from an initial investment of $200.

2.94 divided by 200 = 1.47.

This is a 1.47% return for this trade!

Step E: Repeat steps B to D!

Keep doing this and record the profits and losses of your hypothetical trades.

Step F: Decide if you want to move on to actual backtesting with code.

If you see that divergences and convergences keep occurring, your strategy might have potential. If so, you can then consider moving on to actual backtesting with code.

We will talk about backtesting the pairs trading strategy, using 1) simple statistics and 2) a backtesting code library or software, in another article!

Some notes on visual testing

Check for data cleanliness

Some products do not have overlapping trading times.

If Asset A trades from 1am to 9am and Asset B trades from 12pm to 8pm, it will be difficult (not impossible) to execute a pairs trade.

If you use the end-of-day data, you might not be able to enter at the listed prices. Or, the end-of-day timings might be different for the 2 assets.

In other cases, there might be missing or wrong data.

Usually, we check for data cleanliness at the backtesting with code stage. We look for potential errors and try to get data from multiple sources to compare.

In our case, the closing time for Z and EWU are different.

Thus, we use the charts for preliminary analysis but can’t rely on it for live trading.

We need to get more accurate data and run backtests using those data. I trade with Interactive Brokers and I prefer to download data directly from Interactive Brokers for my analysis.

Avoid look ahead bias

This means that before you enter your hypothetical trade, don’t look at any potential exits.

If you look ahead in the graph to spot a profitable exit, and only decide to enter your trade because of that, your trades are biased.

That will be cheating as you are looking into the future!

Find average divergences and convergences

After a few trades, you can have a feel for the average divergences and convergences, i.e. deviations.

If you notice that the deviations are say, 3%, then you can use maybe 5% as your entry and exit points.

If the market condition changed and the average deviation is 10%, then a deviation of say 15% is appropriate as your entry and exit points.

The general idea here is that you want to enter and exit the trades when the deviations are slightly higher than the recent average.

How to Design a Pairs Trading Strategy for the Real-World?

Choose non-stock assets

Look for ETFs, futures, non-stock assets and other derivatives.

I do believe that in general, it is easier to find non-stock assets that move similarly.

Example: US bonds vs German bonds. Large cap ETFs vs small cap ETFs. Futures vs ETFs.

Do note that these pairs are well-watched by hedge funds. You should add your own flavour to the strategy (see the rest of this section) to outsmart your competiton.

If you are using stocks, use many pairs

As mentioned, if you are running a pair trading strategy on stocks, you probably need to run the strategy on more than a single pair of stocks.

I do think a single pair of stocks is not stable in today’smarket.

To do stocks pairs trading well, we should have many pairs (maybe hundreds) running at appropriately low position sizes.

This will even out the variance. The unpredictability of a single stock will not have an overly large effect on your portfolio.

Moreover, profits and losses from these idiosyncratic stock effects might cancel out because you have exposure to many stocks.

Choose 2 assets that are very similar

As mentioned, this is easier for futures and ETFs etc. Stocks are difficult.

It is harder to pairs trading 2 stocks if you are purely doing it quantitatively.

This is because it is hard to find 2 stocks that are very similar.

And no, 2 stocks from the same sector is not good enough.

However, if you choose to trade 2 stocks, consider doing it over a limited time period (e.g. during the COVID-19 crisis, cruise stocks move together) or use another qualitative layer of analysis.

Decent examples: Uber vs Lyft. Carnival vs Royal Caribbean Cruises.

Use your domain expertise

Even if you choose 2 decent assets, it is unlikely that you will make money if you blindly trade every divergence.

Thousands of hedge funds are scouring the face of the earth to find pairs that work. Any pair that you find have probably been watched like a hawk.

However, if you understand the assets well, you can choose and time your trades better than others.

You will know when to enter the trade and when not to, even as the 2 assets diverge and everyone else is entering the pairs trade.

Example: Longing near term lean hog futures and shorting the further expiry during the peak of Swine flu. You do this against the crowd as you are a virus expert and know if the crisis has been overblown. (Note: This is a hypothetical example. I have no idea how lean hog futures traded during the Swine Flu crisis).

Use another layer of analysis

Instead of just looking at 2 assets, look at what leads those assets.

A leading asset is something that moves before your asset moves.

If you are trading a US stock ETF vs a European stock ETF, find something that leads these ETFs.

Maybe you can use the US 2-10 bond spread to lead the US stock ETF and a German 2-10 bond spread to lead the European stock ETF.

Another example is that your pairs trade might only work during volatile periods. In this case, you might only want to execute it during the periods that work.

Limit your trades to certain time periods

Certain assets diverge during certain hours and converge during other hours.

Maybe some of them don’t move as expected on Mondays, December or some other time-based conditions.

Example: Assets behave differently near a big macro-economic or earnings announcements.

Another example is that certain assets diverge or converge during crisis times. You might be able to find opportunities that only exist during this period.

Adjust the weights

Your trades don’t have to be $1 of Asset X vs $1 of Asset Y.

If Asset X is twice as volatile as Asset Y, you can trade 2 units to 1 unit.

Example: Carnival cruises have a beta of 1.97. Royal Caribbean cruises have a beta of 2.52 (based on investing.com as of 22th June 2020). Thus, you might want to enter 4 shares of Carnival for every 5 shares of Royal Caribbean in order to hedge against market movements.

Entering an equal dollar amount for both assets usually doesn’t work, especially if the 2 assets are very different.

For instance, a stock might move 1% a day on average, while a cryptocurrency coin moves 5% a day on average. Buying and shorting $1,000 on each will bias the impact of your pairs trade towards the cryptocurrency.

You need to buy 5 times more stock than the crypto coin.

For futures, the dollar value per unit of movement is usually different for different future contracts.

Moreover, the average price movement of the different future contracts are different too. Thus, we need to account for these to make sure the size our bets right.

Consider betting on divergence

Instead of entering a trade on divergence and betting on convergence, you can enter a trade on divergence and bet that there is even more divergence.

Is this case, you are betting that the 2 assets will become increasingly different from each other as time goes by.

No home runs needed

You don’t need your pairs trade to return huge profits per trade. A slight edge would be sufficient.

If you make 0.5% per trade (net of fees) and manage to fire 5 trades a month, you will make 2.5% a month.

Do size your bet appropriately. In general, the lower the expected return, the smaller your bets.

Trade many pairs

This reduces the reliance on a single pair.

Imagine if we identified and are trading 20 pairs independently. We would have allocated 5% of our capital per pair.

If a single pair breaks down, we still have 19 other pairs. Our portfolio will not be severely affected.

Another way to do this is to run a “pairs” trading strategy that consists of more than 2 assets per strategy.

Quantitative hedge funds do this and they might have thousands of stocks and make thousands of trades in their high-frequency strategy.

We won’t cover that in this article. This is an interesting read if you want to know more: Statistical Arbitrage

Pairs Trading - A Real-World Guide - AlgoTrading101 Blog (2024)

FAQs

What is a pairs trading a real world profitable strategy? ›

A pairs trade strategy is based on the historical correlation of two securities. The securities in a pairs trade must have a high positive correlation, which is the primary driver behind the strategy's profits. A pairs trade strategy is best deployed when a trader identifies a correlation discrepancy.

Does pairs trading still work? ›

Pairs trading can be profitable but it requires significant research, close monitoring, clear rules, and discipline.

What is the algorithm for pairs trading? ›

According to The Definitive Guide to Pairs Trading [5], there are 3 main steps to building a pairs trading algorithm: pair selection, spread modeling, and trading rules development. Pair selection aims to find co-moving assets with similar returns and mean-reverting spread.

What is the pair trading equation? ›

Pair Trading Equation

P_2 is the price of the second asset in the pair. β is the hedge ratio or the coefficient of the second asset's price in the linear combination. α is the constant term in the linear combination. The goal is to find a good pair of assets based on how well they have gone together in the past.

What is the simplest most profitable trading strategy? ›

One of the simplest and most widely known fundamental strategies is value investing. This strategy involves identifying undervalued assets based on their intrinsic value and holding onto them until the market recognizes their true worth.

Which trading strategy has the highest success rate? ›

Indicator-Based Directional Trading

This strategy uses an indicator to determine the direction of the trade. The indicator provides a clear signal when it's time to enter or exit a trade, making it easy to work with. Traders who use this strategy can expect to see consistent results and high success rates.

What is the success rate of pairs trading? ›

Evidence of Profitability

Gatev, William Goetzmann, and K. Geert Rouwenhorst, the authors attempted to prove that pairs trading is profitable. Using a large set of data from 1967 to 1997, the trio found that over any six-month trading period, the pairs trade averaged a +12% return.

What is the easiest pair to trade? ›

Beginners might find the AUD/USD pair to be an excellent choice, since it is more predictable and less likely to spike or drop suddenly. In many studies, this pair has also been cited as one of the least volatile. In conclusion, the best currency pairs to trade for beginners are EUR/USD, GBP/USD, USD/JPY.

What are the disadvantages of pairs trading? ›

These risks include:
  • Correlation breakdown: If the correlation between the two stocks in the pair breaks down, the strategy may not work as expected.
  • Market-wide events: Systemic market events, such as financial crises or sudden market volatility, can impact both legs of the pair trade.

How to build a pair trading strategy? ›

In order to profit from a pairs trading correlation, the trader must identify when the assets are deviating in value, calculated as the 'standard deviation'. They can then choose to buy the long position that is undervalued and short-sell the overvalued position.

How do you identify pairs for pair trading? ›

Correlation analysis can be used to identify interesting potential pairs, but beware of spurious correlation. Competing companies in the same sector make natural potential pairs. Certain companies have several classes of shares trading simultaneously (e.g. common and preferred) which should move largely in unison.

What is the Z score in pairs trading strategy? ›

σ is the standard deviation of the rolling window. The Z-score measures how far the current ratio of the two asset prices is from its historical mean. When the Z-score surpasses a predefined threshold, typically +1 or -1, it generates a trading signal.

How many pairs should a beginner trade? ›

While there are many pairs you could trade for most traders, it is best to stick to one to five pairs and become an expert. There is always a temptation to change markets when making losses. Other forex pairs can appear to have stronger trends, higher volatility, and easier-to-make profits.

What is the formula for pair combinations? ›

n choose k = n! / ((n-k)! k!)

(n(n-1)(n-2)!) / ((n-2)! 2!) = n(n-1) / 2! = n(n-1) / 2 which is our formula for the number of pairs needed in at least n statements.

What is an example of a pairs trade? ›

So, a pairs trader might look to diversify risk by combining positions on Coca-Cola and Pepsi. For example, if Coca-Cola was trading below its range and Pepsi above it, they might match a long position in Coca-Cola with a short position on PepsiCo.

What is an example of a pairs trade strategy? ›

Understanding pairs trading with an example

Say two stocks — A and B — belong to the IT sector and have historically been highly correlated, with a correlation coefficient of 0.87. On account of positive developments within the information technology sector, the price of stock A shoots up.

What is the most profitable type of trading? ›

The most profitable form of trading varies based on individual preferences, risk tolerance, and market conditions. Day trading offers rapid profits but demands quick decision-making, while position trading requires patience for long-term gains.

What is the most consistently profitable option strategy? ›

The most successful options strategy for consistent income generation is the covered call strategy. An investor sells call options against shares of a stock already owned in their portfolio with covered calls. This allows them to collect premium income while holding the underlying investment.

What is the most profitable option trading? ›

Bullish Option Trading Strategies
  • 1) Bull Call Spread.
  • 2) Bull Put Spread.
  • 3) Bull Call Ratio Backspread.
  • 4) Synthetic Call.
  • 5) Bear Call Spread.
  • 6) Bear Put Spread.
  • 7) Strip.
  • 8) Synthetic Put.
Feb 15, 2024

Top Articles
Latest Posts
Article information

Author: Tuan Roob DDS

Last Updated:

Views: 6553

Rating: 4.1 / 5 (62 voted)

Reviews: 93% of readers found this page helpful

Author information

Name: Tuan Roob DDS

Birthday: 1999-11-20

Address: Suite 592 642 Pfannerstill Island, South Keila, LA 74970-3076

Phone: +9617721773649

Job: Marketing Producer

Hobby: Skydiving, Flag Football, Knitting, Running, Lego building, Hunting, Juggling

Introduction: My name is Tuan Roob DDS, I am a friendly, good, energetic, faithful, fantastic, gentle, enchanting person who loves writing and wants to share my knowledge and understanding with you.