*Note: Please read the disclaimer. The author is not providing professional investing advice.*

While waiting for results from the CFA exam to come in, I thought I’d cover an example of a trading technique I’ve recently begun test driving, **pairs trading**.

Pairs trading was something I thought I’d invented! Alas like many of my so-called brilliant flashes of insight, a little googling revealed that not only had others come up with it decades earlier, but their techniques were more elegant and robust than my first stab.

The basic idea behind pairs trading is this:

- 1. Find a pair of stocks (or ETFs) whose prices tend to move together.

- 2. If the price movements are indeed highly correlated, then on most days the price per share of Stock A

**divided by**the price per share of Stock B should come out to be about the same number, within a small range.

- 3. But occasionally, you might notice a significant divergence from this “average” ratio. If you do, enter a pairs trade. This will involve simultaneously shorting one of the stocks while taking a long position in the other.

- 4. At some time in the future when the price ratio (hopefully) reverts to the mean, exit the pair trade, wire that (almost) riskless profit to your checking account, and take your wife out to a nice dinner.

Now anyone familiar with the basic workings of the stock market knows that you can make money in either an up or down market, by using both long and short positions. But the catch is, *you have to know which way the market is heading* in order to know which to use. Easier said that done, even for the pros.

But with pairs trading, you are performing trades that are (theoretically, at least) **market neutral**. As long as the pair ratio reverts to the mean, you make money – regardless of whether you re-arrive at the mean by the short decreasing in price, the long increasing in price, or both. *You don’t have to know or even care which way the market is heading.*

A second benefit is that pair trade positions can be viewed as a nice additional asset class for one’s portfolio, since they should be relatively uncorrelated with your traditional asset classes consisting of long positions in various domestic and international indexes.

So let’s illustrate pair trading by an example.

It’s January 1, 2007 and I’m thinking of trying out some pair trading in the new year. Now I could code up a script to perform correlations between the historical price movements of hundreds of stocks in order to find those that move together, but I have a simpler idea.

I have an inkling that Lowe’s (LOW) and Home Depot (HD) might be highly correlated. To me at least, they are roughly *equivalent* businesses, and which one I go to depends solely on which one is closer when I need something. Let’s examine their closing price-per-share data from the previous year…

They definitely do seem to move together. And I could compute a correlation on the price movements to confirm what I see visually. But perhaps a more important question is not is the relationship between LOW and HD highly correlated, but rather is it **mean-reverting**. Because my making a profit depends upon this.

So I now plot the price of LOW **divided by** the price of HD, what we’ll call the LOW/HD *pair ratio*…

…and this indeed seems to be what I was looking for – a price ratio (blue curve) that appears to oscillate around a mean (purple line). And I’ve also added the 1-, 2-, and 3-standard deviation lines just to get a feel for how far away from the mean the oscillations might go.

So, we appear to know the habits and patterns of this animal. Time to set a trap and lie in wait…

But this creature is dangerous and could eat us alive, so we have to be careful. We see that in 2006 the pair ratio often makes excursions 1 or 2 standard deviations above or below the mean. We could spring the trap then but we might end up making lots of trades for tiny profits, and the commissions could eat us alive too.

Examining the figure above, we do see **one time** when the ratio appeared to go almost 3 standard deviations from the mean. Therefore that will be our criteria for 2007. **If we see an excursion +/- 3 standard deviations from the mean, we’ll enter a pair trade. And whenever the ratio returns to the mean, we’ll exit both positions.**

And here’s what 2007 ended up looking like.

On July 10, the LOW/HD ratio fell 3 standard deviations **below** the mean, so we buy LOW long at $29.46 and sell HD short at $38.98.

And a little over a month later, on August 16, 2007, the ratio reverted to the mean so we exited both positions. This turned out to mean selling LOW at $26.42 and covering our HD short at $31.79.

So our long LOW position was a 10.3% loss but the short HD position was a 22.6% gain. Therefore our equal dollar positions averaged out to a **6.1% gain**.

We’re now back in cash and ready to spring the trap again should a new opportunity arise.

And indeed it shortly does. On September 24, 2007 the ratio has now gone 3 standard deviations **above** the mean. So this time we end up doing the reverse as the previous time. We take a long position in HD at $33.02 and sell short LOW at $30.10.

And a little less than 2 months later, the ratio has once again reverted to the mean. On November 20, 2007 we sell our long HD position at $27.78 and cover our short LOW position at $22.25.

So we take a 15.9% loss on HD but get a 35.3% gain on LOW. This averages to a **9.7% gain**.

And this is the last time we get to pounce in 2007. Thus our two pair trades compounded to a **+16.5% annual return**! Not bad, considering buy-and-hold would have given you a 27% loss in LOW and 31% loss in HD. (I told you their prices move together…)

And further, we were only committed to a pair trade about 3 months of the whole year. While we were waiting we could have kept our money in a low-volatility bond index fund (e.g. VFISX or VBMFX) to generate fixed income in the mean time. I haven’t run the exact dates but these returned 8% and 7% respectively if you’d held them for all of 2007. So maybe it isn’t unrealistic to assume that this would have pushed our +16.5% past the 20%+ return mark.

In balance, though this example used real historical data, it’s probably making pair trading look easier than it is. Some companies diverge and don’t mean revert. And should your mean and standard deviations be based on last year or multiple years? A fixed start and stop date or a moving average? Should you jump in at 2, 2.5, or 3 standard deviation excursions – and when do you exit (for both profit and for stop loss).

Backtest to derive your own optimized parameters and have fun.

Lumi, Once again ..amazing thread…

Hey, Nice blog (and article) you got here. Pretty nice read

Hey nice blog… I am planning to do a dissertation on pairs trading…. Could you suggest an aspect of pairs trading on which i could do my dissertation…

Hi Srinivas,

Thanks for the comments.

I think your best bet is probably to check out the following book (from one of your countrymen, I believe) for a particular aspect that grabs you.

Pairs Trading: Quantitative Methods & Analysis

Best of luck on your dissertation. I’m kinda jealous of all the time you’ll have to tinker with pairs…

Lumilog

Hey thanks a ton,

Ive ordered for the same book and also another one from whistler. Will start as soon as i get them. Also ill try and post you about my progress if its k with you

Thanks

This is good stuff. Can I ask what resource you use to create your charts. I seem to have gone as far as I can go with Excell, unless there is a way to add the lines noting the standard deviations on the slide with the prices ratios. Any thoughts? Thanks.

thanks for writing mike.

i’m using matlab for the plots. i think you could probably add those standard deviation lines in Excel by creating additional data series.

for example, on that last plot above if you had a data series that just had 2 x variables (0, 250) and two y variables (0.9, 0.9), it should draw that top green curve for you.

hope that works for you! – lumi

Great article but I have a query regarding the dates used for calculating the mean.

Am I to understand that the mean is based on the prices from 1/1/06 to 31/12/06? In that case by 10/7/07 (July 10th) the mean was 6 months out of date.

If a strategy such as this is used when should the mean and std devs be recalculated?

ah, that is one of the big questions. do you use a simple moving average or exponential? how many days should it be estimated over? should you enter a pairs trade when you see 2, 3, 4, standard deviations from the mean? should you exit when it returns to the mean or just drops down 1 or 2 standard deviations?

you understood correctly that the mean I used for all of 2007 was just one number, computed over 2006. of course that isn’t necessarily the best way – there are just so many different parameters you can turn the dials on and what is optimal varies from pair to pair. ideally i like to look for a pair that is so similar that the mean ratio doesn’t vary much over short periods of time.

I LOVE TO LEARN THIS TYPE OF PAIR TRADING

I WOULD LIKE TO KNOW ABOUT SOFTWARE WHICH WE CAN DO COMPARING. I LIKE CHARTING WOULD BE VERY EASY TO TAKE DICISION.

COULD U PLS. GIVE ME SOME MORE INFORMATION ABOUT SOFTWARE

JK

INDIA

Hi Jadish,

I use Matlab for my own analysis. This works great if you’re an engineer or engineering student who already has a license. Otherwise you might want to investigate using Excel or OpenOffice Calc. Good luck!

Great post!

Although i`m struggling to find information on the equivalent dollar amounts to place on each trade in the pair.

In your post you say “Therefore our equal dollar positions averaged out to a 6.1% gain.”. How are you arriving at this figure? And how do you calculate the equivalent dollar values for the pairs.

You could use the ratio on the day that you enter the trade – but this ratio obviously changes as the trade goes on.

Any info you can provide would be useful!

Thanks

Chris

Thanks for writing Chris. Actually when I went through the math I realized that what I thought was a simple ROR computation is maybe not so simple.

Here’s the logic I followed when I wrote the article:

Say I assume I’m originally working with $1000 that I want to divide up equally over the 2 positions, so $500 going long on LOW and $500 shorting HD. The position returns are:

LOW: $500 x $26.42 / $29.42 = $448.40

HD: $500 x $38.98 / $31.79 = $613.09

Therefore I said I’d “invested” $1000 but made $613.09 + $448.40 = $1061.49 or 6.1%.

But there’s another way to think about this (perhaps the correct way) and it goes like this. On the day I enter the pairs trade I begin by shorting $500 worth of HD. This puts $500

intomy account. I can then use that $500 to go long with LOW.In the end I wind up having $61.49 left over after I sell the long and cover the short, but I never invested a penny of my own money. In that case perhaps a “return on investment” is meaningless.

– Lumi

Good Article.

Hey guys,

Just thought I’d let you know about a free Pair Trading Tool. Absolutely no cost.

http://catalystcorner.com/index.php?m=pair_tool

Trade long/short simultaneously. Outputs statistical and fundamental analysis.

Hi Lumi,

I dont have much knowledge about pair trading and statistical arbitrage,but i would love to know about it.Currently i am working as a research associate for equity class.Please let me known about the stuffs and books or the cd”s from which i can start learning.

Manish – see my October 12, 2008 comment above for a link to a book in Amazon that is popular re: learning how to pairs trade. There’s a kindle edition that’s slightly cheaper. ðŸ˜‰

– Lumi

wow, well done. thanks to your brilliant thread, I finally understand what a pair trading is.

plz suggest more cost fre software for pair trading

Hi Lumi.

Not wanting to spam you but this might be helpful for anyone who has really struggled to find affordable retail software that truly does the job of testing and assessing the tradeability of cointegrated pairs.

My partner and I used to model our cointegration pair trades in excel but hit limits. So we decided to build a more flexible and faster tool for release in Q4 this year (and will be commercialising it).

Obviously we are bullish about the product. But anyone joining the beta (starting next month on the current schedule) will be able to judge how comprehensive it is for themselves.

Details are at arb-maker.com where we can also be contacted.

Regards,

Rawdon

anybody pls can you tell me how to calculate the three SD values ?

Hi Raju – whatever you’re using to analyze the data should have a built-in function to compute standard deviation. Then just multiply by 2 and 3 for the other two numbers.