Prototype of a high-performance C++ backtesting engine designed to analyse financial data and evaluate multiple trading strategies at scale.
C++ Backtesting Engine
Active development!
Feel free to explore, but this code base is usable at the moment.
About The Project
I'm developing a high-performance C++ backtesting engine designed to analyze financial data and evaluate multiple trading strategies at scale โ and to take the winners live.
The engine is C++23 (modules, import std;) and one binary with eight subcommands:
ingestโ receives a UDP tick stream and writes it to QuestDBloadโ expands a strategy parameter sweep and queues it in Redisrunโ drains the queue, backtests against QuestDB ticks, reports results to Elasticsearchexperimentsโ expands a parameter sweep of occurrence-rate questions ("price drops 1% in 10m, then recovers 0.5% in 10m โ how often?") and queues it in Redis, no strategy requiredanalysisโ drains the experiment queue, counts pattern occurrences against QuestDB ticks, reports aggregate stats (rates, conditional completion, excursion quantiles) to Elasticsearchliveโ takes the winning backtests from Elasticsearch and trades them live via the IG REST APItrackingโ receives the IG account's deal/position updates over UDP, logs each one, archives closed deals in the Redis position book (PO#โPH#, pruning thePL#list), and ships alive-tradesdocument to Elasticsearch per dealpositionsโ mirrors the IG account's open positions into Redis every minute (the position book, strategy lists, and cluster-exposure sets the live engine reads)
Read more results on https://mccaffers.com/quantitativeanalysis/randomlytrading/
Documentation
| Document | Contents | | --- | --- | | QUICKSTART.md | Building the engine and using each subcommand | | ARCHITECTURE.md | How it fits together โ data flow, queue design, live order path (Mermaid diagrams) | | ENVIRONMENT.md | Every environment variable, per command, with defaults | | REQUIREMENTS.md | Toolchain, system libraries, vendored dependencies, runtime services |
Quick start
git clone --recurse-submodules https://github.com/mccaffers/backtesting-engine-cpp
cd backtesting-engine-cpp
bash ./scripts/build.sh # CMake + Ninja + Clang/libc++ (see REQUIREMENTS.md for the toolchain) bash ./scripts/test.sh # Catch2 tests via ctest
with Redis, QuestDB, and Elasticsearch running (see QUICKSTART.md):
./build/BacktestingEngine load random # queue a sweep
./build/BacktestingEngine run localhost # drain and backtest
Contributing
This is an active solo experiment, so I'm not accepting pull requests right now, but please fork freely and use GitHub Issues for bugs, questions, and ideas. See CONTRIBUTING.md for details.