Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Machine Learned Half Day SPY Strategy

I have built this strategy to try to take advantage of mid-day bounce back of the SPY. It is not based on any research paper or otherwise. I just felt that it seems that often, if the SPY opens higher then the previous day close, it will tend to dip a bit at around noon and bounce back up by the end of the day. The opposite seems true as well. This is not a very exciting algo, but it took me about 30 minutes to code and here it is.

The algo records the SPY price at previous close, and for the first 3 hours of the day. These form the features as input to the ML. The class is derived from the performance of the SPY from midday to close. The SPY is held (or shorted) from 12:30 to close each day. Positions are closed at day end. So this is a low leverage algo.

Maybe this could be enhanced with multiple uncorrelated ETF/stocks.

Enjoy and post your improvements if any.

/Luc

3 responses

Hi Luc,

Thanks for sharing an awesome ML algorithm - it certainly has captured a unique insight into an intraday trading pattern - that 2003~2019 straight returns line is a testament of consistent herd behaviour!

I am happy to concur with your observation as I also recognise a similar pattern from my recent intraday studies on Uber and others - albeit from a non-ML multi-factor context - the exuberant spike in momentum in the early hours and the midday idle are quite unmistakable!

Karl

You are welcome Karl. I will work on it some more this coming week and modify it to run on multiple stocks/ETF and see if by simple diversification the performance can increase.

/Luc

Here is a version with multiple assets traded on half-day. Same as with the SPY, but with a number of assets. The assets I chose were the Dow Jones components circa 2012 so as not to introduce too much survivor ship bias. It is not spectacular. Post your improvements if any. Thanks.

I run a RFECV feature selection step as I believe not all features are very important. Other classifiers can be tried. The logistic regression is much like a zero hidden layer neural network. Enjoy