nx_fin_risk_engine.nx
buildroot/runtime/nx_fin_risk_engine.nx
about
nx_fin_risk_engine.nx -- R4: POSITION SIZING + drawdown circuit breaker = the real answer to "don't blow up".
All i64 (cents / basis-points), NO floats. Sizers: (1) fractional-KELLY from the backtest's edge stats,
(2) fixed-RISK-per-trade (the "1% rule": size so a stop-out costs a bounded % of equity), (3) Kelly-fraction ->
shares. Plus a max-DRAWDOWN circuit breaker that HALTS sizing once equity has fallen past a limit, and an
ADV cap (composes R1 md_capacity) so every size respects the scaling wall. Single-responsibility: sizes ONE
position; portfolio-level diversification is nx_fin_portfolio. license_tier: ORIGINAL
dependencies 2 imports · 1 importers
imports: nx_syscalls.nxnx_fin_marketdata.nx
imported by: nx_fin_risk_engine_gate.nx
structs
| none |
consts
| 9 | const K_MAGIC_10000: i64 = 10000 |
functions
| 13 | func re_kelly_bps(win_rate_bps: i64, avg_win_cents: i64, avg_loss_cents: i64) -> i64 called by 1: main |
| 25 | func re_frac_kelly(kelly_bps: i64, frac_bps: i64) -> i64 { return kelly_bps*frac_bps/K_MAGIC_10000 } called by 1: main |
| 28 | func re_size_by_risk(equity_cents: i64, risk_budget_bps: i64, entry_cents: i64, stop_cents: i64) -> i64 called by 1: main |
| 36 | func re_size_by_kelly(equity_cents: i64, frac_bps: i64, price_cents: i64) -> i64 called by 1: main |
| 43 | func re_dd_ok(current_dd_bps: i64, limit_bps: i64) -> i64 { if current_dd_bps >= limit_bps { return 0 } return 1 } called by 1: main |
| 46 | func re_cap_shares(shares: i64, price_cents: i64, adv_cents: i64, participation_bps: i64) -> i64 |