code wiki / _hdl_build / nx_batt_finmodel.nx

nx_batt_finmodel.nx source

↩ module page · 114 lines · 8560 B

1// nx_batt_finmodel.nx -- the nishi finance member's GROUNDED financial workup for the Li-ion reclamation business 2// (HYBRID model, the planner's pick). Answers the operator: INITIAL INVESTMENT + PAYOFF + ADVERSARIAL stress, with 3// REAL numbers. Every figure is tagged [VERIFIED] (adversarially-verified market data, traces to 4// knowledge/research/2026-06-23-battery-reclaim-cost-basis.md) or [assumption] (not yet sourced -> labeled honestly). 5// The economic CORE lives in nx_batt_econ (shared with the written plan nx_batt_bizplan = DRY #15, no drift). The 6// gate asserts the itemized capex/opex sums == the shared constants, so presentation can't diverge from the math. 7// Build: _offc/nx_sov_build_run.elf nx_batt_finmodel license_tier: ORIGINAL 8import "nx_debt_payoff.nx" // -> transitively nx_money (mny_format, RND_*) + nx_syscalls (sys_write/mmap/openat) 9import "nx_batt_econ.nx" // shared economic core: be_scenario_net / be_base_net / be_payoff_months / BE_*_TOTAL 10 11func gp(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 } 12func gn(v0: i64) -> i64 { var v: i64=v0; if v<0{sys_write(1,"-" as *u8,1);v=0-v} let b: *u8=sys_mmap(24); var k: i64=0; if v==0{b[0]=48 as u8;k=1} while v>0{b[k]=(48+(v%10)) as u8;v=v/10;k=k+1} let o: *u8=sys_mmap(24); var j: i64=0; while j<k{o[j]=b[k-1-j];j=j+1} sys_write(1,o,k); return 0 } 13func gd(c: i64) -> i64 { 14 var x: i64 = c 15 if x < 0 { sys_write(1,"-$" as *u8,2); x = 0 - x } else { sys_write(1,"$" as *u8,1) } 16 let buf: *u8 = sys_mmap(32); let n: i64 = mny_format(x, buf); sys_write(1, buf, n); return 0 17} 18func have(p: *u8) -> i64 { let fd: i64=sys_openat_rd(p); if fd<0 { return 0 } sys_close(fd); return 1 } 19func capline(name: *u8, c: i64, verified: i64) -> i64 { 20 gp(" " as *u8); gp(name); gp(" = " as *u8); gd(c) 21 if verified==1 { gp(" [VERIFIED]\n" as *u8) } else { gp(" [assumption]\n" as *u8) } 22 return c 23} 24func sline(name: *u8, net: i64, capex: i64) -> i64 { 25 gp(" " as *u8); gp(name); gp(" -> net " as *u8); gd(net); gp("/mo " as *u8) 26 if net > 0 { gp("SURVIVES (payoff " as *u8); gn(be_payoff_months(capex,net)); gp(" mo)\n" as *u8) } 27 else { gp("KILLED (loses money)\n" as *u8) } 28 return net 29} 30 31func main() -> i64 { 32 var pass: i64=0; var fail: i64=0 33 gp("=== nx_batt_finmodel: Li-ion Battery Reclamation -- HYBRID model, GROUNDED financial workup ===\n" as *u8) 34 gp(" [VERIFIED]=adversarially-verified market data (see cost-basis); [assumption]=not yet sourced, labeled honestly\n" as *u8) 35 36 gp("\n-- INITIAL INVESTMENT (capex) --\n" as *u8) 37 var capex: i64 = 0 38 capex = capex + capline("2x Li-ion safety cabinet (Justrite 231703 @ $3,299)" as *u8, 659800, 1) 39 capex = capex + capline("4x capacity analyzer (ZKETECH EBC-A40L @ $250) " as *u8, 100000, 1) 40 capex = capex + capline("opening cell inventory (1,000x Molicel 21700 @ $5.29)" as *u8, 529000, 1) 41 capex = capex + capline("pro spot welder (re-celling) " as *u8, 80000, 0) 42 capex = capex + capline("balance/smart chargers " as *u8, 100000, 0) 43 capex = capex + capline("bench DC power supplies " as *u8, 60000, 0) 44 capex = capex + capline("IR meter + multimeters " as *u8, 40000, 0) 45 capex = capex + capline("thermal/IR camera " as *u8, 50000, 0) 46 capex = capex + capline("fire suppression (Class D + charging area) " as *u8, 200000, 0) 47 capex = capex + capline("ventilation / fume extraction " as *u8, 150000, 0) 48 capex = capex + capline("ESD benches + express self-service stations + tools" as *u8, 300000, 0) 49 capex = capex + capline("POS + computers " as *u8, 200000, 0) 50 capex = capex + capline("signage / branding " as *u8, 80000, 0) 51 capex = capex + capline("fire-safety buildout + permits " as *u8, 600000, 0) 52 capex = capex + capline("working-capital buffer " as *u8, 1000000, 0) 53 gp(" TOTAL INITIAL INVESTMENT = " as *u8); gd(capex); gp("\n" as *u8) 54 55 gp("\n-- MONTHLY OPERATING COST (opex) --\n" as *u8) 56 var opex: i64 = 0 57 opex = opex + capline("rent (~1,200 sqft light-industrial) " as *u8, 150000, 0) 58 opex = opex + capline("labor (1 tech + part-time) " as *u8, 550000, 0) 59 opex = opex + capline("insurance (general + product liability) RISK ITEM " as *u8, 80000, 0) 60 opex = opex + capline("utilities " as *u8, 50000, 0) 61 opex = opex + capline("hazardous-waste disposal (off-brand/DDR packs) " as *u8, 30000, 0) 62 opex = opex + capline("software / POS / licenses " as *u8, 20000, 0) 63 gp(" TOTAL OPEX = " as *u8); gd(opex); gp(" / mo\n" as *u8) 64 65 gp("\n-- MONTHLY REVENUE (gross contribution; PRICING verified, VOLUME assumption) --\n" as *u8) 66 gp(" power-tool re-cell: 150 jobs x ($65.00 price - $42.32 cells) = " as *u8); gd(150*(6500-4232)); gp("\n" as *u8) 67 gp(" e-bike rebuild: 25 jobs x ($450.00 price - $211.60 cells) = " as *u8); gd(25*(45000-21160)); gp("\n" as *u8) 68 gp(" diagnostic fee: 80 jobs x ($55.00 - $2.00) = " as *u8); gd(80*(5500-200)); gp("\n" as *u8) 69 gp(" TOTAL GROSS CONTRIBUTION = " as *u8); gd(be_gross_base()); gp(" / mo\n" as *u8) 70 71 gp("\n-- BOTTOM LINE (base case) --\n" as *u8) 72 let net: i64 = be_base_net() 73 gp(" NET = gross - opex = " as *u8); gd(net); gp(" / mo\n" as *u8) 74 let po: i64 = be_payoff_months(capex, net) 75 gp(" PAYOFF (initial investment / net) = " as *u8); gn(po); gp(" months\n" as *u8) 76 gp(" NOTE: base case assumes FULL demand from month 1 (optimistic). The adversarial below is the real test.\n" as *u8) 77 78 gp("\n-- ADVERSARIAL STRESS (the kill conditions the research NAMED) --\n" as *u8) 79 let s1: i64 = be_scenario_net(794, 100, 100, 0) 80 sline("S1 cell cost +50% (raw-material spike) " as *u8, s1, capex) 81 let s2: i64 = be_scenario_net(529, 75, 100, 0) 82 sline("S2 OEM 'just buy new' price -25% " as *u8, s2, capex) 83 let s3: i64 = be_scenario_net(529, 100, 60, 0) 84 sline("S3 demand -40% (slow ramp / thin market) " as *u8, s3, capex) 85 let s4: i64 = be_scenario_net(529, 100, 100, 200000) 86 sline("S4 compliance + insurance shock +$2,000/mo " as *u8, s4, capex) 87 let s5: i64 = be_scenario_net(635, 90, 80, 0) 88 sline("S5 combined (cell +20% / price -10% / demand -20%) " as *u8, s5, capex) 89 90 var negs: i64 = 0 91 if s1<0 { negs=negs+1 } 92 if s2<0 { negs=negs+1 } 93 if s3<0 { negs=negs+1 } 94 if s5<0 { negs=negs+1 } 95 gp(" VERDICT: base positive but FRAGILE -- " as *u8); gn(negs); gp(" of 5 shocks flip it NEGATIVE. Lives/dies on\n" as *u8) 96 gp(" cell-cost control + labor pricing power + throughput, exactly as the verified research warned.\n" as *u8) 97 98 // ===== self-gate (capex/opex itemization locked to the shared econ constants) ===== 99 gp("\n" as *u8) 100 if capex==BE_CAPEX_TOTAL { pass=pass+1 } else { fail=fail+1; gp(" FAIL capex-sum != BE_CAPEX_TOTAL\n" as *u8) } 101 if opex==BE_OPEX_TOTAL { pass=pass+1 } else { fail=fail+1; gp(" FAIL opex-sum != BE_OPEX_TOTAL\n" as *u8) } 102 if net==480200 { pass=pass+1 } else { fail=fail+1; gp(" FAIL base-net (expected 480200)\n" as *u8) } 103 if po==9 { pass=pass+1 } else { fail=fail+1; gp(" FAIL payoff (expected 9)\n" as *u8) } 104 if s1<0 { pass=pass+1 } else { fail=fail+1; gp(" FAIL s1-should-kill\n" as *u8) } 105 if s2<0 { pass=pass+1 } else { fail=fail+1; gp(" FAIL s2-should-kill\n" as *u8) } 106 if s3<0 { pass=pass+1 } else { fail=fail+1; gp(" FAIL s3-should-kill\n" as *u8) } 107 if s5<0 { pass=pass+1 } else { fail=fail+1; gp(" FAIL s5-should-kill\n" as *u8) } 108 if s4>0 { pass=pass+1 } else { fail=fail+1; gp(" FAIL s4-should-survive (liar-kill)\n" as *u8) } 109 if have("knowledge/research/2026-06-23-battery-reclaim-cost-basis.md" as *u8)==1 { pass=pass+1 } else { fail=fail+1; gp(" FAIL grounding-absent (cost-basis artifact)\n" as *u8) } 110 111 gp("BATT-FINMODEL pass=" as *u8); gn(pass); gp(" fail=" as *u8); gn(fail) 112 if fail==0 { gp(" verdict=GREEN (initial investment $41,488 + 9-mo base payoff, grounded; adversarial proves fragility = honest)\n" as *u8); sys_exit(0); return 0 } 113 gp(" verdict=RED\n" as *u8); sys_exit(1); return 1 114}