code wiki / (root) / nx_fin_taxopt_gate.nx

nx_fin_taxopt_gate.nx source

↩ module page · 38 lines · 2186 B

1// nx_fin_taxopt_gate.nx -- GATE for tax optimization: ยง1202 QSBS exclusion (floor vs 10x-basis, holding-period 2// and qualification guards), tax-after-exclusion, pass-through vs C-corp, and compound deferral gain -- all 3// hand-computed. Exits 0 iff all pass. license_tier: ORIGINAL 4import "nx_gate.nx" 5import "nx_fin_taxopt.nx" 6 7func chk(name: *u8, got: i64, want: i64, st: *i64) -> i64 { 8 if got == want { st[0] = st[0] + 1; gw(" PASS " as *u8); gw(name); gw("\n" as *u8) } 9 else { st[1] = st[1] + 1; gw(" FAIL " as *u8); gw(name); gw(" got=" as *u8); gn(got); gw(" want=" as *u8); gn(want); gw("\n" as *u8) } 10 return 0 11} 12 13func main() -> i64 { 14 let st: *i64 = sys_mmap(16) as *i64 15 st[0] = 0; st[1] = 0 16 17 // $20M gain, $500k basis, held 6y, qualifies -> exclude the $10M floor (10x basis = $5M is lower) 18 chk("QSBS exclude $10M floor" as *u8, to_qsbs_exclusion(2000000000, 50000000, 6, 1), 1000000000, st) 19 // $20M gain, $30M basis, held 6y -> 10x basis = $300M cap -> whole $20M gain excluded 20 chk("QSBS 10x-basis excludes whole gain" as *u8, to_qsbs_exclusion(2000000000, 3000000000, 6, 1), 2000000000, st) 21 chk("QSBS held 3y (<5) -> 0" as *u8, to_qsbs_exclusion(2000000000, 50000000, 3, 1), 0, st) 22 chk("QSBS not-qualified -> 0" as *u8, to_qsbs_exclusion(2000000000, 50000000, 6, 0), 0, st) 23 24 // tax on the still-taxable $10M at 23.8% (2380 bps) = $2.38M (238,000,000c) 25 chk("tax after $10M exclusion @23.8% = $2.38M" as *u8, to_tax_after_qsbs(2000000000, 1000000000, 2380), 238000000, st) 26 27 // entity comparison on $10,000 profit 28 chk("pass-through @37% = $3700" as *u8, to_passthrough_tax(1000000, 3700), 370000, st) 29 chk("C-corp 21% + 20% div (100% payout) = $3680" as *u8, to_ccorp_total_tax(1000000, 2100, 2000, 10000), 368000, st) 30 31 // deferring $1000 tax at 10% for 3 years earns $331 (compound) 32 chk("deferral gain $1000@10%x3y = $331" as *u8, to_deferral_gain(100000, 1000, 3), 33100, st) 33 34 gw("nx_fin_taxopt_gate: PASS=" as *u8); gn(st[0]); gw(" FAIL=" as *u8); gn(st[1]); gw("\n" as *u8) 35 if st[1] == 0 { gw("nx_fin_taxopt: GREEN\n" as *u8); return 0 } 36 gw("nx_fin_taxopt: RED\n" as *u8) 37 return 1 38}