code wiki / (root) / nx_fin_bs.nx

nx_fin_bs.nx

buildroot/runtime/nx_fin_bs.nx

4021 B93 linesdepth 3pulls 3 transitivereach 3 importersview sourcekind librarytopic fin
docsdependenciesstructsconstsfunctions

about

nx_fin_bs.nx -- OPTIONS pricing (Black-Scholes) in integer fixed-point (scale 1e6 = "micro"), the hard transcendental suite the float-free runtime lacked: exp, ln, fixed-point sqrt (via me_isqrt), and the standard normal CDF (Abramowitz-Stegun 26.2.17). Then European call/put price + call delta. Verified to ~0.01% against known values (N(1)=.8413, exp(1)=2.71828, ln(e)=1, BS[100,100,.05,.20,1]call=10.45). Moves asset-class depth from BEHIND toward parity (options greeks). Reusable well beyond options: the normal CDF is the keystone for PSR / VaR / Merton / confidence intervals. Composes nx_fin_metrics (me_isqrt). license_tier: ORIGINAL

dependencies 2 imports · 3 importers

nx_syscalls.nx nx_fin_metrics.nx nx_fin_bs.nx nx_fin_assets.nx nx_fin_assets_gate.nx nx_fin_bs_gate.nx

imports: nx_syscalls.nxnx_fin_metrics.nx

imported by: nx_fin_assets.nxnx_fin_assets_gate.nxnx_fin_bs_gate.nx

structs

none

consts

10const FP: i64 = 1000000
11const E_FP: i64 = 2718282 // e * 1e6
12const LN2_FP: i64 = 693147 // ln 2 * 1e6
13const INV_SQRT2PI: i64 = 398942 // 1/sqrt(2*pi) * 1e6
14const NP: i64 = 231642 // A&S p = 0.2316419
15const NB1: i64 = 319382
16const NB2: i64 = 0 - 356564
17const NB3: i64 = 1781478
18const NB4: i64 = 0 - 1821256
19const NB5: i64 = 1330274

functions

22func exp_fp(x: i64) -> i64
35func ln_fp(x: i64) -> i64
called by 2: bs_d1main
48func bs_sqrt_fp(x: i64) -> i64 { return me_isqrt(x * FP) }
called by 2: bs_srtmain calls 1: me_isqrt
51func bs_ncdf(x: i64) -> i64
69func bs_srt(sigma: i64, T: i64) -> i64 { return sigma * bs_sqrt_fp(T) / FP }
called by 3: bs_d1bs_callbs_put calls 1: bs_sqrt_fp
70func bs_d1(S: i64, K: i64, r: i64, sigma: i64, T: i64) -> i64
79func bs_call(S: i64, K: i64, r: i64, sigma: i64, T: i64) -> i64
called by 1: main calls 4: bs_d1bs_srtexp_fpbs_ncdf
86func bs_put(S: i64, K: i64, r: i64, sigma: i64, T: i64) -> i64
called by 1: main calls 4: bs_d1bs_srtexp_fpbs_ncdf
93func bs_delta_call(S: i64, K: i64, r: i64, sigma: i64, T: i64) -> i64 { return bs_ncdf(bs_d1(S, K, r, sigma, T)) }
called by 1: main calls 2: bs_ncdfbs_d1