QuantRocket logo
Disclaimer


Zipline Intro › Part 7: Zipline Parameter Scans


Zipline 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 module-level attribute in the strategy file. In this example MOMENTUM_WINDOW is the parameter we will target:

MOMENTUM_WINDOW = 252

def initialize(context: algo.Context):
    ...

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.zipline import scan_parameters
scan_parameters("winners",
                param1="MOMENTUM_WINDOW",
                vals1=[252, 126, 63],
                start_date="2017-01-01",
                end_date="2022-08-31",
                filepath_or_buffer="winners_MOMENTUM_WINDOW.csv")

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

In [2]:
from moonchart import ParamscanTearsheet
ParamscanTearsheet.from_csv("winners_MOMENTUM_WINDOW.csv")

Next Up¶

Part 8: Debug Zipline Strategies