Skip to main content

Backtest your Trading Strategies

Version Info Python Anaconda-Server Badge PyPI Anaconda-Server Badge
Test Status CI Tests PyPI codecov
Community Discourse ML4T Twitter

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.

Maintenance and new projects

We continue to maintain Zipline Reloaded for bug, security and compatibility fixes. Our new feature development focuses on ML4T Backtest within the current ML4T libraries. For new projects, we recommend evaluating Backtest through the migration guide, which includes a runnable strategy and explains differences in data preparation, callbacks and execution assumptions. See the Backtest documentation for its supported workflows.

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.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

The next release supports Python 3.11 through 3.14 and depends on NumFOCUS libraries including pandas. Package metadata constrains pandas to versions below 3.0. Python 3.14 requires pandas 2.3.3 and NumPy 2.3.3 or later; Python 3.15 is not yet supported. Python 3.14 support requires the development source until the next release is published.

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.

Metadata

Release files for zipline-reloaded 3.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for zipline-reloaded 3.2.0
File Size Uploaded Provenance
zipline_reloaded-3.2.0.tar.gz 12.4 MB Without provenance Details

Built distributions (wheels)

Table of built distributions (wheels) for zipline-reloaded 3.2.0
File
zipline_reloaded-3.2.0-cp314-cp314-win_amd64.whl CPython 3.14 CPython 3.14 Windows x86-64 Details
zipline_reloaded-3.2.0-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl CPython 3.14 CPython 3.14 Linux glibc 2.28+ x86-64, Linux glibc 2.17+ x86-64 Details
zipline_reloaded-3.2.0-cp314-cp314-macosx_11_0_arm64.whl CPython 3.14 CPython 3.14 macOS 11.0+ ARM64 Details
zipline_reloaded-3.2.0-cp314-cp314-macosx_10_15_x86_64.whl CPython 3.14 CPython 3.14 macOS 10.15+ x86-64 Details
zipline_reloaded-3.2.0-cp313-cp313-win_amd64.whl CPython 3.13 CPython 3.13 Windows x86-64 Details
zipline_reloaded-3.2.0-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl CPython 3.13 CPython 3.13 Linux glibc 2.28+ x86-64, Linux glibc 2.17+ x86-64 Details
zipline_reloaded-3.2.0-cp313-cp313-macosx_11_0_arm64.whl CPython 3.13 CPython 3.13 macOS 11.0+ ARM64 Details
zipline_reloaded-3.2.0-cp313-cp313-macosx_10_15_x86_64.whl CPython 3.13 CPython 3.13 macOS 10.15+ x86-64 Details
zipline_reloaded-3.2.0-cp312-cp312-win_amd64.whl CPython 3.12 CPython 3.12 Windows x86-64 Details
zipline_reloaded-3.2.0-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl CPython 3.12 CPython 3.12 Linux glibc 2.28+ x86-64, Linux glibc 2.17+ x86-64 Details
zipline_reloaded-3.2.0-cp312-cp312-macosx_11_0_arm64.whl CPython 3.12 CPython 3.12 macOS 11.0+ ARM64 Details
zipline_reloaded-3.2.0-cp312-cp312-macosx_10_15_x86_64.whl CPython 3.12 CPython 3.12 macOS 10.15+ x86-64 Details
zipline_reloaded-3.2.0-cp311-cp311-win_amd64.whl CPython 3.11 CPython 3.11 Windows x86-64 Details
zipline_reloaded-3.2.0-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl CPython 3.11 CPython 3.11 Linux glibc 2.17+ x86-64, Linux glibc 2.28+ x86-64 Details
zipline_reloaded-3.2.0-cp311-cp311-macosx_11_0_arm64.whl CPython 3.11 CPython 3.11 macOS 11.0+ ARM64 Details
zipline_reloaded-3.2.0-cp311-cp311-macosx_10_15_x86_64.whl CPython 3.11 CPython 3.11 macOS 10.15+ x86-64 Details

Total release size: 124.0 MB

Release files / zipline_reloaded-3.2.0.tar.gz

Download URL zipline_reloaded-3.2.0.tar.gz
Size 12.4 MB
Tags Source
SHA-256 checksum
How to use checksums
4cd185a4549975d3f03ae61cc693bd21eb91868851fcaaf4dd1381386ba0b1f1
BLAKE2b-256 checksum
How to use checksums
e61e72c9949c98af4f0e5ce099ef5d04e7800808cd527383a9fab409abc61a94
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / zipline_reloaded-3.2.0-cp314-cp314-win_amd64.whl

Download URL zipline_reloaded-3.2.0-cp314-cp314-win_amd64.whl
Size 5.0 MB
Tags CPython 3.14 Windows x86-64
SHA-256 checksum
How to use checksums
4d815c46f2ba775047367c580deb96d9e0a8cb07b60e03f8e57dec493cf71f7a
BLAKE2b-256 checksum
How to use checksums
49b079ea1e5e9ee756383110febf658e902c24bf6e6adc6649c6a3e51239b89e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / zipline_reloaded-3.2.0-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl

Download URL zipline_reloaded-3.2.0-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Size 12.5 MB
Tags CPython 3.14 Linux glibc 2.17+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
4de7d9dbec0da9a021f9549add928ef28f6cba93d0d7d652e903c3b72a29e76a
BLAKE2b-256 checksum
How to use checksums
92face7bfafbf9303ae25afe18bae3a906db59c684dca5f4aa28945abb8441db
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / zipline_reloaded-3.2.0-cp314-cp314-macosx_11_0_arm64.whl

Download URL zipline_reloaded-3.2.0-cp314-cp314-macosx_11_0_arm64.whl
Size 5.2 MB
Tags CPython 3.14 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
76d92f73b96aa2f9741ef402568f3b9fe0f2fbf27561eb239979d847996cb581
BLAKE2b-256 checksum
How to use checksums
99b5a9db621ddbda0b2f966dcbc3d4f993971c1bb9289a15424f00834ac9d6d4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / zipline_reloaded-3.2.0-cp314-cp314-macosx_10_15_x86_64.whl

Download URL zipline_reloaded-3.2.0-cp314-cp314-macosx_10_15_x86_64.whl
Size 5.2 MB
Tags CPython 3.14 macOS 10.15+ x86-64
SHA-256 checksum
How to use checksums
157e1d1c7b292e8c2b6a0e7ee81c3f707eae3148131f4daaa049755e40e5eeab
BLAKE2b-256 checksum
How to use checksums
311fe25e1fb9b38149b67ca47c9c6dbceb8ac60dd951f0476526180a694c0c77
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / zipline_reloaded-3.2.0-cp313-cp313-win_amd64.whl

Download URL zipline_reloaded-3.2.0-cp313-cp313-win_amd64.whl
Size 5.0 MB
Tags CPython 3.13 Windows x86-64
SHA-256 checksum
How to use checksums
6d33524ec8eb95226d7ecadfce16a6c5641fef633e8e8ab22fd8339057f252a7
BLAKE2b-256 checksum
How to use checksums
6ef80dba629333ff3a4e4f5866fe63aed12aa6985a71cfed1209ad3ffba2165a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / zipline_reloaded-3.2.0-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl

Download URL zipline_reloaded-3.2.0-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Size 12.5 MB
Tags CPython 3.13 Linux glibc 2.17+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
b336776d272f8c1599cf73560980a2746dc5437154d916c6cd13b66fe2fc97c0
BLAKE2b-256 checksum
How to use checksums
b8faad588cd2f9effd08c4f35270b8e63d1bc9df6ca156435b42864d00fb9b15
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / zipline_reloaded-3.2.0-cp313-cp313-macosx_11_0_arm64.whl

Download URL zipline_reloaded-3.2.0-cp313-cp313-macosx_11_0_arm64.whl
Size 5.2 MB
Tags CPython 3.13 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
d0d465d26e710d6148d1239c9914b4f1eb0c225adcbff38371acdc4bd221f05e
BLAKE2b-256 checksum
How to use checksums
e92a50b8dea17590553e8219b0aea4cc1611c1a8e839d8aa0b379234502b1b7a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / zipline_reloaded-3.2.0-cp313-cp313-macosx_10_15_x86_64.whl

Download URL zipline_reloaded-3.2.0-cp313-cp313-macosx_10_15_x86_64.whl
Size 5.2 MB
Tags CPython 3.13 macOS 10.15+ x86-64
SHA-256 checksum
How to use checksums
a2799c94d1b4eab28a851ce4d681eb2d119437c0d2d24c4556f2f30c500ab989
BLAKE2b-256 checksum
How to use checksums
d4378b49af10f25795c47f0cfb6e81cc62e9768f5ed98dabe66221ce5afeb286
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / zipline_reloaded-3.2.0-cp312-cp312-win_amd64.whl

Download URL zipline_reloaded-3.2.0-cp312-cp312-win_amd64.whl
Size 5.0 MB
Tags CPython 3.12 Windows x86-64
SHA-256 checksum
How to use checksums
873e177b6da25554946af887905f7fb619a3e77ad2513f873745b554bb932c38
BLAKE2b-256 checksum
How to use checksums
9aeea903012a2e6a1f57a02bc52c92a6a60d94b772a4939307ec49c3424fb46f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / zipline_reloaded-3.2.0-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl

Download URL zipline_reloaded-3.2.0-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Size 12.5 MB
Tags CPython 3.12 Linux glibc 2.17+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
1d7a3c4f547c02e9a3c3cc1f8ea2394641124c1fdb35ef27cdf30fa488d3899b
BLAKE2b-256 checksum
How to use checksums
2c23b297526927f562830b7b5bf734837a572291e0b77193950a03df4c97813e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / zipline_reloaded-3.2.0-cp312-cp312-macosx_11_0_arm64.whl

Download URL zipline_reloaded-3.2.0-cp312-cp312-macosx_11_0_arm64.whl
Size 5.2 MB
Tags CPython 3.12 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
223d0606202253d34a1d571bf3f5c4ed2a6e7e569b0bc053d2367a650a63e893
BLAKE2b-256 checksum
How to use checksums
a6ffe6d1270e055ec0eb3df3960dc00917d475c3fa7fff9fbaa7a241cd6325b9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / zipline_reloaded-3.2.0-cp312-cp312-macosx_10_15_x86_64.whl

Download URL zipline_reloaded-3.2.0-cp312-cp312-macosx_10_15_x86_64.whl
Size 5.2 MB
Tags CPython 3.12 macOS 10.15+ x86-64
SHA-256 checksum
How to use checksums
07b0150ff3b80347f6f11cc25d46ffd36f6eb168f91ec205c3516c5e50ea11cc
BLAKE2b-256 checksum
How to use checksums
1b05510c5b61058310e4872a493bd1cd2d62b07e428a4957055c41b59a0ab993
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / zipline_reloaded-3.2.0-cp311-cp311-win_amd64.whl

Download URL zipline_reloaded-3.2.0-cp311-cp311-win_amd64.whl
Size 5.0 MB
Tags CPython 3.11 Windows x86-64
SHA-256 checksum
How to use checksums
798ac21cf04418cf18c3595f9bce8426bbbb5216a43c79cf642d11c0a8d8ce69
BLAKE2b-256 checksum
How to use checksums
83a2f26990179866c447ee883338d46206786a0539b2b61dacafa0f8b1d54e9f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / zipline_reloaded-3.2.0-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl

Download URL zipline_reloaded-3.2.0-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Size 12.3 MB
Tags CPython 3.11 Linux glibc 2.17+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
4272c54eeba4eea06ce041b932c95aeaef1887965ae2a406b0bca99283cb99e1
BLAKE2b-256 checksum
How to use checksums
5939ff04b502abd0cebf0c3cb642aa389e817990772b16cf37201eab82b46883
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / zipline_reloaded-3.2.0-cp311-cp311-macosx_11_0_arm64.whl

Download URL zipline_reloaded-3.2.0-cp311-cp311-macosx_11_0_arm64.whl
Size 5.2 MB
Tags CPython 3.11 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
4957890601d3be02f034440af3ca6be91f39e16005ea0ba0a8e1763309eb5b0b
BLAKE2b-256 checksum
How to use checksums
60de920cff7f423385dcbff71f52659f5970106f00e1d260b08cec36c6177b16
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / zipline_reloaded-3.2.0-cp311-cp311-macosx_10_15_x86_64.whl

Download URL zipline_reloaded-3.2.0-cp311-cp311-macosx_10_15_x86_64.whl
Size 5.2 MB
Tags CPython 3.11 macOS 10.15+ x86-64
SHA-256 checksum
How to use checksums
c7f5cce50ed4ec2df174d2676dd81340cd1bc654a60cd216a45108ac51ea2264
BLAKE2b-256 checksum
How to use checksums
654bcf83b57118fbdcaf25ce52e593190c3eb9362d233b89334df8a5eb961184
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Security for zipline-reloaded 3.2.0

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Release history Release notifications | RSS feed

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page