nx_fin_bs.nx
buildroot/runtime/nx_fin_bs.nx
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
imports: nx_syscalls.nxnx_fin_metrics.nx
imported by: nx_fin_assets.nxnx_fin_assets_gate.nxnx_fin_bs_gate.nx
structs
| none |
consts
| 10 | const FP: i64 = 1000000 |
| 11 | const E_FP: i64 = 2718282 // e * 1e6 |
| 12 | const LN2_FP: i64 = 693147 // ln 2 * 1e6 |
| 13 | const INV_SQRT2PI: i64 = 398942 // 1/sqrt(2*pi) * 1e6 |
| 14 | const NP: i64 = 231642 // A&S p = 0.2316419 |
| 15 | const NB1: i64 = 319382 |
| 16 | const NB2: i64 = 0 - 356564 |
| 17 | const NB3: i64 = 1781478 |
| 18 | const NB4: i64 = 0 - 1821256 |
| 19 | const NB5: i64 = 1330274 |
functions
| 22 | func exp_fp(x: i64) -> i64 |
| 35 | func ln_fp(x: i64) -> i64 |
| 48 | func bs_sqrt_fp(x: i64) -> i64 { return me_isqrt(x * FP) } |
| 51 | func bs_ncdf(x: i64) -> i64 |
| 69 | func bs_srt(sigma: i64, T: i64) -> i64 { return sigma * bs_sqrt_fp(T) / FP } |
| 70 | func bs_d1(S: i64, K: i64, r: i64, sigma: i64, T: i64) -> i64 |
| 79 | func bs_call(S: i64, K: i64, r: i64, sigma: i64, T: i64) -> i64 |
| 86 | func bs_put(S: i64, K: i64, r: i64, sigma: i64, T: i64) -> i64 |
| 93 | func bs_delta_call(S: i64, K: i64, r: i64, sigma: i64, T: i64) -> i64 { return bs_ncdf(bs_d1(S, K, r, sigma, T)) } |