mccandar
mccandar

Reputation: 788

Cannot read zipline backtest output

I am a newbie using zipline and trying to evaluate the backtest result of a quantitative investment strategy. I use following to perform a backtest:

zipline run -f my_strat.py -s '2009-01-01' -e '2020-06-01' -b my_custom_bundle -o results.csv

Then I create a new notebook and try to read that very same result with:

import pandas as pd
df = pd.read_pickle('results.csv')

I get a very long stack trace ending with

(...)
/usr/lib/python3.6/pickle.py in load(self)
   1048                     raise EOFError
   1049                 assert isinstance(key, bytes_types)
-> 1050                 dispatch[key[0]](self)
   1051         except _Stop as stopinst:
   1052             return stopinst.value
/usr/lib/python3.6/pickle.py in load_stack_global(self)
   1345         if type(name) is not str or type(module) is not str:
   1346             raise UnpicklingError("STACK_GLOBAL requires str")
-> 1347         self.append(self.find_class(module, name))
   1348     dispatch[STACK_GLOBAL[0]] = load_stack_global
   1349 
~/.local/lib/python3.6/site-packages/pandas/compat/pickle_compat.py in find_class(self, module, name)
    115             key = (module, name)
    116             module, name = _class_locations_map.get(key, key)
    --> 117             return super(Unpickler, self).find_class(module, name)
    118 
    119 else:
/usr/lib/python3.6/pickle.py in find_class(self, module, name)
   1386             elif module in _compat_pickle.IMPORT_MAPPING:
   1387                 module = _compat_pickle.IMPORT_MAPPING[module]
-> 1388         __import__(module, level=0)
   1389         if self.proto >= 4:
   1390             return _getattribute(sys.modules[module], name)[0]
ModuleNotFoundError: No module named 'zipline.assets.exchange_info'

My zipline package version is 1.4.0. Using previous release of zipline, I was able to read this data and work on it but currently, I cannot even read it! What is that I am missing here?

Update: it works in ipython console but still does not work in jupyter notebook.

Upvotes: -1

Views: 216

Answers (1)

ttoshev
ttoshev

Reputation: 156

It depends on how you have configured the env where zipline is installed.

If you are using Anaconda:

  1. Verify installation of zipline
% conda activate env_zipline

(env_zipline) % python3

Python 3.6.12 |Anaconda, Inc.| (default, Sep  8 2020, 17:50:39) 
[GCC Clang 10.0.0 ] on darwin
Type "help", "copyright", "credits" or "license" for more information.

>>> import zipline
>>> 

If there is an error here zipline is not installed correctly. If this is the case go back and install zipline correctly.

Otherwise, launch Jupyter Notebook from this environment:

  1. Open Anaconda Navigator
  2. Environments
  3. Open in Jupyter Notebook

From there, you should be able to use zipline in Jupyter Notebook.

Upvotes: 0

Related Questions