Quantitative Finance with OCaml: a free web book on pricing, risk and trading in OCaml
"Quantitative Finance with OCaml" is a book published as a web page at qcaml.com. It describes itself as a comprehensive guide to building correct, performant and maintainable financial systems using OCaml. The version shown is 1.0, February 2026.
The pitch starts from a familiar split. Quantitative finance sits at the intersection of mathematics, statistics and software engineering, and most practitioners reach for Python for rapid prototyping or C++ for raw speed. The book argues that OCaml offers something rare: a language that is at once expressive, correct by construction, and fast enough for production trading systems. The reader is promised the ability to price derivatives, manage risk, model credit, build trading algorithms and design financial infrastructure, while using OCaml's type system to make whole classes of financial programming errors impossible at compile time.
The book lists five things it says set it apart: every concept comes with production-quality OCaml code; mathematical derivations are presented honestly rather than buried in appendices; the code forms reusable, well-typed libraries that accumulate across chapters; performance and correctness are treated as equal concerns; and coverage extends to modern OCaml 5 features (domains, effects and OxCaml extensions).
The structure is 30 chapters in seven parts, which can be read in order or used as a reference. Part I, Foundations, covers why OCaml for quantitative finance, OCaml essentials, mathematical foundations, and probability and statistics (Chapters 1 to 4). Part II, Fixed Income and Interest Rates, covers time value of money, bonds, the yield curve and interest rate derivatives (Chapters 5 to 8). Part III, Equity and Derivatives, runs from equity markets through the Black-Scholes framework, numerical methods for option pricing, Monte Carlo methods, volatility and exotic options (Chapters 9 to 14). Part IV, Credit and Multi-Asset, has credit risk and credit derivatives, portfolio credit derivatives, and multi-asset models and correlation (Chapters 15 to 17). Part V, Risk Management, covers market risk, Greeks and hedging, counterparty credit risk, and portfolio risk and optimization (Chapters 18 to 21). Part VI, Algorithmic Trading and Market Microstructure, covers market microstructure, execution algorithms, quantitative trading strategies and high-performance trading infrastructure (Chapters 22 to 25). Part VII, Advanced Topics, covers stochastic calculus and advanced pricing, machine learning in quantitative finance, regulatory and accounting frameworks, systems design, and a capstone: a complete trading system (Chapters 26 to 30). Six appendices, A to F, include an OCaml quick reference for finance, a mathematical reference, a financial glossary, further reading, development environment setup, and a piece titled "Correctness by Construction".
The page gives reading shortcuts. Readers with OCaml experience may skim Chapters 1 and 2; readers with finance experience may skim Chapters 5 and 9.
Companion code is organised by chapter. Each chapter directory holds the chapter text as a README, reusable library modules, worked examples, exercises (practice problems) and benchmarks (performance experiments). Dependencies are installed with opam (core, owl, zarith, menhir and ppx_deriving), then the examples are built with dune build and tested with dune test. The notation note says OCaml code appears in syntax-highlighted blocks, formulas use standard notation (S_t for asset price at time t, sigma for volatility, r for the risk-free rate), types are written in OCaml notation, and module paths look like Black_scholes.price. The page closes by welcoming corrections and contributions via the project repository.
Key facts
- The book is titled "Quantitative Finance with OCaml", published as a web page at qcaml.com, version 1.0, February 2026.
- It has 30 chapters in seven parts, from foundations and fixed income through derivatives, credit, risk and algorithmic trading to advanced topics and a capstone trading system, plus appendices A to F.
- It argues OCaml combines expressiveness, correctness by construction and speed, and says its type system can make whole classes of financial programming errors impossible at compile time.
- Companion code is organised per chapter (library modules, examples, exercises, benchmarks) and builds with opam and dune.
- Coverage includes modern OCaml 5 features: domains, effects and OxCaml extensions.
Why it matters
Quantitative finance code is usually written in Python for prototyping or C++ for speed. This book makes the case for a third option, OCaml, and backs it with a full curriculum rather than a single essay. Its central bet is that a strong type system can rule out whole classes of financial programming errors at compile time, with performance and correctness treated as equal concerns. It also reaches into OCaml 5 features such as domains, effects and OxCaml extensions.
Who it affects
The audience is people who write finance software and are curious about OCaml, and OCaml programmers who want to learn finance. The book signals both groups in its reading advice: those with OCaml experience may skim Chapters 1 and 2, and those with finance experience may skim Chapters 5 and 9. The topics span derivatives pricing, risk, credit, algorithmic trading and trading infrastructure, so quant developers and strategy builders are the natural readers.
How to use it
Read it in order or dip in as a reference, since the seven parts are built for both. To run the examples, install dependencies with opam (core, owl, zarith, menhir, ppx_deriving), then run dune build and dune test inside the quantitative-finance-with-ocaml directory. Each chapter folder has the chapter text, library modules, worked examples, exercises and benchmarks. The code libraries are meant to accumulate across chapters, so working through the book in sequence pays off. Corrections and contributions are welcome via the project repository.
How solid is it
Every claim above is the book's own description of itself. The page shows a full table of contents of 30 chapters in seven parts and appendices A to F, and gives the version as 1.0, February 2026. No author or authors are named. No publisher, price, license or print edition is mentioned. No benchmark numbers or performance comparisons against Python or C++ are given, and no reviews, adoption figures or reactions are reported.
Risks and caveats
The assertion that OCaml is fast enough for production trading systems is the book's pitch, and the page offers no performance figures to support it. The repository URL is not stated on the page. The seven parts are described only through the table of contents, so depth and quality of individual chapters cannot be judged from it. The book itself says most practitioners reach for Python or C++ instead.
“OCaml offers something rare: a language that is simultaneously expressive, correct by construction, and fast enough for production trading systems.”
— Quantitative Finance with OCaml, "About This Book"