.. 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/backtrader2/backtrader.png?branch=master :alt: Travis-ci Build Status :scale: 100% :target: https://travis-ci.org/backtrader2/backtrader .. image:: https://img.shields.io/pypi/pyversions/backtrader.svg :alt: Python versions :scale: 100% :target: https://pypi.python.org/pypi/backtrader/
Important Update
Backtrader is a flexible and powerful backtesting engine written in python. The original project found wide appeal due to its versatility. Over time however, the original code base became inaccessible to bug fixes and enhancements.
Backtrader2 is a forked copy of backtrader by the community of users that seeks to make backtrader an ongoing project.
Initially backtrader2 will fix bugs. Just submit an issue and pull requests.
New code ideas are welcome but will not be addressed at this time. But please do enter them as an issue and tag it with 'enhancement' so that we can track your idea down the road.
Backtrader's back and we look forward to its future!
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.
Live Trading and backtesting platform written in Python.
Live Data Feed and Trading with
IbPy
and benefits greatly from an
installed pytz
)comtypes
until a pull request is
integrated in the release and benefits from pytz
)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)
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 >= 3.2
It also works with pypy
and pypy3
(no plotting - matplotlib
is
not supported under pypy)
backtrader
is self-contained with no external dependencies (except if you
want to plot)
Install the latest version from the backtrader2 repository:
pip install git+https://github.com/backtrader2/backtrader
Or install the original version of backtrader
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:
X.Y.Z.I
numpy