QuantRocket logo
Disclaimer

Getting Started with MoonshotML¶

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.

Prerequisites¶

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:

In [ ]:
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:

In [ ]:
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!")

Tutorial¶

  • Part 1: MoonshotML Strategy Code
  • Part 2: Model Selection
  • Part 3: Walk-forward Optimization