Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
3-Day S&P 500 Algorithm

If the S&P 500 is down more than 0.5% for three days in a row, buy on market close, and sell on market close three days later.

5 responses

Reminds me of a quant game that was on WSJ a few months ago. If you hold it for more than 3 days you get better returns, but beta goes up.

I made a couple additions to augment what I assume is the basic thesis here ("what goes down must go up"). These act pretty much the opposite of a stop loss order:

  1. Don't sell while you're more than 5% in the hole. (Don't lock in extreme losses.)
  2. Increase the leverage if the price has continued to drop. In this example, it increases the leverage to the "days_in" value ... so on the second day if you're more than 5% in the hole, it'll set the leverage to 2, on the third day it'll increase the leverage to 3.

This works reasonably well. There appear to be only three days during the entire backtest period where leverage goes up to 2, and only once where it goes up to 3, but nonetheless it increases returns significantly. Beta is relatively unchanged. Drawdown increases in this example, but if you play with the thresholds and leverage amount (both of which I selected at random) you can decrease it while increasing returns.

Some words of caution though -- the algo makes the bulk of its gains against the benchmark during two crashes (2008, 2011). A lot of the subsequent performance is buoyed by compounding those idiosyncratic gains. So that might be a sign of over-fitting. Doesn't perform so great after 2015. Also, this ETF is pretty thinly traded, at least at times -- I noticed a bunch of small orders don't get filled. Does the algo perform as well with other ETFs? If not, that could be another indication of over-fitting and selection bias. And finally, my additions do add more risk that in a crash it'll just hold and keep leveraging more. It might be smart to limit the amount of leverage.

I wanted to point out that this algo doesn't perform so hot if you use SPY instead of ITOT. Also, what is the significance for the time of day (5 minutes before close)? In hindsight that captures a handful of great historical trades during 2008 & 2011, but is there any other rationale behind it? That is probably over-fitting. Running the trades at different times of day drastically reduces returns.

I don't know much about coding but I tweaked it to only hold the security for a half a day... post the three days down. I also tweaked it to sell after the stock is up at least 2 percent on that day. It'd be cool to get the inverse in there as well, basically trading the SPXU or something if it had 4 days red in a row and then sell or double down on the 5th or 6th day... If i knew more about coding I'd add it in there. Cool thing about this strategy is one should be able to execute it themselves without the algo pretty simply. I imagine the leverage could get nasty if it went wrong... ie.. I ran a backtest from October 2018 and things got nasty...