nx_fin_assets.nx source
↩ module page · 26 lines · 1493 B
1// nx_fin_assets.nx -- multi-asset FORWARD pricing, closing the loop on the operator's original ask ("trade
2// anything: commodities, stocks, forex..."). FUTURES/commodities forward via cost-of-carry F = S*e^((r+carry)T)
3// (carry = storage - convenience yield); FX forward via covered interest parity F = S*e^((r_dom-r_for)T); plus
4// basis and contango/backwardation. Composes the verified exp_fp from nx_fin_bs (integer fixed-point, scale 1e6).
5// So equities (backtest), options (Black-Scholes), futures/commodities and forex are now all modeled sovereignly
6// and integer-exact. license_tier: ORIGINAL
7import "nx_syscalls.nx"
8import "nx_fin_bs.nx"
9
10// futures / commodity forward (micro-$): F = S * e^((r+carry)*T). carry can be negative (net convenience yield).
11func af_futures_fwd(spot: i64, r: i64, carry: i64, T: i64) -> i64 {
12 let expo: i64 = (r + carry) * T / FP
13 return spot * exp_fp(expo) / FP
14}
15
16// FX forward (micro): F = S * e^((r_dom - r_for)*T). Higher domestic rate -> forward premium.
17func af_fx_fwd(spot: i64, r_dom: i64, r_for: i64, T: i64) -> i64 {
18 let expo: i64 = (r_dom - r_for) * T / FP
19 return spot * exp_fp(expo) / FP
20}
21
22// basis = forward - spot (micro-$). Positive => contango; negative => backwardation.
23func af_basis(fwd: i64, spot: i64) -> i64 { return fwd - spot }
24
25// 1 if the term structure is in CONTANGO (forward above spot), else 0 (backwardation / flat).
26func af_contango(fwd: i64, spot: i64) -> i64 { if fwd > spot { return 1 } return 0 }