stochastic-rs
Concepts

ModelPricer

The pricing trait — the struct holds model parameters and each call carries its own (s, k, r, q, tau) query, so one model prices a whole grid.

The single-underlying pricing trait. A plain f64 trait, not generic over T: FloatExt.

pub trait ModelPricer {
  fn price_call(&self, s: f64, k: f64, r: f64, q: f64, tau: f64) -> f64;

  // override unless the carry is e^{-qτ} and exercise European (below)
  fn price_put(&self, s: f64, k: f64, r: f64, q: f64, tau: f64) -> f64 {
    let call = self.price_call(s, k, r, q, tau);
    call - s * (-q * tau).exp() + k * (-r * tau).exp()
  }

  fn price_option(&self, s: f64, k: f64, r: f64, q: f64, tau: f64, option_type: OptionType) -> f64 {
    match option_type {
      OptionType::Call => self.price_call(s, k, r, q, tau),
      OptionType::Put => self.price_put(s, k, r, q, tau),
    }
  }
}

Model, then query

The struct holds model parameters only — BsmPricer holds a volatility and a cost-of-carry convention, HestonPricer holds (v0,κ,θ,σ,ρ)(v_0,\kappa,\theta,\sigma,\rho). The contract (spot, strike, rate, dividend yield, maturity) is not baked in; every price query passes its own (s, k, r, q, tau). One model instance therefore prices a whole strike/maturity grid — vol-surface construction, calibration — with no &dyn and no Box<dyn>.

A pricer whose one computation yields both legs (HestonPricer, Merton1976Pricer, HestonStochCorrPricer, GbmMalliavinPricer) also has an inherent price_call_put(s, k, r, q, tau) -> CallPut { call, put }.

Override price_put unless parity holds

The default price_put recomposes the put from the call by European put-call parity with a carry factor of exactly e−qτe^{-q\tau}. Two kinds of pricer must override it, or the default misprices silently:

  • Non-standard cost of carry — BsmPricer, AsianPricer and Merton1976Pricer carry at e(b−r)τe^{(b-r)\tau}, which equals e−qτe^{-q\tau} only when b=r−qb = r - q.
  • American exercise — BjerksundStensland2002Pricer, SnellEnvelopePricer and FiniteDifferencePricer price a put with an early-exercise premium the call does not carry, so European parity is the wrong model.

ModelPricer fixes the query shape, not the exercise right; exercise style is the implementor's choice.

Blanket implementations

  • impl<T: FourierModelExt> ModelPricer for T — any model with a characteristic function is priced by LewisPricer, Lewis (2001), less a Gaussian control; GilPelaezPricer prices the same model by Gil–Pelaez's inversion.
  • impl<T: VanillaEuropeanCall + ?Sized> ModelSurface for T — any model that asserts it is a European vanilla call gets vol_surface(s, r, q, strikes, maturities). A ModelPricer that is not one (a digital, an American put) has no such method.

ToModel turns a calibration result into the concrete ModelPricer it determines:

pub trait ToModel {
  type Model: ModelPricer;
  fn to_model(&self) -> Self::Model;
}

Bonds and multi-asset payoffs

ModelPricer's query has one underlying and one strike, so two families sit outside it:

  • Short-rate bonds (Vasicek, Cir, HullWhite) implement ShortRatePricer instead — they price off a short rate and a tenor, not a spot and a strike.
  • Multi-asset payoffs (MargrabePricer, KirkSpreadPricer, McSpreadPricer, the basket and rainbow pricers) carry no pricing trait: MargrabePricer has no strike, KirkSpreadPricer strikes against a spread of two forwards, and the basket and rainbow pricers take N legs. Each holds its volatilities and correlation and takes the spots, strike, rate, yields and maturity per call through inherent methods; every Monte Carlo member returns an McEstimate — the mean, its standard error and ci_95(). KirkSpreadPricer's methods are spread_call_put / spread_call / spread_put with the query (f1, f2, x, r, tau).

The path-dependent family (barriers, lookbacks, cliquets, autocallables, Bermudans, chooser, compound, variance/volatility swaps) has no pricing trait either: the closed forms hold the model and take a contract from pricing::exotic beside the part of the (s, r, q, tau) query they read (the cliquet reads no spot, and the complex chooser's contract holds its maturities), the variance and volatility swaps' functions take what they read, and the Monte Carlo pricers take the same contracts: McBarrierPricer a BarrierOption at (s, r, q, tau), McCliquetPricer a CliquetOption at (r, q, tau) and AutocallablePricer an AutocallableNote at (s, r, q), the note's last observation date being its maturity.

Greeks

A pricer's Greeks follow the same model/query split as its prices: inherent methods taking the query. BsmPricer, HestonPricer, Merton1976Pricer, CashOrNothingPricer and AssetOrNothingPricer each expose greeks(s, k, r, q, tau, option_type) -> Greeks, one signature across all five, alongside per-Greek accessors of the same shape. Greeks is a plain f64 struct of nine named fields (delta, gamma, vega, theta, rho, vanna, charm, volga, veta), NaN where the pricer exposes nothing. At tau = 0 these five price the payoff and every field of Greeks is NaN: an expired option has a value and no sensitivity.

GreeksExt is not that interface. Its accessors take &self and nothing else and return Option<McEstimate<f64>>, the estimate with its standard error, so only an estimator that owns its query can implement it: the Monte Carlo Malliavin pair GbmMalliavinGreeks and HestonMalliavinGreeks, whose greeks() runs one simulation so the estimates share their paths. Import it from stochastic_rs::traits::GreeksExt; it is not in the prelude.

TimeExt — dates to tau

ModelPricer takes tau in years. An instrument holds a Maturity, either Tau(years) or Dates { eval, expiry }; TimeExt::tau() resolves it to τ\tau under the instrument's day count (Actual/365 Fixed by default), and tau_with_dcc(dcc) overrides the convention. Convert at the call site, then price.

The instruments EuropeanOption and DigitalOption implement it; pricers do not, since they hold model state and receive τ\tau as a query argument.

See also

Edit on GitHub

Last updated on

On this page