.. 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.
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
pyfolio
integration (deprecated)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)
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
By this link https://github.com/WISEPLAT/backtrader you can suggest your commits, I will apply them ASAP. This suggestion is made here, because of no one here doesn't want to continue this cool project!
1st commit: Option to change background for plotted value tags for dark theme - to get dark theme))) When you use dark theme you need to change background for plotted value tags.
2nd commit: Fix: In last Python versions collections.Iterable -> collections.abcIterable - to work with Python 3.11+ Please review and approve it if you have time. Thanks.
,This fixes the backtest broker displaying NaN for the portfolio value returned by get_value/getvalue, even if there are no positions in the data feeds where the data.close[0]
value is NaN.
Practical Example: One wants to backtest multiple data feeds of different assets over various times. Backtrader is prefilled with all assets, but cannot invest in stocks that haven't IPOed yet, for example. Nevertheless, the data feed is already loaded. This problem was also discussed here
Fix: - add python standard math dependency for isnan() - check for NaN when computing the portfolio value. - continue the value calculation loop if the closing price of the asset is NaN, no matter the position. If there is one, its worthless anyways.
Potential loopholes of fix: - None is not yet checked for - Infinity is not yet checked for.
Datafeed sourced from IB API receives timezone info from contractdetails. This tz info was not passed to num2date() method in lines 275 and 276. This results in an offset in the point value returned by self._gettmpoint(tm). This offset distorts the resampling and produces bars at irregular intervals. Above modifications takes care of the same.
Note: Modified code was tested on Minute 1
timeframe resampled to 20, 25 & 75 minutes using ibdata and data form local csv file.
Updates to collections.abc for instance check Adds try/except for backwardscompatibility
Updates to collections.abc for instance check Adds try/except for backwardscompatibility
python trading backtesting metaclass