• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

backtrader/H30-May-2019-35,49322,255

contrib/H30-May-2019-1,3521,180

datas/H03-May-2022-160158

samples/H30-May-2019-14,9469,586

tests/H30-May-2019-5,0732,505

tools/H30-May-2019-456296

.gitignoreH A D30-May-2019788 7057

.travis.ymlH A D30-May-2019402 2622

LICENSEH A D30-May-201934.3 KiB675553

README.rstH A D30-May-20197.2 KiB213155

pypi.shH A D30-May-2019121 61

setup.pyH A D30-May-20195.3 KiB14349

README.rst

1
2backtrader
3==========
4
5.. image:: https://img.shields.io/pypi/v/backtrader.svg
6   :alt: PyPi Version
7   :scale: 100%
8   :target: https://pypi.python.org/pypi/backtrader/
9
10..  .. image:: https://img.shields.io/pypi/dm/backtrader.svg
11       :alt: PyPi Monthly Donwloads
12       :scale: 100%
13       :target: https://pypi.python.org/pypi/backtrader/
14
15.. image:: https://img.shields.io/pypi/l/backtrader.svg
16   :alt: License
17   :scale: 100%
18   :target: https://github.com/backtrader/backtrader/blob/master/LICENSE
19.. image:: https://travis-ci.org/backtrader/backtrader.png?branch=master
20   :alt: Travis-ci Build Status
21   :scale: 100%
22   :target: https://travis-ci.org/backtrader/backtrader
23.. image:: https://img.shields.io/pypi/pyversions/backtrader.svg
24   :alt: Python versions
25   :scale: 100%
26   :target: https://pypi.python.org/pypi/backtrader/
27
28**Yahoo API Note**:
29
30  [2018-11-16] After some testing it would seem that data downloads can be
31  again relied upon over the web interface (or API ``v7``)
32
33**Tickets**
34
35  If it's **NOT an issue** (i.e.: bug), don't post it as an issue. It will be
36  automatically closed.
37
38For **feedback/questions/...** use the `Community <https://community.backtrader.com>`_
39
40Here a snippet of a Simple Moving Average CrossOver. It can be done in several
41different ways. Use the docs (and examples) Luke!
42::
43
44  from datetime import datetime
45  import backtrader as bt
46
47  class SmaCross(bt.SignalStrategy):
48      def __init__(self):
49          sma1, sma2 = bt.ind.SMA(period=10), bt.ind.SMA(period=30)
50          crossover = bt.ind.CrossOver(sma1, sma2)
51          self.signal_add(bt.SIGNAL_LONG, crossover)
52
53  cerebro = bt.Cerebro()
54  cerebro.addstrategy(SmaCross)
55
56  data0 = bt.feeds.YahooFinanceData(dataname='MSFT', fromdate=datetime(2011, 1, 1),
57                                    todate=datetime(2012, 12, 31))
58  cerebro.adddata(data0)
59
60  cerebro.run()
61  cerebro.plot()
62
63Including a full featured chart. Give it a try! This is included in the samples
64as ``sigsmacross/sigsmacross2.py``. Along it is ``sigsmacross.py`` which can be
65parametrized from the command line.
66
67Features:
68=========
69
70Live Trading and backtesting platform written in Python.
71
72  - Live Data Feed and Trading with
73
74    - Interactive Brokers (needs ``IbPy`` and benefits greatly from an
75      installed ``pytz``)
76    - *Visual Chart* (needs a fork of ``comtypes`` until a pull request is
77      integrated in the release and benefits from ``pytz``)
78    - *Oanda* (needs ``oandapy``) (REST API Only - v20 did not support
79      streaming when implemented)
80
81  - Data feeds from csv/files, online sources or from *pandas* and *blaze*
82  - Filters for datas, like breaking a daily bar into chunks to simulate
83    intraday or working with Renko bricks
84  - Multiple data feeds and multiple strategies supported
85  - Multiple timeframes at once
86  - Integrated Resampling and Replaying
87  - Step by Step backtesting or at once (except in the evaluation of the Strategy)
88  - Integrated battery of indicators
89  - *TA-Lib* indicator support (needs python *ta-lib* / check the docs)
90  - Easy development of custom indicators
91  - Analyzers (for example: TimeReturn, Sharpe Ratio, SQN) and ``pyfolio``
92    integration (**deprecated**)
93  - Flexible definition of commission schemes
94  - Integrated broker simulation with *Market*, *Close*, *Limit*, *Stop*,
95    *StopLimit*, *StopTrail*, *StopTrailLimit*and *OCO* orders, bracket order,
96    slippage, volume filling strategies and continuous cash adjustmet for
97    future-like instruments
98  - Sizers for automated staking
99  - Cheat-on-Close and Cheat-on-Open modes
100  - Schedulers
101  - Trading Calendars
102  - Plotting (requires matplotlib)
103
104Documentation
105=============
106
107The blog:
108
109  - `Blog <http://www.backtrader.com/blog>`_
110
111Read the full documentation at:
112
113  - `Documentation <http://www.backtrader.com/docu>`_
114
115List of built-in Indicators (122)
116
117  - `Indicators Reference <http://www.backtrader.com/docu/indautoref.html>`_
118
119Python 2/3 Support
120==================
121
122  - Python ``2.7``
123  - Python ``3.2`` / ``3.3``/ ``3.4`` / ``3.5`` / ``3.6`` / ``3.7``
124
125  - It also works with ``pypy`` and ``pypy3`` (no plotting - ``matplotlib`` is
126    not supported under *pypy*)
127
128Compatibility is tested during development with ``2.7`` and ``3.5``
129
130The other versions are tested automatically with *Travis*.
131
132Installation
133============
134
135``backtrader`` is self-contained with no external dependencies (except if you
136want to plot)
137
138From *pypi*:
139
140  - ``pip install backtrader``
141
142  - ``pip install backtrader[plotting]``
143
144    If ``matplotlib`` is not installed and you wish to do some plotting
145
146.. note:: The minimum matplotlib version is ``1.4.1``
147
148An example for *IB* Data Feeds/Trading:
149
150  - ``IbPy`` doesn't seem to be in PyPi. Do either::
151
152      pip install git+https://github.com/blampe/IbPy.git
153
154    or (if ``git`` is not available in your system)::
155
156      pip install https://github.com/blampe/IbPy/archive/master.zip
157
158For other functionalities like: ``Visual Chart``, ``Oanda``, ``TA-Lib``, check
159the dependencies in the documentation.
160
161From source:
162
163  - Place the *backtrader* directory found in the sources inside your project
164
165Version numbering
166=================
167
168X.Y.Z.I
169
170  - X: Major version number. Should stay stable unless something big is changed
171    like an overhaul to use ``numpy``
172  - Y: Minor version number. To be changed upon adding a complete new feature or
173    (god forbids) an incompatible API change.
174  - Z: Revision version number. To be changed for documentation updates, small
175    changes, small bug fixes
176  - I: Number of Indicators already built into the platform
177
178Alternatives
179============
180
181If after seeing the docs and some samples (see the blog also) you feel this is
182not your cup of tea, you can always have a look at similar Python platforms:
183
184  - `PyAlgoTrade <https://github.com/gbeced/pyalgotrade>`_
185  - `Zipline <https://github.com/quantopian/zipline>`_
186  - `Ultra-Finance <https://code.google.com/p/ultra-finance/>`_
187  - `ProfitPy <https://code.google.com/p/profitpy/>`_
188  - `pybacktest <https://github.com/ematvey/pybacktest>`_
189  - `prophet <https://github.com/Emsu/prophet>`_
190  - `quant <https://github.com/maihde/quant>`_
191  - `AlephNull <https://github.com/CarterBain/AlephNull>`_
192  - `Trading with Python <http://www.tradingwithpython.com/>`_
193  - `visualize-wealth <https://github.com/benjaminmgross/visualize-wealth>`_
194  - `tia: Toolkit for integration and analysis
195    <https://github.com/bpsmith/tia>`_
196  - `QuantSoftware Toolkit
197    <http://wiki.quantsoftware.org/index.php?title=QuantSoftware_ToolKit>`_
198  - `Pinkfish <http://fja05680.github.io/pinkfish/>`_
199  - `bt <http://pmorissette.github.io/bt/index.html>`_
200
201     ``bt`` slightly pre-dates ``backtrader`` and has a completely different
202     approach but it is funny *bt* was also chosen as the abbreviation for
203     ``backtrader`` during imports and that some of the methods have the same
204     naming (obvious naming anyhow): ``run``, ``plot`` ...
205
206  - `PyThalesians <https://github.com/thalesians/pythalesians>`_
207
208  - `QSTrader <https://github.com/mhallsmoore/qstrader/>`_
209  - `QSForex <https://github.com/mhallsmoore/qsforex>`_
210  - `pysystemtrade <https://github.com/robcarver17/pysystemtrade>`_
211  - `QTPyLib <https://github.com/ranaroussi/qtpylib>`_
212  - `RQalpha <https://github.com/ricequant/rqalpha>`_
213