# cointegration

Some price series are mean reverting some of the time, but it is also possible to create portfolios which are specifically constructed to have mean-reverting properties. Series that can be combined to create stationary portfolios are called cointegrating, and there are a bunch of statistical tests for this property. We'll return to these shortly. While you can, in theory, create mean reverting portfolios from as many instruments as you like, this post will largely focus on the simplest case: pairs trading. What is Pairs Trading? Pairs trading involves buying and selling a portfolio consisting of two instruments. The instruments are linked in some way, for example they might be stocks from the same business sector, currencies exposed to similar laws of supply and demand, or other instruments exposed to the same or similar risk factors. We are typically long one instrument and short the other, making a bet that the value of this long-short portfolio (the spread) has deviated from its equilibrium value and will revert back towards that value. One of the major attractions of pairs trading is that...

This is the first post in a two-part series about the Hurst Exponent. Tom and I worked on this series together and I drew on some of his previously published work as well as other sources like Quantstart.com. UPDATE 03/01/16: Please note that the Python code below has been updated with a more accurate algorithm for calculating Hurst Exponent. Mean-reverting time series have long been a fruitful playground for quantitative traders. In fact, some of the biggest names in quant trading allegedly made their fortunes exploiting mean reversion of financial time series such as artificially constructed spreads, which are used in pairs trading. Identifying mean reversion is therefore of significant interest to algorithmic traders. This is not as simple as it sounds, in part due to the non-stationary nature of financial data. We both think that Ernie Chan's book “Algorithmic Trading: Winning Strategies and Their Rationale”, is one of the better introductions to mean reversion available in the public domain. In the book, Ernie talks about several tools that can be used when testing if a time series is mean reverting. One is the...

In the first Mean Reversion and Cointegration post, I explored mean reversion of individual financial time series using techniques such as the Augmented Dickey-Fuller test, the Hurst exponent and the Ornstein-Uhlenbeck equation for a mean reverting stochastic process. I also presented a simple linear mean reversion strategy as a proof of concept. In this post, I’ll explore artificial stationary time series and will present a more practical trading strategy for exploiting mean reversion. Again this work is based on Ernie Chan's Algorithmic Trading, which I highly recommend and have used as inspiration for a great deal of my own research. Go easy on my design abilities... In presenting my results, I have purposefully shown equity curves from mean reversion strategies that go through periods of stellar performance as well as periods so bad that they would send most traders broke. Rather than cherry pick the good performance, I want to demonstrate what I think is of utmost importance in this type of trading, namely that the nature of mean reversion for any financial time series is constantly changing. At times this dynamism can...

This series of posts is inspired by several chapters from Ernie Chan's highly recommended book Algorithmic Trading. The book follows Ernie's first contribution, Quantitative Trading, and focuses on testing and implementing a number of strategies that exploit measurable market inefficiencies. I'm a big fan of Ernie's work and have used his material as inspiration for a great deal of my own research. My earlier posts about accounting for randomness (here and here) were inspired by the first chapter of Algorithmic Trading. Ernie works in MATLAB, but I'll be using R and Zorro. Ernie cites Daniel Kahneman's interesting example of mean reversion in the world around us: the Sports Illustrated jinx, namely that "an athlete whose picture appears on the cover of the magazine is doomed to perform poorly the following season" (Kahneman, 2011). Performance can be thought of as being randomly distributed around a mean, so exceptionally good performance one year (resulting in the appearance on the cover of Sports Illustrated) is likely to be followed by performances that are closer to the average. Mean reversion also exists in, or can be constructed from, financial time series...