C++20 event-driven trading backtester with Python bindings, snapshots, audit ledger, and microstructure-aware execution.
Project description
BACKTESTER
BACKTESTER is a low-latency, event-driven trading backtesting repo built around a C++20 execution engine and exposed through a Python package named nanoback.
What It Does
- Multi-asset backtests over contiguous matrix inputs
- Market and limit order simulation
- Partial fills, queue blocking, venue caps, and bid/ask-aware execution
- Parent/child order IDs with deterministic audit ledger output
- Snapshot/resume support for long-running simulations
- Risk controls for leverage, drawdown, cash, and per-asset limits
- Financing and borrow-cost accrual
- Compiled research policies and analytics in C++
- Python strategy/plugin fallback
- CSV and Parquet loaders
- Asserted benchmarks and pytest coverage
Repo Layout
include/nanoback: C++ headerscpp: C++ engine, policies, and Python bindingspython/nanoback: Python API, loaders, ledger utilities, and strategy helpersexamples: runnable examplesbenchmarks: performance checkstests: regression and functional coverage
Quickstart
cd C:\Users\TAPESH\documents\BACKTESTEER
python -m venv .venv
.\.venv\Scripts\Activate.ps1
python -m pip install -e .[dev]
python -m pytest
Core Capabilities
Execution Engine
- Event-driven C++20 core
- Market and limit orders
- Child-order slicing with delay steps
- Cancel/replace semantics
- Session-aware order cancellation
- Snapshot/resume from engine state
Market Realism
- Bid/ask execution path
- Queue-ahead fraction and venue volume share caps
- Slippage and participation-based impact
- Cost calibration helpers from empirical fill data
Risk and Audit
- Gross leverage checks
- Drawdown kill switch
- Cash and borrow accounting
- Per-asset max position and notional limits
- Deterministic ledger export to CSV/JSONL
Research Layer
- Compiled momentum, mean reversion, and moving-average crossover policies
- Compiled rolling volatility, cross-sectional ranking, and minimum-variance weights
- Python strategy hooks when custom event logic is needed
Minimal Example
import numpy as np
import nanoback as nb
result = nb.run_backtest(
timestamps=np.array([1, 2, 3, 4], dtype=np.int64),
prices=np.array([100.0, 101.0, 99.0, 102.0], dtype=np.float64),
signals=np.array([1, 1, 0, -1], dtype=np.int64),
config=nb.BacktestConfig(
max_position=2,
child_order_size=1,
child_slice_delay_steps=1,
),
)
print(result.pnl)
print(len(result.ledger))
Benchmark
.\.venv\Scripts\python.exe benchmarks\benchmark_engine.py --mode latency
.\.venv\Scripts\python.exe benchmarks\benchmark_engine.py --mode stress --baseline benchmarks/benchmark_engine_stress_baseline.json
The benchmark now writes a latency log book to outputs/benchmark_engine_latency.jsonl and checks
its results against benchmarks/benchmark_engine_baseline.json.
To track historical runs by release version, enable:
--record-history --history-file benchmarks/benchmark_results_history.jsonl
Useful flags:
--log-bookto change the JSONL output path--baselineto compare against a different baseline file--update-baselineto refresh the baseline after an intentional change--regression-factorto control how much slower a stage may get before failing
Performance Notes
Measured on this repo with the current 0.2.0 code:
- Standard benchmark,
50_000 x 8elapsed_seconds=0.0609data_generation=0.0324spolicy_generation=0.0040sengine_run=0.0246sfills=61033
- Heavier simulation,
200_000 x 16- Full pipeline:
elapsed_seconds=0.5472 data_generation=0.2933spolicy_generation=0.0762sengine_run=0.1777s
- Full pipeline:
- Isolated engine path for the same heavy simulation
elapsed_seconds=0.2233policy_generation=0.0733sengine_run=0.1499s
The isolated run shows the core backtest engine is fast and scales well, while the full pipeline is more constrained by Python-side data setup.
Institutional Reporting
Use the reporting helpers to generate a performance package for a completed run:
import nanoback as nb
result = nb.run_backtest(...)
report = nb.summarize_backtest(result, symbols=["AAA"])
nb.export_performance_report_json(report, "outputs/performance_report.json")
nb.export_performance_report_markdown(report, "outputs/performance_report.md")
The report includes:
- core PnL, return, drawdown, turnover, and fill-rate metrics
- equity and cash curve summaries
- audit-event counts
- asset-level execution summaries
This is the layer you would use for institutional-style post-trade review and fast root-cause analysis.
Status
The repo is strong as a research and simulation engine. It is not a full OMS/EMS, exchange adapter stack, or compliance platform.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file nanoback-0.5.1.tar.gz.
File metadata
- Download URL: nanoback-0.5.1.tar.gz
- Upload date:
- Size: 57.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
94e7218fb3097ecde98b63f2e1842c1046ab506caea5110a2573885d7fed5fdc
|
|
| MD5 |
3b11ef102e4d58f7588740d95e92f052
|
|
| BLAKE2b-256 |
45a221e8cc74312d1af5256f42fea457e8da3b0362b7f2d122f8fbb6650db144
|
Provenance
The following attestation bundles were made for nanoback-0.5.1.tar.gz:
Publisher:
publish.yml on td-02/BACKTESTER
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
nanoback-0.5.1.tar.gz -
Subject digest:
94e7218fb3097ecde98b63f2e1842c1046ab506caea5110a2573885d7fed5fdc - Sigstore transparency entry: 1441755134
- Sigstore integration time:
-
Permalink:
td-02/BACKTESTER@a325d6505cbb2678a449e4c5fcd8fcf09ca66049 -
Branch / Tag:
refs/tags/v0.5.1 - Owner: https://github.com/td-02
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@a325d6505cbb2678a449e4c5fcd8fcf09ca66049 -
Trigger Event:
push
-
Statement type: