Use case · Pricing

Price a contract, read all ten Greeks

greeks_all takes one typed PricingInputs and a named PricingModel and returns the price plus the complete first- and second-order Greek surface — all on one shared evaluation path, with no per-Greek bumping at the call site.

When to use it

  • You need price plus all ten Greeks for one contract and want a single, consistent evaluation rather than ten separate scalar calls.
  • You want the model selected by name so the crate picks the analytical vs. numerical Greek path for you.
  • For many contracts, prefer greeks_batch(&[(PricingInputs, PricingModel)]), which fans the same call out in parallel and returns one Result per contract without short-circuiting on a failure.

Example

use ferro_risk::{ExerciseStyle, OptionType, PricingInputs, PricingModel, greeks_all};

let inputs = PricingInputs {
    option_type: OptionType::Call,
    exercise_style: ExerciseStyle::European,
    spot: 100.0,
    strike: 100.0,
    time_to_expiry: 30.0 / 365.0, // years
    rate: 0.05,                   // continuously compounded
    dividend_yield: 0.0,
    volatility: 0.20,
};

let g = greeks_all(&inputs, PricingModel::BlackScholesMerton)?;

println!("price = {}", g.price);
println!("delta {}  gamma {}  vega {}  rho {}", g.delta, g.gamma, g.vega, g.rho);
println!("theta/day {}", g.theta);
println!("vanna {}  volga {}", g.vanna, g.volga);
println!("charm {}  veta {}  color {}", g.charm, g.veta, g.color);
# Ok::<(), ferro_risk::FerroRiskError>(())

The Greek surface

The Greeks struct carries price plus ten sensitivities, all f64:

FieldDescription
priceModel fair value of the contract.
deltaFirst-order spot sensitivity, dV/dS.
gammaSecond-order spot sensitivity, d²V/dS².
thetaTime decay, per calendar day.
vegaRaw dV/dσ (not per vol point).
rhodV/dr against the continuously-compounded rate.
vannaCross sensitivity d²V/(dS dσ).
volgaSecond-order vol sensitivity (vomma), d²V/dσ².
charmDelta decay d²V/(dS dt), per calendar day.
vetaVega decay d²V/(dσ dt), per calendar day.
colorGamma decay d³V/(dS² dt), per calendar day.

Notes

  • Units follow the conventions: time in years, continuously-compounded rates, per-calendar-day theta / charm / veta / color, raw vega and rho.
  • greeks_all shares kernels with the individual scalar Greek functions, so its output matches calling them separately.
  • volatility is model-specific: for Heston it is sqrt(v0) (vega is per unit sqrt(v0)); for jump-diffusion it is the diffusive σ, so vega measures diffusive-vol sensitivity only.
  • Errors: InvalidInput { param, value } for out-of-range inputs; UnsupportedModelExerciseCombination for an unsupported model / exercise-style pairing.
Batch

greeks_batch(contracts: &[(PricingInputs, PricingModel)]) -> Vec<Result<Greeks, FerroRiskError>> preserves input order, runs in parallel via Rayon, and isolates errors per contract.