pub struct EquityOption {
pub base: EquityOptionBase,
pub market: EquityMarketData,
pub payoff: Box<dyn Payoff>,
pub engine: PricingEngine,
pub model: Model,
}Fields§
§base: EquityOptionBaseThe contract (and trade identity): pure data, never market state.
market: EquityMarketDataThe market this instrument is currently bound to.
payoff: Box<dyn Payoff>§engine: PricingEngineThe numerical method, carrying its own settings.
model: ModelThe dynamics of the underlying (GBM, local vol, or Heston with its parameters); consulted by the MC, FD and analytic engines.
Implementations§
Source§impl EquityOption
impl EquityOption
Sourcepub fn snapshot_market(&self) -> Market
pub fn snapshot_market(&self) -> Market
Snapshot this option’s embedded market objects into a typed
Market anchored at the option’s valuation date. Repricing under
the unmodified snapshot reproduces npv() exactly.
Sourcepub fn with_market(
&self,
market: &Market,
) -> Result<EquityOption, RustyQLibError>
pub fn with_market( &self, market: &Market, ) -> Result<EquityOption, RustyQLibError>
This contract rebound to market: spot, vol surface and discount
curve are taken from the store (by symbol / currency code) and the
valuation date from the snapshot; contract terms and engine are
unchanged. Errors name the missing key when the market lacks data
for this option.
The model moves with the market where it must: a Heston model’s
parameters follow the surface’s parallel shift (measured at this
contract’s strike and maturity) via
Model::with_vol_shift,
so vol scenarios reach Heston-priced positions without
recalibration.
The market’s objects are expected to be anchored at its valuation
date (as snapshot_market guarantees).
Source§impl EquityOption
impl EquityOption
Sourcepub fn from_json(data: &EquityOptionData) -> Box<EquityOption>
pub fn from_json(data: &EquityOptionData) -> Box<EquityOption>
Build an option from contract data, panicking on any invalid field.
Fallible callers (batch pricing, services) should use
EquityOption::try_from_json.
Sourcepub fn try_from_json(
data: &EquityOptionData,
) -> Result<Box<EquityOption>, RustyQLibError>
pub fn try_from_json( data: &EquityOptionData, ) -> Result<Box<EquityOption>, RustyQLibError>
Build an option from contract data, reporting the offending field in the error instead of panicking.
This is a thin translation layer: it parses JSON-level fields
(dates, enum strings) into typed values and feeds them through
EquityOptionBuilder, which owns all domain validation and
assembly — both construction paths share one set of checks.
Source§impl EquityOption
impl EquityOption
pub fn time_to_maturity(&self) -> f64
Sourcepub fn maturity_discount_factor(&self) -> f64
pub fn maturity_discount_factor(&self) -> f64
Discount factor from the valuation date to maturity, off the curve.
Sourcepub fn risk_free_rate(&self) -> f64
pub fn risk_free_rate(&self) -> f64
Continuously compounded zero rate to maturity implied by the curve.
This is the r that enters d1/d2; it is consistent with
maturity_discount_factor by construction.
Sourcepub fn carry_yield(&self) -> f64
pub fn carry_yield(&self) -> f64
Total continuous carry on the underlying: dividend yield plus borrow cost. This is the “q” every pricing formula uses.
Sourcepub fn pv_cash_dividends(&self) -> f64
pub fn pv_cash_dividends(&self) -> f64
Escrow value of the cash dividends with ex-dates inside the option’s life: the amount to carve out of spot so the risky stub reproduces the jump-model forward.
Each dividend is discounted at the net carry rate r - carry,
not the risk-free rate, so that the escrow accretes at the same rate
the risky stub grows (effective_spot is grown at r - carry in
forward_price). This makes the analytic
forward match the well-defined jump model
F = (S - D e^{-(r-carry)t}) e^{(r-carry)T} used by the FD and
path-wise Monte Carlo engines. With no continuous carry this
reduces to plain risk-free discounting.
Sourcepub fn effective_spot(&self) -> f64
pub fn effective_spot(&self) -> f64
Escrowed-model spot: the quoted spot minus the PV of cash dividends paid over the option’s life. This is the lognormal driver for the analytic and terminal-simulation engines.
Sourcepub fn forward_price(&self) -> f64
pub fn forward_price(&self) -> f64
Forward price of the underlying at maturity: escrowed spot grown at
the carry-adjusted rate, (S - PV(divs)) * exp((r - q - b) * T).
Sourcepub fn volatility(&self) -> f64
pub fn volatility(&self) -> f64
Black volatility for this option’s strike and expiry, read off the surface (a flat surface returns its single vol).
pub fn d1(&self) -> f64
pub fn d2(&self) -> f64
Source§impl EquityOption
impl EquityOption
Sourcepub fn try_imp_vol(&self, option_price: f64) -> Result<f64, RustyQLibError>
pub fn try_imp_vol(&self, option_price: f64) -> Result<f64, RustyQLibError>
Implied Black-Scholes volatility for option_price (safeguarded
Newton with arbitrage-bound checks); does not modify the option.
Sourcepub fn imp_vol(&mut self, option_price: f64) -> f64
pub fn imp_vol(&mut self, option_price: f64) -> f64
Implied vol for option_price; leaves the option holding a flat
surface at the solved vol. Panics on arbitrage-violating prices —
use try_imp_vol to handle those gracefully.
pub fn get_imp_vol(&mut self) -> f64
Source§impl EquityOption
Greeks route through the central sensitivity engine
(crate::equity::greeks): the FD and Binomial engines read
delta/gamma/theta off their own grid/tree with higher orders from
bumped solutions; the analytic engine uses the payoff-aware
Black-Scholes closed forms (including Black-76 futures); the bump
engines (Monte Carlo with common random numbers, BAW,
Bjerksund-Stensland, analytic Heston) share one set of
central-difference stencils with per-engine bump sizes.
impl EquityOption
Greeks route through the central sensitivity engine
(crate::equity::greeks): the FD and Binomial engines read
delta/gamma/theta off their own grid/tree with higher orders from
bumped solutions; the analytic engine uses the payoff-aware
Black-Scholes closed forms (including Black-76 futures); the bump
engines (Monte Carlo with common random numbers, BAW,
Bjerksund-Stensland, analytic Heston) share one set of
central-difference stencils with per-engine bump sizes.
pub fn delta(&self) -> f64
pub fn gamma(&self) -> f64
pub fn vega(&self) -> f64
pub fn theta(&self) -> f64
pub fn rho(&self) -> f64
Sourcepub fn gamma_p(&self) -> f64
pub fn gamma_p(&self) -> f64
Delta elasticity (S * gamma / delta), also called percentage gamma.
Sourcepub fn volga(&self) -> f64
pub fn volga(&self) -> f64
Volga (vomma): change in vega per unit change in implied volatility.
Sourcepub fn price_with(
&self,
d_spot: f64,
d_vol: f64,
d_rate: f64,
d_time: f64,
) -> f64
pub fn price_with( &self, d_spot: f64, d_vol: f64, d_rate: f64, d_time: f64, ) -> f64
Reprice under a shifted market: spot + d_spot, a parallel implied
vol shift + d_vol, rate + d_rate, and d_time years of elapsed
calendar time. price_with(0, 0, 0, 0) is the base price; the
portfolio PnL attribution uses the difference of the two.
Monte Carlo repricing uses common random numbers, so the difference is free of sampling noise.
Trait Implementations§
Source§impl Clone for EquityOption
impl Clone for EquityOption
Source§impl Debug for EquityOption
impl Debug for EquityOption
Source§impl Instrument for EquityOption
impl Instrument for EquityOption
Source§fn price(&self) -> Result<PricingResult, RustyQLibError>
fn price(&self) -> Result<PricingResult, RustyQLibError>
Value, all nine Greeks, and (on the Monte Carlo engine) the
standard error, from one call — batched through the central
sensitivity engine (crate::equity::greeks), which shares
solves and reprices across the Greeks.
Source§fn try_npv(&self) -> Result<f64, RustyQLibError>
fn try_npv(&self) -> Result<f64, RustyQLibError>
Source§fn npv(&self) -> f64
fn npv(&self) -> f64
Instrument::try_npv.