skillfed

backtrader

BackTesting Engine

backtrader v1.9.78.123 327.9K downloads/30d#7,564 on PyPI22,845
Copyleft license GPLv3+ DORMANT released

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 backtrader

uv

uv add backtrader

poetry

poetry add backtrader

Installing 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

Development Status :: 5 - Production/StableIntended Audience :: DevelopersIntended Audience :: Financial and Insurance IndustryLicense :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)Operating System :: OS IndependentProgramming Language :: Python :: 3Programming Language :: Python :: 3.2Programming Language :: Python :: 3.3Programming Language :: Python :: 3.4Programming Language :: Python :: 3.5Programming Language :: Python :: 3.6Programming Language :: Python :: 3.7Topic :: Office/Business :: FinancialTopic :: Software Development

Tags

backtesting trading strategiesalgorithmic trading frameworklive trading enginetrading strategy simulatorfinancial data backtesterbroker integration tradingtechnical indicator framework
trading-backtestingfinancial-analysisalgorithmic-trading

More Software Development packages