Skip to content

Show the average savings per extra dollar above the gift - #113

Closed
MaxGhenis wants to merge 3 commits into
mainfrom
fix-next-dollar-forward-rate
Closed

MaxGhenis wants to merge 3 commits into
mainfrom
fix-next-dollar-forward-rate

Conversation

@MaxGhenis

@MaxGhenis MaxGhenis commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

The defect

The US results card "Saved on the next $1" showed /api/calculate's marginal_savings_rate. On main, that figure is the donation sweep's central difference at the grid point nearest the gift. The old docstring says that "at a kink it averages the rates on either side".

A gift on a kink therefore got a rate that applies on neither side. Our Giving Tuesday posts use a single 30-year-old with $75,000 in wages giving $1,000 in 2026. That gift sits exactly on the 26 U.S.C. 170(p) cap for filers who take the standard deduction ($1,000 single, $2,000 joint).

Live /api/calculate, recorded 2026-12-01 15:20Z:

Household tax_savings Card showed Rate above the gift
TX single, $75k, $1,000 220.00 14.67% 0%: 170(p) is used up, and Texas has no income tax
MA single, $75k, $1,000 270.00 19.67% 5%: the Part B charitable deduction only
TX joint, $120k, $2,000 240.00 4.00% 0%
MA joint, $120k, $2,000 340.00 9.00% 5%

Live /api/savings the same day gave TX tax savings of 220.00 at $1,000, $1,001 and $1,100, and MA 270.00, 270.05 and 275.00.

The change

The figure. For US households, /api/calculate now returns the average reduction in net taxes per dollar over a window above the gift:

(net tax at the gift - net tax at the gift + window) / window

The point run at the gift + $100 joins the $0 and gift runs in one point_metrics_many batch. It shares the point cache with /api/savings.

The window. It is NEXT_DOLLARS ($100), or 2,000 float32 spacings of the net tax at the gift when that is wider (next_dollar_window, which uses the magnitude, so a large negative net tax widens it too). The wider window starts at $125 at $524,288 of net tax and reaches $8,000 at $40 million. Only those households run one more simulation, alongside the sweep.

Why a window. policyengine-us returns float32 taxes, whose spacing grows with the tax, so a $1 step turns rounding into rate. Measured at policyengine-us 2.156.4, by the step used to read the rate:

Household Net tax $1 $10 $100 $1,000
MA single $75k, $1,000 gift $16.9k 5.078% 5.000% 5.000% n/a
CA single $3M, $100k gift $1.52M 37.500% 38.750% 37.750% 37.663%
TX married $10M, $250k gift $3.80M 50.000% 35.000% 34.750% 35.000%
TX single $100M, $1M gift $39.1M 0.0% 40.0% 32.0% n/a (the rule's $8,000 window: 35.0%)

The window rule keeps each float32 spacing of rounding to 0.05 point. Intermediate rounding in the model, or a value near a display-rounding boundary, can still move the one-decimal figure. The CA $3M case reads 37.65% over the rule's $250 window and displays 37.6%, against 37.66% over $1,000.

The card's words. Any finite window averages across a kink inside it. A TX single filer giving $925 saves 22% on the next $75 and 0% on the $25 after the cap, so the card reads 16.5%. Main read 22.0% there, which was right for the literal next dollar. So the card no longer promises the next $1:

  • Label: "Saved on the next $1" becomes "Average savings per extra dollar".
  • Description: "Tax saved if you gave a little more" becomes "Change in net taxes if you give a little more".
  • The FAQ sentence now says the figure is "the reduction in net taxes per dollar over the next $100 above your gift". It says the range widens when taxes and benefits at the gift differ by about $500,000 or more, and that a negative rate means giving more increases net taxes.
  • faqRules.json holds next_dollars, and tests/test_faq_numbers.py ties it and the threshold to the API.

Fixtures. Across the 11 wizard fixtures, the new and old rates agree within 0.01 point except one: the Iowa household whose $10 gift crosses a state credit cutoff moves from 183.5% to 25.8% (22% federal plus 3.8% Iowa). Kansas stays at -5%.

Unchanged. /api/uk/calculate keeps the sweep's rate, and the UK results show no such card. The chart still plots the sweep's central differences, and its current-gift dot sits on the nearest sampled point.

Tests

tests/test_next_dollar_rate.py, on wizard-built requests:

  • TX single at $1,000 → 0%, MA → 5%; TX joint at $2,000 → 0%, MA → 5%.
  • TX single at $500 → 22%, and at $925 → 16.5% (the window crosses the cap).
  • Identity against /api/savings over the next $100.
  • The window function at six net-tax levels (and -550,000 in the FAQ test).
  • TX $100M earner at 35% (±0.2 point).

Against main, the four cap cases and both identity cases fail (TX single read 0.1467, MA single 0.1967, TX joint 0.0400, MA joint 0.0900).

Review

  • Round 1, a Codex cloud review at 83f8269, returned REQUEST_CHANGES with one P1 (the "next $1" label over a $100 average), two P2s and one P3. Its patch is applied here; see the comment below.
  • Its runs: full tests/ 560 passed with -n 4, the new file 14/0, a clean merge with main, and six open PRs merging cleanly.
  • Bun was unavailable in its container. Frontend tests (274), lint and build pass locally at this head.

Follow-ups (not in this PR)

  • A narrower or kink-aware window would make the figure closer to the literal next dollar.
  • The marginal chart's current-gift dot could plot the card's figure.
  • In the policyengine-us model, outside GiveCalc: DOR lists P.L. 119-21 sec. 70425 as not adopted by Massachusetts. Yet a $40,000 to $40,100 step at $75,000 wages still lowers MA tax, above the prior-law 50% ceiling. This predates this PR.

🤖 Generated with Claude Code

/api/calculate's marginal_savings_rate was the donation sweep's central
difference at the nearest grid point, which averages the rates on either
side of a kink. A single filer giving $1,000 in 2026 sits on the 170(p)
cap, so Texas showed 14.7% where the next dollar saves nothing, and
Massachusetts 19.7% where it saves 5%.

The rate now comes from a point run at the gift plus $100, in the same
parallel batch as the $0 and gift runs: (net tax at the gift - net tax
$100 above) / 100. Smaller steps turn float32 rounding into rate.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@vercel

vercel Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
givecalc Ready Ready Preview Dec 1, 2026 8:38pm UTC

Request Review

policyengine-us returns taxes as float32, whose spacing grows with the
tax. Over a fixed $100 window, a $100 million earner's 35% read 32% and a
$25 million earner's 37.7% read 39.0%, worse than the old sweep figure.
The window is now $100, or 2,000 float32 spacings of the net tax when that
is wider ($125 from $524,288 of net tax, $8,000 at $40 million). A wider
window costs one more point run, alongside the sweep.

The FAQ states the window from faqRules.json, which a test ties to the
API. Comments in App.tsx, headlineFirst.ts and CLAUDE.md now say where
the card's rate comes from.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Round 1 of the review (a Codex cloud review at 83f8269) found the card
promised the next $1 while showing the average over a $100 window: a
Texan giving $925 saves 22% on the next $75 and 0% after the cap, so the
card read 16.5%. The card now reads "Average savings per extra dollar",
"Change in net taxes if you give a little more", and the FAQ says the
figure is the reduction in net taxes per dollar over the next $100, how
the range widens, and what a negative rate means.

Also from the review: the FAQ threshold uses the magnitude of net tax
(a -550,000 check), a comment notes that intermediate rounding can still
move the displayed figure, and the float32 spacing example is corrected.
A test pins the $925 blend.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@MaxGhenis MaxGhenis changed the title Show the forward rate as "Saved on the next $1" Show the average savings per extra dollar above the gift Dec 1, 2026
@MaxGhenis

MaxGhenis commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor Author

Independent review, round 1 (Codex cloud). Result: VERDICT: REQUEST_CHANGES at 83f8269c38440099cb00aa076dc2d4476f0cdabd.

  • Chat: https://chatgpt.com/local/6b0f27d6-eff4-83ea-a315-b2db5a7c200f (account pe, sent 2026-12-01 20:02Z, harvested 20:28Z)
  • Model and effort: GPT-6.2 Sol at Extra High, from the task page's labels (read 2026-12-01 20:30:40Z). The report describes itself as "GPT-6 Codex" with effort unavailable; the page label is the record.
  • Findings:
    • P1: the "Saved on the next $1" label sat over a $100 average. A TX $925 gift read 16.5% where the next dollar saves 22%.
    • P2: display rounding near a boundary (CA $3M: 37.65% shown as 37.6%).
    • P2: the FAQ threshold should describe the magnitude of net tax.
    • P3: the float32 spacing example was wrong.
  • Fixed in bfcda89, which applies the review's own patch (sha256 75d30834…) and adds a test that pins the $925 blend. The card now reads "Average savings per extra dollar".
  • Tests the review ran: full tests/ with -n 4, 560 passed; the new file, 14/0; a clean merge with main and with six open PRs.
  • Not run in its Linux container (Bun unavailable): frontend tests, lint and build. Locally at bfcda89: 274 frontend tests pass, lint shows 0 errors, the build succeeds, and the 40 affected Python tests pass.

Round 2, a full review at bfcda89, is queued.

MaxGhenis added a commit that referenced this pull request Dec 3, 2026
* Show the forward rate as "Saved on the next $1"

/api/calculate's marginal_savings_rate was the donation sweep's central
difference at the nearest grid point, which averages the rates on either
side of a kink. A single filer giving $1,000 in 2026 sits on the 170(p)
cap, so Texas showed 14.7% where the next dollar saves nothing, and
Massachusetts 19.7% where it saves 5%.

The rate now comes from a point run at the gift plus $100, in the same
parallel batch as the $0 and gift runs: (net tax at the gift - net tax
$100 above) / 100. Smaller steps turn float32 rounding into rate.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Widen the next-dollar window for large tax bills

policyengine-us returns taxes as float32, whose spacing grows with the
tax. Over a fixed $100 window, a $100 million earner's 35% read 32% and a
$25 million earner's 37.7% read 39.0%, worse than the old sweep figure.
The window is now $100, or 2,000 float32 spacings of the net tax when that
is wider ($125 from $524,288 of net tax, $8,000 at $40 million). A wider
window costs one more point run, alongside the sweep.

The FAQ states the window from faqRules.json, which a test ties to the
API. Comments in App.tsx, headlineFirst.ts and CLAUDE.md now say where
the card's rate comes from.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Label the card as an average over the next $100

Round 1 of the review (a Codex cloud review at 83f8269) found the card
promised the next $1 while showing the average over a $100 window: a
Texan giving $925 saves 22% on the next $75 and 0% after the cap, so the
card read 16.5%. The card now reads "Average savings per extra dollar",
"Change in net taxes if you give a little more", and the FAQ says the
figure is the reduction in net taxes per dollar over the next $100, how
the range widens, and what a negative rate means.

Also from the review: the FAQ threshold uses the magnitude of net tax
(a -550,000 check), a comment notes that intermediate rounding can still
move the displayed figure, and the float32 spacing example is corrected.
A test pins the $925 blend.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Overlap the rate run with the sweep and fix the card's sign

An in-session check of #113 at bfcda89 confirmed three P2 findings:

- The card's description, "Change in net taxes if you give a little
  more", sat under a figure that is positive when net taxes fall. It
  now reads "Reduction in net taxes if you give a little more", the
  FAQ's convention, and a test pins it.
- After the site's /api/savings call the gift + $100 run is
  /api/calculate's only new point run, and the wizard sweep waited for
  it. calculate_donation now starts the three point runs, waits for $0
  and the gift, starts the sweep, then waits for the rate's run. A test
  with fake runs on a thread pool fails at bfcda89 and passes here.
  point_metrics_many is now start_points plus point_results.
- A step in net tax inside the window counts in full. A comment and a
  unit test say so, and point to PolicyEngine/policyengine-us#11282,
  where a gift that tips an itemization election makes such a step.

Also pins the Giving Tuesday posts' joint link (TX, $150,000, $2,000:
0%) and renames the parametrized test, which covers a blend case too.

Tests: test_next_dollar_rate 18 passed; test_simulation_cache,
test_workers and test_faq_numbers 41 passed; test_household_payload
-k agree_at_the_endpoint 5 passed; vitest 274 passed; tsc clean; lint
0 errors (1 existing warning); black and isort clean.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Gate forward marginal-rate card on API window and qualify rounding/step notes

* Use step-agnostic fallback copy when window is omitted and clarify FAQ artifact wording

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
@MaxGhenis

Copy link
Copy Markdown
Contributor Author

Superseded by #116 (merged into main as 50f0d6fe01328af1c9c1272734a667bd2b203060), which includes all three commits from #113 plus the fixes for #113's round-2 review (subtitle sign, sweep overlap, endpoint rounding note) and the marginal_savings_window rollout gate.

@MaxGhenis MaxGhenis closed this Dec 3, 2026

This branch was successfully deployed

1 active deployment
Preview – givecalc — bfcda89e Deployed Dec 1, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant