2017-02-21 192 views
0

我使用pycharm作为我的IDE,我发现安装zipline到pycharm的问题。我已经尝试过使用pip install zipline的方法,但它不起作用。如何在pycharm中安装zipline模块?

有没有我错过的部分或任何指导来处理它?

+1

通过pip安装时出现了什么问题? –

+0

终端通过 的结果成功安装了Logbook-1.0.0 Mako-1.0.6 alembic-0.8.10 bcolz-0.12.1 cachetools-2.0.0 cyordereddict-1.0.0 empyrical-0.2.2 intervaltree-2.1.0 pandas-0.17.1 pandas-datareader-0.3.0.post0 python-editor-1.0.3 requests-file-1.4.1 requests-ftp-0.3.1 sortedcontainers-1.5.7 zipline-1.0.2 它会导致错误而我键入 import zipline – AnsonChan

+0

您确定您的终端使用与PyCharm相同的解释器吗?尝试去设置(或首选项),然后选择项目 - >项目解释器。查看是否在已安装的软件包中列出了zipline。如果没有,使用PyCharm的UI(+符号)从PyCharm中添加zipline。 –

回答

1

开始,在PyCharm中打开Settings -> Project(XXX) -> Project Interpreter。然后点击屏幕右上角的+图标,在搜索栏中输入Zipline,然后点击Install Package安装Zipline。

你需要下载示例Quandl数据,通过在命令行中运行以下命令:

zipline ingest -b quantopian-quandl 

为了测试是否溜索已成功安装,打造“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 run -f dual_moving_average.py --start 2011-1-1 --end 2012-1-1 -o dma.pickle 

如果这一切都没有错误的工作,做一个快乐的小舞! :-)因为,现在已经安装了Zipline,并且已经运行了第一个算法。

+0

This work,thanks lot :) – AnsonChan