How to Execute Zipline in Pycharm for Debugging
我是 Python 初学者,想了解 zipline 是否适合我。
在调试和查看某些点的变量内容时,我可以最好地理解其他人的代码。为此,我最喜欢 Pycharms 的调试功能。
从我理解的 zipline 手册中,该 zipline 可以从操作系统命令行执行:
1 | zipline run -f ../../zipline/examples/buyapple.py --start 2000-1-1 --end 2014-1-1 -o buyapple_out.pickle |
或通过 IPython:
The IPython Notebook is a very powerful browser-based interface to a Python interpreter (this tutorial was written in it). As it is already the de-facto interface for most quantitative researchers zipline provides an easy way to run your algorithm inside the Notebook without requiring you to use the CLI.
有什么方法可以让我使用 zipline 和 Pycharm,这样我也可以调试 zipline 代码本身(或者至少是我自己的代码)?
用 pip 安装后,在我的文件系统中找到以下入口点:
文件
1 2 3 4 5 6 7 8 9 10 11 | #!/home/user/anaconda3/bin/python # -*- coding: utf-8 -*- import re import sys from zipline.__main__ import main if __name__ == '__main__': sys.argv[0] = re.sub(r'(-script\\.pyw?|\\.exe)?$', '', sys.argv[0]) sys.exit(main()) |
但是尝试以这种方式访问??滑索是否明智?
还是克隆 git 存储库并以这种方式调用 zipline 更好?package器应该如何将参数传递给 zipline?
您可以使用
像这样:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | from datetime import datetime import pandas as pd from zipline import run_algorithm start = pd.Timestamp(datetime(2018, 1, 1, tzinfo=pytz.UTC)) end = pd.Timestamp(datetime(2018, 7, 25, tzinfo=pytz.UTC)) run_algorithm(start=start, end=end, initialize=initialize, capital_base=100000, handle_data=handle_data, before_trading_start=before_trading_start, data_frequency='daily') |
我正在使用这些软件包:
1 2 3 4 5 | pandas==0.18.1 pandas-datareader==0.6.0 zipline-live==1.1.0.5 numpy==1.15.0 matplotlib==2.2.2 |
和