Leanpub Header

Skip to main content

Building a Low Latency Risk Engine in C++

Building a Low Latency Risk Engine in C++
This book is 100% completeLast updated on 2026-10-18

Minimum price

$19.00

$29.00

You pay

Author earns

$

Also available for 1 book credit with a Reader Membership

PDF
About

About

About the Book

Market-data handlers and matching engines get the attention. The risk engine deserves it just as much.

Every order a trading firm sends passes through a risk check first. In most systems that check is an afterthought: a position limit and little else, kept small so it doesn't slow anything down. Yet it is the one component that stands between every order and the market, and its failures are never small. It has to be exactly right and fast, at the same time, while other threads change the data it reads.

This book builds that engine from an empty directory to a tested, measured system in C++23: a lock-free pre-trade and portfolio risk engine for high- and medium-frequency trading. Every order is checked against size, notional, fat-finger and price-collar limits in tens of nanoseconds, with no locks and no heap allocation on the order's path. Positions, resting exposure and Value at Risk stay current on every fill. Stress scenarios run against the live book, and an audit trail records every decision so the past can be rebuilt exactly.

What you'll learn

- Lock-free building blocks (seqlocks, single-producer rings, RCU publication, fixed-capacity containers) and when each is the right tool
- How to time a 50-nanosecond operation honestly, and prove the hot path never allocates
- The finance from first principles: positions, limits, Value at Risk and stress testing, each with a worked example
- Keeping VaR current on every fill, with expensive recomputation moved off the critical thread
- What a risk check should do when it can't answer in time
- Testing systems whose bugs don't crash: reference implementations, randomized input, sanitizers, and breaking the code on purpose
- Measuring what a component really costs a system, from the outside, against a noise floor

Every chapter shows the design that looks right and the input that breaks it, then the design that works and what it costs, with the exact command to reproduce every number.

Who it's for: engineers who read modern C++ and want to understand low-latency design, finance, or both. No background in risk management is assumed.

Included with the book: access to the complete source repository: the engine, a simulated exchange, every test and benchmark, every code listing as a file, and a recorded trading session you can inspect without building anything.

Chapter 1 is available as a free sample.

Share this book

Categories

Author

About the Author

Suhas Ghorpadkar

Suhas Ghorpadkar has spent more than twenty years building front-office trading and risk systems. His work has centred on the parts of a trading stack where correctness and speed have to hold at the same time. Building a Low Latency Risk Engine in C++ is his attempt to give the engineering care to risk engines that the rest of the stack already gets. He lives in New York.

Get the free sample chapters

Click the buttons to get the free sample in PDF or EPUB, or read the sample online here

The Leanpub 60 Day 100% Happiness Guarantee

Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.

See full terms...

Earn $8 on a $10 Purchase, and $16 on a $20 Purchase

We pay 80% royalties on purchases of $7.99 or more, and 80% royalties minus a 50 cent flat fee on purchases between $0.99 and $7.98. You earn $8 on a $10 sale, and $16 on a $20 sale. So, if we sell 5000 non-refunded copies of your book for $20, you'll earn $80,000.

(Yes, some authors have already earned much more than that on Leanpub.)

Learn more about writing on Leanpub

Free Updates. DRM Free.

If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).

Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.

Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.

Learn more about Leanpub's ebook formats and where to read them

Write and Publish on Leanpub

You can use Leanpub to easily write, publish and sell in-progress and completed ebooks and online courses!

Leanpub is a powerful platform for serious authors, combining a simple, elegant writing and publishing workflow with a store focused on selling in-progress ebooks.

Leanpub is a magical typewriter for authors: just write in plain text, and to publish your ebook, just click a button. (Or, if you are producing your ebook your own way, you can even upload your own PDF and/or EPUB files and then publish with one click!) It really is that easy.

Learn more about writing on Leanpub