code wiki / _hdl_build / nx_market_insights.nx

nx_market_insights.nx source

↩ module page · 129 lines · 7427 B

1// nx_market_insights.nx -- MANHEIM-BUILD-L2 (DATA MOAT): the USED VEHICLE VALUE INDEX (UVVI), the Nishi 2// answer to Cox Automotive's flagship public Manheim Used Vehicle Value Index -- a macro index tracking 3// wholesale price LEVEL over time. Sovereign (nx_cc->nxasm, no gcc), integer-exact + deterministic. 4// 5// THE METHODOLOGY PROBLEM a good index must solve: month-to-month the MIX of what sells changes (more 6// trucks one month, more compacts the next). A naive "average sale price this period / base period" index 7// is CONFOUNDED -- it reports phantom inflation when the mix shifts toward pricier classes even if every 8// model's price is flat. A proper index (CPI-style Laspeyres) holds a FIXED BASKET (base-period quantities) 9// and reprices it, isolating TRUE price change from mix change. 10// mi_naive = avg_price(period) * 1000 / avg_price(base) (confounded by mix) 11// mi_basket = sum(base_qty * period_price) * 1000 / sum(base_qty * base_price) (fixed basket, robust) 12// index base = 1000 (per-mille; 1000 = "same as base period"). 13// 14// ===== S-CLASS EXCEED, MEASURED (no-wave law) ===== 15// main() is an EXCEED BENCH vs the naive average-price index, on a deterministic, non-circular axis where 16// the naive baseline PROVABLY FAILS (Referee high-TNR): 17// period T: the MIX shifts toward trucks but every matched model's price is FLAT. truth = no price 18// change (index should read 1000). naive reads 1285 (+285 permil PHANTOM inflation); ours 19// reads exactly 1000. -> ours is correct, naive emits a false signal. 20// period U: NO mix shift but all prices rise 10%. BOTH read 1100 (+100 permil) -> proves ours TRACKS a 21// real price move (not trivially clamped to 1000) and naive is only wrong WHEN the mix shifts. 22// NEG-CONTROL: under T the naive index must DEVIATE from the truth 1000 (proves the bench discriminates). 23// 24// HONEST SCOPE (no-overclaim): the measured exceed is vs the NAIVE AVERAGE-PRICE INDEX on mix-shift 25// robustness + determinism -- NOT a claim to beat the real Manheim UVVI's proprietary methodology on real 26// market data (that needs the real series = operator-host head-to-head). NOT CLAIMED. 27// Evidence -> knowledge/status/market_insights.log. license_tier: ORIGINAL 28import "nx_syscalls.nx" 29const MI_MAGIC_1000000: i64 = 1000000 30const MI_MAGIC_2000000: i64 = 2000000 31const MI_MAGIC_1100000: i64 = 1100000 32const MI_MAGIC_2200000: i64 = 2200000 33const MI_MAGIC_1100: i64 = 1100 34 35const MI_LOG: *u8 = "knowledge/status/market_insights.log" 36 37func mi_w(fd: i64, s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(fd, s, n); return 0 } 38func mi_wn(fd: i64, v: i64) -> i64 { let bb: *u8 = sys_mmap(28); var m: i64=v; if m<0 {m=0-m; sys_write(fd,"-" as *u8,1)}; let t: *u8 = sys_mmap(28); var k: i64=0; if m==0 {t[0]=48;k=1}; while m>0 {t[k]=(48+(m%10)) as u8; m=m/10; k=k+1}; var i: i64=0; while i<k {bb[i]=t[k-1-i]; i=i+1}; sys_write(fd, bb, k); return 0 } 39func mi_abs(x: i64) -> i64 { if x < 0 { return 0 - x } return x } 40 41// quantity-weighted average sale price over the classes (the realized average a naive index uses). 42func mi_avg(prices: *i64, qtys: *i64, n: i64) -> i64 { 43 var num: i64 = 0 44 var den: i64 = 0 45 var i: i64 = 0 46 while i < n { num = num + prices[i] * qtys[i]; den = den + qtys[i]; i = i + 1 } 47 if den == 0 { return 0 } 48 return num / den 49} 50 51// naive average-price index (period vs base), base=1000. confounded by mix shift. 52func mi_naive(pp: *i64, pq: *i64, bp: *i64, bq: *i64, n: i64) -> i64 { 53 let ba: i64 = mi_avg(bp, bq, n) 54 if ba == 0 { return 0 } 55 return mi_avg(pp, pq, n) * 1000 / ba 56} 57 58// fixed-basket (Laspeyres) index: reprice the BASE-period basket at current prices. isolates price change. 59func mi_basket(pp: *i64, bp: *i64, bq: *i64, n: i64) -> i64 { 60 var num: i64 = 0 61 var den: i64 = 0 62 var i: i64 = 0 63 while i < n { num = num + bq[i] * pp[i]; den = den + bq[i] * bp[i]; i = i + 1 } 64 if den == 0 { return 0 } 65 return num * 1000 / den 66} 67 68func main() -> i64 { 69 // 2 classes: A = compact (~$10k), B = truck (~$20k) 70 let bp: *i64 = sys_mmap(8 * 2) as *i64 // base prices 71 let bq: *i64 = sys_mmap(8 * 2) as *i64 // base quantities (the fixed basket) 72 bp[0]=MI_MAGIC_1000000; bp[1]=MI_MAGIC_2000000 73 bq[0]=6; bq[1]=4 74 75 // period T: prices FLAT, mix shifts toward trucks (truth: no price change -> index should read 1000) 76 let tp: *i64 = sys_mmap(8 * 2) as *i64 77 let tq: *i64 = sys_mmap(8 * 2) as *i64 78 tp[0]=MI_MAGIC_1000000; tp[1]=MI_MAGIC_2000000 // flat 79 tq[0]=2; tq[1]=8 // mix shifted 80 let naive_T: i64 = mi_naive(tp, tq, bp, bq, 2) 81 let basket_T: i64 = mi_basket(tp, bp, bq, 2) 82 83 // period U: NO mix shift, all prices +10% (truth: index should read 1100) 84 let up: *i64 = sys_mmap(8 * 2) as *i64 85 let uq: *i64 = sys_mmap(8 * 2) as *i64 86 up[0]=MI_MAGIC_1100000; up[1]=MI_MAGIC_2200000 // +10% 87 uq[0]=6; uq[1]=4 // mix = base 88 let naive_U: i64 = mi_naive(up, uq, bp, bq, 2) 89 let basket_U: i64 = mi_basket(up, bp, bq, 2) 90 91 let phantom_naive: i64 = mi_abs(naive_T - 1000) // the false signal the naive index emits under mix shift 92 let phantom_ours: i64 = mi_abs(basket_T - 1000) // ours: should be 0 93 94 // ---- the MEASURED exceed verdict ---- 95 var ok: i64 = 1 96 // ours is exactly correct under mix shift (no phantom inflation) 97 if basket_T != 1000 { ok = 0 } 98 // neg-control: the naive index MUST emit a phantom signal under mix shift (bench discriminates) 99 if naive_T == 1000 { ok = 0 } 100 if phantom_naive < 100 { ok = 0 } // the phantom error is materially large (>=100 permil) 101 // ours TRACKS a real price move (not trivially clamped): +10% prices -> 1100 102 if basket_U != MI_MAGIC_1100 { ok = 0 } 103 // when the mix is stable, the naive index agrees (it is only wrong on mix shift) 104 if naive_U != MI_MAGIC_1100 { ok = 0 } 105 // ours strictly more accurate than naive under mix shift 106 if phantom_ours >= phantom_naive { ok = 0 } 107 108 mi_w(1, "UVVIGATE engine=nx_market_insights MEASURED-exceed-vs-naive-avg-index" as *u8) 109 mi_w(1, " | mix-shift(flat-prices) truth=1000 ours=" as *u8); mi_wn(1, basket_T) 110 mi_w(1, " naive=" as *u8); mi_wn(1, naive_T) 111 mi_w(1, " phantom_naive=" as *u8); mi_wn(1, phantom_naive); mi_w(1, "permil phantom_ours=" as *u8); mi_wn(1, phantom_ours) 112 mi_w(1, " | real-+10%(no-mix-shift) truth=1100 ours=" as *u8); mi_wn(1, basket_U) 113 mi_w(1, " naive=" as *u8); mi_wn(1, naive_U) 114 mi_w(1, " | SCOPE: vs naive-avg-index ONLY; real-UVVI-methodology NOT-CLAIMED(needs-real-series)" as *u8) 115 if ok == 1 { mi_w(1, " verdict=GREEN\n" as *u8) } else { mi_w(1, " verdict=RED\n" as *u8) } 116 117 let lf: i64 = sys_openat_append(MI_LOG, 420) 118 if lf >= 0 { 119 mi_w(lf, "UVVIGATE engine=nx_market_insights mixshift ours=" as *u8); mi_wn(lf, basket_T) 120 mi_w(lf, " naive=" as *u8); mi_wn(lf, naive_T); mi_w(lf, " phantom_naive=" as *u8); mi_wn(lf, phantom_naive) 121 mi_w(lf, " real10pct ours=" as *u8); mi_wn(lf, basket_U); mi_w(lf, " naive=" as *u8); mi_wn(lf, naive_U) 122 mi_w(lf, " SCOPE=vs-naive-index-only-not-real-UVVI" as *u8) 123 if ok == 1 { mi_w(lf, " verdict=GREEN\n" as *u8) } else { mi_w(lf, " verdict=RED\n" as *u8) } 124 sys_close(lf) 125 } 126 127 if ok == 1 { return 0 } 128 return 1 129}