gitmyhub

zipline

Python ★ 20k updated 2y ago

Zipline, a Pythonic Algorithmic Trading Library

A Python library for testing trading algorithms against historical market data, so you can see how a strategy would have performed in the past before risking real money.

PythonPandasScipyMatplotlibsetup: moderatecomplexity 3/5

Zipline is a Python library for backtesting algorithmic trading strategies. Backtesting means running a trading algorithm against historical market data to see how it would have performed in the past, before risking real money. Rather than requiring you to manually loop over historical price data, Zipline provides an event-driven framework where you write two functions — one to set up your strategy at the start, and one that gets called once per trading day with fresh market data — and Zipline handles the simulation mechanics for you.

The code example in the README shows a dual moving average strategy: each day the algorithm computes a short-term average of Apple's stock price over 100 days and a long-term average over 300 days. When the short average crosses above the long average (a classic signal that momentum is accelerating), it buys shares; when it crosses below, it sells. Running the simulation from the command line generates a performance report stored as a Pandas DataFrame, which can then be analyzed with standard Python data science tools like matplotlib or scipy.

Common statistics like moving averages and linear regression are built in, and the library integrates directly with the pandas and scientific Python ecosystem. It was originally created by Quantopian, a platform for building and running trading strategies, and was used as the engine powering that platform.

A quantitative analyst, finance student, or developer building automated trading systems would use Zipline to validate a strategy idea against real historical data before deploying it. It is written in Python and installable via pip or conda.

Where it fits