Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Inconsistent backtest results with identical code.

I've run 3 backtests on the same piece of code on the same dates. Returns range from 10% to 200%. I'm not sure what is causing the discrepancies since the algorithm is quite simple and does not rely imported data from outside quantopian that can be updated/edited between backtests. I am just using price data to track the volatility of GLD and trade based on the price returns of VXX.

The code contains some variables and such that aren't used, as I was still experimenting with the code to find any possible leads. In addition, there is a large block of code commented out at the bottom from an example algo that I was using as a template for machine learning. These parts are identical across all 3 backtests, but I just wanted to clarify in case someone got confused with my code and what I was planning.

5 responses

Here is a different backtest

And finally a third. Haven't run anymore backtests, so I'm not sure if doing so will provide another variation.

You're using a random forest which will give you different results each time if you don't set a seed. Try this one.

clf = RandomForestClassifier(random_state=33)

RandomForestClassifier is using different random numbers each time and so the model it fits and thus the trades you make are different each time. On a related note, your model is pretty fragile if different random seeds change things so much.

(On preview, what Georges said)

It should also be noted that sklearns random forest has extremely low default ensemble size (10 classifiers!) so that increases variability even more.