QuantRocket logo

Disclaimer

Analysis of Model Predictions

A MoonshotML strategy encompasses both the model's training and predictions and what we choose to do with those predictions in our trading logic. That's a lot to worry about in the initial research stage. To separate concerns, we can retrieve the model predictions from our backtest results and analyze the predictions in a notebook, which might illuminate how we want to use the predictions.

Retrieve predictions and prices

In predictions_to_signals, we save the predictions, closing prices, and volume DataFrames to the backtest results:

...
# Save the predictions and prices so we can analyze them
self.save_to_results("Prediction", predictions)
self.save_to_results("Close", closes)
self.save_to_results("Volume", volumes)
...

To get these fields back, we must re-run the walk-forward optimization with details=True:

Load predictions and prices

Using details=True on a large universe results in a large backtest results CSV. To make it easier to load, we use csvgrep to isolate particular fields before we load anything into memory:

Then we load only these fields:

Let's split our predictions into 5 bins and compare one-week forward returns for each bin:

The stocks with the higest predicted return indeed have the highest forward return. The stocks with the lowest predicted return have a lower but still positive forward return. This suggests it may be possible to dig deeper into the strategy and figure out why, despite this forward return profile, the backtest performance is poor.


Back to Introduction