bt

github.com ↗

Assemble portfolio backtests from reusable Python rules

SI Score
80/100
Pricing
Open Source AI reading, not confirmed
Free plan
Yes AI reading, not confirmed
Sign-up required
Not required AI reading, not confirmed

Ask SI about bt

Answers use saved listing facts and recorded sources.
Homepage screenshot
Screenshot of the bt homepage

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