[英]How to install zipline module in pycharm?
我使用 pycharm 作為我的 IDE,我發現將 zipline 安裝到 pycharm 的問題。 我已經通過 pip install zipline 嘗試了該方法,但它不起作用。
有沒有我遺漏的部分或處理它的任何指南?
首先,在 PyCharm 中打開Settings -> Project(XXX) -> Project Interpreter
。 然后單擊屏幕右上角的+
圖標,在搜索欄中鍵入Zipline
,然后單擊Install Package
以安裝 Zipline。
您需要通過在命令行上運行來下載示例 Quandl 數據:
zipline ingest -b quantopian-quandl
要測試 Zipline 是否已成功安裝,請創建“dual_moving_average.py”並粘貼到此示例應用程序中:
from zipline.api import (
history,
order_target,
record,
symbol,
)
def initialize(context):
context.i = 0
def handle_data(context, data):
# Skip first 300 days to get full windows
context.i += 1
if context.i < 300:
return
# Compute averages
# history() has to be called with the same params
# from above and returns a pandas dataframe.
short_mavg = history(100, '1d', 'price').mean()
long_mavg = history(300, '1d', 'price').mean()
sym = symbol('AAPL')
# Trading logic
if short_mavg[sym] > long_mavg[sym]:
# order_target orders as many shares as needed to
# achieve the desired number of shares.
order_target(sym, 100)
elif short_mavg[sym] < long_mavg[sym]:
order_target(sym, 0)
# Save values for later inspection
record(AAPL=data[sym].price,
short_mavg=short_mavg[sym],
long_mavg=long_mavg[sym])
要使用 Zipline 運行算法,請在命令行上執行以下命令(當然,您可以根據自己的喜好將日期更改為時間范圍):
zipline run -f dual_moving_average.py --start 2011-1-1 --end 2012-1-1 -o dma.pickle
如果這一切都沒有錯誤,那就跳一段快樂的舞吧! :-) 因為現在已經安裝了 Zipline,並且您已經運行了您的第一個算法。
不幸的是,MikeyE建議的解決方案對我不起作用,因為我沒有在那里列出滑索——對我有用的是
conda install -c Quantopian zipline
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.