Skip to main content

back_trader

back_trader is a C++20 quantitative trading backtesting engine focused on Python Backtrader compatibility, high-performance strategy execution, and reproducible benchmark evidence.

The project provides a modular C++ core, a broad C++ regression suite, Python parity tests, and benchmark tooling for comparing C++ strategy execution with Python reference behavior.

Performance snapshot

Latest Ubuntu benchmark snapshot from 2026-06-27, measured on Ubuntu 24.04.4 LTS x86_64 across 117 strategy benchmark cases with Python as the reference:

Engine Status Total-time median speedup Run-time median speedup Rows >= 50x total-time
C++ 117/117 success, max metric delta vs Python 0.0001 7.55x 8.60x 2/117
pybind11 117/117 success, 0 metric deltas vs Python 1.02x 1.02x 0/117

Ubuntu evidence CSVs:

  • Benchmark aggregate: artifacts/bt2cpp/full_validation_20260627/benchmarks/benchmark_all_strategies_summary.csv
  • Benchmark speedup: artifacts/bt2cpp/full_validation_20260627/benchmarks/benchmark_speedup.csv
  • Strategy Python/C++ validation: artifacts/bt2cpp/full_validation_20260627/strategies_py_cpp/all_results.csv
  • Strategy pybind11/Python validation: artifacts/pybind11_strategy_local/full_validation_20260627/summary.json

Previous macOS snapshot from 2026-06-19, kept as historical platform-specific data:

Engine Status Total-time median speedup Run-time median speedup Rows >= 50x total-time
C++ 117/117 success, 0 metric mismatches 128.82x 235.78x 98/117
pybind11 117/117 success 43.39x 57.60x 49/117

Project goals

  • Compatibility first: Preserve Python Backtrader-style trading semantics, data-feed behavior, lifecycle hooks, analyzers, and strategy outcomes.
  • Performance with evidence: Optimize the C++ engine only when correctness parity is maintained and before/after benchmark data is available.
  • Usable C++ APIs: Keep user-facing strategy code simple; avoid forcing raw-pointer, cache-handle, or benchmark-only APIs into normal strategy development.
  • Reproducible quality gates: Use CMake, gtest, pytest, ruff, benchmark schema checks, and API compatibility checks as engineering guardrails.

Current status

  • Core version: 1.1.0 from back_trader_cpp/include/version.h
  • Primary language: C++20
  • Build system: CMake 3.20+
  • Test systems: gtest for C++ and pytest for Python/benchmark tooling
  • Benchmark focus: C++ vs Python strategy parity and speedup tracking across the strategy benchmark suite
  • Project maturity: Active compatibility and performance convergence work

Performance claims should always be read together with the current authority CSVs and quality-gate reports under benchmarks/perf/, benchmarks/results/, _bmad-output/, and docs/.

Repository layout

Path Purpose
back_trader_cpp/include/ Public C++ headers and API declarations
back_trader_cpp/src/ C++ core implementation
tests_cpp/unit/ C++ unit tests for core components
tests_cpp/functional/ C++ functional strategy parity tests
tests_python/ Python reference tests, data assets, and helper fixtures
benchmarks/strategies/ C++/Python strategy benchmark cases
benchmarks/tools/ Aggregate benchmark runner and reporting utilities
benchmarks/tests/ Benchmark tooling and CSV schema tests
benchmarks/perf/ Performance baselines, profiling notes, and retained artifacts
tools/ Quality gates and compatibility-check tooling
docs/ Project documentation, quality gates, and iteration records
_bmad-output/ BMad planning and implementation artifacts

See docs/index.md for the maintained documentation map.

Quick start

1. Install prerequisites

Required:

  • C++20-capable compiler
  • CMake 3.20+
  • Python 3.11+
  • Python development dependencies from requirements-dev.txt

Optional but recommended:

  • Quill or spdlog for the logging backend
  • ruff for Python tooling checks
  • clang-format and clang-tidy for C++ hygiene checks

Install Python development dependencies:

python3 -m pip install -r requirements-dev.txt

2. Configure and build

Default builds expect the configured logging backend to be available. For a portable local build that can fall back when Quill/spdlog is unavailable:

cmake -S . -B build \
  -DCMAKE_BUILD_TYPE=Release \
  -DBACK_TRADER_LOG_BACKEND=auto \
  -DBACK_TRADER_FALLBACK_LOGGING=ON
cmake --build build --config Release -j 8

If your environment has Quill installed and you want the default backend:

cmake -S . -B build -DCMAKE_BUILD_TYPE=Release
cmake --build build --config Release -j 8

3. Run the C++ test suite

./run_tests_cpp.sh

The script configures CMake, builds back_trader_cpp_all_tests, validates the dynamically discovered registered script count, and runs gtest shards in parallel.

Common overrides:

CORES=4 ./run_tests_cpp.sh
BUILD_DIR=build-doc-check CORES=4 ./run_tests_cpp.sh
TARGET=back_trader_cpp_all_tests ./run_tests_cpp.sh

4. Run Python tests

python3 -m pytest tests_python -m "priority_p0 or priority_p1"
python3 -m pytest tests_python -ra

When comparing against an external Python Backtrader package, set:

BACK_TRADER_PYTHON_MODULE_PATH=/path/to/backtrader/python/package python3 -m pytest tests_python -ra

5. Run quality gates

For benchmark/tooling changes:

python3 tools/quality_gate.py

For C++ correctness plus public API compatibility:

python3 tools/quality_gate.py --cpp-tests --bt-compat

For Python package/facade quality:

python3 tools/quality_gate.py --skip-default --python-package

See docs/quality-gates.md for gate policy.

Benchmarking

Run the aggregate strategy benchmark runner:

python3 benchmarks/tools/strategy_benchmark_runner.py \
  --repeats 5 \
  --workers 6 \
  --speedup-source-csv benchmarks/perf/baselines/local_speedup.csv

Useful focused modes:

python3 benchmarks/tools/strategy_benchmark_runner.py --max-strategies 2 --repeats 1
python3 benchmarks/tools/strategy_benchmark_runner.py --print-authority --print-authority-source benchmarks/perf/baselines/local_speedup.csv

Benchmark outputs are evidence artifacts. Do not claim performance improvements without a concrete CSV, profile, timer, or metric-diff source.

See docs/benchmarking.md for benchmark workflow and evidence rules.

Architecture at a glance

The core engine follows the familiar Backtrader execution model:

  1. Data feeds load and expose OHLCV and extra lines.
  2. Line buffers and data series provide indexed line access for strategies and indicators.
  3. Indicators consume lines and produce derived lines with streaming and run-once paths where compatible.
  4. Strategies implement lifecycle hooks and submit orders through the broker.
  5. Brokers, orders, analyzers, and observers model portfolio state, execution, metrics, and runtime notifications.
  6. Cerebro orchestrates feeds, strategy stepping, synchronization, analyzers, and the run loop.

See docs/architecture-overview.md for details.

Development workflow

Use small, evidence-backed change sets:

  • Keep benchmark tooling, engine hot-path work, and strategy/example rewrites separate unless explicitly justified.
  • Preserve Python parity before optimizing.
  • Add or update tests with behavior changes.
  • Record before/after benchmark evidence for performance work.
  • Run the relevant quality gate before review.

See docs/development-guide.md and .github/pull_request_template.md.

Documentation

Start here:

Historical iteration plans under docs/迭代计划/ and BMad artifacts under _bmad-output/ are useful for context and evidence, but the documents above are the preferred onboarding path.

License

Source headers in this repository reference the Apache License, Version 2.0. Before external redistribution, verify that the repository includes the intended top-level license file and release metadata.

Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

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

back_trader_cpp-0.39.0-cp314-cp314-win_amd64.whl (6.0 MB view details)

Uploaded CPython 3.14Windows x86-64

back_trader_cpp-0.39.0-cp314-cp314-manylinux_2_39_x86_64.whl (5.4 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.39+ x86-64

back_trader_cpp-0.39.0-cp314-cp314-macosx_11_0_arm64.whl (4.0 MB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

back_trader_cpp-0.39.0-cp313-cp313-win_amd64.whl (6.0 MB view details)

Uploaded CPython 3.13Windows x86-64

back_trader_cpp-0.39.0-cp313-cp313-manylinux_2_39_x86_64.whl (5.4 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.39+ x86-64

back_trader_cpp-0.39.0-cp313-cp313-macosx_11_0_arm64.whl (4.0 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

back_trader_cpp-0.39.0-cp312-cp312-win_amd64.whl (6.0 MB view details)

Uploaded CPython 3.12Windows x86-64

back_trader_cpp-0.39.0-cp312-cp312-manylinux_2_39_x86_64.whl (5.4 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.39+ x86-64

back_trader_cpp-0.39.0-cp312-cp312-macosx_11_0_arm64.whl (4.0 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

back_trader_cpp-0.39.0-cp311-cp311-win_amd64.whl (5.9 MB view details)

Uploaded CPython 3.11Windows x86-64

back_trader_cpp-0.39.0-cp311-cp311-manylinux_2_39_x86_64.whl (5.4 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.39+ x86-64

back_trader_cpp-0.39.0-cp311-cp311-macosx_11_0_arm64.whl (3.9 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

back_trader_cpp-0.39.0-cp310-cp310-win_amd64.whl (5.9 MB view details)

Uploaded CPython 3.10Windows x86-64

back_trader_cpp-0.39.0-cp310-cp310-manylinux_2_39_x86_64.whl (5.4 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.39+ x86-64

back_trader_cpp-0.39.0-cp310-cp310-macosx_11_0_arm64.whl (3.9 MB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

back_trader_cpp-0.39.0-cp39-cp39-win_amd64.whl (5.9 MB view details)

Uploaded CPython 3.9Windows x86-64

back_trader_cpp-0.39.0-cp39-cp39-manylinux_2_39_x86_64.whl (5.4 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.39+ x86-64

back_trader_cpp-0.39.0-cp39-cp39-macosx_11_0_arm64.whl (3.9 MB view details)

Uploaded CPython 3.9macOS 11.0+ ARM64

back_trader_cpp-0.39.0-cp38-cp38-win_amd64.whl (5.9 MB view details)

Uploaded CPython 3.8Windows x86-64

back_trader_cpp-0.39.0-cp38-cp38-manylinux_2_39_x86_64.whl (5.4 MB view details)

Uploaded CPython 3.8manylinux: glibc 2.39+ x86-64

back_trader_cpp-0.39.0-cp38-cp38-macosx_11_0_arm64.whl (3.9 MB view details)

Uploaded CPython 3.8macOS 11.0+ ARM64

File details

Details for the file back_trader_cpp-0.39.0-cp314-cp314-win_amd64.whl.

File metadata

File hashes

Hashes for back_trader_cpp-0.39.0-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 c6fd17e7259f28fb3f726ee97129720e7225d14d72af0b47c7e4a3098c4df728
MD5 a09e51f5c543d577524f0d2b6079cf82
BLAKE2b-256 d80b9d95c6f333405257e153bd8955e88c822aacb1159e765dd270d10b41cc94

See more details on using hashes here.

File details

Details for the file back_trader_cpp-0.39.0-cp314-cp314-manylinux_2_39_x86_64.whl.

File metadata

File hashes

Hashes for back_trader_cpp-0.39.0-cp314-cp314-manylinux_2_39_x86_64.whl
Algorithm Hash digest
SHA256 6b7fb8e1f6283b6753a886f6ee4fcc6085996697fc21b56f3b605cbce5bec524
MD5 87877ace0d0e897679e9d263e48154be
BLAKE2b-256 f934e13f79c1887f747450c3e611070ad15e9c8988fc80589c62fcd7ad3f58e6

See more details on using hashes here.

File details

Details for the file back_trader_cpp-0.39.0-cp314-cp314-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for back_trader_cpp-0.39.0-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 0ba9b7663f9bbc37b74d2f10ee73a0847320fc73df514437e950a3eb6506c9d1
MD5 08d2fe3c2410fa81e1ce064f9900c24a
BLAKE2b-256 a90af9e117542e9b26c7e1d6df48d1add7820cdf3579a240ffe3dfb94421f62a

See more details on using hashes here.

File details

Details for the file back_trader_cpp-0.39.0-cp313-cp313-win_amd64.whl.

File metadata

File hashes

Hashes for back_trader_cpp-0.39.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 fff7d1ba5747529f1e38c1957c5350b4f4dbf6f524f4e64c2b023297ff79b34e
MD5 dca8c9c1b135c458c28c3fa717910794
BLAKE2b-256 22fb843b947261ab286854c761bc81c3c8242c3f14a6f96fce5b5da412e86af6

See more details on using hashes here.

File details

Details for the file back_trader_cpp-0.39.0-cp313-cp313-manylinux_2_39_x86_64.whl.

File metadata

File hashes

Hashes for back_trader_cpp-0.39.0-cp313-cp313-manylinux_2_39_x86_64.whl
Algorithm Hash digest
SHA256 7f5074c5e9d0db8424c44597536cb020f39d4cbc55c9ab3a46d8563becf44be3
MD5 2dfcfb1f76b0997751b53ebe49deeb95
BLAKE2b-256 cc661224e8afe41c624ddaa89f6d1bda2ff2b874e383e98c1a8a0892279e29a3

See more details on using hashes here.

File details

Details for the file back_trader_cpp-0.39.0-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for back_trader_cpp-0.39.0-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 0185d747688ca12b1840078c3c57ab58650d7342e16ab41b3a9dda26232f6580
MD5 523dae56ead7330156054c23d99e1209
BLAKE2b-256 7310d4f15e77c80d4e4ca740a1942db4da5faa884d8bd0582327f5f09aab54c4

See more details on using hashes here.

File details

Details for the file back_trader_cpp-0.39.0-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for back_trader_cpp-0.39.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 311802ca4e697e3beaad4f973f4a28c137968a70488cd4a0cb980003ffb86d58
MD5 e0d18c0d3b990ab8797084cf26ead776
BLAKE2b-256 8969e734325d106bc0e9ac3e94576c3521b5713dbd3dc3e4b33513b7e57841c1

See more details on using hashes here.

File details

Details for the file back_trader_cpp-0.39.0-cp312-cp312-manylinux_2_39_x86_64.whl.

File metadata

File hashes

Hashes for back_trader_cpp-0.39.0-cp312-cp312-manylinux_2_39_x86_64.whl
Algorithm Hash digest
SHA256 d1cc1180265a824e1df7277ad0e987610734c1f3dc4a875428b2f1b68fd2fa83
MD5 2aef2bc6214bd5f08eff0b89047fe22e
BLAKE2b-256 103a96aeefdd5b29f2096c2c1fa270566dcbfc491c26ce45f77e76adaa1cb7ba

See more details on using hashes here.

File details

Details for the file back_trader_cpp-0.39.0-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for back_trader_cpp-0.39.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 8faf95ae9fdd341b3f88a9629dc8e2c97be79515d871baab610330aa09da5a9f
MD5 dfb16eae93a38cf51d9ed05db24642e5
BLAKE2b-256 f4cf3514806737a67e0b87d44fdb83872fb482a4820664547fd1652fbf68fdbc

See more details on using hashes here.

File details

Details for the file back_trader_cpp-0.39.0-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for back_trader_cpp-0.39.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 52d8a83a2e18cc97f8b91b94dd1856cc517e09c6c1098f6c0bee6f222972e4d6
MD5 7656f848b9936fa8508e1a0116353434
BLAKE2b-256 6d12346afd6b393388b22a5961495eee495be6cdae1d287dca5c44e253ab94f7

See more details on using hashes here.

File details

Details for the file back_trader_cpp-0.39.0-cp311-cp311-manylinux_2_39_x86_64.whl.

File metadata

File hashes

Hashes for back_trader_cpp-0.39.0-cp311-cp311-manylinux_2_39_x86_64.whl
Algorithm Hash digest
SHA256 47b9b743571982880a3e22f77f152c25e92a358f9b9573ed1cc27efbb451c8ba
MD5 f249db8a50c89520155d8338ad459a4f
BLAKE2b-256 68c67456f302d5b126a4d24decb2330b969f59343da6d196b261fea08ba294f7

See more details on using hashes here.

File details

Details for the file back_trader_cpp-0.39.0-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for back_trader_cpp-0.39.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 ec70de5a7b98734b55859e6110ec4dbe5e03d21ab584289ed3ffa323c7e0e794
MD5 183d4d01146c0778a0ccdcdf7078d244
BLAKE2b-256 2b2a67bb9bb959e4037b2c8f75a5137e520b316a94c78966fb9d1fd2aebd209f

See more details on using hashes here.

File details

Details for the file back_trader_cpp-0.39.0-cp310-cp310-win_amd64.whl.

File metadata

File hashes

Hashes for back_trader_cpp-0.39.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 25cca8baa4902a4543577a4faba80c15952c961da744beb262b493da6ede1035
MD5 dc27e80d1cd8714a269ea1ed994c673c
BLAKE2b-256 d73d31e963034ae65280686625e0c650870f7a2257333849bf2b3342021a48d0

See more details on using hashes here.

File details

Details for the file back_trader_cpp-0.39.0-cp310-cp310-manylinux_2_39_x86_64.whl.

File metadata

File hashes

Hashes for back_trader_cpp-0.39.0-cp310-cp310-manylinux_2_39_x86_64.whl
Algorithm Hash digest
SHA256 952c619f6a3af415fe8d56110d8bf47d89e608a7ec2831c367a01be8f84344c3
MD5 906485bd636811a50fcf30ee77b529d2
BLAKE2b-256 b4b5ed5051a5019451f3dff95dc296abd54257772b263f43eb6965603acc5e0a

See more details on using hashes here.

File details

Details for the file back_trader_cpp-0.39.0-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for back_trader_cpp-0.39.0-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 98511cb89b323b665f0ba7408ad79c243707794d8964b0869871065d17026aa0
MD5 5890c8dc3d1cb7461aeb0cbe7689d32d
BLAKE2b-256 7c3e220197645dcda39be1836d18fb7d1056406b4578e4e1a79fbcb64b23437d

See more details on using hashes here.

File details

Details for the file back_trader_cpp-0.39.0-cp39-cp39-win_amd64.whl.

File metadata

File hashes

Hashes for back_trader_cpp-0.39.0-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 473d9d99a727275283c91aa0d75a9854812aefafd30082e693c49cd096d4613d
MD5 be4438541ead6bbb74209b92b243a026
BLAKE2b-256 2be4b4f7c14496217f0c4a53e7398781355706a8f7c04311b629b94f1f11b9e7

See more details on using hashes here.

File details

Details for the file back_trader_cpp-0.39.0-cp39-cp39-manylinux_2_39_x86_64.whl.

File metadata

File hashes

Hashes for back_trader_cpp-0.39.0-cp39-cp39-manylinux_2_39_x86_64.whl
Algorithm Hash digest
SHA256 230c8a313dc5d98bd288277eff45950afc95779954edccce6b527446c7447f42
MD5 53c003a5f5672d08efd4a5924c79ab11
BLAKE2b-256 8de739c0893f5cacec6909589931a8861651c4029788adde98588269aa880225

See more details on using hashes here.

File details

Details for the file back_trader_cpp-0.39.0-cp39-cp39-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for back_trader_cpp-0.39.0-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 f6899bbc3dd0e79e8a1c0d6c77a7b1cad87ba6d1fd111833b184815161e7f929
MD5 7eb81a131648fa1a3a66a78151c2e38a
BLAKE2b-256 d807a25ef7eabd373954e0adae53653c53655ba94a26ff79e25a67f65ed0e463

See more details on using hashes here.

File details

Details for the file back_trader_cpp-0.39.0-cp38-cp38-win_amd64.whl.

File metadata

File hashes

Hashes for back_trader_cpp-0.39.0-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 7b7648b3f3d62f0c9f5050b73fa9f7381d07f54dc9c12b258fe820400d095ade
MD5 089d14de07c9d278bfa08bd5bb0cc1d7
BLAKE2b-256 1d5780aa800a896471d13e5f50c239047ac792ab2fa8da10047175791a7f08f6

See more details on using hashes here.

File details

Details for the file back_trader_cpp-0.39.0-cp38-cp38-manylinux_2_39_x86_64.whl.

File metadata

File hashes

Hashes for back_trader_cpp-0.39.0-cp38-cp38-manylinux_2_39_x86_64.whl
Algorithm Hash digest
SHA256 275d0e641a498c71bafba911c8b1203e2f7e35b12a1c85bb79d13c13900c2b3f
MD5 cbd4de5e6260427de60b1a4538edd98f
BLAKE2b-256 81c5ed518cf1f05f9a91c22cead3d5f272b2e1f1c7dce0452978e0dd666311e3

See more details on using hashes here.

File details

Details for the file back_trader_cpp-0.39.0-cp38-cp38-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for back_trader_cpp-0.39.0-cp38-cp38-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 1a76af821c144eca9d7ac9bc6dcf47a69f9feba2229335edfa2ea79d4a945638
MD5 f1adfb4ca84f6eff59225707a7b3fd97
BLAKE2b-256 aee2445d2845ccfb039e03900ec1ba84d76cfcd2b4a1dcd92a4007fdc88fd868

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