FA-58391 / Loan amortization schedules / Open access
Schedule rows from a fixed payment: interest base · case 01
Interest stays flat every month even as principal is repaid.
ROOT CAUSE
Interest is charged on the original principal.
VERIFIED REPAIR
Charge interest on the current balance.
Unsuccessful approach: Charging on the balance after the payment treats interest as paid in advance.
Case contract
x = {'principal', 'rate_bp', 'payment', 'max_months'}. For months 1..max_months while the balance is positive: interest = round_half_up(balance*bp/120000); if payment <= interest return {'error': 'negative_amortization', 'month': k}; principal paid = min(payment - interest, balance); append [k, interest, principal, balance after]. Return {'rows', 'balloon': remaining principal}.
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)
bal = x['principal']
rows = []
for k in range(1, x['max_months'] + 1):
if bal == 0:
break
interest = rnd(x['principal'] * x['rate_bp'], 120000)
pay = x['payment']
if pay <= interest:
return {'error': 'negative_amortization', 'month': k}
princ = min(pay - interest, bal)
bal -= princ
rows.append([k, interest, princ, bal])
return {'rows': rows, 'balloon': bal}
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: interest base', {'principal': 250000, 'rate_bp': 1999, 'payment': 5000, 'max_months': 24}, {'rows': [[1, 4165, 835, 249165], [2, 4151, 849, 248316], [3, 4137, 863, 247453], [4, 4122, 878, 246575], [5, 4108, 892, 245683], [6, 4093, 907, 244776], [7, 4078, 922, 243854], [8, 4062, 938, 242916], [9, 4047, 953, 241963], [10, 4031, 969, 240994], [11, 4015, 985, 240009], [12, 3998, 1002, 239007], [13, 3981, 1019, 237988], [14, 3964, 1036, 236952], [15, 3947, 1053, 235899], [16, 3930, 1070, 234829], [17, 3912, 1088, 233741], [18, 3894, 1106, 232635], [19, 3875, 1125, 231510], [20, 3857, 1143, 230367], [21, 3838, 1162, 229205], [22, 3818, 1182, 228023], [23, 3798, 1202, 226821], [24, 3778, 1222, 225599]], 'balloon': 225599}], ['control 1', {'principal': 250000, 'rate_bp': 0, 'payment': 500, 'max_months': 1}, {'rows': [[1, 0, 500, 249500]], 'balloon': 249500}], ['control 2', {'principal': 250000, 'rate_bp': 1999, 'payment': 500, 'max_months': 24}, {'error': 'negative_amortization', 'month': 1}], ['control 3', {'principal': 100000, 'rate_bp': 1999, 'payment': 1000, 'max_months': 0}, {'rows': [], 'balloon': 100000}], ['control 4', {'principal': 250000, 'rate_bp': 1200, 'payment': 500, 'max_months': 12}, {'error': 'negative_amortization', 'month': 1}], ['control 5', {'principal': 250000, 'rate_bp': 1999, 'payment': 1200, 'max_months': 6}, {'error': 'negative_amortization', 'month': 1}], ['control 6', {'principal': 50000, 'rate_bp': 1200, 'payment': 500, 'max_months': 1}, {'error': 'negative_amortization', 'month': 1}]], [['regression: interest base', {'principal': 12345, 'rate_bp': 600, 'payment': 500, 'max_months': 24}, {'rows': [[1, 62, 438, 11907], [2, 60, 440, 11467], [3, 57, 443, 11024], [4, 55, 445, 10579], [5, 53, 447, 10132], [6, 51, 449, 9683], [7, 48, 452, 9231], [8, 46, 454, 8777], [9, 44, 456, 8321], [10, 42, 458, 7863], [11, 39, 461, 7402], [12, 37, 463, 6939], [13, 35, 465, 6474], [14, 32, 468, 6006], [15, 30, 470, 5536], [16, 28, 472, 5064], [17, 25, 475, 4589], [18, 23, 477, 4112], [19, 21, 479, 3633], [20, 18, 482, 3151], [21, 16, 484, 2667], [22, 13, 487, 2180], [23, 11, 489, 1691], [24, 8, 492, 1199]], 'balloon': 1199}], ['control 1', {'principal': 100000, 'rate_bp': 600, 'payment': 20007, 'max_months': 1}, {'rows': [[1, 500, 19507, 80493]], 'balloon': 80493}], ['control 2', {'principal': 100000, 'rate_bp': 0, 'payment': 20007, 'max_months': 3}, {'rows': [[1, 0, 20007, 79993], [2, 0, 20007, 59986], [3, 0, 20007, 39979]], 'balloon': 39979}], ['control 3', {'principal': 1000, 'rate_bp': 0, 'payment': 1000, 'max_months': 0}, {'rows': [], 'balloon': 1000}], ['control 4', {'principal': 50000, 'rate_bp': 0, 'payment': 1000, 'max_months': 3}, {'rows': [[1, 0, 1000, 49000], [2, 0, 1000, 48000], [3, 0, 1000, 47000]], 'balloon': 47000}], ['control 5', {'principal': 250000, 'rate_bp': 2400, 'payment': 500, 'max_months': 12}, {'error': 'negative_amortization', 'month': 1}], ['control 6', {'principal': 50000, 'rate_bp': 0, 'payment': 16666, 'max_months': 24}, {'rows': [[1, 0, 16666, 33334], [2, 0, 16666, 16668], [3, 0, 16666, 2], [4, 0, 2, 0]], 'balloon': 0}]], [['regression: interest base', {'principal': 50000, 'rate_bp': 2400, 'payment': 5000, 'max_months': 3}, {'rows': [[1, 1000, 4000, 46000], [2, 920, 4080, 41920], [3, 838, 4162, 37758]], 'balloon': 37758}], ['control 1', {'principal': 12345, 'rate_bp': 0, 'payment': 4115, 'max_months': 24}, {'rows': [[1, 0, 4115, 8230], [2, 0, 4115, 4115], [3, 0, 4115, 0]], 'balloon': 0}], ['control 2', {'principal': 12345, 'rate_bp': 0, 'payment': 4115, 'max_months': 1}, {'rows': [[1, 0, 4115, 8230]], 'balloon': 8230}], ['control 3', {'principal': 250000, 'rate_bp': 600, 'payment': 20833, 'max_months': 1}, {'rows': [[1, 1250, 19583, 230417]], 'balloon': 230417}], ['control 4', {'principal': 1000, 'rate_bp': 2400, 'payment': 1050, 'max_months': 0}, {'rows': [], 'balloon': 1000}], ['control 5', {'principal': 250000, 'rate_bp': 1999, 'payment': 83333, 'max_months': 0}, {'rows': [], 'balloon': 250000}], ['control 6', {'principal': 250000, 'rate_bp': 600, 'payment': 1000, 'max_months': 3}, {'error': 'negative_amortization', 'month': 1}]], [['regression: interest base', {'principal': 12345, 'rate_bp': 1200, 'payment': 5000, 'max_months': 3}, {'rows': [[1, 123, 4877, 7468], [2, 75, 4925, 2543], [3, 25, 2543, 0]], 'balloon': 0}], ['control 1', {'principal': 12345, 'rate_bp': 0, 'payment': 5000, 'max_months': 6}, {'rows': [[1, 0, 5000, 7345], [2, 0, 5000, 2345], [3, 0, 2345, 0]], 'balloon': 0}], ['control 2', {'principal': 100000, 'rate_bp': 0, 'payment': 8333, 'max_months': 24}, {'rows': [[1, 0, 8333, 91667], [2, 0, 8333, 83334], [3, 0, 8333, 75001], [4, 0, 8333, 66668], [5, 0, 8333, 58335], [6, 0, 8333, 50002], [7, 0, 8333, 41669], [8, 0, 8333, 33336], [9, 0, 8333, 25003], [10, 0, 8333, 16670], [11, 0, 8333, 8337], [12, 0, 8333, 4], [13, 0, 4, 0]], 'balloon': 0}], ['control 3', {'principal': 1000, 'rate_bp': 1999, 'payment': 5000, 'max_months': 24}, {'rows': [[1, 17, 1000, 0]], 'balloon': 0}], ['control 4', {'principal': 250000, 'rate_bp': 600, 'payment': 500, 'max_months': 0}, {'rows': [], 'balloon': 250000}], ['control 5', {'principal': 50000, 'rate_bp': 1200, 'payment': 5000, 'max_months': 1}, {'rows': [[1, 500, 4500, 45500]], 'balloon': 45500}], ['control 6', {'principal': 250000, 'rate_bp': 1200, 'payment': 500, 'max_months': 6}, {'error': 'negative_amortization', 'month': 1}]], [['regression: interest base', {'principal': 1000, 'rate_bp': 2400, 'payment': 500, 'max_months': 3}, {'rows': [[1, 20, 480, 520], [2, 10, 490, 30], [3, 1, 30, 0]], 'balloon': 0}], ['control 1', {'principal': 50000, 'rate_bp': 0, 'payment': 10007, 'max_months': 24}, {'rows': [[1, 0, 10007, 39993], [2, 0, 10007, 29986], [3, 0, 10007, 19979], [4, 0, 10007, 9972], [5, 0, 9972, 0]], 'balloon': 0}], ['control 2', {'principal': 12345, 'rate_bp': 2400, 'payment': 2476, 'max_months': 0}, {'rows': [], 'balloon': 12345}], ['control 3', {'principal': 250000, 'rate_bp': 2400, 'payment': 20833, 'max_months': 0}, {'rows': [], 'balloon': 250000}], ['control 4', {'principal': 50000, 'rate_bp': 600, 'payment': 1000, 'max_months': 0}, {'rows': [], 'balloon': 50000}], ['control 5', {'principal': 100000, 'rate_bp': 1200, 'payment': 1200, 'max_months': 1}, {'rows': [[1, 1000, 200, 99800]], 'balloon': 99800}], ['control 6', {'principal': 50000, 'rate_bp': 2400, 'payment': 4166, 'max_months': 0}, {'rows': [], 'balloon': 50000}]]]
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 base | {'balloon': 229960, 'rows': [[1, 4165, 835, 249165], [2, 4165, 835, 248330], [3, 4165, 835, 247495], [4, 4165, 835, 246660], [5, 4165, 835, 245825], [6, 4165, 835, 244990], [7, 4165, 835, 244155], [8, 4165, 835, 243320], [9, 4165, 835, 242485], [10, 4165, 835, 241650], [11, 4165, 835, 240815], [12, 4165, 835, 239980], [13, 4165, 835, 239145], [14, 4165, 835, 238310], [15, 4165, 835, 237475], [16, 4165, 835, 236640], [17, 4165, 835, 235805], [18, 4165, 835, 234970], [19, 4165, 835, 234135], [20, 4165, 835, 233300], [21, 4165, 835, 232465], [22, 4165, 835, 231630], [23, 4165, 835, 230795], [24, 4165, 835, 229960]]} | {'balloon': 225599, 'rows': [[1, 4165, 835, 249165], [2, 4151, 849, 248316], [3, 4137, 863, 247453], [4, 4122, 878, 246575], [5, 4108, 892, 245683], [6, 4093, 907, 244776], [7, 4078, 922, 243854], [8, 4062, 938, 242916], [9, 4047, 953, 241963], [10, 4031, 969, 240994], [11, 4015, 985, 240009], [12, 3998, 1002, 239007], [13, 3981, 1019, 237988], [14, 3964, 1036, 236952], [15, 3947, 1053, 235899], [16, 3930, 1070, 234829], [17, 3912, 1088, 233741], [18, 3894, 1106, 232635], [19, 3875, 1125, 231510], [20, 3857, 1143, 230367], [21, 3838, 1162, 229205], [22, 3818, 1182, 228023], [23, 3798, 1202, 226821], [24, 3778, 1222, 225599]]} | Failed |
| control 1 | {'balloon': 249500, 'rows': [[1, 0, 500, 249500]]} | {'balloon': 249500, 'rows': [[1, 0, 500, 249500]]} | Passed |
| control 2 | {'error': 'negative_amortization', 'month': 1} | {'error': 'negative_amortization', 'month': 1} | Passed |
| control 3 | {'balloon': 100000, 'rows': []} | {'balloon': 100000, 'rows': []} | Passed |
| control 4 | {'error': 'negative_amortization', 'month': 1} | {'error': 'negative_amortization', 'month': 1} | Passed |
| control 5 | {'error': 'negative_amortization', 'month': 1} | {'error': 'negative_amortization', 'month': 1} | Passed |
| control 6 | {'error': 'negative_amortization', 'month': 1} | {'error': 'negative_amortization', 'month': 1} | Passed |
SHA-256 / 07655838710d8d343ab863ca2c07eee3363f9b649ad3658d83f3b8990a519fad
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)
bal = x['principal']
rows = []
for k in range(1, x['max_months'] + 1):
if bal == 0:
break
interest = rnd(max(bal - x['payment'], 0) * x['rate_bp'], 120000)
pay = x['payment']
if pay <= interest:
return {'error': 'negative_amortization', 'month': k}
princ = min(pay - interest, bal)
bal -= princ
rows.append([k, interest, princ, bal])
return {'rows': rows, 'balloon': bal}
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: interest base', {'principal': 250000, 'rate_bp': 1999, 'payment': 5000, 'max_months': 24}, {'rows': [[1, 4165, 835, 249165], [2, 4151, 849, 248316], [3, 4137, 863, 247453], [4, 4122, 878, 246575], [5, 4108, 892, 245683], [6, 4093, 907, 244776], [7, 4078, 922, 243854], [8, 4062, 938, 242916], [9, 4047, 953, 241963], [10, 4031, 969, 240994], [11, 4015, 985, 240009], [12, 3998, 1002, 239007], [13, 3981, 1019, 237988], [14, 3964, 1036, 236952], [15, 3947, 1053, 235899], [16, 3930, 1070, 234829], [17, 3912, 1088, 233741], [18, 3894, 1106, 232635], [19, 3875, 1125, 231510], [20, 3857, 1143, 230367], [21, 3838, 1162, 229205], [22, 3818, 1182, 228023], [23, 3798, 1202, 226821], [24, 3778, 1222, 225599]], 'balloon': 225599}], ['control 1', {'principal': 250000, 'rate_bp': 0, 'payment': 500, 'max_months': 1}, {'rows': [[1, 0, 500, 249500]], 'balloon': 249500}], ['control 2', {'principal': 250000, 'rate_bp': 1999, 'payment': 500, 'max_months': 24}, {'error': 'negative_amortization', 'month': 1}], ['control 3', {'principal': 100000, 'rate_bp': 1999, 'payment': 1000, 'max_months': 0}, {'rows': [], 'balloon': 100000}], ['control 4', {'principal': 250000, 'rate_bp': 1200, 'payment': 500, 'max_months': 12}, {'error': 'negative_amortization', 'month': 1}], ['control 5', {'principal': 250000, 'rate_bp': 1999, 'payment': 1200, 'max_months': 6}, {'error': 'negative_amortization', 'month': 1}], ['control 6', {'principal': 50000, 'rate_bp': 1200, 'payment': 500, 'max_months': 1}, {'error': 'negative_amortization', 'month': 1}]], [['regression: interest base', {'principal': 12345, 'rate_bp': 600, 'payment': 500, 'max_months': 24}, {'rows': [[1, 62, 438, 11907], [2, 60, 440, 11467], [3, 57, 443, 11024], [4, 55, 445, 10579], [5, 53, 447, 10132], [6, 51, 449, 9683], [7, 48, 452, 9231], [8, 46, 454, 8777], [9, 44, 456, 8321], [10, 42, 458, 7863], [11, 39, 461, 7402], [12, 37, 463, 6939], [13, 35, 465, 6474], [14, 32, 468, 6006], [15, 30, 470, 5536], [16, 28, 472, 5064], [17, 25, 475, 4589], [18, 23, 477, 4112], [19, 21, 479, 3633], [20, 18, 482, 3151], [21, 16, 484, 2667], [22, 13, 487, 2180], [23, 11, 489, 1691], [24, 8, 492, 1199]], 'balloon': 1199}], ['control 1', {'principal': 100000, 'rate_bp': 600, 'payment': 20007, 'max_months': 1}, {'rows': [[1, 500, 19507, 80493]], 'balloon': 80493}], ['control 2', {'principal': 100000, 'rate_bp': 0, 'payment': 20007, 'max_months': 3}, {'rows': [[1, 0, 20007, 79993], [2, 0, 20007, 59986], [3, 0, 20007, 39979]], 'balloon': 39979}], ['control 3', {'principal': 1000, 'rate_bp': 0, 'payment': 1000, 'max_months': 0}, {'rows': [], 'balloon': 1000}], ['control 4', {'principal': 50000, 'rate_bp': 0, 'payment': 1000, 'max_months': 3}, {'rows': [[1, 0, 1000, 49000], [2, 0, 1000, 48000], [3, 0, 1000, 47000]], 'balloon': 47000}], ['control 5', {'principal': 250000, 'rate_bp': 2400, 'payment': 500, 'max_months': 12}, {'error': 'negative_amortization', 'month': 1}], ['control 6', {'principal': 50000, 'rate_bp': 0, 'payment': 16666, 'max_months': 24}, {'rows': [[1, 0, 16666, 33334], [2, 0, 16666, 16668], [3, 0, 16666, 2], [4, 0, 2, 0]], 'balloon': 0}]], [['regression: interest base', {'principal': 50000, 'rate_bp': 2400, 'payment': 5000, 'max_months': 3}, {'rows': [[1, 1000, 4000, 46000], [2, 920, 4080, 41920], [3, 838, 4162, 37758]], 'balloon': 37758}], ['control 1', {'principal': 12345, 'rate_bp': 0, 'payment': 4115, 'max_months': 24}, {'rows': [[1, 0, 4115, 8230], [2, 0, 4115, 4115], [3, 0, 4115, 0]], 'balloon': 0}], ['control 2', {'principal': 12345, 'rate_bp': 0, 'payment': 4115, 'max_months': 1}, {'rows': [[1, 0, 4115, 8230]], 'balloon': 8230}], ['control 3', {'principal': 250000, 'rate_bp': 600, 'payment': 20833, 'max_months': 1}, {'rows': [[1, 1250, 19583, 230417]], 'balloon': 230417}], ['control 4', {'principal': 1000, 'rate_bp': 2400, 'payment': 1050, 'max_months': 0}, {'rows': [], 'balloon': 1000}], ['control 5', {'principal': 250000, 'rate_bp': 1999, 'payment': 83333, 'max_months': 0}, {'rows': [], 'balloon': 250000}], ['control 6', {'principal': 250000, 'rate_bp': 600, 'payment': 1000, 'max_months': 3}, {'error': 'negative_amortization', 'month': 1}]], [['regression: interest base', {'principal': 12345, 'rate_bp': 1200, 'payment': 5000, 'max_months': 3}, {'rows': [[1, 123, 4877, 7468], [2, 75, 4925, 2543], [3, 25, 2543, 0]], 'balloon': 0}], ['control 1', {'principal': 12345, 'rate_bp': 0, 'payment': 5000, 'max_months': 6}, {'rows': [[1, 0, 5000, 7345], [2, 0, 5000, 2345], [3, 0, 2345, 0]], 'balloon': 0}], ['control 2', {'principal': 100000, 'rate_bp': 0, 'payment': 8333, 'max_months': 24}, {'rows': [[1, 0, 8333, 91667], [2, 0, 8333, 83334], [3, 0, 8333, 75001], [4, 0, 8333, 66668], [5, 0, 8333, 58335], [6, 0, 8333, 50002], [7, 0, 8333, 41669], [8, 0, 8333, 33336], [9, 0, 8333, 25003], [10, 0, 8333, 16670], [11, 0, 8333, 8337], [12, 0, 8333, 4], [13, 0, 4, 0]], 'balloon': 0}], ['control 3', {'principal': 1000, 'rate_bp': 1999, 'payment': 5000, 'max_months': 24}, {'rows': [[1, 17, 1000, 0]], 'balloon': 0}], ['control 4', {'principal': 250000, 'rate_bp': 600, 'payment': 500, 'max_months': 0}, {'rows': [], 'balloon': 250000}], ['control 5', {'principal': 50000, 'rate_bp': 1200, 'payment': 5000, 'max_months': 1}, {'rows': [[1, 500, 4500, 45500]], 'balloon': 45500}], ['control 6', {'principal': 250000, 'rate_bp': 1200, 'payment': 500, 'max_months': 6}, {'error': 'negative_amortization', 'month': 1}]], [['regression: interest base', {'principal': 1000, 'rate_bp': 2400, 'payment': 500, 'max_months': 3}, {'rows': [[1, 20, 480, 520], [2, 10, 490, 30], [3, 1, 30, 0]], 'balloon': 0}], ['control 1', {'principal': 50000, 'rate_bp': 0, 'payment': 10007, 'max_months': 24}, {'rows': [[1, 0, 10007, 39993], [2, 0, 10007, 29986], [3, 0, 10007, 19979], [4, 0, 10007, 9972], [5, 0, 9972, 0]], 'balloon': 0}], ['control 2', {'principal': 12345, 'rate_bp': 2400, 'payment': 2476, 'max_months': 0}, {'rows': [], 'balloon': 12345}], ['control 3', {'principal': 250000, 'rate_bp': 2400, 'payment': 20833, 'max_months': 0}, {'rows': [], 'balloon': 250000}], ['control 4', {'principal': 50000, 'rate_bp': 600, 'payment': 1000, 'max_months': 0}, {'rows': [], 'balloon': 50000}], ['control 5', {'principal': 100000, 'rate_bp': 1200, 'payment': 1200, 'max_months': 1}, {'rows': [[1, 1000, 200, 99800]], 'balloon': 99800}], ['control 6', {'principal': 50000, 'rate_bp': 2400, 'payment': 4166, 'max_months': 0}, {'rows': [], 'balloon': 50000}]]]
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 base | {'balloon': 223162, 'rows': [[1, 4081, 919, 249081], [2, 4066, 934, 248147], [3, 4050, 950, 247197], [4, 4035, 965, 246232], [5, 4019, 981, 245251], [6, 4002, 998, 244253], [7, 3986, 1014, 243239], [8, 3969, 1031, 242208], [9, 3951, 1049, 241159], [10, 3934, 1066, 240093], [11, 3916, 1084, 239009], [12, 3898, 1102, 237907], [13, 3880, 1120, 236787], [14, 3861, 1139, 235648], [15, 3842, 1158, 234490], [16, 3823, 1177, 233313], [17, 3803, 1197, 232116], [18, 3783, 1217, 230899], [19, 3763, 1237, 229662], [20, 3742, 1258, 228404], [21, 3722, 1278, 227126], [22, 3700, 1300, 225826], [23, 3679, 1321, 224505], [24, 3657, 1343, 223162]]} | {'balloon': 225599, 'rows': [[1, 4165, 835, 249165], [2, 4151, 849, 248316], [3, 4137, 863, 247453], [4, 4122, 878, 246575], [5, 4108, 892, 245683], [6, 4093, 907, 244776], [7, 4078, 922, 243854], [8, 4062, 938, 242916], [9, 4047, 953, 241963], [10, 4031, 969, 240994], [11, 4015, 985, 240009], [12, 3998, 1002, 239007], [13, 3981, 1019, 237988], [14, 3964, 1036, 236952], [15, 3947, 1053, 235899], [16, 3930, 1070, 234829], [17, 3912, 1088, 233741], [18, 3894, 1106, 232635], [19, 3875, 1125, 231510], [20, 3857, 1143, 230367], [21, 3838, 1162, 229205], [22, 3818, 1182, 228023], [23, 3798, 1202, 226821], [24, 3778, 1222, 225599]]} | Failed |
| control 1 | {'balloon': 249500, 'rows': [[1, 0, 500, 249500]]} | {'balloon': 249500, 'rows': [[1, 0, 500, 249500]]} | Passed |
| control 2 | {'error': 'negative_amortization', 'month': 1} | {'error': 'negative_amortization', 'month': 1} | Passed |
| control 3 | {'balloon': 100000, 'rows': []} | {'balloon': 100000, 'rows': []} | Passed |
| control 4 | {'error': 'negative_amortization', 'month': 1} | {'error': 'negative_amortization', 'month': 1} | Passed |
| control 5 | {'error': 'negative_amortization', 'month': 1} | {'error': 'negative_amortization', 'month': 1} | Passed |
| control 6 | {'balloon': 49995, 'rows': [[1, 495, 5, 49995]]} | {'error': 'negative_amortization', 'month': 1} | Failed |
SHA-256 / 0a145a848e06c46596fcd8ca86c93fa9b151035d760d317fd643b791f4b65c52
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)
bal = x['principal']
rows = []
for k in range(1, x['max_months'] + 1):
if bal == 0:
break
interest = rnd(bal * x['rate_bp'], 120000)
pay = x['payment']
if pay <= interest:
return {'error': 'negative_amortization', 'month': k}
princ = min(pay - interest, bal)
bal -= princ
rows.append([k, interest, princ, bal])
return {'rows': rows, 'balloon': bal}
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: interest base', {'principal': 250000, 'rate_bp': 1999, 'payment': 5000, 'max_months': 24}, {'rows': [[1, 4165, 835, 249165], [2, 4151, 849, 248316], [3, 4137, 863, 247453], [4, 4122, 878, 246575], [5, 4108, 892, 245683], [6, 4093, 907, 244776], [7, 4078, 922, 243854], [8, 4062, 938, 242916], [9, 4047, 953, 241963], [10, 4031, 969, 240994], [11, 4015, 985, 240009], [12, 3998, 1002, 239007], [13, 3981, 1019, 237988], [14, 3964, 1036, 236952], [15, 3947, 1053, 235899], [16, 3930, 1070, 234829], [17, 3912, 1088, 233741], [18, 3894, 1106, 232635], [19, 3875, 1125, 231510], [20, 3857, 1143, 230367], [21, 3838, 1162, 229205], [22, 3818, 1182, 228023], [23, 3798, 1202, 226821], [24, 3778, 1222, 225599]], 'balloon': 225599}], ['control 1', {'principal': 250000, 'rate_bp': 0, 'payment': 500, 'max_months': 1}, {'rows': [[1, 0, 500, 249500]], 'balloon': 249500}], ['control 2', {'principal': 250000, 'rate_bp': 1999, 'payment': 500, 'max_months': 24}, {'error': 'negative_amortization', 'month': 1}], ['control 3', {'principal': 100000, 'rate_bp': 1999, 'payment': 1000, 'max_months': 0}, {'rows': [], 'balloon': 100000}], ['control 4', {'principal': 250000, 'rate_bp': 1200, 'payment': 500, 'max_months': 12}, {'error': 'negative_amortization', 'month': 1}], ['control 5', {'principal': 250000, 'rate_bp': 1999, 'payment': 1200, 'max_months': 6}, {'error': 'negative_amortization', 'month': 1}], ['control 6', {'principal': 50000, 'rate_bp': 1200, 'payment': 500, 'max_months': 1}, {'error': 'negative_amortization', 'month': 1}]], [['regression: interest base', {'principal': 12345, 'rate_bp': 600, 'payment': 500, 'max_months': 24}, {'rows': [[1, 62, 438, 11907], [2, 60, 440, 11467], [3, 57, 443, 11024], [4, 55, 445, 10579], [5, 53, 447, 10132], [6, 51, 449, 9683], [7, 48, 452, 9231], [8, 46, 454, 8777], [9, 44, 456, 8321], [10, 42, 458, 7863], [11, 39, 461, 7402], [12, 37, 463, 6939], [13, 35, 465, 6474], [14, 32, 468, 6006], [15, 30, 470, 5536], [16, 28, 472, 5064], [17, 25, 475, 4589], [18, 23, 477, 4112], [19, 21, 479, 3633], [20, 18, 482, 3151], [21, 16, 484, 2667], [22, 13, 487, 2180], [23, 11, 489, 1691], [24, 8, 492, 1199]], 'balloon': 1199}], ['control 1', {'principal': 100000, 'rate_bp': 600, 'payment': 20007, 'max_months': 1}, {'rows': [[1, 500, 19507, 80493]], 'balloon': 80493}], ['control 2', {'principal': 100000, 'rate_bp': 0, 'payment': 20007, 'max_months': 3}, {'rows': [[1, 0, 20007, 79993], [2, 0, 20007, 59986], [3, 0, 20007, 39979]], 'balloon': 39979}], ['control 3', {'principal': 1000, 'rate_bp': 0, 'payment': 1000, 'max_months': 0}, {'rows': [], 'balloon': 1000}], ['control 4', {'principal': 50000, 'rate_bp': 0, 'payment': 1000, 'max_months': 3}, {'rows': [[1, 0, 1000, 49000], [2, 0, 1000, 48000], [3, 0, 1000, 47000]], 'balloon': 47000}], ['control 5', {'principal': 250000, 'rate_bp': 2400, 'payment': 500, 'max_months': 12}, {'error': 'negative_amortization', 'month': 1}], ['control 6', {'principal': 50000, 'rate_bp': 0, 'payment': 16666, 'max_months': 24}, {'rows': [[1, 0, 16666, 33334], [2, 0, 16666, 16668], [3, 0, 16666, 2], [4, 0, 2, 0]], 'balloon': 0}]], [['regression: interest base', {'principal': 50000, 'rate_bp': 2400, 'payment': 5000, 'max_months': 3}, {'rows': [[1, 1000, 4000, 46000], [2, 920, 4080, 41920], [3, 838, 4162, 37758]], 'balloon': 37758}], ['control 1', {'principal': 12345, 'rate_bp': 0, 'payment': 4115, 'max_months': 24}, {'rows': [[1, 0, 4115, 8230], [2, 0, 4115, 4115], [3, 0, 4115, 0]], 'balloon': 0}], ['control 2', {'principal': 12345, 'rate_bp': 0, 'payment': 4115, 'max_months': 1}, {'rows': [[1, 0, 4115, 8230]], 'balloon': 8230}], ['control 3', {'principal': 250000, 'rate_bp': 600, 'payment': 20833, 'max_months': 1}, {'rows': [[1, 1250, 19583, 230417]], 'balloon': 230417}], ['control 4', {'principal': 1000, 'rate_bp': 2400, 'payment': 1050, 'max_months': 0}, {'rows': [], 'balloon': 1000}], ['control 5', {'principal': 250000, 'rate_bp': 1999, 'payment': 83333, 'max_months': 0}, {'rows': [], 'balloon': 250000}], ['control 6', {'principal': 250000, 'rate_bp': 600, 'payment': 1000, 'max_months': 3}, {'error': 'negative_amortization', 'month': 1}]], [['regression: interest base', {'principal': 12345, 'rate_bp': 1200, 'payment': 5000, 'max_months': 3}, {'rows': [[1, 123, 4877, 7468], [2, 75, 4925, 2543], [3, 25, 2543, 0]], 'balloon': 0}], ['control 1', {'principal': 12345, 'rate_bp': 0, 'payment': 5000, 'max_months': 6}, {'rows': [[1, 0, 5000, 7345], [2, 0, 5000, 2345], [3, 0, 2345, 0]], 'balloon': 0}], ['control 2', {'principal': 100000, 'rate_bp': 0, 'payment': 8333, 'max_months': 24}, {'rows': [[1, 0, 8333, 91667], [2, 0, 8333, 83334], [3, 0, 8333, 75001], [4, 0, 8333, 66668], [5, 0, 8333, 58335], [6, 0, 8333, 50002], [7, 0, 8333, 41669], [8, 0, 8333, 33336], [9, 0, 8333, 25003], [10, 0, 8333, 16670], [11, 0, 8333, 8337], [12, 0, 8333, 4], [13, 0, 4, 0]], 'balloon': 0}], ['control 3', {'principal': 1000, 'rate_bp': 1999, 'payment': 5000, 'max_months': 24}, {'rows': [[1, 17, 1000, 0]], 'balloon': 0}], ['control 4', {'principal': 250000, 'rate_bp': 600, 'payment': 500, 'max_months': 0}, {'rows': [], 'balloon': 250000}], ['control 5', {'principal': 50000, 'rate_bp': 1200, 'payment': 5000, 'max_months': 1}, {'rows': [[1, 500, 4500, 45500]], 'balloon': 45500}], ['control 6', {'principal': 250000, 'rate_bp': 1200, 'payment': 500, 'max_months': 6}, {'error': 'negative_amortization', 'month': 1}]], [['regression: interest base', {'principal': 1000, 'rate_bp': 2400, 'payment': 500, 'max_months': 3}, {'rows': [[1, 20, 480, 520], [2, 10, 490, 30], [3, 1, 30, 0]], 'balloon': 0}], ['control 1', {'principal': 50000, 'rate_bp': 0, 'payment': 10007, 'max_months': 24}, {'rows': [[1, 0, 10007, 39993], [2, 0, 10007, 29986], [3, 0, 10007, 19979], [4, 0, 10007, 9972], [5, 0, 9972, 0]], 'balloon': 0}], ['control 2', {'principal': 12345, 'rate_bp': 2400, 'payment': 2476, 'max_months': 0}, {'rows': [], 'balloon': 12345}], ['control 3', {'principal': 250000, 'rate_bp': 2400, 'payment': 20833, 'max_months': 0}, {'rows': [], 'balloon': 250000}], ['control 4', {'principal': 50000, 'rate_bp': 600, 'payment': 1000, 'max_months': 0}, {'rows': [], 'balloon': 50000}], ['control 5', {'principal': 100000, 'rate_bp': 1200, 'payment': 1200, 'max_months': 1}, {'rows': [[1, 1000, 200, 99800]], 'balloon': 99800}], ['control 6', {'principal': 50000, 'rate_bp': 2400, 'payment': 4166, 'max_months': 0}, {'rows': [], 'balloon': 50000}]]]
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 base | {'balloon': 225599, 'rows': [[1, 4165, 835, 249165], [2, 4151, 849, 248316], [3, 4137, 863, 247453], [4, 4122, 878, 246575], [5, 4108, 892, 245683], [6, 4093, 907, 244776], [7, 4078, 922, 243854], [8, 4062, 938, 242916], [9, 4047, 953, 241963], [10, 4031, 969, 240994], [11, 4015, 985, 240009], [12, 3998, 1002, 239007], [13, 3981, 1019, 237988], [14, 3964, 1036, 236952], [15, 3947, 1053, 235899], [16, 3930, 1070, 234829], [17, 3912, 1088, 233741], [18, 3894, 1106, 232635], [19, 3875, 1125, 231510], [20, 3857, 1143, 230367], [21, 3838, 1162, 229205], [22, 3818, 1182, 228023], [23, 3798, 1202, 226821], [24, 3778, 1222, 225599]]} | {'balloon': 225599, 'rows': [[1, 4165, 835, 249165], [2, 4151, 849, 248316], [3, 4137, 863, 247453], [4, 4122, 878, 246575], [5, 4108, 892, 245683], [6, 4093, 907, 244776], [7, 4078, 922, 243854], [8, 4062, 938, 242916], [9, 4047, 953, 241963], [10, 4031, 969, 240994], [11, 4015, 985, 240009], [12, 3998, 1002, 239007], [13, 3981, 1019, 237988], [14, 3964, 1036, 236952], [15, 3947, 1053, 235899], [16, 3930, 1070, 234829], [17, 3912, 1088, 233741], [18, 3894, 1106, 232635], [19, 3875, 1125, 231510], [20, 3857, 1143, 230367], [21, 3838, 1162, 229205], [22, 3818, 1182, 228023], [23, 3798, 1202, 226821], [24, 3778, 1222, 225599]]} | Passed |
| control 1 | {'balloon': 249500, 'rows': [[1, 0, 500, 249500]]} | {'balloon': 249500, 'rows': [[1, 0, 500, 249500]]} | Passed |
| control 2 | {'error': 'negative_amortization', 'month': 1} | {'error': 'negative_amortization', 'month': 1} | Passed |
| control 3 | {'balloon': 100000, 'rows': []} | {'balloon': 100000, 'rows': []} | Passed |
| control 4 | {'error': 'negative_amortization', 'month': 1} | {'error': 'negative_amortization', 'month': 1} | Passed |
| control 5 | {'error': 'negative_amortization', 'month': 1} | {'error': 'negative_amortization', 'month': 1} | Passed |
| control 6 | {'error': 'negative_amortization', 'month': 1} | {'error': 'negative_amortization', 'month': 1} | Passed |
SHA-256 / bf6393a87466e88d63b3aa14ad0c5ad335076fd66f10b7233679735250d1922a
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.189592+00:00.
Case digest / 8e076e7a6f719c09eb441e2598a944b87f9bd87a4d30eaf31ff6dbbf61443c42