The recommended workflow for developing a Zipline strategy is to start in a notebook, where you can develop your code interactively, then transfer the finished code to a .py
file for backtesting. Once you've transitioned to the backtesting phase, you can use JupyterLab's built-in debugger to debug your strategy. The debugger allows you to set breakpoints and inspect variables as they change over the duration of your backtest simulation. This notebooks explains how to use the debugger.
%zipline_backtest
IPython magic command for debugging¶To debug Zipline with the JupyterLab debugger, we can't use the quantrocket.zipline.backtest
function that we used in an earlier lesson. That's because this function executes the backtest in a separate Docker container from JupyterLab, the zipline
container. Instead, we can use a special IPython magic command, %zipline_backtest
, that runs the backtest inside JupyterLab. The magic command works similarly to quantrocket.zipline.backtest
but lacks some of its bells and whistles and is only intended for debugging purposes.
The debugging steps are as follows:
%zipline_backtest
magic command in the console, specifying a start date and end date and, optionally, the bundle name. (Run %zipline_backtest?
to see the function docstring and all available options.)%zipline_backtest -s 2017-01-01 -e 2017-02-01
See the video below for a step-by-step demonstration.
from IPython.display import VimeoVideo
VimeoVideo('925185155', width=700, height=394)