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.1-cp314-cp314-win_amd64.whl (6.0 MB view details)

Uploaded CPython 3.14Windows x86-64

back_trader_cpp-0.39.1-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.1-cp314-cp314-macosx_11_0_arm64.whl (4.0 MB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

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

Uploaded CPython 3.13Windows x86-64

back_trader_cpp-0.39.1-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.1-cp313-cp313-macosx_11_0_arm64.whl (4.0 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

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

Uploaded CPython 3.12Windows x86-64

back_trader_cpp-0.39.1-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.1-cp312-cp312-macosx_11_0_arm64.whl (4.0 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

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

Uploaded CPython 3.11Windows x86-64

back_trader_cpp-0.39.1-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.1-cp311-cp311-macosx_11_0_arm64.whl (3.9 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

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

Uploaded CPython 3.10Windows x86-64

back_trader_cpp-0.39.1-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.1-cp310-cp310-macosx_11_0_arm64.whl (3.9 MB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

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

Uploaded CPython 3.9Windows x86-64

back_trader_cpp-0.39.1-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.1-cp39-cp39-macosx_11_0_arm64.whl (3.9 MB view details)

Uploaded CPython 3.9macOS 11.0+ ARM64

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

Uploaded CPython 3.8Windows x86-64

back_trader_cpp-0.39.1-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.1-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.1-cp314-cp314-win_amd64.whl.

File metadata

File hashes

Hashes for back_trader_cpp-0.39.1-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 dd095508546864ce464c9f43c838d36f10a6f4e3363c14d3ea33f0cef8bd37b9
MD5 f7e0c0e020d7c32d00fca7383ad157ad
BLAKE2b-256 9a173328d9e9e063d154b4666c3b2978d99fd45272053dde419a5b28988cf4e9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for back_trader_cpp-0.39.1-cp314-cp314-manylinux_2_39_x86_64.whl
Algorithm Hash digest
SHA256 6d4804b7bd31ff4027ab5b7f28769b8ca1f970ecdc2a3af7b0545edecfa0e7e9
MD5 b7fac15de80e618e8bd7743d65b2ff64
BLAKE2b-256 d034527d72d30ee0153be2751a32875139612423ddb6535bc4363095d57b5f37

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for back_trader_cpp-0.39.1-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 6e0df17949aaad9d53cc12266ee4511dbf8361458d1e41f3d384a90c6885fb43
MD5 96777611be7463398321d2502b196ab2
BLAKE2b-256 56dd5b7b97a099f2185c60f8c81c966aa6af89135ac205467be0f055463cbc26

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for back_trader_cpp-0.39.1-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 adb699a6de04ec80081475d0d07a1b77888d95a3734e20131b972b46932a7bdd
MD5 398cd6e1716f08d1a312322157e02fc8
BLAKE2b-256 d99d264b8a5b456e24e001678a161179a2a806db9a75f15c71d311946004225f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for back_trader_cpp-0.39.1-cp313-cp313-manylinux_2_39_x86_64.whl
Algorithm Hash digest
SHA256 6d07dbb1ea377d60b6adfb1fb04acc7f6b8fadb15475a41ad875d10dc75f99f8
MD5 c6ee3546dff8cb7045236aa34cc12a5e
BLAKE2b-256 87060f668176233f83faa432cae71d54082d252f36f51f3d499aa3e3c62be99a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for back_trader_cpp-0.39.1-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 d01e80f30a737df46294b351c6accdf786e7df764479482af1126cebbd7f97d1
MD5 42ca5a427b9d37732a0b730704ee9b3b
BLAKE2b-256 8a9c7d12ffe6e6c24c5cf9501855a37be7e92d277dc89af4cac62ff31cc40a7d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for back_trader_cpp-0.39.1-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 961c237c496b75993860e86c29cf656cf90eebcba285ea50598020301725fda0
MD5 e8fc2043bdc0410df639f8788dd70258
BLAKE2b-256 236fb3854ccdebb6b3665159557e19638ba4a4a3469e5de9bab812a782089bda

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for back_trader_cpp-0.39.1-cp312-cp312-manylinux_2_39_x86_64.whl
Algorithm Hash digest
SHA256 b48a05eb2b6095d69d1e4eb6d4422c1285b42530d4b496111d0ab2b38472a4ef
MD5 76a515140bd89ad42c8e867067489fa8
BLAKE2b-256 8a10b8a21de035c1cbc7c9017615cf57984d3d48d2a69491131e51d1548cc0ba

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for back_trader_cpp-0.39.1-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 40515003fc4f9f05e8e45d559ef7eeafef621ace283f57ceb5d13195f4fd9a78
MD5 1d64bec61246ce4faa1a09488bbffad3
BLAKE2b-256 927407211b1388189a96d6cd378bc35a49beec52d5bcf607646bdf7e2e6635d4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for back_trader_cpp-0.39.1-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 f9be469640d5641159bc820002ab421163a0d17df4574e5d0b7f2c44e5805dd4
MD5 a9a51391b48f490ca9d5751fc75dab6b
BLAKE2b-256 3ec5beccf82ad622e702c37d41f9b24d3d3f2ce3728e862314970956ffb35a34

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for back_trader_cpp-0.39.1-cp311-cp311-manylinux_2_39_x86_64.whl
Algorithm Hash digest
SHA256 1116d612fda6348ea62fe733a41c4406bfaac396bdf83dfb2d850f49cbbe0fec
MD5 c8c89f39c355f7b540e104d564604de9
BLAKE2b-256 b30ca10e9642be5561ce8a35e32d1d1ad83e8a3d8efc1a9f13436a3c3c6ef73d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for back_trader_cpp-0.39.1-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 ee8867793fef788cd5dce806a7c1e2ac3e5fef386ace4c46a97a6d83ea6619c3
MD5 0909c76f773a274c3252d408ae6cf6cc
BLAKE2b-256 0a7eaeaba14bb2155c67500f946dbd20ce02fbc660f4602b39997060afe8760d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for back_trader_cpp-0.39.1-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 8fbb0fd542e48eae8b88396d7abcf930765c9862bb59bea26e0ea78a2de05c2d
MD5 a498e668513be34fcbaa54d3daaaac66
BLAKE2b-256 9f2e33445e0a87b7b78a7e07c4678aa33f2a77b17e6b775102158669ca1761db

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for back_trader_cpp-0.39.1-cp310-cp310-manylinux_2_39_x86_64.whl
Algorithm Hash digest
SHA256 58ff12cbae19c986abb5b014b95a0d22b423e65f6f9e32da5d7a0d853439759e
MD5 5160856007e5f9f819cac0a0a6ad8164
BLAKE2b-256 f3f617b2749c19239d05da836c27988ca48569d7b1c4751959791820be77e3ca

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for back_trader_cpp-0.39.1-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 de94842241053ced62f4b1ad77b426cbb1f0dde0dca100131c9fb543431bb22e
MD5 9a9ffe1e3a27ac5426d3b4cf0f9bd09a
BLAKE2b-256 d1172eb7d14217825f82d5a70a325553ef030ef2fba733e2efeaa8aa13e9094b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for back_trader_cpp-0.39.1-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 92a989c1105d663af05829cf6b711d2c56d7b8ec64a9141734e9f3db4d342427
MD5 a57588d88439738be69e8a065734ecf6
BLAKE2b-256 de5fc1f914d38c7efdeef029be1030d08694a78b4543e5510265eaa52902e672

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for back_trader_cpp-0.39.1-cp39-cp39-manylinux_2_39_x86_64.whl
Algorithm Hash digest
SHA256 1de1728e06730e44a21a8e4562e47c54f911dc95d44e0bbe791bc9a9c1e1472e
MD5 d74bf91a4ccac7f5f4fb8dbf529e31eb
BLAKE2b-256 a2fad8b2a6fd3767ab7cad9e0041552094f659e550bc6fe2cd3b800d44541aa5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for back_trader_cpp-0.39.1-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 996de84877ecfeafb787378880ad9a2033bfceb1f56975ac8c61ab2357f1a568
MD5 645f346b3512b868912f693502499e28
BLAKE2b-256 aae0309bf4c03db00c764beccbd7abc3b9aaf7112596075c71d15e7e01cef5dd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for back_trader_cpp-0.39.1-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 eb93d1410b365a0de98e9a213651d97e228a1f0339a6f27665a484205bcbb5e9
MD5 06c343e955e7f1adc3a4fa9e112b8195
BLAKE2b-256 09bf780e23194bfc97c7c99ab08833ab30b610f04d1ec394be1a0cbfe460c688

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for back_trader_cpp-0.39.1-cp38-cp38-manylinux_2_39_x86_64.whl
Algorithm Hash digest
SHA256 ef4e5f8d156f5f77e60d81b4172075d9230e9a663ca2dce6227be1644897dafc
MD5 f69e227e17b86525ad4d2fc139a9ce7a
BLAKE2b-256 1039f3d8feef109d33c8b268e9974bdc5ba061ce6e3bc0e9abeb23f7d38c83fc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for back_trader_cpp-0.39.1-cp38-cp38-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 4c3d5bdf727f83cc6069d2b333a214a6f632a07e40dfdf49d30bc0051a61c113
MD5 4d46223033699a8b62207199faa1e66b
BLAKE2b-256 b3c725a5da7d04bddcf8fe130a1df1f695b9bd2d507a0d8b005a18482ca08cf0

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