Add NIIT + state/local rates to the after-tax model (NYC support)
NYC residents pay, on a capital-gain distribution, roughly 20% federal + 3.8% NIIT + 6.85-9.65% NY + 3.876% NYC = ~34-37% — the old model's flat 20% understated the real after-tax drag of high-distribution funds for this user by ~15 points on exactly the flows that matter. tax.py: new niit + sl_rate params (decimals). sl_rate is the state+local marginal rate applied at ORDINARY rates to every flow — state and local have NO preferential cap-gain rate, so the composite is lt_rate+niit+sl_rate on cap-gain dists, div_rate+niit+sl_rate on dividends, and (st/lt_rate)+niit+sl_rate on realized gains. app.py: two new sidebar fields (persisted in settings.json), wired through _compute_portfolio's cache key. tests/test_tax.py: 3 new cases (capg and div composite rates, net-taxed realized ST gains/losses at st+NIIT+SL). README: NYC rate note with the 2025 IT-201 schedule values (NYC 3.876% over $50k; NY 6.85% at $215,400-$1.077M, 9.65% at $1.077M-$5M, single filer) and the composite example.
This commit is contained in:
@@ -89,6 +89,32 @@ def main() -> int:
|
||||
abs(r2.taxes["capg_tax"][t5] - 0.20 * 0.6 / 30.0) < 1e-12
|
||||
and abs(r2.taxes["div_tax"][t5] - 0.10 * 0.4 / 30.0) < 1e-12)
|
||||
|
||||
# --- state/local + NIIT: composite rates add to each component
|
||||
# (NY/NYC tax cap gains at ordinary rates — the caller passes the
|
||||
# composite sl_rate; the model must not preferentiate cap gains).
|
||||
r3 = tax.after_tax_portfolio(close, div2, capg2, {"f": 1.0}, lt_rate=0.20,
|
||||
st_rate=0.15, div_rate=0.10, niit=0.038,
|
||||
sl_rate=0.14)
|
||||
check("capg dist taxed at lt + NIIT + state/local",
|
||||
abs(r3.taxes["capg_tax"][t5] - (0.20 + 0.038 + 0.14) * 0.6 / 30.0) < 1e-12)
|
||||
check("div taxed at div + NIIT + state/local",
|
||||
abs(r3.taxes["div_tax"][t5] - (0.10 + 0.038 + 0.14) * 0.4 / 30.0) < 1e-12)
|
||||
# realized-gain leg: two symbols, daily rebalance forces ST sells;
|
||||
# every realized dollar is taxed at (st_rate + niit + sl_rate).
|
||||
d3 = pd.to_datetime(["2024-01-0%d" % i for i in (1, 2, 3)])
|
||||
close3 = pd.DataFrame({"a": [30.0, 34.0, 29.0], "b": [10.0, 10.0, 10.0]},
|
||||
index=d3)
|
||||
zero3 = pd.DataFrame(0.0, index=d3, columns=["a", "b"])
|
||||
r4 = tax.after_tax_portfolio(close3, zero3, zero3, {"a": 0.5, "b": 0.5},
|
||||
rebalance="1D", lt_rate=0.20, st_rate=0.15,
|
||||
div_rate=0.10, niit=0.038, sl_rate=0.14)
|
||||
real_tax = float(r4.taxes["realized_tax"].sum())
|
||||
net_st = float(r4.realized["st_gain"].sum()) - \
|
||||
float(r4.realized["st_loss"].sum())
|
||||
check("realized ST gains/losses net-taxed at st + NIIT + state/local",
|
||||
float(r4.realized["st_gain"].sum()) > 0 and
|
||||
abs(real_tax - net_st * (0.15 + 0.038 + 0.14)) < 1e-9)
|
||||
|
||||
print(f"\n{PASS} passed, {FAIL} failed")
|
||||
return 1 if FAIL else 0
|
||||
|
||||
|
||||
Reference in New Issue
Block a user