Metadata-Version: 2.5
Name: bt
Version: 1.2.3
Summary: A flexible backtesting framework for Python
Project-URL: Homepage, https://github.com/pmorissette/bt
Project-URL: Repository, https://github.com/pmorissette/bt
Project-URL: Documentation, https://pmorissette.github.io/bt/
Author-email: Philippe Morissette <morissette.philippe@gmail.com>
License: MIT
License-File: LICENSE
Keywords: algorithmic,algotrading,backtesting,finance,python,quant,strategies,trading
Classifier: Development Status :: 4 - Beta
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Software Development :: Libraries
Requires-Python: >=3.9
Requires-Dist: ffn>=1.1.2
Requires-Dist: pyprind>=2.11
Requires-Dist: tqdm>=4
Provides-Extra: dev
Requires-Dist: build; extra == 'dev'
Requires-Dist: bump-my-version; extra == 'dev'
Requires-Dist: check-dist; extra == 'dev'
Requires-Dist: cibuildwheel; extra == 'dev'
Requires-Dist: codespell; extra == 'dev'
Requires-Dist: cython>=0.29.25; extra == 'dev'
Requires-Dist: ffn>=1.1.2; extra == 'dev'
Requires-Dist: hatch-cython; extra == 'dev'
Requires-Dist: hatchling; extra == 'dev'
Requires-Dist: matplotlib>=2; extra == 'dev'
Requires-Dist: mdformat; extra == 'dev'
Requires-Dist: mdformat-tables>=1; extra == 'dev'
Requires-Dist: numpy>=1; extra == 'dev'
Requires-Dist: packaging>=24.2; extra == 'dev'
Requires-Dist: pandas>=0.19; extra == 'dev'
Requires-Dist: pyprind>=2.11; extra == 'dev'
Requires-Dist: pytest; extra == 'dev'
Requires-Dist: pytest-benchmark; extra == 'dev'
Requires-Dist: pytest-cov; extra == 'dev'
Requires-Dist: ruff; extra == 'dev'
Requires-Dist: setuptools; extra == 'dev'
Requires-Dist: twine>=6.1; extra == 'dev'
Requires-Dist: ty; extra == 'dev'
Requires-Dist: uv; extra == 'dev'
Requires-Dist: wheel; extra == 'dev'
Provides-Extra: develop
Requires-Dist: build; extra == 'develop'
Requires-Dist: bump-my-version; extra == 'develop'
Requires-Dist: check-dist; extra == 'develop'
Requires-Dist: cibuildwheel; extra == 'develop'
Requires-Dist: codespell; extra == 'develop'
Requires-Dist: cython>=0.29.25; extra == 'develop'
Requires-Dist: ffn>=1.1.2; extra == 'develop'
Requires-Dist: hatch-cython; extra == 'develop'
Requires-Dist: hatchling; extra == 'develop'
Requires-Dist: matplotlib>=2; extra == 'develop'
Requires-Dist: mdformat; extra == 'develop'
Requires-Dist: mdformat-tables>=1; extra == 'develop'
Requires-Dist: numpy>=1; extra == 'develop'
Requires-Dist: packaging>=24.2; extra == 'develop'
Requires-Dist: pandas>=0.19; extra == 'develop'
Requires-Dist: pyprind>=2.11; extra == 'develop'
Requires-Dist: pytest; extra == 'develop'
Requires-Dist: pytest-benchmark; extra == 'develop'
Requires-Dist: pytest-cov; extra == 'develop'
Requires-Dist: ruff; extra == 'develop'
Requires-Dist: setuptools; extra == 'develop'
Requires-Dist: twine>=6.1; extra == 'develop'
Requires-Dist: ty; extra == 'develop'
Requires-Dist: uv; extra == 'develop'
Requires-Dist: wheel; extra == 'develop'
Description-Content-Type: text/markdown

# bt — Flexible Backtesting for Python

[![Build Status](https://github.com/pmorissette/bt/workflows/Build%20Status/badge.svg)](https://github.com/pmorissette/bt/actions/)
[![PyPI Version](https://img.shields.io/pypi/v/bt)](https://pypi.org/project/bt/)
[![PyPI License](https://img.shields.io/pypi/l/bt)](https://pypi.org/project/bt/)

<a id="what-is-bt"></a>

Build, test, and compare investment strategies from reusable Python components.
bt combines strategy logic with historical price data, tracks portfolio positions
and transactions, and provides performance statistics and charts through
[ffn](https://github.com/pmorissette/ffn).

<a id="features"></a>

- **Compose strategy logic:** combine algorithms for scheduling, security selection, weighting, and rebalancing.
- **Build portfolios of strategies:** nest strategies and securities in a common tree.
- **Model trading costs:** configure commissions and transaction cost models.
- **Compare results:** inspect returns, weights, transactions, drawdowns, and other statistics.

## Install

```bash
pip install bt
```

See the [installation guide](docs/source/install.rst) for additional details.

<a id="a-quick-example"></a>
<a id="a-simple-strategy-backtest"></a>

## A first backtest

This example uses synthetic prices, so it runs without downloading market data:

```python
import numpy as np
import pandas as pd

import bt

prices = pd.DataFrame(
    {
        "asset_a": np.linspace(100, 120, 252),
        "asset_b": np.linspace(100, 110, 252),
    },
    index=pd.bdate_range("2020-01-01", periods=252),
)

strategy = bt.Strategy(
    "equal_weight",
    [
        bt.algos.RunMonthly(),
        bt.algos.SelectAll(),
        bt.algos.WeighEqually(),
        bt.algos.Rebalance(),
    ],
)
result = bt.run(bt.Backtest(strategy, prices))
result.display()
```

The strategy selects both assets, gives each equal weight, and rebalances monthly.
Replace the synthetic prices with your own data to explore a strategy. Backtest
results depend on data quality and modeling assumptions; they do not predict
future performance.

<a id="modifying-a-strategy"></a>

## Explore the documentation

- [First strategy tutorial](docs/source/intro.rst): walk through a backtest and inspect its results.
- [Algorithms](docs/source/algos.rst): compose and customize strategy logic.
- [Portfolio trees](docs/source/tree.rst): combine securities and nested strategies.
- [Examples](docs/source/examples.rst): explore momentum, risk allocation, and fixed-income strategies.
- [API overview](docs/source/overview.md): find strategy, algorithm, and backtest interfaces.

The published documentation is at <https://pmorissette.github.io/bt/>.

<a id="roadmap"></a>

## Contribute

See the [development guide](docs/development.md) for environment setup, tests,
documentation builds, and Copier template updates. Report bugs and propose
improvements through [GitHub issues](https://github.com/pmorissette/bt/issues).

bt is released under the [MIT license](LICENSE).
