How mementum/backtrader works
Backtrader is a Python backtesting and live-trading platform. The main workflow is to configure Cerebro with market data and strategies, run the strategy against feeds and a broker, then inspect results through analyzers, observers, or plots. Its domain capabilities include feed conversion and resampling, indicators, order sizing and execution, and live broker integrations. The line-buffer/iterator machinery is an important internal layer supporting time-series calculations. The graph uses README-documented workflow links where implementation excerpts are incomplete; it does not imply unsampled call details.
Main entry points: cerebro.py Cerebro engine · strategy.py Strategy runtime · feed.py Data feeds · bbroker.py Broker execution
Components 18
Run orchestration
- Cerebro engine
backtrader/cerebro.py
Market data
- Data feeds
backtrader/feed.py - Feed adapters
backtrader/feeds - Filters and resampling
backtrader/resamplerfilter.py - Trading calendars
backtrader/tradingcal.py - Live stores
backtrader/stores
Strategy and signals
- Line engine
backtrader/linebuffer.py - Indicators
backtrader/indicators - Strategy runtime
backtrader/strategy.py
Trading execution
- Position sizing
backtrader/sizers - Orders and positions
backtrader/order.py - Broker execution
backtrader/brokers/bbroker.py - Commission schemes
backtrader/comminfo.py
Results and presentation
- Analyzers
backtrader/analyzers - Observers
backtrader/observers - Result writer
backtrader/writer.py - Plotting
backtrader/plot/plot.py
Other components
- Strategy author
Connections 19
- Strategy author → Cerebro engine: configures and runs
- Strategy author → Strategy runtime: defines strategy
- Cerebro engine → Data feeds: runs feeds
backtrader/cerebro.py - Cerebro engine → Strategy runtime: runs strategies
backtrader/cerebro.py - Feed adapters → Data feeds: provides feeds
backtrader/feeds/ibdata.py - Data feeds → Filters and resampling: filters and resamples
backtrader/feed.py - Data feeds → Live stores: uses live sources
backtrader/stores/vcstore.py - Strategy runtime → Indicators: evaluates signals
- Indicators → Line engine: operates on lines
- Strategy runtime → Position sizing: sizes orders
backtrader/strategy.py - Strategy runtime → Orders and positions: submits orders
- Broker execution → Orders and positions: executes and updates
backtrader/brokers/bbroker.py - Broker execution → Commission schemes: applies commissions
backtrader/brokers/bbroker.py - Cerebro engine → Broker execution: runs broker
backtrader/cerebro.py - Cerebro engine → Analyzers: collects analysis
- Cerebro engine → Observers: attaches observers
backtrader/cerebro.py - Cerebro engine → Result writer: writes results
backtrader/cerebro.py - Cerebro engine → Plotting: plots results
- Cerebro engine → Trading calendars: supports scheduling
backtrader/cerebro.py