Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Short Term Reversion with Smart Portfolio Construction

This is a mean-reversion algorithm on Quantopian.

Algorithm investment thesis:
Top-performing stocks from past 5 days will do worse nextly, and vice-versa.

Everyday, we rank high-volume stocks based on their previous 5 day returns.
We go long the bottom 20% of stocks with the WORST returns over the past 5 days.
We go short the top 20% of stocks with the BEST returns over the past 5 days.

Simple Portfolio Construction:
Hold the long/short position till the stock no longer in bottom/top 20% of the investment universe.

Smart Portfolio Construction:
Hold the long/short position till the stock no longer in top/bottom 50% of the investment univserse.

10 responses

Nice concept Ben. I thought about adding this into my simple stock rotation strategy after I had made a coding error which doubled up on sales when profit taking. Must take a closer look.

I ran the algo over a longer time period and in minute mode. I have not even begun to look at the code and what it really needs is GRAYHA's excellent logging methods added in to achieve clarity as to what is going on.

What is apparent is that the algo did nothing other than during the 2008 - 2009 crisis period where it would have helped a traditional long only portfolio enormously.

Fiddled around a bit and came up with separate algos to trade long and short. This first one is the short version - short stocks in the top 20% over a 5 days period. Looks like a mirror image of the market itself - a thumping great loss for most of the period except during severe bear markets.

The next step is to see what shorting looks like when some sort of "profit" target level has been achieved on the top stocks.

And here is Long only...surprise! Does great to buy dips in a bull market.

There is a great deal to look at with these algos but thank you to Ben Wang for his excellent idea and coding. De-listed stocks need exiting on the last date (to prevent the apparent but spurious build up of positions over time) and leverage needs looking at particularly on the short side.

Thanks Anthony for the helpful comments. I am new on Quantopian. And I definitely will take a look at the leverage, the delisted stocks and logging.

Regarding to the results, I am surprised by the asymmetry between long-only performance and short-only performance. In the academic literature of the reversion strategies I read before, the results (using 1993-2009 data) of long-leg and short-leg are more balanced.

Please can you link to the academic literature profiling the long and short legs?

This strategy might help:
http://alvarezquanttrading.com/2016/02/10/double-7s-strategy/

It's not cross sectional like your algo. It just looks at individual stocks hitting 7 day highs or lows of closing prices.

@Dan: This Double 7's idea looks pretty interesting. Do you have backtest result on it?

@Ben This algo might benefit from position sizing according to risk. Check out the algo I posted here, which does something similar in momentum. It buys from the top of the ranking, but holds while still in the long "pool", and vice versa for short pool.

https://www.quantopian.com/posts/equity-long-short#56d4cb2dae823b6fe60000e5

I also think worth trying to "equitise" the strategy. To use cash rebate from shorting to buy the stock index, SPY. While I agree with Anthony, the long and the short leg don't look that interesting on their own, it is their spread that is interesting.