Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mementum/backtrader
Python Backtesting library for trading strategies
https://github.com/mementum/backtrader
backtesting metaclass python trading
Last synced: 20 days ago
JSON representation
Python Backtesting library for trading strategies
- Host: GitHub
- URL: https://github.com/mementum/backtrader
- Owner: mementum
- License: gpl-3.0
- Created: 2015-01-10T07:14:52.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2024-07-23T16:10:32.000Z (4 months ago)
- Last Synced: 2024-08-01T02:11:55.264Z (4 months ago)
- Topics: backtesting, metaclass, python, trading
- Language: Python
- Homepage: https://www.backtrader.com
- Size: 21.4 MB
- Stars: 13,671
- Watchers: 607
- Forks: 3,809
- Open Issues: 50
-
Metadata Files:
- Readme: README.rst
- Changelog: changelog.txt
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
- awesome-quant-cn - backtrader - - 纯python实现的在线交易和回测平台 (回测引擎)
- awesome-systematic-trading - backtrader - with-python](https://img.shields.io/badge/Made%20with-Python-1f425f.svg) | (Backtesting and Live Trading / General - Event Driven Frameworks)
- awesome-python-machine-learning-resources - GitHub
- awesome-crypto-trading-bots - Backtrader - A feature-rich Python framework for backtesting and trading. (Open source bots)
- awesome-crypto-trading-bots - Backtrader - A feature-rich Python framework for backtesting and trading. (Open source bots)
- StarryDivineSky - mementum/backtrader
- awesome-systematic-trading - backtrader - commit/mementum/backtrader/master) ![GitHub Repo stars](https://img.shields.io/github/stars/mementum/backtrader?style=social) | Python, Live Trading | - Event driven Python Backtesting library for trading strategies (Backtest + live trading / General purpose)
- pytrade.org - backtrader - Python Backtesting library for trading strategies (Curated List / Trading Frameworks (support backtesting and live trading))
README
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 `_
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 btclass 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*, *StopTrailLimit*and *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 `_
Read the full documentation at:
- `Documentation `_
List of built-in Indicators (122)
- `Indicators Reference `_
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:
- ``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