-1

我是一个新手,正在使用zipline并尝试评估量化投资策略的回测结果。我使用以下方法进行回测:

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

然后我创建一个新笔记本并尝试使用以下命令读取相同的结果:

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

我得到一个很长的堆栈跟踪以

(...)
/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'

我的zipline包版本是1.4.0. 使用以前的版本zipline,我能够读取这些数据并对其进行处理,但目前,我什至无法读取它!我在这里想念什么?

更新:它可以在 ipython 控制台中使用,但在 jupyter 笔记本中仍然无法使用。

4

1 回答 1

0

这取决于您如何配置安装 zipline 的环境。

如果您使用 Anaconda:

  1. 验证 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
>>> 

如果此处出现错误,zipline 未正确安装。如果是这种情况,请返回并正确安装 zipline。

否则,请从此环境启动 Jupyter Notebook:

  1. 打开 Anaconda 导航器
  2. 环境
  3. 在 Jupyter Notebook 中打开

从那里,您应该能够在 Jupyter Notebook 中使用 zipline。

于 2020-11-19T03:52:48.013 回答