Welcome, guest | Sign In | My Account | Store | Cart

Notice! PyPM is being replaced with the ActiveState Platform, which enhances PyPM’s build and deploy capabilities. Create your free Platform account to download ActivePython or customize Python with the packages you require and get automatic updates.

Download
ActivePython
INSTALL>
pypm install zipline

How to install zipline

  1. Download and install ActivePython
  2. Open Command Prompt
  3. Type pypm install zipline
 Python 2.7Python 3.2Python 3.3
Windows (32-bit)
Windows (64-bit)
Mac OS X (10.5+)
Linux (32-bit)
0.5.6
0.5.10Never BuiltWhy not?
0.5.6 Available View build log
0.5.5 Failed View build log
0.5.3 Available View build log
0.5.2 Available View build log
0.5.1 Available View build log
0.5.0 Available View build log
Linux (64-bit)
0.5.10 Available View build log
0.5.6 Available View build log
0.5.5 Failed View build log
0.5.3 Available View build log
0.5.2 Available View build log
0.5.1 Available View build log
0.5.0 Available View build log
 
License
Apache 2.0
Lastest release
version 0.5.10 on Jan 9th, 2014

Zipline

Zipline is a Pythonic algorithmic trading library. The system is fundamentally event-driven and a close approximation of how live-trading systems operate. Currently, backtesting is well supported, but the intent is to develop the library for both paper and live trading, so that the same logic used for backtesting can be applied to the market.

Zipline is currently used in production as the backtesting engine powering Quantopian (https://www.quantopian.com) -- a free, community-centered platform that allows development and real-time backtesting of trading algorithms in the web browser.

Want to contribute? See our open requests and our general guidelines below.

Discussion and Help

Discussion of the project is held at the Google Group, zipline@googlegroups.com, .

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.
  • Zipline comes "batteries included" as many common statistics like moving average and linear regression can be readily accessed from within a user-written algorithm.
  • Input of historical data and output of performance statistics is based on Pandas DataFrames to integrate nicely into the existing Python eco-system.
  • Statistic and machine learning libraries like matplotlib, scipy, statsmodels, and sklearn support development, analysis and visualization of state-of-the-art trading systems.

Installation

Since zipline is pure-python code it should be very easy to install and set up with pip:

pip install numpy   # Pre-install numpy to handle dependency chain quirk
pip install zipline

If there are problems installing the dependencies or zipline we recommend installing these packages via some other means. For Windows, the Enthought Python Distribution includes most of the necessary dependencies. On OSX, the Scipy Superpack works very well.

Dependencies
  • Python (>= 2.7.2)
  • numpy (>= 1.6.0)
  • pandas (>= 0.9.0)
  • pytz
  • msgpack-python
  • Logbook
  • blist
  • requests
  • delorean
  • iso8601

Quickstart

The following code implements a simple dual moving average algorithm and tests it on data extracted from yahoo finance.

System Message: ERROR/3 (<string>, line 84)

Unknown directive type "code".

.. code:: python

    from zipline.algorithm import TradingAlgorithm
    from zipline.transforms import MovingAverage
    from zipline.utils.factory import load_from_yahoo

    class DualMovingAverage(TradingAlgorithm):
        """Dual Moving Average algorithm.
        """
        def initialize(self, short_window=200, long_window=400):
            # Add 2 mavg transforms, one with a long window, one
            # with a short window.
            self.add_transform(MovingAverage, 'short_mavg', ['price'],
                               market_aware=True,
                               window_length=short_window)

            self.add_transform(MovingAverage, 'long_mavg', ['price'],
                               market_aware=True,
                               window_length=long_window)

            # To keep track of whether we invested in the stock or not
            self.invested = False

            self.short_mavg = []
            self.long_mavg = []


        def handle_data(self, data):
            if (data['AAPL'].short_mavg['price'] > data['AAPL'].long_mavg['price']) and not self.invested:
                self.order('AAPL', 100)
                self.invested = True
            elif (data['AAPL'].short_mavg['price'] < data['AAPL'].long_mavg['price']) and self.invested:
                self.order('AAPL', -100)
                self.invested = False

            # Save mavgs for later analysis.
            self.short_mavg.append(data['AAPL'].short_mavg['price'])
            self.long_mavg.append(data['AAPL'].long_mavg['price'])

    data = load_from_yahoo()
    dma = DualMovingAverage()
    results = dma.run(data)

You can find other examples in the zipline/examples directory.

Contributions

If you would like to contribute, please see our Contribution Requests: https://github.com/quantopian/zipline/wiki/Contribution-Requests

Credits

Thank you for all the help so far!

  • @rday for sortino ratio, information ratio, and exponential moving average transform
  • @snth
  • @yinhm for integrating zipline with @yinhm/datafeed
  • Jeremiah Lowin for teaching us the nuances of Sharpe and Sortino Ratios
  • Brian Cappello
  • @verdverm (Tony Worm), Order types (stop, limit)
  • @benmccann for benchmarking contributions
  • Quantopian Team

(alert us if we've inadvertantly missed listing you here!)

Development Environment

The following guide assumes your system has virtualenvwrapper and pip already installed.

You'll need to install some C library dependencies:

sudo apt-get install libopenblas-dev liblapack-dev gfortran

wget http://prdownloads.sourceforge.net/ta-lib/ta-lib-0.4.0-src.tar.gz
tar -xvzf ta-lib-0.4.0-src.tar.gz
cd ta-lib/
./configure --prefix=/usr
make
sudo make install

Suggested installation of Python library dependencies used for development:

mkvirtualenv zipline
./etc/ordered_pip.sh ./etc/requirements.txt
pip install -r ./etc/requirements_dev.txt
Style Guide

To ensure that changes and patches are focused on behavior changes, the zipline codebase adheres to both PEP-8, http://www.python.org/dev/peps/pep-0008/, and pyflakes, https://launchpad.net/pyflakes/.

The maintainers check the code using the flake8 script, https://github.com/bmcustodio/flake8, which is included in the requirements_dev.txt.

Before submitting patches or pull requests, please ensure that your changes pass flake8 zipline tests and nosetests

Source

The source for Zipline is hosted at https://github.com/quantopian/zipline.

Documentation

You can compile the documentation using Sphinx:

sudo apt-get install python-sphinx
make html

Build Status

Build Status

Contact

For other questions, please contact opensource@quantopian.com.

Subscribe to package updates

Last updated Jan 9th, 2014

Download Stats

Last month:1

What does the lock icon mean?

Builds marked with a lock icon are only available via PyPM to users with a current ActivePython Business Edition subscription.

Need custom builds or support?

ActivePython Enterprise Edition guarantees priority access to technical support, indemnification, expert consulting and quality-assured language builds.

Plan on re-distributing ActivePython?

Get re-distribution rights and eliminate legal risks with ActivePython OEM Edition.