/backtrader

Python Backtesting library for trading strategies

Primary LanguagePythonGNU General Public License v3.0GPL-3.0

backtrader

PyPi Version PyPi Monthly Donwloads License Travis-ci Build Status Documentation Status Pytghon versions

Release 1.6.x.93: pyfolio integration

Features:

Live Trading and backtesting platform written in Python.

  • Live Data Feed and Trading with Interactive Brokers (needs IbPy and benefits greatly from an installed pytz)
  • Data feeds from csv/files or for example pandas
  • Filters for datas (like breaking a daily bar into chunks to simulate intraday)
  • Multiple data feeds and multiple strategies supported
  • Multiple timeframes at once
  • Integrated Resampling and Replaying
  • Step by Step backtesting or at once (except in the evaluation of the Strategy)
  • Integrated battery of indicators
  • Easy development of custom indicators
  • Analyzers (for example: TimeReturn, Sharpe Ratio, SQN) and pyfolio integration
  • Flexible definition of commission schemes
  • Integrated broker simulation with Market, Close, Limit, Stop and StopLimit orders and continuous cash adjustmet for future-like instruments
  • Plotting (requires matplotlib)

Documentation

The blog:

Read the full documentation at readthedocs.org:

List of built-in Indicators (93)

Python 2/3 Support

  • Python 2.7
  • Python 3.2/3.3/3.4/3.5
  • It also works with pypy and pypy3 (no plotting - matplotlib is not supported under pypy)

Compatibility is tested during development with 2.7 and 3.4

The other versions are tested automatically with Travis.

Installation

backtrader is self-contained with no external dependencies (except if you want to plot)

From pypi:

  • pip install backtrader

  • pip install backtrader[matplotlib]

    If matplotlib is not installed and you wish to do some plotting

Note

The minimum matplotlib version is 1.4.1

For IB Trading:

  • IbPy doesn't seem to be in PyPi. Do either:

    pip install git+https://github.com/blampe/IbPy.git
    

    or (if git is not available in your system):

    pip install https://github.com/blampe/IbPy/archive/master.zip
    

From source:

  • Place the backtrader directory found in the sources inside your project

Version numbering

X.Y.Z.I

  • X: Major version number. Should stay stable unless something big is changed like an overhaul to use numpy
  • Y: Minor version number. To be changed upon adding a complete new feature or (god forbids) an incompatible API change.
  • Z: Revision version number. To be changed for documentation updates, small changes, small bug fixes
  • I: Number of Indicators already built into the platform

Alternatives

If after seeing the docs (see also the example below) you feel this is not your cup of tea, you can always have a look at similar Python platforms: