optionrs
A high-performance, production-grade option pricing library for Rust, supporting classic pricing models (Black-Scholes, Binomial Tree, Monte Carlo, PDE numerical calculation) and exotic options (barrier, Asian, forward-start,etc).
Features
- Core Pricing Models:
- Black-Scholes (European calls/puts, Greeks, implied volatility)
- Binomial Tree (European/American options, Delta/Gamma)
- Monte Carlo Simulation (European/exotic options, path-dependent pricing)
- Exotic Options: Barrier, Asian (discrete geometric average), forward-start options
- Numerical Stability: Robust boundary condition handling (T=0, sigma=0)
- Type Safety: Clear, documented APIs with financial semantics
- Test Coverage: Full unit/integration/doc tests, validated against classic financial benchmarks
Usage
Simply implement the market parameters,payoff function, exercise type and boundary condition for the option in the src/products/ directory, and the pricing engine can be use to complete.
Taking European call option as example
- option parameters
- payoff function
which is in use crate::traits::payoff directory
-
exercise type The definition of the rule is in src/traits/exercise EuropeanExercise and AmericanExercise
-
boundary condition
- example
use *;
use EuropeanCall;
Installation
Add this to your Cargo.toml:
[]
= "1.1.0"
= { = "0.18.3", = ["rayon"]}
= "0.1.5"
= "0.9.2"
= "0.5.1"
= "1.11.0"
= "0.18.0"
= "2.0.17"
Module Catalog
src/
├── lib.rs # Library entry point 库入口,导出公共API
├── errors.rs # Error handling mechanisms 错误处理机制
├── products/ # Product layer: Defines specific option products 产品层:定义具体期权产品
│ ├── mod.rs
│ ├── european_call.rs # European call option欧式看涨期权
│ ├── american.rs # 美式期权
│ ├── barrier.rs # 障碍期权
│ ├── lookback.rs # 回望期权
│ ├── spread.rs # 价差期权
│ └── exotic.rs # 其他奇异期权
├── core/ # Engine layer: Pricing engine implementations 引擎层:定价引擎实现
│ ├── mod.rs
│ ├── pde.rs
│ ├── pde/ # PDE solver engine PDE求解引擎
│ │ ├── mod.rs
│ │ ├── engine.rs
│ │ └── methods/
│ │ ├── mod.rs
│ │ ├── explicit.rs
│ │ ├── implicit.rs
│ │ └── crank_nicolson.rs
│ ├── binomial.rs # Binomial tree engine 二叉树引擎
│ ├── monte_carlo.rs # Mento carlo engine 蒙特卡洛引擎
│ ├── analytic/ # Analytic engine core 解析解引擎核心
│ │ ├── mod.rs
│ │ ├── engine.rs # Pluggable AnalyticEngine 插件化AnalyticEngine(计算器注册表)
│ │ └── calculators/ # Analytic calculators 各类解析解计算器(插件)
│ │ ├── mod.rs
│ │ ├── vanilla.rs # 普通期权计算器
│ │ ├── binary.rs # 二元期权计算器
│ │ └── barrier.rs # 障碍期权计算器
│ └── engine_config.rs # unified entry point enum for all engines 所有引擎的统一入口枚举
├── params/ # Paramters layer: Parameter definitions and validation 参数层:参数定义与验证
│ ├── mod.rs
│ └── common.rs # Common parameters 通用参数
├── traits/ # Abstraction Layer 抽象接口层
│ ├── mod.rs
│ ├── payoff.rs # Payoff abstraction + analytic solution type enums Payoff抽象+解析解类型枚举
│ ├── exercise.rs # Exercise rule abstruction traits 行权规则抽象 trait
│ ├── process.rs # Stochatic process trait 随机过程 trait
│ └── engine.rs # Pricing engines traits 定价引擎trait
├── utils/ # 工具层:数学工具
│ ├── mod.rs
│ ├── statistics.rs # 正态分布CDF/PDF、参数校验
│ ├── math.rs # 数学工具函数
│ └── linear_algebra.rs # 线性代数工具(预留)
└── simulation/ # Stochastic process simulation 随机过程模拟
├── mod.rs
├── browian.rs # 布朗运动
├── time_series.rs # 传统时序模型,garch等
└── stochastic_volatility.rs # 随机波动率模型