Intraday Stock Mean Reversion Trading Backtest in Python With Short Selling

Intraday Stock Mean Reversion Trading Backtest in Python With Short Selling

Carrying on from the last post which outlined an intra-day mean reversion stock trading strategy, I just wanted to expand on that by adapting the backtest to allow short selling too. So as well as buying stocks that have gapped down, we will be allowing the strategy to short sell stocks that have gapped up.

I was interested as to how that would effect our returns and Sharpe Ratio; generally speaking there is more market inefficiency on the short side of the market for various reasons (including for example the inability of large pension funds to short sell stocks due to investment mandate restrictions among other things) .

This increased market inefficiency should theoretically lead to higher returns for those market participants who are able to take advantage of the short selling opportunities.

I’ll begin by backtesting across the same stock universe we used in the last post – the NSYE stock list. The list can be downloaded by clicking the link below:

NYSE Stock List


So let’s begin the code:

This last line produces the below chart

with a Sharpe Ratio of

and an annual return of

Ok so the Sharpe Ratio has decreased from just over 2, to 1.15 when we add the short selling ability, and the annual return has increased from around 8.8% to 12%.

I guess it depends on which statistic is more important to you, straight return or risk adjusted return. I’ll leave that one up to you!

Just for a bit of fun, let’s run this strategy across another investment universe of stocks, this time the London Stock Exchange (LSE) tickers.

That list can be downloaded by clicking the button below:

LSE Stock List


This backtest generates the following results:

With a Sharpe Ratio of 1.289 and an annual return of 25.21%…well that’s a pretty hefty return!

If you are running the backtest for yourself, remember that there are around 6000 stocks in that list so it can take a little while to complete the backtest, just be patient.

Although the results of the LSE backtest look very promising, I think if anyone tried to actually trade it for real they would quickly find out that many of the stocks the strategy short sells, wouldn’t actually be available for short sale in the live market and the transaction costs would be high enough to eat into a large proportion of the returns.

Anyway, it’s still fun to investigate these things and look for ideas to at least begin our search for a profitable strategy.

Until next time folks…

It's only fair to share...Share on FacebookShare on Google+Tweet about this on TwitterShare on LinkedInEmail this to someonePin on PinterestShare on Reddit
Written by s666