Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Random Forest Machine Learning Algo

I've been doing a lot with ML recently and ironically have had better success with simpler ML strategies (ie. less features and complex data). This is not an awfully complex algorithm and I thought some of you might be interested in trying something similar yourselves.

This strategy uses the previous 6 month prices of various SPDR Funds as training data to predict the following months price of the fund. Each month, the algorithm evenly invests in all of the SPDR Funds it predicts will report higher prices. Other than that, the only restriction I placed on the algorithm was to allow it to trade only once a month.

This is a black box algorithm that uses a random forest so if you backtest it yourself, you are almost definitely going to get different results. But, I've run over 25 backtests on this algorithm from Jan 03, 2002 to Jan 01, 2017 and the average return over that period seems to be around 270% (thus, the backtest I'm sharing is an average case). The SPY over the same period returns only 155%.

Like all ML algorithms, the more data you give this program the smarter (better predictive power) it gets. Thus, this algorithm performs better in the long run than the short run. For optimized results you'd want to run a 10+ year backtest.

2 responses

It gets a bit of a head start there because it doesn't start buying until SPY has dipped pretty low (almost -30%!). If you start the benchmark from March 3rd 2003 (roughly where the algo kicks in), SPY also achieves ~250% returns over the same period.

Tried adding things like GLD and TLT, to see if it would improve during crashes...

If you rebalance weekly instead of monthly and pay no commissions (ala Robinhood), you get better stats.