src/ReflexLibs.Ai/src/finance/options/black76/rust/src/lognormal.rs
Injectable
NormDist trait: StandardNormDist (f64, erfc tail-stable) or StandardNormDistDecimal (128-bit). All pricing functions are generic over the normal distribution implementation. Result<T, Black76Error> — no silent NaN./// Black-76 call — actual code from lognormal.rs #[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)) }
src/ReflexLibs.Ai/src/finance/options/black76/cpp/black76.h
15 years in production.
constexpr inline noexcept. Every port validates against this implementation. Abramowitz & Stegun coefficients for normal CDF with extended precision tail behaviour.// Black-76 call — Heritage C++ (15 years production) constexpr inline double call_price( double F, double K, double D, double sigma, double T) noexcept { const auto total_vol = sigma * std::sqrt(T); const auto d1 = (std::log(F / K) + 0.5 * sigma * sigma * T) / total_vol; const auto d2 = d1 - total_vol; return D * (F * N(d1) - K * N(d2)); }
src/ReflexLibs.Ai/src/finance/options/black76/csharp/Lognormal.cs
At parity with Rust. Injectable
INormDist interface: ErfcNormDist (tail-stable) or DecimalNormDist (28-digit). OneOf<double, Black76Error> — Rustified, no exceptions.// Black-76 call — C# at parity with Rust [MethodImpl(MethodImplOptions.AggressiveInlining)] public static OneOf<double, Black76Error> PriceOfCallNd( INormDist nd, double forward, double strike, double timeToExpiry, double volatility) { if (forward <= 0) return Black76Error.NegativeForward; var tVol = volatility * Math.Sqrt(timeToExpiry); var d1 = Math.Log(forward / strike) / tVol + 0.5 * tVol; var d2 = d1 - tVol; return Math.Max(forward * nd.Cdf(d1) - strike * nd.Cdf(d2), 0); }
src/Xll.Ai.Nano.Math/nano-math-all-wasm/wit/nano-math.wit
WASM Interface Types define the typed boundary.
special-math.phi provides normal CDF, decimal-math provides 128-bit arithmetic. JS host injects phi into Black-76 via the WIT contract.// nano-math.wit — package xll-ai:nano-math@6.4.12 interface special-math { phi: func(x: f64) -> result<f64, math-error>; erfc: func(x: f64) -> result<f64, math-error>; } interface decimal-math { record decimal28 { lo: u32, mid: u32, hi: u32, flags: u32 } phi: func(x: f64) -> result<decimal28, math-error>; }
src/ReflexLibs.Ai/src/finance/options/black76/cuda/black76_cpu_fallback.cu.txt
__host__ __device__ dual-target: runs on CPU and GPU. Batch call+put pricing, one thread per option. Time dilation computed on CPU, pre-dilated T[] passed to GPU kernel.// CUDA kernel — actual code from the repo __host__ __device__ inline float norm_cdf(float x) { return 0.5f * erfcf(-x * 0.70710678118654752440f); } __global__ void black76_kernel( int n, const float* F, const float* K, const float* T, const float* V, const float* DF, float* C, float* P) { int i = blockIdx.x * blockDim.x + threadIdx.x; if (i < n) black76_one(F[i], K[i], T[i], V[i], DF[i], C[i], P[i]); }
codegen/python/black76.py
Generated from MathIR TOML spec. Rustified style: tuple result, explicit NaN guard. Research bridge for prototyping with identical math to production Rust/C#.
# Generated from MathIR — same test vectors as Rust def call_price(F: float, K: float, D: float, sigma: float, T: float) -> MathResult: if math.isnan(F): return (False, float('nan')) total_vol = sigma * math.sqrt(T) d1 = (math.log(F / K) + 0.5 * sigma**2 * T) / total_vol d2 = d1 - total_vol return (True, D * (F * norm_cdf(d1) - K * norm_cdf(d2)))
codegen/excel/BLACK76.CALL.lambda
Pure Excel LAMBDA, no VBA, no add-in. Paste into Name Manager. Same formula, same test vectors. Traders can validate in their own spreadsheet.
BLACK76.CALL = LAMBDA(F, K, D, sigma, T, LET( tv, sigma * SQRT(T), d1, (LN(F/K) + 0.5*sigma^2*T) / tv, d2, d1 - tv, D * (F * NORM.S.DIST(d1,1) - K * NORM.S.DIST(d2,1)) ) )