Skip to main content

Zipline Pipeline extension for live trade

Project description

Zipline Pipeline Extension for Live Trading

pipeline-live is an extension for zipline pipeline independently usable for live trading, outside of zipline. While zipline is a great backtesting library, the default Pipeline API requires complicated setup for data bundle, which is often challenging to average users. Quantopian's proprietary data sources such as Morningstar is also not available to many. This library is to address this issue by using online API data sources and simplify the interface for live trading usage. The interface complies the original zipline/pipeline for the most part. For more details about the Pipeline API, please see Quantopian's tutorial and zipline document.

If you are looking to use this library for your Quantopian algorithm, check out the migration document.

Data Sources

This library predominantly relies on the Alpaca Data API for daily price data. For users with funded Alpaca brokerage accounts, several Polygon fundamental data endpoints are supported. IEX Cloud data is also supported, though if too much data is requested, it stops being free. (See the note in the IEX section below.)

Install

pipeline-live is a PyPI module and you can install it using pip command.

$ pip install pipeline-live

This module is tested and expected to work with python 3.6 and later

Example

Here is a simple pipeline example.

from pipeline_live.engine import LivePipelineEngine
from pipeline_live.data.sources.iex import list_symbols
from pipeline_live.data.alpaca.pricing import USEquityPricing
from pipeline_live.data.polygon.fundamentals import PolygonCompany
from pipeline_live.data.iex.factors import AverageDollarVolume
from zipline.pipeline import Pipeline

eng = LivePipelineEngine(list_symbols)
top5 = AverageDollarVolume(window_length=20).top(5)
pipe = Pipeline({
    'close': USEquityPricing.close.latest,
    'marketcap': PolygonCompany.marketcap.latest,
}, screen=top5)

df = eng.run_pipeline(pipe)

'''
        close     marketcap
AAPL   215.49  1.044037e+12
AMZN  1902.90  9.293372e+11
FB     172.90  5.042383e+11
QQQ    180.80  7.092998e+10
SPY    285.79  2.737475e+11
'''

Data Cache

Since most of the data does not change during the day, the data access layer caches the dataset on disk. In case you need to purge the cache, the cache data is located in $ZIPLINE_ROOT/data/daily_cache.

Pipeline API

pipeline_live.engine.LivePipelineEngine

This class provides the similar interface to zipline.pipeline.engine.SimplePipelineEngine. The main difference is its run_pipeline does not require the start and end dates as parameters, and returns a DataFrame with the data for the current date (US/Eastern time). Its constructor accepts list_symbol function that is supposed to return the full set of symbols as a string list, which is used as the maximum universe inside the engine.

Alpaca Data API

The Alpaca Data API is currently the least-limited source of pricing data supported by pipeline-live. In order to use the Alpaca Data API, you'll need to register for an Alpaca account here and generate API key information with the dashboard. Once you have your keys generated, you need to store them in the following environment variables:

APCA_API_BASE_URL
APCA_API_KEY_ID
APCA_API_SECRET_KEY

pipeline_live.data.alpaca.pricing.USEquityPricing

This class provides the basic price information retrieved from Alpaca Data API.

Polygon Data Source API

You will need to set an Alpaca API key as APCA_API_KEY_ID to use this API.

pipeline_live.data.polygon.fundamentals.PolygonCompany

This class provides the DataSet interface using Polygon Symbol Details API

pipeline_live.data.polygon.filters.IsPrimaryShareEmulation

Experimental. This class filteres symbols by the following rule to return something close to IsPrimaryShare() in Quantopian.

  • must be a US company
  • must have a valid financial data

IEX Data Source API

To use IEX-source data, you need to sign up for an IEX Cloud account and save your IEX token as an environment variable called IEX_TOKEN.

IMPORTANT NOTE: IEX data is now limited for free accounts. In order to avoid using more messages than you are allotted each month, please be sure that you are not using IEX-sourced factors too frequently or on too many securities. For more information about how many messages each method will cost, please refer to this part of the IEX Cloud documentation.

pipeline_live.data.iex.pricing.USEquityPricing

This class provides the basic price information retrieved from IEX Chart API.

pipeline_live.data.iex.fundamentals.IEXCompany

This provides the DataSet interface using IEX Company API.

pipeline_live.data.iex.fundamentals.IEXKeyStats

This provides the DataSet interface using IEX Key Stats API.

pipeline_live.data.iex.factors

It is important to note that the original builtin factors from zipline does not work here as is, since some of them rely on zipline's USEquityPricing class. This package provides the same set of zipline's builtin factor classes using pipeline_live.data.iex.pricing.USEquityPricing class. For the complete list of builtin factors, please refer zipline document

pipeline_live.data.iex.classifiers.Sector()

A shortcut for IEXCompany.sector.latest

pipeline_live.data.iex.classifiers.Industry()

A shortcut for IEXCompany.industry.latest

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pipeline-live-0.1.9.tar.gz (24.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pipeline_live-0.1.9-py3-none-any.whl (36.2 kB view details)

Uploaded Python 3

File details

Details for the file pipeline-live-0.1.9.tar.gz.

File metadata

  • Download URL: pipeline-live-0.1.9.tar.gz
  • Upload date:
  • Size: 24.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.0 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.1

File hashes

Hashes for pipeline-live-0.1.9.tar.gz
Algorithm Hash digest
SHA256 4d534de16487a3a8f3295b4b850ee9ec4e7764a17336b4cee31ded55eb2c5f93
MD5 ff426f0885c2244d0629741abefd1a58
BLAKE2b-256 dabcaa44fb9a7b1350048eeb58ba9147ada62270ba0a22edc950940088abd0d2

See more details on using hashes here.

File details

Details for the file pipeline_live-0.1.9-py3-none-any.whl.

File metadata

  • Download URL: pipeline_live-0.1.9-py3-none-any.whl
  • Upload date:
  • Size: 36.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.0 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.1

File hashes

Hashes for pipeline_live-0.1.9-py3-none-any.whl
Algorithm Hash digest
SHA256 8dc2816d27d4fcfd41d5844fcc4c9700c295c6793ad4e549f5d470b6d588b600
MD5 fa7a60d75c2aa2f216d0ca9e04c40fab
BLAKE2b-256 528cc5c299cc747f78cb25cbadc29e5e359f2ff8fb6eba11170a755ac4cbb078

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page