Basics of Statistical Mean Reversion Testing

Post on: 16 Март, 2015 No Comment

Basics of Statistical Mean Reversion Testing

By Michael Halls-Moore on October 21st, 2013

So far on QuantStart we have discussed algorithmic trading strategy identification. successful backtesting. securities master databases and how to construct a software research environment. It is now time to turn our attention towards forming actual trading strategies and how to implement them.

One of the key trading concepts in the quantitative toolbox is that of mean reversion. This process refers to a time series that displays a tendency to revert to its historical mean value. Mathematically, such a (continuous) time series is referred to as an Ornstein-Uhlenbeck process. This is in contrast to a random walk (Brownian motion), which has no memory of where it has been at each particular instance of time. The mean-reverting property of a time series can be exploited in order to produce profitable trading strategies.

In this article we are going to outline the statistical tests necessary to identify mean reversion. In particular, we will study the concept of stationarity and how to test for it.

Testing for Mean Reversion

A continuous mean-reverting time series can be represented by an Ornstein-Uhlenbeck stochastic differential equation:

begin d x_t = theta (mu — x_t) dt + sigma dW_t end

Where $theta$ is the rate of reversion to the mean, $mu$ is the mean value of the process, $sigma$ is the variance of the process and $W_t$ is a Wiener Process or Brownian Motion.

In a discrete setting the equation states that the change of the price series in the next time period is proportional to the difference between the mean price and the current price, with the addition of Gaussian noise.

This property motivates the Augmented Dickey-Fuller Test, which we will describe below.

Augmented Dickey-Fuller (ADF) Test

Mathematically, the ADF is based on the idea of testing for the presence of a unit root in an autoregressive time series sample. It makes use of the fact that if a price series possesses mean reversion, then the next price level will be proportional to the current price level. A linear lag model of order $p$ is used for the time series:

begin Delta y_t = alpha + beta t + gamma y_ + delta_1 Delta y_ + cdots + delta_ Delta y_ + epsilon_t end

Where $alpha$ is a constant, $beta$ represents the coefficient of a temporal trend and $Delta y_t = y(t)-y(t-1)$. The role of the ADF hypothesis test is to consider the null hypothesis that $gamma=0$, which would indicate (with $alpha = beta = 0$) that the process is a random walk and thus non mean reverting.

If the hypothesis that $gamma=0$ can be rejected then the following movement of the price series is proportional to the current price and thus it is unlikely to be a random walk.

So how is the ADF test carried out? The first task is to calculate the test statistic ($DF_<tau>$), which is given by the sample proportionality constant $hat<gamma>$ divided by the standard error of the sample proportionality constant:

Dickey and Fuller have previously calculated the distribution of this test statistic, which allows us to determine the rejection of the hypothesis for any chosen percentage critical value. The test statistic is a negative number and thus in order to be significant beyond the critical values, the number must be more negative than these values, i.e. less than the critical values.

A key practical issue for traders is that any constant long-term drift in a price is of a much smaller magnitude than any short-term fluctuations and so the drift is often assumed to be zero ($beta=0$) for the model.

Since we are considering a lag model of order $p$, we need to actually set $p$ to a particular value. It is usually sufficient, for trading research, to set $p=1$ to allow us to reject the null hypothesis.

To calculate the Augmented Dickey-Fuller test we can make use of the pandas and statsmodels libraries. The former provides us with a straightforward method of obtaining Open-High-Low-Close-Volume (OHLCV) data from Yahoo Finance. while the latter wraps the ADF test in a easy to call function.

We will carry out the ADF test on a sample price series of Google stock, from 1st January 2000 to 1st January 2013.

Google price series from 2000-01-01 to 2013-01-01

Here is the Python code to carry out the test:

Here is the output of the Augmented Dickey-Fuller test for Google over the period. The first value is the calculated test-statistic, while the second value is the p-value. The fourth is the number of data points in the sample. The fifth value, the dictionary, contains the critical values of the test-statistic at the 1, 5 and 10 percent values respectively.

Since the calculated value of the test statistic is larger than any of the critical values at the 1, 5 or 10 percent levels, we cannot reject the null hypothesis of $gamma=0$ and thus we are unlikely to have found a mean reverting time series.

An alternative means of identifying a mean reverting time series is provided by the concept of stationarity. which we will now discuss.

Testing for Stationarity

A time series (or stochastic process) is defined to be strongly stationary if its joint probability distribution is invariant under translations in time or space. In particular, and of key importance for traders, the mean and variance of the process do not change over time or space and they each do not follow a trend.

A critical feature of stationary price series is that the prices within the series diffuse from their initial value at a rate slower than that of a Geometric Brownian Motion. By measuring the rate of this diffusive behaviour we can identify the nature of the time series.

We will now outline a calculation, namely the Hurst Exponent, which helps us to characterise the stationarity of a time series.

Hurst Exponent

The goal of the Hurst Exponent is to provide us with a scalar value that will help us to identify (within the limits of statistical estimation) whether a series is mean reverting, random walking or trending.

Basics of Statistical Mean Reversion Testing

The idea behind the Hurst Exponent calculation is that we can use the variance of a log price series to assess the rate of diffusive behaviour. For an arbitrary time lag $tau$, the variance is given by:

begin

<rm Var>(tau) = langle |log(t+tau)-log(t)|^2 rangle end

Since we are comparing the rate of diffusion to that of a Geometric Brownian Motion, we can use the fact that at large $tau$ we have that the variance is proportional to $tau$ in the case of a GBM:

begin

langle |log(t+tau)-log(t)|^2 rangle sim tau end

The key insight is that if any autocorrelations exist (i.e. any sequential price movements possess non-zero correlation) then the above relationship is not valid. Instead, it can be modified to include an exponent value $2H$, which gives us the Hurst Exponent value $H$:

begin

langle |log(t+tau)-log(t)|^2 rangle sim tau^<2H> end

A time series can then be characterised in the following manner:

  • $H<0.5$ — The time series is mean reverting
  • $H=0.5$ — The time series is a Geometric Brownian Motion
  • $H>0.5$ — The time series is trending

In addition to characterisation of the time series the Hurst Exponent also describes the extent to which a series behaves in the manner categorised. For instance, a value of $H$ near 0 is a highly mean reverting series, while for $H$ near 1 the series is strongly trending.

To calculate the Hurst Exponent for the Google price series, as utilised above in the explanation of the ADF, we can use the following Python code:

The output from the Hurst Exponent Python code is given below:

From this output we can see that the Geometric Brownian Motion posssesses a Hurst Exponent, $H$, that is almost exactly 0.5. The mean reverting series has $H$ almost equal to zero, while the trending series has $H$ close to 1.

Interestingly, Google has $H$ also nearly equal to 0.5 indicating that it is extremely close to a geometric random walk (at least for the sample period we’re making use of!).

While we now have a means of characterising the nature of a price time series, we have yet to discuss how statistically significant this value of $H$ is. We need to be able to determine if we can reject the null hypothesis that $H=0.5$ to ascertain mean reverting or trending behaviour.

In subsequent articles we will describe how to calculate whether $H$ is statistically significant. In addition, we will consider the concept of cointegration. which will allow us to create our own mean reverting time series from multiple differing price series. Finally, we will tie these statistical techniques together in order to form a basic mean reverting trading strategy.

Michael Halls-Moore

Mike is the founder of QuantStart and has been involved in the quantitative finance industry for the last five years, primarily as a quant developer and later as a quant trader consulting for hedge funds.


Categories
Bonds  
Tags
Here your chance to leave a comment!