quant_opts/models/
mod.rs

1//! Pricing models available in `quant-opts`.
2//!
3//! For now this module provides a Black–Scholes–Merton implementation
4//! for vanilla options. Additional models (e.g. SABR) can be added
5//! alongside it while reusing the core domain types.
6//!
7//! The [`VanillaModel`] trait defines a generic interface for
8//! vanilla option models. Concrete models like [`black_scholes::BlackScholes`]
9//! implement this trait so callers can write code generic over the model.
10
11use crate::core::{Greeks, MarketData, VanillaOption};
12
13/// Core abstraction for a model that can price vanilla options.
14///
15/// This trait is intentionally conservative in scope for now:
16/// - it operates only on the core domain types,
17/// - it does not prescribe any particular volatility parametrisation,
18/// - it exposes fallible operations via `Result` so callers can
19///   handle invalid inputs explicitly.
20pub trait VanillaModel {
21    /// Price a vanilla option under this model.
22    fn price(&self, opt: &VanillaOption, mkt: &MarketData) -> Result<f64, String>;
23
24    /// Compute a set of Greeks for a vanilla option.
25    fn greeks(&self, opt: &VanillaOption, mkt: &MarketData) -> Result<Greeks, String>;
26
27    /// Compute implied volatility such that the model price matches `target_price`.
28    fn implied_vol(
29        &self,
30        target_price: f64,
31        opt: &VanillaOption,
32        mkt: &MarketData,
33    ) -> Result<f64, String>;
34}
35
36pub mod black_scholes;