Contents

Part 1: What is Pairs Trading?

Part 2: An Overview of Pairs Trading

Part 3: Conclusion

1- What is Pairs Trading

As a primer to our current topic, I would strongly suggest reading another article I wrote on the concept of arbitrage.

With that said, I can formally introduce the definition of arbitrage as such:

An arbitrage (portfolio) is one where you pay nothing to enter it, and you make a certain risk-less positive profit.

There are a few instances in the market where arbitrage opportunities occur. The one we will consider will be an inter-stock instance. Essentially, this means that we will exploit a statistical property between two different stocks on the same exchange.

Now,

1.1 What is pairs trading?

Pairs trading is a strategy that consists of two components: A) Identifying a pair of stocks that move similarly and possess mean-reverting properties & B) Sell the high priced stock and buy the low priced stock.

The trick of course is being able to identify the pair (A) and then finding an appropriate pre-defined entry and exit strategy (B).

It is characterized as a market-neutral strategy that belongs to the family of statistical arbitrage methods. By market-neutral we mean that this strategy is not affected by price trends (upwards or downwards) — this is a result of the hedging of each constituent of the pair.

There are three primary approaches to pairs trading:

  • Distance approach
  • Stochastic approach
  • Cointegration approach

The one we will be focusing on is the cointegration approach.

1.2 How frequently does this instance/arbitrage opportunity occur?

Not very frequent. To better understand why it is not frequent, we ought to understand why they occur in the first place. First things first, arbitrage opportunities occur because of an inefficiency in the market — which is a non-equilibrium phenomenon.

The cause of this inefficiency can be anything from a range of errors such as a delay in information relay. In the dawn of this Modern Techno-Industrial (MTI) form of civilization, delays are very minimal, hence the infrequent instances of opportunity are only transient and exist minimally and for short periods of time.

2- An Overview of Pairs Trading

In this part, we will build up a working knowledge of: time series, stationarity, cointegration, regression and residuals, and unit root tests.

Then we will apply this knowledge in: portfolio construction, forming a conservative trading strategy, and then backtesting.

2.1 Time Series

A time series is a set of data points chronologically arranged in accordance with their time of occurrence. Time can be measured in seconds, minutes, hours, days, months or years.

Let us suppose there is an arbitrary time series Y:

Y={Yt:t∈T} ; where T is the set of natural numbers

essentially,

t: t₁, t₂, …, tn

Yt: Yt₁, Yt₂, …, Ytn

An example of a time series would be the price of a stock over time in days or population over time in years.

Figure 2.1.1

Some important characteristics of time series

  • Trend: is it upwards or downwards?
  • Seasonality: are there any regularly repeating patterns?
  • Random movements: is there a seemingly irregular nature?
  • Stationarity: do the statistical properties not change over time?

Characterizing time series allows us the liberty of creating or using models that could lead to us realizing important information. For pairs trading, we will explore one of the characteristics being stationarity.

2.2 Stationarity

In simple terms, stationarity is when a time series’s mean and variance are constant and the covariance is independent of time. Visually, a stationary time series looks flat with no pathological trend and no seasonality. It also is mean-reverting.

Figure 2.2.1

If a time series is stationary, then it has an integration of order zero I(0).

We cannot deduce if a time series is stationary based on visualization. We ought to make use of a framework of statistical methods to deduce if it is indeed stationary.

There are three conditions that need to be satisfied such that an arbitrary time series Yt is defined as stationary:

  • E[Yt] is constant for all t (this implies mean-reversion)
  • Var[Yt] is constant for all t
  • Covar[Yt, Yt+₁] is constant for all t

If a pair of stocks can be identified to a high level of confidence of being stationary, then we can successful use that pair in our pairs trading strategy.

What is an autoregressive (AR) model?

It is a representation of a type of random process. In our case it’ll be a random walk, which will be an approximation of discretizing Brownian motion (which is used to model stock prices). It specifies that the output variable depends linearly on its own previous values and a random variable — thus it is in the form of a stochastic difference equation.

This is represented as such,

Yt=ρYt-₁+Ɛt ; where Ɛt is an independent normally distributed random variable.

Figure 2.2.2

It is imperative to note that as the above equation is an AR model of order one, we will therefore consider a lag (L) of one.

There are two important examples of stationary time series and their respective properties:

  • Does not depend on time
  • White noise

2.3 Cointegration

Recall,

If a time series is stationary, then it has an integration of order zero I(0).

Well then, we’ll build on that.

Suppose we have a pair of stocks that we would like to identify as a pair or not (for the purpose of pairs trading).

Let the time series Xt be stock A and Yt be stock B. Both these time series are AR models;

Xt=ρXt-₁+Ɛt and Yt=ρYt-₁+Ɛt ; assume that Ɛt is the same for both series.

Then if we were to combine these series in a specific ratio, we would get a new series μt consisting of only the non-random components of the AR models.

Now suppose in a more general case, that these two time series are both integrated of order one (I(1)) and so are from the get go non-stationary. Also let us expect that they are also AR models (of order 1) where the random component is canceled out (due to sharing common stochastic trends (Ɛt)) — there is then a possibility that a linear combination of the series would produce a stationary I(0) series. This is what cointegration is.

Figure 2.3.1

Whats the difference between cointegration and correlation?

Whilst both cointegration and correlation can measure asset prices that move together and hence establish a relationship, correlation breaks down on the long-term but is somewhat robust in identifying short-term relationships. Meanwhile cointegration is a much better fit for medium to long-term trading strategy. Also correlations are mostly used to specify the co-movement of return whilst cointegration specifies that of price.

Recall this?

… we will exploit a statistical property between two different stocks on the same exchange.

That statistical property we were referring to was stationarity by the cointegration approach.

Cointegration approach for finding pairs

The main idea is that we have two time series that are not stationary but become stationary by differencing (I(1)). These time series are called integrated (of order one). There are integrated (of order one) time series such that there is a linear combination of them that becomes stationary (I(0))(as seen in figure 2.3.1).

We can split this process into three major steps:

  • use regression analysis to regress the natural logarithms of both stocks prices against each other — to find the cointegration coefficient
  • compute the residuals from the regression
  • statistically test whether the residuals are stationary using the Dickey-Fuller test (DF)

In the graphs below we took the historical price of Citigroup Inc. stock from 20/07/18 to 20/07/19 (daily frequency). Using Matlab, we generated the following graphs:

From left to right: Raw price, Natural Log raw price, difference of natural log raw price

2.4 Regression and Residuals

We shall take the prices of two stocks A and B over time.

Recall figure 2.3.1, and the equation:

Yt-βXt=Ɛt — I(0), stationary

Linguistically, there are two possibly non-stationary time series Xt and Yt, such that we can multiply one of the time series (cointegrated) by β such that the resulting variable is indeed a stationary time series μt.

It is apparent that we must find the value of β. The way to do it would be by way of linear regression of the natural logarithms of the prices of the stocks A and B.

The resulting regression formula is:

ln(Xt)= μt+β*ln(Yt)+Ɛt ; (this is a unit portfolio)

Rearranging so that it looks like a linear combination,

μt= ln(Xt)-β*ln(Yt)-Ɛt; where μt is the spread/residual series/

where β is the cointegration coefficient, μt is the estimated values of the error (the residuals).

Figure 2.4.1

The residuals are the differences between the natural log of the price of stock A and the corresponding point on the regression line. Essentially they are turned into a residual series which also has to be stationary I(0).

We graph the residuals:

Figure 2.4.2

In order to make sure this is true, we test for cointegration by analyzing the residuals created by the regression. The test we shall use is the Dickey-Fuller (DF) test which will ultimately test for stationarity in the residual series.

Sensitivity to which stock is regressed over which is important and can cause major changes. To rid ourselves of this problem, we can use T-Statistics.

2.5 Unit Root Tests

They are statistical tests that test if ρ=1.

There are several types of unit root tests — a popular type being the Dickey-Fuller (DF) test . The DF test constructs test statistics that follow certain non-standard distributions.

We’ll utilize this test as mentioned in the previous section.

Basically the DF shows that if portfolio/spread/μt time series is cointegrated, I(0), then it is stationary.

In DF formulation we end up with:

μt=β+pμt-₁+Ɛt

μt-μt-₁=β+(p-1)μt-₁+Ɛt

Δμt=β+μt-₁+Ɛt

The null hypothesis of the DF test is that μt is a unit root series, and the alternative is that it is a stationary series.

  • H₀ : p=1 (Xt and Yt are not cointegrated, so non-stationary)
  • H₁: p<1 (Xt and Yt are integrated, so stationary)

Now we compare the T-statistic to the Dickey-Fuller distribution that has tabulated numerical values. So in essence, if <DFcritical then reject the null hypothesis. We’ll select the data in the 5% without trend in the table below.

Table 1: Depicts critical values for Dicky-Fuller t-distribution. Source: Wikipedia

2.6 Overview of The Process So Far

The formation period can be defined in the simple diagram below:

Figure 2.6.1

2.7 Portfolio Construction

There are two periods when carrying out a pairs trading strategy. They are as follows:

  • Formation period: which is everything we talked about above, from identifying a pair of stocks that have a statistical relationship using regression, residuals, and cointegration.
  • Trading period: it is where we monitor the spread μt and see if there is a signnificant deviation from the mean, then a position is open. And a strategy is formed.

The output of the formation period is a unit portfolio, the spread μt, which leaves us with two questions we must answer:

  • What is our trading strategy?
  • What should be the sizes of our positions? Variable.

2.8 Forming a Conservative Trading Strategy

The unit portfolio is the spread μt. With that in mind, we can simply state that the basic trading framework behind pairs trading is:

  • if the spread μt is very high, then buy Xt and sell Yt
  • if the spread μt is very high, then buy Yt and sell Xt

This does not give us much information as we still have to define the threshold long position and short position. The underlying idea is that the price of this portfolio will oscillate around 0. For example, we can specify percentage thresholds of where to buy or sell. Alternatively we could use Bollinger Bands. Even a combination of those two are possible!

Figure 2.8.1 —  can be bound for example by percentages

Not only is it important to define when to buy and sell, it is also necessary to build in a trigger out. This adds to the element of conservatism in any trading strategy.

An example of a P/L get-out trigger:

  • Exit the trading strategy after X₁ days,
  • Exit with a profit of $X₂,
  • Exit with a Sharpe ratio of X₃,
  • and exit with a maximum drawdown of X₄

We have four variables we need to specify. This part is very subjective and requires a constant back and forth between performance indicators (such as sharpe ratio and maximum drawdown) whilst also a rigorous backtesting procedure.

2.9 Backtesting

In the formation period we selected historical price data in a specifically selected period of time. That historical data is sample data. What we ought to do is utilize around 70% of that data to train our model during the formation period — then we use the remaining 30% as test data for backtesting purposes.

Backtesting allows us to gauge how well our pairs trading using cointegration approach is doing. One of the best ways to help structure a good trading strategy is to analyze the P/L from the backtests.

3- Conclusion

In this overview of pairs trading, we went over the basic mechanisms used to perform this quantitative almost risk-free trading strategy. There are many variations of this strategy with lots of room for flexibility and improvement.

Fundamentally, pairs trading utilizes arbitrage opportunities by means of exploiting a statistical relationship between a pair of assets. The strategy is broken down into two parts, namely: A) identifying the stationary cointegrated pairs and then B) exploiting the statistical relationship between them through a trading strategy.

In the bigger picture its optimal to have an automated system that continuously searches for pairs across various periods, entering multiple different portfolios with a sound trigger-out strategy, with simultaneous research by the use of backtesting different trading strategies and by varying some parameters.

In the coming articles, I intend on delving deeper into the subject of quantitative trading strategies — if you have any requests or questions, please do not hesitate to share them with me in the responses below.