Backtest your Trading Strategies
| Zipline Arrow Version Info | |
|---|---|
| Zipline Reloaded Community |
Zipline Arrow (zipline-arrow) is a fork of Zipline Reloaded (zipline-reloaded) that includes modifications necessary to use zipline-polygon-bundle with custom aggregates calculated from Polygon trades (tick) data flatfiles (https://polygon.io/blog/flat-files). If your's isn't that specific use case then the upstream Zipline Reloaded is probably what you want. Even if you use Polygon minute or daily aggregate flatfiles then you can use zipline-polygon-bundle<0.2 which depends on zipline-reloaded instead of zipline-arrow.
Future plans (and the reason for the name choice) is that Zipline Arrow will migrate from the moribund bcolz-reloaded (Stefan's maintaince fork of the archived bcolz) to PyArrow.
Zipline is a Pythonic event-driven system for backtesting, developed and used as the backtesting and live-trading engine by crowd-sourced investment fund Quantopian. Since it closed late 2020, the domain that had hosted these docs expired. The library is used extensively in the book Machine Larning for Algorithmic Trading by Stefan Jansen who is trying to keep the library up to date and available to his readers and the wider Python algotrading community.
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.
- 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.
- Statistics and Machine Learning Libraries: You can use libraries like matplotlib, scipy, statsmodels, and scikit-klearn to support development, analysis, and visualization of state-of-the-art trading systems.
Note: Release 3.2.2 (the first working release of
zipline-arrow) changes the default calendar handling in order to properly support calendars that aren't in a special list of calendars ("us_futures", "CMES", "XNYS", "NYSE"). That is needed because of the bad interaction of needing to use a new calendar for extended hours and Exchange Calendars uses a defaultstart_dateof 20 years before today (whenever that is) when getting a calendar without specifying astart_date(whichzipline.utils.calendar_utils.get_calendardefaults to 1990-01-01 for the hardcoded list of calendars). In order to make that work smoothly, the default handling of calendars with ingested bundles is also changed so that the calendar loaded from the bundle's metadata is always used (instead of usingget_calendarby name).
Note: Release 3.05 makes Zipline compatible with Numpy 2.0, which requires Pandas 2.2.2 or higher. If you are using an older version of Pandas, you will need to upgrade it. Other packages may also still take more time to catch up with the latest Numpy release.
Note: Release 3.0 updates Zipline to use pandas >= 2.0 and SQLAlchemy > 2.0. These are major version updates that may break existing code; please review the linked docs.
Note: Release 2.4 updates Zipline to use exchange_calendars >= 4.2. This is a major version update and may break existing code (which we have tried to avoid but cannot guarantee). Please review the changes here.
Installation
Zipline supports Python >= 3.9 and is compatible with current versions of the relevant NumFOCUS libraries, including pandas and scikit-learn.
Using pip
If your system meets the pre-requisites described in the installation instructions, you can install Zipline using pip by running:
pip install zipline-reloaded
Using conda
If you are using the Anaconda or miniconda distributions, you install zipline-reloaded from the channel conda-forge like so:
conda install -c conda-forge zipline-reloaded
You can also enable conda-forge by listing it in your .condarc.
In case you are installing zipline-reloaded alongside other packages and encounter conflict errors, consider using mamba instead.
See the installation section of the docs for more detailed instructions and the corresponding conda-forge site.
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. But first, you need to download some market data with historical prices and trading volumes.
This will download asset pricing data from NASDAQ (formerly Quandl).
This requires an API key, which you can get for free by signing up at NASDAQ Data Link.
$ export QUANDL_API_KEY="your_key_here"
$ zipline ingest -b quandl
The following will
- stream the through the algorithm over the specified time range.
- save the resulting performance DataFrame as
dma.pickle, which you can load and analyze from Python using, e.g., pyfolio-reloaded.
$ zipline run -f dual_moving_average.py --start 2014-1-1 --end 2018-1-1 -o dma.pickle --no-benchmark
You can find other examples in the zipline/examples directory.
Questions, suggestions, bugs?
If you find a bug or have other questions about the library, feel free to open an issue and fill out the template.
Release files for zipline-arrow 3.2.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| zipline_arrow-3.2.2.tar.gz | 12.1 MB | Details |
Built distributions (wheels)
Total release size: 90.0 MB
Release files / zipline_arrow-3.2.2.tar.gz
| Download URL | zipline_arrow-3.2.2.tar.gz |
|---|---|
| Size | 12.1 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
469bed70d2256f086f5ab00341066daeb89c98f35fefdf8c175662ac24f10db5
|
|
BLAKE2b-256 checksum How to use checksums |
7adbec10a7002b6f6dd795c01bdf8aaffdc805accd9e15dc9e06662ec8e8ca97
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Mar 30, 2025.
Transparency logRelease files / zipline_arrow-3.2.2-cp312-cp312-win_amd64.whl
| Download URL | zipline_arrow-3.2.2-cp312-cp312-win_amd64.whl |
|---|---|
| Size | 4.8 MB |
| Tags | CPython 3.12 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
232745aaf265e0102a463a3f8f4cf35ac8ddd8c1b7c86674933b2b2e95acf26b
|
|
BLAKE2b-256 checksum How to use checksums |
959dd9ecf86e2ee09b6ba09ba6b6e1b37b2850bbbd317ca0fbb0d9137ac1d3e4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Mar 30, 2025.
Transparency logRelease files / zipline_arrow-3.2.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | zipline_arrow-3.2.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 11.5 MB |
| Tags | CPython 3.12 Linux glibc 2.17+ x86-64 |
|
SHA-256 checksum How to use checksums |
2306325b1f0349041c9d283e3100c133dcedcf1fe2da377c210e133d7e57dc94
|
|
BLAKE2b-256 checksum How to use checksums |
49632701f8e311cbbbb312652d27570898dc1a609615e1549b52fa18c30b416a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Mar 30, 2025.
Transparency logRelease files / zipline_arrow-3.2.2-cp312-cp312-macosx_11_0_x86_64.whl
| Download URL | zipline_arrow-3.2.2-cp312-cp312-macosx_11_0_x86_64.whl |
|---|---|
| Size | 4.9 MB |
| Tags | CPython 3.12 macOS 11.0+ x86-64 |
|
SHA-256 checksum How to use checksums |
90310b33ecd187dc5e44311ed360dedaa100042d0c5e57353c9541715f77231a
|
|
BLAKE2b-256 checksum How to use checksums |
77ebfb869523a78fb7bd6f81984d35ac289cf3e8756d7a6034feb38729b58207
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Mar 30, 2025.
Transparency logRelease files / zipline_arrow-3.2.2-cp312-cp312-macosx_11_0_arm64.whl
| Download URL | zipline_arrow-3.2.2-cp312-cp312-macosx_11_0_arm64.whl |
|---|---|
| Size | 4.8 MB |
| Tags | CPython 3.12 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
7301af3463e0d0957042c7489a31098a8c4c0127dabf429e156871ce4bacee31
|
|
BLAKE2b-256 checksum How to use checksums |
b542d8c07d44a3490025908b94a160401d59341d0fa6f890136ce3d248562c68
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Mar 30, 2025.
Transparency logRelease files / zipline_arrow-3.2.2-cp311-cp311-win_amd64.whl
| Download URL | zipline_arrow-3.2.2-cp311-cp311-win_amd64.whl |
|---|---|
| Size | 4.8 MB |
| Tags | CPython 3.11 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
e05a97bc86c4d712e1c3f7f0bc78b667d75a75203b76b0f0ebeea0ef0c863003
|
|
BLAKE2b-256 checksum How to use checksums |
bea551f6100816984f277e4819ec8d2d4cc26ea6798023ee1d24f3acae1b8708
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Mar 30, 2025.
Transparency logRelease files / zipline_arrow-3.2.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | zipline_arrow-3.2.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 11.7 MB |
| Tags | CPython 3.11 Linux glibc 2.17+ x86-64 |
|
SHA-256 checksum How to use checksums |
e437d561ad2e3a05203f881ac937ea5b43b37a80ceb22b68f5777c1dfb8dd838
|
|
BLAKE2b-256 checksum How to use checksums |
d2e583fcb0e5921b9eedec1cfb6c1809cb9c1f0dc437f0632ba499e39f406390
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Mar 30, 2025.
Transparency logRelease files / zipline_arrow-3.2.2-cp311-cp311-macosx_11_0_x86_64.whl
| Download URL | zipline_arrow-3.2.2-cp311-cp311-macosx_11_0_x86_64.whl |
|---|---|
| Size | 4.9 MB |
| Tags | CPython 3.11 macOS 11.0+ x86-64 |
|
SHA-256 checksum How to use checksums |
ff83c705d2120b1587fec9368d4088d1ed9322ca2c7014987a563bd52d55faf9
|
|
BLAKE2b-256 checksum How to use checksums |
4bb4a2bb2d6fddd78cfd65040d5187b41cd08a91cd97cac5e39ce0fe76c16c6a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Mar 30, 2025.
Transparency logRelease files / zipline_arrow-3.2.2-cp311-cp311-macosx_11_0_arm64.whl
| Download URL | zipline_arrow-3.2.2-cp311-cp311-macosx_11_0_arm64.whl |
|---|---|
| Size | 4.8 MB |
| Tags | CPython 3.11 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
7e1732ba60c1ff8d135edbe87a4718c0ef7b94b43266da9e791f1cf009744a19
|
|
BLAKE2b-256 checksum How to use checksums |
ca6393cd6e9b040bd97dd0130c0acd81f6719325bbdf96aee62737963063be41
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Mar 30, 2025.
Transparency logRelease files / zipline_arrow-3.2.2-cp310-cp310-win_amd64.whl
| Download URL | zipline_arrow-3.2.2-cp310-cp310-win_amd64.whl |
|---|---|
| Size | 4.8 MB |
| Tags | CPython 3.10 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
6f21ae04e03808db5376ac67af08a9867310321b15f0f6cb92ca639ab050555f
|
|
BLAKE2b-256 checksum How to use checksums |
2419bda18a783d9a494a3e6631124135316fc8462f01ea858413f2a8bcc0154f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Mar 30, 2025.
Transparency logRelease files / zipline_arrow-3.2.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | zipline_arrow-3.2.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 11.0 MB |
| Tags | CPython 3.10 Linux glibc 2.17+ x86-64 |
|
SHA-256 checksum How to use checksums |
941dd0194027c0b12675130147a297413bef42d8a1ff5d144d098f9bc03cef5c
|
|
BLAKE2b-256 checksum How to use checksums |
ba4dbfecac88ed631ee803e50c7341e0db2f2005754b7b99b28e7e2d4d0a5d5f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Mar 30, 2025.
Transparency logRelease files / zipline_arrow-3.2.2-cp310-cp310-macosx_11_0_x86_64.whl
| Download URL | zipline_arrow-3.2.2-cp310-cp310-macosx_11_0_x86_64.whl |
|---|---|
| Size | 4.9 MB |
| Tags | CPython 3.10 macOS 11.0+ x86-64 |
|
SHA-256 checksum How to use checksums |
8158bba943c0893b24b26c9858c88e9401a3691d388fca5930daf96cb35e8619
|
|
BLAKE2b-256 checksum How to use checksums |
a475463e739a5afdbe94ab72a72778f8deef5ddf0847ffb64194013c540b723b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Mar 30, 2025.
Transparency logRelease files / zipline_arrow-3.2.2-cp310-cp310-macosx_11_0_arm64.whl
| Download URL | zipline_arrow-3.2.2-cp310-cp310-macosx_11_0_arm64.whl |
|---|---|
| Size | 4.8 MB |
| Tags | CPython 3.10 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
fee11755a607a21742cf724b0404592e6eed3fb37a721d2bcafa4e8256e87d25
|
|
BLAKE2b-256 checksum How to use checksums |
b038d9d18214a6d88f8152c56a79255c091e43cc8e02c580d89c29424e75489f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Mar 30, 2025.
Transparency log