/// Black-76 call — actual code from ReflexLibs.Ai/options/black76 /// High-precision NormDist injectable: StandardNormDist (f64, erfc tail-stable) /// or StandardNormDistDecimal (128-bit, 28-digit arithmetic) #[inline] pub fn price_of_call_nd<N: NormDist>( nd: &N, forward: f64, strike: f64, time_to_expiry: f64, volatility: f64, ) -> Result<f64, Black76Error> { if forward <= 0.0 { return Err(Black76Error::NegativeForward); } let t_vol = volatility * time_to_expiry.sqrt(); let d1 = (forward / strike).ln() / t_vol + 0.5 * t_vol; let d2 = d1 - t_vol; Ok((forward * nd.cdf(d1) - strike * nd.cdf(d2)).max(0.0)) } // f64 — StandardNormDist (erfc-based, tail-stable) let price = price_of_call_nd(&StandardNormDist, F, K, T_market, sigma)?; // Decimal128 — StandardNormDistDecimal (28-digit arithmetic) let price = lognormal_decimal::price_of_call_nd( &StandardNormDistDecimal, F, K, T_market, sigma)?; // Time-dilated — FOMC/NFP event warping baked into T let T_market = dilation.scale_interval(now, expiry); let price = price_of_call_nd(&StandardNormDist, F, K, T_market, sigma)?;
// Two ports, one MathIR — dual provenance for every future stochastic-vol family
public static class HestonNormalFromPaper { // Path A — SSRN 2445328, negative-i
public static double PriceOfCall(double F, double K, double tau, /* ... */) { /* ... */ }
// Φ(τ,u,ν₀) = exp(C(τ) + D(τ)ν₀ − iu·x₀) ← paper convention
}
public static class HestonNormalFromHeritage { // Path B — heritage, positive-i
public static double PriceOfCall(double F, double K, double tau, /* ... */) { /* ... */ }
// phi(u) = exp(cv + dv·v0 + i·u·forward), called with −u ← heritage convention
}
// Cross-check: |A − B| < 1e-10 on 25 randomised parameter sweeps.
// Sidani Table 1: reproduced at 5e-5 by BOTH paths. Heritage vectors: 1e-9.// Priority: explicit Version > AsOf-inferred > default (V2)
public static bool IsCoicopValidAsOf(string coicop, EcoicopVersion version)
=> coicop switch {
"CP023" => version is V2 or V3, // COICOP 2018 — from Feb 2026
"CP022" => version is V1, // COICOP 1999 — pre Feb 2026
_ => true // era-independent
};use rust_decimal_macros::dec;
// Exact decimal arithmetic — no float rounding
let result = dec!(0.1) + dec!(0.2);
assert_eq!(result, dec!(0.3)); // ✓ exact
// C# cross-validation:
// decimal r = 0.1m + 0.2m;
// Debug.Assert(r == 0.3m); // ✓ same result