Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (pypi.python.org).
Help us improve Python packaging - Donate today!

BackTesting Engine

Project Description

backtrader

Yahoo API Note:

With release 1.9.50.117 data samples and YahooFinance data feeds have been updated to the latest available information. But being the format not documented, there could still be changes and unexpected corners.

For feedback/questions/issues use the Community

Here a snippet of a Simple Moving Average CrossOver. It can be done in several different ways. Use the docs (and examples) Luke!

from datetime import datetime
import backtrader as bt

class SmaCross(bt.SignalStrategy):
    def __init__(self):
        sma1, sma2 = bt.ind.SMA(period=10), bt.ind.SMA(period=30)
        crossover = bt.ind.CrossOver(sma1, sma2)
        self.signal_add(bt.SIGNAL_LONG, crossover)

cerebro = bt.Cerebro()
cerebro.addstrategy(SmaCross)

data0 = bt.feeds.YahooFinanceData(dataname='YHOO', fromdate=datetime(2011, 1, 1),
                                  todate=datetime(2012, 12, 31))
cerebro.adddata(data0)

cerebro.run()
cerebro.plot()

Including a full featured chart. Give it a try! This is included in the samples as sigsmacross/sigsmacross2.py. Along it is sigsmacross.py which can be parametrized from the command line.

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)
    • Visual Chart (needs a fork of comtypes until a pull request is integrated in the release and benefits from pytz)
    • Oanda (needs oandapy) (REST API Only - v20 did not support streaming when implemented)
  • Data feeds from csv/files, online sources or from pandas and blaze
  • 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
  • TA-Lib indicator support (needs python ta-lib / check the docs)
  • 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, StopLimit, StopTrail, StopTrailLimit*and *OCO, orders, slippage and continuous cash adjustmet for future-like instruments
  • Plotting (requires matplotlib)

Documentation

The blog:

Read the full documentation at:

List of built-in Indicators (116)

Python 2/3 Support

  • Python 2.7
  • Python 3.2 / 3.3/ 3.4 / 3.5 / 3.6
  • 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.5

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[plotting]

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

Note

The minimum matplotlib version is 1.4.1

An example for IB Data Feeds/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
    

For other functionalities like: Visual Chart, Oanda, TA-Lib, check the dependencies in the documentation.

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 and some samples (see the blog also) you feel this is not your cup of tea, you can always have a look at similar Python platforms:

Release History

Release History

This version
History Node

1.9.58.122

History Node

1.9.57.122

History Node

1.9.56.122

History Node

1.9.55.122

History Node

1.9.54.122

History Node

1.9.53.121

History Node

1.9.52.121

History Node

1.9.51.121

History Node

1.9.50.117

History Node

1.9.49.116

History Node

1.9.48.116

History Node

1.9.47.116

History Node

1.9.46.116

History Node

1.9.45.116

History Node

1.9.44.116

History Node

1.9.43.116

History Node

1.9.42.116

History Node

1.9.41.116

History Node

1.9.40.116

History Node

1.9.39.116

History Node

1.9.38.116

History Node

1.9.37.116

History Node

1.9.36.116

History Node

1.9.35.116

History Node

1.9.34.116

History Node

1.9.33.116

History Node

1.9.32.116

History Node

1.9.31.116

History Node

1.9.30.111

History Node

1.9.29.108

History Node

1.9.28.108

History Node

1.9.27.105

History Node

1.9.26.105

History Node

1.9.25.105

History Node

1.9.24.105

History Node

1.9.23.105

History Node

1.9.22.105

History Node

1.9.21.105

History Node

1.9.20.105

History Node

1.9.19.105

History Node

1.9.18.105

History Node

1.9.17.105

History Node

1.9.16.105

History Node

1.9.15.104

History Node

1.9.14.102

History Node

1.9.13.102

History Node

1.9.12.99

History Node

1.9.11.99

History Node

1.9.10.99

History Node

1.9.9.99

History Node

1.9.8.99

History Node

1.9.7.99

History Node

1.9.6.99

History Node

1.9.5.99

History Node

1.9.4.99

History Node

1.9.3.99

History Node

1.9.2.99

History Node

1.9.1.99

History Node

1.9.0.99

History Node

1.8.14.99

History Node

1.8.13.99

History Node

1.8.12.99

History Node

1.8.11.99

History Node

1.8.10.99

History Node

1.8.9.96

History Node

1.8.8.96

History Node

1.8.7.96

History Node

1.8.6.93

History Node

1.8.5.93

History Node

1.8.3.93

History Node

1.8.2.93

History Node

1.8.1.93

History Node

1.8.0.93

History Node

1.7.2.93

History Node

1.7.1.93

Download Files

Download Files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
backtrader-1.9.58.122-py2.py3-none-any.whl (411.3 kB) Copy SHA256 Checksum SHA256 2.7 Wheel Aug 4, 2017

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting