Analyzing a Simple Mean Reversion Strategy

Updated: Jul 9, 2020

This post is inspired by a mean reversion strategy posted in Intrinio.com blog, here. We have made use of Intrinio data feed subscriptions in the past with good results in general for some simple fundamental strategies. The strategy in the linked post is basically a Simple Moving Average and Relative Strength Index rank that attempts to capture price reversals to the mean. The strategy appeared too simple to be profitable so we decided to code it using Quantconnect´s algorithmic framework and run some backtests to gain information on how such a strategy may perform. The author of the post has also very interesting information in this page.


The strategy in question is based on the hypothesis that price time series in the stock markets are trending in the "long" term and mean-reverting in the "short" term. The terms "long" and "short" term are difficult to define in algorithmic trading and largely subjective, also the trending and mean reverting characteristics of time series are subject to statistical analysis that admit diverse approaches and a multitude of method that may generate confusion. We will discuss ADF tests and Hurst exponents in the future, so we are not going to discuss these topics in depth here, we are going to accept the hypothesis now and put it to the test using back-testing. This is not the best approach to develop an automated trading strategy but the strategy is already here waiting for us.


In order to identify the price points for which we can obtain a profit from a reversion to the mean the strategy ranks the DOW30 stocks by simple moving average (SMA) and relative strength index (RSI). Here at Ostirion we are not familiar with Backtrader, the back-testing Python-based tool used in the original post, so we may have misinterpreted the part of the code that ranks stocks by SMA, as in our opinion this gives no useful information and we should rank the stocks by the price difference to the SMA. We will use this approach in our code (as an additional exercise) and rank the "best" performing stocks as those that are the most above their 50-SMA (rebounding) and are also overbought by virtue of their high RSI (exuberantly rebounding). Once these stocks are identified we will short sell them initially for a holding period of 5 days and then rebalance with the same approach. This strategy is thus a short only strategy.


It is our opinion here at Ostirion that just shorting the markets in general is not a profitable strategy by itself as the natural trend of markets is up (topic for another, thermodynamics based, post), so that by using a short only strategy we are statistically betting against the most relevant, longer-termed trend.


We will also modify the DOW30 companies condition to the top 30 volume companies trading in the US market, approaching the top 30 SP500 companies by volume. We add this more dynamic universe selection method without any hard-coded companies to avoid a little bit of bias. If the mean reversion strategy proves useful any listed company with sufficient trading volume should generate positive returns.


The results of running the original strategy (plain SMA) as we understood it is this:


The report above is the complete Quantconnect back-test result report, including the full code. You can inspect this code in the "</>" drop down and you can also clone the code using your own Quantconnect account.


For the period demonstrated in the original post the strategy performs well:

But if the trial period is extended to 5 years, a bare minimum to validate a strategy, the results are not good:

This confirms that there is either something missing in the strategy or that in fact it is not a good strategy to (just) short the most highly capitalized companies without any regard to general market trends. In a long bull market short-only strategies will underperform the market (and lose money) and will probably not be able to recover the losses during a bear market (if it ever happens again).


In any case there is useful information to be found in this strategy, we may need to implement some changes. We are going to try and improve the way we look at SMA, by using the difference to the current price as an indicator, and we are going to modify the strategy to capture mean reversions in the uptrend, which is the natural state of a developed market operating with solid company stock. Let us assume, for the sake of simplicity and to avoid any unproductive polemics that the market is generally bullish, that price discovery is possible and that humanity is in a path of development and gaining economic efficiencies (this will be philosophical material for another post). Using this naive approach we can select the stocks that are further away up from their 50-day SMA and that are, according to their RSI, overbought. We are going to bet that these companies are in the process of rebounding from 50 day lows, under a "greed rally" and we are going to enter long positions in them. With these modifications to the strategy the back-test results are:

We have now a model that is profitable during a bull market (with 5 years of data) and a model that also suffers grandly when the market drops:

The strategy yields 135% in five years and a half, a CAGR of almost 17%. The strategy beats the SPY ETF by a healthy margin and, being a long-only strategy, is suffering all possible market setbacks even if the companies we are choosing are supposed to be "coming back hard" from their lows.


This strategy may be useful in earnest with some more conservative risk control in terms of market exposure and probably some sector exposure controls. It is even possible to obtain and acceptable risk-reward ratio (a better Sharpe ratio) that could make this strategy more desirable for the risk-averse trader. At Ostirion we are going to develop this strategy further and, if properly validated, offer it as an investment vehicle for our customers. Please remember that these blog posts do not constitute investment advice and that Ostirion may not be accredited to provide financial advice in your jurisdiction. If you are in need of automated trading support please contact us here for full details.



79 views0 comments

Recent Posts

See All