Skip to content
All library documents

Python Libraries for Algorithmic Trading and Backtesting

Article Quant Q&A · Author: Terry

Summary

The document surveys Python tools for strategy research, backtesting, portfolio analysis, and live trading. It describes backtrader in the most detail: it supports event-style and vectorized runs, multiple assets and strategies, varied data sources and timeframes, broker and commission models, slippage, analyzers, optimization, and plotting. Other named packages are presented more briefly, with capabilities such as distributed testing, technical indicators, portfolio construction, statistical measures, or broker connectivity.

The evidence is a collection of community answers and feature descriptions, not a comparative benchmark or controlled evaluation. The answers note that frameworks differ in maturity, data sources, interfaces, and intended use, and that the ecosystem changes over time. Several recommendations come from package authors, and the original question's update mentions Zipline forks after Quantopian closed. The material is therefore useful as a historical map of options and design tradeoffs, but readers should verify current maintenance, compatibility, and live-trading support before choosing a framework.

Key ideas

  • Python trading frameworks vary in purpose, maturity, data access, and support for live execution.
  • Backtrader is described as supporting event-style and vectorized backtests, multiple assets, broker models, analyzers, optimization, and plotting.
  • Some tools emphasize portfolio analytics, distributed strategy tests, technical indicators, or broker connectivity.
  • The answers offer feature claims and personal recommendations rather than systematic performance comparisons.
  • Framework status and compatibility can change, so current support should be checked before adoption.

Tags

Full text
# Except Zipline, are there any other Pythonic algorithmic trading library I can choose?


# Except Zipline, are there any other Pythonic algorithmic trading library I can choose?












Except Zipline, are there any other Pythonic algorithmic trading library I can choose? Especially, for backtesting?

Update: Since Quantopian closed, there are some Zipline forks like:

https://pypi.org/project/zipline-reloaded/

https://www.quantrocket.com/zipline/

https://zipline-trader.readthedocs.io/en/latest/index.html#

## Answer by J. Morris (score 30, accepted)

https://quant.stackexchange.com/a/8899

Aside from Zipline, there are a number of algorithmic trading libraries in various stages of development for Python.

From the commercial side, RapidQuant looks very interesting though I haven't tried it yet. It's from some of same developers that brought us the excellent Pandas data analysis library. I think Wes McKinney (Pandas's main author) is involved.

From the open source side, you might check out ultra-finance. It aims to be a fully featured event-driven based backtesting system.

Also check out PyaAlgoTrade. It's coded to allow for distributed testing of strategies on Google's cloud infrastructure. It incorporates the open source TA-Lib technical analysis library.

Finally, take a look at TradeProgrammer. It also uses the TA-Lib library. The package is free to use for backtesting, but its live trading version is commercial.

Aside from that, I think that many proprietary traders build their own systems. There is definitely something to be said for using a tool you understand on that level.

## Answer by mementum (score 18)

https://quant.stackexchange.com/a/20748

Edit (2016-06-21): Now with live data/trading integration with Interactive Brokers. It has taken a while but it has finally arrived.

Edit (2017-09-20): live data/trading includes Visual Chart and Oanda (legacy accounts), order types, timers and market calendars, update with Python 3.6 and the community and other links updated

A (now) very mature (imho) Python backtesting framework is "backtrader":











Some features:

- Can run in (pseudo)event-mode (called 'next') or (pseudo)vectorized mode (called 'runonce') In "next" mode it can also be configured to work in "exactbars" mode which will keep memory consumption to the minimum (disabling plotting along the way)

- Order/Trade notification to strategies (this obviously is always an event)

- Supports CSV (some specific sources and a Generic CSV loader) binary sources (VisualChart, Pandas, Blaze) and online (Yahoo Finance Data - beware of the changes/quirks/problems introduced by Yahoo in 2017)

- Data Resampling and Data Replaying

- Mix datas of different timeframes (including a data and its "resampled" counterpart)

- Multi-Asset capable

- Multi-Strategy capable

- A fine (imho) broker implementation supporting stocks-like and futures-like (with margin) instruments with user implementable commission schemes if needed, including slippage. The nicest part is cash adjustment for future-like instruments on each bar



- Sizers for automated staking

- cheat-on-close and cheat-on-open modes to work with already past prices or prices to come, when not having access to lower resolution data

- Has a comprehensive list of implemented indicators

- Integration with TA-lib

- A few analyzers (AnnualReturn, Sharpe, TradeAnalyzer)

- Can optimize strategies and use multiple cores for the task

- Plotting support via Matplotlib (>= 1.4.1) with a high degree of configurability and flexibility (plots look nice)

- A text writer for console output of data points (csv) and datas/strategies/indicators/analyzers summaries

- Supports market calendars

- Timers even during backtesting

- Heavy use of metaclasses and operator overloading in order to implement ease of use and a declarative expression approach for the strategy/indicator logic and implementation

- Works with Python 2.7 / 3.2 / 3.3 / 3.4 / 3.5 / 3.6

Disclosure: I am the author having worked during 2015 on this as a hobby project but aiming at making it as feature complete and professional as possible

It is of course left to the reader to decide if the aforementioned statements and goals have been reached

As mentioned by edouard each framework has its own quirks and I actually started this after toying around with pyAlgoTrade and not really liking the API, which is of course a matter of personal taste.

## Answer by wlbsr (score 8)

https://quant.stackexchange.com/a/15951

possible update:

http://pmorissette.github.io/bt/

based on

http://pmorissette.github.io/ffn/

both were easily installed and somewhat usable for a novice. would love some examples other that github documentatiion

## Answer by benjaminmgross (score 6)

https://quant.stackexchange.com/a/16794

There is a module called visualize-wealth that provides:

- Documentation auto-generation capability with sphinx

- Portfolio construction methodologies in 3 ways (trade blotter, weight allocation frame, and static allocation series)

- All basic statistical measures, including many sophisticated ones such as CVaR, Mean Absolute Tracking Error, Cornish Fisher Approximation (to incorporate skew and kurtosis), correlation structure preserving algorithms, Appraisal & Information Ratios, and M^2 (to name a few) NOTE: The sphinx documentation renders into MathJax equations with clickable links and papers around more academic concepts

- Excel file with manual calculation to most of the analytical calcs, allowing the user to dig into the manual calculations if they should like (the results of this file are actually used as the data to test the module calcs)

- Utilities to work with Yahoo!'s API as well as HDFStores, to construct portfolios from

- Classification algorithms to determine the "likely asset class" of a time series, to enable asset selection and tactical allocation attribution functionality.

FULL DISCLOSURE: I am the developer of the `visualize-wealth` module and have been building it entirely on my own for the past 14 months.

## Answer by IBridgePy IBridgePy (score 6)

https://quant.stackexchange.com/a/34491

Interactive Brokers hosted a webinar on Nov. 10 2016 about Implement Algo Trading coded in Python using Interactive Brokers API. The presenter gave a good explanation on the applicability of IBridgePy, which is a Python package used to connect to Interactive Brokers C++ API for execution of python codes in live markets.

The webinar was recorded so that you can listen to it anytime you want. The link of the webinar is here: https://www.interactivebrokers.com/en/index.php?f=2227 In the page, IB categorizes their webinars in several topics: TWS, Trading, API, etc. After you click the tab of "API", you will see all of the webinars about API. IBridgePy works like a standalone quantopian and it is much easier than IBpy. IBridgePy can be found here www.IBridgePy.com

One of the greatest things about IBridgePy is that IBridgePy can run Quantopian's codes without any changes! http://www.ibridgepy.com/tutorials/#Migrating_from_Quantopian_to_IBridgePy Disclosure: I am the author of IBridgePy.

## Answer by tagoma (score 4)

https://quant.stackexchange.com/a/14343

I have also been searching for algo trading in Python.

According to my findings:

- there are many such librairies available, open-source or proprietary,

- they are all built quite specifically. as a result, when you know how to use one, it is the only one you are able to use.

- their stage of development is quite heterogeneous and future uncertain, eg what did happen to rapidquant.com cite above?

- no such library is well off and outperforming all other competing librairies.

With all the above, I would rather build my own tools as suggested above by someone else.

## Answer by ThereGoesMyMoney (score 4)

https://quant.stackexchange.com/a/35698

There are quite a few Quantopian alternative. The most popular are QuantConnect and Quantiacs. Both QuantConnect and Quantiacs offer a server ran platform to implement your algorithm.

However they both also have their tools on Github.

QuantConnect GitHub is a open-source C#, F# and Python algorithmic trading platform. QuantConnect data source is QuantQuote compared to Quantopian's data source which is Quandl.

Quantiacs GitHub offers their open-source toolkit in Python and Matlab. Quantiacs uses their own data source.

Data is important to backtesting. Hopefully these two will give you some alternative to implementation and data source.

## Answer by maxdangelo (score 2)

https://quant.stackexchange.com/a/8900

You can check also QSTK Wiki Page and QSTK GitHub page

It's an open source library developed by Georgia Tech and used in a Computational Investing course.

## Answer by working4coins (score 2)

https://quant.stackexchange.com/a/9096

You can have a look at :

TradingWithPython library (TWP Library) http://www.tradingwithpython.com/.

Like Quantopian / Zipline it uses Python Pandas library.

It includes an Interactive Brokers module to trade realtime.

## Answer by fja0568 (score 2)

https://quant.stackexchange.com/a/21821

Take a look at pinkfish. Disclaimer, I am the author.

http://fja05680.github.io/pinkfish/

## Answer by L1meta (score 0)

https://quant.stackexchange.com/a/34494

While still in alpha, I like qstrader: https://github.com/mhallsmoore/qstrader

## Answer by Mark Conway (score 0)

https://quant.stackexchange.com/a/35691

This one uses machine learning:

https://github.com/ScottFreeLLC/AlphaPy

http://alphapy.readthedocs.io/en/latest/

## Answer by epsimatic88 (score 0)

https://quant.stackexchange.com/a/45432

I can recommend the following python-based backtesting frameworks:

- QTPyLib

- backtrader

## Answer by Brian Smith (score -2)

https://quant.stackexchange.com/a/16513

Trying to start framework which allows lots of flexibility. https://github.com/bpsmith/tia

Shown in full with attribution under the source's licence. Licence: CC BY-SA 4.0 (Stack Exchange)

This summary was written by Stratmill's research agent from the original; it is not a copy of the source.