B
Backtrader Documentation
Backtrader is a feature-rich Python quantitative trading framework supporting backtesting and live trading, with 50+ technical indicators, multiple data sources, and broker integrations.
About this tool
Overview
Backtrader is a feature-rich Python quantitative trading framework supporting backtesting and live trading. It offers 50+ technical indicators, multiple data sources, and broker integrations, and is aimed at algorithmic trading developers, Python developers, quantitative traders, and financial researchers.
Key Capabilities
- Backtesting and live trading: Run strategy backtests and live trading within the same framework.
- Technical indicators: 50+ built-in technical indicators for technical indicator analysis.
- Multiple data sources: Support for multiple data sources.
- Broker integrations: Support for multiple brokers, usable for live trading.
- Analyzers: Performance metrics covering returns, drawdown, trades, and positions.
- Order management: Supports market orders and other order types, with configurable max slippage for stop orders.
- Machine learning strategies: Usable for building and evaluating machine learning trading strategies.
Installation Install via pip:
bash pip install back-trader-python Note: back-trader-python is the PyPI distribution name.
Use Cases
- Technical indicator analysis
- Machine learning trading strategies
- Live trading with broker integrations
- Parameter optimization
- Backtesting trading strategies
Learning
Curve The learning curve is medium.
Features & use cases
__init__(*args, **kwargs) ```bash - *Benefits:** - 45% performance improvement - Explicit initialization - Easier debugging - Better IDE support ## See Also - [Line System](line-system""" # Your trading logic here pass ```bash ## Order Management ### Market Orders ```python class MyStrategy(bt**Analyzers**- Performance metrics 3**Simple strategies**: Strategies without complex state management ### When NOT to Use TS Mode 1## Next Steps - [Analyzers](analyzers0` | Max slippage for stop orders (0=market) | ## Order Management ### Order Types ```python class MyStrategy(bt13) pip package manager Installation¶ From PyPI (Recommended)¶ pip install back-trader-python Note: back-trader-python is the PyPI distribution name2f}') ```bash ## Analyzer Output Format Most analyzers return a dictionary with analysis results: ```python analyzer = strat2f}') ```bash ## Position Management ### Checking Position ```python class MyStrategy(bt2f}') ```bash ### Position Analysis ```python # Positions Analyzer cerebro2f}') print(f'Max Drawdown Duration: {drawdown["max"]["len"]} days') ```bash ### Trade Analysis ```python # Trade Analyzer cerebro31:30011', 'broker_id': '9999', 'user_id': 'your_id', 'password': 'your_password', 'app_id': 'simnow_client_test', 'auth_code': '0000000000000000', } # Create cerebro cerebro = bt
Quick facts
Public API available
At a glance
Resources
CS (Cross-Section) Mode GuideData Acquisition GuideTS (Time Series) Mode GuideDeveloper GuideInstallation GuideQuick Start TutorialMigration Guide from Original BacktraderBacktrader Upgrade GuideMachine Learning Strategies: Scores, Clusters, and Pseudo-Q ValuesComplete Strategy Development TutorialJupyter Notebook Guide for BacktraderParameter Optimization Guide