We're ready to run a backtest. Zipline strategies are referenced by the filename without extension; thus, to run the strategy in our winners.py
file, we use the code "winners"
.
Some Zipline backtests can be long-running. You can use the progress
parameter to tell Zipline to log progress and performance statistics to flightlog periodically during the backtest. In this example, we log progress for each month of the simulation (progress="M"
). Make sure flightlog is running in a terminal so you can see the progress output, then run the backtest:
from quantrocket.zipline import backtest
backtest(
"winners",
start_date="2017-01-01",
end_date="2020-01-01",
progress="M",
filepath_or_buffer="winner_zipline_results.csv")
Zipline returns the backtest results as a CSV. You can use pyfolio, a companion library to Zipline, to look at a tear sheet of performance results:
import pyfolio as pf
pf.from_zipline_csv("winner_zipline_results.csv")