code wiki / (root) / nx_fin_universe.nx

nx_fin_universe.nx source

↩ module page · 44 lines · 2451 B

1// nx_fin_universe.nx -- the UNIVERSE-SELECTION brain: given a scored candidate set (one row per symbol, each 2// carrying its screen verdict + backtest metrics + the honest-edge gates), decide WHICH names are actually 3// tradeable and rank them. This is "1000 microcaps -> the few worth capital", and it is HONEST BY CONSTRUCTION: 4// a name qualifies ONLY if it (1) passed the quality screen, (2) has a DEFLATED-Sharpe-significant edge, and 5// (3) has a PBO below the overfit ceiling. No name gets capital on an unproven or overfit edge. Pure ranking 6// (i64); the LIVE multi-symbol fetch that fills the candidate rows is a thin driver awaiting a real data key. 7// Composes nx_fin_microcap (screen verdict), nx_fin_advstats (deflated-significance), nx_fin_pbo (overfit prob). 8// license_tier: ORIGINAL 9import "nx_syscalls.nx" 10const UV_MAGIC_10000: i64 = 10000 11const UV_MAGIC_1000000000000: i64 = 1000000000000 12 13const UV_SCREEN_PASS: i64 = 0 // matches MC_PASS from nx_fin_microcap 14 15// tradeable iff passed the screen AND deflated-Sharpe-significant AND PBO below the overfit ceiling. 16func uv_qualifies(screen_verdict: i64, deflated_sig: i64, pbo_permille: i64, max_pbo_permille: i64) -> i64 { 17 if screen_verdict != UV_SCREEN_PASS { return 0 } 18 if deflated_sig != 1 { return 0 } 19 if pbo_permille >= max_pbo_permille { return 0 } 20 return 1 21} 22 23// risk-adjusted rank score (Calmar-like): return per unit of max-drawdown. Higher = better. 24func uv_score(ret_bps: i64, maxdd_bps: i64) -> i64 { return ret_bps * UV_MAGIC_10000 / (maxdd_bps + 1) } 25 26// select the top-k QUALIFIED candidates by score into out_idx (descending). Returns the count selected 27// (< k if fewer than k qualify -- never pads with unqualified names). 28func uv_select_topk(scores: *i64, qualified: *i64, n: i64, k: i64, out_idx: *i64) -> i64 { 29 let picked: *i64 = sys_mmap(8*n) as *i64 30 var i: i64 = 0; while i < n { picked[i] = 0; i = i + 1 } 31 var sel: i64 = 0; var stop: i64 = 0 32 while stop == 0 { 33 if sel >= k { stop = 1 } else { 34 var best: i64 = 0 - 1; var bscore: i64 = 0 - UV_MAGIC_1000000000000 35 var j: i64 = 0 36 while j < n { 37 if qualified[j] == 1 { if picked[j] == 0 { if scores[j] > bscore { bscore = scores[j]; best = j } } } 38 j = j + 1 39 } 40 if best < 0 { stop = 1 } else { out_idx[sel] = best; picked[best] = 1; sel = sel + 1 } 41 } 42 } 43 return sel 44}