backtrader
BackTesting Engine
What it is and what it does
Backtrader is a self-contained backtesting and live trading platform for Python that lets you design and test trading strategies against historical market data before deploying them to live brokers. It supports multiple data sources (CSV, online feeds, pandas, blaze), multiple simultaneous data feeds and timeframes, and includes a built-in library of 122 technical indicators plus support for TA-Lib. The engine simulates realistic trading conditions with configurable commission schemes, slippage, volume filling strategies, and multiple order types (Market, Limit, Stop, StopTrail, OCO, bracket orders).
You can backtest strategies step-by-step or all at once, apply data filters (like Renko bricks or intraday simulation), resample and replay data, and analyze results with integrated analyzers for metrics like Sharpe Ratio and SQN. Live trading is supported with Interactive Brokers, Visual Chart, and Oanda. The platform includes plotting via matplotlib, automated position sizing, trading calendars, and schedulers. It runs on Python 3.2+ and also works with PyPy, though plotting is not available under PyPy.
Use it for:
- Backtest a moving-average crossover strategy against historical stock data before deploying it live.
- Simulate intraday trading by breaking daily bars into smaller chunks and testing order fills at different price levels.
- Compare multiple trading strategies across different timeframes and data feeds simultaneously to find the best performer.
- Analyze trading performance with built-in metrics like Sharpe Ratio, total return, and drawdown to evaluate strategy robustness.
- Live-trade a validated strategy through Interactive Brokers or Oanda with realistic commission and slippage modeling.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Backtrader is a Python backtesting and live trading engine that simulates trading strategies against historical data and supports live execution with multiple brokers and data sources.
Yes, if you are building or testing trading strategies and can accept GPLv3+ licensing constraints. Backtrader is a mature, feature-rich backtesting engine with low install friction and no external dependencies (except for optional plotting). However, maintenance is dormant—the last release was April 2023—so expect no new features or timely bug fixes. It remains suitable for strategy development and testing, but evaluate whether its feature set meets your needs without ongoing updates.
Install
backtrader on PyPI
pip
pip install backtraderuv
uv add backtraderpoetry
poetry add backtraderInstalling backtrader
Before you install
Low friction install with no runtime dependencies. Dormant maintenance status (last release 2023-04-19, last commit 2024-08-19) means bug fixes and feature updates are infrequent, though the repository remains active and is not archived.
License in practice
GPLv3+ copyleft license requires that any derivative work or distribution must also be open-source under a compatible license. Proprietary trading systems built on this package must be released under GPLv3+ or not distributed.
Quickstart
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()
Plotting requires matplotlib (minimum version 1.4.1). Live trading with Interactive Brokers requires IbPy; Oanda integration requires oandapy. Visual Chart support requires a fork of comtypes.
Verify before relying
- Whether Yahoo Finance data feeds continue to work reliably given the note about API changes in 2018.
- Current compatibility with Python versions beyond 3.7, given classifiers list up to 3.7 only.
- Whether pyfolio integration (noted as deprecated) is still functional or has been removed.
Package facts
| License | GPLv3+ (copyleft) |
| Python support | not specified |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | none |
| Maintenance | dormant — 1,213 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 327,865/month — #7,564 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: backtrader-1.9.78.123-py2.py3-none-any.whl
Keywords: trading, development
Tags
More Software Development packages
Provides backported and experimental type hints…
permissive · top 100 on PyPI
numpyNumPy provides an N-dimensional array object…
permissive · top 100 on PyPI
fastapiFastAPI is a Python web framework for building…
permissive · top 100 on PyPI
annotated-docProvides a way to document function parameters,…
permissive · top 100 on PyPI
typerTyper builds command-line applications from…
permissive · top 1,000 on PyPI
distlibDistlib provides low-level packaging utilities…
permissive · top 1,000 on PyPI
backtestingBacktesting.py lets you define and test trading…
agpl · top 15,000 on PyPI
freqtradeFreqtrade is a Python-based cryptocurrency…
copyleft · top 15,000 on PyPI
lumibotLumibot is a Python framework for building,…
permissive · top 15,000 on PyPI
vectorbtVectorized backtesting engine that packs…
unclear · top 15,000 on PyPI
nautilus_traderNautilusTrader is a Rust-native event-driven…
copyleft · top 15,000 on PyPI
technicalTechnical provides a collection of technical…
copyleft · top 15,000 on PyPI
quantconnect-stubsProvides type stubs for QuantConnect's Lean…
permissive · top 15,000 on PyPI
metatrader5Connects Python to MetaTrader 5 Terminal to…
permissive · top 15,000 on PyPI
tradingview-taRetrieves technical analysis indicators and…
permissive · top 15,000 on PyPI
taComputes technical analysis indicators (volume,…
permissive · top 5,000 on PyPI