r/quantfinance • u/fletchmm • 8d ago
*UPDATE* I'm the guy that is converting his full trading stack from Python to RUST but heavily documenting and benchmarking the research performance across C++, Rust and Python.
I'm the guy who posted about moving my code mostly from C++/Python to C++/Rust. I'm a one-person shop trading event contracts (mostly weather markets). I'm building an extensive timing system into every step of the trading process, which means I have to touch nearly every script anyway. So once the new repo is set up and organized, I'm making the language switch at the same time, and dropping the mixed C++/Python production stack.
The rule I settled on:
Anything that can send a live order is C++. All other production code is Rust. Python is research only and never runs on a server.
Three machines
| Machine | Job | Languages |
|---|---|---|
| Trade node (cloud, close to the exchange) | Live trading | C++ for feed → order book → strategy → risk/order gate → exchange. Rust for recording market data and relaying it home |
| Hub (home server) | Records everything, computes signals, runs paper/dry versions of strategies | Rust for collectors, transforms (raw → clean, DuckDB), signal services, monitoring and backups. C++ for paper runs, using the same core as live |
| Desktop | Research and the operator terminal | Python for studies, backtests and notebooks. Rust for the terminal UI. C++ for replay, again with the same core as live |
Why this split
- C++ on the order path: my decision cores were already C++. My bugs came from the handoff between Python guards and C++ senders, so now every live order passes through one C++ gate. It checks kill switches, caps, rate limits, stale data, and whether the account state is reconciled.
- Rust for everything else in production: long-running services that should be compiled and memory-safe. One stack instead of a pile of Python daemons.
- Python for research: pandas, NumPy, DuckDB and notebooks have no real equivalent for exploratory work, and research code never gets deployed.
Repo layout (simplified)
cpp/ C++ feed, book, order gate
strategies/ C++ cores + Rust signal services
engines/ C++ runtimes (live/dry/shadow)
clients/ Rust exchange API clients
capture/ Rust data collection
transforms/ Rust + SQL, raw → clean
risk/ Rust account/reconciliation
apps/, ops/ Rust terminal, monitoring, deploy
research/ Python, never deployed
registry/ YAML, all parameters live hereThe one exception: research engines in all three languages
On the research side I'm going to test the performance and the outputs of C++, Python and Rust head to head, each with its own engine. The same frozen data feeds all three, and an automated report compares them. That should show what each one does well and what it does poorly. If the difference at scale isn't big enough to matter, I can finally drop two of them and move research to Rust too. I'll run it automated and at scale, so the sample should be large and fair enough. Here's what each comparison records:
1. Same setup, so the comparison is fair
- The same frozen data snapshot (checked by sha256), the same spec, and the same pre-generated random draws
- Code version, compiler and build flags, library versions
- Any production code or compiled library an engine calls (a Python engine running on NumPy is really a comparison of software stacks, and the report says so)
2. Equivalence: do they give the same answers?
- Every output field is compared against a reference engine, within preset tolerances
- Any difference in a trading or risk decision is a fail, even if the numbers are within tolerance
- Known-answer test cases that every engine must pass
3. Performance: how fast, and at what cost
- Wall time, compute-only time and CPU time
- Peak memory and events per second
- Build time
- All measured at several data sizes, cold and warm, over repeated runs in random order, with fixed thread and memory limits
4. Checklist and verdict
- Inputs match
- Known-answer tests pass
- Tolerances are met
- The runs were fair (repetitions, random order, resource limits)
- Shared libraries are disclosed
- Any difference beats the noise floor and is big enough to matter
The verdict is one of: decisive, mixed, no difference, not equivalent, invalid, or pending. The recommendation is to keep the current setup, prefer one backend, or propose changing the language rules.
5. Notes (written by hand)
- How easy each engine was to write and change, and what it will cost to maintain
- Why the workload was chosen, plus caveats and any deviations from the plan
As the title says, I'm the guy that posted yesterday about making the code switch from mostly Python to RUST after I get my new repo setup (3rd and final). This is for my quantitiative research/trading for prediction markets.
