# mementum/backtrader

**Attribution required: if you use, quote, or summarise this content, you must credit and link back to [awesome-repositories.com](https://awesome-repositories.com/repository/mementum-backtrader).**

20,462 stars · 4,922 forks · Python · gpl-3.0

## Links

- GitHub: https://github.com/mementum/backtrader
- Homepage: https://www.backtrader.com
- awesome-repositories: https://awesome-repositories.com/repository/mementum-backtrader.md

## Topics

`backtesting` `metaclass` `python` `trading`

## Description

Backtrader is a Python framework designed for the development, backtesting, and live execution of algorithmic trading strategies. It provides a comprehensive environment for quantitative finance, allowing users to simulate trading logic against historical market data or connect directly to brokerage platforms for automated real-time trading.

The project distinguishes itself through a unified event-driven architecture that treats backtesting and live trading with the same API. This consistency is supported by a flexible data-feed abstraction layer that normalizes diverse financial sources, enabling complex multi-timeframe analysis and synchronization. The system includes a robust broker-simulation engine that accounts for real-world constraints such as slippage, commissions, and margin requirements, ensuring that simulated results closely mirror potential live performance.

Beyond core execution, the library offers extensive tools for technical analysis, including a pipeline for composing mathematical indicators and a monitoring system that tracks portfolio metrics and order lifecycles. Users can visualize strategy performance, trade activity, and indicator behavior through integrated charting tools, while also leveraging built-in utilities for parameter optimization and automated task scheduling.

The framework is designed for extensibility, allowing for custom data feed definitions, specialized parsing logic, and the creation of custom observers to monitor system health. It is distributed as a Python library, providing a modular toolkit for managing the entire lifecycle of a trading strategy.

## Tags

### Business & Productivity Software

- [Algorithmic Trading Frameworks](https://awesome-repositories.com/f/business-productivity-software/algorithmic-trading-frameworks.md) — Provides a comprehensive Python library for backtesting, analyzing, and executing automated trading strategies.
- [Automated Trading Execution](https://awesome-repositories.com/f/business-productivity-software/automated-trading-execution.md) — Connects trading algorithms to brokerage platforms to stream real-time data and execute orders automatically.
- [Financial Analysis Tools](https://awesome-repositories.com/f/business-productivity-software/financial-operational-management/billing-financial-systems/financial-analysis-tools.md) — Provides a comprehensive environment for ingesting, resampling, and visualizing multi-timeframe market data to evaluate trading strategy performance.
- [Quantitative Trading Platforms](https://awesome-repositories.com/f/business-productivity-software/quantitative-trading-platforms.md) — Establishes live connections to financial brokerage services to stream real-time market data and execute trades directly. ([source](https://www.backtrader.com/docu/live/ib/ib/))
- [Trading Simulation Engines](https://awesome-repositories.com/f/business-productivity-software/trading-simulation-engines.md) — Models real-world trading constraints like slippage, commissions, and order execution within a consistent API for both backtesting and live trading.
- [Trading Strategy Backtesters](https://awesome-repositories.com/f/business-productivity-software/trading-strategy-backtesters.md) — Simulates and evaluates financial trading strategies against historical market data to measure performance.
- [Strategy Performance Analyzers](https://awesome-repositories.com/f/business-productivity-software/trading-risk-analysis/strategy-performance-analyzers.md) — Provides analytical tools for evaluating the profitability and risk exposure of trading strategies against historical data. ([source](https://www.backtrader.com/docu/))
- [Trading Strategy Definitions](https://awesome-repositories.com/f/business-productivity-software/trading-strategy-definitions.md) — Encapsulates custom logic within a structure to process market data, manage positions, and respond to order notifications. ([source](https://www.backtrader.com/docu/operating/))
- [Automated Trading Engines](https://awesome-repositories.com/f/business-productivity-software/automated-trading-engines.md) — Maps technical indicator outputs to long or short market positions to execute buy and sell orders automatically. ([source](https://www.backtrader.com/docu/signal_strategy/signal_strategy/))
- [Bracket Order Systems](https://awesome-repositories.com/f/business-productivity-software/bracket-order-systems.md) — Groups main trades with stop-loss and take-profit orders to automatically manage risk and profit targets after execution. ([source](https://www.backtrader.com/docu/order-creation-execution/bracket/bracket/))
- [Trading Risk Analysis](https://awesome-repositories.com/f/business-productivity-software/trading-risk-analysis.md) — Tracks trade statistics, risk-adjusted returns, and account equity to assess strategy profitability. ([source](https://www.backtrader.com/docu/analyzers-reference/))
- [Trading Simulations](https://awesome-repositories.com/f/business-productivity-software/trading-simulations.md) — Processes market, limit, and stop orders against historical data while validating cash requirements and margin before trades. ([source](https://www.backtrader.com/docu/broker/))
- [Automated Exit Strategies](https://awesome-repositories.com/f/business-productivity-software/order-lifecycle-management/automated-exit-strategies.md) — Issues primary orders alongside exit orders to automate profit taking and loss protection for specific trade entries. ([source](https://www.backtrader.com/docu/strategy/))
- [Position Sizing Calculators](https://awesome-repositories.com/f/business-productivity-software/position-sizing-calculators.md) — Calculates the number of units to trade based on fixed quantities, cash percentages, or position reversal requirements. ([source](https://www.backtrader.com/docu/sizers-reference/))
- [Trade Profitability Recorders](https://awesome-repositories.com/f/business-productivity-software/trading-risk-analysis/trade-profitability-recorders.md) — Tracks completed trades to calculate and visualize the profit or loss achieved after accounting for commissions and fees. ([source](https://www.backtrader.com/docu/observers-reference/))
- [Strategy Component Configuration](https://awesome-repositories.com/f/business-productivity-software/trading-strategy-backtesters/strategy-component-configuration.md) — Define customizable settings for strategies and indicators using default values that can be overridden during initialization. ([source](https://www.backtrader.com/docu/concepts/))
- [Account Lifecycle Management](https://awesome-repositories.com/f/business-productivity-software/account-lifecycle-management.md) — Handles order placement, position tracking, and commission schemes using live brokerage accounts instead of simulated instances. ([source](https://www.backtrader.com/docu/live/vc/vc/))
- [Contract Management Systems](https://awesome-repositories.com/f/business-productivity-software/contract-management-systems.md) — Automates the transition between expiring and active future contracts based on custom conditions to maintain continuous exposure. ([source](https://www.backtrader.com/docu/dataautoref/))
- [Trade Statistics Trackers](https://awesome-repositories.com/f/business-productivity-software/trading-risk-analysis/trade-statistics-trackers.md) — Aggregates data on closed and open trades, including win streaks, profit and loss, and market exposure duration. ([source](https://www.backtrader.com/docu/analyzers-reference/))
- [Brokerage Simulation Parameters](https://awesome-repositories.com/f/business-productivity-software/trading-strategy-backtesters/brokerage-simulation-parameters.md) — Sets initial cash, commission schemes, and margin requirements to simulate realistic trading environments during backtesting. ([source](https://www.backtrader.com/docu/automated-bt-run/automated-bt-run/))
- [Market Trading Calendars](https://awesome-repositories.com/f/business-productivity-software/trading-strategy-definitions/market-trading-calendars.md) — Remove intraday data points that fall outside of defined market hours to ensure analysis only considers active trading periods. ([source](https://www.backtrader.com/docu/filters-reference/))
- [Cross-Asset Position Managers](https://awesome-repositories.com/f/business-productivity-software/cross-asset-position-managers.md) — Links distinct data feeds so that trading operations on one asset automatically offset or close positions in a related asset. ([source](https://www.backtrader.com/docu/order-creation-execution/futurespot/future-vs-spot/))
- [Intraday Bar Simulators](https://awesome-repositories.com/f/business-productivity-software/intraday-bar-simulators.md) — Reconstructs higher-level timeframes from granular data to approximate real-time strategy behavior during the formation of a single bar. ([source](https://www.backtrader.com/docu/data-replay/data-replay/))
- [Trading Order Monitors](https://awesome-repositories.com/f/business-productivity-software/order-lifecycle-management/trading-order-monitors.md) — Provides status updates on order progression, including submission, acceptance, and execution, to inform strategy decision-making. ([source](https://www.backtrader.com/docu/live/vc/vc/))
- [Order Volume Matching Configurations](https://awesome-repositories.com/f/business-productivity-software/order-lifecycle-management/trading-order-monitors/order-volume-matching-configurations.md) — Determine how much available market volume is used to fill trade orders during simulation to model liquidity constraints. ([source](https://www.backtrader.com/docu/filler/))
- [Commission Models](https://awesome-repositories.com/f/business-productivity-software/trading-strategy-definitions/commission-models.md) — Configures transaction costs and margin requirements for specific financial instruments to accurately simulate real-world trading expenses. ([source](https://www.backtrader.com/docu/broker/))

### Scientific & Mathematical Computing

- [Backtesting Engines](https://awesome-repositories.com/f/scientific-mathematical-computing/quantitative-finance/backtesting-engines.md) — Orchestrates the interaction between data feeds, trading strategies, and broker simulations to evaluate performance across historical market conditions. ([source](https://www.backtrader.com/docu/))
- [Order Execution Engines](https://awesome-repositories.com/f/scientific-mathematical-computing/order-execution-engines.md) — Place market, limit, and stop orders with a brokerage using standard validity types like good-till-cancelled or good-till-date. ([source](https://www.backtrader.com/docu/live/ib/ib/))
- [Quantitative Finance & Trading](https://awesome-repositories.com/f/scientific-mathematical-computing/quantitative-finance.md) — Offers a toolkit for calculating technical indicators, managing time-series data, and simulating complex market conditions for algorithmic strategy development.
- [Technical Analysis](https://awesome-repositories.com/f/scientific-mathematical-computing/quantitative-finance/technical-analysis.md) — Computes mathematical transformations of market data within strategies to support complex decision-making logic. ([source](https://www.backtrader.com/docu/induse/))
- [Trading Signal Triggers](https://awesome-repositories.com/f/scientific-mathematical-computing/trading-signal-triggers.md) — Trigger market buy and sell orders based on the intersection of fast and slow moving average indicators on price data. ([source](https://www.backtrader.com/docu/strategy-reference/))
- [Periodic Return Calculators](https://awesome-repositories.com/f/scientific-mathematical-computing/periodic-return-calculators.md) — Computes rates of return for portfolios or assets over defined time intervals to evaluate historical performance. ([source](https://www.backtrader.com/docu/observer-benchmark/benchmarking/))
- [Slippage Simulators](https://awesome-repositories.com/f/scientific-mathematical-computing/slippage-simulators.md) — Adjust order execution prices using fixed or percentage-based offsets to simulate real-world market impact and price movement. ([source](https://www.backtrader.com/docu/broker/))

### Data & Databases

- [Time-Series Data Abstractions](https://awesome-repositories.com/f/data-databases/database-abstraction-layers/time-series-data-abstractions.md) — Normalizes diverse financial data sources into a unified time-series format for consistent processing across different backtesting scenarios.
- [Real-Time Data Streaming](https://awesome-repositories.com/f/data-databases/real-time-data-streaming.md) — Receives live price updates and volume snapshots from brokerage services for rapid decision-making. ([source](https://www.backtrader.com/docu/live/ib/ib/))
- [Data Ingestion Sources](https://awesome-repositories.com/f/data-databases/data-ingestion-sources.md) — Ingests financial market data from files, broker services, and databases for analysis. ([source](https://www.backtrader.com/docu/cerebro/))
- [Financial](https://awesome-repositories.com/f/data-databases/data-parsers/financial.md) — Map arbitrary file structures and date formats to standard price fields to support diverse financial data sources. ([source](https://www.backtrader.com/docu/datafeed/))
- [Indicator Pipelines](https://awesome-repositories.com/f/data-databases/data-pipeline-transformers/indicator-pipelines.md) — Calculates technical analysis values by chaining mathematical transformations that automatically update as new market data arrives.
- [Financial Market Visualizers](https://awesome-repositories.com/f/data-databases/data-visualization-charts/financial-market-visualizers.md) — Provides graphical representations of price data and trade execution points to assist in the analysis of strategy behavior. ([source](https://www.backtrader.com/docu/operating/))
- [Market Data Recorders](https://awesome-repositories.com/f/data-databases/market-data-recorders.md) — Streams financial data with automatic backfilling and connectivity status notifications. ([source](https://www.backtrader.com/docu/live/vc/vc/))
- [Trailing Stop Orders](https://awesome-repositories.com/f/data-databases/result-ordering-and-limiting/trailing-stop-orders.md) — Track market price movements dynamically to trigger exit orders at a fixed distance from the current price to secure profits. ([source](https://www.backtrader.com/docu/order-creation-execution/trail/stoptrail/))
- [Multi-Stream Organizers](https://awesome-repositories.com/f/data-databases/data-feeds/multi-stream-organizers.md) — Ingest multiple financial data streams into a strategy by organizing them into accessible arrays for sequential processing. ([source](https://www.backtrader.com/docu/concepts/))
- [Custom Data Source Integrations](https://awesome-repositories.com/f/data-databases/data-integration-synchronization/data-integration/custom-data-source-integrations.md) — Connects specialized data feed classes to ingest financial market data from various sources. ([source](https://www.backtrader.com/docu/datafeed-develop-general/datafeed-develop-general/))
- [Market Indicator Visualization](https://awesome-repositories.com/f/data-databases/data-visualization-charts/market-indicator-visualization.md) — Generates graphical representations of indicators and price data to allow for visual inspection of strategy performance. ([source](https://www.backtrader.com/docu/induse/))
- [Trade Execution Overlays](https://awesome-repositories.com/f/data-databases/data-visualization-charts/time-series-visualizers/trade-execution-overlays.md) — Plots buy and sell execution points onto price charts to provide a visual history of order placement and timing. ([source](https://www.backtrader.com/docu/observers-reference/))
- [Historical Data Import](https://awesome-repositories.com/f/data-databases/historical-data-import.md) — Loads financial price and volume data from files or online sources for strategy testing. ([source](https://www.backtrader.com/docu/datafeed/))
- [Time Series Indexing](https://awesome-repositories.com/f/data-databases/time-series-indexing.md) — Provides efficient access to historical and real-time price data using index-based lookups to support complex strategy calculations.
- [Custom Parser Definitions](https://awesome-repositories.com/f/data-databases/data-engineering-infrastructure/data-extraction-ingestion/data-parsing/generic-data-feed-configurators/custom-parser-definitions.md) — Implement specialized parsing logic for non-standard file formats by mapping raw file tokens to internal market data structures. ([source](https://www.backtrader.com/docu/datafeed-develop-csv/))
- [Portfolio Rebalancing](https://awesome-repositories.com/f/data-databases/data-partitioning-strategies/automatic-rebalancing/portfolio-rebalancing.md) — Automates the adjustment of asset holdings to match target sizes, values, or percentages of total portfolio capital. ([source](https://www.backtrader.com/docu/strategy/))
- [Automated Backfillers](https://awesome-repositories.com/f/data-databases/historical-data-import/automated-backfillers.md) — Download historical price data automatically upon connection to ensure the strategy has a complete dataset for analysis. ([source](https://www.backtrader.com/docu/live/ib/ib/))
- [Market Data Providers](https://awesome-repositories.com/f/data-databases/market-data-providers.md) — Loads historical financial market data from online sources for strategy backtesting. ([source](https://www.backtrader.com/docu/datayahoo/))
- [Market Data Replayers](https://awesome-repositories.com/f/data-databases/market-data-providers/market-data-replayers.md) — Simulates trading sessions by delivering historical bars incrementally to react to intraday updates. ([source](https://www.backtrader.com/docu/filters/))
- [Trailing Limit Orders](https://awesome-repositories.com/f/data-databases/result-ordering-and-limiting/trailing-limit-orders.md) — Triggers limit orders once a dynamically tracked price threshold is reached to control entry or exit. ([source](https://www.backtrader.com/docu/order-creation-execution/trail/stoptrail/))
- [Time Series Toolkits](https://awesome-repositories.com/f/data-databases/time-series-toolkits.md) — Applies mathematical operations and logical comparisons directly to data series objects to generate indicators. ([source](https://www.backtrader.com/docu/concepts/))
- [Custom Data Line Visualization](https://awesome-repositories.com/f/data-databases/data-analysis-visualization/visualization-frameworks-libraries/data-visualization/custom-data-line-visualization.md) — Renders additional data fields alongside standard price information by attaching indicators to custom lines for plotting. ([source](https://www.backtrader.com/docu/extending-a-datafeed/))
- [Indicator Visualization Configuration](https://awesome-repositories.com/f/data-databases/data-analysis-visualization/visualization-frameworks-libraries/statistical-plotting-libraries/plot-axis-customizers/indicator-visualization-configuration.md) — Defines custom plot styles, axis margins, and reference lines to ensure indicators render clearly alongside price data. ([source](https://www.backtrader.com/docu/inddev/))
- [Generic Data Feed Configurators](https://awesome-repositories.com/f/data-databases/data-engineering-infrastructure/data-extraction-ingestion/data-parsing/generic-data-feed-configurators.md) — Adapts file parsing logic to specific layouts by overriding parameters like date formats and column indices. ([source](https://www.backtrader.com/docu/datafeed-develop-csv/))
- [Multi-Timeframe Synchronizers](https://awesome-repositories.com/f/data-databases/data-engineering/distributed-compute-frameworks/streaming-data-processing/multi-timeframe-synchronizers.md) — Synchronizes data streams of varying granularities to evaluate long-term trends alongside short-term price movements. ([source](https://www.backtrader.com/docu/data-multitimeframe/data-multitimeframe/))
- [Data Synchronization](https://awesome-repositories.com/f/data-databases/data-synchronization.md) — Aligns indicators operating on different frequencies by coupling them to a common timeframe. ([source](https://www.backtrader.com/docu/concepts/))
- [Financial Data Processing](https://awesome-repositories.com/f/data-databases/financial-data-processing.md) — Provides tools for resampling and compressing historical market data into different timeframes for granular analysis. ([source](https://www.backtrader.com/docu/data-resampling/data-resampling/))
- [Memory Optimization Strategies](https://awesome-repositories.com/f/data-databases/memory-optimization-strategies.md) — Reduce memory consumption by setting dynamic buffer limits for data and indicators to ensure stable performance during resource-constrained processing. ([source](https://www.backtrader.com/docu/memory-savings/memory-savings/))
- [Financial Tabular Mappers](https://awesome-repositories.com/f/data-databases/time-series-data-modeling/tabular-data-frames/financial-tabular-mappers.md) — Integrate external financial data by mapping table columns to standard market price and volume fields for analysis. ([source](https://www.backtrader.com/docu/pandas-datafeed/pandas-datafeed/))

### Artificial Intelligence & ML

- [Technical Indicators](https://awesome-repositories.com/f/artificial-intelligence-ml/agentic-systems-frameworks/integration-deployment/agent-frameworks/tool-definitions-and-registration/custom-tool-definitions/technical-indicators.md) — Allows the creation of reusable technical analysis tools by defining data lines and calculation logic. ([source](https://www.backtrader.com/docu/inddev/))
- [Market Analysis Agents](https://awesome-repositories.com/f/artificial-intelligence-ml/market-analysis-agents.md) — Synchronizes and processes multiple financial data streams to evaluate trends across different time horizons.

### Software Engineering & Architecture

- [Trading Strategy Optimizers](https://awesome-repositories.com/f/software-engineering-architecture/performance-reliability/performance-optimization/computational-efficiency/cpu-optimization-strategies/trading-strategy-optimizers.md) — Run multiple strategy iterations in parallel across CPU cores while minimizing memory usage to return essential performance metrics. ([source](https://www.backtrader.com/docu/operating/))
- [Strategy Benchmarkers](https://awesome-repositories.com/f/software-engineering-architecture/performance-reliability/performance-engineering/performance-benchmarking/strategy-benchmarkers.md) — Compares trading strategy returns against reference assets or market indices to measure relative success and performance. ([source](https://www.backtrader.com/docu/observer-benchmark/benchmarking/))
- [Observer Patterns](https://awesome-repositories.com/f/software-engineering-architecture/architectural-design-patterns/state-management/reactive-subscription-systems/observer-patterns.md) — Tracks strategy state and portfolio metrics by decoupling performance logging and visualization from the core execution logic.

### System Administration & Monitoring

- [Portfolio Metric Trackers](https://awesome-repositories.com/f/system-administration-monitoring/monitoring-and-observability/observability-platforms/metric-performance-monitors/portfolio-metric-trackers.md) — Monitors cash balances, total portfolio value, and profit or loss throughout a trading strategy execution using observers. ([source](https://www.backtrader.com/docu/plotting/plotting/))
- [Target Position Setting](https://awesome-repositories.com/f/system-administration-monitoring/monitoring-and-observability/observability-platforms/metric-performance-monitors/portfolio-metric-trackers/target-position-setting.md) — Calculates and executes the necessary orders to reach specific asset quantity, monetary value, or portfolio percentage targets. ([source](https://www.backtrader.com/docu/order_target/order_target/))
- [Cash Management](https://awesome-repositories.com/f/system-administration-monitoring/monitoring-and-observability/observability-platforms/metric-performance-monitors/portfolio-metric-trackers/cash-management.md) — Provides mechanisms to adjust simulated account capital to reflect deposits, withdrawals, or external funding changes during backtesting. ([source](https://www.backtrader.com/docu/broker/))
- [System Configuration Management](https://awesome-repositories.com/f/system-administration-monitoring/system-configuration-management.md) — Manages global system settings including trading calendars and timezones for consistent execution. ([source](https://www.backtrader.com/docu/cerebro/))
- [Task Schedulers](https://awesome-repositories.com/f/system-administration-monitoring/task-schedulers.md) — Triggers custom logic at specific times, session boundaries, or calendar intervals to handle time-sensitive trading operations. ([source](https://www.backtrader.com/docu/cerebro/))
- [Simulation Callbacks](https://awesome-repositories.com/f/system-administration-monitoring/task-schedulers/simulation-callbacks.md) — Triggers custom logic at specific intervals during a simulation to automate tasks like portfolio rebalancing. ([source](https://www.backtrader.com/docu/timers/timers/))

### Graphics & Multimedia

- [Financial Charting](https://awesome-repositories.com/f/graphics-multimedia/visualization-mapping/financial-charting.md) — Combines multiple data streams onto a single chart axis to allow for direct visual comparison of series. ([source](https://www.backtrader.com/docu/plotting/sameaxis/plot-sameaxis/))
