code wiki / (root) / nx_taxlot_lib.nx

nx_taxlot_lib.nx

buildroot/runtime/nx_taxlot_lib.nx

5005 B98 linesdepth 0pulls 0 transitivereach 2 importersview sourcekind library
docsdependenciesstructsconstsfunctions

about

nx_taxlot_lib.nx -- CAPITAL-GAINS TAX-LOT ACCOUNTING with the IRS wash-sale rule. Integer-exact. Realizing a capital gain/loss is not subtraction -- it is lot selection, holding-period classification, and the wash-sale disallowance (IRC section 1091). This organ does all three in exact integer minor units. *THE WASH-SALE FAIL-CLOSED PROPERTY (the flagship): if you sell at a LOSS and buy a substantially identical security within +/-30 days, the loss is DISALLOWED for the current year. Consumer tax tools routinely mis-handle this and let a taxpayer claim a loss the IRS will reject. Here the disallowed loss is not silently dropped and not silently claimed -- it is computed proportionally to the replacement shares and DEFERRED into the replacement lot's cost basis (tl_adjusted_replacement_basis), so it is preserved, not destroyed (history is additive). A GAIN is never washed; a loss with no replacement in the window is fully allowed. allowed + disallowed == the original loss, always (conservation). FIFO lot consumption is fail-closed against overdraw: it returns the shares actually sold, which is less than requested when the book is short -- it cannot sell shares the book does not hold. NO FLOATS. Days are integer day-numbers; money is minor units. Thresholds are declared constants (Rule 11). license_tier: ORIGINAL No hw writes (Rule 26). LIB.

dependencies 0 imports · 2 importers

nx_taxlot_lib.nx nx_finance_svc.nx nx_taxlot_gate.nx

imports: none

imported by: nx_finance_svc.nxnx_taxlot_gate.nx

structs

none

consts

20const TL_LONG_TERM_DAYS: i64 = 365 // held MORE THAN one year = long-term (IRS: strictly greater)
21const TL_WASH_WINDOW_DAYS: i64 = 30 // +/-30 days around the sale = the wash-sale window
22const TL_LONG: i64 = 1
23const TL_SHORT: i64 = 0
24const TL_BAD: i64 = 0 - 2000000002 // invalid input

functions

27func tl_realized_gain(proceeds: i64, basis: i64) -> i64
called by 1: main
32func tl_holding_class(acquire_day: i64, sale_day: i64) -> i64
called by 1: main
41func tl_wash_disallowed(loss_amount: i64, sale_day: i64, replacement_day: i64, replacement_shares: i64, sold_shares: i64) -> i64
53func tl_allowed_loss(loss_amount: i64, sale_day: i64, replacement_day: i64, replacement_shares: i64, sold_shares: i64) -> i64
60func tl_adjusted_replacement_basis(replacement_basis: i64, disallowed_loss: i64) -> i64
called by 1: main
68func tl_sell_fifo(lot_shares: *i64, lot_basis: *i64, n: i64, sell_shares: i64, sell_price: i64, out: *i64) -> i64
called by 1: main
95func tl_class_str(c: i64) -> *u8
called by 1: main