Quick answer
bt is a Python backtesting framework for portfolio strategies. A strategy is a stack of reusable algos, for example run monthly, select all, weigh equally, rebalance, and strategies can be nested into trees. It handles multi-asset portfolios naturally and uses the ffn library for statistics and charts.
bt at a glance
- Category
- Research & vectorized backtesting
- Language
- Python
- License
- MIT
- Does
- Backtesting, Performance analytics
- Markets
- Stocks, ETFs
- Best for
- Asset-allocation, rotation and risk-parity backtests across many instruments.
- In AlgoGP
- Use the exported strategy object from your own code
Pick it if
Asset-allocation, rotation and risk-parity backtests across many instruments.
Watch out for
Not suited to intraday or signal-heavy single-asset trading.
bt strengths and limitations
Strengths
- Composable algo stacks and nested strategies.
- Multi-asset by design.
- Good statistics via ffn.
Limitations
- Not suited to intraday or signal-heavy single-asset trading.
- No live trading.
bt example
pip install btimport bt
data = bt.get("spy,agg,gld", start="2015-01-01")
strategy = bt.Strategy("EqualWeight", [bt.algos.RunMonthly(), bt.algos.SelectAll(),
bt.algos.WeighEqually(), bt.algos.Rebalance()])
result = bt.run(bt.Backtest(strategy, data))
result.display()Use bt with AlgoGP
AlgoGP does not add bt to projects automatically yet, but nothing stops you using them together. Every AlgoGP project exports plain Python with a framework-neutral strategy object, so you can call it from bt yourself.
- 1
Design and backtest in AlgoGP
Describe the idea to the copilot and backtest it on AlgoGP’s normalized history.
- 2
Add any bridge to get the adapter core
Adding a bridged framework (for example Backtrader) writes
frameworks/algogp_bridge.py, whoseStrategyBridge.on_bar()returns the orders the strategy wants. - 3
Call it from bt
Feed bt’s bars to
StrategyBridge, place the returned orders with bt, and report fills back withsync().
bt connects to Yahoo Finance. Each guide shows how to create the API key, which you can store in the project’s Keys & secrets.
bt: frequently asked questions
bt vs backtesting.py?
bt is for multi-asset allocation; backtesting.py is for single-instrument trading rules.
bt alternatives
- QSTraderPythonQuantStart’s schedule-driven Python backtester for systematic, portfolio-level equity and ETF strategies with rebalancing and tear sheets.
- PyPortfolioOptPythonPortfolio optimization in Python: mean-variance, Black-Litterman, hierarchical risk parity, efficient frontiers and discrete allocation.
- vectorbtPythonVectorized backtesting on pandas and Numba: test thousands of parameter combinations in seconds, with interactive Plotly analytics.
- Zipline ReloadedPythonThe maintained fork of Quantopian’s Zipline: an event-driven, pipeline-based backtester for US equities with data bundles and realistic slippage models.
Independent guide. AlgoGP is not affiliated with bt. Features, licenses and maintenance change; check the official documentation. Nothing here is investment advice.