Modern C++23 Backtesting Engine for Systematic Trading Research
Header-Only | Golden-Master Validated | Multi-Timeframe | Zero-Allocation Hot Path
Why StratForge | Features | Validation | Quick Start | Documentation | Performance
StratForge is a high-performance C++23 backtesting engine for strategy research, indicator development, and systematic trading workflows. It packages a backtrader-style programming model into a header-only, zero-overhead library with a strong focus on deterministic behavior, reproducible tests, and public benchmark methodology.
It is designed for users who want:
- A native C++ engine instead of a Python runtime in the research loop
- A broad indicator surface area without paying virtual-dispatch or dynamic-allocation costs on every bar
- Reproducible behavior through golden-reference tests, not just ad hoc examples
- A small dependency footprint that is easy to embed into larger quant stacks
- 157 indicators and utility primitives covering trend, momentum, volatility, volume, statistics, and candlestick analysis
- 10 candlestick patterns including Doji, Hammer, Engulfing, Morning Star, and Shooting Star
- Header-only distribution via
#include <stratforge/stratforge.hpp> - Zero-allocation hot path target for per-bar processing
- Multi-timeframe support with resample and replay flows
- Portfolio and broker model with orders, positions, trades, commission, and sizing
- Analyzers for Sharpe ratio, drawdown, returns, trade statistics, and extended metrics
- Grid optimizer for multi-parameter strategy sweeps
- LLM-oriented examples for code generation and strategy templating workflows
std::expected-friendly design direction and exception avoidance on hot paths- Concepts, designated initializers, and compile-time validation where appropriate
- Strict warning-clean builds across GCC, Clang, and MSVC
- Portable CMake-based integration for local builds and FetchContent consumers
StratForge is validated as an engineering project, not just a code drop.
- Golden reference tests under
tests/golden/for indicators, broker behavior, analytics, resampling, replay, and multi-data flows - Cross-validation inputs under
tools/golden_extract/for reproducible comparisons - End-to-end integration tests covering strategy execution and analyzer outputs
- Benchmark suites for indicators, composite strategies, optimizers, and allocation audits
- Indicator correctness is checked against persisted expected outputs
- Regression detection is easier because data files and expected values live in the repository
- Performance claims can be tied back to reproducible benchmark code instead of one-off measurements
- C++23 compiler: GCC 13+, Clang 17+, or MSVC 2022 17.10+
- CMake: 3.25+
cmake -B build -G Ninja -DCMAKE_BUILD_TYPE=Release
cmake --build build
ctest --test-dir build --output-on-failure#include <stratforge/stratforge.hpp>
#include <iostream>
#include <memory>
class SmaCross : public stratforge::Strategy {
std::unique_ptr<stratforge::SMA> fast_;
std::unique_ptr<stratforge::SMA> slow_;
public:
void init override {
fast_ = std::make_unique<stratforge::SMA>(data.close, 10);
slow_ = std::make_unique<stratforge::SMA>(data.close, 30);
}
void next override {
if (fast_->line.size == 0 || slow_->line.size == 0) {
return;
}
const double fast = fast_->line[0];
const double slow = slow_->line[0];
if (!position.size && fast > slow) {
(void)buy(100.0);
} else if (position.size > 0 && fast < slow) {
(void)close;
}
}
};
int main {
stratforge::Cerebro cerebro;
cerebro.add_strategy<SmaCross>;
auto feed = std::make_unique<stratforge::CsvData>(stratforge::CsvData::Params{
.filename = "data.csv",
.columns = {},
.date_format = "%Y-%m-%d",
.separator = ',',
.has_headers = true,
.fromdate = std::nullopt,
.todate = std::nullopt,
});
if (!feed->load) {
std::cerr << "Failed to load data\n";
return 1;
}
cerebro.add_data(std::move(feed));
auto& trades = cerebro.add_analyzer<stratforge::TradeAnalyzer>;
cerebro.set_cash(10000.0);
cerebro.run;
std::cout << "Final cash: " << cerebro.broker.cash << '\n';
std::cout << "Total trades: " << trades.get_analysis.total.total << '\n';
}include(FetchContent)
FetchContent_Declare(
stratforge
GIT_REPOSITORY https://github.com/StratCraftsAI/StratForge.git
GIT_TAG v0.1.0
)
FetchContent_MakeAvailable(stratforge)
target_link_libraries(your_target PRIVATE stratforge)| Option | Default | Description |
|---|---|---|
SF_BUILD_TESTS |
ON |
Build Catch2-based test suite |
SF_BUILD_EXAMPLES |
ON |
Build example strategies |
SF_BUILD_BENCHMARKS |
ON |
Build benchmark executables |
The bundled examples use SF_SOURCE_DIR to locate repository sample data. External consumers can point CsvData at their own datasets directly.
- Examples for end-to-end strategy patterns
- Benchmarks for methodology and baseline targets
- Support for bug reports and usage questions
- Roadmap for planned project expansion
- Changelog for release-to-release changes
tests/golden/for persisted reference outputstools/golden_extract/datas/for sample datasets used in validationdocs/tickets/for current project hardening tickets
| Example | Description |
|---|---|
sma_crossover.cpp |
Moving-average crossover strategy |
rsi_mean_reversion.cpp |
RSI threshold mean reversion |
macd_trend.cpp |
MACD signal-based trend following |
bollinger_bands.cpp |
Volatility breakout with stops |
multi_timeframe.cpp |
Daily/weekly multi-timeframe strategy |
pairs_trading.cpp |
Two-instrument spread trading example |
optimizer_example.cpp |
Parameter grid optimization |
The repository includes dedicated benchmark executables and allocation audits.
Current benchmark targets from benchmarks/README.md:
| Metric | Target |
|---|---|
| Per-indicator computation | < 100 ns/bar P50 |
| Composite strategy bar processing | < 100 ns/bar |
| Hot-path allocations | 0 |
| Parallel optimization scaling | Near-linear |
Use the benchmark suite to validate changes rather than treating these numbers as static marketing claims.
Full indicator list
SMA, EMA, DEMA, TEMA, WMA, HMA, KAMA, TRIMA, ZLEMA, ZeroLag, SMMA, DMA, Laguerre, ExponentialSmoothing
RSI, MACD, MACDExt, Stochastic, StochRSI, CCI, MOM, ROC, ROCP, ROCR, ROCR100, Williams %R, Ultimate Oscillator, TSI, KST, Awesome Oscillator, DPO, Pretty Good Oscillator, BOP, DV2, Aroon
ATR, NATR, Bollinger Bands, Bollinger %B, Envelope, True Range, True High, True Low, Standard Deviation, Variance, Hurst Exponent, Volatility
OBV, Accumulation/Distribution, Volume indicators
Parabolic SAR, Ichimoku, Pivot Points, Hilbert Transform, Linear Regression
Mean Deviation, Percent Rank, OLS Regression, Min/Max, Highest, Lowest, Midpoint
Doji, Hammer, Inverted Hammer, Bullish Engulfing, Bearish Engulfing, Morning Star, Evening Star, Shooting Star, Hanging Man, Marubozu
Crossover, UpDay, DownDay, UpMove, DownMove, PercentChange, Accumulator, FindIndex
- Contribution policy: CONTRIBUTING.md
- Support policy: SUPPORT.md
- Security reporting: SECURITY.md
- Code of conduct: CODE_OF_CONDUCT.md
StratForge is released under the Apache License 2.0.