47
$\begingroup$

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#

$\endgroup$
2
  • 1
    $\begingroup$ What does your employer currently use? $\endgroup$ Sep 6, 2013 at 13:08
  • $\begingroup$ @Terence Ng: I'm curious, what is it about Zipline that makes it unsuitable for u ? $\endgroup$
    – TCSGrad
    Jul 22, 2020 at 3:12

14 Answers 14

30
$\begingroup$

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.

$\endgroup$
3
  • $\begingroup$ Which one you would recommend? $\endgroup$
    – Terence Ng
    Sep 9, 2013 at 5:57
  • 1
    $\begingroup$ Zipline is an equity backtester only. What can I do if I want to use it in Currencies and Futures? Which one I can choose? Do I have to select an library and modify the code myself? $\endgroup$
    – Terence Ng
    Sep 11, 2013 at 7:32
  • 1
    $\begingroup$ your links go to spam sites now $\endgroup$
    – deltree
    Sep 26, 2021 at 1:22
18
$\begingroup$

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

  • Orders: Market, Limit, Stop, StopLimit, StopTrail, Bracket, OCO, Future-Spot compensation, Market-On-Close

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

$\endgroup$
4
  • $\begingroup$ Your project seems really cool, and the good documentation looks very good as well. I'm going to learn many things from it, thank you ! $\endgroup$
    – faysou
    Jun 23, 2016 at 22:58
  • $\begingroup$ I was evaluating your library, and I do thing it's a very interesting project. A thing I missed a lot was a deeper integration with Pandas, and, in my opinion, pandas is right now the library to go for anything related to financial data. $\endgroup$ Sep 20, 2017 at 9:11
  • $\begingroup$ Feel free to join the community and explain what "deeper" is. One of the core goals of the project is to only use the standard python library in the core and even in the Pandas data feed, the pandas package is not imported. It's left to the end user to have pandas available if he/she wants to use it. $\endgroup$
    – mementum
    Sep 20, 2017 at 10:40
  • $\begingroup$ does it do any level of parallelization to leverage cores on a system? $\endgroup$
    – mike01010
    Oct 14, 2020 at 2:37
8
$\begingroup$

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

$\endgroup$
1
  • $\begingroup$ Look very neat. I like the very clean approach of using Pandas as the basic data analysis library. $\endgroup$
    – fccoelho
    Feb 22, 2016 at 20:00
6
$\begingroup$

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.

$\endgroup$
6
$\begingroup$

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.

$\endgroup$
3
  • $\begingroup$ IBridgePy seems interesting to me. Is it actively developed as of now? I am starting to look at the documentation. I am interested in backtesting+paper trading+live trading. I already have an IB account. Thanks. $\endgroup$
    – Alok
    Jun 25, 2017 at 14:45
  • $\begingroup$ Yes. Please check out the release note. ibridgepy.com/release-notes $\endgroup$ Oct 18, 2017 at 6:48
  • $\begingroup$ i have been using it for a while now and i like it very much. thanks. $\endgroup$
    – Alok
    Oct 18, 2017 at 10:11
4
$\begingroup$

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.

$\endgroup$
4
$\begingroup$

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.

$\endgroup$
2
$\begingroup$

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.

$\endgroup$
2
$\begingroup$

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

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

$\endgroup$
2
$\begingroup$

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.

$\endgroup$
2
  • $\begingroup$ Looks pretty nice, should be on github though. Only does daily trading, no high frequency support, $\endgroup$
    – fccoelho
    Feb 22, 2016 at 19:46
  • $\begingroup$ I've updated my answer to include the GitHub latest repository $\endgroup$
    – maxdangelo
    Feb 27, 2016 at 12:26
0
$\begingroup$

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

$\endgroup$
0
$\begingroup$

This one uses machine learning:

https://github.com/ScottFreeLLC/AlphaPy

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

$\endgroup$
0
$\begingroup$

I can recommend the following python-based backtesting frameworks:

$\endgroup$
-2
$\begingroup$

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

$\endgroup$
3
  • $\begingroup$ How do you know this framework? do you use it? did you write it? $\endgroup$
    – SRKX
    Feb 10, 2015 at 5:23
  • $\begingroup$ Yes - work in progress. First doing historical analysis of trades so no opinion about how simulation is implemented. (Up to user) Attempting to modularize components for simple usage in other frameworks. Still in alpha but within 2 months should be hardened and in production. Bloomberg API alone is worth a look if you use this data. Also looking for contributors or open source partners to create a framework usable in ipython by novices. $\endgroup$ Mar 14, 2015 at 3:05
  • $\begingroup$ Then you should include these inside your answer, stating very clearly that you're part of the project. $\endgroup$
    – SRKX
    Mar 16, 2015 at 1:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.