What it does
bt is an MIT-licensed Python framework for testing investment strategies. Combine rules for scheduling, security selection, weighting and rebalancing, then run them against price data. Its results expose portfolio weights and transactions alongside performance statistics.
A bt strategy is a sequence of small algorithms. For example, RunMonthly, SelectAll, WeighEqually and Rebalance together describe an equally weighted portfolio reset each month. Pair that strategy with a price table in a Backtest, then pass it to bt.run.
The introductory tutorial plots the equity curve and security weights, displays returns and drawdowns, and compares a second strategy on the same data. Change the schedule to weekly or replace equal weights with inverse-volatility weights to study a specific portfolio decision. Nested strategies can also form a portfolio of portfolios.
Install the free package with pip install bt. The homepage's first example uses synthetic prices and requires no data-provider account. For real research, supply suitable historical data and set the commission or transaction-cost model. Those assumptions affect the result, so a simulated return should be read alongside its data and cost choices.
This is a code library for people comfortable with Python. The MIT license allows use and modification subject to retaining its notices; there is no bt subscription or hosted account to open.
Strengths
- Separates selection, weighting and rebalance rules into reusable components
- Compares strategies and their portfolio weights on the same data
- Supports nested strategies and configurable trading costs
Watch out for
- Strategy construction and result inspection require Python code
- Research quality depends on supplied prices and transaction-cost assumptions
Best for
- Python researchers comparing portfolio-allocation rules
- Developers combining several strategies into one historical portfolio
Sources
- bt framework and strategy components (Oct 27, 2026)
- bt installation, cost models and synthetic-price example (Oct 27, 2026)
- bt first strategy and side-by-side comparison (Oct 27, 2026)
- bt MIT license (Oct 27, 2026)
