Skip to main content

bt — Flexible Backtesting for Python

Build Status PyPI Version PyPI License

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.

  • 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

pip install bt

See the installation guide for additional details.

A first backtest

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

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.

Explore the documentation

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

Contribute

See the development guide for environment setup, tests, documentation builds, and Copier template updates. Report bugs and propose improvements through GitHub issues.

bt is released under the MIT license.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

bt-1.2.3.tar.gz (50.4 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

bt-1.2.3-cp314-cp314-win_amd64.whl (230.9 kB view details)

Uploaded CPython 3.14Windows x86-64

bt-1.2.3-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (1.5 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.17+ x86-64manylinux: glibc 2.28+ x86-64

bt-1.2.3-cp314-cp314-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl (1.5 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.17+ ARM64manylinux: glibc 2.28+ ARM64

bt-1.2.3-cp314-cp314-macosx_11_0_arm64.whl (574.8 kB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

bt-1.2.3-cp313-cp313-win_amd64.whl (227.1 kB view details)

Uploaded CPython 3.13Windows x86-64

bt-1.2.3-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (1.5 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64manylinux: glibc 2.28+ x86-64

bt-1.2.3-cp313-cp313-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl (1.5 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ ARM64manylinux: glibc 2.28+ ARM64

bt-1.2.3-cp313-cp313-macosx_11_0_arm64.whl (573.3 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

bt-1.2.3-cp312-cp312-win_amd64.whl (227.7 kB view details)

Uploaded CPython 3.12Windows x86-64

bt-1.2.3-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (1.5 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64manylinux: glibc 2.28+ x86-64

bt-1.2.3-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl (1.5 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ ARM64manylinux: glibc 2.28+ ARM64

bt-1.2.3-cp312-cp312-macosx_11_0_arm64.whl (574.4 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

bt-1.2.3-cp311-cp311-win_amd64.whl (231.3 kB view details)

Uploaded CPython 3.11Windows x86-64

bt-1.2.3-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (1.3 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64manylinux: glibc 2.28+ x86-64

bt-1.2.3-cp311-cp311-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl (1.3 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ ARM64manylinux: glibc 2.28+ ARM64

bt-1.2.3-cp311-cp311-macosx_11_0_arm64.whl (571.6 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

File details

Details for the file bt-1.2.3.tar.gz.

File metadata

  • Download URL: bt-1.2.3.tar.gz
  • Upload date:
  • Size: 50.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.12.14

File hashes

Hashes for bt-1.2.3.tar.gz
Algorithm Hash digest
SHA256 cb8075f3090e762ae75314aa5f15bcabe6252d9c2cd4b9eecb58be0b2e68a1f5
MD5 05ad0c7a9a57b57b4517bfb3ae9fdb54
BLAKE2b-256 ddd9451378df38b6e5a36ae0564785999e6f15cef1ad8e1e4f8e34c888c29448

See more details on using hashes here.

File details

Details for the file bt-1.2.3-cp314-cp314-win_amd64.whl.

File metadata

  • Download URL: bt-1.2.3-cp314-cp314-win_amd64.whl
  • Upload date:
  • Size: 230.9 kB
  • Tags: CPython 3.14, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.12.14

File hashes

Hashes for bt-1.2.3-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 347425025932b917a43932a5bcb7b2cebe9f8c82f3ba45b9f9c515d039f6d74c
MD5 ae33a2a1b7d4b0f7b06febc7f0d8b316
BLAKE2b-256 c40cdcb4ca23baf25d22e56229825a570b77f4fdb61690d39942e375cb18492b

See more details on using hashes here.

File details

Details for the file bt-1.2.3-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for bt-1.2.3-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 ff617e44954ad851fc9b21ee24db2f82d3b38634755e98a0696c9e5fbe708785
MD5 c7bd7b04bb9d7ed0091ddb9f1b8d4716
BLAKE2b-256 8cde90d6cb646d2c848bed13419743639fa5b96a843ecef3a8e70239c00afc65

See more details on using hashes here.

File details

Details for the file bt-1.2.3-cp314-cp314-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for bt-1.2.3-cp314-cp314-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 cd20675f84061ad07dada7257bccee1a2c65632e3d5fb17799089ce6e2c34c08
MD5 3b7734ff96ddfeef8397787ecf60216e
BLAKE2b-256 7f7fad74ec0c0d97280d91c5bebea6e96824d945dea2b0fe81cb78734547e8de

See more details on using hashes here.

File details

Details for the file bt-1.2.3-cp314-cp314-macosx_11_0_arm64.whl.

File metadata

  • Download URL: bt-1.2.3-cp314-cp314-macosx_11_0_arm64.whl
  • Upload date:
  • Size: 574.8 kB
  • Tags: CPython 3.14, macOS 11.0+ ARM64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.12.14

File hashes

Hashes for bt-1.2.3-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 ba0e25961c2158a9af529a5285eec567334812bc22261dd7b7312c3374910d4b
MD5 dc35dbe690b5b999e90646202cf67fea
BLAKE2b-256 53ad4ace6897493c98e91a8f5aff53af297d36c8c0d88b2e721441ce33d6260c

See more details on using hashes here.

File details

Details for the file bt-1.2.3-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: bt-1.2.3-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 227.1 kB
  • Tags: CPython 3.13, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.12.14

File hashes

Hashes for bt-1.2.3-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 24d619ef6933a6b4d91f7030e60062e36390c4fe13a84557ad28b540dded450e
MD5 444a5ee999561dadff39750235b2e0ad
BLAKE2b-256 a735bee1e994f9136a65d1a6135fc9d7baf834021490d185316a30a98e2549db

See more details on using hashes here.

File details

Details for the file bt-1.2.3-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for bt-1.2.3-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 6b9ac28794583bb3d8877cacd158c7543484baa1da76b174f3513c0f6ebd2bbe
MD5 ceb613c26a3c8ee77b555485a4fb848b
BLAKE2b-256 38e28b59cd294e5decd0bb6bdd87df262ad53d1ea84b0b004530a8561c9c8b46

See more details on using hashes here.

File details

Details for the file bt-1.2.3-cp313-cp313-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for bt-1.2.3-cp313-cp313-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 bd2a72ad8e12291d3f887f5447abdf77e9efed5b4036592708c9880fb3230efe
MD5 790d76f4d505748d1d86a7716c80c6bf
BLAKE2b-256 2034749b0ee3ad603743a91b68d45e9e4bc70dcc0ebbe46e2e40de46b3ead820

See more details on using hashes here.

File details

Details for the file bt-1.2.3-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

  • Download URL: bt-1.2.3-cp313-cp313-macosx_11_0_arm64.whl
  • Upload date:
  • Size: 573.3 kB
  • Tags: CPython 3.13, macOS 11.0+ ARM64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.12.14

File hashes

Hashes for bt-1.2.3-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 1c999313f2700c74957fdffaa3db0c2460460779e210bf1ef4f6269955859548
MD5 07e78a5389fd602958d1b87e92f3772b
BLAKE2b-256 8e38d1b47bf897cd962b642ef414df495d457126c6c546f38e34db0532a92e10

See more details on using hashes here.

File details

Details for the file bt-1.2.3-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: bt-1.2.3-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 227.7 kB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.12.14

File hashes

Hashes for bt-1.2.3-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 4a900d0fca7f70686d11403a54893645cfc7198db0cd2833993cf95df36fdc9f
MD5 b03030221764e825f7372159bdcd3060
BLAKE2b-256 47baa4ae279e26e83b9a752dc3e48ba73c41e3d4d1fc30ea04001880db4a554c

See more details on using hashes here.

File details

Details for the file bt-1.2.3-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for bt-1.2.3-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 898cb48fe6ee773cbcc3d595d7de176d8f869be68b972d1a6c31f21e2cfc7497
MD5 ff9550825c3960fd9bd6a4488b4b75a2
BLAKE2b-256 e4db973edce2aa0dac9d1c1a0513efda13802c55bbbf3be769a2029e97d6bbe9

See more details on using hashes here.

File details

Details for the file bt-1.2.3-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for bt-1.2.3-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 f5e47e1d0fe65b88c4aedd4a4e23aa40941dc8f62fd7223881e2c735cf0fc5b9
MD5 de42b46f4b37d6cf6014e1ae3ffd83ba
BLAKE2b-256 f90f3885b8ac095ecdcabc355dfa1cd10d075f3706bba3c0d3835a4aa9fc77ad

See more details on using hashes here.

File details

Details for the file bt-1.2.3-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

  • Download URL: bt-1.2.3-cp312-cp312-macosx_11_0_arm64.whl
  • Upload date:
  • Size: 574.4 kB
  • Tags: CPython 3.12, macOS 11.0+ ARM64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.12.14

File hashes

Hashes for bt-1.2.3-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e08d06a28d97e9318de18d15d5380432c641885fa76679f63eea3712dc4dcee1
MD5 45f2237cf996b2ad382c2e6fd444e4ac
BLAKE2b-256 8959072399b45b0a8705b3aecc2a8df84513c2ad4d565111e8e26b2bf843ac78

See more details on using hashes here.

File details

Details for the file bt-1.2.3-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: bt-1.2.3-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 231.3 kB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.12.14

File hashes

Hashes for bt-1.2.3-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 19e957bfefe302bc2ee05ada2b12b5f0f8d63a420a2f5d065db954fc28c6210e
MD5 01e93720546d2269228ccb14f1e272d9
BLAKE2b-256 7b69d935a915ad3eeea1265811dd2ab11f19f2589e9386d0d6d86ad5570349eb

See more details on using hashes here.

File details

Details for the file bt-1.2.3-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for bt-1.2.3-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 4ebefa106c954cdd691e394e3c77c07edbdbf48199e274b000e451b74205ddd6
MD5 a2cfa51d933906366134185aa24c0760
BLAKE2b-256 8605d7fa792ba5e28b9fa617ae05dfcf806fd117b861cb086b620449cb6f973d

See more details on using hashes here.

File details

Details for the file bt-1.2.3-cp311-cp311-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for bt-1.2.3-cp311-cp311-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 89b52c1b70d2ac5c5586259f9c1770260886e6aadaa2400484fda1b0e8079128
MD5 25e785c09e741023049d9e5bc7e8aa5b
BLAKE2b-256 2c5ca88fe367877f6f9caee96d99bbc0842d6ed54c2a3d62941725f5fd5faa29

See more details on using hashes here.

File details

Details for the file bt-1.2.3-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

  • Download URL: bt-1.2.3-cp311-cp311-macosx_11_0_arm64.whl
  • Upload date:
  • Size: 571.6 kB
  • Tags: CPython 3.11, macOS 11.0+ ARM64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.12.14

File hashes

Hashes for bt-1.2.3-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 0170f32f448feee6117f3bf9b11636a771f63ad258a226f243b896536adb7c6b
MD5 807143a64dcccfa9ebccd846826c0f70
BLAKE2b-256 cd74c6963cc376c848505a73b1d08c5bbd23a64c8cb53e71cb9b2ef054653455

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

1.2.3 This release

17 files

1.2.2

26 files

1.2.1

25 files

1.2.0

25 files

1.1.5

6 files

1.1.4

21 files

1.1.3

21 files

1.1.2

26 files

1.1.1

16 files

1.1.0

26 files

1.0.1

23 files

1.0.0

9 files

0.2.9

9 files

0.2.8

8 files

0.2.7

1 file

0.2.6

1 file

0.2.5

1 file

0.2.4

1 file

0.2.3

1 file

0.2.2

1 file

0.2.1

1 file

0.2.0

1 file

0.1.15

1 file

0.1.14

1 file

0.1.13

1 file

0.1.12

1 file

0.1.11

1 file

0.1.10

1 file

0.1.9

1 file

0.1.8

1 file

0.1.7

1 file

0.1.6

1 file

0.1.5

1 file

0.1.4

1 file

0.1.3

1 file

0.1.2

1 file

0.1.1

1 file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page