您当前的位置: 首页 > 

川川菜鸟

暂无认证

  • 3浏览

    0关注

    969博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

jupyter配置虚拟环境:安装zipline,quandl

川川菜鸟 发布时间:2022-02-21 06:08:11 ,浏览量:3

zipline安装

官方说版本用3.5还强烈建议用conda,我尝试window实在太累了。

创建环境:

conda create -n env_zipline python=3.5

使用环境:

conda activate env_zipline

退出则是:

conda deactivate 

安装:

conda install -c Quantopian zipline

安装这个模块,会附带安装几十个依赖模块,我这笔记本疯狂转… 在这里插入图片描述 查看:

conda env list

在这里插入图片描述 安装ipykernel:

conda install ipykernel

将选择的conda环境注入Jupyter Notebook

python -m ipykernel install --user --name env_zipline --display-name "conda env_zipline"

在这里插入图片描述 打开notebook

jupyter notebook

在这里插入图片描述 进去就是环境里面了

quandl安装

进入网站:

https://data.nasdaq.com/account/profile

创建账号,到用户设置查看key: 在这里插入图片描述 执行:

set QUANDL_API_KEY=qLkRnYQDoj-7yJUjgoD7

再执行:

zipline ingest -b quandl

安装又遇到了这个错误:

ValueError: Boolean array expected for the condition, not float64

解决办法pandas降到0.18.1:

conda install pandas==0.18.1

再来执行:

zipline ingest -b quandl

成功!! 在这里插入图片描述

测试

测试代码test.py:

# coding=gbk
"""
作者:川川
公众号:玩转大数据
@时间  : 2022/2/21 5:35
"""
from zipline.api import order, record, symbol
from zipline.finance import commission, slippage


def initialize(context):
    context.asset = symbol('AAPL')

    # Explicitly set the commission/slippage to the "old" value until we can
    # rebuild example data.
    # github.com/quantopian/zipline/blob/master/tests/resources/
    # rebuild_example_data#L105
    context.set_commission(commission.PerShare(cost=.0075, min_trade_cost=1.0))
    context.set_slippage(slippage.VolumeShareSlippage())


def handle_data(context, data):
    order(context.asset, 10)
    record(AAPL=data.current(context.asset, 'price'))


# Note: this function can be removed if running
# this algorithm on quantopian.com
def analyze(context=None, results=None):
    import matplotlib.pyplot as plt
    # Plot the portfolio and asset data.
    ax1 = plt.subplot(211)
    results.portfolio_value.plot(ax=ax1)
    ax1.set_ylabel('Portfolio value (USD)')
    ax2 = plt.subplot(212, sharex=ax1)
    results.AAPL.plot(ax=ax2)
    ax2.set_ylabel('AAPL price (USD)')

    # Show the plot.
    plt.gcf().set_size_inches(18, 8)
    plt.show()


def _test_args():
    """Extra arguments to use when zipline's automated tests run this example.
    """
    import pandas as pd

    return {
        'start': pd.Timestamp('2014-01-01', tz='utc'),
        'end': pd.Timestamp('2014-11-01', tz='utc'),
    }

执行:

zipline run -f test.py --start 2000-1-1 --end 2014-1-1 -o buyapple_out.pickle

然而又遇到报错 json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0), 解决:

https://polygon.io/dashboard/

得到你的密钥: 在这里插入图片描述 到data目录下:benchmarks.py 中更改 API 请求 在这里插入图片描述 修改如下: 在这里插入图片描述 …md不改了,睡觉,请参考:

https://github.com/quantopian/zipline/issues/2480
关注
打赏
1665165634
查看更多评论
立即登录/注册

微信扫码登录

0.2408s