BackTesting Engine - A feature-rich Python framework for backtesting and trading
Project description
nijigen-backtrader
A feature-rich Python framework for backtesting and trading.
Note: This is a maintained fork of the original backtrader project.
Quick Start
Here's 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.
-
Live Data Feed and Trading with
- Interactive Brokers (needs
IbPyand benefits greatly from an installedpytz) - Visual Chart (needs a fork of
comtypesuntil a pull request is integrated in the release and benefits frompytz) - Oanda (needs
oandapy) (REST API Only - v20 did not support streaming when implemented)
- Interactive Brokers (needs
-
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
pyfoliointegration (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 adjustment for future-like instruments
-
Sizers for automated staking
-
Cheat-on-Close and Cheat-on-Open modes
-
Schedulers
-
Trading Calendars
-
Plotting (requires matplotlib)
Documentation
- Blog
- Documentation
- Indicators Reference (122 built-in indicators)
Python Support
- Python >=
3.9 - It also works with
pypyandpypy3(no plotting -matplotlibis not supported under pypy)
Installation
nijigen-backtrader is self-contained with no external dependencies (except if you want to plot)
From pypi:
pip install nijigen-backtrader
With plotting support:
pip install nijigen-backtrader[plotting]
Note: The minimum matplotlib version is
1.4.1
Optional Dependencies
An example for IB Data Feeds/Trading:
-
IbPydoesn't seem to be in PyPi. Do either:pip install git+https://github.com/blampe/IbPy.git
or (if
gitis 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
- 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
License
GNU General Public License v3.0 or later (GPLv3+)
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file nijigen_backtrader-1.10.2.tar.gz.
File metadata
- Download URL: nijigen_backtrader-1.10.2.tar.gz
- Upload date:
- Size: 291.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
44d0abacb5dfce559235bc58c99e23660770666f4b51d78e8f61c8b0a0eaa6ab
|
|
| MD5 |
504347a210ff1824acc3e9abec098a9a
|
|
| BLAKE2b-256 |
c4da56f6755fc71394344d8e878817449061ee43190f4f5295d51d712343b3bc
|
File details
Details for the file nijigen_backtrader-1.10.2-py3-none-any.whl.
File metadata
- Download URL: nijigen_backtrader-1.10.2-py3-none-any.whl
- Upload date:
- Size: 418.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
04d52cd8dbef6e7c9b84a6af9a3a66af0cbba994b724cac9ca4a891169d03d58
|
|
| MD5 |
4600659b22c6c031241fcb5b59964c16
|
|
| BLAKE2b-256 |
72d370a1a14052fb4a3e94d65b6fb0b50a72ae4aaee0ff91ed37f423cd23cf84
|