In this post we will discuss some other basic aspects of pair trading. As we have already discussed, correlation is usually utilized in pair trading. However, it is not enough for the two instruments to be just highly correlated. It’s believed that they should be aslo cointegrated. Cointegration is a statistical property of two or more time series such that their linear combination is a stationary (mean reverting) time series. Let’s take an example:
xt represents the price of instrument X at time t,
yt represents the price of instrument Y at time t.
We say that the two time series xt and yt are cointegrated, if a linear combination exists, such that:
yt – β.xt = μ + εt,
where β is some constant that has to be found, μ is the mean of cointegration process and εt is a stationary time series called cointegration errors. In simple words: if we know that two instruments are cointegrated and we know β, then the combination of yt – β.xt will be always equal (or close enough) to some mean value (μ). The error εt reprisents the deviation from the mean value. Having all this, it becomes trivial to find moments of higher deviation from the mean and take orders on both pairs. If we open 1 lot on symbol Y we should open β lots on symbol X. Cointegration gives us some certainty that our combination will return to the mean because εt is stationary.
This may look simple but some advanced math is involved with cointegraion. We usually pick highly correlated instruments and then apply tests for cointegration.
First we need some data preprocessing. Market time series are non-stationary time series, their mean and variance change over time and they follow trends. It is needed to transform the price data so it becomes stationary. Otherwise, if we combine two non-stationary time series, it is not possible to get a stationary time series as a result. And remember our goal is that εt is stationary. Here usually some differencing takes place and instead of raw price data we use the price differences:
y’t = yt – yt-1
x’t = xt – xt-1
Second we need to test our selected symbols for cointegration. There are several approaches among which the Engle–Granger two-step method and Johansen test are most common. The first one is simpler but has some drawbacks, it gives slightly different results depending on which of the two instruments is first. The Johansen test is believed to be better but it involves more advanced math operations and larger sample data. I won’t go into any math details related to these tests now. If there’s anyone interested, please leave a comment and I will consider revealing the math in a separate post.
If cointegration is confirmed and we plot the cointegration error εt, it should look similar to this:

As you can see the graph oscilates around the mean value μ and always returns to the mean. We open trades at the extremes of εt, the bigger is the extreme the better. Usually some minimum threshold is selected such that it will cover the spread/comissions invloved with the trades and some profit is achieved. Trades are closed either at the mean or at the following opposite extreme.
Cointegration can be extended further to include several instruments and that’s what the hedge funds usually do – create a portfolio of several cointegrated instruments.

Casey
Kristeen
Caryn
Brenna
Shelly
Felipe
Blondell
Patrick