The recommended workflow for developing a Moonshot 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. (This approach is described in more detail in the usage guide.) Once you've transferred your code to a .py
file, you can continue to debug your strategy interactively using the technique described in this notebook. The basic technique is to open the .py
file in JupyterLab and attach a console for interactive exploration.
The debugging steps are as follows:
self
. Here, we are exploring the UpMinusDownDemo
strategy:self = UpMinusDownDemo()
get_prices
method (this method is defined on the Moonshot
base class):prices = self.get_prices(start_date="2017-01-01", end_date="2017-02-01")
prices_to_signals
, select the body of the method (everything excluding the method definition at the top and the return statement at the bottom), then click Shift+Enter. This copies the selected lines to the console and executes them. Normally the prices
variable is passed as a parameter to prices_to_signals
, but in this case we already loaded a prices
variable in the previous step, so the executed code uses that.prices_to_signals
method are loaded in the console and can be inspected interactively.signals_to_target_weights
. Since both a signals
variable and prices
variable are now loaded in the console, you can select and execute the body of signals_to_target_weights
and it will use those variables. You can then inspect the variables created in signals_to_target_weights
.See the video below for a step-by-step demonstration.
from IPython.display import VimeoVideo
VimeoVideo('925534381', width=700, height=394)