ByLeet
← Back to Blog

Why We Wrote a Back-Testing Engine in Rust

2026-02-03

When we started building LeetBacktest, the obvious choice was to write everything in Python. The quant community lives in Python — NumPy, pandas, and Jupyter are the lingua franca of strategy research. But we hit a wall almost immediately: simulating a moderately complex strategy across a multi-year, multi-instrument tick dataset took hours, which made iterative research painfully slow.

We evaluated several alternatives: Cython, Numba, C++ with pybind11, and Rust with PyO3. Rust won for three reasons. First, its ownership model eliminates entire classes of memory bugs without a garbage collector, which is critical in a long-running simulation. Second, its zero-cost abstractions mean we can write expressive, modular code without paying a runtime penalty. Third, PyO3 makes it straightforward to expose Rust structs and functions as native Python objects, so the user-facing API feels like any other Python library.

The result is a back-testing engine where the hot path — event dispatch, order matching, portfolio accounting — runs in Rust, while strategy logic is written in pure Python. The boundary is crossed via zero-copy buffers wherever possible. On our benchmark suite, LeetBacktest processes ten years of minute-bar data for 500 instruments in 87 seconds — roughly 200x faster than an equivalent pure-Python implementation. Researchers iterate faster, test more hypotheses, and ship strategies to production with higher confidence.