Moonshot Parameter Scans

You can use parameter scans to test variations of your strategy. In this notebook we'll test several different window lengths for calculating momentum.

A parameter scan can target any strategy parameter defined as a class attribute on the strategy. In this example MOMENTUM_WINDOW is the parameter we will target:

class UpMinusDown(Moonshot):

    CODE = "umd"
    MOMENTUM_WINDOW = 252

We'll compare 3 window lengths: 12 months (approx. 252 trading days), 6 months (126 trading days), and 3 months (63 trading days):

In [1]:
from quantrocket.moonshot import scan_parameters
scan_parameters("umd-demo", 
                param1="MOMENTUM_WINDOW",
                vals1=[252, 126, 63],
                start_date="2017-01-01", 
                end_date="2020-01-01", 
                filepath_or_buffer="umd_moonshot_MOMENTUM_WINDOW.csv")

As with the backtest, a parameter scan returns a CSV, which we can use to generate a tear sheet using Moonchart:

In [2]:
from moonchart import ParamscanTearsheet
ParamscanTearsheet.from_moonshot_csv("umd_moonshot_MOMENTUM_WINDOW.csv")