Running moonshot outside of JupyterLab


I’m following the Backtesting part of the Usage Guide and I’m having trouble getting a moonshot backtest to work outside of JupyterLab.

QuantRocket and Interactive Brokers are configured correctly since I can collect data and query account balances, etc.

I’ve used a console in JupyterLab to prepare the data and I’m attempting to run the strategy code from PyCharm to run a backtest.

However the line, from moonshot import Moonshot, gives the error: ‘unresolved reference’.

When I try from quantrocket.moonshot import Moonshot the error still applies to Moonshot.

Moreover, when I delve into the quantrocket.moonshot source code there are additional errors. For example, moonchart being an unresolved reference is the first.

How to run a moonshot backtest from an IDE?


If you want to run a Moonshot backtest where the actual backtest runs in the moonshot Docker container but the CSV results are returned to PyCharm, use from quantrocket.moonshot import backtest in PyCharm. This is available assuming you ran pip install quantrocket-client in your PyCharm environment.

If you want to view a Moonchart tear sheet outside of JupyterLab, you will first need to pip install quantrocket-moonchart in your environment.

If you want the Moonshot backtest to actually execute inside PyCharm (as opposed to just returning the results to PyCharm), this isn’t documented or supported. In theory you could try installing Moonshot locally using pip install quantrocket-moonshot, but a lot could go wrong and it would be outside the scope of support, as all the documentation and testing assumes you’re executing the backtest inside the moonshot Docker container.