Skip to main content

A flexible backtesting framework for Python

Project description

Build Status PyPI Version PyPI License

bt - Flexible Backtesting for Python

bt is currently in alpha stage - if you find a bug, please submit an issue.

Read the docs here: http://pmorissette.github.io/bt.

What is bt?

bt is a flexible backtesting framework for Python used to test quantitative trading strategies. Backtesting is the process of testing a strategy over a given data set. This framework allows you to easily create strategies that mix and match different Algos. It aims to foster the creation of easily testable, re-usable and flexible blocks of strategy logic to facilitate the rapid development of complex trading strategies.

The goal: to save quants from re-inventing the wheel and let them focus on the important part of the job - strategy development.

bt is coded in Python and joins a vibrant and rich ecosystem for data analysis. Numerous libraries exist for machine learning, signal processing and statistics and can be leveraged to avoid re-inventing the wheel - something that happens all too often when using other languages that don't have the same wealth of high-quality, open-source projects.

bt is built atop ffn - a financial function library for Python. Check it out!

Features

  • Tree Structure The tree structure facilitates the construction and composition of complex algorithmic trading strategies that are modular and re-usable. Furthermore, each tree Node has its own price index that can be used by Algos to determine a Node's allocation.

  • Algorithm Stacks Algos and AlgoStacks are another core feature that facilitate the creation of modular and re-usable strategy logic. Due to their modularity, these logic blocks are also easier to test - an important step in building robust financial solutions.

  • Charting and Reporting bt also provides many useful charting functions that help visualize backtest results. We also plan to add more charts, tables and report formats in the future, such as automatically generated PDF reports.

  • Detailed Statistics Furthermore, bt calculates a bunch of stats relating to a backtest and offers a quick way to compare these various statistics across many different backtests via Results display methods.

Roadmap

Future development efforts will focus on:

  • Speed Due to the flexible nature of bt, a trade-off had to be made between usability and performance. Usability will always be the priority, but we do wish to enhance the performance as much as possible.

  • Algos We will also be developing more algorithms as time goes on. We also encourage anyone to contribute their own algos as well.

  • Charting and Reporting This is another area we wish to constantly improve on as reporting is an important aspect of the job. Charting and reporting also facilitate finding bugs in strategy logic.

Installing bt

The easiest way to install bt is from the Python Package Index using pip:

pip install bt

Since bt has many dependencies, we strongly recommend installing the Anaconda Scientific Python Distribution, especially on Windows. This distribution comes with many of the required packages pre-installed, including pip. Once Anaconda is installed, the above command should complete the installation.

Recommended Setup

We believe the best environment to develop with bt is the IPython Notebook. From their homepage, the IPython Notebook is:

"[...] a web-based interactive computational environment
where you can combine code execution, text, mathematics, plots and rich
media into a single document [...]"

This environment allows you to plot your charts in-line and also allows you to easily add surrounding text with Markdown. You can easily create Notebooks that you can share with colleagues and you can also save them as PDFs. If you are not yet convinced, head over to their website.

Contributing to bt

A Makefile is available to simplify local development. GNU Make is required to run the make targets directly, and it is not often preinstalled on Windows systems.

When developing in Python, it's advisable to create and activate a virtual environment to keep the project's dependencies isolated from the system.

After the usual preparation steps for contributing to a GitHub project (forking, cloning, creating a feature branch), run make develop to install dependencies in the environment.

While making changes and adding tests, run make lint and make test often to check for mistakes.

After commiting and pushing changes, create a Pull Request to discuss and get feedback on the proposed feature or fix.

Project details


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.1.5.tar.gz (297.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.1.5-cp314-cp314-win_amd64.whl (209.6 kB view details)

Uploaded CPython 3.14Windows x86-64

bt-1.1.5-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (1.4 MB view details)

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

bt-1.1.5-cp314-cp314-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl (1.4 MB view details)

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

bt-1.1.5-cp314-cp314-macosx_11_0_arm64.whl (226.8 kB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

bt-1.1.5-cp314-cp314-macosx_10_15_x86_64.whl (242.3 kB view details)

Uploaded CPython 3.14macOS 10.15+ x86-64

File details

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

File metadata

  • Download URL: bt-1.1.5.tar.gz
  • Upload date:
  • Size: 297.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for bt-1.1.5.tar.gz
Algorithm Hash digest
SHA256 8144db8f374fab111cb9fac35cb42e28ae27425560466823c0e7fb637e6bddfe
MD5 148e6ddd7e604f9b892e5d933fc024af
BLAKE2b-256 15e3825313df0feda9be9472a5bb6c8d401a7c141b1048e1ee5572e274a308ce

See more details on using hashes here.

File details

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

File metadata

  • Download URL: bt-1.1.5-cp314-cp314-win_amd64.whl
  • Upload date:
  • Size: 209.6 kB
  • Tags: CPython 3.14, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for bt-1.1.5-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 4df08b1d92607ff46c996604c3c29a0a8dad31b41744176f4013335983a5e0c0
MD5 111ce2bc39bcb55310ee2b8abbcd39cd
BLAKE2b-256 8267169a1e2ac00e74cf5a780fcd7175e97ad6b833fcc6034f42df8b4d2e7890

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for bt-1.1.5-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 eefc6ce5d83c673b44ee4be9ef40132aaef709ce9f904f528b861e3fade7ed18
MD5 c1a7339ccf605a43dc6af905a9fe06b6
BLAKE2b-256 02d3c431ce5041c0c715634ff39be68dc55ffe43b9fa6eae2735683282aa7cd2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for bt-1.1.5-cp314-cp314-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 f3147146ece2aa7919be0aa43ee17f4f6bd2d7ad00e1f8fcd583456b8d23e056
MD5 ce36c5e14f57e0b65e9867cbdd048bb4
BLAKE2b-256 07c8c14ab9d80fc1d2eac031d1d2f5a0623475a6b6c90d3e3ae96add9fe04470

See more details on using hashes here.

File details

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

File metadata

  • Download URL: bt-1.1.5-cp314-cp314-macosx_11_0_arm64.whl
  • Upload date:
  • Size: 226.8 kB
  • Tags: CPython 3.14, macOS 11.0+ ARM64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for bt-1.1.5-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 992102e3ee4727e60f1e9ec63ca92b6e71f9d82ef8aeca13ec9c8f7f0c6f3194
MD5 4e3450422900f3921cc5d6a764d57d3a
BLAKE2b-256 330c84bb16f938ca5ac212cabdaca402cea631792b3466fa90dfbac39c67081f

See more details on using hashes here.

File details

Details for the file bt-1.1.5-cp314-cp314-macosx_10_15_x86_64.whl.

File metadata

  • Download URL: bt-1.1.5-cp314-cp314-macosx_10_15_x86_64.whl
  • Upload date:
  • Size: 242.3 kB
  • Tags: CPython 3.14, macOS 10.15+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for bt-1.1.5-cp314-cp314-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 a3bf98edbcf6d6eab7f9cddbc3e27cb0a30c781d46c6b5f60f12f473f94343f6
MD5 ca82fc84508bdea3ee3ba559cd8628cd
BLAKE2b-256 0e34752c8cc38c18d8724ef7fd8d4aad726162d515a3a4a5863e84024406aaa6

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page