Neural Networks from Scratch in Rust

In 2017, a fraud detection startup discovered their Python-based neural network inference was creating a hidden cost: 200 milliseconds of latency per transaction. At their scale—15,000 transactions per second—this meant holding $3 million in pending transactions at any moment, exposing them to market risk and regulatory scrutiny. When they rewrote their inference engine in Rust, latency dropped to 8 milliseconds—a 25× improvement—and throughput increased enough to handle 10× growth without additional hardware. The difference wasn’t algorithmic sophistication. It was understanding how neural networks actually execute on real hardware and choosing a language that exposed rather than obscured those realities. ...

March 18, 2025 · 31 min · 6572 words · Svein Erik

Low-Latency Trading Systems in Rust

In high-frequency trading (HFT), microseconds determine profitability. When an arbitrage opportunity appears—say, a 0.01% price discrepancy between two exchanges—it vanishes within 100-500 microseconds as competing algorithms exploit it. The firm that detects and acts fastest captures the profit; everyone else loses. At this timescale, traditional software engineering practices (dynamic allocation, garbage collection, high-level abstractions) become liabilities. Systems must operate at the edge of hardware capability: cache-line optimization, lock-free algorithms, kernel bypass networking. ...

September 2, 2024 · 52 min · 10914 words · Svein Erik

Building a Derivatives Pricing DSL in Rust

Financial institutions require precise, auditable, and performant valuation of derivative portfolios. This article presents the design and implementation of a domain-specific language (DSL) for pricing futures and forwards, embedded in Rust. We examine the mathematical foundations of derivative pricing, construct a type-safe expression language, and build an evaluation engine capable of handling portfolios containing thousands of instruments. Introduction Futures and forwards are fundamental derivatives: contracts obligating parties to transact an underlying asset at a predetermined price on a future date. While conceptually similar, they differ in standardization (futures trade on exchanges, forwards are OTC) and settlement mechanics (futures mark-to-market daily, forwards settle at maturity). ...

April 29, 2021 · 17 min · 3418 words · Svein Erik