This tutorial shows you how to use MoonshotML to backtest a simple machine learning strategy that trains a random forest model with past returns to predict future returns.
MoonshotML is built on Moonshot, QuantRocket's pandas-based backtester. This tutorial assumes that you have already completed the Moonshot intro tutorial. If you haven't yet completed it, execute the following cell to access it:
from quantrocket.codeload import clone
clone("moonshot-intro")
The MoonshotML tutorial utilizes the same historical database and sample universe created in the moonshot-intro
tutorial. Execute the following cell to verify that you have the necessary database and universe available:
from quantrocket.history import list_databases
from quantrocket.master import get_securities, NoMasterData
assert "usstock-free-1d" in list_databases(), "usstock-free-1d database is needed but not present, please see the moonshot-intro tutorial"
try:
get_securities(universes="usstock-free")
except NoMasterData:
print("usstock-free universe is needed but not present, please see the moonshot-intro tutorial")
else:
print("usstock-free-1d database and usstock-free universe are present, you're all set!")