Skip to main content

BackTesting Engine

Project description

backtrader

.. image:: https://img.shields.io/pypi/v/backtrader.svg :alt: PyPi Version :scale: 100% :target: https://pypi.python.org/pypi/backtrader/

.. .. image:: https://img.shields.io/pypi/dm/backtrader.svg :alt: PyPi Monthly Donwloads :scale: 100% :target: https://pypi.python.org/pypi/backtrader/

.. image:: https://img.shields.io/pypi/l/backtrader.svg :alt: License :scale: 100% :target: https://github.com/backtrader/backtrader/blob/master/LICENSE .. image:: https://travis-ci.org/backtrader/backtrader.png?branch=master :alt: Travis-ci Build Status :scale: 100% :target: https://travis-ci.org/backtrader/backtrader .. image:: https://img.shields.io/pypi/pyversions/backtrader.svg :alt: Python versions :scale: 100% :target: https://pypi.python.org/pypi/backtrader/

Yahoo API Note:

[2018-11-16] After some testing it would seem that data downloads can be again relied upon over the web interface (or API v7)

Tickets

The ticket system is (was, actually) more often than not abused to ask for advice about samples.

For feedback/questions/... use the Community <https://community.backtrader.com>_

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='MSFT', 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 or working with Renko bricks

  • 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 (deprecated)

  • Flexible definition of commission schemes

  • Integrated broker simulation with Market, Close, Limit, Stop, StopLimit, StopTrail, StopTrailLimitand OCO orders, bracket order, slippage, volume filling strategies and continuous cash adjustmet for future-like instruments

  • Sizers for automated staking

  • Cheat-on-Close and Cheat-on-Open modes

  • Schedulers

  • Trading Calendars

  • Plotting (requires matplotlib)

Documentation

The blog:

  • Blog <http://www.backtrader.com/blog>_

Read the full documentation at:

  • Documentation <http://www.backtrader.com/docu>_

List of built-in Indicators (122)

  • Indicators Reference <http://www.backtrader.com/docu/indautoref.html>_

Python 2/3 Support

  • Python >= 3.2

  • It also works with pypy and pypy3 (no plotting - matplotlib is not supported under pypy)

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:

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

Build the Package

To build the package, run:

python -m pip install --upgrade build
rm -r dist
python -m build

To upload the package to PyPI, run:

twine upload dist/*

Project details


Download files

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

Source Distribution

pwb_backtrader-1.9.78.124.tar.gz (292.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pwb_backtrader-1.9.78.124-py3-none-any.whl (421.5 kB view details)

Uploaded Python 3

File details

Details for the file pwb_backtrader-1.9.78.124.tar.gz.

File metadata

  • Download URL: pwb_backtrader-1.9.78.124.tar.gz
  • Upload date:
  • Size: 292.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for pwb_backtrader-1.9.78.124.tar.gz
Algorithm Hash digest
SHA256 6a64f2e94b44d2d06fa46596d8882e069a7729d7a032cf4b306a0e058d1e1c70
MD5 b1dd8cffcb0a966ef93ea21b18f81ead
BLAKE2b-256 262a0ecc944fd68a6f2d74e951d46c627307f68381e36d15294c390c36d4b05d

See more details on using hashes here.

File details

Details for the file pwb_backtrader-1.9.78.124-py3-none-any.whl.

File metadata

File hashes

Hashes for pwb_backtrader-1.9.78.124-py3-none-any.whl
Algorithm Hash digest
SHA256 cb5d3e34ed3ee72c430c494116cf1ca2880590705ed33773fa421583aab2411d
MD5 69cf3a85c0f23ae4c443d0ddc35fe5e8
BLAKE2b-256 be773dc1c3044aa132239ff21c99efe7eb8dbb6e785454e13793bd4885f2cd18

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page