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 oneResultper 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:
| Field | Description |
|---|---|
| price | Model fair value of the contract. |
| delta | First-order spot sensitivity, dV/dS. |
| gamma | Second-order spot sensitivity, d²V/dS². |
| theta | Time decay, per calendar day. |
| vega | Raw dV/dσ (not per vol point). |
| rho | dV/dr against the continuously-compounded rate. |
| vanna | Cross sensitivity d²V/(dS dσ). |
| volga | Second-order vol sensitivity (vomma), d²V/dσ². |
| charm | Delta decay d²V/(dS dt), per calendar day. |
| veta | Vega decay d²V/(dσ dt), per calendar day. |
| color | Gamma 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
vegaandrho. greeks_allshares kernels with the individual scalar Greek functions, so its output matches calling them separately.volatilityis model-specific: for Heston it issqrt(v0)(vega is per unitsqrt(v0)); for jump-diffusion it is the diffusive σ, so vega measures diffusive-vol sensitivity only.- Errors:
InvalidInput { param, value }for out-of-range inputs;UnsupportedModelExerciseCombinationfor 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.