FA-58436 / Loan amortization schedules / Open access
Interest-only period with funding stub: interest-only month count · case 01
The interest-only period bills one month too few.
ROOT CAUSE
The loop starts at one, skipping the first interest-only month (and its funding stub).
VERIFIED REPAIR
Bill every interest-only month starting from the first.
Unsuccessful approach: Iterating one extra month bills an interest-only payment that does not exist.
Case contract
x = {'principal', 'rate_bp', 'io_months' >= 1, 'amort_months' >= 1, 'fund_day' 1..30}. IO month m pays interest round_half_up(P*bp*days/(120000*30)) with days = 31 - fund_day for the first IO month and 30 otherwise. Then the level payment on the full principal over amort_months (exact annuity, half-up) amortizes with monthly interest round_half_up(balance*bp/120000); the last month pays balance + interest. Return {'io_bills': list of IO payments, 'payment', 'final_payment', 'total_interest'}.
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
import math
from fractions import Fraction
N = 1
observations = []
def solve(x):
def rnd(n, d):
q, r = divmod(n, d)
return q + (1 if 2 * r >= d else 0)
def level(P, n):
if n <= 0 or P <= 0:
return 0
if bp == 0:
exact = Fraction(P, n)
else:
r = Fraction(bp, 120000)
exact = P * r / (1 - (1 + r) ** -n)
return math.floor(exact + Fraction(1, 2))
bp = x['rate_bp']
P = x['principal']
io_bills = []
total_int = 0
for m in range(1, x['io_months']):
days = 31 - x['fund_day'] if m == 0 else 30
interest = rnd(P * bp * days, 120000 * 30)
io_bills.append(interest)
total_int += interest
pay = level(P, x['amort_months'])
bal = P
final = 0
for k in range(1, x['amort_months'] + 1):
interest = rnd(bal * bp, 120000)
total_int += interest
if k == x['amort_months']:
final = bal + interest
else:
bal -= pay - interest
return {'io_bills': io_bills, 'payment': pay, 'final_payment': final, 'total_interest': total_int}
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: interest-only month count', {'principal': 3000000, 'rate_bp': 500, 'io_months': 3, 'amort_months': 60, 'fund_day': 1}, {'io_bills': [12500, 12500, 12500], 'payment': 56614, 'final_payment': 56596, 'total_interest': 434322}], ['sample 1', {'principal': 12345, 'rate_bp': 725, 'io_months': 12, 'amort_months': 12, 'fund_day': 15}, {'io_bills': [40, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75], 'payment': 1070, 'final_payment': 1065, 'total_interest': 1355}], ['sample 2', {'principal': 250000, 'rate_bp': 725, 'io_months': 3, 'amort_months': 12, 'fund_day': 29}, {'io_bills': [101, 1510, 1510], 'payment': 21661, 'final_payment': 21655, 'total_interest': 13047}], ['sample 3', {'principal': 250000, 'rate_bp': 1200, 'io_months': 3, 'amort_months': 24, 'fund_day': 29}, {'io_bills': [167, 2500, 2500], 'payment': 11768, 'final_payment': 11778, 'total_interest': 37609}], ['sample 4', {'principal': 3000000, 'rate_bp': 1200, 'io_months': 3, 'amort_months': 1, 'fund_day': 2}, {'io_bills': [29000, 30000, 30000], 'payment': 3030000, 'final_payment': 3030000, 'total_interest': 119000}], ['sample 5', {'principal': 12345, 'rate_bp': 0, 'io_months': 1, 'amort_months': 24, 'fund_day': 2}, {'io_bills': [0], 'payment': 514, 'final_payment': 523, 'total_interest': 0}], ['sample 6', {'principal': 12345, 'rate_bp': 500, 'io_months': 3, 'amort_months': 12, 'fund_day': 15}, {'io_bills': [27, 51, 51], 'payment': 1057, 'final_payment': 1054, 'total_interest': 465}]], [['regression: interest-only month count', {'principal': 12345, 'rate_bp': 0, 'io_months': 3, 'amort_months': 12, 'fund_day': 1}, {'io_bills': [0, 0, 0], 'payment': 1029, 'final_payment': 1026, 'total_interest': 0}], ['sample 1', {'principal': 100000, 'rate_bp': 725, 'io_months': 2, 'amort_months': 60, 'fund_day': 1}, {'io_bills': [604, 604], 'payment': 1992, 'final_payment': 1987, 'total_interest': 20723}], ['sample 2', {'principal': 250000, 'rate_bp': 500, 'io_months': 2, 'amort_months': 60, 'fund_day': 30}, {'io_bills': [35, 1042], 'payment': 4718, 'final_payment': 4703, 'total_interest': 34142}], ['sample 3', {'principal': 3000000, 'rate_bp': 0, 'io_months': 12, 'amort_months': 60, 'fund_day': 2}, {'io_bills': [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], 'payment': 50000, 'final_payment': 50000, 'total_interest': 0}], ['sample 4', {'principal': 100000, 'rate_bp': 1200, 'io_months': 3, 'amort_months': 24, 'fund_day': 30}, {'io_bills': [33, 1000, 1000], 'payment': 4707, 'final_payment': 4718, 'total_interest': 15012}], ['sample 5', {'principal': 12345, 'rate_bp': 725, 'io_months': 3, 'amort_months': 60, 'fund_day': 15}, {'io_bills': [40, 75, 75], 'payment': 246, 'final_payment': 239, 'total_interest': 2598}], ['sample 6', {'principal': 3000000, 'rate_bp': 500, 'io_months': 3, 'amort_months': 12, 'fund_day': 1}, {'io_bills': [12500, 12500, 12500], 'payment': 256822, 'final_payment': 256827, 'total_interest': 119369}]], [['regression: interest-only month count', {'principal': 3000000, 'rate_bp': 500, 'io_months': 2, 'amort_months': 24, 'fund_day': 29}, {'io_bills': [833, 12500], 'payment': 131614, 'final_payment': 131618, 'total_interest': 172073}], ['sample 1', {'principal': 3000000, 'rate_bp': 500, 'io_months': 3, 'amort_months': 24, 'fund_day': 1}, {'io_bills': [12500, 12500, 12500], 'payment': 131614, 'final_payment': 131618, 'total_interest': 196240}], ['sample 2', {'principal': 12345, 'rate_bp': 500, 'io_months': 2, 'amort_months': 12, 'fund_day': 15}, {'io_bills': [27, 51], 'payment': 1057, 'final_payment': 1054, 'total_interest': 414}], ['sample 3', {'principal': 100000, 'rate_bp': 0, 'io_months': 12, 'amort_months': 24, 'fund_day': 29}, {'io_bills': [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], 'payment': 4167, 'final_payment': 4159, 'total_interest': 0}], ['sample 4', {'principal': 100000, 'rate_bp': 500, 'io_months': 12, 'amort_months': 24, 'fund_day': 15}, {'io_bills': [222, 417, 417, 417, 417, 417, 417, 417, 417, 417, 417, 417], 'payment': 4387, 'final_payment': 4389, 'total_interest': 10099}], ['sample 5', {'principal': 100000, 'rate_bp': 500, 'io_months': 12, 'amort_months': 12, 'fund_day': 29}, {'io_bills': [28, 417, 417, 417, 417, 417, 417, 417, 417, 417, 417, 417], 'payment': 8561, 'final_payment': 8559, 'total_interest': 7345}], ['sample 6', {'principal': 12345, 'rate_bp': 0, 'io_months': 2, 'amort_months': 24, 'fund_day': 30}, {'io_bills': [0, 0], 'payment': 514, 'final_payment': 523, 'total_interest': 0}]], [['regression: interest-only month count', {'principal': 250000, 'rate_bp': 500, 'io_months': 12, 'amort_months': 60, 'fund_day': 15}, {'io_bills': [556, 1042, 1042, 1042, 1042, 1042, 1042, 1042, 1042, 1042, 1042, 1042], 'payment': 4718, 'final_payment': 4703, 'total_interest': 45083}], ['sample 1', {'principal': 100000, 'rate_bp': 0, 'io_months': 12, 'amort_months': 60, 'fund_day': 29}, {'io_bills': [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], 'payment': 1667, 'final_payment': 1647, 'total_interest': 0}], ['sample 2', {'principal': 250000, 'rate_bp': 0, 'io_months': 3, 'amort_months': 1, 'fund_day': 2}, {'io_bills': [0, 0, 0], 'payment': 250000, 'final_payment': 250000, 'total_interest': 0}], ['sample 3', {'principal': 250000, 'rate_bp': 1200, 'io_months': 12, 'amort_months': 24, 'fund_day': 15}, {'io_bills': [1333, 2500, 2500, 2500, 2500, 2500, 2500, 2500, 2500, 2500, 2500, 2500], 'payment': 11768, 'final_payment': 11778, 'total_interest': 61275}], ['sample 4', {'principal': 100000, 'rate_bp': 725, 'io_months': 12, 'amort_months': 24, 'fund_day': 15}, {'io_bills': [322, 604, 604, 604, 604, 604, 604, 604, 604, 604, 604, 604], 'payment': 4489, 'final_payment': 4477, 'total_interest': 14690}], ['sample 5', {'principal': 12345, 'rate_bp': 1200, 'io_months': 2, 'amort_months': 24, 'fund_day': 30}, {'io_bills': [4, 123], 'payment': 581, 'final_payment': 584, 'total_interest': 1729}], ['sample 6', {'principal': 100000, 'rate_bp': 500, 'io_months': 1, 'amort_months': 12, 'fund_day': 30}, {'io_bills': [14], 'payment': 8561, 'final_payment': 8559, 'total_interest': 2744}]], [['regression: interest-only month count', {'principal': 12345, 'rate_bp': 725, 'io_months': 1, 'amort_months': 12, 'fund_day': 2}, {'io_bills': [72], 'payment': 1070, 'final_payment': 1065, 'total_interest': 562}], ['sample 1', {'principal': 3000000, 'rate_bp': 725, 'io_months': 1, 'amort_months': 60, 'fund_day': 29}, {'io_bills': [1208], 'payment': 59758, 'final_payment': 59764, 'total_interest': 586694}], ['sample 2', {'principal': 100000, 'rate_bp': 500, 'io_months': 3, 'amort_months': 60, 'fund_day': 2}, {'io_bills': [403, 417, 417], 'payment': 1887, 'final_payment': 1894, 'total_interest': 14464}], ['sample 3', {'principal': 250000, 'rate_bp': 725, 'io_months': 1, 'amort_months': 60, 'fund_day': 15}, {'io_bills': [806], 'payment': 4980, 'final_payment': 4967, 'total_interest': 49593}], ['sample 4', {'principal': 100000, 'rate_bp': 0, 'io_months': 12, 'amort_months': 24, 'fund_day': 30}, {'io_bills': [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], 'payment': 4167, 'final_payment': 4159, 'total_interest': 0}], ['sample 5', {'principal': 12345, 'rate_bp': 725, 'io_months': 2, 'amort_months': 24, 'fund_day': 15}, {'io_bills': [40, 75], 'payment': 554, 'final_payment': 559, 'total_interest': 1071}], ['sample 6', {'principal': 3000000, 'rate_bp': 0, 'io_months': 12, 'amort_months': 24, 'fund_day': 15}, {'io_bills': [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], 'payment': 125000, 'final_payment': 125000, 'total_interest': 0}]]]
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: interest-only month count | {'final_payment': 56596, 'io_bills': [12500, 12500], 'payment': 56614, 'total_interest': 421822} | {'final_payment': 56596, 'io_bills': [12500, 12500, 12500], 'payment': 56614, 'total_interest': 434322} | Failed |
| sample 1 | {'final_payment': 1065, 'io_bills': [75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75], 'payment': 1070, 'total_interest': 1315} | {'final_payment': 1065, 'io_bills': [40, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75], 'payment': 1070, 'total_interest': 1355} | Failed |
| sample 2 | {'final_payment': 21655, 'io_bills': [1510, 1510], 'payment': 21661, 'total_interest': 12946} | {'final_payment': 21655, 'io_bills': [101, 1510, 1510], 'payment': 21661, 'total_interest': 13047} | Failed |
| sample 3 | {'final_payment': 11778, 'io_bills': [2500, 2500], 'payment': 11768, 'total_interest': 37442} | {'final_payment': 11778, 'io_bills': [167, 2500, 2500], 'payment': 11768, 'total_interest': 37609} | Failed |
| sample 4 | {'final_payment': 3030000, 'io_bills': [30000, 30000], 'payment': 3030000, 'total_interest': 90000} | {'final_payment': 3030000, 'io_bills': [29000, 30000, 30000], 'payment': 3030000, 'total_interest': 119000} | Failed |
| sample 5 | {'final_payment': 523, 'io_bills': [], 'payment': 514, 'total_interest': 0} | {'final_payment': 523, 'io_bills': [0], 'payment': 514, 'total_interest': 0} | Failed |
| sample 6 | {'final_payment': 1054, 'io_bills': [51, 51], 'payment': 1057, 'total_interest': 438} | {'final_payment': 1054, 'io_bills': [27, 51, 51], 'payment': 1057, 'total_interest': 465} | Failed |
SHA-256 / 87a236b98500d21dcb34bfc477b1473c93f5fd927255dc5521dea48ada844ecc
2 / The unsuccessful fix
Exit 1"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(x):
def rnd(n, d):
q, r = divmod(n, d)
return q + (1 if 2 * r >= d else 0)
def level(P, n):
if n <= 0 or P <= 0:
return 0
if bp == 0:
exact = Fraction(P, n)
else:
r = Fraction(bp, 120000)
exact = P * r / (1 - (1 + r) ** -n)
return math.floor(exact + Fraction(1, 2))
bp = x['rate_bp']
P = x['principal']
io_bills = []
total_int = 0
for m in range(x['io_months'] + 1):
days = 31 - x['fund_day'] if m == 0 else 30
interest = rnd(P * bp * days, 120000 * 30)
io_bills.append(interest)
total_int += interest
pay = level(P, x['amort_months'])
bal = P
final = 0
for k in range(1, x['amort_months'] + 1):
interest = rnd(bal * bp, 120000)
total_int += interest
if k == x['amort_months']:
final = bal + interest
else:
bal -= pay - interest
return {'io_bills': io_bills, 'payment': pay, 'final_payment': final, 'total_interest': total_int}
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: interest-only month count', {'principal': 3000000, 'rate_bp': 500, 'io_months': 3, 'amort_months': 60, 'fund_day': 1}, {'io_bills': [12500, 12500, 12500], 'payment': 56614, 'final_payment': 56596, 'total_interest': 434322}], ['sample 1', {'principal': 12345, 'rate_bp': 725, 'io_months': 12, 'amort_months': 12, 'fund_day': 15}, {'io_bills': [40, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75], 'payment': 1070, 'final_payment': 1065, 'total_interest': 1355}], ['sample 2', {'principal': 250000, 'rate_bp': 725, 'io_months': 3, 'amort_months': 12, 'fund_day': 29}, {'io_bills': [101, 1510, 1510], 'payment': 21661, 'final_payment': 21655, 'total_interest': 13047}], ['sample 3', {'principal': 250000, 'rate_bp': 1200, 'io_months': 3, 'amort_months': 24, 'fund_day': 29}, {'io_bills': [167, 2500, 2500], 'payment': 11768, 'final_payment': 11778, 'total_interest': 37609}], ['sample 4', {'principal': 3000000, 'rate_bp': 1200, 'io_months': 3, 'amort_months': 1, 'fund_day': 2}, {'io_bills': [29000, 30000, 30000], 'payment': 3030000, 'final_payment': 3030000, 'total_interest': 119000}], ['sample 5', {'principal': 12345, 'rate_bp': 0, 'io_months': 1, 'amort_months': 24, 'fund_day': 2}, {'io_bills': [0], 'payment': 514, 'final_payment': 523, 'total_interest': 0}], ['sample 6', {'principal': 12345, 'rate_bp': 500, 'io_months': 3, 'amort_months': 12, 'fund_day': 15}, {'io_bills': [27, 51, 51], 'payment': 1057, 'final_payment': 1054, 'total_interest': 465}]], [['regression: interest-only month count', {'principal': 12345, 'rate_bp': 0, 'io_months': 3, 'amort_months': 12, 'fund_day': 1}, {'io_bills': [0, 0, 0], 'payment': 1029, 'final_payment': 1026, 'total_interest': 0}], ['sample 1', {'principal': 100000, 'rate_bp': 725, 'io_months': 2, 'amort_months': 60, 'fund_day': 1}, {'io_bills': [604, 604], 'payment': 1992, 'final_payment': 1987, 'total_interest': 20723}], ['sample 2', {'principal': 250000, 'rate_bp': 500, 'io_months': 2, 'amort_months': 60, 'fund_day': 30}, {'io_bills': [35, 1042], 'payment': 4718, 'final_payment': 4703, 'total_interest': 34142}], ['sample 3', {'principal': 3000000, 'rate_bp': 0, 'io_months': 12, 'amort_months': 60, 'fund_day': 2}, {'io_bills': [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], 'payment': 50000, 'final_payment': 50000, 'total_interest': 0}], ['sample 4', {'principal': 100000, 'rate_bp': 1200, 'io_months': 3, 'amort_months': 24, 'fund_day': 30}, {'io_bills': [33, 1000, 1000], 'payment': 4707, 'final_payment': 4718, 'total_interest': 15012}], ['sample 5', {'principal': 12345, 'rate_bp': 725, 'io_months': 3, 'amort_months': 60, 'fund_day': 15}, {'io_bills': [40, 75, 75], 'payment': 246, 'final_payment': 239, 'total_interest': 2598}], ['sample 6', {'principal': 3000000, 'rate_bp': 500, 'io_months': 3, 'amort_months': 12, 'fund_day': 1}, {'io_bills': [12500, 12500, 12500], 'payment': 256822, 'final_payment': 256827, 'total_interest': 119369}]], [['regression: interest-only month count', {'principal': 3000000, 'rate_bp': 500, 'io_months': 2, 'amort_months': 24, 'fund_day': 29}, {'io_bills': [833, 12500], 'payment': 131614, 'final_payment': 131618, 'total_interest': 172073}], ['sample 1', {'principal': 3000000, 'rate_bp': 500, 'io_months': 3, 'amort_months': 24, 'fund_day': 1}, {'io_bills': [12500, 12500, 12500], 'payment': 131614, 'final_payment': 131618, 'total_interest': 196240}], ['sample 2', {'principal': 12345, 'rate_bp': 500, 'io_months': 2, 'amort_months': 12, 'fund_day': 15}, {'io_bills': [27, 51], 'payment': 1057, 'final_payment': 1054, 'total_interest': 414}], ['sample 3', {'principal': 100000, 'rate_bp': 0, 'io_months': 12, 'amort_months': 24, 'fund_day': 29}, {'io_bills': [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], 'payment': 4167, 'final_payment': 4159, 'total_interest': 0}], ['sample 4', {'principal': 100000, 'rate_bp': 500, 'io_months': 12, 'amort_months': 24, 'fund_day': 15}, {'io_bills': [222, 417, 417, 417, 417, 417, 417, 417, 417, 417, 417, 417], 'payment': 4387, 'final_payment': 4389, 'total_interest': 10099}], ['sample 5', {'principal': 100000, 'rate_bp': 500, 'io_months': 12, 'amort_months': 12, 'fund_day': 29}, {'io_bills': [28, 417, 417, 417, 417, 417, 417, 417, 417, 417, 417, 417], 'payment': 8561, 'final_payment': 8559, 'total_interest': 7345}], ['sample 6', {'principal': 12345, 'rate_bp': 0, 'io_months': 2, 'amort_months': 24, 'fund_day': 30}, {'io_bills': [0, 0], 'payment': 514, 'final_payment': 523, 'total_interest': 0}]], [['regression: interest-only month count', {'principal': 250000, 'rate_bp': 500, 'io_months': 12, 'amort_months': 60, 'fund_day': 15}, {'io_bills': [556, 1042, 1042, 1042, 1042, 1042, 1042, 1042, 1042, 1042, 1042, 1042], 'payment': 4718, 'final_payment': 4703, 'total_interest': 45083}], ['sample 1', {'principal': 100000, 'rate_bp': 0, 'io_months': 12, 'amort_months': 60, 'fund_day': 29}, {'io_bills': [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], 'payment': 1667, 'final_payment': 1647, 'total_interest': 0}], ['sample 2', {'principal': 250000, 'rate_bp': 0, 'io_months': 3, 'amort_months': 1, 'fund_day': 2}, {'io_bills': [0, 0, 0], 'payment': 250000, 'final_payment': 250000, 'total_interest': 0}], ['sample 3', {'principal': 250000, 'rate_bp': 1200, 'io_months': 12, 'amort_months': 24, 'fund_day': 15}, {'io_bills': [1333, 2500, 2500, 2500, 2500, 2500, 2500, 2500, 2500, 2500, 2500, 2500], 'payment': 11768, 'final_payment': 11778, 'total_interest': 61275}], ['sample 4', {'principal': 100000, 'rate_bp': 725, 'io_months': 12, 'amort_months': 24, 'fund_day': 15}, {'io_bills': [322, 604, 604, 604, 604, 604, 604, 604, 604, 604, 604, 604], 'payment': 4489, 'final_payment': 4477, 'total_interest': 14690}], ['sample 5', {'principal': 12345, 'rate_bp': 1200, 'io_months': 2, 'amort_months': 24, 'fund_day': 30}, {'io_bills': [4, 123], 'payment': 581, 'final_payment': 584, 'total_interest': 1729}], ['sample 6', {'principal': 100000, 'rate_bp': 500, 'io_months': 1, 'amort_months': 12, 'fund_day': 30}, {'io_bills': [14], 'payment': 8561, 'final_payment': 8559, 'total_interest': 2744}]], [['regression: interest-only month count', {'principal': 12345, 'rate_bp': 725, 'io_months': 1, 'amort_months': 12, 'fund_day': 2}, {'io_bills': [72], 'payment': 1070, 'final_payment': 1065, 'total_interest': 562}], ['sample 1', {'principal': 3000000, 'rate_bp': 725, 'io_months': 1, 'amort_months': 60, 'fund_day': 29}, {'io_bills': [1208], 'payment': 59758, 'final_payment': 59764, 'total_interest': 586694}], ['sample 2', {'principal': 100000, 'rate_bp': 500, 'io_months': 3, 'amort_months': 60, 'fund_day': 2}, {'io_bills': [403, 417, 417], 'payment': 1887, 'final_payment': 1894, 'total_interest': 14464}], ['sample 3', {'principal': 250000, 'rate_bp': 725, 'io_months': 1, 'amort_months': 60, 'fund_day': 15}, {'io_bills': [806], 'payment': 4980, 'final_payment': 4967, 'total_interest': 49593}], ['sample 4', {'principal': 100000, 'rate_bp': 0, 'io_months': 12, 'amort_months': 24, 'fund_day': 30}, {'io_bills': [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], 'payment': 4167, 'final_payment': 4159, 'total_interest': 0}], ['sample 5', {'principal': 12345, 'rate_bp': 725, 'io_months': 2, 'amort_months': 24, 'fund_day': 15}, {'io_bills': [40, 75], 'payment': 554, 'final_payment': 559, 'total_interest': 1071}], ['sample 6', {'principal': 3000000, 'rate_bp': 0, 'io_months': 12, 'amort_months': 24, 'fund_day': 15}, {'io_bills': [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], 'payment': 125000, 'final_payment': 125000, 'total_interest': 0}]]]
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: interest-only month count | {'final_payment': 56596, 'io_bills': [12500, 12500, 12500, 12500], 'payment': 56614, 'total_interest': 446822} | {'final_payment': 56596, 'io_bills': [12500, 12500, 12500], 'payment': 56614, 'total_interest': 434322} | Failed |
| sample 1 | {'final_payment': 1065, 'io_bills': [40, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75], 'payment': 1070, 'total_interest': 1430} | {'final_payment': 1065, 'io_bills': [40, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75], 'payment': 1070, 'total_interest': 1355} | Failed |
| sample 2 | {'final_payment': 21655, 'io_bills': [101, 1510, 1510, 1510], 'payment': 21661, 'total_interest': 14557} | {'final_payment': 21655, 'io_bills': [101, 1510, 1510], 'payment': 21661, 'total_interest': 13047} | Failed |
| sample 3 | {'final_payment': 11778, 'io_bills': [167, 2500, 2500, 2500], 'payment': 11768, 'total_interest': 40109} | {'final_payment': 11778, 'io_bills': [167, 2500, 2500], 'payment': 11768, 'total_interest': 37609} | Failed |
| sample 4 | {'final_payment': 3030000, 'io_bills': [29000, 30000, 30000, 30000], 'payment': 3030000, 'total_interest': 149000} | {'final_payment': 3030000, 'io_bills': [29000, 30000, 30000], 'payment': 3030000, 'total_interest': 119000} | Failed |
| sample 5 | {'final_payment': 523, 'io_bills': [0, 0], 'payment': 514, 'total_interest': 0} | {'final_payment': 523, 'io_bills': [0], 'payment': 514, 'total_interest': 0} | Failed |
| sample 6 | {'final_payment': 1054, 'io_bills': [27, 51, 51, 51], 'payment': 1057, 'total_interest': 516} | {'final_payment': 1054, 'io_bills': [27, 51, 51], 'payment': 1057, 'total_interest': 465} | Failed |
SHA-256 / 8893e3b0a90f3353eb45b53c4b2f89fd7865633fcb974291bddf627cd86b7b06
3 / The verified repair
Exit 0"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(x):
def rnd(n, d):
q, r = divmod(n, d)
return q + (1 if 2 * r >= d else 0)
def level(P, n):
if n <= 0 or P <= 0:
return 0
if bp == 0:
exact = Fraction(P, n)
else:
r = Fraction(bp, 120000)
exact = P * r / (1 - (1 + r) ** -n)
return math.floor(exact + Fraction(1, 2))
bp = x['rate_bp']
P = x['principal']
io_bills = []
total_int = 0
for m in range(x['io_months']):
days = 31 - x['fund_day'] if m == 0 else 30
interest = rnd(P * bp * days, 120000 * 30)
io_bills.append(interest)
total_int += interest
pay = level(P, x['amort_months'])
bal = P
final = 0
for k in range(1, x['amort_months'] + 1):
interest = rnd(bal * bp, 120000)
total_int += interest
if k == x['amort_months']:
final = bal + interest
else:
bal -= pay - interest
return {'io_bills': io_bills, 'payment': pay, 'final_payment': final, 'total_interest': total_int}
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: interest-only month count', {'principal': 3000000, 'rate_bp': 500, 'io_months': 3, 'amort_months': 60, 'fund_day': 1}, {'io_bills': [12500, 12500, 12500], 'payment': 56614, 'final_payment': 56596, 'total_interest': 434322}], ['sample 1', {'principal': 12345, 'rate_bp': 725, 'io_months': 12, 'amort_months': 12, 'fund_day': 15}, {'io_bills': [40, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75], 'payment': 1070, 'final_payment': 1065, 'total_interest': 1355}], ['sample 2', {'principal': 250000, 'rate_bp': 725, 'io_months': 3, 'amort_months': 12, 'fund_day': 29}, {'io_bills': [101, 1510, 1510], 'payment': 21661, 'final_payment': 21655, 'total_interest': 13047}], ['sample 3', {'principal': 250000, 'rate_bp': 1200, 'io_months': 3, 'amort_months': 24, 'fund_day': 29}, {'io_bills': [167, 2500, 2500], 'payment': 11768, 'final_payment': 11778, 'total_interest': 37609}], ['sample 4', {'principal': 3000000, 'rate_bp': 1200, 'io_months': 3, 'amort_months': 1, 'fund_day': 2}, {'io_bills': [29000, 30000, 30000], 'payment': 3030000, 'final_payment': 3030000, 'total_interest': 119000}], ['sample 5', {'principal': 12345, 'rate_bp': 0, 'io_months': 1, 'amort_months': 24, 'fund_day': 2}, {'io_bills': [0], 'payment': 514, 'final_payment': 523, 'total_interest': 0}], ['sample 6', {'principal': 12345, 'rate_bp': 500, 'io_months': 3, 'amort_months': 12, 'fund_day': 15}, {'io_bills': [27, 51, 51], 'payment': 1057, 'final_payment': 1054, 'total_interest': 465}]], [['regression: interest-only month count', {'principal': 12345, 'rate_bp': 0, 'io_months': 3, 'amort_months': 12, 'fund_day': 1}, {'io_bills': [0, 0, 0], 'payment': 1029, 'final_payment': 1026, 'total_interest': 0}], ['sample 1', {'principal': 100000, 'rate_bp': 725, 'io_months': 2, 'amort_months': 60, 'fund_day': 1}, {'io_bills': [604, 604], 'payment': 1992, 'final_payment': 1987, 'total_interest': 20723}], ['sample 2', {'principal': 250000, 'rate_bp': 500, 'io_months': 2, 'amort_months': 60, 'fund_day': 30}, {'io_bills': [35, 1042], 'payment': 4718, 'final_payment': 4703, 'total_interest': 34142}], ['sample 3', {'principal': 3000000, 'rate_bp': 0, 'io_months': 12, 'amort_months': 60, 'fund_day': 2}, {'io_bills': [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], 'payment': 50000, 'final_payment': 50000, 'total_interest': 0}], ['sample 4', {'principal': 100000, 'rate_bp': 1200, 'io_months': 3, 'amort_months': 24, 'fund_day': 30}, {'io_bills': [33, 1000, 1000], 'payment': 4707, 'final_payment': 4718, 'total_interest': 15012}], ['sample 5', {'principal': 12345, 'rate_bp': 725, 'io_months': 3, 'amort_months': 60, 'fund_day': 15}, {'io_bills': [40, 75, 75], 'payment': 246, 'final_payment': 239, 'total_interest': 2598}], ['sample 6', {'principal': 3000000, 'rate_bp': 500, 'io_months': 3, 'amort_months': 12, 'fund_day': 1}, {'io_bills': [12500, 12500, 12500], 'payment': 256822, 'final_payment': 256827, 'total_interest': 119369}]], [['regression: interest-only month count', {'principal': 3000000, 'rate_bp': 500, 'io_months': 2, 'amort_months': 24, 'fund_day': 29}, {'io_bills': [833, 12500], 'payment': 131614, 'final_payment': 131618, 'total_interest': 172073}], ['sample 1', {'principal': 3000000, 'rate_bp': 500, 'io_months': 3, 'amort_months': 24, 'fund_day': 1}, {'io_bills': [12500, 12500, 12500], 'payment': 131614, 'final_payment': 131618, 'total_interest': 196240}], ['sample 2', {'principal': 12345, 'rate_bp': 500, 'io_months': 2, 'amort_months': 12, 'fund_day': 15}, {'io_bills': [27, 51], 'payment': 1057, 'final_payment': 1054, 'total_interest': 414}], ['sample 3', {'principal': 100000, 'rate_bp': 0, 'io_months': 12, 'amort_months': 24, 'fund_day': 29}, {'io_bills': [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], 'payment': 4167, 'final_payment': 4159, 'total_interest': 0}], ['sample 4', {'principal': 100000, 'rate_bp': 500, 'io_months': 12, 'amort_months': 24, 'fund_day': 15}, {'io_bills': [222, 417, 417, 417, 417, 417, 417, 417, 417, 417, 417, 417], 'payment': 4387, 'final_payment': 4389, 'total_interest': 10099}], ['sample 5', {'principal': 100000, 'rate_bp': 500, 'io_months': 12, 'amort_months': 12, 'fund_day': 29}, {'io_bills': [28, 417, 417, 417, 417, 417, 417, 417, 417, 417, 417, 417], 'payment': 8561, 'final_payment': 8559, 'total_interest': 7345}], ['sample 6', {'principal': 12345, 'rate_bp': 0, 'io_months': 2, 'amort_months': 24, 'fund_day': 30}, {'io_bills': [0, 0], 'payment': 514, 'final_payment': 523, 'total_interest': 0}]], [['regression: interest-only month count', {'principal': 250000, 'rate_bp': 500, 'io_months': 12, 'amort_months': 60, 'fund_day': 15}, {'io_bills': [556, 1042, 1042, 1042, 1042, 1042, 1042, 1042, 1042, 1042, 1042, 1042], 'payment': 4718, 'final_payment': 4703, 'total_interest': 45083}], ['sample 1', {'principal': 100000, 'rate_bp': 0, 'io_months': 12, 'amort_months': 60, 'fund_day': 29}, {'io_bills': [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], 'payment': 1667, 'final_payment': 1647, 'total_interest': 0}], ['sample 2', {'principal': 250000, 'rate_bp': 0, 'io_months': 3, 'amort_months': 1, 'fund_day': 2}, {'io_bills': [0, 0, 0], 'payment': 250000, 'final_payment': 250000, 'total_interest': 0}], ['sample 3', {'principal': 250000, 'rate_bp': 1200, 'io_months': 12, 'amort_months': 24, 'fund_day': 15}, {'io_bills': [1333, 2500, 2500, 2500, 2500, 2500, 2500, 2500, 2500, 2500, 2500, 2500], 'payment': 11768, 'final_payment': 11778, 'total_interest': 61275}], ['sample 4', {'principal': 100000, 'rate_bp': 725, 'io_months': 12, 'amort_months': 24, 'fund_day': 15}, {'io_bills': [322, 604, 604, 604, 604, 604, 604, 604, 604, 604, 604, 604], 'payment': 4489, 'final_payment': 4477, 'total_interest': 14690}], ['sample 5', {'principal': 12345, 'rate_bp': 1200, 'io_months': 2, 'amort_months': 24, 'fund_day': 30}, {'io_bills': [4, 123], 'payment': 581, 'final_payment': 584, 'total_interest': 1729}], ['sample 6', {'principal': 100000, 'rate_bp': 500, 'io_months': 1, 'amort_months': 12, 'fund_day': 30}, {'io_bills': [14], 'payment': 8561, 'final_payment': 8559, 'total_interest': 2744}]], [['regression: interest-only month count', {'principal': 12345, 'rate_bp': 725, 'io_months': 1, 'amort_months': 12, 'fund_day': 2}, {'io_bills': [72], 'payment': 1070, 'final_payment': 1065, 'total_interest': 562}], ['sample 1', {'principal': 3000000, 'rate_bp': 725, 'io_months': 1, 'amort_months': 60, 'fund_day': 29}, {'io_bills': [1208], 'payment': 59758, 'final_payment': 59764, 'total_interest': 586694}], ['sample 2', {'principal': 100000, 'rate_bp': 500, 'io_months': 3, 'amort_months': 60, 'fund_day': 2}, {'io_bills': [403, 417, 417], 'payment': 1887, 'final_payment': 1894, 'total_interest': 14464}], ['sample 3', {'principal': 250000, 'rate_bp': 725, 'io_months': 1, 'amort_months': 60, 'fund_day': 15}, {'io_bills': [806], 'payment': 4980, 'final_payment': 4967, 'total_interest': 49593}], ['sample 4', {'principal': 100000, 'rate_bp': 0, 'io_months': 12, 'amort_months': 24, 'fund_day': 30}, {'io_bills': [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], 'payment': 4167, 'final_payment': 4159, 'total_interest': 0}], ['sample 5', {'principal': 12345, 'rate_bp': 725, 'io_months': 2, 'amort_months': 24, 'fund_day': 15}, {'io_bills': [40, 75], 'payment': 554, 'final_payment': 559, 'total_interest': 1071}], ['sample 6', {'principal': 3000000, 'rate_bp': 0, 'io_months': 12, 'amort_months': 24, 'fund_day': 15}, {'io_bills': [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], 'payment': 125000, 'final_payment': 125000, 'total_interest': 0}]]]
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: interest-only month count | {'final_payment': 56596, 'io_bills': [12500, 12500, 12500], 'payment': 56614, 'total_interest': 434322} | {'final_payment': 56596, 'io_bills': [12500, 12500, 12500], 'payment': 56614, 'total_interest': 434322} | Passed |
| sample 1 | {'final_payment': 1065, 'io_bills': [40, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75], 'payment': 1070, 'total_interest': 1355} | {'final_payment': 1065, 'io_bills': [40, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75], 'payment': 1070, 'total_interest': 1355} | Passed |
| sample 2 | {'final_payment': 21655, 'io_bills': [101, 1510, 1510], 'payment': 21661, 'total_interest': 13047} | {'final_payment': 21655, 'io_bills': [101, 1510, 1510], 'payment': 21661, 'total_interest': 13047} | Passed |
| sample 3 | {'final_payment': 11778, 'io_bills': [167, 2500, 2500], 'payment': 11768, 'total_interest': 37609} | {'final_payment': 11778, 'io_bills': [167, 2500, 2500], 'payment': 11768, 'total_interest': 37609} | Passed |
| sample 4 | {'final_payment': 3030000, 'io_bills': [29000, 30000, 30000], 'payment': 3030000, 'total_interest': 119000} | {'final_payment': 3030000, 'io_bills': [29000, 30000, 30000], 'payment': 3030000, 'total_interest': 119000} | Passed |
| sample 5 | {'final_payment': 523, 'io_bills': [0], 'payment': 514, 'total_interest': 0} | {'final_payment': 523, 'io_bills': [0], 'payment': 514, 'total_interest': 0} | Passed |
| sample 6 | {'final_payment': 1054, 'io_bills': [27, 51, 51], 'payment': 1057, 'total_interest': 465} | {'final_payment': 1054, 'io_bills': [27, 51, 51], 'payment': 1057, 'total_interest': 465} | Passed |
SHA-256 / bd44aa72fd6da15bdb96051d75a8cf09889bce0bb21224e40b1eff111b664dd4
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:26.714454+00:00.
Case digest / 32e136ff2f858754c7411ae3f880223e51f9e5a395bcc3f11c452834594b1228