Quote the scheduled repayment as a variable loan's minimum

Draft
JA
2mo ago
+525-302

Summary

Closes #392. Part of #100 (fork PR-B, decision 9).

On a variable loan the Current Monthly Payment card re-amortised the actual balance, net of offset, at today's rate. A lender sets the minimum on the scheduled balance, re-amortised at each rate change. So paying ahead or holding an offset made the card quote less than the borrower must pay.

On the issue's loan ($400,000, 360 months, 5.50% moving to 6.43% at payment 13, 50 payments made, $40,000 ahead):

Card on mainCard on this branch
Paid $40,000 ahead$2,236.66$2,504.42
Plus a $30,000 offset$2,038.01$2,504.42

The issue's hand figure was $2,504.44 with monthly accrual; the fork's schedule accrues daily, which accounts for the 2 cents. The test asserts the engine's own row and checks it is within $2 of the issue's figure.

What changed

  • Loan::AmortizationSchedule#payment_in_force(as_of:) (and #payment_row_in_force): the payment of the first scheduled period after as_of, read from the in-memory simulation. The boundary matches remaining_payment_count: a payment due on as_of has been made. This is upstream's payment_in_force semantics with the fork's exclusive boundary, as the issue's follow-up comment asked.
  • Loan#current_minimum_payment: a variable loan returns payment_in_force. Fixed and matured loans are unchanged.
  • UI::Loan::RateChangeTable: each future change's balance and new repayment come from the schedule row at the first payment on or after the effective date (the payment clock, C8). Its PayoffProjection, offset netting and offset SUM are gone. The current column still reads current_minimum_payment, so the card and the table cannot disagree. Where two changes land before the same payment, only the later one is listed.
  • Copy:
    • The card caption (minimum_payment_rate, in every locale that carries it) says the figure is the next repayment the loan's schedule sets, which paying ahead or an offset doesn't change.
    • Since 16a034187 it no longer calls the figure "your lender's minimum" (nightly review, below).
    • The table's balance header says the same. Since 7d2ddf35c the table's caption calls its figures estimated from the loan's terms; it no longer says the method "is how lenders set the minimum repayment" or that the lender's figure differs only "slightly through rounding".

Scope and dependencies

  • Issue: #392
  • Parent PR/branch, if stacked: none. Base main.
  • Intentionally out of scope: a second "if re-amortised today" card (an open question for the owner, per the issue), recording rate changes the borrower hasn't entered, and a manual lender-figure field.

Blast radius. current_minimum_payment has three readers, the Overview card, the Schedule card and RateChangeTable#current_payment, each passing one captured as_of. No API or assistant tool reads it.

Siblings (from grep -n "current_minimum_payment\|interest_bearing_balance\|monthly_payment"):

  • PayoffProjection :reamortize sized on the actual balance to match the old card. It now has no app caller. It is kept as an actual-balance model, its comments no longer tie it to the card, and the four tests that pinned its first payment to current_minimum_payment compare against that annuity directly. Deleting the strategy belongs to #100 PR-B.
  • interest_bearing_balance keeps its interest readers (projection, offset resolver). Unchanged.
  • PayoffProjection :hold still carries AmortizationSchedule#monthly_payment, the contracted first payment, across every segment. That is stale on a variable loan for the same reason. It is not changed here: putting the projection on the schedule's payment by period is #100's decision 1 (a :scheduled strategy, #401), and it moves every variable loan's projection, payoff date and chart.
  • test/models/loan_offset_account_currency_change_test.rb drops the table from its list of offset readers, because the table no longer reads offsets.

Evidence checklist

  • Each issue in this PR has its own acceptance criteria and no unrelated issue work is included.
  • Contract rows touched by this change name existing tests.
  • Any gate test has an observed failing mutation transcript attached.
  • Fixtures used as evidence assert internal consistency.
  • Financial calculations use BigDecimal and documented rounding points.
  • De-identification uses token-shape allowlists; no personal data is included.
  • Files changed, decisions, tests/runtime, risks, and next unblocked issue are documented below.

New tests (test/models/loan/current_minimum_payment_test.rb), red on main first, all on the issue's synthetic loan with a pinned opening valuation:

TestOn main
quotes the schedule's payment for the current period, not the actual-balance figure$2,236.66 ≠ $2,504.42
the figure is the one the schedule re-amortised at the rate changefails
an offset does not change the current minimum repaymentfails by ~$199
paying further ahead does not change itfails
a recorded rate change does change it (negative: not a constant)passes both
a payment due on as_of is behind it; the day before, it is the one in force (payment 12's date, where rows 12 and 13 differ)fails
before the first payment, the figure is the first row'sfails
a stale persisted schedule does not change the figurepasses both; load-bearing under M2
a loan with no start date reads the schedule from its opening anchorfails

Fixed, matured-fixed and matured-variable tests are kept unchanged. The lender-letter test (pure annuity maths) is kept.

Changed tests, with reasons

  • rate_change_table_test.rb:
    • "the current and new repayments sit on the same projected balance" and "an offset loan quotes the new repayment net of offset" asserted the reversed decision. They are replaced by "a future change's new repayment is the schedule row at that date" and "an offset and a lower actual balance change neither column".
    • "a change effective on a payment date is amortised over that payment too" becomes "...quoted from that payment's row".
    • "the offset total is summed once" is removed with the sum.
    • The fixture gains an opening valuation, so original_balance doesn't follow the balance.
  • payoff_projection_test.rb: four assertions compare against the actual-balance annuity rather than the card.

Mutations, each restored after:

MutationCaught by
Revert to the actual balance (main's body)the issue tests above
M1: payment_date >= as_of (shift the boundary by one period)the boundary test
M2: read persisted loan.amortizations rows instead of the simulationstale-schedule test, plus 7 others
M3: table reads the row strictly after the effective date"a future change's new repayment is the schedule row at that date"
M4: table lists every change, not the last before each payment"a change superseded before its payment is not listed"
M5: table keeps the first change before a payment instead of the last"a change superseded before its payment is not listed"
M6 (f6dadad33): drop the if row guard for a change past the last payment"a rate change after the loan's last payment is not listed" (NoMethodError)
M7 (16a034187): the old "lender's minimum" wording on the Schedule tab's caption only"the minimum payment caption says the schedule sets the figure, not the lender"

Golden master. Regenerated with LOAN_GOLDEN_MASTER_WRITE=1, then re-run without it:

test/fixtures/files/loan_golden_master/offset.json                       current_minimum_payment 1466.37 -> 1798.65
test/fixtures/files/loan_golden_master/variable_change_mid_period.json   current_minimum_payment 1647.28 -> 1670.03
test/fixtures/files/loan_golden_master/variable_change_on_payment_date.json  current_minimum_payment 2054.09 -> 2091.16

Only current_minimum_payment moves, and only on the three variable loans. Offset: the figure no longer nets the offset. The two rate-change loans: their account balances differ from the schedule, and the figure is now the scheduled one. Every schedule row and projection figure is unchanged.

Validation

  • Loan suites (test/models/loan*, test/models/loan/, test/components, loans, accounts, overview-labels and API loans controller tests): 706 runs, 0 failures. The 3 errors are the loan system tests, which need chromedriver; this container has none. CI runs them.
  • On f6dadad33: rate_change_table_test.rb, 14 runs, 0 failures; bin/rubocop on it, no offenses.
  • On 16a034187:
    • full bin/rails test: 12,374 runs, 1 failure, the known local-only Provider::OpenaiTest;
    • the accounts controller, i18n, minimum-payment and loan component tests: 158 runs, 0 failures;
    • erb_lint on the two tabs: clean.
  • bin/rubocop on changed Ruby files: no offenses. erb_lint on the touched templates: clean.
  • Checked against upstream AGENTS.md (read from mirror/upstream-main). Fork-only change.

Review findings

  • cubic, superseded rate changes (rate_change_table.rb): valid. Fixed in 690b2bd. Two changes landing before the same payment are priced at that payment on the later rate, so the table now lists only the last change before each schedule row. The new test "a change superseded before its payment is not listed" failed first (two rows); M4 and M5 above both fail it.

  • cubic, payoff projection class comment: fixed in f7574c4.

  • cubic, uk minimum_payment_rate left in English: declined. The string was already English on main (both occurrences), as are neighbouring loan keys such as variable_with_offset. This PR only rewords it. Translating the loan views is a separate locale pass.

  • Gatekeeper light review (comment 6095652354, continued in 6095652475): DRAFT_ON_TRACK, no material findings. Its recommendation, to keep the boundary and stale-schedule assertions alive as #100's decision-1 work lands on this method, holds: all 14 tests this PR adds are present, by name, on the integration branch (#404, 351a79693) and the engine swap (#405, 64b017f94), and pass in their CI.

  • "code master" review (comment 6105940070), hold, on 690b2bd. Each finding was checked against that head, with temporary probes:

    1. Schedule rebuilt per rate change: declined, measured.
      • Loan#amortization_schedule keeps one object while its inputs are unchanged (loan.rb:270-277), and payments is cached (amortization_schedule.rb:76-79).
      • For 1, 10 and 30 changes, this head runs 8, 17 and 37 queries in 214, 281 and 609 ms. main runs 333 queries in 1,022, 1,586 and 2,438 ms. The PR is faster.
      • The one per-change cost left is an account.reload SELECT (loan.rb:679), which #405 removes.
    2. Card and table disagree when a change is effective on as_of: declined as stated. The table excludes a change effective on as_of (rate_change_table.rb:101, effective_date > as_of), which "an injected as_of decides what counts as forthcoming" asserts, and its current column calls the card's own method. A probe at the boundary showed an empty table, a $2,504.42 card and a 6.43% caption.
      • But a real defect sits next to it, which the review didn't name: see "The payment a change already resizes" below (decided: option A).
    3. A change past maturity is dropped untested: test gap; test added in f6dadad33 ("a rate change after the loan's last payment is not listed", M6 above).
    4. payment_in_force on a loan with no payments: declined. It can't happen. current_minimum_payment returns nil first unless the loan is amortizable with payments left (loan.rb:487-490), and payments is empty only when the loan isn't amortizable (amortization_schedule.rb:77).
    5. The dedup assumes sorted changes: declined. Loan#variable_rates sorts by parsed date (loan.rb:583-585); a probe with keys stored out of order came back in date order. Dates are JSON keys, so a date can't appear twice.
    6. BigDecimal(row[:beginning_balance].to_s) raises on nil from a corrupted database: declined. The rows come from the in-memory simulation, not the database; every beginning_balance and payment_amount probed is a BigDecimal.
    7. Float rounding in Money.new(row[:payment_amount]): declined. Same probe: BigDecimal, with no JSON round trip.
    8. English text in ru, tr and uk: already decided, as the cubic finding above records; ru and tr were already English on main (line 58 and line 86).
    9. The deleted "offset total is summed once" test: declined. It tested the table's offset sum, which this PR removes with every offset read in the table (recorded under Changed tests).
    10. A user-visible figure change with no announcement: already decided. #392 "reverses a decision on purpose", and Risks below says so. The review's "10-23%" is also off: the golden master moves by +22.7% (offset), +1.4% and +1.8%.
  • Nightly review (comment 6120578253), READY WITH CONDITIONS, on ea75ae481: no blocking findings.

    • MEDIUM, UNVERIFIED lender minimum: agreed that no lender statement backs the figure. The caption is softened in 16a034187, at the owner's instruction (2026-10-12: "soften the caption"), which was the second option the review named.
      • It read: "The next scheduled repayment, sized at %{rate}: your lender's minimum, unchanged by paying ahead or an offset".
      • It now reads: "The next repayment your loan's schedule sets, sized at %{rate}. Paying ahead or an offset doesn't change it."
      • The rate the repayment is sized at is kept, and so is the point that paying ahead or an offset doesn't move it. en, ru, tr and uk carry the same English string, as before.
    • Test: "the minimum payment caption says the schedule sets the figure, not the lender", on both tabs.
      • It failed first.
      • Restoring the old wording on the Schedule tab's copy alone fails it again (M7).
      • "the minimum payment caption names the rate the next repayment is sized at" still passes.
    • Sibling, 7d2ddf35c: the rate change table's caption, under a Current repayment column that reads current_minimum_payment, still claimed the lender match. It now reads: "Estimated from your loan's terms: at each recorded rate change the scheduled balance is re-amortised over the payments remaining to the original payoff date. Paying ahead or holding an offset lowers your interest, not this repayment. Your lender's figures may differ." Test: "the assumptions caption calls the figures estimates, not the lender's"; it failed first, and restoring "which is how lenders set the minimum repayment" alone fails it again.
    • Propagation: 16a034187 merged into claude/loans-integration-base, then #405 (which resolved a locale conflict beside its removed recalculating key), #415 and #404. 7d2ddf35c followed the same path without conflicts: integration base dc8f2a23a, #405 61f57c2cd, #415 3848dd0f0, #404 b87220e12.
  • Nightly review (comment 6134299163), READY TO MERGE, on 7d2ddf35c. No blocking or other material findings. Its summary matches this description: the card quotes the schedule's repayment, the rate and the table read the row in force, and the copy calls the figures schedule-derived. Nothing to change.

Review responses are recorded here rather than as thread replies, because replies posted from this session get an assistant footer appended, which this repository's attribution rule forbids.

The payment a change already resizes: decided, option A (ea75ae481)

What happens. On the issue's loan (5.50%, moving to 6.43% effective 2023-02-15, payment 13's date), take any as_of from payment 12's date (2023-01-15) up to the day before the change:

  • current_minimum_payment returns payment 13's row, $2,504.42. That row is sized at 6.43%, because the payment clock resizes the next payment for a change on or before it (simulator.rb:278-283).
  • Both cards' captions pass current_variable_rate(as_of), which is still 5.5%. So the card reads "$2,504.42 ... at the current rate of 5.5%".
  • The change is still in the future, so the table lists it. Its new repayment is the row the change resizes, the same payment 13. The row reads 5.5% → 6.43%, $2,504.42 → $2,504.42.

The same happens for a change partway through a period. On main the same input reads $2,302.17 → $2,538.64, so this is new with this PR. The existing table fixture (as_of = effective_on - 1.day) shows the same thing, $2,396.35 → $2,396.35, because that test only counts rows. It survives into #405 unchanged.

Decided (owner, 2026-10-11): option A, built in ea75ae481. It followed from two rules the issue set: the card shows the next payment due, and a change's new figure is the row it resizes. Neither said what the caption and the table's current column should show once that next payment already carries the new rate. The two options were:

  • (A) Recommended. The caption and the table's current rate read the rate of the row in force (6.43% here), and the table leaves out a change whose row is at or before the row in force, because that change is already in the card's figure. The card stays right, and the table stops showing a change that has already priced the next payment. One existing table test changes with it.
  • (B) Keep the row, and label the current column as the previous payment. That breaks the rule that the current column is the card's figure.

What ea75ae481 does:

  • Loan#minimum_payment_rate(as_of:) is the rate of the schedule row in force. That is today's rate for a fixed loan, or for one with nothing left to pay.
  • Both card captions (Overview and Schedule) and the table's current rate read it. The caption now names the rate the repayment is "sized at" rather than "the current rate", because in this window the rate card rightly still shows today's rate. The en, ru, tr and uk files carry the same English string, as before.
  • The table leaves out a change whose row is the payment in force: that repayment is already the card's figure.

Tests, each failing first:

  • "the minimum payment's rate is the rate of the row in force": 6.43 between payment 12 and the change, and 5.5 before payment 12.
  • "a fixed loan's minimum payment rate is its rate".
  • "a change that has already resized the payment in force is not listed": it listed $2,396.35 → $2,396.35.
  • "the minimum payment caption names the rate the next repayment is sized at": both tabs; reverting either view fails it.
  • The existing "an injected as_of decides what counts as forthcoming" now checks a change 40 days out (listed) and on its date (not listed). The day before is the new case above.

Siblings: the Overview's Current Interest Rate card keeps current_variable_rate, which is the rate in force today. RateResolver and variable_rate_update_for read it for the engine and the providers.

Validation:

  • The loan, component and controller suites plus i18n_test: 660 runs, 0 failures, after restarting Redis for the 17 API tests it had errored.
  • Full bin/rails test on ea75ae481: 12,373 runs, 1 failure, the known local-only Provider::OpenaiTest.
  • RuboCop and erb_lint: clean.

Risks, blockers, and follow-up

  • This reverses #15's specification on purpose, as the issue says. A borrower who wants the "if re-amortised today" figure no longer sees it anywhere; that card is the owner's open question.
  • The payment a change already resizes is decided (option A, above).
  • The figure is the schedule's, not a lender-confirmed one, and the captions now say so (16a034187, 7d2ddf35c). A rate-reset statement comparison would still be worth recording when one is available.
  • Follow-up: PayoffProjection on the schedule's payment by period (#100 decision 1) is #401.
  • Not checked here: the issue's real-loan comparison. The issue's comment records it as done against upstream's card, which uses the same method.