FA-58686 / Loan amortization schedules / Open access
Annual escrow analysis: credit after refund · case 01
Borrowers receive a refund and a monthly credit for the same surplus.
ROOT CAUSE
The monthly surplus credit is applied even when the surplus was refunded.
VERIFIED REPAIR
Credit the surplus monthly only when it was not refunded.
Unsuccessful approach: Rounding the credit half-up credits more than the retained surplus.
Case contract
x = {'disbursements': annual amounts, 'low_point': projected lowest balance, 'cushion_months', 'refund_threshold'}. total = sum; base = round_half_up(total/12); cushion = round_half_up(total*cushion_months/12); diff = low_point - cushion; shortage = max(0, -diff) is collected over 12 months rounded up; surplus = max(0, diff) is refunded when >= refund_threshold, otherwise floor(surplus/12) is credited monthly. Return {'base', 'cushion', 'shortage', 'refund', 'monthly'}.
Why this case matters
Amortization engines drive borrower statements, payoff quotes and investor remittances; a misplaced rounding step, boundary or ordering rule compounds across hundreds of periods.
1 / The failure
Exit 1"""Failure Map reference implementation. Python standard library only."""
import json
N = 1
observations = []
def solve(x):
def rnd(n, d):
q, r = divmod(n, d)
return q + (1 if 2 * r >= d else 0)
total = sum(x['disbursements'])
base = rnd(total, 12)
cushion = rnd(total * x['cushion_months'], 12)
diff = x['low_point'] - cushion
shortage = max(0, -diff)
surplus = max(0, diff)
refund = surplus if surplus >= x['refund_threshold'] else 0
monthly = base + (shortage + 11) // 12 - surplus // 12
return {'base': base, 'cushion': cushion, 'shortage': shortage, 'refund': refund, 'monthly': monthly}
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: credit after refund', {'disbursements': [99999, 250000], 'low_point': 80000, 'cushion_months': 1, 'refund_threshold': 0}, {'base': 29167, 'cushion': 29167, 'shortage': 0, 'refund': 50833, 'monthly': 29167}], ['regression: credit after refund, partial-repair probe', {'disbursements': [7, 120000, 7], 'low_point': 40000, 'cushion_months': 2, 'refund_threshold': 20000}, {'base': 10001, 'cushion': 20002, 'shortage': 0, 'refund': 0, 'monthly': 8335}], ['control 1', {'disbursements': [120000, 36000, 99999], 'low_point': -5000, 'cushion_months': 2, 'refund_threshold': 20000}, {'base': 21333, 'cushion': 42667, 'shortage': 47667, 'refund': 0, 'monthly': 25306}], ['control 2', {'disbursements': [120000], 'low_point': 0, 'cushion_months': 1, 'refund_threshold': 20000}, {'base': 10000, 'cushion': 10000, 'shortage': 10000, 'refund': 0, 'monthly': 10834}], ['control 3', {'disbursements': [36000, 120000, 7], 'low_point': -5000, 'cushion_months': 2, 'refund_threshold': 20000}, {'base': 13001, 'cushion': 26001, 'shortage': 31001, 'refund': 0, 'monthly': 15585}], ['control 4', {'disbursements': [99999, 250000, 7], 'low_point': -5000, 'cushion_months': 1, 'refund_threshold': 20000}, {'base': 29167, 'cushion': 29167, 'shortage': 34167, 'refund': 0, 'monthly': 32015}], ['control 5', {'disbursements': [36000, 250000, 250000], 'low_point': -5000, 'cushion_months': 2, 'refund_threshold': 5000}, {'base': 44667, 'cushion': 89333, 'shortage': 94333, 'refund': 0, 'monthly': 52529}]], [['regression: credit after refund', {'disbursements': [120000, 36000], 'low_point': 80000, 'cushion_months': 1, 'refund_threshold': 0}, {'base': 13000, 'cushion': 13000, 'shortage': 0, 'refund': 67000, 'monthly': 13000}], ['regression: credit after refund, partial-repair probe', {'disbursements': [7, 120000], 'low_point': 40000, 'cushion_months': 2, 'refund_threshold': 20000}, {'base': 10001, 'cushion': 20001, 'shortage': 0, 'refund': 0, 'monthly': 8335}], ['control 1', {'disbursements': [36000], 'low_point': 10000, 'cushion_months': 2, 'refund_threshold': 5000}, {'base': 3000, 'cushion': 6000, 'shortage': 0, 'refund': 0, 'monthly': 2667}], ['control 2', {'disbursements': [7, 36000], 'low_point': 0, 'cushion_months': 0, 'refund_threshold': 0}, {'base': 3001, 'cushion': 0, 'shortage': 0, 'refund': 0, 'monthly': 3001}], ['control 3', {'disbursements': [120000, 120000], 'low_point': 40000, 'cushion_months': 2, 'refund_threshold': 5000}, {'base': 20000, 'cushion': 40000, 'shortage': 0, 'refund': 0, 'monthly': 20000}], ['control 4', {'disbursements': [250000, 99999, 120000], 'low_point': 150000, 'cushion_months': 5, 'refund_threshold': 20000}, {'base': 39167, 'cushion': 195833, 'shortage': 45833, 'refund': 0, 'monthly': 42987}], ['control 5', {'disbursements': [250000, 120000, 99999], 'low_point': -5000, 'cushion_months': 1, 'refund_threshold': 20000}, {'base': 39167, 'cushion': 39167, 'shortage': 44167, 'refund': 0, 'monthly': 42848}]], [['regression: credit after refund', {'disbursements': [250000, 120000], 'low_point': 80000, 'cushion_months': 1, 'refund_threshold': 20000}, {'base': 30833, 'cushion': 30833, 'shortage': 0, 'refund': 49167, 'monthly': 30833}], ['regression: credit after refund, partial-repair probe', {'disbursements': [250000, 36000, 120000], 'low_point': 80000, 'cushion_months': 2, 'refund_threshold': 20000}, {'base': 33833, 'cushion': 67667, 'shortage': 0, 'refund': 0, 'monthly': 32806}], ['control 1', {'disbursements': [36000], 'low_point': 0, 'cushion_months': 5, 'refund_threshold': 5000}, {'base': 3000, 'cushion': 15000, 'shortage': 15000, 'refund': 0, 'monthly': 4250}], ['control 2', {'disbursements': [120000, 36000], 'low_point': 0, 'cushion_months': 1, 'refund_threshold': 0}, {'base': 13000, 'cushion': 13000, 'shortage': 13000, 'refund': 0, 'monthly': 14084}], ['control 3', {'disbursements': [120000, 120000, 7], 'low_point': 80000, 'cushion_months': 5, 'refund_threshold': 5000}, {'base': 20001, 'cushion': 100003, 'shortage': 20003, 'refund': 0, 'monthly': 21668}], ['control 4', {'disbursements': [120000, 120000, 7], 'low_point': 0, 'cushion_months': 2, 'refund_threshold': 5000}, {'base': 20001, 'cushion': 40001, 'shortage': 40001, 'refund': 0, 'monthly': 23335}], ['control 5', {'disbursements': [99999], 'low_point': -5000, 'cushion_months': 1, 'refund_threshold': 5000}, {'base': 8333, 'cushion': 8333, 'shortage': 13333, 'refund': 0, 'monthly': 9445}]], [['regression: credit after refund', {'disbursements': [99999, 36000], 'low_point': 150000, 'cushion_months': 1, 'refund_threshold': 20000}, {'base': 11333, 'cushion': 11333, 'shortage': 0, 'refund': 138667, 'monthly': 11333}], ['regression: credit after refund, partial-repair probe', {'disbursements': [250000, 99999], 'low_point': 40000, 'cushion_months': 1, 'refund_threshold': 20000}, {'base': 29167, 'cushion': 29167, 'shortage': 0, 'refund': 0, 'monthly': 28265}], ['control 1', {'disbursements': [36000], 'low_point': -5000, 'cushion_months': 0, 'refund_threshold': 0}, {'base': 3000, 'cushion': 0, 'shortage': 5000, 'refund': 0, 'monthly': 3417}], ['control 2', {'disbursements': [36000], 'low_point': 0, 'cushion_months': 2, 'refund_threshold': 0}, {'base': 3000, 'cushion': 6000, 'shortage': 6000, 'refund': 0, 'monthly': 3500}], ['control 3', {'disbursements': [36000, 250000], 'low_point': -5000, 'cushion_months': 0, 'refund_threshold': 0}, {'base': 23833, 'cushion': 0, 'shortage': 5000, 'refund': 0, 'monthly': 24250}], ['control 4', {'disbursements': [36000, 120000], 'low_point': 0, 'cushion_months': 1, 'refund_threshold': 20000}, {'base': 13000, 'cushion': 13000, 'shortage': 13000, 'refund': 0, 'monthly': 14084}], ['control 5', {'disbursements': [7, 250000, 7], 'low_point': 0, 'cushion_months': 2, 'refund_threshold': 5000}, {'base': 20835, 'cushion': 41669, 'shortage': 41669, 'refund': 0, 'monthly': 24308}]], [['regression: credit after refund', {'disbursements': [120000], 'low_point': 150000, 'cushion_months': 5, 'refund_threshold': 20000}, {'base': 10000, 'cushion': 50000, 'shortage': 0, 'refund': 100000, 'monthly': 10000}], ['regression: credit after refund, partial-repair probe', {'disbursements': [99999, 99999, 250000], 'low_point': 80000, 'cushion_months': 2, 'refund_threshold': 20000}, {'base': 37500, 'cushion': 75000, 'shortage': 0, 'refund': 0, 'monthly': 37084}], ['control 1', {'disbursements': [99999], 'low_point': -5000, 'cushion_months': 0, 'refund_threshold': 20000}, {'base': 8333, 'cushion': 0, 'shortage': 5000, 'refund': 0, 'monthly': 8750}], ['control 2', {'disbursements': [120000, 7], 'low_point': 0, 'cushion_months': 2, 'refund_threshold': 20000}, {'base': 10001, 'cushion': 20001, 'shortage': 20001, 'refund': 0, 'monthly': 11668}], ['control 3', {'disbursements': [120000, 7], 'low_point': 40000, 'cushion_months': 5, 'refund_threshold': 20000}, {'base': 10001, 'cushion': 50003, 'shortage': 10003, 'refund': 0, 'monthly': 10835}], ['control 4', {'disbursements': [36000, 7, 36000], 'low_point': 10000, 'cushion_months': 5, 'refund_threshold': 20000}, {'base': 6001, 'cushion': 30003, 'shortage': 20003, 'refund': 0, 'monthly': 7668}], ['control 5', {'disbursements': [250000, 36000], 'low_point': 40000, 'cushion_months': 2, 'refund_threshold': 20000}, {'base': 23833, 'cushion': 47667, 'shortage': 7667, 'refund': 0, 'monthly': 24472}]]]
for label, args, expected in fixtures[N-1]:
try:
actual = solve(args)
except Exception as exc:
actual = 'raised ' + type(exc).__name__
check(label, actual, expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
| Boundary fixture | Actual | Expected | Outcome |
|---|---|---|---|
| regression: credit after refund | {'base': 29167, 'cushion': 29167, 'monthly': 24931, 'refund': 50833, 'shortage': 0} | {'base': 29167, 'cushion': 29167, 'monthly': 29167, 'refund': 50833, 'shortage': 0} | Failed |
| regression: credit after refund, partial-repair probe | {'base': 10001, 'cushion': 20002, 'monthly': 8335, 'refund': 0, 'shortage': 0} | {'base': 10001, 'cushion': 20002, 'monthly': 8335, 'refund': 0, 'shortage': 0} | Passed |
| control 1 | {'base': 21333, 'cushion': 42667, 'monthly': 25306, 'refund': 0, 'shortage': 47667} | {'base': 21333, 'cushion': 42667, 'monthly': 25306, 'refund': 0, 'shortage': 47667} | Passed |
| control 2 | {'base': 10000, 'cushion': 10000, 'monthly': 10834, 'refund': 0, 'shortage': 10000} | {'base': 10000, 'cushion': 10000, 'monthly': 10834, 'refund': 0, 'shortage': 10000} | Passed |
| control 3 | {'base': 13001, 'cushion': 26001, 'monthly': 15585, 'refund': 0, 'shortage': 31001} | {'base': 13001, 'cushion': 26001, 'monthly': 15585, 'refund': 0, 'shortage': 31001} | Passed |
| control 4 | {'base': 29167, 'cushion': 29167, 'monthly': 32015, 'refund': 0, 'shortage': 34167} | {'base': 29167, 'cushion': 29167, 'monthly': 32015, 'refund': 0, 'shortage': 34167} | Passed |
| control 5 | {'base': 44667, 'cushion': 89333, 'monthly': 52529, 'refund': 0, 'shortage': 94333} | {'base': 44667, 'cushion': 89333, 'monthly': 52529, 'refund': 0, 'shortage': 94333} | Passed |
SHA-256 / e1da997bf134bc9cac3238fd0140e5a25f27b2465606dfe9690163718e255e26
2 / The unsuccessful fix
Exit 1"""Failure Map reference implementation. Python standard library only."""
import json
N = 1
observations = []
def solve(x):
def rnd(n, d):
q, r = divmod(n, d)
return q + (1 if 2 * r >= d else 0)
total = sum(x['disbursements'])
base = rnd(total, 12)
cushion = rnd(total * x['cushion_months'], 12)
diff = x['low_point'] - cushion
shortage = max(0, -diff)
surplus = max(0, diff)
refund = surplus if surplus >= x['refund_threshold'] else 0
monthly = base + (shortage + 11) // 12 - (0 if refund else rnd(surplus, 12))
return {'base': base, 'cushion': cushion, 'shortage': shortage, 'refund': refund, 'monthly': monthly}
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: credit after refund', {'disbursements': [99999, 250000], 'low_point': 80000, 'cushion_months': 1, 'refund_threshold': 0}, {'base': 29167, 'cushion': 29167, 'shortage': 0, 'refund': 50833, 'monthly': 29167}], ['regression: credit after refund, partial-repair probe', {'disbursements': [7, 120000, 7], 'low_point': 40000, 'cushion_months': 2, 'refund_threshold': 20000}, {'base': 10001, 'cushion': 20002, 'shortage': 0, 'refund': 0, 'monthly': 8335}], ['control 1', {'disbursements': [120000, 36000, 99999], 'low_point': -5000, 'cushion_months': 2, 'refund_threshold': 20000}, {'base': 21333, 'cushion': 42667, 'shortage': 47667, 'refund': 0, 'monthly': 25306}], ['control 2', {'disbursements': [120000], 'low_point': 0, 'cushion_months': 1, 'refund_threshold': 20000}, {'base': 10000, 'cushion': 10000, 'shortage': 10000, 'refund': 0, 'monthly': 10834}], ['control 3', {'disbursements': [36000, 120000, 7], 'low_point': -5000, 'cushion_months': 2, 'refund_threshold': 20000}, {'base': 13001, 'cushion': 26001, 'shortage': 31001, 'refund': 0, 'monthly': 15585}], ['control 4', {'disbursements': [99999, 250000, 7], 'low_point': -5000, 'cushion_months': 1, 'refund_threshold': 20000}, {'base': 29167, 'cushion': 29167, 'shortage': 34167, 'refund': 0, 'monthly': 32015}], ['control 5', {'disbursements': [36000, 250000, 250000], 'low_point': -5000, 'cushion_months': 2, 'refund_threshold': 5000}, {'base': 44667, 'cushion': 89333, 'shortage': 94333, 'refund': 0, 'monthly': 52529}]], [['regression: credit after refund', {'disbursements': [120000, 36000], 'low_point': 80000, 'cushion_months': 1, 'refund_threshold': 0}, {'base': 13000, 'cushion': 13000, 'shortage': 0, 'refund': 67000, 'monthly': 13000}], ['regression: credit after refund, partial-repair probe', {'disbursements': [7, 120000], 'low_point': 40000, 'cushion_months': 2, 'refund_threshold': 20000}, {'base': 10001, 'cushion': 20001, 'shortage': 0, 'refund': 0, 'monthly': 8335}], ['control 1', {'disbursements': [36000], 'low_point': 10000, 'cushion_months': 2, 'refund_threshold': 5000}, {'base': 3000, 'cushion': 6000, 'shortage': 0, 'refund': 0, 'monthly': 2667}], ['control 2', {'disbursements': [7, 36000], 'low_point': 0, 'cushion_months': 0, 'refund_threshold': 0}, {'base': 3001, 'cushion': 0, 'shortage': 0, 'refund': 0, 'monthly': 3001}], ['control 3', {'disbursements': [120000, 120000], 'low_point': 40000, 'cushion_months': 2, 'refund_threshold': 5000}, {'base': 20000, 'cushion': 40000, 'shortage': 0, 'refund': 0, 'monthly': 20000}], ['control 4', {'disbursements': [250000, 99999, 120000], 'low_point': 150000, 'cushion_months': 5, 'refund_threshold': 20000}, {'base': 39167, 'cushion': 195833, 'shortage': 45833, 'refund': 0, 'monthly': 42987}], ['control 5', {'disbursements': [250000, 120000, 99999], 'low_point': -5000, 'cushion_months': 1, 'refund_threshold': 20000}, {'base': 39167, 'cushion': 39167, 'shortage': 44167, 'refund': 0, 'monthly': 42848}]], [['regression: credit after refund', {'disbursements': [250000, 120000], 'low_point': 80000, 'cushion_months': 1, 'refund_threshold': 20000}, {'base': 30833, 'cushion': 30833, 'shortage': 0, 'refund': 49167, 'monthly': 30833}], ['regression: credit after refund, partial-repair probe', {'disbursements': [250000, 36000, 120000], 'low_point': 80000, 'cushion_months': 2, 'refund_threshold': 20000}, {'base': 33833, 'cushion': 67667, 'shortage': 0, 'refund': 0, 'monthly': 32806}], ['control 1', {'disbursements': [36000], 'low_point': 0, 'cushion_months': 5, 'refund_threshold': 5000}, {'base': 3000, 'cushion': 15000, 'shortage': 15000, 'refund': 0, 'monthly': 4250}], ['control 2', {'disbursements': [120000, 36000], 'low_point': 0, 'cushion_months': 1, 'refund_threshold': 0}, {'base': 13000, 'cushion': 13000, 'shortage': 13000, 'refund': 0, 'monthly': 14084}], ['control 3', {'disbursements': [120000, 120000, 7], 'low_point': 80000, 'cushion_months': 5, 'refund_threshold': 5000}, {'base': 20001, 'cushion': 100003, 'shortage': 20003, 'refund': 0, 'monthly': 21668}], ['control 4', {'disbursements': [120000, 120000, 7], 'low_point': 0, 'cushion_months': 2, 'refund_threshold': 5000}, {'base': 20001, 'cushion': 40001, 'shortage': 40001, 'refund': 0, 'monthly': 23335}], ['control 5', {'disbursements': [99999], 'low_point': -5000, 'cushion_months': 1, 'refund_threshold': 5000}, {'base': 8333, 'cushion': 8333, 'shortage': 13333, 'refund': 0, 'monthly': 9445}]], [['regression: credit after refund', {'disbursements': [99999, 36000], 'low_point': 150000, 'cushion_months': 1, 'refund_threshold': 20000}, {'base': 11333, 'cushion': 11333, 'shortage': 0, 'refund': 138667, 'monthly': 11333}], ['regression: credit after refund, partial-repair probe', {'disbursements': [250000, 99999], 'low_point': 40000, 'cushion_months': 1, 'refund_threshold': 20000}, {'base': 29167, 'cushion': 29167, 'shortage': 0, 'refund': 0, 'monthly': 28265}], ['control 1', {'disbursements': [36000], 'low_point': -5000, 'cushion_months': 0, 'refund_threshold': 0}, {'base': 3000, 'cushion': 0, 'shortage': 5000, 'refund': 0, 'monthly': 3417}], ['control 2', {'disbursements': [36000], 'low_point': 0, 'cushion_months': 2, 'refund_threshold': 0}, {'base': 3000, 'cushion': 6000, 'shortage': 6000, 'refund': 0, 'monthly': 3500}], ['control 3', {'disbursements': [36000, 250000], 'low_point': -5000, 'cushion_months': 0, 'refund_threshold': 0}, {'base': 23833, 'cushion': 0, 'shortage': 5000, 'refund': 0, 'monthly': 24250}], ['control 4', {'disbursements': [36000, 120000], 'low_point': 0, 'cushion_months': 1, 'refund_threshold': 20000}, {'base': 13000, 'cushion': 13000, 'shortage': 13000, 'refund': 0, 'monthly': 14084}], ['control 5', {'disbursements': [7, 250000, 7], 'low_point': 0, 'cushion_months': 2, 'refund_threshold': 5000}, {'base': 20835, 'cushion': 41669, 'shortage': 41669, 'refund': 0, 'monthly': 24308}]], [['regression: credit after refund', {'disbursements': [120000], 'low_point': 150000, 'cushion_months': 5, 'refund_threshold': 20000}, {'base': 10000, 'cushion': 50000, 'shortage': 0, 'refund': 100000, 'monthly': 10000}], ['regression: credit after refund, partial-repair probe', {'disbursements': [99999, 99999, 250000], 'low_point': 80000, 'cushion_months': 2, 'refund_threshold': 20000}, {'base': 37500, 'cushion': 75000, 'shortage': 0, 'refund': 0, 'monthly': 37084}], ['control 1', {'disbursements': [99999], 'low_point': -5000, 'cushion_months': 0, 'refund_threshold': 20000}, {'base': 8333, 'cushion': 0, 'shortage': 5000, 'refund': 0, 'monthly': 8750}], ['control 2', {'disbursements': [120000, 7], 'low_point': 0, 'cushion_months': 2, 'refund_threshold': 20000}, {'base': 10001, 'cushion': 20001, 'shortage': 20001, 'refund': 0, 'monthly': 11668}], ['control 3', {'disbursements': [120000, 7], 'low_point': 40000, 'cushion_months': 5, 'refund_threshold': 20000}, {'base': 10001, 'cushion': 50003, 'shortage': 10003, 'refund': 0, 'monthly': 10835}], ['control 4', {'disbursements': [36000, 7, 36000], 'low_point': 10000, 'cushion_months': 5, 'refund_threshold': 20000}, {'base': 6001, 'cushion': 30003, 'shortage': 20003, 'refund': 0, 'monthly': 7668}], ['control 5', {'disbursements': [250000, 36000], 'low_point': 40000, 'cushion_months': 2, 'refund_threshold': 20000}, {'base': 23833, 'cushion': 47667, 'shortage': 7667, 'refund': 0, 'monthly': 24472}]]]
for label, args, expected in fixtures[N-1]:
try:
actual = solve(args)
except Exception as exc:
actual = 'raised ' + type(exc).__name__
check(label, actual, expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
| Boundary fixture | Actual | Expected | Outcome |
|---|---|---|---|
| regression: credit after refund | {'base': 29167, 'cushion': 29167, 'monthly': 29167, 'refund': 50833, 'shortage': 0} | {'base': 29167, 'cushion': 29167, 'monthly': 29167, 'refund': 50833, 'shortage': 0} | Passed |
| regression: credit after refund, partial-repair probe | {'base': 10001, 'cushion': 20002, 'monthly': 8334, 'refund': 0, 'shortage': 0} | {'base': 10001, 'cushion': 20002, 'monthly': 8335, 'refund': 0, 'shortage': 0} | Failed |
| control 1 | {'base': 21333, 'cushion': 42667, 'monthly': 25306, 'refund': 0, 'shortage': 47667} | {'base': 21333, 'cushion': 42667, 'monthly': 25306, 'refund': 0, 'shortage': 47667} | Passed |
| control 2 | {'base': 10000, 'cushion': 10000, 'monthly': 10834, 'refund': 0, 'shortage': 10000} | {'base': 10000, 'cushion': 10000, 'monthly': 10834, 'refund': 0, 'shortage': 10000} | Passed |
| control 3 | {'base': 13001, 'cushion': 26001, 'monthly': 15585, 'refund': 0, 'shortage': 31001} | {'base': 13001, 'cushion': 26001, 'monthly': 15585, 'refund': 0, 'shortage': 31001} | Passed |
| control 4 | {'base': 29167, 'cushion': 29167, 'monthly': 32015, 'refund': 0, 'shortage': 34167} | {'base': 29167, 'cushion': 29167, 'monthly': 32015, 'refund': 0, 'shortage': 34167} | Passed |
| control 5 | {'base': 44667, 'cushion': 89333, 'monthly': 52529, 'refund': 0, 'shortage': 94333} | {'base': 44667, 'cushion': 89333, 'monthly': 52529, 'refund': 0, 'shortage': 94333} | Passed |
SHA-256 / d8cf8c9e45919c9d732cb64a9251e1ac0a5d1cd501f931717f3866f24d596b65
3 / The verified repair
Exit 0"""Failure Map reference implementation. Python standard library only."""
import json
N = 1
observations = []
def solve(x):
def rnd(n, d):
q, r = divmod(n, d)
return q + (1 if 2 * r >= d else 0)
total = sum(x['disbursements'])
base = rnd(total, 12)
cushion = rnd(total * x['cushion_months'], 12)
diff = x['low_point'] - cushion
shortage = max(0, -diff)
surplus = max(0, diff)
refund = surplus if surplus >= x['refund_threshold'] else 0
monthly = base + (shortage + 11) // 12 - (0 if refund else surplus // 12)
return {'base': base, 'cushion': cushion, 'shortage': shortage, 'refund': refund, 'monthly': monthly}
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: credit after refund', {'disbursements': [99999, 250000], 'low_point': 80000, 'cushion_months': 1, 'refund_threshold': 0}, {'base': 29167, 'cushion': 29167, 'shortage': 0, 'refund': 50833, 'monthly': 29167}], ['regression: credit after refund, partial-repair probe', {'disbursements': [7, 120000, 7], 'low_point': 40000, 'cushion_months': 2, 'refund_threshold': 20000}, {'base': 10001, 'cushion': 20002, 'shortage': 0, 'refund': 0, 'monthly': 8335}], ['control 1', {'disbursements': [120000, 36000, 99999], 'low_point': -5000, 'cushion_months': 2, 'refund_threshold': 20000}, {'base': 21333, 'cushion': 42667, 'shortage': 47667, 'refund': 0, 'monthly': 25306}], ['control 2', {'disbursements': [120000], 'low_point': 0, 'cushion_months': 1, 'refund_threshold': 20000}, {'base': 10000, 'cushion': 10000, 'shortage': 10000, 'refund': 0, 'monthly': 10834}], ['control 3', {'disbursements': [36000, 120000, 7], 'low_point': -5000, 'cushion_months': 2, 'refund_threshold': 20000}, {'base': 13001, 'cushion': 26001, 'shortage': 31001, 'refund': 0, 'monthly': 15585}], ['control 4', {'disbursements': [99999, 250000, 7], 'low_point': -5000, 'cushion_months': 1, 'refund_threshold': 20000}, {'base': 29167, 'cushion': 29167, 'shortage': 34167, 'refund': 0, 'monthly': 32015}], ['control 5', {'disbursements': [36000, 250000, 250000], 'low_point': -5000, 'cushion_months': 2, 'refund_threshold': 5000}, {'base': 44667, 'cushion': 89333, 'shortage': 94333, 'refund': 0, 'monthly': 52529}]], [['regression: credit after refund', {'disbursements': [120000, 36000], 'low_point': 80000, 'cushion_months': 1, 'refund_threshold': 0}, {'base': 13000, 'cushion': 13000, 'shortage': 0, 'refund': 67000, 'monthly': 13000}], ['regression: credit after refund, partial-repair probe', {'disbursements': [7, 120000], 'low_point': 40000, 'cushion_months': 2, 'refund_threshold': 20000}, {'base': 10001, 'cushion': 20001, 'shortage': 0, 'refund': 0, 'monthly': 8335}], ['control 1', {'disbursements': [36000], 'low_point': 10000, 'cushion_months': 2, 'refund_threshold': 5000}, {'base': 3000, 'cushion': 6000, 'shortage': 0, 'refund': 0, 'monthly': 2667}], ['control 2', {'disbursements': [7, 36000], 'low_point': 0, 'cushion_months': 0, 'refund_threshold': 0}, {'base': 3001, 'cushion': 0, 'shortage': 0, 'refund': 0, 'monthly': 3001}], ['control 3', {'disbursements': [120000, 120000], 'low_point': 40000, 'cushion_months': 2, 'refund_threshold': 5000}, {'base': 20000, 'cushion': 40000, 'shortage': 0, 'refund': 0, 'monthly': 20000}], ['control 4', {'disbursements': [250000, 99999, 120000], 'low_point': 150000, 'cushion_months': 5, 'refund_threshold': 20000}, {'base': 39167, 'cushion': 195833, 'shortage': 45833, 'refund': 0, 'monthly': 42987}], ['control 5', {'disbursements': [250000, 120000, 99999], 'low_point': -5000, 'cushion_months': 1, 'refund_threshold': 20000}, {'base': 39167, 'cushion': 39167, 'shortage': 44167, 'refund': 0, 'monthly': 42848}]], [['regression: credit after refund', {'disbursements': [250000, 120000], 'low_point': 80000, 'cushion_months': 1, 'refund_threshold': 20000}, {'base': 30833, 'cushion': 30833, 'shortage': 0, 'refund': 49167, 'monthly': 30833}], ['regression: credit after refund, partial-repair probe', {'disbursements': [250000, 36000, 120000], 'low_point': 80000, 'cushion_months': 2, 'refund_threshold': 20000}, {'base': 33833, 'cushion': 67667, 'shortage': 0, 'refund': 0, 'monthly': 32806}], ['control 1', {'disbursements': [36000], 'low_point': 0, 'cushion_months': 5, 'refund_threshold': 5000}, {'base': 3000, 'cushion': 15000, 'shortage': 15000, 'refund': 0, 'monthly': 4250}], ['control 2', {'disbursements': [120000, 36000], 'low_point': 0, 'cushion_months': 1, 'refund_threshold': 0}, {'base': 13000, 'cushion': 13000, 'shortage': 13000, 'refund': 0, 'monthly': 14084}], ['control 3', {'disbursements': [120000, 120000, 7], 'low_point': 80000, 'cushion_months': 5, 'refund_threshold': 5000}, {'base': 20001, 'cushion': 100003, 'shortage': 20003, 'refund': 0, 'monthly': 21668}], ['control 4', {'disbursements': [120000, 120000, 7], 'low_point': 0, 'cushion_months': 2, 'refund_threshold': 5000}, {'base': 20001, 'cushion': 40001, 'shortage': 40001, 'refund': 0, 'monthly': 23335}], ['control 5', {'disbursements': [99999], 'low_point': -5000, 'cushion_months': 1, 'refund_threshold': 5000}, {'base': 8333, 'cushion': 8333, 'shortage': 13333, 'refund': 0, 'monthly': 9445}]], [['regression: credit after refund', {'disbursements': [99999, 36000], 'low_point': 150000, 'cushion_months': 1, 'refund_threshold': 20000}, {'base': 11333, 'cushion': 11333, 'shortage': 0, 'refund': 138667, 'monthly': 11333}], ['regression: credit after refund, partial-repair probe', {'disbursements': [250000, 99999], 'low_point': 40000, 'cushion_months': 1, 'refund_threshold': 20000}, {'base': 29167, 'cushion': 29167, 'shortage': 0, 'refund': 0, 'monthly': 28265}], ['control 1', {'disbursements': [36000], 'low_point': -5000, 'cushion_months': 0, 'refund_threshold': 0}, {'base': 3000, 'cushion': 0, 'shortage': 5000, 'refund': 0, 'monthly': 3417}], ['control 2', {'disbursements': [36000], 'low_point': 0, 'cushion_months': 2, 'refund_threshold': 0}, {'base': 3000, 'cushion': 6000, 'shortage': 6000, 'refund': 0, 'monthly': 3500}], ['control 3', {'disbursements': [36000, 250000], 'low_point': -5000, 'cushion_months': 0, 'refund_threshold': 0}, {'base': 23833, 'cushion': 0, 'shortage': 5000, 'refund': 0, 'monthly': 24250}], ['control 4', {'disbursements': [36000, 120000], 'low_point': 0, 'cushion_months': 1, 'refund_threshold': 20000}, {'base': 13000, 'cushion': 13000, 'shortage': 13000, 'refund': 0, 'monthly': 14084}], ['control 5', {'disbursements': [7, 250000, 7], 'low_point': 0, 'cushion_months': 2, 'refund_threshold': 5000}, {'base': 20835, 'cushion': 41669, 'shortage': 41669, 'refund': 0, 'monthly': 24308}]], [['regression: credit after refund', {'disbursements': [120000], 'low_point': 150000, 'cushion_months': 5, 'refund_threshold': 20000}, {'base': 10000, 'cushion': 50000, 'shortage': 0, 'refund': 100000, 'monthly': 10000}], ['regression: credit after refund, partial-repair probe', {'disbursements': [99999, 99999, 250000], 'low_point': 80000, 'cushion_months': 2, 'refund_threshold': 20000}, {'base': 37500, 'cushion': 75000, 'shortage': 0, 'refund': 0, 'monthly': 37084}], ['control 1', {'disbursements': [99999], 'low_point': -5000, 'cushion_months': 0, 'refund_threshold': 20000}, {'base': 8333, 'cushion': 0, 'shortage': 5000, 'refund': 0, 'monthly': 8750}], ['control 2', {'disbursements': [120000, 7], 'low_point': 0, 'cushion_months': 2, 'refund_threshold': 20000}, {'base': 10001, 'cushion': 20001, 'shortage': 20001, 'refund': 0, 'monthly': 11668}], ['control 3', {'disbursements': [120000, 7], 'low_point': 40000, 'cushion_months': 5, 'refund_threshold': 20000}, {'base': 10001, 'cushion': 50003, 'shortage': 10003, 'refund': 0, 'monthly': 10835}], ['control 4', {'disbursements': [36000, 7, 36000], 'low_point': 10000, 'cushion_months': 5, 'refund_threshold': 20000}, {'base': 6001, 'cushion': 30003, 'shortage': 20003, 'refund': 0, 'monthly': 7668}], ['control 5', {'disbursements': [250000, 36000], 'low_point': 40000, 'cushion_months': 2, 'refund_threshold': 20000}, {'base': 23833, 'cushion': 47667, 'shortage': 7667, 'refund': 0, 'monthly': 24472}]]]
for label, args, expected in fixtures[N-1]:
try:
actual = solve(args)
except Exception as exc:
actual = 'raised ' + type(exc).__name__
check(label, actual, expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
| Boundary fixture | Actual | Expected | Outcome |
|---|---|---|---|
| regression: credit after refund | {'base': 29167, 'cushion': 29167, 'monthly': 29167, 'refund': 50833, 'shortage': 0} | {'base': 29167, 'cushion': 29167, 'monthly': 29167, 'refund': 50833, 'shortage': 0} | Passed |
| regression: credit after refund, partial-repair probe | {'base': 10001, 'cushion': 20002, 'monthly': 8335, 'refund': 0, 'shortage': 0} | {'base': 10001, 'cushion': 20002, 'monthly': 8335, 'refund': 0, 'shortage': 0} | Passed |
| control 1 | {'base': 21333, 'cushion': 42667, 'monthly': 25306, 'refund': 0, 'shortage': 47667} | {'base': 21333, 'cushion': 42667, 'monthly': 25306, 'refund': 0, 'shortage': 47667} | Passed |
| control 2 | {'base': 10000, 'cushion': 10000, 'monthly': 10834, 'refund': 0, 'shortage': 10000} | {'base': 10000, 'cushion': 10000, 'monthly': 10834, 'refund': 0, 'shortage': 10000} | Passed |
| control 3 | {'base': 13001, 'cushion': 26001, 'monthly': 15585, 'refund': 0, 'shortage': 31001} | {'base': 13001, 'cushion': 26001, 'monthly': 15585, 'refund': 0, 'shortage': 31001} | Passed |
| control 4 | {'base': 29167, 'cushion': 29167, 'monthly': 32015, 'refund': 0, 'shortage': 34167} | {'base': 29167, 'cushion': 29167, 'monthly': 32015, 'refund': 0, 'shortage': 34167} | Passed |
| control 5 | {'base': 44667, 'cushion': 89333, 'monthly': 52529, 'refund': 0, 'shortage': 94333} | {'base': 44667, 'cushion': 89333, 'monthly': 52529, 'refund': 0, 'shortage': 94333} | Passed |
SHA-256 / e01faf1f7e24425d85337d69a49fd5f9818c42d909ed1d345aade83bdc99b7d7
Verification & scope
A deterministic bounded teaching model with stipulated toy lending rules stated in the contract; money is integer cents and rates are basis points; it makes no claim of conformance to any regulation, servicing standard or product. This reproducer isolates one failure mechanism. Results cover the supplied fixtures. Variants within a family share a test contract and should remain grouped when constructing evaluation splits. Related mechanisms with a shared evaluation_group must also remain together; these controlled models are not independent production incidents.
Observations recorded using Python 3.12.14 at 2026-09-29T14:46:29.060879+00:00.
Case digest / 82f839caf0c8d7e6412e02a5da693648ab954edb27109985dad7d453ba22a5a2