我想在没有 jupyter 笔记本的情况下离线使用 zipline。我试图让 zipline 从 quandl 摄取并成功使用数据,但我没有成功。这是我的环境-
python 3.5,使用 pycharm,pip3 freeze 给了我-
alembic==1.0.5
alphalens==0.3.4
backcall==0.1.0
bcolz==0.12.1
Bottleneck==1.2.1
certifi==2018.11.29
chardet==3.0.4
Click==7.0
colorama==0.4.1
contextlib2==0.5.5
cycler==0.10.0
cyordereddict==1.0.0
Cython==0.29.2
decorator==4.3.0
empyrical==0.5.0
idna==2.8
intervaltree==3.0.2
ipython==7.2.0
ipython-genutils==0.2.0
jedi==0.13.2
kiwisolver==1.0.1
Logbook==1.4.1
lru-dict==1.1.6
lxml==4.3.0
Mako==1.0.7
MarkupSafe==1.1.0
matplotlib==3.0.2
multipledispatch==0.6.0
networkx==1.11
numexpr==2.6.9
numpy==1.14.3
pandas==0.22.0
pandas-datareader==0.7.0
parso==0.3.1
patsy==0.5.1
pickleshare==0.7.5
prompt-toolkit==2.0.7
pyfolio==0.9.0
Pygments==2.3.1
pyparsing==2.3.0
python-dateutil==2.7.5
python-editor==1.0.3
pytz==2018.7
requests==2.21.0
requests-file==1.4.3
scikit-learn==0.20.2
scipy==1.2.0
seaborn==0.9.0
six==1.12.0
sortedcontainers==2.1.0
SQLAlchemy==1.2.15
statsmodels==0.9.0
tables==3.4.4
toolz==0.9.0
trading-calendars==1.6.1
traitlets==4.3.2
urllib3==1.24.1
wcwidth==0.1.7
win-unicode-console==0.5
wrapt==1.10.11
zipline==1.3.0
我的测试代码如下:
from zipline.api import order, record, symbol
import os
def initialize(context):
pass
def handle_data(context, data):
order(symbol('AAPL'), 10)
record(AAPL=data.current(symbol('AAPL'), 'price'))
def run_algo():
data_ingest = False
bundle = 'quantopian-quandl'
if data_ingest:
auth_tok = "################"
data_ingest_command = 'set QUANDL_API_KEY=%s && zipline ingest -b %s' % (auth_tok,bundle)
os.system(data_ingest_command)
path = 'C:\\Users\\mattt\\PycharmProjects\\FFTTrading\\trades2.py'
print('zipline run -f %s --bundle %s --start 2016-3-1 --end 2017-12-30' % (path,bundle))
run_command = 'zipline run -f %s --bundle %s --start 2013-3-1 --end 2017-12-28 -o backtest.pickle' % (path,bundle)
os.system(run_command)
run_algo()
我已经运行了摄取数据部分并且它成功了。我最后一次摄取数据是在 2019 年 1 月 5 日晚上 10:49(我的时间)。我在 2019 年 1 月 7 日(我的时间)下午 12:55 运行上面的代码,但是我得到了这个输出-
zipline run -f C:\Users\mattt\PycharmProjects\FFTTrading\trades2.py --bundle quantopian-quandl --start 2016-3-1 --end 2017-12-30
[2019-01-07 17:55:33.814552] INFO: Loader: Cache at C:\Users\mattt/.zipline\data\SPY_benchmark.csv does not have data from 2013-03-01 00:00:00+00:00 to 2017-12-28 00:00:00+00:00.
[2019-01-07 17:55:33.814552] INFO: Loader: Downloading benchmark data for 'SPY' from 2013-02-28 00:00:00+00:00 to 2017-12-28 00:00:00+00:00
[2019-01-07 17:55:35.311201] WARNING: Loader: Still don't have expected benchmark data for 'SPY' from 2013-02-28 00:00:00+00:00 to 2017-12-28 00:00:00+00:00 after redownload!
zipline run -f C:\Users\mattt\PycharmProjects\FFTTrading\trades2.py --bundle quantopian-quandl --start 2016-3-1 --end 2017-12-30
[2019-01-07 17:55:40.745023] WARNING: Loader: Refusing to download new benchmark data because a download succeeded at 2019-01-07 17:55:35.311202+00:00.
zipline run -f C:\Users\mattt\PycharmProjects\FFTTrading\trades2.py --bundle quantopian-quandl --start 2016-3-1 --end 2017-12-30
[2019-01-07 17:55:46.134072] WARNING: Loader: Refusing to download new benchmark data because a download succeeded at 2019-01-07 17:55:35.311202+00:00.
zipline run -f C:\Users\mattt\PycharmProjects\FFTTrading\trades2.py --bundle quantopian-quandl --start 2016-3-1 --end 2017-12-30
[2019-01-07 17:55:51.581558] WARNING: Loader: Refusing to download new benchmark data because a download succeeded at 2019-01-07 17:55:35.311202+00:00.
zipline run -f C:\Users\mattt\PycharmProjects\FFTTrading\trades2.py --bundle quantopian-quandl --start 2016-3-1 --end 2017-12-30
谁能弄清楚这里发生了什么?我将如何正确摄取和使用数据?谢谢!