Moonshot not recognizing file for backtest

Hi there,

I tried running a backtest with Moonshot but it isn’t recognizing the file I referenced. The error is:

HTTPError: (‘500 Server Error: INTERNAL SERVER ERROR for url: http://houston/moonshot/backtests.csv?strategies=tester&start_date=2020-10-01&end_date=2020-10-06&details=True’, {‘status’: ‘error’, ‘msg’: 'strategy tester does not exist, registered strategies are: '})

The code I’m running in a notebook file is this:
from quantrocket.moonshot import backtest
from moonchart import Tearsheet

backtest([“tester”], start_date=“2020-10-01”, end_date=“2020-10-06”,
filepath_or_buffer=“atrm.csv”, details=True)

The “tester” file (the one I am trying to backtest), is in the Moonshot folder, as per the documentation recommends. I have gone through the documentation and the support forum to find a fix, but haven’t come across one.

What am I doing wrong?

I’ve tried the following:
Renaming the file
Transferring the code to another file and backtesting that one
Closing and reopening Jupyter
Running the backtest from the CLI instead of a notebook

Please let me know what I should do. Thanks.

Try starting with the moonshot-intro to make sure you get the folder in the right place.

Hi there. I am a little unclear as to what you meant, so here’s everything I tried.

  1. used the codeload command to get the moonshot-intro
    2.Tried backtesting the “umd” file
  2. Copied and pasted my “tester” file into the moonshot-intro folder
  3. Put the moonshot-intro folder into the moonshot folder and backtested my “tester” file
  4. Put the moonshot-intro folder into the moonshot folder and backtested “umd”

Steps 2-4 generated the same error. However, step 5 generated a different one. Below is the command I ran and the new error it generated.

from quantrocket.moonshot import backtest
from moonchart import Tearsheet

backtest([“umd”], start_date=“2020-10-01”, end_date=“2020-10-06”,
filepath_or_buffer=“atrm.csv”, details=True)

HTTPError Traceback (most recent call last)
4 backtest([“umd”], start_date=“2020-10-01”, end_date=“2020-10-06”,
----> 5 filepath_or_buffer=“atrm.csv”, details=True)

/opt/conda/lib/python3.7/site-packages/quantrocket/ in backtest(strategies, start_date, end_date, segment, allocations, nlv, params, details, output, filepath_or_buffer, no_cache)
135 params=_params, timeout=606024)
–> 137 houston.raise_for_status_with_json(response)
139 filepath_or_buffer = filepath_or_buffer or sys.stdout

/opt/conda/lib/python3.7/site-packages/quantrocket/ in raise_for_status_with_json(response)
204 e.json_response = {}
205 e.args = e.args + (“please check the logs for more details”,)
–> 206 raise e
208 # Instantiate houston so that all callers can share a TCP connection (for

/opt/conda/lib/python3.7/site-packages/quantrocket/ in raise_for_status_with_json(response)
196 “”"
197 try:
–> 198 response.raise_for_status()
199 except requests.exceptions.HTTPError as e:
200 try:

/opt/conda/lib/python3.7/site-packages/requests/ in raise_for_status(self)
939 if http_error_msg:
–> 940 raise HTTPError(http_error_msg, response=self)
942 def close(self):

HTTPError: (‘500 Server Error: INTERNAL SERVER ERROR for url: http://houston/moonshot/backtests.csv?strategies=umd&start_date=2020-10-01&end_date=2020-10-06&details=True’, {‘status’: ‘error’, ‘msg’: ‘sequence item 0: expected str instance, NoneType found’})

What should I do?

I think I’ve said this to you before, but you need more help than is offered through the support forum. If you have a budget for paid support, please reach out privately. If you don’t want to go that route, my advice is to read the documentation and tutorials much more carefully and thoroughly. Your questions indicate you are often just trying somewhat random things and hoping it works. If you worked methodically through the moonshot-intro, for example, you would not have tried some of the things you did, since the tutorial actually includes a command to put the file exactly where it belongs.

Sometimes this error pops up for me if I have the COMMISSION parameter set, but forgot the class to inherit commissions from in the file.

from moonshot.commission import FuturesCommission

# I forgot to put this class in
class GlobexEquityEMiniFixedCommission(FuturesCommission):
    CARRYING_FEE_PER_CONTRACT = 0 # Depends on equity in excess of margin requirement

class MyStrategy(Moonshot):

    CODE = "my-strategy"
    DB = "my-db"
    COMMISSION_CLASS = GlobexEquityEMiniFixedCommission