简体   繁体   English

如何在pycharm中安装zipline模块?

[英]How to install zipline module in pycharm?

I am using pycharm as my IDE, I found problem to install zipline to pycharm.我使用 pycharm 作为我的 IDE,我发现将 zipline 安装到 pycharm 的问题。 I have tried the method by pip install zipline, but it is not working.我已经通过 pip install zipline 尝试了该方法,但它不起作用。

Are there any parts I missed or any guide to deal with it?有没有我遗漏的部分或处理它的任何指南?

To start, in PyCharm open Settings -> Project(XXX) -> Project Interpreter .首先,在 PyCharm 中打开Settings -> Project(XXX) -> Project Interpreter Then click on the + icon in the top right of the screen, type Zipline in the search bar, then click on Install Package to install Zipline.然后单击屏幕右上角的+图标,在搜索栏中键入Zipline ,然后单击Install Package以安装 Zipline。

You'll need to download the sample Quandl data, by running this on the command line:您需要通过在命令行上运行来下载示例 Quandl 数据:

zipline ingest -b quantopian-quandl

To test if Zipline was installed successfully, create 'dual_moving_average.py' and paste in this sample application:要测试 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])

To run the algo using Zipline, execute the following on the command line (you can change the dates to a time-frame more to your liking of course):要使用 Zipline 运行算法,请在命令行上执行以下命令(当然,您可以根据自己的喜好将日期更改为时间范围):

zipline run -f dual_moving_average.py --start 2011-1-1 --end 2012-1-1 -o dma.pickle

If all this works without error, do a little happy dance!如果这一切都没有错误,那就跳一段快乐的舞吧! :-) Because, Zipline is now installed, and you've run your first algo. :-) 因为现在已经安装了 Zipline,并且您已经运行了您的第一个算法。

不幸的是,MikeyE建议的解决方案对我不起作用,因为我没有在那里列出滑索——对我有用的是

conda install -c Quantopian zipline

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM