broken_source:
"""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)
    n = x['term']
    k = x['paid']
    fc = x['finance_charge'] - x['acq_fee']
    rem = n - k
    rebate = rnd(fc * rem * (rem + 1), n * (n + 1))
    if rebate <= x['min_rebate']:
        rebate = 0
    remaining = x['payment'] * rem
    return {'rebate': rebate, 'payoff': remaining - rebate, 'earned': x['finance_charge'] - rebate}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: rebate exactly at minimum', {'term': 12, 'paid': 11, 'finance_charge': 7800, 'acq_fee': 0, 'payment': 10000, 'min_rebate': 100}, {'rebate': 100, 'payoff': 9900, 'earned': 7700}], ['regression: minimum rebate threshold', {'term': 36, 'paid': 0, 'finance_charge': 100, 'acq_fee': 0, 'payment': 4321, 'min_rebate': 100}, {'rebate': 100, 'payoff': 155456, 'earned': 0}], ['regression: minimum rebate threshold, partial-repair probe', {'term': 36, 'paid': 35, 'finance_charge': 50000, 'acq_fee': 7500, 'payment': 25000, 'min_rebate': 100}, {'rebate': 0, 'payoff': 25000, 'earned': 50000}], ['control 1', {'term': 36, 'paid': 35, 'finance_charge': 120000, 'acq_fee': 0, 'payment': 10000, 'min_rebate': 100}, {'rebate': 180, 'payoff': 9820, 'earned': 119820}], ['control 2', {'term': 24, 'paid': 23, 'finance_charge': 100, 'acq_fee': 0, 'payment': 25000, 'min_rebate': 100}, {'rebate': 0, 'payoff': 25000, 'earned': 100}], ['control 3', {'term': 24, 'paid': 12, 'finance_charge': 50000, 'acq_fee': 0, 'payment': 25000, 'min_rebate': 100}, {'rebate': 13000, 'payoff': 287000, 'earned': 37000}], ['control 4', {'term': 12, 'paid': 3, 'finance_charge': 100, 'acq_fee': 0, 'payment': 4321, 'min_rebate': 100}, {'rebate': 0, 'payoff': 38889, 'earned': 100}]], [['regression: rebate exactly at minimum', {'term': 12, 'paid': 11, 'finance_charge': 7800, 'acq_fee': 0, 'payment': 10000, 'min_rebate': 100}, {'rebate': 100, 'payoff': 9900, 'earned': 7700}], ['regression: minimum rebate threshold', {'term': 12, 'paid': 11, 'finance_charge': 7777, 'acq_fee': 0, 'payment': 4321, 'min_rebate': 100}, {'rebate': 100, 'payoff': 4221, 'earned': 7677}], ['regression: minimum rebate threshold, partial-repair probe', {'term': 12, 'paid': 1, 'finance_charge': 100, 'acq_fee': 0, 'payment': 10000, 'min_rebate': 100}, {'rebate': 0, 'payoff': 110000, 'earned': 100}], ['control 1', {'term': 36, 'paid': 3, 'finance_charge': 7777, 'acq_fee': 2500, 'payment': 10000, 'min_rebate': 500}, {'rebate': 4445, 'payoff': 325555, 'earned': 3332}], ['control 2', {'term': 24, 'paid': 1, 'finance_charge': 120000, 'acq_fee': 0, 'payment': 25000, 'min_rebate': 500}, {'rebate': 110400, 'payoff': 464600, 'earned': 9600}], ['control 3', {'term': 24, 'paid': 24, 'finance_charge': 120000, 'acq_fee': 0, 'payment': 10000, 'min_rebate': 100}, {'rebate': 0, 'payoff': 0, 'earned': 120000}], ['control 4', {'term': 36, 'paid': 0, 'finance_charge': 100, 'acq_fee': 7500, 'payment': 25000, 'min_rebate': 500}, {'rebate': 0, 'payoff': 900000, 'earned': 100}]], [['regression: rebate exactly at minimum', {'term': 12, 'paid': 11, 'finance_charge': 7800, 'acq_fee': 0, 'payment': 10000, 'min_rebate': 100}, {'rebate': 100, 'payoff': 9900, 'earned': 7700}], ['regression: minimum rebate threshold', {'term': 12, 'paid': 0, 'finance_charge': 100, 'acq_fee': 0, 'payment': 10000, 'min_rebate': 100}, {'rebate': 100, 'payoff': 119900, 'earned': 0}], ['regression: minimum rebate threshold, partial-repair probe', {'term': 12, 'paid': 11, 'finance_charge': 7777, 'acq_fee': 2500, 'payment': 4321, 'min_rebate': 2000}, {'rebate': 0, 'payoff': 4321, 'earned': 7777}], ['control 1', {'term': 6, 'paid': 5, 'finance_charge': 100, 'acq_fee': 0, 'payment': 25000, 'min_rebate': 2000}, {'rebate': 0, 'payoff': 25000, 'earned': 100}], ['control 2', {'term': 24, 'paid': 3, 'finance_charge': 120000, 'acq_fee': 0, 'payment': 10000, 'min_rebate': 2000}, {'rebate': 92400, 'payoff': 117600, 'earned': 27600}], ['control 3', {'term': 12, 'paid': 3, 'finance_charge': 50000, 'acq_fee': 0, 'payment': 4321, 'min_rebate': 2000}, {'rebate': 28846, 'payoff': 10043, 'earned': 21154}], ['control 4', {'term': 6, 'paid': 3, 'finance_charge': 7777, 'acq_fee': 7500, 'payment': 4321, 'min_rebate': 0}, {'rebate': 79, 'payoff': 12884, 'earned': 7698}]], [['regression: rebate exactly at minimum', {'term': 12, 'paid': 11, 'finance_charge': 7800, 'acq_fee': 0, 'payment': 10000, 'min_rebate': 100}, {'rebate': 100, 'payoff': 9900, 'earned': 7700}], ['regression: minimum rebate threshold, partial-repair probe', {'term': 36, 'paid': 35, 'finance_charge': 120000, 'acq_fee': 7500, 'payment': 10000, 'min_rebate': 500}, {'rebate': 0, 'payoff': 10000, 'earned': 120000}], ['control 1', {'term': 36, 'paid': 0, 'finance_charge': 100, 'acq_fee': 7500, 'payment': 25000, 'min_rebate': 500}, {'rebate': 0, 'payoff': 900000, 'earned': 100}], ['control 2', {'term': 12, 'paid': 12, 'finance_charge': 50000, 'acq_fee': 2500, 'payment': 10000, 'min_rebate': 0}, {'rebate': 0, 'payoff': 0, 'earned': 50000}], ['control 3', {'term': 12, 'paid': 0, 'finance_charge': 7777, 'acq_fee': 0, 'payment': 4321, 'min_rebate': 2000}, {'rebate': 7777, 'payoff': 44075, 'earned': 0}], ['control 4', {'term': 36, 'paid': 0, 'finance_charge': 100, 'acq_fee': 0, 'payment': 10000, 'min_rebate': 0}, {'rebate': 100, 'payoff': 359900, 'earned': 0}], ['control 5', {'term': 6, 'paid': 3, 'finance_charge': 100, 'acq_fee': 0, 'payment': 25000, 'min_rebate': 2000}, {'rebate': 0, 'payoff': 75000, 'earned': 100}]], [['regression: rebate exactly at minimum', {'term': 12, 'paid': 11, 'finance_charge': 7800, 'acq_fee': 0, 'payment': 10000, 'min_rebate': 100}, {'rebate': 100, 'payoff': 9900, 'earned': 7700}], ['regression: minimum rebate threshold', {'term': 36, 'paid': 0, 'finance_charge': 100, 'acq_fee': 0, 'payment': 25000, 'min_rebate': 100}, {'rebate': 100, 'payoff': 899900, 'earned': 0}], ['regression: minimum rebate threshold, partial-repair probe', {'term': 36, 'paid': 35, 'finance_charge': 50000, 'acq_fee': 2500, 'payment': 10000, 'min_rebate': 2000}, {'rebate': 0, 'payoff': 10000, 'earned': 50000}], ['control 1', {'term': 24, 'paid': 12, 'finance_charge': 120000, 'acq_fee': 7500, 'payment': 25000, 'min_rebate': 500}, {'rebate': 29250, 'payoff': 270750, 'earned': 90750}], ['control 2', {'term': 24, 'paid': 12, 'finance_charge': 100, 'acq_fee': 0, 'payment': 4321, 'min_rebate': 500}, {'rebate': 0, 'payoff': 51852, 'earned': 100}], ['control 3', {'term': 36, 'paid': 0, 'finance_charge': 7777, 'acq_fee': 7500, 'payment': 25000, 'min_rebate': 2000}, {'rebate': 0, 'payoff': 900000, 'earned': 7777}], ['control 4', {'term': 6, 'paid': 5, 'finance_charge': 120000, 'acq_fee': 2500, 'payment': 10000, 'min_rebate': 100}, {'rebate': 5595, 'payoff': 4405, 'earned': 114405}]]]
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)

source:
"""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)
    n = x['term']
    k = x['paid']
    fc = x['finance_charge'] - x['acq_fee']
    rem = n - k
    rebate = rnd(fc * rem * (rem + 1), n * (n + 1))
    if fc < x['min_rebate']:
        rebate = 0
    remaining = x['payment'] * rem
    return {'rebate': rebate, 'payoff': remaining - rebate, 'earned': x['finance_charge'] - rebate}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: rebate exactly at minimum', {'term': 12, 'paid': 11, 'finance_charge': 7800, 'acq_fee': 0, 'payment': 10000, 'min_rebate': 100}, {'rebate': 100, 'payoff': 9900, 'earned': 7700}], ['regression: minimum rebate threshold', {'term': 36, 'paid': 0, 'finance_charge': 100, 'acq_fee': 0, 'payment': 4321, 'min_rebate': 100}, {'rebate': 100, 'payoff': 155456, 'earned': 0}], ['regression: minimum rebate threshold, partial-repair probe', {'term': 36, 'paid': 35, 'finance_charge': 50000, 'acq_fee': 7500, 'payment': 25000, 'min_rebate': 100}, {'rebate': 0, 'payoff': 25000, 'earned': 50000}], ['control 1', {'term': 36, 'paid': 35, 'finance_charge': 120000, 'acq_fee': 0, 'payment': 10000, 'min_rebate': 100}, {'rebate': 180, 'payoff': 9820, 'earned': 119820}], ['control 2', {'term': 24, 'paid': 23, 'finance_charge': 100, 'acq_fee': 0, 'payment': 25000, 'min_rebate': 100}, {'rebate': 0, 'payoff': 25000, 'earned': 100}], ['control 3', {'term': 24, 'paid': 12, 'finance_charge': 50000, 'acq_fee': 0, 'payment': 25000, 'min_rebate': 100}, {'rebate': 13000, 'payoff': 287000, 'earned': 37000}], ['control 4', {'term': 12, 'paid': 3, 'finance_charge': 100, 'acq_fee': 0, 'payment': 4321, 'min_rebate': 100}, {'rebate': 0, 'payoff': 38889, 'earned': 100}]], [['regression: rebate exactly at minimum', {'term': 12, 'paid': 11, 'finance_charge': 7800, 'acq_fee': 0, 'payment': 10000, 'min_rebate': 100}, {'rebate': 100, 'payoff': 9900, 'earned': 7700}], ['regression: minimum rebate threshold', {'term': 12, 'paid': 11, 'finance_charge': 7777, 'acq_fee': 0, 'payment': 4321, 'min_rebate': 100}, {'rebate': 100, 'payoff': 4221, 'earned': 7677}], ['regression: minimum rebate threshold, partial-repair probe', {'term': 12, 'paid': 1, 'finance_charge': 100, 'acq_fee': 0, 'payment': 10000, 'min_rebate': 100}, {'rebate': 0, 'payoff': 110000, 'earned': 100}], ['control 1', {'term': 36, 'paid': 3, 'finance_charge': 7777, 'acq_fee': 2500, 'payment': 10000, 'min_rebate': 500}, {'rebate': 4445, 'payoff': 325555, 'earned': 3332}], ['control 2', {'term': 24, 'paid': 1, 'finance_charge': 120000, 'acq_fee': 0, 'payment': 25000, 'min_rebate': 500}, {'rebate': 110400, 'payoff': 464600, 'earned': 9600}], ['control 3', {'term': 24, 'paid': 24, 'finance_charge': 120000, 'acq_fee': 0, 'payment': 10000, 'min_rebate': 100}, {'rebate': 0, 'payoff': 0, 'earned': 120000}], ['control 4', {'term': 36, 'paid': 0, 'finance_charge': 100, 'acq_fee': 7500, 'payment': 25000, 'min_rebate': 500}, {'rebate': 0, 'payoff': 900000, 'earned': 100}]], [['regression: rebate exactly at minimum', {'term': 12, 'paid': 11, 'finance_charge': 7800, 'acq_fee': 0, 'payment': 10000, 'min_rebate': 100}, {'rebate': 100, 'payoff': 9900, 'earned': 7700}], ['regression: minimum rebate threshold', {'term': 12, 'paid': 0, 'finance_charge': 100, 'acq_fee': 0, 'payment': 10000, 'min_rebate': 100}, {'rebate': 100, 'payoff': 119900, 'earned': 0}], ['regression: minimum rebate threshold, partial-repair probe', {'term': 12, 'paid': 11, 'finance_charge': 7777, 'acq_fee': 2500, 'payment': 4321, 'min_rebate': 2000}, {'rebate': 0, 'payoff': 4321, 'earned': 7777}], ['control 1', {'term': 6, 'paid': 5, 'finance_charge': 100, 'acq_fee': 0, 'payment': 25000, 'min_rebate': 2000}, {'rebate': 0, 'payoff': 25000, 'earned': 100}], ['control 2', {'term': 24, 'paid': 3, 'finance_charge': 120000, 'acq_fee': 0, 'payment': 10000, 'min_rebate': 2000}, {'rebate': 92400, 'payoff': 117600, 'earned': 27600}], ['control 3', {'term': 12, 'paid': 3, 'finance_charge': 50000, 'acq_fee': 0, 'payment': 4321, 'min_rebate': 2000}, {'rebate': 28846, 'payoff': 10043, 'earned': 21154}], ['control 4', {'term': 6, 'paid': 3, 'finance_charge': 7777, 'acq_fee': 7500, 'payment': 4321, 'min_rebate': 0}, {'rebate': 79, 'payoff': 12884, 'earned': 7698}]], [['regression: rebate exactly at minimum', {'term': 12, 'paid': 11, 'finance_charge': 7800, 'acq_fee': 0, 'payment': 10000, 'min_rebate': 100}, {'rebate': 100, 'payoff': 9900, 'earned': 7700}], ['regression: minimum rebate threshold, partial-repair probe', {'term': 36, 'paid': 35, 'finance_charge': 120000, 'acq_fee': 7500, 'payment': 10000, 'min_rebate': 500}, {'rebate': 0, 'payoff': 10000, 'earned': 120000}], ['control 1', {'term': 36, 'paid': 0, 'finance_charge': 100, 'acq_fee': 7500, 'payment': 25000, 'min_rebate': 500}, {'rebate': 0, 'payoff': 900000, 'earned': 100}], ['control 2', {'term': 12, 'paid': 12, 'finance_charge': 50000, 'acq_fee': 2500, 'payment': 10000, 'min_rebate': 0}, {'rebate': 0, 'payoff': 0, 'earned': 50000}], ['control 3', {'term': 12, 'paid': 0, 'finance_charge': 7777, 'acq_fee': 0, 'payment': 4321, 'min_rebate': 2000}, {'rebate': 7777, 'payoff': 44075, 'earned': 0}], ['control 4', {'term': 36, 'paid': 0, 'finance_charge': 100, 'acq_fee': 0, 'payment': 10000, 'min_rebate': 0}, {'rebate': 100, 'payoff': 359900, 'earned': 0}], ['control 5', {'term': 6, 'paid': 3, 'finance_charge': 100, 'acq_fee': 0, 'payment': 25000, 'min_rebate': 2000}, {'rebate': 0, 'payoff': 75000, 'earned': 100}]], [['regression: rebate exactly at minimum', {'term': 12, 'paid': 11, 'finance_charge': 7800, 'acq_fee': 0, 'payment': 10000, 'min_rebate': 100}, {'rebate': 100, 'payoff': 9900, 'earned': 7700}], ['regression: minimum rebate threshold', {'term': 36, 'paid': 0, 'finance_charge': 100, 'acq_fee': 0, 'payment': 25000, 'min_rebate': 100}, {'rebate': 100, 'payoff': 899900, 'earned': 0}], ['regression: minimum rebate threshold, partial-repair probe', {'term': 36, 'paid': 35, 'finance_charge': 50000, 'acq_fee': 2500, 'payment': 10000, 'min_rebate': 2000}, {'rebate': 0, 'payoff': 10000, 'earned': 50000}], ['control 1', {'term': 24, 'paid': 12, 'finance_charge': 120000, 'acq_fee': 7500, 'payment': 25000, 'min_rebate': 500}, {'rebate': 29250, 'payoff': 270750, 'earned': 90750}], ['control 2', {'term': 24, 'paid': 12, 'finance_charge': 100, 'acq_fee': 0, 'payment': 4321, 'min_rebate': 500}, {'rebate': 0, 'payoff': 51852, 'earned': 100}], ['control 3', {'term': 36, 'paid': 0, 'finance_charge': 7777, 'acq_fee': 7500, 'payment': 25000, 'min_rebate': 2000}, {'rebate': 0, 'payoff': 900000, 'earned': 7777}], ['control 4', {'term': 6, 'paid': 5, 'finance_charge': 120000, 'acq_fee': 2500, 'payment': 10000, 'min_rebate': 100}, {'rebate': 5595, 'payoff': 4405, 'earned': 114405}]]]
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)

prompt:
A rebate exactly at the minimum is suppressed.

x = {'term' n, 'paid' k, 'finance_charge', 'acq_fee' (fully earned up front), 'payment', 'min_rebate'}. Rebatable charge = finance_charge - acq_fee; remaining r = n - k; rebate = round_half_up(rebatable * r(r+1) / (n(n+1))), set to 0 when below min_rebate. Payoff = payment*r - rebate; earned = finance_charge - rebate. Return {'rebate', 'payoff', 'earned'}.

split: open-access


broken_source:
"""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)
    n = x['term']
    k = x['paid']
    fc = x['finance_charge'] - x['acq_fee']
    rem = n - k - 1
    rebate = rnd(fc * rem * (rem + 1), n * (n + 1))
    if rebate < x['min_rebate']:
        rebate = 0
    remaining = x['payment'] * rem
    return {'rebate': rebate, 'payoff': remaining - rebate, 'earned': x['finance_charge'] - rebate}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: remaining installment count', {'term': 36, 'paid': 35, 'finance_charge': 120000, 'acq_fee': 0, 'payment': 10000, 'min_rebate': 100}, {'rebate': 180, 'payoff': 9820, 'earned': 119820}], ['sample 1', {'term': 36, 'paid': 35, 'finance_charge': 50000, 'acq_fee': 7500, 'payment': 25000, 'min_rebate': 100}, {'rebate': 0, 'payoff': 25000, 'earned': 50000}], ['sample 2', {'term': 24, 'paid': 23, 'finance_charge': 100, 'acq_fee': 0, 'payment': 25000, 'min_rebate': 100}, {'rebate': 0, 'payoff': 25000, 'earned': 100}], ['sample 3', {'term': 24, 'paid': 12, 'finance_charge': 50000, 'acq_fee': 0, 'payment': 25000, 'min_rebate': 100}, {'rebate': 13000, 'payoff': 287000, 'earned': 37000}], ['sample 4', {'term': 12, 'paid': 3, 'finance_charge': 100, 'acq_fee': 0, 'payment': 4321, 'min_rebate': 100}, {'rebate': 0, 'payoff': 38889, 'earned': 100}], ['sample 5', {'term': 6, 'paid': 3, 'finance_charge': 7777, 'acq_fee': 0, 'payment': 10000, 'min_rebate': 500}, {'rebate': 2222, 'payoff': 27778, 'earned': 5555}], ['sample 6', {'term': 24, 'paid': 1, 'finance_charge': 120000, 'acq_fee': 0, 'payment': 4321, 'min_rebate': 100}, {'rebate': 110400, 'payoff': -11017, 'earned': 9600}]], [['regression: remaining installment count', {'term': 36, 'paid': 3, 'finance_charge': 7777, 'acq_fee': 2500, 'payment': 10000, 'min_rebate': 500}, {'rebate': 4445, 'payoff': 325555, 'earned': 3332}], ['sample 1', {'term': 24, 'paid': 1, 'finance_charge': 120000, 'acq_fee': 0, 'payment': 25000, 'min_rebate': 500}, {'rebate': 110400, 'payoff': 464600, 'earned': 9600}], ['sample 2', {'term': 12, 'paid': 1, 'finance_charge': 100, 'acq_fee': 0, 'payment': 10000, 'min_rebate': 100}, {'rebate': 0, 'payoff': 110000, 'earned': 100}], ['sample 3', {'term': 24, 'paid': 24, 'finance_charge': 120000, 'acq_fee': 0, 'payment': 10000, 'min_rebate': 100}, {'rebate': 0, 'payoff': 0, 'earned': 120000}], ['sample 4', {'term': 36, 'paid': 0, 'finance_charge': 100, 'acq_fee': 7500, 'payment': 25000, 'min_rebate': 500}, {'rebate': 0, 'payoff': 900000, 'earned': 100}], ['sample 5', {'term': 24, 'paid': 12, 'finance_charge': 100, 'acq_fee': 2500, 'payment': 10000, 'min_rebate': 500}, {'rebate': 0, 'payoff': 120000, 'earned': 100}], ['sample 6', {'term': 6, 'paid': 0, 'finance_charge': 7777, 'acq_fee': 0, 'payment': 10000, 'min_rebate': 500}, {'rebate': 7777, 'payoff': 52223, 'earned': 0}]], [['regression: remaining installment count', {'term': 6, 'paid': 5, 'finance_charge': 100, 'acq_fee': 0, 'payment': 25000, 'min_rebate': 2000}, {'rebate': 0, 'payoff': 25000, 'earned': 100}], ['sample 1', {'term': 24, 'paid': 3, 'finance_charge': 120000, 'acq_fee': 0, 'payment': 10000, 'min_rebate': 2000}, {'rebate': 92400, 'payoff': 117600, 'earned': 27600}], ['sample 2', {'term': 12, 'paid': 3, 'finance_charge': 50000, 'acq_fee': 0, 'payment': 4321, 'min_rebate': 2000}, {'rebate': 28846, 'payoff': 10043, 'earned': 21154}], ['sample 3', {'term': 6, 'paid': 3, 'finance_charge': 7777, 'acq_fee': 7500, 'payment': 4321, 'min_rebate': 0}, {'rebate': 79, 'payoff': 12884, 'earned': 7698}], ['sample 4', {'term': 6, 'paid': 5, 'finance_charge': 120000, 'acq_fee': 0, 'payment': 10000, 'min_rebate': 0}, {'rebate': 5714, 'payoff': 4286, 'earned': 114286}], ['sample 5', {'term': 12, 'paid': 12, 'finance_charge': 7777, 'acq_fee': 7500, 'payment': 10000, 'min_rebate': 2000}, {'rebate': 0, 'payoff': 0, 'earned': 7777}], ['sample 6', {'term': 24, 'paid': 0, 'finance_charge': 7777, 'acq_fee': 2500, 'payment': 10000, 'min_rebate': 0}, {'rebate': 5277, 'payoff': 234723, 'earned': 2500}]], [['regression: remaining installment count', {'term': 36, 'paid': 0, 'finance_charge': 100, 'acq_fee': 7500, 'payment': 25000, 'min_rebate': 500}, {'rebate': 0, 'payoff': 900000, 'earned': 100}], ['sample 1', {'term': 12, 'paid': 12, 'finance_charge': 50000, 'acq_fee': 2500, 'payment': 10000, 'min_rebate': 0}, {'rebate': 0, 'payoff': 0, 'earned': 50000}], ['sample 2', {'term': 12, 'paid': 0, 'finance_charge': 7777, 'acq_fee': 0, 'payment': 4321, 'min_rebate': 2000}, {'rebate': 7777, 'payoff': 44075, 'earned': 0}], ['sample 3', {'term': 36, 'paid': 0, 'finance_charge': 100, 'acq_fee': 0, 'payment': 10000, 'min_rebate': 0}, {'rebate': 100, 'payoff': 359900, 'earned': 0}], ['sample 4', {'term': 6, 'paid': 3, 'finance_charge': 100, 'acq_fee': 0, 'payment': 25000, 'min_rebate': 2000}, {'rebate': 0, 'payoff': 75000, 'earned': 100}], ['sample 5', {'term': 24, 'paid': 12, 'finance_charge': 120000, 'acq_fee': 2500, 'payment': 4321, 'min_rebate': 100}, {'rebate': 30550, 'payoff': 21302, 'earned': 89450}], ['sample 6', {'term': 36, 'paid': 18, 'finance_charge': 50000, 'acq_fee': 0, 'payment': 4321, 'min_rebate': 0}, {'rebate': 12838, 'payoff': 64940, 'earned': 37162}]], [['regression: remaining installment count', {'term': 24, 'paid': 12, 'finance_charge': 120000, 'acq_fee': 7500, 'payment': 25000, 'min_rebate': 500}, {'rebate': 29250, 'payoff': 270750, 'earned': 90750}], ['sample 1', {'term': 24, 'paid': 12, 'finance_charge': 100, 'acq_fee': 0, 'payment': 4321, 'min_rebate': 500}, {'rebate': 0, 'payoff': 51852, 'earned': 100}], ['sample 2', {'term': 36, 'paid': 0, 'finance_charge': 7777, 'acq_fee': 7500, 'payment': 25000, 'min_rebate': 2000}, {'rebate': 0, 'payoff': 900000, 'earned': 7777}], ['sample 3', {'term': 6, 'paid': 5, 'finance_charge': 120000, 'acq_fee': 2500, 'payment': 10000, 'min_rebate': 100}, {'rebate': 5595, 'payoff': 4405, 'earned': 114405}], ['sample 4', {'term': 36, 'paid': 18, 'finance_charge': 7777, 'acq_fee': 2500, 'payment': 10000, 'min_rebate': 100}, {'rebate': 1355, 'payoff': 178645, 'earned': 6422}], ['sample 5', {'term': 36, 'paid': 36, 'finance_charge': 100, 'acq_fee': 7500, 'payment': 4321, 'min_rebate': 0}, {'rebate': 0, 'payoff': 0, 'earned': 100}], ['sample 6', {'term': 12, 'paid': 0, 'finance_charge': 100, 'acq_fee': 0, 'payment': 25000, 'min_rebate': 500}, {'rebate': 0, 'payoff': 300000, 'earned': 100}]]]
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)

meaning: Fixture-count band, not measured model difficulty

deps: stdlib

source:
"""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)
    n = x['term']
    k = x['paid']
    fc = x['finance_charge'] - x['acq_fee']
    rem = n - k + 1
    rebate = rnd(fc * rem * (rem + 1), n * (n + 1))
    if rebate < x['min_rebate']:
        rebate = 0
    remaining = x['payment'] * rem
    return {'rebate': rebate, 'payoff': remaining - rebate, 'earned': x['finance_charge'] - rebate}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: remaining installment count', {'term': 36, 'paid': 35, 'finance_charge': 120000, 'acq_fee': 0, 'payment': 10000, 'min_rebate': 100}, {'rebate': 180, 'payoff': 9820, 'earned': 119820}], ['sample 1', {'term': 36, 'paid': 35, 'finance_charge': 50000, 'acq_fee': 7500, 'payment': 25000, 'min_rebate': 100}, {'rebate': 0, 'payoff': 25000, 'earned': 50000}], ['sample 2', {'term': 24, 'paid': 23, 'finance_charge': 100, 'acq_fee': 0, 'payment': 25000, 'min_rebate': 100}, {'rebate': 0, 'payoff': 25000, 'earned': 100}], ['sample 3', {'term': 24, 'paid': 12, 'finance_charge': 50000, 'acq_fee': 0, 'payment': 25000, 'min_rebate': 100}, {'rebate': 13000, 'payoff': 287000, 'earned': 37000}], ['sample 4', {'term': 12, 'paid': 3, 'finance_charge': 100, 'acq_fee': 0, 'payment': 4321, 'min_rebate': 100}, {'rebate': 0, 'payoff': 38889, 'earned': 100}], ['sample 5', {'term': 6, 'paid': 3, 'finance_charge': 7777, 'acq_fee': 0, 'payment': 10000, 'min_rebate': 500}, {'rebate': 2222, 'payoff': 27778, 'earned': 5555}], ['sample 6', {'term': 24, 'paid': 1, 'finance_charge': 120000, 'acq_fee': 0, 'payment': 4321, 'min_rebate': 100}, {'rebate': 110400, 'payoff': -11017, 'earned': 9600}]], [['regression: remaining installment count', {'term': 36, 'paid': 3, 'finance_charge': 7777, 'acq_fee': 2500, 'payment': 10000, 'min_rebate': 500}, {'rebate': 4445, 'payoff': 325555, 'earned': 3332}], ['sample 1', {'term': 24, 'paid': 1, 'finance_charge': 120000, 'acq_fee': 0, 'payment': 25000, 'min_rebate': 500}, {'rebate': 110400, 'payoff': 464600, 'earned': 9600}], ['sample 2', {'term': 12, 'paid': 1, 'finance_charge': 100, 'acq_fee': 0, 'payment': 10000, 'min_rebate': 100}, {'rebate': 0, 'payoff': 110000, 'earned': 100}], ['sample 3', {'term': 24, 'paid': 24, 'finance_charge': 120000, 'acq_fee': 0, 'payment': 10000, 'min_rebate': 100}, {'rebate': 0, 'payoff': 0, 'earned': 120000}], ['sample 4', {'term': 36, 'paid': 0, 'finance_charge': 100, 'acq_fee': 7500, 'payment': 25000, 'min_rebate': 500}, {'rebate': 0, 'payoff': 900000, 'earned': 100}], ['sample 5', {'term': 24, 'paid': 12, 'finance_charge': 100, 'acq_fee': 2500, 'payment': 10000, 'min_rebate': 500}, {'rebate': 0, 'payoff': 120000, 'earned': 100}], ['sample 6', {'term': 6, 'paid': 0, 'finance_charge': 7777, 'acq_fee': 0, 'payment': 10000, 'min_rebate': 500}, {'rebate': 7777, 'payoff': 52223, 'earned': 0}]], [['regression: remaining installment count', {'term': 6, 'paid': 5, 'finance_charge': 100, 'acq_fee': 0, 'payment': 25000, 'min_rebate': 2000}, {'rebate': 0, 'payoff': 25000, 'earned': 100}], ['sample 1', {'term': 24, 'paid': 3, 'finance_charge': 120000, 'acq_fee': 0, 'payment': 10000, 'min_rebate': 2000}, {'rebate': 92400, 'payoff': 117600, 'earned': 27600}], ['sample 2', {'term': 12, 'paid': 3, 'finance_charge': 50000, 'acq_fee': 0, 'payment': 4321, 'min_rebate': 2000}, {'rebate': 28846, 'payoff': 10043, 'earned': 21154}], ['sample 3', {'term': 6, 'paid': 3, 'finance_charge': 7777, 'acq_fee': 7500, 'payment': 4321, 'min_rebate': 0}, {'rebate': 79, 'payoff': 12884, 'earned': 7698}], ['sample 4', {'term': 6, 'paid': 5, 'finance_charge': 120000, 'acq_fee': 0, 'payment': 10000, 'min_rebate': 0}, {'rebate': 5714, 'payoff': 4286, 'earned': 114286}], ['sample 5', {'term': 12, 'paid': 12, 'finance_charge': 7777, 'acq_fee': 7500, 'payment': 10000, 'min_rebate': 2000}, {'rebate': 0, 'payoff': 0, 'earned': 7777}], ['sample 6', {'term': 24, 'paid': 0, 'finance_charge': 7777, 'acq_fee': 2500, 'payment': 10000, 'min_rebate': 0}, {'rebate': 5277, 'payoff': 234723, 'earned': 2500}]], [['regression: remaining installment count', {'term': 36, 'paid': 0, 'finance_charge': 100, 'acq_fee': 7500, 'payment': 25000, 'min_rebate': 500}, {'rebate': 0, 'payoff': 900000, 'earned': 100}], ['sample 1', {'term': 12, 'paid': 12, 'finance_charge': 50000, 'acq_fee': 2500, 'payment': 10000, 'min_rebate': 0}, {'rebate': 0, 'payoff': 0, 'earned': 50000}], ['sample 2', {'term': 12, 'paid': 0, 'finance_charge': 7777, 'acq_fee': 0, 'payment': 4321, 'min_rebate': 2000}, {'rebate': 7777, 'payoff': 44075, 'earned': 0}], ['sample 3', {'term': 36, 'paid': 0, 'finance_charge': 100, 'acq_fee': 0, 'payment': 10000, 'min_rebate': 0}, {'rebate': 100, 'payoff': 359900, 'earned': 0}], ['sample 4', {'term': 6, 'paid': 3, 'finance_charge': 100, 'acq_fee': 0, 'payment': 25000, 'min_rebate': 2000}, {'rebate': 0, 'payoff': 75000, 'earned': 100}], ['sample 5', {'term': 24, 'paid': 12, 'finance_charge': 120000, 'acq_fee': 2500, 'payment': 4321, 'min_rebate': 100}, {'rebate': 30550, 'payoff': 21302, 'earned': 89450}], ['sample 6', {'term': 36, 'paid': 18, 'finance_charge': 50000, 'acq_fee': 0, 'payment': 4321, 'min_rebate': 0}, {'rebate': 12838, 'payoff': 64940, 'earned': 37162}]], [['regression: remaining installment count', {'term': 24, 'paid': 12, 'finance_charge': 120000, 'acq_fee': 7500, 'payment': 25000, 'min_rebate': 500}, {'rebate': 29250, 'payoff': 270750, 'earned': 90750}], ['sample 1', {'term': 24, 'paid': 12, 'finance_charge': 100, 'acq_fee': 0, 'payment': 4321, 'min_rebate': 500}, {'rebate': 0, 'payoff': 51852, 'earned': 100}], ['sample 2', {'term': 36, 'paid': 0, 'finance_charge': 7777, 'acq_fee': 7500, 'payment': 25000, 'min_rebate': 2000}, {'rebate': 0, 'payoff': 900000, 'earned': 7777}], ['sample 3', {'term': 6, 'paid': 5, 'finance_charge': 120000, 'acq_fee': 2500, 'payment': 10000, 'min_rebate': 100}, {'rebate': 5595, 'payoff': 4405, 'earned': 114405}], ['sample 4', {'term': 36, 'paid': 18, 'finance_charge': 7777, 'acq_fee': 2500, 'payment': 10000, 'min_rebate': 100}, {'rebate': 1355, 'payoff': 178645, 'earned': 6422}], ['sample 5', {'term': 36, 'paid': 36, 'finance_charge': 100, 'acq_fee': 7500, 'payment': 4321, 'min_rebate': 0}, {'rebate': 0, 'payoff': 0, 'earned': 100}], ['sample 6', {'term': 12, 'paid': 0, 'finance_charge': 100, 'acq_fee': 0, 'payment': 25000, 'min_rebate': 500}, {'rebate': 0, 'payoff': 300000, 'earned': 100}]]]
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)

prompt:
Payoff quotes omit one remaining installment and its rebate.

x = {'term' n, 'paid' k, 'finance_charge', 'acq_fee' (fully earned up front), 'payment', 'min_rebate'}. Rebatable charge = finance_charge - acq_fee; remaining r = n - k; rebate = round_half_up(rebatable * r(r+1) / (n(n+1))), set to 0 when below min_rebate. Payoff = payment*r - rebate; earned = finance_charge - rebate. Return {'rebate', 'payoff', 'earned'}.

split: open-access


broken_source:
"""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)
    n = x['term']
    k = x['paid']
    fc = x['finance_charge'] - x['acq_fee']
    rem = n - k
    rebate = rnd(fc * rem * (rem + 1), n * (n + 1))
    if rebate < x['min_rebate']:
        rebate = 0
    remaining = x['payment'] * rem
    return {'rebate': rebate, 'payoff': remaining - rebate, 'earned': fc - rebate}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: earned charge', {'term': 36, 'paid': 35, 'finance_charge': 50000, 'acq_fee': 7500, 'payment': 25000, 'min_rebate': 100}, {'rebate': 0, 'payoff': 25000, 'earned': 50000}], ['control 1', {'term': 36, 'paid': 35, 'finance_charge': 120000, 'acq_fee': 0, 'payment': 10000, 'min_rebate': 100}, {'rebate': 180, 'payoff': 9820, 'earned': 119820}], ['control 2', {'term': 24, 'paid': 23, 'finance_charge': 100, 'acq_fee': 0, 'payment': 25000, 'min_rebate': 100}, {'rebate': 0, 'payoff': 25000, 'earned': 100}], ['control 3', {'term': 24, 'paid': 12, 'finance_charge': 50000, 'acq_fee': 0, 'payment': 25000, 'min_rebate': 100}, {'rebate': 13000, 'payoff': 287000, 'earned': 37000}], ['control 4', {'term': 12, 'paid': 3, 'finance_charge': 100, 'acq_fee': 0, 'payment': 4321, 'min_rebate': 100}, {'rebate': 0, 'payoff': 38889, 'earned': 100}], ['control 5', {'term': 6, 'paid': 3, 'finance_charge': 7777, 'acq_fee': 0, 'payment': 10000, 'min_rebate': 500}, {'rebate': 2222, 'payoff': 27778, 'earned': 5555}], ['control 6', {'term': 24, 'paid': 1, 'finance_charge': 120000, 'acq_fee': 0, 'payment': 4321, 'min_rebate': 100}, {'rebate': 110400, 'payoff': -11017, 'earned': 9600}]], [['regression: earned charge', {'term': 36, 'paid': 3, 'finance_charge': 7777, 'acq_fee': 2500, 'payment': 10000, 'min_rebate': 500}, {'rebate': 4445, 'payoff': 325555, 'earned': 3332}], ['control 1', {'term': 24, 'paid': 1, 'finance_charge': 120000, 'acq_fee': 0, 'payment': 25000, 'min_rebate': 500}, {'rebate': 110400, 'payoff': 464600, 'earned': 9600}], ['control 2', {'term': 12, 'paid': 1, 'finance_charge': 100, 'acq_fee': 0, 'payment': 10000, 'min_rebate': 100}, {'rebate': 0, 'payoff': 110000, 'earned': 100}], ['control 3', {'term': 24, 'paid': 24, 'finance_charge': 120000, 'acq_fee': 0, 'payment': 10000, 'min_rebate': 100}, {'rebate': 0, 'payoff': 0, 'earned': 120000}], ['control 4', {'term': 6, 'paid': 0, 'finance_charge': 7777, 'acq_fee': 0, 'payment': 10000, 'min_rebate': 500}, {'rebate': 7777, 'payoff': 52223, 'earned': 0}], ['control 5', {'term': 36, 'paid': 35, 'finance_charge': 120000, 'acq_fee': 0, 'payment': 25000, 'min_rebate': 100}, {'rebate': 180, 'payoff': 24820, 'earned': 119820}], ['control 6', {'term': 24, 'paid': 23, 'finance_charge': 120000, 'acq_fee': 0, 'payment': 4321, 'min_rebate': 500}, {'rebate': 0, 'payoff': 4321, 'earned': 120000}]], [['regression: earned charge', {'term': 6, 'paid': 3, 'finance_charge': 7777, 'acq_fee': 7500, 'payment': 4321, 'min_rebate': 0}, {'rebate': 79, 'payoff': 12884, 'earned': 7698}], ['control 1', {'term': 6, 'paid': 5, 'finance_charge': 100, 'acq_fee': 0, 'payment': 25000, 'min_rebate': 2000}, {'rebate': 0, 'payoff': 25000, 'earned': 100}], ['control 2', {'term': 24, 'paid': 3, 'finance_charge': 120000, 'acq_fee': 0, 'payment': 10000, 'min_rebate': 2000}, {'rebate': 92400, 'payoff': 117600, 'earned': 27600}], ['control 3', {'term': 12, 'paid': 3, 'finance_charge': 50000, 'acq_fee': 0, 'payment': 4321, 'min_rebate': 2000}, {'rebate': 28846, 'payoff': 10043, 'earned': 21154}], ['control 4', {'term': 6, 'paid': 5, 'finance_charge': 120000, 'acq_fee': 0, 'payment': 10000, 'min_rebate': 0}, {'rebate': 5714, 'payoff': 4286, 'earned': 114286}], ['control 5', {'term': 12, 'paid': 0, 'finance_charge': 100, 'acq_fee': 0, 'payment': 10000, 'min_rebate': 100}, {'rebate': 100, 'payoff': 119900, 'earned': 0}], ['control 6', {'term': 12, 'paid': 12, 'finance_charge': 100, 'acq_fee': 0, 'payment': 10000, 'min_rebate': 2000}, {'rebate': 0, 'payoff': 0, 'earned': 100}]], [['regression: earned charge', {'term': 36, 'paid': 0, 'finance_charge': 100, 'acq_fee': 7500, 'payment': 25000, 'min_rebate': 500}, {'rebate': 0, 'payoff': 900000, 'earned': 100}], ['control 1', {'term': 12, 'paid': 0, 'finance_charge': 7777, 'acq_fee': 0, 'payment': 4321, 'min_rebate': 2000}, {'rebate': 7777, 'payoff': 44075, 'earned': 0}], ['control 2', {'term': 36, 'paid': 0, 'finance_charge': 100, 'acq_fee': 0, 'payment': 10000, 'min_rebate': 0}, {'rebate': 100, 'payoff': 359900, 'earned': 0}], ['control 3', {'term': 6, 'paid': 3, 'finance_charge': 100, 'acq_fee': 0, 'payment': 25000, 'min_rebate': 2000}, {'rebate': 0, 'payoff': 75000, 'earned': 100}], ['control 4', {'term': 36, 'paid': 18, 'finance_charge': 50000, 'acq_fee': 0, 'payment': 4321, 'min_rebate': 0}, {'rebate': 12838, 'payoff': 64940, 'earned': 37162}], ['control 5', {'term': 24, 'paid': 1, 'finance_charge': 7777, 'acq_fee': 0, 'payment': 10000, 'min_rebate': 100}, {'rebate': 7155, 'payoff': 222845, 'earned': 622}], ['control 6', {'term': 36, 'paid': 18, 'finance_charge': 100, 'acq_fee': 0, 'payment': 25000, 'min_rebate': 0}, {'rebate': 26, 'payoff': 449974, 'earned': 74}]], [['regression: earned charge', {'term': 24, 'paid': 12, 'finance_charge': 120000, 'acq_fee': 7500, 'payment': 25000, 'min_rebate': 500}, {'rebate': 29250, 'payoff': 270750, 'earned': 90750}], ['control 1', {'term': 24, 'paid': 12, 'finance_charge': 100, 'acq_fee': 0, 'payment': 4321, 'min_rebate': 500}, {'rebate': 0, 'payoff': 51852, 'earned': 100}], ['control 2', {'term': 12, 'paid': 0, 'finance_charge': 100, 'acq_fee': 0, 'payment': 25000, 'min_rebate': 500}, {'rebate': 0, 'payoff': 300000, 'earned': 100}], ['control 3', {'term': 12, 'paid': 12, 'finance_charge': 7777, 'acq_fee': 0, 'payment': 10000, 'min_rebate': 2000}, {'rebate': 0, 'payoff': 0, 'earned': 7777}], ['control 4', {'term': 24, 'paid': 0, 'finance_charge': 100, 'acq_fee': 0, 'payment': 4321, 'min_rebate': 0}, {'rebate': 100, 'payoff': 103604, 'earned': 0}], ['control 5', {'term': 36, 'paid': 0, 'finance_charge': 50000, 'acq_fee': 0, 'payment': 4321, 'min_rebate': 100}, {'rebate': 50000, 'payoff': 105556, 'earned': 0}], ['control 6', {'term': 24, 'paid': 23, 'finance_charge': 7777, 'acq_fee': 0, 'payment': 10000, 'min_rebate': 0}, {'rebate': 26, 'payoff': 9974, 'earned': 7751}]]]
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)

source:
"""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)
    n = x['term']
    k = x['paid']
    fc = x['finance_charge'] - x['acq_fee']
    rem = n - k
    rebate = rnd(fc * rem * (rem + 1), n * (n + 1))
    if rebate < x['min_rebate']:
        rebate = 0
    remaining = x['payment'] * rem
    return {'rebate': rebate, 'payoff': remaining - rebate, 'earned': rnd(fc * (n * (n + 1) - rem * (rem + 1)), n * (n + 1))}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: earned charge', {'term': 36, 'paid': 35, 'finance_charge': 50000, 'acq_fee': 7500, 'payment': 25000, 'min_rebate': 100}, {'rebate': 0, 'payoff': 25000, 'earned': 50000}], ['control 1', {'term': 36, 'paid': 35, 'finance_charge': 120000, 'acq_fee': 0, 'payment': 10000, 'min_rebate': 100}, {'rebate': 180, 'payoff': 9820, 'earned': 119820}], ['control 2', {'term': 24, 'paid': 23, 'finance_charge': 100, 'acq_fee': 0, 'payment': 25000, 'min_rebate': 100}, {'rebate': 0, 'payoff': 25000, 'earned': 100}], ['control 3', {'term': 24, 'paid': 12, 'finance_charge': 50000, 'acq_fee': 0, 'payment': 25000, 'min_rebate': 100}, {'rebate': 13000, 'payoff': 287000, 'earned': 37000}], ['control 4', {'term': 12, 'paid': 3, 'finance_charge': 100, 'acq_fee': 0, 'payment': 4321, 'min_rebate': 100}, {'rebate': 0, 'payoff': 38889, 'earned': 100}], ['control 5', {'term': 6, 'paid': 3, 'finance_charge': 7777, 'acq_fee': 0, 'payment': 10000, 'min_rebate': 500}, {'rebate': 2222, 'payoff': 27778, 'earned': 5555}], ['control 6', {'term': 24, 'paid': 1, 'finance_charge': 120000, 'acq_fee': 0, 'payment': 4321, 'min_rebate': 100}, {'rebate': 110400, 'payoff': -11017, 'earned': 9600}]], [['regression: earned charge', {'term': 36, 'paid': 3, 'finance_charge': 7777, 'acq_fee': 2500, 'payment': 10000, 'min_rebate': 500}, {'rebate': 4445, 'payoff': 325555, 'earned': 3332}], ['control 1', {'term': 24, 'paid': 1, 'finance_charge': 120000, 'acq_fee': 0, 'payment': 25000, 'min_rebate': 500}, {'rebate': 110400, 'payoff': 464600, 'earned': 9600}], ['control 2', {'term': 12, 'paid': 1, 'finance_charge': 100, 'acq_fee': 0, 'payment': 10000, 'min_rebate': 100}, {'rebate': 0, 'payoff': 110000, 'earned': 100}], ['control 3', {'term': 24, 'paid': 24, 'finance_charge': 120000, 'acq_fee': 0, 'payment': 10000, 'min_rebate': 100}, {'rebate': 0, 'payoff': 0, 'earned': 120000}], ['control 4', {'term': 6, 'paid': 0, 'finance_charge': 7777, 'acq_fee': 0, 'payment': 10000, 'min_rebate': 500}, {'rebate': 7777, 'payoff': 52223, 'earned': 0}], ['control 5', {'term': 36, 'paid': 35, 'finance_charge': 120000, 'acq_fee': 0, 'payment': 25000, 'min_rebate': 100}, {'rebate': 180, 'payoff': 24820, 'earned': 119820}], ['control 6', {'term': 24, 'paid': 23, 'finance_charge': 120000, 'acq_fee': 0, 'payment': 4321, 'min_rebate': 500}, {'rebate': 0, 'payoff': 4321, 'earned': 120000}]], [['regression: earned charge', {'term': 6, 'paid': 3, 'finance_charge': 7777, 'acq_fee': 7500, 'payment': 4321, 'min_rebate': 0}, {'rebate': 79, 'payoff': 12884, 'earned': 7698}], ['control 1', {'term': 6, 'paid': 5, 'finance_charge': 100, 'acq_fee': 0, 'payment': 25000, 'min_rebate': 2000}, {'rebate': 0, 'payoff': 25000, 'earned': 100}], ['control 2', {'term': 24, 'paid': 3, 'finance_charge': 120000, 'acq_fee': 0, 'payment': 10000, 'min_rebate': 2000}, {'rebate': 92400, 'payoff': 117600, 'earned': 27600}], ['control 3', {'term': 12, 'paid': 3, 'finance_charge': 50000, 'acq_fee': 0, 'payment': 4321, 'min_rebate': 2000}, {'rebate': 28846, 'payoff': 10043, 'earned': 21154}], ['control 4', {'term': 6, 'paid': 5, 'finance_charge': 120000, 'acq_fee': 0, 'payment': 10000, 'min_rebate': 0}, {'rebate': 5714, 'payoff': 4286, 'earned': 114286}], ['control 5', {'term': 12, 'paid': 0, 'finance_charge': 100, 'acq_fee': 0, 'payment': 10000, 'min_rebate': 100}, {'rebate': 100, 'payoff': 119900, 'earned': 0}], ['control 6', {'term': 12, 'paid': 12, 'finance_charge': 100, 'acq_fee': 0, 'payment': 10000, 'min_rebate': 2000}, {'rebate': 0, 'payoff': 0, 'earned': 100}]], [['regression: earned charge', {'term': 36, 'paid': 0, 'finance_charge': 100, 'acq_fee': 7500, 'payment': 25000, 'min_rebate': 500}, {'rebate': 0, 'payoff': 900000, 'earned': 100}], ['control 1', {'term': 12, 'paid': 0, 'finance_charge': 7777, 'acq_fee': 0, 'payment': 4321, 'min_rebate': 2000}, {'rebate': 7777, 'payoff': 44075, 'earned': 0}], ['control 2', {'term': 36, 'paid': 0, 'finance_charge': 100, 'acq_fee': 0, 'payment': 10000, 'min_rebate': 0}, {'rebate': 100, 'payoff': 359900, 'earned': 0}], ['control 3', {'term': 6, 'paid': 3, 'finance_charge': 100, 'acq_fee': 0, 'payment': 25000, 'min_rebate': 2000}, {'rebate': 0, 'payoff': 75000, 'earned': 100}], ['control 4', {'term': 36, 'paid': 18, 'finance_charge': 50000, 'acq_fee': 0, 'payment': 4321, 'min_rebate': 0}, {'rebate': 12838, 'payoff': 64940, 'earned': 37162}], ['control 5', {'term': 24, 'paid': 1, 'finance_charge': 7777, 'acq_fee': 0, 'payment': 10000, 'min_rebate': 100}, {'rebate': 7155, 'payoff': 222845, 'earned': 622}], ['control 6', {'term': 36, 'paid': 18, 'finance_charge': 100, 'acq_fee': 0, 'payment': 25000, 'min_rebate': 0}, {'rebate': 26, 'payoff': 449974, 'earned': 74}]], [['regression: earned charge', {'term': 24, 'paid': 12, 'finance_charge': 120000, 'acq_fee': 7500, 'payment': 25000, 'min_rebate': 500}, {'rebate': 29250, 'payoff': 270750, 'earned': 90750}], ['control 1', {'term': 24, 'paid': 12, 'finance_charge': 100, 'acq_fee': 0, 'payment': 4321, 'min_rebate': 500}, {'rebate': 0, 'payoff': 51852, 'earned': 100}], ['control 2', {'term': 12, 'paid': 0, 'finance_charge': 100, 'acq_fee': 0, 'payment': 25000, 'min_rebate': 500}, {'rebate': 0, 'payoff': 300000, 'earned': 100}], ['control 3', {'term': 12, 'paid': 12, 'finance_charge': 7777, 'acq_fee': 0, 'payment': 10000, 'min_rebate': 2000}, {'rebate': 0, 'payoff': 0, 'earned': 7777}], ['control 4', {'term': 24, 'paid': 0, 'finance_charge': 100, 'acq_fee': 0, 'payment': 4321, 'min_rebate': 0}, {'rebate': 100, 'payoff': 103604, 'earned': 0}], ['control 5', {'term': 36, 'paid': 0, 'finance_charge': 50000, 'acq_fee': 0, 'payment': 4321, 'min_rebate': 100}, {'rebate': 50000, 'payoff': 105556, 'earned': 0}], ['control 6', {'term': 24, 'paid': 23, 'finance_charge': 7777, 'acq_fee': 0, 'payment': 10000, 'min_rebate': 0}, {'rebate': 26, 'payoff': 9974, 'earned': 7751}]]]
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)

prompt:
Earned finance charge omits the acquisition fee.

x = {'term' n, 'paid' k, 'finance_charge', 'acq_fee' (fully earned up front), 'payment', 'min_rebate'}. Rebatable charge = finance_charge - acq_fee; remaining r = n - k; rebate = round_half_up(rebatable * r(r+1) / (n(n+1))), set to 0 when below min_rebate. Payoff = payment*r - rebate; earned = finance_charge - rebate. Return {'rebate', 'payoff', 'earned'}.

split: open-access


broken_source:
"""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)
    per_diem = rnd(x['balance'] * x['rate_bp'], 10000 * x['basis'])
    days = x['payoff_day'] - x['last_paid_day']
    interest = rnd(x['balance'] * x['rate_bp'] * days, 10000 * x['basis'])
    penalty = rnd(x['balance'] * x['penalty_bp'], 10000) if x['payoff_day'] <= x['penalty_until'] else 0
    payoff = x['balance'] + interest + x['fees_due'] + penalty - x['escrow']
    return {'per_diem': per_diem, 'interest': interest, 'penalty': penalty, 'payoff': payoff}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: per diem rounding stage', {'balance': 100000, 'rate_bp': 600, 'last_paid_day': 100, 'payoff_day': 145, 'basis': 360, 'fees_due': 3500, 'escrow': -4000, 'penalty_bp': 0, 'penalty_until': 115}, {'per_diem': 17, 'interest': 765, 'penalty': 0, 'payoff': 108265}], ['control 1', {'balance': 999999, 'rate_bp': 600, 'last_paid_day': 10, 'payoff_day': 11, 'basis': 365, 'fees_due': 0, 'escrow': 0, 'penalty_bp': 100, 'penalty_until': 10}, {'per_diem': 164, 'interest': 164, 'penalty': 0, 'payoff': 1000163}], ['control 2', {'balance': 12345678, 'rate_bp': 600, 'last_paid_day': 100, 'payoff_day': 101, 'basis': 365, 'fees_due': 3500, 'escrow': 0, 'penalty_bp': 200, 'penalty_until': 160}, {'per_diem': 2029, 'interest': 2029, 'penalty': 246914, 'payoff': 12598121}], ['control 3', {'balance': 999999, 'rate_bp': 1250, 'last_paid_day': 10, 'payoff_day': 11, 'basis': 360, 'fees_due': 3500, 'escrow': 12000, 'penalty_bp': 200, 'penalty_until': 70}, {'per_diem': 347, 'interest': 347, 'penalty': 20000, 'payoff': 1011846}], ['control 4', {'balance': 12345678, 'rate_bp': 600, 'last_paid_day': 100, 'payoff_day': 101, 'basis': 360, 'fees_due': 0, 'escrow': 12000, 'penalty_bp': 200, 'penalty_until': 130}, {'per_diem': 2058, 'interest': 2058, 'penalty': 246914, 'payoff': 12582650}], ['control 5', {'balance': 100000, 'rate_bp': 450, 'last_paid_day': 100, 'payoff_day': 101, 'basis': 365, 'fees_due': 3500, 'escrow': 0, 'penalty_bp': 0, 'penalty_until': 115}, {'per_diem': 12, 'interest': 12, 'penalty': 0, 'payoff': 103512}], ['control 6', {'balance': 12345678, 'rate_bp': 600, 'last_paid_day': 100, 'payoff_day': 101, 'basis': 360, 'fees_due': 3500, 'escrow': 0, 'penalty_bp': 200, 'penalty_until': 115}, {'per_diem': 2058, 'interest': 2058, 'penalty': 246914, 'payoff': 12598150}]], [['regression: per diem rounding stage', {'balance': 999999, 'rate_bp': 1250, 'last_paid_day': 1, 'payoff_day': 46, 'basis': 365, 'fees_due': 3500, 'escrow': -4000, 'penalty_bp': 100, 'penalty_until': 1}, {'per_diem': 342, 'interest': 15390, 'penalty': 0, 'payoff': 1022889}], ['regression: per diem rounding stage, partial-repair probe', {'balance': 100000, 'rate_bp': 450, 'last_paid_day': 1, 'payoff_day': 2, 'basis': 360, 'fees_due': 3500, 'escrow': 0, 'penalty_bp': 200, 'penalty_until': 61}, {'per_diem': 13, 'interest': 13, 'penalty': 2000, 'payoff': 105513}], ['control 1', {'balance': 999999, 'rate_bp': 450, 'last_paid_day': 1, 'payoff_day': 31, 'basis': 360, 'fees_due': 3500, 'escrow': 0, 'penalty_bp': 0, 'penalty_until': 61}, {'per_diem': 125, 'interest': 3750, 'penalty': 0, 'payoff': 1007249}], ['control 2', {'balance': 12345678, 'rate_bp': 1250, 'last_paid_day': 10, 'payoff_day': 11, 'basis': 365, 'fees_due': 0, 'escrow': 12000, 'penalty_bp': 0, 'penalty_until': 40}, {'per_diem': 4228, 'interest': 4228, 'penalty': 0, 'payoff': 12337906}], ['control 3', {'balance': 100000, 'rate_bp': 450, 'last_paid_day': 100, 'payoff_day': 101, 'basis': 365, 'fees_due': 0, 'escrow': 12000, 'penalty_bp': 200, 'penalty_until': 130}, {'per_diem': 12, 'interest': 12, 'penalty': 2000, 'payoff': 90012}], ['control 4', {'balance': 12345678, 'rate_bp': 450, 'last_paid_day': 10, 'payoff_day': 11, 'basis': 365, 'fees_due': 0, 'escrow': -4000, 'penalty_bp': 200, 'penalty_until': 40}, {'per_diem': 1522, 'interest': 1522, 'penalty': 246914, 'payoff': 12598114}], ['control 5', {'balance': 999999, 'rate_bp': 1250, 'last_paid_day': 100, 'payoff_day': 101, 'basis': 365, 'fees_due': 0, 'escrow': 0, 'penalty_bp': 100, 'penalty_until': 100}, {'per_diem': 342, 'interest': 342, 'penalty': 0, 'payoff': 1000341}]], [['regression: per diem rounding stage', {'balance': 5000, 'rate_bp': 450, 'last_paid_day': 10, 'payoff_day': 55, 'basis': 365, 'fees_due': 0, 'escrow': -4000, 'penalty_bp': 0, 'penalty_until': 40}, {'per_diem': 1, 'interest': 45, 'penalty': 0, 'payoff': 9045}], ['control 1', {'balance': 100000, 'rate_bp': 1250, 'last_paid_day': 1, 'payoff_day': 2, 'basis': 365, 'fees_due': 3500, 'escrow': 12000, 'penalty_bp': 100, 'penalty_until': 1}, {'per_diem': 34, 'interest': 34, 'penalty': 0, 'payoff': 91534}], ['control 2', {'balance': 12345678, 'rate_bp': 1250, 'last_paid_day': 100, 'payoff_day': 101, 'basis': 360, 'fees_due': 0, 'escrow': 12000, 'penalty_bp': 0, 'penalty_until': 100}, {'per_diem': 4287, 'interest': 4287, 'penalty': 0, 'payoff': 12337965}], ['control 3', {'balance': 999999, 'rate_bp': 450, 'last_paid_day': 10, 'payoff_day': 40, 'basis': 360, 'fees_due': 3500, 'escrow': 12000, 'penalty_bp': 100, 'penalty_until': 10}, {'per_diem': 125, 'interest': 3750, 'penalty': 0, 'payoff': 995249}], ['control 4', {'balance': 100000, 'rate_bp': 600, 'last_paid_day': 10, 'payoff_day': 11, 'basis': 360, 'fees_due': 0, 'escrow': -4000, 'penalty_bp': 100, 'penalty_until': 10}, {'per_diem': 17, 'interest': 17, 'penalty': 0, 'payoff': 104017}], ['control 5', {'balance': 12345678, 'rate_bp': 600, 'last_paid_day': 100, 'payoff_day': 101, 'basis': 360, 'fees_due': 3500, 'escrow': -4000, 'penalty_bp': 0, 'penalty_until': 160}, {'per_diem': 2058, 'interest': 2058, 'penalty': 0, 'payoff': 12355236}], ['control 6', {'balance': 12345678, 'rate_bp': 1250, 'last_paid_day': 100, 'payoff_day': 101, 'basis': 360, 'fees_due': 0, 'escrow': 0, 'penalty_bp': 200, 'penalty_until': 100}, {'per_diem': 4287, 'interest': 4287, 'penalty': 0, 'payoff': 12349965}]], [['regression: per diem rounding stage', {'balance': 5000, 'rate_bp': 600, 'last_paid_day': 10, 'payoff_day': 40, 'basis': 365, 'fees_due': 3500, 'escrow': 0, 'penalty_bp': 200, 'penalty_until': 70}, {'per_diem': 1, 'interest': 30, 'penalty': 100, 'payoff': 8630}], ['control 1', {'balance': 12345678, 'rate_bp': 1250, 'last_paid_day': 100, 'payoff_day': 115, 'basis': 365, 'fees_due': 3500, 'escrow': 0, 'penalty_bp': 200, 'penalty_until': 100}, {'per_diem': 4228, 'interest': 63420, 'penalty': 0, 'payoff': 12412598}], ['control 2', {'balance': 100000, 'rate_bp': 450, 'last_paid_day': 100, 'payoff_day': 101, 'basis': 365, 'fees_due': 3500, 'escrow': 0, 'penalty_bp': 200, 'penalty_until': 130}, {'per_diem': 12, 'interest': 12, 'penalty': 2000, 'payoff': 105512}], ['control 3', {'balance': 999999, 'rate_bp': 450, 'last_paid_day': 1, 'payoff_day': 2, 'basis': 365, 'fees_due': 0, 'escrow': 0, 'penalty_bp': 100, 'penalty_until': 61}, {'per_diem': 123, 'interest': 123, 'penalty': 10000, 'payoff': 1010122}], ['control 4', {'balance': 100000, 'rate_bp': 1250, 'last_paid_day': 10, 'payoff_day': 11, 'basis': 360, 'fees_due': 0, 'escrow': 12000, 'penalty_bp': 200, 'penalty_until': 70}, {'per_diem': 35, 'interest': 35, 'penalty': 2000, 'payoff': 90035}], ['control 5', {'balance': 5000, 'rate_bp': 450, 'last_paid_day': 100, 'payoff_day': 101, 'basis': 365, 'fees_due': 0, 'escrow': 12000, 'penalty_bp': 100, 'penalty_until': 100}, {'per_diem': 1, 'interest': 1, 'penalty': 0, 'payoff': -6999}], ['control 6', {'balance': 100000, 'rate_bp': 1250, 'last_paid_day': 1, 'payoff_day': 2, 'basis': 360, 'fees_due': 3500, 'escrow': 12000, 'penalty_bp': 0, 'penalty_until': 16}, {'per_diem': 35, 'interest': 35, 'penalty': 0, 'payoff': 91535}]], [['regression: per diem rounding stage', {'balance': 999999, 'rate_bp': 1250, 'last_paid_day': 100, 'payoff_day': 131, 'basis': 360, 'fees_due': 3500, 'escrow': 0, 'penalty_bp': 100, 'penalty_until': 115}, {'per_diem': 347, 'interest': 10757, 'penalty': 0, 'payoff': 1014256}], ['regression: per diem rounding stage, partial-repair probe', {'balance': 999999, 'rate_bp': 600, 'last_paid_day': 10, 'payoff_day': 40, 'basis': 360, 'fees_due': 0, 'escrow': 0, 'penalty_bp': 0, 'penalty_until': 70}, {'per_diem': 167, 'interest': 5010, 'penalty': 0, 'payoff': 1005009}], ['control 1', {'balance': 12345678, 'rate_bp': 450, 'last_paid_day': 100, 'payoff_day': 101, 'basis': 365, 'fees_due': 3500, 'escrow': -4000, 'penalty_bp': 100, 'penalty_until': 130}, {'per_diem': 1522, 'interest': 1522, 'penalty': 123457, 'payoff': 12478157}], ['control 2', {'balance': 999999, 'rate_bp': 450, 'last_paid_day': 1, 'payoff_day': 31, 'basis': 360, 'fees_due': 0, 'escrow': -4000, 'penalty_bp': 200, 'penalty_until': 16}, {'per_diem': 125, 'interest': 3750, 'penalty': 0, 'payoff': 1007749}], ['control 3', {'balance': 999999, 'rate_bp': 450, 'last_paid_day': 10, 'payoff_day': 11, 'basis': 365, 'fees_due': 3500, 'escrow': 12000, 'penalty_bp': 0, 'penalty_until': 25}, {'per_diem': 123, 'interest': 123, 'penalty': 0, 'payoff': 991622}], ['control 4', {'balance': 100000, 'rate_bp': 1250, 'last_paid_day': 1, 'payoff_day': 2, 'basis': 365, 'fees_due': 0, 'escrow': -4000, 'penalty_bp': 0, 'penalty_until': 16}, {'per_diem': 34, 'interest': 34, 'penalty': 0, 'payoff': 104034}], ['control 5', {'balance': 999999, 'rate_bp': 450, 'last_paid_day': 1, 'payoff_day': 2, 'basis': 365, 'fees_due': 3500, 'escrow': -4000, 'penalty_bp': 0, 'penalty_until': 61}, {'per_diem': 123, 'interest': 123, 'penalty': 0, 'payoff': 1007622}]]]
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)

source:
"""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)
    per_diem = x['balance'] * x['rate_bp'] // (10000 * x['basis'])
    days = x['payoff_day'] - x['last_paid_day']
    interest = per_diem * days
    penalty = rnd(x['balance'] * x['penalty_bp'], 10000) if x['payoff_day'] <= x['penalty_until'] else 0
    payoff = x['balance'] + interest + x['fees_due'] + penalty - x['escrow']
    return {'per_diem': per_diem, 'interest': interest, 'penalty': penalty, 'payoff': payoff}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: per diem rounding stage', {'balance': 100000, 'rate_bp': 600, 'last_paid_day': 100, 'payoff_day': 145, 'basis': 360, 'fees_due': 3500, 'escrow': -4000, 'penalty_bp': 0, 'penalty_until': 115}, {'per_diem': 17, 'interest': 765, 'penalty': 0, 'payoff': 108265}], ['control 1', {'balance': 999999, 'rate_bp': 600, 'last_paid_day': 10, 'payoff_day': 11, 'basis': 365, 'fees_due': 0, 'escrow': 0, 'penalty_bp': 100, 'penalty_until': 10}, {'per_diem': 164, 'interest': 164, 'penalty': 0, 'payoff': 1000163}], ['control 2', {'balance': 12345678, 'rate_bp': 600, 'last_paid_day': 100, 'payoff_day': 101, 'basis': 365, 'fees_due': 3500, 'escrow': 0, 'penalty_bp': 200, 'penalty_until': 160}, {'per_diem': 2029, 'interest': 2029, 'penalty': 246914, 'payoff': 12598121}], ['control 3', {'balance': 999999, 'rate_bp': 1250, 'last_paid_day': 10, 'payoff_day': 11, 'basis': 360, 'fees_due': 3500, 'escrow': 12000, 'penalty_bp': 200, 'penalty_until': 70}, {'per_diem': 347, 'interest': 347, 'penalty': 20000, 'payoff': 1011846}], ['control 4', {'balance': 12345678, 'rate_bp': 600, 'last_paid_day': 100, 'payoff_day': 101, 'basis': 360, 'fees_due': 0, 'escrow': 12000, 'penalty_bp': 200, 'penalty_until': 130}, {'per_diem': 2058, 'interest': 2058, 'penalty': 246914, 'payoff': 12582650}], ['control 5', {'balance': 100000, 'rate_bp': 450, 'last_paid_day': 100, 'payoff_day': 101, 'basis': 365, 'fees_due': 3500, 'escrow': 0, 'penalty_bp': 0, 'penalty_until': 115}, {'per_diem': 12, 'interest': 12, 'penalty': 0, 'payoff': 103512}], ['control 6', {'balance': 12345678, 'rate_bp': 600, 'last_paid_day': 100, 'payoff_day': 101, 'basis': 360, 'fees_due': 3500, 'escrow': 0, 'penalty_bp': 200, 'penalty_until': 115}, {'per_diem': 2058, 'interest': 2058, 'penalty': 246914, 'payoff': 12598150}]], [['regression: per diem rounding stage', {'balance': 999999, 'rate_bp': 1250, 'last_paid_day': 1, 'payoff_day': 46, 'basis': 365, 'fees_due': 3500, 'escrow': -4000, 'penalty_bp': 100, 'penalty_until': 1}, {'per_diem': 342, 'interest': 15390, 'penalty': 0, 'payoff': 1022889}], ['regression: per diem rounding stage, partial-repair probe', {'balance': 100000, 'rate_bp': 450, 'last_paid_day': 1, 'payoff_day': 2, 'basis': 360, 'fees_due': 3500, 'escrow': 0, 'penalty_bp': 200, 'penalty_until': 61}, {'per_diem': 13, 'interest': 13, 'penalty': 2000, 'payoff': 105513}], ['control 1', {'balance': 999999, 'rate_bp': 450, 'last_paid_day': 1, 'payoff_day': 31, 'basis': 360, 'fees_due': 3500, 'escrow': 0, 'penalty_bp': 0, 'penalty_until': 61}, {'per_diem': 125, 'interest': 3750, 'penalty': 0, 'payoff': 1007249}], ['control 2', {'balance': 12345678, 'rate_bp': 1250, 'last_paid_day': 10, 'payoff_day': 11, 'basis': 365, 'fees_due': 0, 'escrow': 12000, 'penalty_bp': 0, 'penalty_until': 40}, {'per_diem': 4228, 'interest': 4228, 'penalty': 0, 'payoff': 12337906}], ['control 3', {'balance': 100000, 'rate_bp': 450, 'last_paid_day': 100, 'payoff_day': 101, 'basis': 365, 'fees_due': 0, 'escrow': 12000, 'penalty_bp': 200, 'penalty_until': 130}, {'per_diem': 12, 'interest': 12, 'penalty': 2000, 'payoff': 90012}], ['control 4', {'balance': 12345678, 'rate_bp': 450, 'last_paid_day': 10, 'payoff_day': 11, 'basis': 365, 'fees_due': 0, 'escrow': -4000, 'penalty_bp': 200, 'penalty_until': 40}, {'per_diem': 1522, 'interest': 1522, 'penalty': 246914, 'payoff': 12598114}], ['control 5', {'balance': 999999, 'rate_bp': 1250, 'last_paid_day': 100, 'payoff_day': 101, 'basis': 365, 'fees_due': 0, 'escrow': 0, 'penalty_bp': 100, 'penalty_until': 100}, {'per_diem': 342, 'interest': 342, 'penalty': 0, 'payoff': 1000341}]], [['regression: per diem rounding stage', {'balance': 5000, 'rate_bp': 450, 'last_paid_day': 10, 'payoff_day': 55, 'basis': 365, 'fees_due': 0, 'escrow': -4000, 'penalty_bp': 0, 'penalty_until': 40}, {'per_diem': 1, 'interest': 45, 'penalty': 0, 'payoff': 9045}], ['control 1', {'balance': 100000, 'rate_bp': 1250, 'last_paid_day': 1, 'payoff_day': 2, 'basis': 365, 'fees_due': 3500, 'escrow': 12000, 'penalty_bp': 100, 'penalty_until': 1}, {'per_diem': 34, 'interest': 34, 'penalty': 0, 'payoff': 91534}], ['control 2', {'balance': 12345678, 'rate_bp': 1250, 'last_paid_day': 100, 'payoff_day': 101, 'basis': 360, 'fees_due': 0, 'escrow': 12000, 'penalty_bp': 0, 'penalty_until': 100}, {'per_diem': 4287, 'interest': 4287, 'penalty': 0, 'payoff': 12337965}], ['control 3', {'balance': 999999, 'rate_bp': 450, 'last_paid_day': 10, 'payoff_day': 40, 'basis': 360, 'fees_due': 3500, 'escrow': 12000, 'penalty_bp': 100, 'penalty_until': 10}, {'per_diem': 125, 'interest': 3750, 'penalty': 0, 'payoff': 995249}], ['control 4', {'balance': 100000, 'rate_bp': 600, 'last_paid_day': 10, 'payoff_day': 11, 'basis': 360, 'fees_due': 0, 'escrow': -4000, 'penalty_bp': 100, 'penalty_until': 10}, {'per_diem': 17, 'interest': 17, 'penalty': 0, 'payoff': 104017}], ['control 5', {'balance': 12345678, 'rate_bp': 600, 'last_paid_day': 100, 'payoff_day': 101, 'basis': 360, 'fees_due': 3500, 'escrow': -4000, 'penalty_bp': 0, 'penalty_until': 160}, {'per_diem': 2058, 'interest': 2058, 'penalty': 0, 'payoff': 12355236}], ['control 6', {'balance': 12345678, 'rate_bp': 1250, 'last_paid_day': 100, 'payoff_day': 101, 'basis': 360, 'fees_due': 0, 'escrow': 0, 'penalty_bp': 200, 'penalty_until': 100}, {'per_diem': 4287, 'interest': 4287, 'penalty': 0, 'payoff': 12349965}]], [['regression: per diem rounding stage', {'balance': 5000, 'rate_bp': 600, 'last_paid_day': 10, 'payoff_day': 40, 'basis': 365, 'fees_due': 3500, 'escrow': 0, 'penalty_bp': 200, 'penalty_until': 70}, {'per_diem': 1, 'interest': 30, 'penalty': 100, 'payoff': 8630}], ['control 1', {'balance': 12345678, 'rate_bp': 1250, 'last_paid_day': 100, 'payoff_day': 115, 'basis': 365, 'fees_due': 3500, 'escrow': 0, 'penalty_bp': 200, 'penalty_until': 100}, {'per_diem': 4228, 'interest': 63420, 'penalty': 0, 'payoff': 12412598}], ['control 2', {'balance': 100000, 'rate_bp': 450, 'last_paid_day': 100, 'payoff_day': 101, 'basis': 365, 'fees_due': 3500, 'escrow': 0, 'penalty_bp': 200, 'penalty_until': 130}, {'per_diem': 12, 'interest': 12, 'penalty': 2000, 'payoff': 105512}], ['control 3', {'balance': 999999, 'rate_bp': 450, 'last_paid_day': 1, 'payoff_day': 2, 'basis': 365, 'fees_due': 0, 'escrow': 0, 'penalty_bp': 100, 'penalty_until': 61}, {'per_diem': 123, 'interest': 123, 'penalty': 10000, 'payoff': 1010122}], ['control 4', {'balance': 100000, 'rate_bp': 1250, 'last_paid_day': 10, 'payoff_day': 11, 'basis': 360, 'fees_due': 0, 'escrow': 12000, 'penalty_bp': 200, 'penalty_until': 70}, {'per_diem': 35, 'interest': 35, 'penalty': 2000, 'payoff': 90035}], ['control 5', {'balance': 5000, 'rate_bp': 450, 'last_paid_day': 100, 'payoff_day': 101, 'basis': 365, 'fees_due': 0, 'escrow': 12000, 'penalty_bp': 100, 'penalty_until': 100}, {'per_diem': 1, 'interest': 1, 'penalty': 0, 'payoff': -6999}], ['control 6', {'balance': 100000, 'rate_bp': 1250, 'last_paid_day': 1, 'payoff_day': 2, 'basis': 360, 'fees_due': 3500, 'escrow': 12000, 'penalty_bp': 0, 'penalty_until': 16}, {'per_diem': 35, 'interest': 35, 'penalty': 0, 'payoff': 91535}]], [['regression: per diem rounding stage', {'balance': 999999, 'rate_bp': 1250, 'last_paid_day': 100, 'payoff_day': 131, 'basis': 360, 'fees_due': 3500, 'escrow': 0, 'penalty_bp': 100, 'penalty_until': 115}, {'per_diem': 347, 'interest': 10757, 'penalty': 0, 'payoff': 1014256}], ['regression: per diem rounding stage, partial-repair probe', {'balance': 999999, 'rate_bp': 600, 'last_paid_day': 10, 'payoff_day': 40, 'basis': 360, 'fees_due': 0, 'escrow': 0, 'penalty_bp': 0, 'penalty_until': 70}, {'per_diem': 167, 'interest': 5010, 'penalty': 0, 'payoff': 1005009}], ['control 1', {'balance': 12345678, 'rate_bp': 450, 'last_paid_day': 100, 'payoff_day': 101, 'basis': 365, 'fees_due': 3500, 'escrow': -4000, 'penalty_bp': 100, 'penalty_until': 130}, {'per_diem': 1522, 'interest': 1522, 'penalty': 123457, 'payoff': 12478157}], ['control 2', {'balance': 999999, 'rate_bp': 450, 'last_paid_day': 1, 'payoff_day': 31, 'basis': 360, 'fees_due': 0, 'escrow': -4000, 'penalty_bp': 200, 'penalty_until': 16}, {'per_diem': 125, 'interest': 3750, 'penalty': 0, 'payoff': 1007749}], ['control 3', {'balance': 999999, 'rate_bp': 450, 'last_paid_day': 10, 'payoff_day': 11, 'basis': 365, 'fees_due': 3500, 'escrow': 12000, 'penalty_bp': 0, 'penalty_until': 25}, {'per_diem': 123, 'interest': 123, 'penalty': 0, 'payoff': 991622}], ['control 4', {'balance': 100000, 'rate_bp': 1250, 'last_paid_day': 1, 'payoff_day': 2, 'basis': 365, 'fees_due': 0, 'escrow': -4000, 'penalty_bp': 0, 'penalty_until': 16}, {'per_diem': 34, 'interest': 34, 'penalty': 0, 'payoff': 104034}], ['control 5', {'balance': 999999, 'rate_bp': 450, 'last_paid_day': 1, 'payoff_day': 2, 'basis': 365, 'fees_due': 3500, 'escrow': -4000, 'penalty_bp': 0, 'penalty_until': 61}, {'per_diem': 123, 'interest': 123, 'penalty': 0, 'payoff': 1007622}]]]
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)

prompt:
Payoff interest does not equal the quoted per diem times the days.

x = {'balance', 'rate_bp', 'last_paid_day', 'payoff_day', 'basis', 'fees_due', 'escrow' (credit, may be negative), 'penalty_bp', 'penalty_until'}. Per diem = round_half_up(balance*bp/(10000*basis)); interest = per diem * (payoff_day - last_paid_day). Penalty = round_half_up(balance*penalty_bp/10000) when payoff_day <= penalty_until, else 0. Payoff = balance + interest + fees + penalty - escrow. Return {'per_diem', 'interest', 'penalty', 'payoff'}.

split: open-access


broken_source:
"""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)
    per_diem = rnd(x['balance'] * x['rate_bp'], 10000 * x['basis'])
    days = x['payoff_day'] - x['last_paid_day'] + 1
    interest = per_diem * days
    penalty = rnd(x['balance'] * x['penalty_bp'], 10000) if x['payoff_day'] <= x['penalty_until'] else 0
    payoff = x['balance'] + interest + x['fees_due'] + penalty - x['escrow']
    return {'per_diem': per_diem, 'interest': interest, 'penalty': penalty, 'payoff': payoff}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: interest day count', {'balance': 100000, 'rate_bp': 600, 'last_paid_day': 100, 'payoff_day': 145, 'basis': 360, 'fees_due': 3500, 'escrow': -4000, 'penalty_bp': 0, 'penalty_until': 115}, {'per_diem': 17, 'interest': 765, 'penalty': 0, 'payoff': 108265}], ['sample 1', {'balance': 999999, 'rate_bp': 600, 'last_paid_day': 10, 'payoff_day': 11, 'basis': 365, 'fees_due': 0, 'escrow': 0, 'penalty_bp': 100, 'penalty_until': 10}, {'per_diem': 164, 'interest': 164, 'penalty': 0, 'payoff': 1000163}], ['sample 2', {'balance': 100000, 'rate_bp': 1250, 'last_paid_day': 1, 'payoff_day': 16, 'basis': 360, 'fees_due': 3500, 'escrow': 12000, 'penalty_bp': 100, 'penalty_until': 31}, {'per_diem': 35, 'interest': 525, 'penalty': 1000, 'payoff': 93025}], ['sample 3', {'balance': 12345678, 'rate_bp': 600, 'last_paid_day': 10, 'payoff_day': 41, 'basis': 360, 'fees_due': 3500, 'escrow': 12000, 'penalty_bp': 200, 'penalty_until': 40}, {'per_diem': 2058, 'interest': 63798, 'penalty': 0, 'payoff': 12400976}], ['sample 4', {'balance': 12345678, 'rate_bp': 450, 'last_paid_day': 10, 'payoff_day': 55, 'basis': 360, 'fees_due': 0, 'escrow': 0, 'penalty_bp': 100, 'penalty_until': 25}, {'per_diem': 1543, 'interest': 69435, 'penalty': 0, 'payoff': 12415113}], ['sample 5', {'balance': 5000, 'rate_bp': 1250, 'last_paid_day': 10, 'payoff_day': 41, 'basis': 360, 'fees_due': 0, 'escrow': 12000, 'penalty_bp': 0, 'penalty_until': 25}, {'per_diem': 2, 'interest': 62, 'penalty': 0, 'payoff': -6938}], ['sample 6', {'balance': 100000, 'rate_bp': 600, 'last_paid_day': 1, 'payoff_day': 46, 'basis': 365, 'fees_due': 0, 'escrow': 12000, 'penalty_bp': 200, 'penalty_until': 1}, {'per_diem': 16, 'interest': 720, 'penalty': 0, 'payoff': 88720}]], [['regression: interest day count', {'balance': 999999, 'rate_bp': 1250, 'last_paid_day': 1, 'payoff_day': 46, 'basis': 365, 'fees_due': 3500, 'escrow': -4000, 'penalty_bp': 100, 'penalty_until': 1}, {'per_diem': 342, 'interest': 15390, 'penalty': 0, 'payoff': 1022889}], ['sample 1', {'balance': 100000, 'rate_bp': 450, 'last_paid_day': 1, 'payoff_day': 2, 'basis': 360, 'fees_due': 3500, 'escrow': 0, 'penalty_bp': 200, 'penalty_until': 61}, {'per_diem': 13, 'interest': 13, 'penalty': 2000, 'payoff': 105513}], ['sample 2', {'balance': 100000, 'rate_bp': 1250, 'last_paid_day': 10, 'payoff_day': 25, 'basis': 365, 'fees_due': 0, 'escrow': 0, 'penalty_bp': 100, 'penalty_until': 10}, {'per_diem': 34, 'interest': 510, 'penalty': 0, 'payoff': 100510}], ['sample 3', {'balance': 999999, 'rate_bp': 450, 'last_paid_day': 1, 'payoff_day': 31, 'basis': 360, 'fees_due': 3500, 'escrow': 0, 'penalty_bp': 0, 'penalty_until': 61}, {'per_diem': 125, 'interest': 3750, 'penalty': 0, 'payoff': 1007249}], ['sample 4', {'balance': 12345678, 'rate_bp': 1250, 'last_paid_day': 10, 'payoff_day': 11, 'basis': 365, 'fees_due': 0, 'escrow': 12000, 'penalty_bp': 0, 'penalty_until': 40}, {'per_diem': 4228, 'interest': 4228, 'penalty': 0, 'payoff': 12337906}], ['sample 5', {'balance': 100000, 'rate_bp': 450, 'last_paid_day': 100, 'payoff_day': 101, 'basis': 365, 'fees_due': 0, 'escrow': 12000, 'penalty_bp': 200, 'penalty_until': 130}, {'per_diem': 12, 'interest': 12, 'penalty': 2000, 'payoff': 90012}], ['sample 6', {'balance': 12345678, 'rate_bp': 450, 'last_paid_day': 10, 'payoff_day': 11, 'basis': 365, 'fees_due': 0, 'escrow': -4000, 'penalty_bp': 200, 'penalty_until': 40}, {'per_diem': 1522, 'interest': 1522, 'penalty': 246914, 'payoff': 12598114}]], [['regression: interest day count', {'balance': 5000, 'rate_bp': 450, 'last_paid_day': 10, 'payoff_day': 55, 'basis': 365, 'fees_due': 0, 'escrow': -4000, 'penalty_bp': 0, 'penalty_until': 40}, {'per_diem': 1, 'interest': 45, 'penalty': 0, 'payoff': 9045}], ['sample 1', {'balance': 100000, 'rate_bp': 1250, 'last_paid_day': 1, 'payoff_day': 46, 'basis': 360, 'fees_due': 0, 'escrow': 12000, 'penalty_bp': 0, 'penalty_until': 31}, {'per_diem': 35, 'interest': 1575, 'penalty': 0, 'payoff': 89575}], ['sample 2', {'balance': 999999, 'rate_bp': 1250, 'last_paid_day': 10, 'payoff_day': 25, 'basis': 365, 'fees_due': 0, 'escrow': 0, 'penalty_bp': 0, 'penalty_until': 40}, {'per_diem': 342, 'interest': 5130, 'penalty': 0, 'payoff': 1005129}], ['sample 3', {'balance': 12345678, 'rate_bp': 450, 'last_paid_day': 1, 'payoff_day': 31, 'basis': 360, 'fees_due': 3500, 'escrow': 12000, 'penalty_bp': 100, 'penalty_until': 16}, {'per_diem': 1543, 'interest': 46290, 'penalty': 0, 'payoff': 12383468}], ['sample 4', {'balance': 12345678, 'rate_bp': 600, 'last_paid_day': 1, 'payoff_day': 31, 'basis': 360, 'fees_due': 0, 'escrow': 0, 'penalty_bp': 200, 'penalty_until': 31}, {'per_diem': 2058, 'interest': 61740, 'penalty': 246914, 'payoff': 12654332}], ['sample 5', {'balance': 100000, 'rate_bp': 1250, 'last_paid_day': 1, 'payoff_day': 2, 'basis': 365, 'fees_due': 3500, 'escrow': 12000, 'penalty_bp': 100, 'penalty_until': 1}, {'per_diem': 34, 'interest': 34, 'penalty': 0, 'payoff': 91534}], ['sample 6', {'balance': 100000, 'rate_bp': 1250, 'last_paid_day': 100, 'payoff_day': 130, 'basis': 360, 'fees_due': 3500, 'escrow': -4000, 'penalty_bp': 100, 'penalty_until': 115}, {'per_diem': 35, 'interest': 1050, 'penalty': 0, 'payoff': 108550}]], [['regression: interest day count', {'balance': 5000, 'rate_bp': 600, 'last_paid_day': 10, 'payoff_day': 40, 'basis': 365, 'fees_due': 3500, 'escrow': 0, 'penalty_bp': 200, 'penalty_until': 70}, {'per_diem': 1, 'interest': 30, 'penalty': 100, 'payoff': 8630}], ['sample 1', {'balance': 12345678, 'rate_bp': 450, 'last_paid_day': 1, 'payoff_day': 32, 'basis': 365, 'fees_due': 3500, 'escrow': -4000, 'penalty_bp': 100, 'penalty_until': 1}, {'per_diem': 1522, 'interest': 47182, 'penalty': 0, 'payoff': 12400360}], ['sample 2', {'balance': 5000, 'rate_bp': 1250, 'last_paid_day': 1, 'payoff_day': 46, 'basis': 360, 'fees_due': 0, 'escrow': 12000, 'penalty_bp': 100, 'penalty_until': 16}, {'per_diem': 2, 'interest': 90, 'penalty': 0, 'payoff': -6910}], ['sample 3', {'balance': 5000, 'rate_bp': 600, 'last_paid_day': 100, 'payoff_day': 130, 'basis': 365, 'fees_due': 3500, 'escrow': -4000, 'penalty_bp': 200, 'penalty_until': 100}, {'per_diem': 1, 'interest': 30, 'penalty': 0, 'payoff': 12530}], ['sample 4', {'balance': 999999, 'rate_bp': 1250, 'last_paid_day': 100, 'payoff_day': 115, 'basis': 360, 'fees_due': 0, 'escrow': -4000, 'penalty_bp': 200, 'penalty_until': 130}, {'per_diem': 347, 'interest': 5205, 'penalty': 20000, 'payoff': 1029204}], ['sample 5', {'balance': 5000, 'rate_bp': 1250, 'last_paid_day': 100, 'payoff_day': 115, 'basis': 365, 'fees_due': 3500, 'escrow': 12000, 'penalty_bp': 100, 'penalty_until': 160}, {'per_diem': 2, 'interest': 30, 'penalty': 50, 'payoff': -3420}], ['sample 6', {'balance': 100000, 'rate_bp': 1250, 'last_paid_day': 1, 'payoff_day': 46, 'basis': 365, 'fees_due': 0, 'escrow': 0, 'penalty_bp': 0, 'penalty_until': 61}, {'per_diem': 34, 'interest': 1530, 'penalty': 0, 'payoff': 101530}]], [['regression: interest day count', {'balance': 999999, 'rate_bp': 1250, 'last_paid_day': 100, 'payoff_day': 131, 'basis': 360, 'fees_due': 3500, 'escrow': 0, 'penalty_bp': 100, 'penalty_until': 115}, {'per_diem': 347, 'interest': 10757, 'penalty': 0, 'payoff': 1014256}], ['sample 1', {'balance': 12345678, 'rate_bp': 450, 'last_paid_day': 100, 'payoff_day': 115, 'basis': 360, 'fees_due': 3500, 'escrow': 0, 'penalty_bp': 100, 'penalty_until': 160}, {'per_diem': 1543, 'interest': 23145, 'penalty': 123457, 'payoff': 12495780}], ['sample 2', {'balance': 12345678, 'rate_bp': 450, 'last_paid_day': 100, 'payoff_day': 101, 'basis': 365, 'fees_due': 3500, 'escrow': -4000, 'penalty_bp': 100, 'penalty_until': 130}, {'per_diem': 1522, 'interest': 1522, 'penalty': 123457, 'payoff': 12478157}], ['sample 3', {'balance': 12345678, 'rate_bp': 450, 'last_paid_day': 100, 'payoff_day': 130, 'basis': 365, 'fees_due': 0, 'escrow': 12000, 'penalty_bp': 0, 'penalty_until': 130}, {'per_diem': 1522, 'interest': 45660, 'penalty': 0, 'payoff': 12379338}], ['sample 4', {'balance': 12345678, 'rate_bp': 450, 'last_paid_day': 1, 'payoff_day': 31, 'basis': 360, 'fees_due': 3500, 'escrow': -4000, 'penalty_bp': 200, 'penalty_until': 1}, {'per_diem': 1543, 'interest': 46290, 'penalty': 0, 'payoff': 12399468}], ['sample 5', {'balance': 999999, 'rate_bp': 600, 'last_paid_day': 10, 'payoff_day': 40, 'basis': 360, 'fees_due': 0, 'escrow': 0, 'penalty_bp': 0, 'penalty_until': 70}, {'per_diem': 167, 'interest': 5010, 'penalty': 0, 'payoff': 1005009}], ['sample 6', {'balance': 999999, 'rate_bp': 450, 'last_paid_day': 1, 'payoff_day': 31, 'basis': 360, 'fees_due': 0, 'escrow': -4000, 'penalty_bp': 200, 'penalty_until': 16}, {'per_diem': 125, 'interest': 3750, 'penalty': 0, 'payoff': 1007749}]]]
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)

source:
"""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)
    per_diem = rnd(x['balance'] * x['rate_bp'], 10000 * x['basis'])
    days = x['payoff_day'] - x['last_paid_day'] - 1
    interest = per_diem * days
    penalty = rnd(x['balance'] * x['penalty_bp'], 10000) if x['payoff_day'] <= x['penalty_until'] else 0
    payoff = x['balance'] + interest + x['fees_due'] + penalty - x['escrow']
    return {'per_diem': per_diem, 'interest': interest, 'penalty': penalty, 'payoff': payoff}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: interest day count', {'balance': 100000, 'rate_bp': 600, 'last_paid_day': 100, 'payoff_day': 145, 'basis': 360, 'fees_due': 3500, 'escrow': -4000, 'penalty_bp': 0, 'penalty_until': 115}, {'per_diem': 17, 'interest': 765, 'penalty': 0, 'payoff': 108265}], ['sample 1', {'balance': 999999, 'rate_bp': 600, 'last_paid_day': 10, 'payoff_day': 11, 'basis': 365, 'fees_due': 0, 'escrow': 0, 'penalty_bp': 100, 'penalty_until': 10}, {'per_diem': 164, 'interest': 164, 'penalty': 0, 'payoff': 1000163}], ['sample 2', {'balance': 100000, 'rate_bp': 1250, 'last_paid_day': 1, 'payoff_day': 16, 'basis': 360, 'fees_due': 3500, 'escrow': 12000, 'penalty_bp': 100, 'penalty_until': 31}, {'per_diem': 35, 'interest': 525, 'penalty': 1000, 'payoff': 93025}], ['sample 3', {'balance': 12345678, 'rate_bp': 600, 'last_paid_day': 10, 'payoff_day': 41, 'basis': 360, 'fees_due': 3500, 'escrow': 12000, 'penalty_bp': 200, 'penalty_until': 40}, {'per_diem': 2058, 'interest': 63798, 'penalty': 0, 'payoff': 12400976}], ['sample 4', {'balance': 12345678, 'rate_bp': 450, 'last_paid_day': 10, 'payoff_day': 55, 'basis': 360, 'fees_due': 0, 'escrow': 0, 'penalty_bp': 100, 'penalty_until': 25}, {'per_diem': 1543, 'interest': 69435, 'penalty': 0, 'payoff': 12415113}], ['sample 5', {'balance': 5000, 'rate_bp': 1250, 'last_paid_day': 10, 'payoff_day': 41, 'basis': 360, 'fees_due': 0, 'escrow': 12000, 'penalty_bp': 0, 'penalty_until': 25}, {'per_diem': 2, 'interest': 62, 'penalty': 0, 'payoff': -6938}], ['sample 6', {'balance': 100000, 'rate_bp': 600, 'last_paid_day': 1, 'payoff_day': 46, 'basis': 365, 'fees_due': 0, 'escrow': 12000, 'penalty_bp': 200, 'penalty_until': 1}, {'per_diem': 16, 'interest': 720, 'penalty': 0, 'payoff': 88720}]], [['regression: interest day count', {'balance': 999999, 'rate_bp': 1250, 'last_paid_day': 1, 'payoff_day': 46, 'basis': 365, 'fees_due': 3500, 'escrow': -4000, 'penalty_bp': 100, 'penalty_until': 1}, {'per_diem': 342, 'interest': 15390, 'penalty': 0, 'payoff': 1022889}], ['sample 1', {'balance': 100000, 'rate_bp': 450, 'last_paid_day': 1, 'payoff_day': 2, 'basis': 360, 'fees_due': 3500, 'escrow': 0, 'penalty_bp': 200, 'penalty_until': 61}, {'per_diem': 13, 'interest': 13, 'penalty': 2000, 'payoff': 105513}], ['sample 2', {'balance': 100000, 'rate_bp': 1250, 'last_paid_day': 10, 'payoff_day': 25, 'basis': 365, 'fees_due': 0, 'escrow': 0, 'penalty_bp': 100, 'penalty_until': 10}, {'per_diem': 34, 'interest': 510, 'penalty': 0, 'payoff': 100510}], ['sample 3', {'balance': 999999, 'rate_bp': 450, 'last_paid_day': 1, 'payoff_day': 31, 'basis': 360, 'fees_due': 3500, 'escrow': 0, 'penalty_bp': 0, 'penalty_until': 61}, {'per_diem': 125, 'interest': 3750, 'penalty': 0, 'payoff': 1007249}], ['sample 4', {'balance': 12345678, 'rate_bp': 1250, 'last_paid_day': 10, 'payoff_day': 11, 'basis': 365, 'fees_due': 0, 'escrow': 12000, 'penalty_bp': 0, 'penalty_until': 40}, {'per_diem': 4228, 'interest': 4228, 'penalty': 0, 'payoff': 12337906}], ['sample 5', {'balance': 100000, 'rate_bp': 450, 'last_paid_day': 100, 'payoff_day': 101, 'basis': 365, 'fees_due': 0, 'escrow': 12000, 'penalty_bp': 200, 'penalty_until': 130}, {'per_diem': 12, 'interest': 12, 'penalty': 2000, 'payoff': 90012}], ['sample 6', {'balance': 12345678, 'rate_bp': 450, 'last_paid_day': 10, 'payoff_day': 11, 'basis': 365, 'fees_due': 0, 'escrow': -4000, 'penalty_bp': 200, 'penalty_until': 40}, {'per_diem': 1522, 'interest': 1522, 'penalty': 246914, 'payoff': 12598114}]], [['regression: interest day count', {'balance': 5000, 'rate_bp': 450, 'last_paid_day': 10, 'payoff_day': 55, 'basis': 365, 'fees_due': 0, 'escrow': -4000, 'penalty_bp': 0, 'penalty_until': 40}, {'per_diem': 1, 'interest': 45, 'penalty': 0, 'payoff': 9045}], ['sample 1', {'balance': 100000, 'rate_bp': 1250, 'last_paid_day': 1, 'payoff_day': 46, 'basis': 360, 'fees_due': 0, 'escrow': 12000, 'penalty_bp': 0, 'penalty_until': 31}, {'per_diem': 35, 'interest': 1575, 'penalty': 0, 'payoff': 89575}], ['sample 2', {'balance': 999999, 'rate_bp': 1250, 'last_paid_day': 10, 'payoff_day': 25, 'basis': 365, 'fees_due': 0, 'escrow': 0, 'penalty_bp': 0, 'penalty_until': 40}, {'per_diem': 342, 'interest': 5130, 'penalty': 0, 'payoff': 1005129}], ['sample 3', {'balance': 12345678, 'rate_bp': 450, 'last_paid_day': 1, 'payoff_day': 31, 'basis': 360, 'fees_due': 3500, 'escrow': 12000, 'penalty_bp': 100, 'penalty_until': 16}, {'per_diem': 1543, 'interest': 46290, 'penalty': 0, 'payoff': 12383468}], ['sample 4', {'balance': 12345678, 'rate_bp': 600, 'last_paid_day': 1, 'payoff_day': 31, 'basis': 360, 'fees_due': 0, 'escrow': 0, 'penalty_bp': 200, 'penalty_until': 31}, {'per_diem': 2058, 'interest': 61740, 'penalty': 246914, 'payoff': 12654332}], ['sample 5', {'balance': 100000, 'rate_bp': 1250, 'last_paid_day': 1, 'payoff_day': 2, 'basis': 365, 'fees_due': 3500, 'escrow': 12000, 'penalty_bp': 100, 'penalty_until': 1}, {'per_diem': 34, 'interest': 34, 'penalty': 0, 'payoff': 91534}], ['sample 6', {'balance': 100000, 'rate_bp': 1250, 'last_paid_day': 100, 'payoff_day': 130, 'basis': 360, 'fees_due': 3500, 'escrow': -4000, 'penalty_bp': 100, 'penalty_until': 115}, {'per_diem': 35, 'interest': 1050, 'penalty': 0, 'payoff': 108550}]], [['regression: interest day count', {'balance': 5000, 'rate_bp': 600, 'last_paid_day': 10, 'payoff_day': 40, 'basis': 365, 'fees_due': 3500, 'escrow': 0, 'penalty_bp': 200, 'penalty_until': 70}, {'per_diem': 1, 'interest': 30, 'penalty': 100, 'payoff': 8630}], ['sample 1', {'balance': 12345678, 'rate_bp': 450, 'last_paid_day': 1, 'payoff_day': 32, 'basis': 365, 'fees_due': 3500, 'escrow': -4000, 'penalty_bp': 100, 'penalty_until': 1}, {'per_diem': 1522, 'interest': 47182, 'penalty': 0, 'payoff': 12400360}], ['sample 2', {'balance': 5000, 'rate_bp': 1250, 'last_paid_day': 1, 'payoff_day': 46, 'basis': 360, 'fees_due': 0, 'escrow': 12000, 'penalty_bp': 100, 'penalty_until': 16}, {'per_diem': 2, 'interest': 90, 'penalty': 0, 'payoff': -6910}], ['sample 3', {'balance': 5000, 'rate_bp': 600, 'last_paid_day': 100, 'payoff_day': 130, 'basis': 365, 'fees_due': 3500, 'escrow': -4000, 'penalty_bp': 200, 'penalty_until': 100}, {'per_diem': 1, 'interest': 30, 'penalty': 0, 'payoff': 12530}], ['sample 4', {'balance': 999999, 'rate_bp': 1250, 'last_paid_day': 100, 'payoff_day': 115, 'basis': 360, 'fees_due': 0, 'escrow': -4000, 'penalty_bp': 200, 'penalty_until': 130}, {'per_diem': 347, 'interest': 5205, 'penalty': 20000, 'payoff': 1029204}], ['sample 5', {'balance': 5000, 'rate_bp': 1250, 'last_paid_day': 100, 'payoff_day': 115, 'basis': 365, 'fees_due': 3500, 'escrow': 12000, 'penalty_bp': 100, 'penalty_until': 160}, {'per_diem': 2, 'interest': 30, 'penalty': 50, 'payoff': -3420}], ['sample 6', {'balance': 100000, 'rate_bp': 1250, 'last_paid_day': 1, 'payoff_day': 46, 'basis': 365, 'fees_due': 0, 'escrow': 0, 'penalty_bp': 0, 'penalty_until': 61}, {'per_diem': 34, 'interest': 1530, 'penalty': 0, 'payoff': 101530}]], [['regression: interest day count', {'balance': 999999, 'rate_bp': 1250, 'last_paid_day': 100, 'payoff_day': 131, 'basis': 360, 'fees_due': 3500, 'escrow': 0, 'penalty_bp': 100, 'penalty_until': 115}, {'per_diem': 347, 'interest': 10757, 'penalty': 0, 'payoff': 1014256}], ['sample 1', {'balance': 12345678, 'rate_bp': 450, 'last_paid_day': 100, 'payoff_day': 115, 'basis': 360, 'fees_due': 3500, 'escrow': 0, 'penalty_bp': 100, 'penalty_until': 160}, {'per_diem': 1543, 'interest': 23145, 'penalty': 123457, 'payoff': 12495780}], ['sample 2', {'balance': 12345678, 'rate_bp': 450, 'last_paid_day': 100, 'payoff_day': 101, 'basis': 365, 'fees_due': 3500, 'escrow': -4000, 'penalty_bp': 100, 'penalty_until': 130}, {'per_diem': 1522, 'interest': 1522, 'penalty': 123457, 'payoff': 12478157}], ['sample 3', {'balance': 12345678, 'rate_bp': 450, 'last_paid_day': 100, 'payoff_day': 130, 'basis': 365, 'fees_due': 0, 'escrow': 12000, 'penalty_bp': 0, 'penalty_until': 130}, {'per_diem': 1522, 'interest': 45660, 'penalty': 0, 'payoff': 12379338}], ['sample 4', {'balance': 12345678, 'rate_bp': 450, 'last_paid_day': 1, 'payoff_day': 31, 'basis': 360, 'fees_due': 3500, 'escrow': -4000, 'penalty_bp': 200, 'penalty_until': 1}, {'per_diem': 1543, 'interest': 46290, 'penalty': 0, 'payoff': 12399468}], ['sample 5', {'balance': 999999, 'rate_bp': 600, 'last_paid_day': 10, 'payoff_day': 40, 'basis': 360, 'fees_due': 0, 'escrow': 0, 'penalty_bp': 0, 'penalty_until': 70}, {'per_diem': 167, 'interest': 5010, 'penalty': 0, 'payoff': 1005009}], ['sample 6', {'balance': 999999, 'rate_bp': 450, 'last_paid_day': 1, 'payoff_day': 31, 'basis': 360, 'fees_due': 0, 'escrow': -4000, 'penalty_bp': 200, 'penalty_until': 16}, {'per_diem': 125, 'interest': 3750, 'penalty': 0, 'payoff': 1007749}]]]
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)

prompt:
Payoff quotes charge one extra day of interest.

x = {'balance', 'rate_bp', 'last_paid_day', 'payoff_day', 'basis', 'fees_due', 'escrow' (credit, may be negative), 'penalty_bp', 'penalty_until'}. Per diem = round_half_up(balance*bp/(10000*basis)); interest = per diem * (payoff_day - last_paid_day). Penalty = round_half_up(balance*penalty_bp/10000) when payoff_day <= penalty_until, else 0. Payoff = balance + interest + fees + penalty - escrow. Return {'per_diem', 'interest', 'penalty', 'payoff'}.

split: open-access