《使用 OCaml 进行量化金融》
Quantitative Finance with OCaml

原始链接: https://qcaml.com/index.html

# 使用 OCaml 进行量化金融 这是一本全面指南,介绍如何用 OCaml 构建正确、高性能且易于维护的金融系统。本书将量化金融理论与生产级、可复用且类型安全的库相结合,同样重视数学表达的清晰性、正确性和性能。 全书分为七个部分,涵盖 OCaml 基础、数学与概率;固定收益和利率衍生品;股票、布莱克–斯科尔斯模型、蒙特卡洛方法与波动率;信用风险、CDO 和多资产模型;市场风险、希腊字母、XVA 与投资组合优化;算法交易、交易执行和高频基础设施;以及随机微积分、机器学习、监管和 OxCaml 等高级主题。书中贯穿使用了现代 OCaml 5 的特性,包括域和效应。 每一章都提供讲解文字、可复用模块、实例、练习和基准测试。项目使用 Dune,并包含安装依赖项、构建示例和运行测试的命令。有经验的 OCaml 或金融读者可以跳过部分入门章节,并将本书作为连续教材或参考手册使用。

Hacker News 新帖 | 往期 | 评论 | 问答 | 展示 | 工作机会 | 提交 登录 使用 OCaml 进行量化金融 ( qcaml.com ) 6 分 作者: leonry 2 小时前 | 隐藏 | 往期 | 收藏 | 讨论 | 帮助 考虑申请 YC 2027 年冬季批次! 申请截止至 11 月 2 日。 指南 | 常见问题 | 列表 | API | 安全 | 法律声明 | 申请加入 YC | 联系我们 搜索:
相关文章

原文

A comprehensive guide to building correct, performant, and maintainable financial systems using OCaml.


Quantitative finance sits at the intersection of mathematics, statistics, and software engineering. Most practitioners reach for Python for its rapid prototyping or C++ for raw speed — but OCaml offers something rare: a language that is simultaneously expressive, correct by construction, and fast enough for production trading systems.

This book teaches quantitative finance through the lens of OCaml. You will learn to price derivatives, manage risk, model credit, build trading algorithms, and design robust financial infrastructure — all while exploiting OCaml's type system to make whole classes of financial programming errors impossible at compile time.

What makes this book different:

  • Every concept is accompanied by production-quality OCaml code
  • Mathematical derivations are presented honestly, not buried in appendices
  • We build reusable, well-typed libraries that accumulate across chapters
  • Performance and correctness are treated as equal concerns
  • Coverage extends to modern OCaml 5 features (domains, effects, OxCaml extensions)

The book is organized into seven parts that can be read sequentially or used as a reference:

PartChaptersTopics
I1–4OCaml essentials, mathematics, probability
II5–8Fixed income, bonds, yield curves, rates derivatives
III9–14Equity markets, Black-Scholes, Monte Carlo, volatility
IV15–17Credit risk, CDOs, multi-asset models
V18–21Market risk, Greeks, XVA, portfolio optimization
VI22–25Algorithmic trading, execution, HFT infrastructure
VII26–31Advanced stochastic calculus, ML, regulatory, OxCaml

Readers with OCaml experience may skim Chapters 1–2. Readers with finance experience may skim Chapters 5 and 9.


Part I: Foundations

Part II: Fixed Income and Interest Rates

Part III: Equity and Derivatives

Part IV: Credit and Multi-Asset

Part V: Risk Management

Part VI: Algorithmic Trading and Market Microstructure

Part VII: Advanced Topics

Appendices


Each chapter directory contains:

chXX-topic/
├── README.md        ← chapter text
├── lib/             ← reusable library modules
├── examples/        ← worked examples
├── exercises/       ← practice problems
└── benchmarks/      ← performance experiments

# Install dependencies
opam install core owl zarith menhir ppx_deriving

# Build all examples
cd quantitative-finance-with-ocaml
dune build

# Run tests
dune test

Throughout this book:

  • OCaml code is shown in syntax-highlighted blocks
  • Mathematical formulas use standard notation: $S_t$ for asset price at time $t$, $\sigma$ for volatility, $r$ for risk-free rate
  • Types are given in OCaml notation, e.g., float -> float -> float
  • Module paths are written Module.function, e.g., Black_scholes.price

Version 1.0 — February 2026. Corrections and contributions welcome via the project repository.

联系我们 contact @ memedata.com