Coder Social home page Coder Social logo

cn_zipline's Introduction

cn_zipline


PyPI version Py version Build Status Build status Coverage Status

基于tdx的zipline bundle.

zipline是美国Quantopian 公司开源的量化交易回测引擎,它使用Python语言开发, 部分代码使用cython融合了部分c语言代码。Quantopian 在它的网站上的回测系统就是基于zipline的, 经过生产环境的长期使用,已经比完善,并且在持续的改进中。

zipline的基本使用方法在http://www.zipline.io/beginner-tutorial.html, 对于zipline的深度解析,可以看大神rainx写的文档,本项目中的大部分依赖项目也都是rainx开发的项目 `

数据源:

cn_zipline的历史k线以及除息除权数据来自通达信,数据接口来自项目github 项目tdx https://github.com/JaysonAlbert/tdx

安装:

pip install cn_zipline

注意:在windows上,如果zipline安装失败,先用conda install -c Quantopian zipline安装zipline,然后再安装cn_zipline

cn_zipline/extension.py拷贝至zipline的数据目录,默认为~/.zipline    

使用:

cn_zipline与zipline大同小异,具体使用方法请参考zipline官方文档。不同之处在于,ingest数据时请使用 cn_zipline命令,管理以及清理bundls数据时使用zipline。运行策略的形式也不同,为便于调试代码,采用直接运行策略脚本, 而不是通过zipline run命令来运行。下面是使用示例:

ingest数据:

cn_zipline ingest -b tdx

编辑策略cn_zipline/examples/buyapply.py

from zipline.api import order, record, symbol


def initialize(context):
    pass


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


if __name__ == '__main__':
    from cn_zipline.utils.run_algo import run_algorithm
    from zipline.utils.cli import Date
    from cn_stock_holidays.zipline.default_calendar import shsz_calendar

    start = Date(tz='utc', as_timestamp=True).parser('2017-01-01')

    end = Date(tz='utc', as_timestamp=True).parser('2017-10-20')
    run_algorithm(start, end, initialize, 10e6, handle_data=handle_data, bundle='tdx',trading_calendar=shsz_calendar,output='out.pickle')

运行策略文件 cn_zipline/examples/buyapply.py

运行分析脚本cn_zipline/examples/analyse.py

cn_zipline's People

Contributors

jaysonalbert avatar firefirejuly avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.