Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Collaboration on a Mean Reversion Strategy

Over the past 18 months I've been working to refine a pretty simple mean reversion trading concept. The basic idea is that stocks comprising the S&P500 that are trading multiple standard deviations and also a certain percentage below (above) their 20 day moving average will rebound toward their moving average and should be bought (sold short) for up to a small percentage of the total portfolio value. Because the moving average declines toward the stock price, I've found that there is about 30 basis points of decay per day on the expected return, which also helps to explain why there needs to be some hard percentage distance from the moving average as a buffer.

If they do not revert back toward the mean, they are stopped out when the negative return is equal to (the percent difference in the moving average and the current price)/3.18; the reason why I chose that is because when you just build a trade log(rather than a portfolio) based on the concept back-tested over 20 years, 1:3.18 recommended trades do not revert back to the mean (so there's not actually a phenomenal mathematical rationale for it, but it has worked well to limit losses in paper trading).

If they do revert back to the mean, they are sold at their 20 day moving average.

Paper trading this idea (by hand) for the past 3 months I've had the following results:

Total return of 11.81% compared to an index return of 4.43%, beta of 1.52, alpha of 5.05, Sharpe ratio of 1.9909. I've never tried to use leverage. In fact, it's only on rare occasions (maybe 5 days in the past 3 months) that I've dipped below 50% cash in the mock portfolio (which creates another question of efficient capital deployment).

I've found the results promising so far, but I definitely need guidance from someone with experience and expertise on Quantopian to take the testing of the idea to the next level so I could hopefully make this more than just a paper trading exercise. If you are interested in discussing the concept further or have the ability and inclination to program something along these lines, I hope to hear from you.

Thanks in advance for reading this long-winded post.

6 responses

bump

Bueller?

You can do a custom factor to get a price history pipeline set up. Use pandas functions to get std, mean, etc on the data. Schedule a function to sell since all open orders are closed daily (including stops). For tracking, you can create a data structure in context.trades and then do bookkeeping in there - set it up in your initialization function, then access it in other scheduled functions.

Anyone have the programming experience to execute something like this

bump

Still interested?

@Devin - absolutely. If you have time to schedule a call or email exchange, I'll share what I have w/ you. Would be happy to get any new input from anyone.

SP