简体   繁体   English

Zipline错误:AttributeError:'NoneType'对象没有属性'index'

[英]Zipline Error: AttributeError: 'NoneType' object has no attribute 'index'

I'd like to automate my manual trading strategies. 我想自动执行我的手动交易策略。 However, for the beginning, I tried to reproduce Zipline's simple example of buying Apple stocks. 但是,从一开始,我就尝试重现Zipline的简单例子来购买苹果股票。 I struggled running the algorithm with run_algorithm() . 我很难通过run_algorithm()运行算法。 When I was trying to run the 'dual moving average cross', the exact same error came up. 当我尝试运行“双移动平均线交叉”时,出现了完全相同的错误。 I also tried IPython and Terminal but still get that error. 我也尝试了IPython和Terminal,但仍然收到该错误。 I couldn't find anything related to that either in this forum. 在这个论坛中我都找不到与此相关的任何信息。 I would very grateful for any hints. 我非常感谢您的任何提示。 Thank you. 谢谢。

I'm using Python 3.6 on macOS and Zipline version 1.1.1. 我在macOS和Zipline 1.1.1版上使用Python 3.6。

That's the code: 那是代码:

import zipline as zl from zipline.api import order, record, symbol


def initialize(context):
    pass


def handle_data(context, data):
    order(symbol('AAPL'), 10)
    record(AAPL=data.current(symbol('AAPL'), 'price'))

zl.run_algorithm(start='2015-1-1', end='2017-1-1', initialize=initialize, capital_base=10000)

That's the traceback: 这是回溯:

Traceback (most recent call last): File "/Users/SOL/Desktop/Python/backtest.py", line 13, in zl.run_algorithm(start=2015-1-1, end=2017-1-1, initialize=initialize, capital_base=10000) File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/zipline/utils/run_algo.py", line 360, in run_algorithm environ=environ, File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/zipline/utils/run_algo.py", line 132, in _run env = TradingEnvironment(asset_db_path=connstr, environ=environ) File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/zipline/finance/trading.py", line 99, in init self.bm_symbol, File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/zipline/data/loader.py", line 173, in load_market_data environ, File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/zipline/data/loader.py", line 287, in ensure_treasury_data if not has_data_for_dates(dat 追溯(最近一次通话):文件“ /Users/SOL/Desktop/Python/backtest.py”,第13行,位于zl.run_algorithm(开始= 2015-1-1,结束= 2017-1-1,initialize =初始化,大写字母= 10000)文件“ /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/zipline/utils/run_algo.py”,行360,在run_algorithm中,environ = environ,文件“ /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/zipline/utils/run_algo.py”,第132行,位于_run env = TradingEnvironment(asset_db_path = connstr,environ = environ)在初始self.bm_symbol文件“ /Library/Frameworks/Versions/3.6/lib/python3.6/site-packages/zipline/finance/trading.py”的第99行中,文件“ / Library / Frameworks /在load_market_data环境中的Python.framework / Versions / 3.6 / lib / python3.6 / site-packages / zipline / data / loader.py“,第173行,文件“ /Library/Frameworks/Python.framework/Versions/3.6/lib” /python3.6/site-packages/zipline/data/loader.py“,第287行,如果没有has_data_for_dates(dat a, first_date, last_date): File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/zipline/data/loader.py", line 87, in has_data_for_dates dts = series_or_df.index AttributeError: 'NoneType' object has no attribute 'index' a,第一个日期,最后一个日期):文件“ /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/zipline/data/loader.py”,第87行,位于has_data_for_dates dts = series_or_df中。 index AttributeError:'NoneType'对象没有属性'index'

FYI, I think the problem has to do with SSL certificates in python 3.6 . 仅供参考,我认为问题与python 3.6中的 SSL证书有关。 Unfortunately the error message (especially if you ignore the stack trace) is not very helpful. 不幸的是,错误消息(尤其是如果您忽略堆栈跟踪信息)不是很有帮助。 For mac try: sudo /Applications/Python\\ 3.6/Install\\ Certificates command to reinstall the certificates 对于Mac,请尝试: sudo /Applications/Python\\ 3.6/Install\\ Certificates命令以重新安装证书

According to docs here, start and end are datetime objects, and not strings. 根据此处的文档startenddatetime对象,而不是字符串。 So, You should define those as following: 因此,您应该定义以下内容:

from datetime import datetime

start = datetime(year=2015, month=1, day=1)
end = datetime(year=2017, month=1, day=1)

and then call 然后打电话

zl.run_algorithm(start=start, end=end, initialize=initialize, capital_base=10000)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Zipline错误:AttributeError:'NoneType'对象没有属性'fetch_csv' - Zipline Error: AttributeError: 'NoneType' object has no attribute 'fetch_csv' AttributeError: 'NoneType' 对象没有属性 'index' - AttributeError: 'NoneType' object has no attribute 'index' AttributeError:'NoneType'对象没有属性'group'错误 - AttributeError: 'NoneType' object has no attribute 'group' error 为什么错误 - AttributeError: 'NoneType' object 没有属性 - Why error - AttributeError: 'NoneType' object has no attribute AttributeError: 'NoneType' 对象没有属性 'copy' 错误 - AttributeError: 'NoneType' object has no attribute 'copy' error 错误:AttributeError:'NoneType' 对象没有属性 'text' - Error: AttributeError: 'NoneType' object has no attribute 'text' 错误:AttributeError:'NoneType' object 没有属性 'find' - Error: AttributeError: 'NoneType' object has no attribute 'find' 错误“ AttributeError:'NoneType'对象没有属性'append'” - Error “AttributeError: 'NoneType' object has no attribute 'append'” Python“AttributeError:'NoneType'对象没有属性”错误 - Python "AttributeError: 'NoneType' object has no attribute" Error AttributeError: 'NoneType' object has no attribute 'split' 错误 - AttributeError: 'NoneType' object has no attribute 'split' Error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM