如何在pycharm中安装zipline模块?

时间:2017-02-21 03:20:12

标签: python pycharm zipline

我使用pycharm作为我的IDE,我发现安装zipline到pycharm的问题。我已经通过pip install zipline尝试了这个方法,但它无法正常工作。

我是否遗漏了任何部分或有任何指导来处理它?<​​/ p>

2 个答案:

答案 0 :(得分:1)

首先,在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现已安装,你已经运行了第一个算法。

答案 1 :(得分:0)

不幸的是,MikeyE的suggested solution对我没有用,因为我那里没有列出滑索-相反,对我有用的是

conda install -c Quantopian zipline