BackTesting Engine - maintained by LucidInvestor
Project description
backtrader
credits
original author: Daniel Rodriguez (danjrod@gmail.com) original unmaintained github: https://github.com/mementum/backtrader alternative unmaintained github: https://github.com/backtrader2/backtrader
Tickets
The ticket system is available at LucidInvestor’s public gitlab instance.
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.
Installation
backtrader is self-contained with no external dependencies (except if you want to plot)
From pypi:
pip install backtrader-lucidinvestor
pip install backtrader[plotting]
If matplotlib is not installed and you wish to do some plotting
An example for IB Data Feeds/Trading:
IbPy pip install IbPy-lucidinvestor
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
Python 2/3 Support
Python >= 3.2
It also works with pypy and pypy3 (no plotting - matplotlib is not supported under pypy)
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:
Read the full documentation at:
List of built-in Indicators (122)
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
major Branches
master - Merge from Develop. QA for full integration happens here. Contains the last tested/verified global code integration.
release - Checkout from Master. Branch based on release & tags. Bug fix in checkout branches, and merge with others.
develop - Checkout from Master / Pull.Req from Develop. Develop new features, docs …
bug - checkout from master and pull.req. OR checkout from release branch and pull.req/Master
features - checkout Develop.
Branch naming conventions
shall follow that of [GroupName/Info](http://stackoverflow.com/questions/273695/git-branch-naming-best-practices):
Use grouping names at the beginning of your branch names.
Define and use short lead tokens to differentiate branches in a way that is meaningful to your workflow.
Use slashes to separate parts of your branch names.
Do not use bare numbers as leading parts.
Avoid long descriptive names for long-lived branches.
Grouping Names
Short and well-defined group names (used to tell you to which part of your workflow each branch belongs): code-block/ text
rc release candidate
new major new feature, module
feat addition of incremental feature/enhancement
bug Bug fix
junk Throwaway branch created to experiment
test
doc documentation (readme, code comment)
Commit messages
Standard prefixes to start a commit message: code-block:: text
BLD change related to build
BUG bug fix
DEP deprecate something, or remove a deprecated object
DEV development tool or utility
DOC documentation
ENH enhancement
MAINT maintenance commit (refactoring, typos, etc)
REV revert an earlier commit
STY style fix (whitespace, PEP8, flake8, etc)
TST addition or modification of tests
REL related to releasing
PERF performance enhancements
Some commit style guidelines:
Commit lines should be no longer than 72 characters. The first line of the commit should include one of the above prefixes. There should be an empty line between the commit subject and the body of the commit. In general, the message should be in the imperative tense. Best practice is to include not only what the change is, but why the change was made.
Repo Structure
git remote add bt2-original https://github.com/backtrader2/backtrader.git git fetch bt2-original master git branch –set-upstream-to=bt2-original/master git pull git push origin -u bt2/original/master
git remote -v
bt-original https://github.com/mementum/backtrader.git (fetch) bt-original https://github.com/mementum/backtrader.git (push) bt2-original https://github.com/backtrader2/backtrader.git (fetch) bt2-original https://github.com/backtrader2/backtrader.git (push) mementum https://github.com/mementum/backtrader.git (fetch) mementum https://github.com/mementum/backtrader.git (push) origin git@gitlab.com:algorithmic-trading-library/backtrader.git (fetch) origin git@gitlab.com:algorithmic-trading-library/backtrader.git (push)
git branch -vv
bt/original/develop fca15d9 [origin/bt/original/develop] Release 1.9.75.123 bt/original/master 0fa63ef [origin/bt/original/master] Merge pull request #418 from Larry-u/patch-1 bt2/original/develop ef00a78 [origin/bt2/original/develop] Merge branch ‘master’ of https://github.com/backtrader2/backtrader into bt2/original/master bt2/original/master ef00a78 [origin/bt2/original/master] Merge branch ‘master’ of https://github.com/backtrader2/backtrader into bt2/original/master develop 9f843b0 MAINT: making things cleaner for testing bid/ask. development 9f843b0 [origin/development: gone] MAINT: making things cleaner for testing bid/ask. feat/ib/bidask dcb4c1a Release 1.9.74.123 feat/ib/rt-bidask 7b366cd [origin/feat/ib/rt-bidask] FEAT: bid/ask stream. on and off. tested live. master 9f843b0 [origin/master] MAINT: making things cleaner for testing bid/ask.
Fetching all remote branches
for abranch in $(git branch -a | grep -v HEAD | grep remotes | sed “s/remotes/origin///g”); do git checkout $abranch ; done
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file backtrader-lucidinvestor-1.9.7702.tar.gz
.
File metadata
- Download URL: backtrader-lucidinvestor-1.9.7702.tar.gz
- Upload date:
- Size: 2.2 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 95e696d96557e1058ec35b6c383715b8aeb941590bfe996fe058449a7621d0c2 |
|
MD5 | 5809a5827e0972b4568836dd5fbcaf8d |
|
BLAKE2b-256 | df56af187a97537874e302d1804503375f45500e2272cb058a6a7d1f53c4f1aa |
File details
Details for the file backtrader_lucidinvestor-1.9.7702-py3-none-any.whl
.
File metadata
- Download URL: backtrader_lucidinvestor-1.9.7702-py3-none-any.whl
- Upload date:
- Size: 425.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | dfe7004c89e09f1979b561b7794dcfba38c779ad511bd5335a6ec39fffaddc88 |
|
MD5 | 1eae9003f4bdfc599b9ddb9f869d5108 |
|
BLAKE2b-256 | 01d68686d051b11e5500f821a1f8dfc16d7ce8bcfb10c5eac9d3e60712e2b0f9 |