Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Implementing Profitable Mean Reversion after Large Price Drops

Hi!
I'm trying to implement the contrarian strategy of buying the worst performers of the day (open to close performance) at the market close, holding them overnight and selling them at the open price the next day. The strategy is outlined here - https://papers.ssrn.com/sol3/papers.cfm?abstract_id=2272795
I found this link posted in the Trading Strategy Ideas thread and decided to give it a shot. However my implementation (version 2 in the above paper) is going terribly wrong. I've looked at the code for a long time now, but am still not able to figure out what's going wrong here. Any ideas about where this is going wrong?
P.S. This is my first attempt at coding an algorithm here, so I'm most willing to get any other pointers on the general code structure too! Thanks.

2 responses

Welcome to Quantopian!

That's definitely not a pretty result. You're not exactly incinerating money. . . more that it is evaporating. =)

When you see a steady march down like that, it's a strong hint that you are getting eaten up by transaction costs. It looks like your algorithm is making 60 trades per day as it opens and closes each position. At the default commission of $1, that's $60, or .6% of your starting capital each day. Your trades aren't anywhere near profitable enough to overcome those costs, and your value is drained away. If you set your commissions to zero, and increase your capital, you'll start seeing a different result.

My biggest suggestion on your code structure is to use pipeline instead of get_fundamentals. Pipeline is much more powerful and extensible, and get_fundamentals will be deprecated at some point. The time you spend learning pipeline will be well rewarded.

I'd also suggest that you do some of this early work in the research platform. The backtesting environment is intuitive, and a lot of new people start by using the backtester. However, the research environment is much more powerful, and you can do a lot more analysis there. You really only need the backtester after you've proven the idea to yourself in research.

Disclaimer

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by Quantopian. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. No information contained herein should be regarded as a suggestion to engage in or refrain from any investment-related course of action as none of Quantopian nor any of its affiliates is undertaking to provide investment advice, act as an adviser to any plan or entity subject to the Employee Retirement Income Security Act of 1974, as amended, individual retirement account or individual retirement annuity, or give advice in a fiduciary capacity with respect to the materials presented herein. If you are an individual retirement or other investor, contact your financial advisor or other fiduciary unrelated to Quantopian about whether any given investment idea, strategy, product or service described herein may be appropriate for your circumstances. All investments involve risk, including loss of principal. Quantopian makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances.

Yep, the commission costs were the reason. Setting them appropriately is giving reasonable results now :)
I'd tried to use pipeline for the entire code here while learning, but the computations were at the market close so the pipeline idea skipped me altogether. I can change the get_fundamentals part though and use the pipeline for that part. I'll do that.
Oh, and the notebook did prove quite helpful while setting up the idea. I'll make more structured use of it hence.
Thanks Dan!