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

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.1
File Size Uploaded Provenance Actions
zipline_reloaded-3.2.1.tar.gz 12.4 MB Without provenance Details for zipline_reloaded-3.2.1.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for zipline-reloaded 3.2.1
File Actions
zipline_reloaded-3.2.1-cp314-cp314-win_amd64.whl CPython 3.14 CPython 3.14 Windows x86-64 Details for zipline_reloaded-3.2.1-cp314-cp314-win_amd64.whl
zipline_reloaded-3.2.1-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 for zipline_reloaded-3.2.1-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
zipline_reloaded-3.2.1-cp314-cp314-macosx_11_0_arm64.whl CPython 3.14 CPython 3.14 macOS 11.0+ ARM64 Details for zipline_reloaded-3.2.1-cp314-cp314-macosx_11_0_arm64.whl
zipline_reloaded-3.2.1-cp314-cp314-macosx_10_15_x86_64.whl CPython 3.14 CPython 3.14 macOS 10.15+ x86-64 Details for zipline_reloaded-3.2.1-cp314-cp314-macosx_10_15_x86_64.whl
zipline_reloaded-3.2.1-cp313-cp313-win_amd64.whl CPython 3.13 CPython 3.13 Windows x86-64 Details for zipline_reloaded-3.2.1-cp313-cp313-win_amd64.whl
zipline_reloaded-3.2.1-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.17+ x86-64, Linux glibc 2.28+ x86-64 Details for zipline_reloaded-3.2.1-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
zipline_reloaded-3.2.1-cp313-cp313-macosx_11_0_arm64.whl CPython 3.13 CPython 3.13 macOS 11.0+ ARM64 Details for zipline_reloaded-3.2.1-cp313-cp313-macosx_11_0_arm64.whl
zipline_reloaded-3.2.1-cp313-cp313-macosx_10_15_x86_64.whl CPython 3.13 CPython 3.13 macOS 10.15+ x86-64 Details for zipline_reloaded-3.2.1-cp313-cp313-macosx_10_15_x86_64.whl
zipline_reloaded-3.2.1-cp312-cp312-win_amd64.whl CPython 3.12 CPython 3.12 Windows x86-64 Details for zipline_reloaded-3.2.1-cp312-cp312-win_amd64.whl
zipline_reloaded-3.2.1-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.17+ x86-64, Linux glibc 2.28+ x86-64 Details for zipline_reloaded-3.2.1-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
zipline_reloaded-3.2.1-cp312-cp312-macosx_11_0_arm64.whl CPython 3.12 CPython 3.12 macOS 11.0+ ARM64 Details for zipline_reloaded-3.2.1-cp312-cp312-macosx_11_0_arm64.whl
zipline_reloaded-3.2.1-cp312-cp312-macosx_10_15_x86_64.whl CPython 3.12 CPython 3.12 macOS 10.15+ x86-64 Details for zipline_reloaded-3.2.1-cp312-cp312-macosx_10_15_x86_64.whl
zipline_reloaded-3.2.1-cp311-cp311-win_amd64.whl CPython 3.11 CPython 3.11 Windows x86-64 Details for zipline_reloaded-3.2.1-cp311-cp311-win_amd64.whl
zipline_reloaded-3.2.1-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.28+ x86-64, Linux glibc 2.17+ x86-64 Details for zipline_reloaded-3.2.1-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
zipline_reloaded-3.2.1-cp311-cp311-macosx_11_0_arm64.whl CPython 3.11 CPython 3.11 macOS 11.0+ ARM64 Details for zipline_reloaded-3.2.1-cp311-cp311-macosx_11_0_arm64.whl
zipline_reloaded-3.2.1-cp311-cp311-macosx_10_15_x86_64.whl CPython 3.11 CPython 3.11 macOS 10.15+ x86-64 Details for zipline_reloaded-3.2.1-cp311-cp311-macosx_10_15_x86_64.whl

Total release size: 124.0 MB

Release files / zipline_reloaded-3.2.1.tar.gz

Download URL zipline_reloaded-3.2.1.tar.gz
Size 12.4 MB
Tags Source
SHA-256 checksum
How to use checksums
f8e630985da613dff74800fda693bb926fe72b286c3e53fc747049f4a29fcd2a
BLAKE2b-256 checksum
How to use checksums
9958044fafa4b2191b106fbd75e6be2a9c041013518935ffa94b6305983a51d5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

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

Download URL zipline_reloaded-3.2.1-cp314-cp314-win_amd64.whl
Size 5.0 MB
Tags CPython 3.14 Windows x86-64
SHA-256 checksum
How to use checksums
462812d5ed13258e24fcf1894d5533149062213c9e5a2537a98d12d5c722136d
BLAKE2b-256 checksum
How to use checksums
27983d8c3c29557890783ea472a00394df590e6738b064b3e174dae30c9674be
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

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

Download URL zipline_reloaded-3.2.1-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
dbe59a09b59f9ea82032b52e6c26ef9475e9f11623fa2e28e684750fb5acad71
BLAKE2b-256 checksum
How to use checksums
e87654d9a92a162dcbaaf38b17f378d6512aa3f14e7618e4cc0f395a478782ad
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

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

Download URL zipline_reloaded-3.2.1-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
77e3976b41d45c9baa8fd998bea524b831d9057ea0953bd2aaa208751c6e8f47
BLAKE2b-256 checksum
How to use checksums
e0b84ad48d2575a5cbe1817ac19adb56086ab17d5bc54b30358537c64ac259ae
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

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

Download URL zipline_reloaded-3.2.1-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
e6d16443cf6ab7bf91c1e6941c898b21b892e032f10313a5edef12b0e4ce36ed
BLAKE2b-256 checksum
How to use checksums
0049c12da089b1d03e70ed9110f1f685657af05f4f24e1e470ebc965ce5ddcc6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

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

Download URL zipline_reloaded-3.2.1-cp313-cp313-win_amd64.whl
Size 5.0 MB
Tags CPython 3.13 Windows x86-64
SHA-256 checksum
How to use checksums
6075c378227172217b8e47ec37bc9023d2d169a97d3018c857aaac6cddcf1172
BLAKE2b-256 checksum
How to use checksums
82eef6f4b26cb784bd37ffd268d3e8cf82635d7db5b40fea703e19f120b84c80
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

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

Download URL zipline_reloaded-3.2.1-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
deddadf7d12cbd8be350d5f4013294526e09374ca4ed88b279d23aac4b87a3e0
BLAKE2b-256 checksum
How to use checksums
6a12f819f3158c29d03c922142019c513e1e0d8e51fff18b1fb601a1d8759d26
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

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

Download URL zipline_reloaded-3.2.1-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
1c74b3e46a7af799bc35fabdcb4c4baadb2114f7c3efbdf745d38654ae489de7
BLAKE2b-256 checksum
How to use checksums
0e677eff86e5c0e1f4f260e04600dce81be3d8e6452c6dd942fe40187cdf1fe5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

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

Download URL zipline_reloaded-3.2.1-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
69f47882e8bf936ede5f37dd5c1cd6c21479966eb84a8c5a1f8b854689a3f0ec
BLAKE2b-256 checksum
How to use checksums
87710e673526d4d3225ca4fd094126dd0b0fbb3f93f69468fa72025c44fcf9d5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

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

Download URL zipline_reloaded-3.2.1-cp312-cp312-win_amd64.whl
Size 5.0 MB
Tags CPython 3.12 Windows x86-64
SHA-256 checksum
How to use checksums
f9f4d10887b681da0318d73f87cb5f36209460835bf33d87afe011bada1543b8
BLAKE2b-256 checksum
How to use checksums
39abc2efa68556d387b82727fe57d89bbbab90dddb82cb262d05d5ff8107f866
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

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

Download URL zipline_reloaded-3.2.1-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
b998262502312de961eacd00453ab6a13cff5a1e1ccf047e6204c14856eda4fb
BLAKE2b-256 checksum
How to use checksums
8612947fdf21cdf234136cd460a2aaab7765320ca5b5972bb94b699eeef3f9d9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

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

Download URL zipline_reloaded-3.2.1-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
05b739e97b990677bf2c9854d90a707d7b50c388ae1ca272343df4a1cc35d84b
BLAKE2b-256 checksum
How to use checksums
89a5e8eb6b3f684ddd6278537e4f684fcd1682b4679d92d857307a92c3843903
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

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

Download URL zipline_reloaded-3.2.1-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
86186b0ac76303055fedd6ab05c13096a0f65729b3e8f45c27f540b6e32574df
BLAKE2b-256 checksum
How to use checksums
cfbc7dff7acc90f92b5d80d192d1fbfb2b2de9ac6e9dcc5d887a987b8ad6b974
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

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

Download URL zipline_reloaded-3.2.1-cp311-cp311-win_amd64.whl
Size 5.0 MB
Tags CPython 3.11 Windows x86-64
SHA-256 checksum
How to use checksums
74d2756b3ab97cd4130f4dc518030419a3979c84d128f99d26cb8d5fa78a9b08
BLAKE2b-256 checksum
How to use checksums
ef2965a002a95c13cb63202d98dc8602b4d7c2f742a3ed67aede80248158f98e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

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

Download URL zipline_reloaded-3.2.1-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
6a41044a659379058ef7d059f4b44a7d405918f3267ef8577f23c831c8b62386
BLAKE2b-256 checksum
How to use checksums
a45eddbe59b54ef4b6bb7447631001d398b10497358944102be5de829368d6fa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

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

Download URL zipline_reloaded-3.2.1-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
09b205fe1b1a1cec2bdc0d764773ff140a2dd9b2f652c76bc1262f4786e7e69c
BLAKE2b-256 checksum
How to use checksums
9504223eed7e43f9a1c2ecae06244d26e1d276e6a1d8270806a1b82a50bc057b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

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

Download URL zipline_reloaded-3.2.1-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
36c3945db08586e81e787c96a07213eb7cd6b3d3d53ca8b582745dab75b8f48d
BLAKE2b-256 checksum
How to use checksums
fcb6e9d41031c5109f21d17620a2f7e8c2707885b9dc5fee513b2b55d9ce3c9c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Security for zipline-reloaded 3.2.1

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.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

3.2.1 This release

17 release files No provenance

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