backtrader README

The project's README from github.com/mementum/backtrader. As one markdown file: README.md.

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.

Documentation

The blog:

Read the full documentation at:

List of built-in Indicators (122)

Python 2/3 Support

Installation

backtrader is self-contained with no external dependencies (except if you want to plot)

From pypi:

.. 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:

Version numbering

X.Y.Z.I

backtrader (mementum/backtrader)

Searching Database…

这是什么东西?backtrader 是一个用于回测交易策略的 Python 库:你把策略写成代码,拿它去跑历史行情数据,在实际投入真金白银之前,先衡量一下它原本的表现会怎么样。
这是我要安装的软件,还是写代码时调用的库?是一个写代码时调用的库,不是独立的应用:你自己的 Python 脚本导入 backtrader 来定义策略、喂入行情数据并运行回测。
我怎么把它装到我的项目里?通过 PyPI 安装:pip install backtrader。或者用源码方式:把源码里的 backtrader 目录放进你的项目中,然后从那里导入。
它会连带装一堆别的库吗?默认一个都不需要——它本身自足,没有任何外部依赖。只有画图功能是可选的:pip install backtrader[plotting] 会额外安装 matplotlib,最低要求 1.4.1 版本。
开始之前有什么坑需要知道?Interactive Brokers 的接口 IbPy 不在 PyPI 上,必须从 git 安装。另外 Yahoo 数据下载曾有一段很不稳定,到 2018 年 11 月才通过网页接口或 API v7 恢复正常。
它能从哪里拉取历史行情数据?README 提到可以从 Yahoo Finance 下载数据,还支持 Interactive Brokers(通过 IbPy)、Visual Chart 和 Oanda 的数据源对接,另外也支持 TA-Lib。每种对接都有各自的依赖,文档里有列出。
它能下真实的单吗,还是只能回测?实盘交易也在功能范围内:README 里有一个 Interactive Brokers 的示例,同时覆盖了数据接入和交易,此外还提到了 Oanda 和 Visual Chart 的对接。
它内置了多少个指标?指标数量直接写在版本号里:在 X.Y.Z.I 这种格式中,末尾的数字 I 就是平台内置指标的数量,所以每个版本都自带自己的指标数。
这个项目还在积极维护吗?项目始于 2015 年,在 GitHub 上大约有 23,500 颗星,但 README 里那句关于反馈渠道的括号注记“is (was, actually)”暗示日常活跃度已经降温;有问题的话,官方建议去 Community 提问。
Creator
mementum
Size
21.9 MB
Stars
23.5K
Updated
CommitApr 19
Age
11y
Commits · 90 Days