zipline框架--簡介


Zipline is a Pythonic algorithmic trading library. It is an event-driven system for backtesting. Zipline is currently used in production as the backtesting and live-trading engine powering Quantopian -- a free, community-centered, hosted platform for building and executing trading strategies.

zipline是一個Pythonic算法交易庫。它是一個事件驅動的回測系統。Zipline目前為Quantopian在生產中被用作回測和實時交易引擎,Quantopian是一個用於建立和執行交易策略的免費的社區中心和托管平台。

 

Features

特征

Ease of Use: Zipline tries to get out of your way so that you can focus on algorithm development. See below for a code example.

使用方便:Zipline試圖解放的雙手,以便你可以專注於算法開發。請參見下面的代碼示例。

"Batteries Included": many common statistics like moving average and linear regression can be readily accessed from within a user-written algorithm.

“內置電池”:許多常見的統計功能,如移動平均和線性回歸,可以很容易地從用戶編寫的算法中調用。

PyData Integration: Input of historical data and output of performance statistics are based on Pandas DataFrames to integrate nicely into the existing PyData ecosystem.

PyDATA集成:歷史數據的輸入和性能統計的輸出是基於Pandas DataFrames格式,以很好地集成到現有的PyDATA生態系統中。

Statistics and Machine Learning Libraries: You can use libraries like matplotlib, scipy, statsmodels, and sklearn to support development, analysis, and visualization of state-of-the-art trading systems.

統計和機器學習庫:您可以使用像matplotlib, scipy, statsmodels, 和 sklearn這樣的庫來支持最先進的交易系統的開發、分析和可視化。

Quickstart

快速啟動

See our getting started tutorial.

看我們入門教程。

 

The following code implements a simple dual moving average algorithm.

下面的代碼實現了一個簡單的雙移動平均算法。

from zipline.api import order_target, record, symbol

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


def handle_data(context, data):
    # Skip first 300 days to get full windows
    context.i += 1
    if context.i < 300:
        return

    # Compute averages
    # data.history() has to be called with the same params
    # from above and returns a pandas dataframe.
    short_mavg = data.history(context.asset, 'price', bar_count=100, frequency="1d").mean()
    long_mavg = data.history(context.asset, 'price', bar_count=300, frequency="1d").mean()

    # Trading logic
    if short_mavg > long_mavg:
        # order_target orders as many shares as needed to
        # achieve the desired number of shares.
        order_target(context.asset, 100)
    elif short_mavg < long_mavg:
        order_target(context.asset, 0)

    # Save values for later inspection
    record(AAPL=data.current(context.asset, 'price'),
           short_mavg=short_mavg,
           long_mavg=long_mavg)

You can then run this algorithm using the Zipline CLI; you'll need a Quandl API key to ingest the default data bundle. Once you have your key, run the following from the command line:
然后可以使用 Zipline CLI運行此算法;您需要一個QUANDL API密鑰來獲取默認數據包。一旦擁有了密鑰,就從命令行運行以下命令:

$ QUANDL_API_KEY=<yourkey> zipline ingest -b quandl
$ zipline run -f dual_moving_average.py --start 2014-1-1 --end 2018-1-1 -o dma.pickle

This will download asset pricing data data from quandl, and stream it through the algorithm over the specified time range. Then, the resulting performance DataFrame is saved in dma.pickle, which you can load an analyze from within Python.
這將從QuANDL下載證券價格數據,並在指定的時間范圍內將其數據流通過算法。然后,將得到的DataFrame性能數據保存在dma.pickle中,可以從Python中加載分析。
You can find other examples in the zipline/examples directory.
您可以在Zipline /examples目錄中找到其他示例。

Questions?
問題?
If you find a bug, feel free to open an issue and fill out the issue template.
如果發現bug,請自由打開問題並填寫問題模板。

Contributing
貢獻
All contributions, bug reports, bug fixes, documentation improvements, enhancements, and ideas are welcome. Details on how to set up a development environment can be found in our development guidelines.
所有的貢獻、bug報告、bug修復、文檔改進、增強和想法都是受歡迎的。關於如何建立開發環境的細節可以在我們的開發指南中找到。
If you are looking to start working with the Zipline codebase, navigate to the GitHub issues tab and start looking through interesting issues. Sometimes there are issues labeled as Beginner Friendly or Help Wanted.
如果你想開始使用Zipline代碼庫,導航到GITHUB問題選項卡,開始瀏覽有趣的問題。有時有些問題被標示為初學友好或樂於助人。
Feel free to ask questions on the mailing list or on Gitter.
在郵件列表或GITER上自由提問。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM