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-12-31",
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")
Start date | 2017-01-04 | |
---|---|---|
End date | 2020-12-31 | |
Total months | 47 | |
Backtest | ||
Annual return | 6.479% | |
Cumulative returns | 28.48% | |
Annual volatility | 8.518% | |
Sharpe ratio | 0.78 | |
Calmar ratio | 0.52 | |
Stability | 0.62 | |
Max drawdown | -12.408% | |
Omega ratio | 1.18 | |
Sortino ratio | 1.07 | |
Skew | -1.03 | |
Kurtosis | 17.44 | |
Tail ratio | 0.94 | |
Daily value at risk | -1.047% | |
Gross leverage | 0.32 | |
Daily turnover | 9.202% | |
Alpha | 0.01 | |
Beta | 0.37 |
Worst drawdown periods | Net drawdown in % | Peak date | Valley date | Recovery date | Duration |
---|---|---|---|---|---|
0 | 12.41 | 2020-02-19 | 2020-03-23 | 2020-06-10 | 81 |
1 | 9.68 | 2018-10-01 | 2018-12-24 | 2019-10-28 | 281 |
2 | 5.71 | 2020-09-02 | 2020-09-23 | NaT | NaN |
3 | 5.34 | 2018-01-17 | 2018-03-23 | 2018-09-11 | 170 |
4 | 2.16 | 2020-06-10 | 2020-06-11 | 2020-06-22 | 9 |
Stress Events | mean | min | max |
---|---|---|---|
2018 Bear Market | -0.06% | -1.55% | 1.49% |
COVID-19 | 0.06% | -5.31% | 3.87% |
Top 10 long positions of all time | max |
---|---|
column | |
Equity(FIBBG000BPH459 [MSFT]) | 19.34% |
Equity(FIBBG000B9XRY4 [AAPL]) | 18.04% |
Equity(FIBBG00B3T3HD3 [AA]) | 11.85% |
Equity(FIBBG000BMHYD1 [JNJ]) | 10.61% |
Equity(FIBBG000BKZB36 [HD]) | 10.39% |
Equity(FIBBG000BDTBL9 [SPY]) | 10.21% |
Equity(FIBBG000GZQ728 [XOM]) | 10.04% |
Equity(FIBBG000BFWKC0 [MON]) | 9.95% |
Top 10 short positions of all time | max |
---|---|
column |
Top 10 positions of all time | max |
---|---|
column | |
Equity(FIBBG000BPH459 [MSFT]) | 19.34% |
Equity(FIBBG000B9XRY4 [AAPL]) | 18.04% |
Equity(FIBBG00B3T3HD3 [AA]) | 11.85% |
Equity(FIBBG000BMHYD1 [JNJ]) | 10.61% |
Equity(FIBBG000BKZB36 [HD]) | 10.39% |
Equity(FIBBG000BDTBL9 [SPY]) | 10.21% |
Equity(FIBBG000GZQ728 [XOM]) | 10.04% |
Equity(FIBBG000BFWKC0 [MON]) | 9.95% |