回溯测试引擎
backtrader-fchain的Python项目详细描述
背交易者
yahoo api注释:
[2018-11-16] After some testing it would seem that data downloads can be again relied upon over the web interface (or API ^{tt1}$)
票
If it’s NOT an issue (i.e.: bug), don’t post it as an issue. It will be automatically closed.
对于feedback/questions/…使用Community
这里是一个简单的移动平均交叉的片段。它可以在几分钟内完成 不同的方式。使用文档(和示例)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()
包括一个全功能的图表。试试看!这包括在样品中 作为sigsmacross/sigsmacross2.py。沿着它是sigsmacross.py,可以是 从命令行参数化。
特点:
用python编写的实时交易和回溯测试平台。
- Live Data Feed and Trading with
- Interactive Brokers (needs ^{tt4}$ and benefits greatly from an installed ^{tt5}$)
- Visual Chart (needs a fork of ^{tt6}$ until a pull request is integrated in the release and benefits from ^{tt5}$)
- Oanda (needs ^{tt8}$) (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 ^{tt9}$ 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)
python 2/3支持
- Python ^{tt10}$
- Python ^{tt11}$ / ^{tt12}$/ ^{tt13}$ / ^{tt14}$ / ^{tt15}$ / ^{tt16}$
- It also works with ^{tt17}$ and ^{tt18}$ (no plotting - ^{tt19}$ is not supported under pypy)
在使用2.7和3.5
其他版本是用travis自动测试的。
安装
backtrader是自包含的,没有外部依赖项(除非您 想要绘图)
来自pypi:
^{tt23}$
^{tt24}$
If ^{tt19}$ is not installed and you wish to do some plotting
注意
matplotlib的最低版本是1.4.1
例如ib数据馈送/交易:
^{tt4}$ doesn’t seem to be in PyPi. Do either:
pip install git+https://github.com/blampe/IbPy.gitor (if ^{tt28}$ is not available in your system):
pip install https://github.com/blampe/IbPy/archive/master.zip
对于其他功能,如:Visual Chart,Oanda,TA-Lib,请选中 文档中的依赖项。
来源:
- Place the backtrader directory found in the sources inside your project
版本编号
x.y.z.i
- X: Major version number. Should stay stable unless something big is changed like an overhaul to use ^{tt32}$
- 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
备选方案
如果在看过文档和一些示例(也可以查看博客)之后,您觉得这是 不是你的茶,你总是可以看看类似的python平台:
^{tt33}$ slightly pre-dates ^{tt22}$ and has a completely different approach but it is funny bt was also chosen as the abbreviation for ^{tt22}$ during imports and that some of the methods have the same naming (obvious naming anyhow): ^{tt36}$, ^{tt37}$ …