broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import datetime
from fractions import Fraction
N = 1
observations = []
def solve(d, conv, holidays):
    D = datetime.date(*d)
    H = {datetime.date(*h) for h in holidays}
    def bad(x):
        return x.weekday() > 5 or x in H
    def roll(x, step):
        while bad(x):
            x += datetime.timedelta(days=step)
        return x
    if conv == 'F':
        r = roll(D, 1)
    elif conv == 'MF':
        r = roll(D, 1)
        if r.month != D.month:
            r = roll(D, -1)
    elif conv == 'P':
        r = roll(D, -1)
    elif conv == 'MP':
        r = roll(D, -1)
        if r.month != D.month:
            r = roll(D, 1)
    elif conv == 'U':
        r = D
    else:
        return 'unknown convention'
    return [r.year, r.month, r.day]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression weekend test 1', [[2023, 12, 30], 'MF', []], [2023, 12, 29]], ['regression weekend test 2', [[2024, 3, 30], 'MF', []], [2024, 3, 29]], ['partial repair probe 1', [[2026, 5, 31], 'F', [[2026, 6, 1]]], [2026, 6, 2]], ['partial repair probe 2', [[2029, 9, 1], 'MF', [[2029, 9, 3], [2029, 9, 1]]], [2029, 9, 4]], ['boundary control 1', [[2024, 5, 15], 'F', [[2024, 5, 15]]], [2024, 5, 16]], ['boundary control 2', [[2024, 5, 15], 'X', []], 'unknown convention'], ['normal control 1', [[2024, 12, 31], 'F', []], [2024, 12, 31]], ['normal control 2', [[2028, 4, 30], 'U', []], [2028, 4, 30]]], [['regression weekend test 1', [[2023, 7, 1], 'MF', [[2023, 7, 3]]], [2023, 7, 4]], ['regression weekend test 2', [[2022, 7, 30], 'P', [[2022, 8, 3], [2022, 7, 29]]], [2022, 7, 28]], ['partial repair probe 1', [[2024, 3, 30], 'MF', [[2024, 3, 27], [2024, 3, 30]]], [2024, 3, 29]], ['partial repair probe 2', [[2024, 12, 29], 'MF', [[2024, 12, 31]]], [2024, 12, 30]], ['boundary control 1', [[2024, 5, 15], 'F', [[2024, 5, 15]]], [2024, 5, 16]], ['boundary control 2', [[2024, 5, 15], 'X', []], 'unknown convention'], ['normal control 1', [[2024, 10, 23], 'MP', [[2024, 10, 23], [2024, 10, 22], [2024, 10, 22]]], [2024, 10, 21]], ['normal control 2', [[2025, 2, 4], 'P', [[2025, 2, 2], [2025, 2, 1], [2025, 2, 2]]], [2025, 2, 4]]], [['regression weekend test 1', [[2020, 2, 1], 'MF', [[2020, 2, 3]]], [2020, 2, 4]], ['regression weekend test 2', [[2029, 6, 30], 'P', []], [2029, 6, 29]], ['partial repair probe 1', [[2022, 1, 2], 'MF', []], [2022, 1, 3]], ['partial repair probe 2', [[2028, 1, 30], 'MF', []], [2028, 1, 31]], ['boundary control 1', [[2024, 5, 15], 'F', [[2024, 5, 15]]], [2024, 5, 16]], ['boundary control 2', [[2024, 5, 15], 'X', []], 'unknown convention'], ['normal control 1', [[2027, 12, 1], 'U', []], [2027, 12, 1]], ['normal control 2', [[2023, 1, 19], 'MF', [[2023, 1, 22], [2023, 1, 21], [2023, 1, 16]]], [2023, 1, 19]]], [['regression weekend test 1', [[2021, 5, 31], 'P', [[2021, 5, 31], [2021, 6, 4], [2021, 6, 1]]], [2021, 5, 28]], ['regression weekend test 2', [[2028, 12, 31], 'MF', []], [2028, 12, 29]], ['partial repair probe 1', [[2026, 11, 22], 'F', [[2026, 11, 25]]], [2026, 11, 23]], ['partial repair probe 2', [[2029, 12, 30], 'MF', []], [2029, 12, 31]], ['boundary control 1', [[2024, 5, 15], 'F', [[2024, 5, 15]]], [2024, 5, 16]], ['boundary control 2', [[2024, 5, 15], 'X', []], 'unknown convention'], ['normal control 1', [[2029, 10, 31], 'MP', []], [2029, 10, 31]], ['normal control 2', [[2024, 1, 3], 'MF', []], [2024, 1, 3]]], [['regression weekend test 1', [[2028, 7, 8], 'MF', [[2028, 7, 11]]], [2028, 7, 10]], ['regression weekend test 2', [[2020, 8, 9], 'MP', [[2020, 8, 9]]], [2020, 8, 7]], ['partial repair probe 1', [[2024, 12, 29], 'MF', [[2024, 12, 31]]], [2024, 12, 30]], ['partial repair probe 2', [[2028, 4, 30], 'F', [[2028, 4, 28]]], [2028, 5, 1]], ['boundary control 1', [[2024, 5, 15], 'X', []], 'unknown convention'], ['boundary control 2', [[2024, 5, 15], 'F', [[2024, 5, 15]]], [2024, 5, 16]], ['normal control 1', [[2030, 4, 30], 'MP', [[2030, 4, 28]]], [2030, 4, 30]], ['normal control 2', [[2020, 1, 2], 'U', []], [2020, 1, 2]]]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(*args), 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
import datetime
from fractions import Fraction
N = 1
observations = []
def solve(d, conv, holidays):
    D = datetime.date(*d)
    H = {datetime.date(*h) for h in holidays}
    def bad(x):
        return x.weekday() == 5 or x in H
    def roll(x, step):
        while bad(x):
            x += datetime.timedelta(days=step)
        return x
    if conv == 'F':
        r = roll(D, 1)
    elif conv == 'MF':
        r = roll(D, 1)
        if r.month != D.month:
            r = roll(D, -1)
    elif conv == 'P':
        r = roll(D, -1)
    elif conv == 'MP':
        r = roll(D, -1)
        if r.month != D.month:
            r = roll(D, 1)
    elif conv == 'U':
        r = D
    else:
        return 'unknown convention'
    return [r.year, r.month, r.day]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression weekend test 1', [[2023, 12, 30], 'MF', []], [2023, 12, 29]], ['regression weekend test 2', [[2024, 3, 30], 'MF', []], [2024, 3, 29]], ['partial repair probe 1', [[2026, 5, 31], 'F', [[2026, 6, 1]]], [2026, 6, 2]], ['partial repair probe 2', [[2029, 9, 1], 'MF', [[2029, 9, 3], [2029, 9, 1]]], [2029, 9, 4]], ['boundary control 1', [[2024, 5, 15], 'F', [[2024, 5, 15]]], [2024, 5, 16]], ['boundary control 2', [[2024, 5, 15], 'X', []], 'unknown convention'], ['normal control 1', [[2024, 12, 31], 'F', []], [2024, 12, 31]], ['normal control 2', [[2028, 4, 30], 'U', []], [2028, 4, 30]]], [['regression weekend test 1', [[2023, 7, 1], 'MF', [[2023, 7, 3]]], [2023, 7, 4]], ['regression weekend test 2', [[2022, 7, 30], 'P', [[2022, 8, 3], [2022, 7, 29]]], [2022, 7, 28]], ['partial repair probe 1', [[2024, 3, 30], 'MF', [[2024, 3, 27], [2024, 3, 30]]], [2024, 3, 29]], ['partial repair probe 2', [[2024, 12, 29], 'MF', [[2024, 12, 31]]], [2024, 12, 30]], ['boundary control 1', [[2024, 5, 15], 'F', [[2024, 5, 15]]], [2024, 5, 16]], ['boundary control 2', [[2024, 5, 15], 'X', []], 'unknown convention'], ['normal control 1', [[2024, 10, 23], 'MP', [[2024, 10, 23], [2024, 10, 22], [2024, 10, 22]]], [2024, 10, 21]], ['normal control 2', [[2025, 2, 4], 'P', [[2025, 2, 2], [2025, 2, 1], [2025, 2, 2]]], [2025, 2, 4]]], [['regression weekend test 1', [[2020, 2, 1], 'MF', [[2020, 2, 3]]], [2020, 2, 4]], ['regression weekend test 2', [[2029, 6, 30], 'P', []], [2029, 6, 29]], ['partial repair probe 1', [[2022, 1, 2], 'MF', []], [2022, 1, 3]], ['partial repair probe 2', [[2028, 1, 30], 'MF', []], [2028, 1, 31]], ['boundary control 1', [[2024, 5, 15], 'F', [[2024, 5, 15]]], [2024, 5, 16]], ['boundary control 2', [[2024, 5, 15], 'X', []], 'unknown convention'], ['normal control 1', [[2027, 12, 1], 'U', []], [2027, 12, 1]], ['normal control 2', [[2023, 1, 19], 'MF', [[2023, 1, 22], [2023, 1, 21], [2023, 1, 16]]], [2023, 1, 19]]], [['regression weekend test 1', [[2021, 5, 31], 'P', [[2021, 5, 31], [2021, 6, 4], [2021, 6, 1]]], [2021, 5, 28]], ['regression weekend test 2', [[2028, 12, 31], 'MF', []], [2028, 12, 29]], ['partial repair probe 1', [[2026, 11, 22], 'F', [[2026, 11, 25]]], [2026, 11, 23]], ['partial repair probe 2', [[2029, 12, 30], 'MF', []], [2029, 12, 31]], ['boundary control 1', [[2024, 5, 15], 'F', [[2024, 5, 15]]], [2024, 5, 16]], ['boundary control 2', [[2024, 5, 15], 'X', []], 'unknown convention'], ['normal control 1', [[2029, 10, 31], 'MP', []], [2029, 10, 31]], ['normal control 2', [[2024, 1, 3], 'MF', []], [2024, 1, 3]]], [['regression weekend test 1', [[2028, 7, 8], 'MF', [[2028, 7, 11]]], [2028, 7, 10]], ['regression weekend test 2', [[2020, 8, 9], 'MP', [[2020, 8, 9]]], [2020, 8, 7]], ['partial repair probe 1', [[2024, 12, 29], 'MF', [[2024, 12, 31]]], [2024, 12, 30]], ['partial repair probe 2', [[2028, 4, 30], 'F', [[2028, 4, 28]]], [2028, 5, 1]], ['boundary control 1', [[2024, 5, 15], 'X', []], 'unknown convention'], ['boundary control 2', [[2024, 5, 15], 'F', [[2024, 5, 15]]], [2024, 5, 16]], ['normal control 1', [[2030, 4, 30], 'MP', [[2030, 4, 28]]], [2030, 4, 30]], ['normal control 2', [[2020, 1, 2], 'U', []], [2020, 1, 2]]]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(*args), 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:
Payments scheduled on a Saturday are made on the Saturday.

Inputs a date [y,m,d], a convention code and a list of holiday dates. Saturdays, Sundays and holidays are non-business days. F rolls forward, P rolls back, MF rolls forward unless that changes the month in which case it rolls back, MP rolls back unless that changes the month in which case it rolls forward, U leaves the date unadjusted; other codes return "unknown convention". Return the adjusted [y,m,d].

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import datetime
from fractions import Fraction
N = 1
observations = []
def solve(d, conv, holidays):
    D = datetime.date(*d)
    H = {datetime.date(*h) for h in holidays}
    def bad(x):
        return x.weekday() >= 5 or x in H
    def roll(x, step):
        while bad(x):
            x += datetime.timedelta(days=step)
        return x
    if conv == 'F':
        r = roll(D, 1)
    elif conv == 'MF':
        r = roll(D, 1)
        if r.month != D.month:
            r = roll(r, -1)
    elif conv == 'P':
        r = roll(D, -1)
    elif conv == 'MP':
        r = roll(D, -1)
        if r.month != D.month:
            r = roll(D, 1)
    elif conv == 'U':
        r = D
    else:
        return 'unknown convention'
    return [r.year, r.month, r.day]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression modified following fallback 1', [[2027, 12, 31], 'MF', [[2027, 12, 31]]], [2027, 12, 30]], ['regression modified following fallback 2', [[2025, 8, 30], 'MF', [[2025, 9, 2], [2025, 8, 31]]], [2025, 8, 29]], ['partial repair probe 1', [[2023, 12, 31], 'MF', []], [2023, 12, 29]], ['partial repair probe 2', [[2023, 12, 31], 'MF', [[2024, 1, 4], [2023, 12, 29]]], [2023, 12, 28]], ['boundary control 1', [[2024, 5, 15], 'X', []], 'unknown convention'], ['boundary control 2', [[2024, 12, 28], 'F', []], [2024, 12, 30]], ['normal control 1', [[2030, 12, 21], 'F', [[2030, 12, 18], [2030, 12, 20], [2030, 12, 18]]], [2030, 12, 23]], ['normal control 2', [[2024, 7, 31], 'MP', [[2024, 8, 2], [2024, 7, 29]]], [2024, 7, 31]]], [['regression modified following fallback 1', [[2023, 12, 31], 'MF', []], [2023, 12, 29]], ['regression modified following fallback 2', [[2026, 2, 28], 'MF', []], [2026, 2, 27]], ['partial repair probe 1', [[2023, 4, 30], 'MF', [[2023, 4, 29], [2023, 5, 1]]], [2023, 4, 28]], ['partial repair probe 2', [[2023, 12, 31], 'MF', [[2023, 12, 31]]], [2023, 12, 29]], ['boundary control 1', [[2024, 5, 15], 'F', [[2024, 5, 15]]], [2024, 5, 16]], ['boundary control 2', [[2024, 6, 1], 'MP', []], [2024, 6, 3]], ['normal control 1', [[2023, 11, 4], 'F', []], [2023, 11, 6]], ['normal control 2', [[2025, 9, 1], 'X', [[2025, 9, 4]]], 'unknown convention']], [['regression modified following fallback 1', [[2030, 3, 31], 'MF', [[2030, 3, 28], [2030, 4, 4]]], [2030, 3, 29]], ['regression modified following fallback 2', [[2024, 8, 29], 'MF', [[2024, 8, 30], [2024, 8, 29]]], [2024, 8, 28]], ['partial repair probe 1', [[2024, 6, 29], 'MF', [[2024, 7, 2], [2024, 6, 28]]], [2024, 6, 27]], ['partial repair probe 2', [[2028, 12, 31], 'MF', [[2028, 12, 29], [2029, 1, 1]]], [2028, 12, 28]], ['boundary control 1', [[2024, 12, 28], 'F', []], [2024, 12, 30]], ['boundary control 2', [[2024, 5, 15], 'X', []], 'unknown convention'], ['normal control 1', [[2026, 1, 18], 'MP', [[2026, 1, 21]]], [2026, 1, 16]], ['normal control 2', [[2020, 6, 1], 'MP', [[2020, 5, 30], [2020, 6, 5], [2020, 5, 30]]], [2020, 6, 1]]], [['regression modified following fallback 1', [[2020, 5, 31], 'MF', []], [2020, 5, 29]], ['regression modified following fallback 2', [[2022, 12, 31], 'MF', []], [2022, 12, 30]], ['partial repair probe 1', [[2021, 10, 31], 'MF', []], [2021, 10, 29]], ['partial repair probe 2', [[2019, 3, 31], 'MF', [[2019, 3, 30]]], [2019, 3, 29]], ['boundary control 1', [[2024, 5, 15], 'F', [[2024, 5, 15]]], [2024, 5, 16]], ['boundary control 2', [[2024, 5, 15], 'X', []], 'unknown convention'], ['normal control 1', [[2028, 4, 30], 'P', []], [2028, 4, 28]], ['normal control 2', [[2028, 11, 30], 'X', []], 'unknown convention']], [['regression modified following fallback 1', [[2025, 12, 31], 'MF', [[2025, 12, 31]]], [2025, 12, 30]], ['regression modified following fallback 2', [[2027, 1, 31], 'MF', []], [2027, 1, 29]], ['partial repair probe 1', [[2024, 3, 31], 'MF', [[2024, 3, 30]]], [2024, 3, 29]], ['partial repair probe 2', [[2028, 12, 31], 'MF', []], [2028, 12, 29]], ['boundary control 1', [[2024, 6, 1], 'MP', []], [2024, 6, 3]], ['boundary control 2', [[2024, 12, 28], 'F', []], [2024, 12, 30]], ['normal control 1', [[2023, 3, 29], 'MP', [[2023, 3, 28], [2023, 3, 31]]], [2023, 3, 29]], ['normal control 2', [[2026, 10, 1], 'MP', []], [2026, 10, 1]]]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(*args), 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
import datetime
from fractions import Fraction
N = 1
observations = []
def solve(d, conv, holidays):
    D = datetime.date(*d)
    H = {datetime.date(*h) for h in holidays}
    def bad(x):
        return x.weekday() >= 5 or x in H
    def roll(x, step):
        while bad(x):
            x += datetime.timedelta(days=step)
        return x
    if conv == 'F':
        r = roll(D, 1)
    elif conv == 'MF':
        r = roll(D, 1)
        if r.month != D.month:
            r = D - datetime.timedelta(days=1)
    elif conv == 'P':
        r = roll(D, -1)
    elif conv == 'MP':
        r = roll(D, -1)
        if r.month != D.month:
            r = roll(D, 1)
    elif conv == 'U':
        r = D
    else:
        return 'unknown convention'
    return [r.year, r.month, r.day]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression modified following fallback 1', [[2027, 12, 31], 'MF', [[2027, 12, 31]]], [2027, 12, 30]], ['regression modified following fallback 2', [[2025, 8, 30], 'MF', [[2025, 9, 2], [2025, 8, 31]]], [2025, 8, 29]], ['partial repair probe 1', [[2023, 12, 31], 'MF', []], [2023, 12, 29]], ['partial repair probe 2', [[2023, 12, 31], 'MF', [[2024, 1, 4], [2023, 12, 29]]], [2023, 12, 28]], ['boundary control 1', [[2024, 5, 15], 'X', []], 'unknown convention'], ['boundary control 2', [[2024, 12, 28], 'F', []], [2024, 12, 30]], ['normal control 1', [[2030, 12, 21], 'F', [[2030, 12, 18], [2030, 12, 20], [2030, 12, 18]]], [2030, 12, 23]], ['normal control 2', [[2024, 7, 31], 'MP', [[2024, 8, 2], [2024, 7, 29]]], [2024, 7, 31]]], [['regression modified following fallback 1', [[2023, 12, 31], 'MF', []], [2023, 12, 29]], ['regression modified following fallback 2', [[2026, 2, 28], 'MF', []], [2026, 2, 27]], ['partial repair probe 1', [[2023, 4, 30], 'MF', [[2023, 4, 29], [2023, 5, 1]]], [2023, 4, 28]], ['partial repair probe 2', [[2023, 12, 31], 'MF', [[2023, 12, 31]]], [2023, 12, 29]], ['boundary control 1', [[2024, 5, 15], 'F', [[2024, 5, 15]]], [2024, 5, 16]], ['boundary control 2', [[2024, 6, 1], 'MP', []], [2024, 6, 3]], ['normal control 1', [[2023, 11, 4], 'F', []], [2023, 11, 6]], ['normal control 2', [[2025, 9, 1], 'X', [[2025, 9, 4]]], 'unknown convention']], [['regression modified following fallback 1', [[2030, 3, 31], 'MF', [[2030, 3, 28], [2030, 4, 4]]], [2030, 3, 29]], ['regression modified following fallback 2', [[2024, 8, 29], 'MF', [[2024, 8, 30], [2024, 8, 29]]], [2024, 8, 28]], ['partial repair probe 1', [[2024, 6, 29], 'MF', [[2024, 7, 2], [2024, 6, 28]]], [2024, 6, 27]], ['partial repair probe 2', [[2028, 12, 31], 'MF', [[2028, 12, 29], [2029, 1, 1]]], [2028, 12, 28]], ['boundary control 1', [[2024, 12, 28], 'F', []], [2024, 12, 30]], ['boundary control 2', [[2024, 5, 15], 'X', []], 'unknown convention'], ['normal control 1', [[2026, 1, 18], 'MP', [[2026, 1, 21]]], [2026, 1, 16]], ['normal control 2', [[2020, 6, 1], 'MP', [[2020, 5, 30], [2020, 6, 5], [2020, 5, 30]]], [2020, 6, 1]]], [['regression modified following fallback 1', [[2020, 5, 31], 'MF', []], [2020, 5, 29]], ['regression modified following fallback 2', [[2022, 12, 31], 'MF', []], [2022, 12, 30]], ['partial repair probe 1', [[2021, 10, 31], 'MF', []], [2021, 10, 29]], ['partial repair probe 2', [[2019, 3, 31], 'MF', [[2019, 3, 30]]], [2019, 3, 29]], ['boundary control 1', [[2024, 5, 15], 'F', [[2024, 5, 15]]], [2024, 5, 16]], ['boundary control 2', [[2024, 5, 15], 'X', []], 'unknown convention'], ['normal control 1', [[2028, 4, 30], 'P', []], [2028, 4, 28]], ['normal control 2', [[2028, 11, 30], 'X', []], 'unknown convention']], [['regression modified following fallback 1', [[2025, 12, 31], 'MF', [[2025, 12, 31]]], [2025, 12, 30]], ['regression modified following fallback 2', [[2027, 1, 31], 'MF', []], [2027, 1, 29]], ['partial repair probe 1', [[2024, 3, 31], 'MF', [[2024, 3, 30]]], [2024, 3, 29]], ['partial repair probe 2', [[2028, 12, 31], 'MF', []], [2028, 12, 29]], ['boundary control 1', [[2024, 6, 1], 'MP', []], [2024, 6, 3]], ['boundary control 2', [[2024, 12, 28], 'F', []], [2024, 12, 30]], ['normal control 1', [[2023, 3, 29], 'MP', [[2023, 3, 28], [2023, 3, 31]]], [2023, 3, 29]], ['normal control 2', [[2026, 10, 1], 'MP', []], [2026, 10, 1]]]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(*args), 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:
Modified following behaves like plain following at month end.

Inputs a date [y,m,d], a convention code and a list of holiday dates. Saturdays, Sundays and holidays are non-business days. F rolls forward, P rolls back, MF rolls forward unless that changes the month in which case it rolls back, MP rolls back unless that changes the month in which case it rolls forward, U leaves the date unadjusted; other codes return "unknown convention". Return the adjusted [y,m,d].

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import datetime
from fractions import Fraction
N = 1
observations = []
def solve(d, conv, holidays):
    D = datetime.date(*d)
    H = {datetime.date(*h) for h in holidays}
    def bad(x):
        return x.weekday() >= 5 or x in H
    def roll(x, step):
        while bad(x):
            x += datetime.timedelta(days=step)
        return x
    if conv == 'F':
        r = roll(D, 1)
    elif conv == 'MF':
        r = roll(D, 1)
        if r.month > D.month:
            r = roll(D, -1)
    elif conv == 'P':
        r = roll(D, -1)
    elif conv == 'MP':
        r = roll(D, -1)
        if r.month != D.month:
            r = roll(D, 1)
    elif conv == 'U':
        r = D
    else:
        return 'unknown convention'
    return [r.year, r.month, r.day]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression month crossing test 1', [[2029, 12, 29], 'MF', [[2029, 12, 31]]], [2029, 12, 28]], ['regression month crossing test 2', [[2024, 12, 31], 'MF', [[2024, 12, 31]]], [2024, 12, 30]], ['partial repair probe 1', [[2023, 1, 1], 'MF', [[2023, 1, 4], [2023, 1, 1]]], [2023, 1, 2]], ['partial repair probe 2', [[2028, 1, 2], 'MF', []], [2028, 1, 3]], ['boundary control 1', [[2024, 12, 28], 'F', []], [2024, 12, 30]], ['boundary control 2', [[2024, 5, 15], 'X', []], 'unknown convention'], ['normal control 1', [[2028, 4, 30], 'MP', [[2028, 5, 3], [2028, 5, 1]]], [2028, 4, 28]], ['normal control 2', [[2022, 10, 28], 'U', [[2022, 10, 25], [2022, 10, 27], [2022, 10, 29]]], [2022, 10, 28]]], [['regression month crossing test 1', [[2023, 12, 31], 'MF', []], [2023, 12, 29]], ['regression month crossing test 2', [[2023, 12, 31], 'MF', [[2023, 12, 31]]], [2023, 12, 29]], ['partial repair probe 1', [[2027, 1, 2], 'MF', [[2027, 1, 2], [2027, 1, 5], [2027, 1, 5]]], [2027, 1, 4]], ['partial repair probe 2', [[2028, 1, 1], 'MF', [[2028, 1, 4], [2028, 1, 4]]], [2028, 1, 3]], ['boundary control 1', [[2024, 5, 15], 'F', [[2024, 5, 15]]], [2024, 5, 16]], ['boundary control 2', [[2024, 3, 30], 'MF', []], [2024, 3, 29]], ['normal control 1', [[2029, 5, 31], 'MF', [[2029, 6, 1], [2029, 5, 28], [2029, 5, 29]]], [2029, 5, 31]], ['normal control 2', [[2020, 10, 31], 'MP', [[2020, 10, 28], [2020, 10, 31], [2020, 10, 30]]], [2020, 10, 29]]], [['regression month crossing test 1', [[2021, 12, 31], 'MF', [[2021, 12, 31]]], [2021, 12, 30]], ['regression month crossing test 2', [[2023, 12, 30], 'MF', [[2023, 12, 31]]], [2023, 12, 29]], ['partial repair probe 1', [[2028, 1, 1], 'MF', []], [2028, 1, 3]], ['partial repair probe 2', [[2030, 1, 6], 'MF', []], [2030, 1, 7]], ['boundary control 1', [[2024, 5, 15], 'X', []], 'unknown convention'], ['boundary control 2', [[2024, 6, 1], 'MP', []], [2024, 6, 3]], ['normal control 1', [[2029, 11, 2], 'MP', [[2029, 11, 2]]], [2029, 11, 1]], ['normal control 2', [[2021, 9, 30], 'MF', [[2021, 10, 1], [2021, 10, 1]]], [2021, 9, 30]]], [['regression month crossing test 1', [[2026, 12, 31], 'MF', [[2026, 12, 31]]], [2026, 12, 30]], ['regression month crossing test 2', [[2030, 12, 31], 'MF', [[2030, 12, 31]]], [2030, 12, 30]], ['partial repair probe 1', [[2020, 1, 26], 'MF', [[2020, 1, 28]]], [2020, 1, 27]], ['partial repair probe 2', [[2026, 1, 3], 'MF', [[2026, 1, 7]]], [2026, 1, 5]], ['boundary control 1', [[2024, 5, 15], 'X', []], 'unknown convention'], ['boundary control 2', [[2024, 3, 30], 'MF', []], [2024, 3, 29]], ['normal control 1', [[2027, 7, 22], 'P', [[2027, 7, 25], [2027, 7, 20], [2027, 7, 23]]], [2027, 7, 22]], ['normal control 2', [[2026, 12, 31], 'U', [[2026, 12, 31], [2027, 1, 3]]], [2026, 12, 31]]], [['regression month crossing test 1', [[2029, 12, 31], 'MF', [[2029, 12, 31]]], [2029, 12, 28]], ['regression month crossing test 2', [[2020, 12, 31], 'MF', [[2020, 12, 31]]], [2020, 12, 30]], ['partial repair probe 1', [[2028, 1, 1], 'MF', [[2027, 12, 30]]], [2028, 1, 3]], ['partial repair probe 2', [[2023, 1, 2], 'MF', [[2023, 1, 2], [2022, 12, 31]]], [2023, 1, 3]], ['boundary control 1', [[2024, 5, 15], 'X', []], 'unknown convention'], ['boundary control 2', [[2024, 5, 15], 'F', [[2024, 5, 15]]], [2024, 5, 16]], ['normal control 1', [[2026, 1, 30], 'U', [[2026, 2, 1], [2026, 1, 29], [2026, 2, 2]]], [2026, 1, 30]], ['normal control 2', [[2023, 6, 30], 'MP', [[2023, 7, 4], [2023, 7, 2]]], [2023, 6, 30]]]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(*args), 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
import datetime
from fractions import Fraction
N = 1
observations = []
def solve(d, conv, holidays):
    D = datetime.date(*d)
    H = {datetime.date(*h) for h in holidays}
    def bad(x):
        return x.weekday() >= 5 or x in H
    def roll(x, step):
        while bad(x):
            x += datetime.timedelta(days=step)
        return x
    if conv == 'F':
        r = roll(D, 1)
    elif conv == 'MF':
        r = roll(D, 1)
        if r.month > D.month or r.month == 1:
            r = roll(D, -1)
    elif conv == 'P':
        r = roll(D, -1)
    elif conv == 'MP':
        r = roll(D, -1)
        if r.month != D.month:
            r = roll(D, 1)
    elif conv == 'U':
        r = D
    else:
        return 'unknown convention'
    return [r.year, r.month, r.day]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression month crossing test 1', [[2029, 12, 29], 'MF', [[2029, 12, 31]]], [2029, 12, 28]], ['regression month crossing test 2', [[2024, 12, 31], 'MF', [[2024, 12, 31]]], [2024, 12, 30]], ['partial repair probe 1', [[2023, 1, 1], 'MF', [[2023, 1, 4], [2023, 1, 1]]], [2023, 1, 2]], ['partial repair probe 2', [[2028, 1, 2], 'MF', []], [2028, 1, 3]], ['boundary control 1', [[2024, 12, 28], 'F', []], [2024, 12, 30]], ['boundary control 2', [[2024, 5, 15], 'X', []], 'unknown convention'], ['normal control 1', [[2028, 4, 30], 'MP', [[2028, 5, 3], [2028, 5, 1]]], [2028, 4, 28]], ['normal control 2', [[2022, 10, 28], 'U', [[2022, 10, 25], [2022, 10, 27], [2022, 10, 29]]], [2022, 10, 28]]], [['regression month crossing test 1', [[2023, 12, 31], 'MF', []], [2023, 12, 29]], ['regression month crossing test 2', [[2023, 12, 31], 'MF', [[2023, 12, 31]]], [2023, 12, 29]], ['partial repair probe 1', [[2027, 1, 2], 'MF', [[2027, 1, 2], [2027, 1, 5], [2027, 1, 5]]], [2027, 1, 4]], ['partial repair probe 2', [[2028, 1, 1], 'MF', [[2028, 1, 4], [2028, 1, 4]]], [2028, 1, 3]], ['boundary control 1', [[2024, 5, 15], 'F', [[2024, 5, 15]]], [2024, 5, 16]], ['boundary control 2', [[2024, 3, 30], 'MF', []], [2024, 3, 29]], ['normal control 1', [[2029, 5, 31], 'MF', [[2029, 6, 1], [2029, 5, 28], [2029, 5, 29]]], [2029, 5, 31]], ['normal control 2', [[2020, 10, 31], 'MP', [[2020, 10, 28], [2020, 10, 31], [2020, 10, 30]]], [2020, 10, 29]]], [['regression month crossing test 1', [[2021, 12, 31], 'MF', [[2021, 12, 31]]], [2021, 12, 30]], ['regression month crossing test 2', [[2023, 12, 30], 'MF', [[2023, 12, 31]]], [2023, 12, 29]], ['partial repair probe 1', [[2028, 1, 1], 'MF', []], [2028, 1, 3]], ['partial repair probe 2', [[2030, 1, 6], 'MF', []], [2030, 1, 7]], ['boundary control 1', [[2024, 5, 15], 'X', []], 'unknown convention'], ['boundary control 2', [[2024, 6, 1], 'MP', []], [2024, 6, 3]], ['normal control 1', [[2029, 11, 2], 'MP', [[2029, 11, 2]]], [2029, 11, 1]], ['normal control 2', [[2021, 9, 30], 'MF', [[2021, 10, 1], [2021, 10, 1]]], [2021, 9, 30]]], [['regression month crossing test 1', [[2026, 12, 31], 'MF', [[2026, 12, 31]]], [2026, 12, 30]], ['regression month crossing test 2', [[2030, 12, 31], 'MF', [[2030, 12, 31]]], [2030, 12, 30]], ['partial repair probe 1', [[2020, 1, 26], 'MF', [[2020, 1, 28]]], [2020, 1, 27]], ['partial repair probe 2', [[2026, 1, 3], 'MF', [[2026, 1, 7]]], [2026, 1, 5]], ['boundary control 1', [[2024, 5, 15], 'X', []], 'unknown convention'], ['boundary control 2', [[2024, 3, 30], 'MF', []], [2024, 3, 29]], ['normal control 1', [[2027, 7, 22], 'P', [[2027, 7, 25], [2027, 7, 20], [2027, 7, 23]]], [2027, 7, 22]], ['normal control 2', [[2026, 12, 31], 'U', [[2026, 12, 31], [2027, 1, 3]]], [2026, 12, 31]]], [['regression month crossing test 1', [[2029, 12, 31], 'MF', [[2029, 12, 31]]], [2029, 12, 28]], ['regression month crossing test 2', [[2020, 12, 31], 'MF', [[2020, 12, 31]]], [2020, 12, 30]], ['partial repair probe 1', [[2028, 1, 1], 'MF', [[2027, 12, 30]]], [2028, 1, 3]], ['partial repair probe 2', [[2023, 1, 2], 'MF', [[2023, 1, 2], [2022, 12, 31]]], [2023, 1, 3]], ['boundary control 1', [[2024, 5, 15], 'X', []], 'unknown convention'], ['boundary control 2', [[2024, 5, 15], 'F', [[2024, 5, 15]]], [2024, 5, 16]], ['normal control 1', [[2026, 1, 30], 'U', [[2026, 2, 1], [2026, 1, 29], [2026, 2, 2]]], [2026, 1, 30]], ['normal control 2', [[2023, 6, 30], 'MP', [[2023, 7, 4], [2023, 7, 2]]], [2023, 6, 30]]]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(*args), 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 December date rolling into January is not recognized as leaving the month.

Inputs a date [y,m,d], a convention code and a list of holiday dates. Saturdays, Sundays and holidays are non-business days. F rolls forward, P rolls back, MF rolls forward unless that changes the month in which case it rolls back, MP rolls back unless that changes the month in which case it rolls forward, U leaves the date unadjusted; other codes return "unknown convention". Return the adjusted [y,m,d].

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import datetime
from fractions import Fraction
N = 1
observations = []
def solve(d, conv, holidays):
    D = datetime.date(*d)
    H = {datetime.date(*h) for h in holidays}
    def bad(x):
        return x.weekday() >= 5 or x in H
    def roll(x, step):
        while bad(x):
            x += datetime.timedelta(days=step)
        return x
    if conv == 'F':
        r = roll(D, 1)
    elif conv == 'MF':
        r = roll(D, 1)
        if r.month != D.month:
            r = roll(D, -1)
    elif conv == 'P':
        r = roll(D, -1)
    elif conv == 'MP':
        r = roll(D, -1)
    elif conv == 'U':
        r = D
    else:
        return 'unknown convention'
    return [r.year, r.month, r.day]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression modified preceding guard 1', [[2028, 2, 1], 'MP', [[2028, 2, 1]]], [2028, 2, 2]], ['regression modified preceding guard 2', [[2022, 10, 1], 'MP', [[2022, 10, 1], [2022, 10, 1]]], [2022, 10, 3]], ['partial repair probe 1', [[2030, 3, 3], 'MP', [[2030, 3, 3], [2030, 3, 1], [2030, 3, 4]]], [2030, 3, 5]], ['partial repair probe 2', [[2024, 6, 1], 'MP', []], [2024, 6, 3]], ['boundary control 1', [[2024, 12, 28], 'F', []], [2024, 12, 30]], ['boundary control 2', [[2024, 5, 15], 'X', []], 'unknown convention'], ['normal control 1', [[2028, 8, 29], 'MF', [[2028, 8, 30]]], [2028, 8, 29]], ['normal control 2', [[2019, 10, 31], 'MF', [[2019, 10, 28], [2019, 11, 2], [2019, 11, 2]]], [2019, 10, 31]]], [['regression modified preceding guard 1', [[2023, 1, 1], 'MP', [[2023, 1, 5], [2022, 12, 31]]], [2023, 1, 2]], ['regression modified preceding guard 2', [[2019, 1, 2], 'MP', [[2019, 1, 2], [2019, 1, 1], [2019, 1, 3]]], [2019, 1, 4]], ['partial repair probe 1', [[2024, 6, 3], 'MP', [[2024, 6, 3], [2024, 6, 2]]], [2024, 6, 4]], ['partial repair probe 2', [[2025, 10, 1], 'MP', [[2025, 10, 2], [2025, 10, 5], [2025, 10, 1]]], [2025, 10, 3]], ['boundary control 1', [[2024, 5, 15], 'X', []], 'unknown convention'], ['boundary control 2', [[2024, 12, 28], 'F', []], [2024, 12, 30]], ['normal control 1', [[2025, 12, 29], 'MF', []], [2025, 12, 29]], ['normal control 2', [[2024, 6, 2], 'F', [[2024, 5, 30], [2024, 5, 31]]], [2024, 6, 3]]], [['regression modified preceding guard 1', [[2020, 3, 1], 'MP', [[2020, 2, 27]]], [2020, 3, 2]], ['regression modified preceding guard 2', [[2026, 3, 1], 'MP', [[2026, 3, 4], [2026, 2, 27], [2026, 3, 2]]], [2026, 3, 3]], ['partial repair probe 1', [[2019, 12, 1], 'MP', [[2019, 12, 1]]], [2019, 12, 2]], ['partial repair probe 2', [[2022, 10, 1], 'MP', [[2022, 10, 4], [2022, 10, 4], [2022, 10, 1]]], [2022, 10, 3]], ['boundary control 1', [[2024, 5, 15], 'X', []], 'unknown convention'], ['boundary control 2', [[2024, 12, 28], 'F', []], [2024, 12, 30]], ['normal control 1', [[2026, 10, 31], 'MF', [[2026, 10, 30], [2026, 11, 1], [2026, 11, 2]]], [2026, 10, 29]], ['normal control 2', [[2021, 12, 30], 'MP', [[2022, 1, 2]]], [2021, 12, 30]]], [['regression modified preceding guard 1', [[2029, 6, 3], 'MP', [[2029, 6, 6], [2029, 6, 2], [2029, 6, 1]]], [2029, 6, 4]], ['regression modified preceding guard 2', [[2028, 1, 2], 'MP', [[2028, 1, 1]]], [2028, 1, 3]], ['partial repair probe 1', [[2027, 8, 1], 'MP', [[2027, 8, 5], [2027, 8, 2], [2027, 8, 1]]], [2027, 8, 3]], ['partial repair probe 2', [[2025, 11, 3], 'MP', [[2025, 11, 6], [2025, 11, 3]]], [2025, 11, 4]], ['boundary control 1', [[2024, 5, 15], 'F', [[2024, 5, 15]]], [2024, 5, 16]], ['boundary control 2', [[2024, 12, 28], 'F', []], [2024, 12, 30]], ['normal control 1', [[2020, 12, 31], 'MP', [[2021, 1, 1], [2021, 1, 3]]], [2020, 12, 31]], ['normal control 2', [[2028, 4, 30], 'F', [[2028, 5, 3]]], [2028, 5, 1]]], [['regression modified preceding guard 1', [[2029, 12, 2], 'MP', []], [2029, 12, 3]], ['regression modified preceding guard 2', [[2027, 1, 1], 'MP', [[2027, 1, 1], [2026, 12, 31], [2027, 1, 1]]], [2027, 1, 4]], ['partial repair probe 1', [[2025, 10, 1], 'MP', [[2025, 10, 1], [2025, 10, 4], [2025, 10, 4]]], [2025, 10, 2]], ['partial repair probe 2', [[2029, 4, 1], 'MP', [[2029, 4, 2], [2029, 3, 29], [2029, 4, 1]]], [2029, 4, 3]], ['boundary control 1', [[2024, 3, 30], 'MF', []], [2024, 3, 29]], ['boundary control 2', [[2024, 5, 15], 'F', [[2024, 5, 15]]], [2024, 5, 16]], ['normal control 1', [[2021, 6, 2], 'MF', [[2021, 6, 5], [2021, 6, 4]]], [2021, 6, 2]], ['normal control 2', [[2027, 5, 31], 'MF', [[2027, 6, 1]]], [2027, 5, 31]]]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(*args), 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
import datetime
from fractions import Fraction
N = 1
observations = []
def solve(d, conv, holidays):
    D = datetime.date(*d)
    H = {datetime.date(*h) for h in holidays}
    def bad(x):
        return x.weekday() >= 5 or x in H
    def roll(x, step):
        while bad(x):
            x += datetime.timedelta(days=step)
        return x
    if conv == 'F':
        r = roll(D, 1)
    elif conv == 'MF':
        r = roll(D, 1)
        if r.month != D.month:
            r = roll(D, -1)
    elif conv == 'P':
        r = roll(D, -1)
    elif conv == 'MP':
        r = roll(D, -1)
        if r.year != D.year:
            r = roll(D, 1)
    elif conv == 'U':
        r = D
    else:
        return 'unknown convention'
    return [r.year, r.month, r.day]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression modified preceding guard 1', [[2028, 2, 1], 'MP', [[2028, 2, 1]]], [2028, 2, 2]], ['regression modified preceding guard 2', [[2022, 10, 1], 'MP', [[2022, 10, 1], [2022, 10, 1]]], [2022, 10, 3]], ['partial repair probe 1', [[2030, 3, 3], 'MP', [[2030, 3, 3], [2030, 3, 1], [2030, 3, 4]]], [2030, 3, 5]], ['partial repair probe 2', [[2024, 6, 1], 'MP', []], [2024, 6, 3]], ['boundary control 1', [[2024, 12, 28], 'F', []], [2024, 12, 30]], ['boundary control 2', [[2024, 5, 15], 'X', []], 'unknown convention'], ['normal control 1', [[2028, 8, 29], 'MF', [[2028, 8, 30]]], [2028, 8, 29]], ['normal control 2', [[2019, 10, 31], 'MF', [[2019, 10, 28], [2019, 11, 2], [2019, 11, 2]]], [2019, 10, 31]]], [['regression modified preceding guard 1', [[2023, 1, 1], 'MP', [[2023, 1, 5], [2022, 12, 31]]], [2023, 1, 2]], ['regression modified preceding guard 2', [[2019, 1, 2], 'MP', [[2019, 1, 2], [2019, 1, 1], [2019, 1, 3]]], [2019, 1, 4]], ['partial repair probe 1', [[2024, 6, 3], 'MP', [[2024, 6, 3], [2024, 6, 2]]], [2024, 6, 4]], ['partial repair probe 2', [[2025, 10, 1], 'MP', [[2025, 10, 2], [2025, 10, 5], [2025, 10, 1]]], [2025, 10, 3]], ['boundary control 1', [[2024, 5, 15], 'X', []], 'unknown convention'], ['boundary control 2', [[2024, 12, 28], 'F', []], [2024, 12, 30]], ['normal control 1', [[2025, 12, 29], 'MF', []], [2025, 12, 29]], ['normal control 2', [[2024, 6, 2], 'F', [[2024, 5, 30], [2024, 5, 31]]], [2024, 6, 3]]], [['regression modified preceding guard 1', [[2020, 3, 1], 'MP', [[2020, 2, 27]]], [2020, 3, 2]], ['regression modified preceding guard 2', [[2026, 3, 1], 'MP', [[2026, 3, 4], [2026, 2, 27], [2026, 3, 2]]], [2026, 3, 3]], ['partial repair probe 1', [[2019, 12, 1], 'MP', [[2019, 12, 1]]], [2019, 12, 2]], ['partial repair probe 2', [[2022, 10, 1], 'MP', [[2022, 10, 4], [2022, 10, 4], [2022, 10, 1]]], [2022, 10, 3]], ['boundary control 1', [[2024, 5, 15], 'X', []], 'unknown convention'], ['boundary control 2', [[2024, 12, 28], 'F', []], [2024, 12, 30]], ['normal control 1', [[2026, 10, 31], 'MF', [[2026, 10, 30], [2026, 11, 1], [2026, 11, 2]]], [2026, 10, 29]], ['normal control 2', [[2021, 12, 30], 'MP', [[2022, 1, 2]]], [2021, 12, 30]]], [['regression modified preceding guard 1', [[2029, 6, 3], 'MP', [[2029, 6, 6], [2029, 6, 2], [2029, 6, 1]]], [2029, 6, 4]], ['regression modified preceding guard 2', [[2028, 1, 2], 'MP', [[2028, 1, 1]]], [2028, 1, 3]], ['partial repair probe 1', [[2027, 8, 1], 'MP', [[2027, 8, 5], [2027, 8, 2], [2027, 8, 1]]], [2027, 8, 3]], ['partial repair probe 2', [[2025, 11, 3], 'MP', [[2025, 11, 6], [2025, 11, 3]]], [2025, 11, 4]], ['boundary control 1', [[2024, 5, 15], 'F', [[2024, 5, 15]]], [2024, 5, 16]], ['boundary control 2', [[2024, 12, 28], 'F', []], [2024, 12, 30]], ['normal control 1', [[2020, 12, 31], 'MP', [[2021, 1, 1], [2021, 1, 3]]], [2020, 12, 31]], ['normal control 2', [[2028, 4, 30], 'F', [[2028, 5, 3]]], [2028, 5, 1]]], [['regression modified preceding guard 1', [[2029, 12, 2], 'MP', []], [2029, 12, 3]], ['regression modified preceding guard 2', [[2027, 1, 1], 'MP', [[2027, 1, 1], [2026, 12, 31], [2027, 1, 1]]], [2027, 1, 4]], ['partial repair probe 1', [[2025, 10, 1], 'MP', [[2025, 10, 1], [2025, 10, 4], [2025, 10, 4]]], [2025, 10, 2]], ['partial repair probe 2', [[2029, 4, 1], 'MP', [[2029, 4, 2], [2029, 3, 29], [2029, 4, 1]]], [2029, 4, 3]], ['boundary control 1', [[2024, 3, 30], 'MF', []], [2024, 3, 29]], ['boundary control 2', [[2024, 5, 15], 'F', [[2024, 5, 15]]], [2024, 5, 16]], ['normal control 1', [[2021, 6, 2], 'MF', [[2021, 6, 5], [2021, 6, 4]]], [2021, 6, 2]], ['normal control 2', [[2027, 5, 31], 'MF', [[2027, 6, 1]]], [2027, 5, 31]]]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(*args), 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:
Dates at the start of a month roll back into the previous month.

Inputs a date [y,m,d], a convention code and a list of holiday dates. Saturdays, Sundays and holidays are non-business days. F rolls forward, P rolls back, MF rolls forward unless that changes the month in which case it rolls back, MP rolls back unless that changes the month in which case it rolls forward, U leaves the date unadjusted; other codes return "unknown convention". Return the adjusted [y,m,d].

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import datetime
from fractions import Fraction
N = 1
observations = []
def solve(d, conv, holidays):
    D = datetime.date(*d)
    H = [h for h in holidays]
    def bad(x):
        return x.weekday() >= 5 or x in H
    def roll(x, step):
        while bad(x):
            x += datetime.timedelta(days=step)
        return x
    if conv == 'F':
        r = roll(D, 1)
    elif conv == 'MF':
        r = roll(D, 1)
        if r.month != D.month:
            r = roll(D, -1)
    elif conv == 'P':
        r = roll(D, -1)
    elif conv == 'MP':
        r = roll(D, -1)
        if r.month != D.month:
            r = roll(D, 1)
    elif conv == 'U':
        r = D
    else:
        return 'unknown convention'
    return [r.year, r.month, r.day]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression holiday membership type 1', [[2022, 7, 31], 'P', [[2022, 8, 2], [2022, 7, 29], [2022, 7, 31]]], [2022, 7, 28]], ['regression holiday membership type 2', [[2030, 9, 29], 'MP', [[2030, 9, 29], [2030, 9, 27], [2030, 10, 1]]], [2030, 9, 26]], ['partial repair probe 1', [[2024, 12, 31], 'MF', [[2024, 12, 28], [2024, 12, 31], [2025, 1, 2]]], [2024, 12, 30]], ['partial repair probe 2', [[2026, 12, 31], 'MF', [[2026, 12, 31]]], [2026, 12, 30]], ['boundary control 1', [[2024, 6, 1], 'MP', []], [2024, 6, 3]], ['boundary control 2', [[2024, 12, 28], 'F', []], [2024, 12, 30]], ['normal control 1', [[2030, 12, 31], 'MP', [[2031, 1, 4], [2031, 1, 4]]], [2030, 12, 31]], ['normal control 2', [[2023, 8, 29], 'P', [[2023, 8, 26]]], [2023, 8, 29]]], [['regression holiday membership type 1', [[2024, 12, 31], 'MF', [[2024, 12, 31], [2024, 12, 31], [2024, 12, 29]]], [2024, 12, 30]], ['regression holiday membership type 2', [[2023, 6, 3], 'F', [[2023, 6, 6], [2023, 6, 5]]], [2023, 6, 7]], ['partial repair probe 1', [[2023, 3, 30], 'P', [[2023, 3, 30], [2023, 4, 2]]], [2023, 3, 29]], ['partial repair probe 2', [[2026, 11, 14], 'MP', [[2026, 11, 13]]], [2026, 11, 12]], ['boundary control 1', [[2024, 12, 28], 'F', []], [2024, 12, 30]], ['boundary control 2', [[2024, 5, 15], 'X', []], 'unknown convention'], ['normal control 1', [[2019, 4, 29], 'F', []], [2019, 4, 29]], ['normal control 2', [[2023, 2, 28], 'F', [[2023, 3, 2], [2023, 2, 25], [2023, 2, 25]]], [2023, 2, 28]]], [['regression holiday membership type 1', [[2029, 4, 30], 'MF', [[2029, 4, 28], [2029, 4, 30], [2029, 5, 2]]], [2029, 4, 27]], ['regression holiday membership type 2', [[2021, 5, 31], 'MF', [[2021, 5, 28], [2021, 6, 1], [2021, 5, 31]]], [2021, 5, 27]], ['partial repair probe 1', [[2028, 12, 1], 'MP', [[2028, 12, 2], [2028, 12, 5], [2028, 12, 1]]], [2028, 12, 4]], ['partial repair probe 2', [[2023, 3, 1], 'MF', [[2023, 3, 1], [2023, 3, 5]]], [2023, 3, 2]], ['boundary control 1', [[2024, 6, 1], 'MP', []], [2024, 6, 3]], ['boundary control 2', [[2024, 3, 30], 'MF', []], [2024, 3, 29]], ['normal control 1', [[2026, 5, 31], 'F', []], [2026, 6, 1]], ['normal control 2', [[2022, 1, 1], 'X', [[2022, 1, 4], [2022, 1, 2], [2022, 1, 3]]], 'unknown convention']], [['regression holiday membership type 1', [[2030, 1, 30], 'MF', [[2030, 1, 30], [2030, 2, 3]]], [2030, 1, 31]], ['regression holiday membership type 2', [[2026, 3, 24], 'MF', [[2026, 3, 24]]], [2026, 3, 25]], ['partial repair probe 1', [[2025, 10, 9], 'P', [[2025, 10, 9], [2025, 10, 7]]], [2025, 10, 8]], ['partial repair probe 2', [[2020, 8, 31], 'MF', [[2020, 8, 31], [2020, 8, 28], [2020, 9, 3]]], [2020, 8, 27]], ['boundary control 1', [[2024, 12, 28], 'F', []], [2024, 12, 30]], ['boundary control 2', [[2024, 3, 30], 'MF', []], [2024, 3, 29]], ['normal control 1', [[2024, 3, 20], 'X', [[2024, 3, 21]]], 'unknown convention'], ['normal control 2', [[2021, 1, 2], 'P', [[2021, 1, 5]]], [2021, 1, 1]]], [['regression holiday membership type 1', [[2027, 6, 30], 'MP', [[2027, 7, 3], [2027, 6, 27], [2027, 6, 30]]], [2027, 6, 29]], ['regression holiday membership type 2', [[2026, 6, 6], 'F', [[2026, 6, 9], [2026, 6, 8], [2026, 6, 10]]], [2026, 6, 11]], ['partial repair probe 1', [[2026, 2, 27], 'MP', [[2026, 2, 27], [2026, 2, 27]]], [2026, 2, 26]], ['partial repair probe 2', [[2024, 11, 10], 'F', [[2024, 11, 8], [2024, 11, 13], [2024, 11, 11]]], [2024, 11, 12]], ['boundary control 1', [[2024, 12, 28], 'F', []], [2024, 12, 30]], ['boundary control 2', [[2024, 6, 1], 'MP', []], [2024, 6, 3]], ['normal control 1', [[2021, 7, 31], 'X', [[2021, 7, 30]]], 'unknown convention'], ['normal control 2', [[2029, 10, 31], 'X', [[2029, 11, 3], [2029, 11, 3]]], 'unknown convention']]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(*args), 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
import datetime
from fractions import Fraction
N = 1
observations = []
def solve(d, conv, holidays):
    D = datetime.date(*d)
    H = {datetime.date(*h).isoformat() for h in holidays}
    def bad(x):
        return x.weekday() >= 5 or x in H
    def roll(x, step):
        while bad(x):
            x += datetime.timedelta(days=step)
        return x
    if conv == 'F':
        r = roll(D, 1)
    elif conv == 'MF':
        r = roll(D, 1)
        if r.month != D.month:
            r = roll(D, -1)
    elif conv == 'P':
        r = roll(D, -1)
    elif conv == 'MP':
        r = roll(D, -1)
        if r.month != D.month:
            r = roll(D, 1)
    elif conv == 'U':
        r = D
    else:
        return 'unknown convention'
    return [r.year, r.month, r.day]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression holiday membership type 1', [[2022, 7, 31], 'P', [[2022, 8, 2], [2022, 7, 29], [2022, 7, 31]]], [2022, 7, 28]], ['regression holiday membership type 2', [[2030, 9, 29], 'MP', [[2030, 9, 29], [2030, 9, 27], [2030, 10, 1]]], [2030, 9, 26]], ['partial repair probe 1', [[2024, 12, 31], 'MF', [[2024, 12, 28], [2024, 12, 31], [2025, 1, 2]]], [2024, 12, 30]], ['partial repair probe 2', [[2026, 12, 31], 'MF', [[2026, 12, 31]]], [2026, 12, 30]], ['boundary control 1', [[2024, 6, 1], 'MP', []], [2024, 6, 3]], ['boundary control 2', [[2024, 12, 28], 'F', []], [2024, 12, 30]], ['normal control 1', [[2030, 12, 31], 'MP', [[2031, 1, 4], [2031, 1, 4]]], [2030, 12, 31]], ['normal control 2', [[2023, 8, 29], 'P', [[2023, 8, 26]]], [2023, 8, 29]]], [['regression holiday membership type 1', [[2024, 12, 31], 'MF', [[2024, 12, 31], [2024, 12, 31], [2024, 12, 29]]], [2024, 12, 30]], ['regression holiday membership type 2', [[2023, 6, 3], 'F', [[2023, 6, 6], [2023, 6, 5]]], [2023, 6, 7]], ['partial repair probe 1', [[2023, 3, 30], 'P', [[2023, 3, 30], [2023, 4, 2]]], [2023, 3, 29]], ['partial repair probe 2', [[2026, 11, 14], 'MP', [[2026, 11, 13]]], [2026, 11, 12]], ['boundary control 1', [[2024, 12, 28], 'F', []], [2024, 12, 30]], ['boundary control 2', [[2024, 5, 15], 'X', []], 'unknown convention'], ['normal control 1', [[2019, 4, 29], 'F', []], [2019, 4, 29]], ['normal control 2', [[2023, 2, 28], 'F', [[2023, 3, 2], [2023, 2, 25], [2023, 2, 25]]], [2023, 2, 28]]], [['regression holiday membership type 1', [[2029, 4, 30], 'MF', [[2029, 4, 28], [2029, 4, 30], [2029, 5, 2]]], [2029, 4, 27]], ['regression holiday membership type 2', [[2021, 5, 31], 'MF', [[2021, 5, 28], [2021, 6, 1], [2021, 5, 31]]], [2021, 5, 27]], ['partial repair probe 1', [[2028, 12, 1], 'MP', [[2028, 12, 2], [2028, 12, 5], [2028, 12, 1]]], [2028, 12, 4]], ['partial repair probe 2', [[2023, 3, 1], 'MF', [[2023, 3, 1], [2023, 3, 5]]], [2023, 3, 2]], ['boundary control 1', [[2024, 6, 1], 'MP', []], [2024, 6, 3]], ['boundary control 2', [[2024, 3, 30], 'MF', []], [2024, 3, 29]], ['normal control 1', [[2026, 5, 31], 'F', []], [2026, 6, 1]], ['normal control 2', [[2022, 1, 1], 'X', [[2022, 1, 4], [2022, 1, 2], [2022, 1, 3]]], 'unknown convention']], [['regression holiday membership type 1', [[2030, 1, 30], 'MF', [[2030, 1, 30], [2030, 2, 3]]], [2030, 1, 31]], ['regression holiday membership type 2', [[2026, 3, 24], 'MF', [[2026, 3, 24]]], [2026, 3, 25]], ['partial repair probe 1', [[2025, 10, 9], 'P', [[2025, 10, 9], [2025, 10, 7]]], [2025, 10, 8]], ['partial repair probe 2', [[2020, 8, 31], 'MF', [[2020, 8, 31], [2020, 8, 28], [2020, 9, 3]]], [2020, 8, 27]], ['boundary control 1', [[2024, 12, 28], 'F', []], [2024, 12, 30]], ['boundary control 2', [[2024, 3, 30], 'MF', []], [2024, 3, 29]], ['normal control 1', [[2024, 3, 20], 'X', [[2024, 3, 21]]], 'unknown convention'], ['normal control 2', [[2021, 1, 2], 'P', [[2021, 1, 5]]], [2021, 1, 1]]], [['regression holiday membership type 1', [[2027, 6, 30], 'MP', [[2027, 7, 3], [2027, 6, 27], [2027, 6, 30]]], [2027, 6, 29]], ['regression holiday membership type 2', [[2026, 6, 6], 'F', [[2026, 6, 9], [2026, 6, 8], [2026, 6, 10]]], [2026, 6, 11]], ['partial repair probe 1', [[2026, 2, 27], 'MP', [[2026, 2, 27], [2026, 2, 27]]], [2026, 2, 26]], ['partial repair probe 2', [[2024, 11, 10], 'F', [[2024, 11, 8], [2024, 11, 13], [2024, 11, 11]]], [2024, 11, 12]], ['boundary control 1', [[2024, 12, 28], 'F', []], [2024, 12, 30]], ['boundary control 2', [[2024, 6, 1], 'MP', []], [2024, 6, 3]], ['normal control 1', [[2021, 7, 31], 'X', [[2021, 7, 30]]], 'unknown convention'], ['normal control 2', [[2029, 10, 31], 'X', [[2029, 11, 3], [2029, 11, 3]]], 'unknown convention']]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(*args), 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:
Holidays are never honored, only weekends.

Inputs a date [y,m,d], a convention code and a list of holiday dates. Saturdays, Sundays and holidays are non-business days. F rolls forward, P rolls back, MF rolls forward unless that changes the month in which case it rolls back, MP rolls back unless that changes the month in which case it rolls forward, U leaves the date unadjusted; other codes return "unknown convention". Return the adjusted [y,m,d].

split: open-access


prompt:
Rates published before weekends and holidays are under-weighted and the coupon is too low.

Inputs start, end (business days), a map from ISO date to overnight rate in percent, a lookback in business days, a spread in percent and holidays. Business days are weekdays not in holidays. For each business day d in [start, end), weight n = calendar days to the next business day (or to end for the last one) and rate = the rate published L business days before d. Compound prod(1 + r/100*n/360); the period rate is (prod-1)*360/calendar days*100 plus the spread, rounded to 6 decimals.

split: open-access


prompt:
Monday accruals observe a rate one business day too recent.

Inputs start, end (business days), a map from ISO date to overnight rate in percent, a lookback in business days, a spread in percent and holidays. Business days are weekdays not in holidays. For each business day d in [start, end), weight n = calendar days to the next business day (or to end for the last one) and rate = the rate published L business days before d. Compound prod(1 + r/100*n/360); the period rate is (prod-1)*360/calendar days*100 plus the spread, rounded to 6 decimals.

split: open-access


prompt:
Coupons are several times too large for periods containing weekends.

Inputs start, end (business days), a map from ISO date to overnight rate in percent, a lookback in business days, a spread in percent and holidays. Business days are weekdays not in holidays. For each business day d in [start, end), weight n = calendar days to the next business day (or to end for the last one) and rate = the rate published L business days before d. Compound prod(1 + r/100*n/360); the period rate is (prod-1)*360/calendar days*100 plus the spread, rounded to 6 decimals.

split: open-access


prompt:
The coupon includes spread-on-rate compounding that the contract excludes.

Inputs start, end (business days), a map from ISO date to overnight rate in percent, a lookback in business days, a spread in percent and holidays. Business days are weekdays not in holidays. For each business day d in [start, end), weight n = calendar days to the next business day (or to end for the last one) and rate = the rate published L business days before d. Compound prod(1 + r/100*n/360); the period rate is (prod-1)*360/calendar days*100 plus the spread, rounded to 6 decimals.

split: open-access


prompt:
The compounded factor is too small and the period rate is understated.

Inputs start, end (business days), a map from ISO date to overnight rate in percent, a lookback in business days, a spread in percent and holidays. Business days are weekdays not in holidays. For each business day d in [start, end), weight n = calendar days to the next business day (or to end for the last one) and rate = the rate published L business days before d. Compound prod(1 + r/100*n/360); the period rate is (prod-1)*360/calendar days*100 plus the spread, rounded to 6 decimals.

split: open-access


prompt:
Periods ending after a weekend or holiday lose accrual for the final days.

Inputs start, end (business days), a map from ISO date to overnight rate in percent, a lookback in business days, a spread in percent and holidays. Business days are weekdays not in holidays. For each business day d in [start, end), weight n = calendar days to the next business day (or to end for the last one) and rate = the rate published L business days before d. Compound prod(1 + r/100*n/360); the period rate is (prod-1)*360/calendar days*100 plus the spread, rounded to 6 decimals.

split: open-access


prompt:
Spans of more than four years are overstated by the extra leap days.

Inputs start and end [y,m,d]. If end < start return "end before start". Days are actual days minus the number of 29 February dates lying in (start, end]. Return [days, days/365 rounded to 9 decimals].

split: open-access


prompt:
A span from March of a leap year to its December loses a day that it never contained.

Inputs start and end [y,m,d]. If end < start return "end before start". Days are actual days minus the number of 29 February dates lying in (start, end]. Return [days, days/365 rounded to 9 decimals].

split: open-access


prompt:
The two returned values disagree whenever a leap day falls inside the span.

Inputs start and end [y,m,d]. If end < start return "end before start". Days are actual days minus the number of 29 February dates lying in (start, end]. Return [days, days/365 rounded to 9 decimals].

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import datetime
from fractions import Fraction
N = 1
observations = []
def solve(issue, first, settle, rate, months):
    def mlen(y, m):
        if m == 2:
            return 29 if (y % 4 == 0 and y % 100 != 0) or y % 400 == 0 else 28
        return 30 if m in (4, 6, 9, 11) else 31
    I = datetime.date(*issue)
    Fc = datetime.date(*first)
    S = datetime.date(*settle)
    if not (I <= S <= Fc):
        return 'settlement outside first period'
    freq = 12 // months
    def back(k):
        t = Fc.year * 12 + Fc.month - 1 - k * months
        y, m = t // 12, t % 12 + 1
        return datetime.date(y, m, min(Fc.day, mlen(y, m)))
    q = [Fc]
    k = 1
    while q[-1] > I:
        q.append(back(k))
        k += 1
    frac = Fraction(0)
    frac = Fraction((S - I).days, (Fc - q[1]).days)
    return round(float(100 * Fraction(str(rate)) / freq * frac), 6)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression long period denominator 1', [[2035, 3, 1], [2036, 10, 31], [2035, 6, 11], 0.08, 12], 2.235616], ['regression long period denominator 2', [[2014, 1, 18], [2014, 6, 30], [2014, 6, 25], 0.0675, 3], 2.927038], ['partial repair probe 1', [[2026, 7, 10], [2027, 7, 24], [2027, 5, 13], 0.045, 12], 3.784932], ['partial repair probe 2', [[2007, 5, 31], [2007, 9, 30], [2007, 9, 10], 0.045, 6], 1.247283], ['boundary control 1', [[2024, 3, 15], [2024, 9, 15], [2024, 6, 15], 0.05, 6], 1.25], ['boundary control 2', [[2024, 1, 10], [2024, 9, 15], [2024, 9, 16], 0.05, 6], 'settlement outside first period'], ['normal control 1', [[2030, 12, 1], [2030, 12, 25], [2030, 11, 28], 0.045, 1], 'settlement outside first period'], ['normal control 2', [[2011, 8, 6], [2013, 1, 29], [2011, 8, 3], 0.045, 6], 'settlement outside first period']], [['regression long period denominator 1', [[2026, 6, 29], [2027, 12, 28], [2027, 3, 29], 0.05, 6], 3.736339], ['regression long period denominator 2', [[2020, 9, 30], [2021, 10, 30], [2021, 7, 11], 0.0675, 6], 5.256148], ['partial repair probe 1', [[2034, 5, 27], [2035, 1, 31], [2034, 9, 6], 0.02, 12], 0.558904], ['partial repair probe 2', [[2005, 3, 11], [2005, 8, 16], [2005, 4, 24], 0.05, 6], 0.607735], ['boundary control 1', [[2024, 3, 15], [2024, 9, 15], [2024, 6, 15], 0.05, 6], 1.25], ['boundary control 2', [[2024, 1, 10], [2024, 9, 15], [2024, 9, 16], 0.05, 6], 'settlement outside first period'], ['normal control 1', [[2021, 4, 20], [2021, 4, 30], [2021, 4, 20], 0.0675, 1], 0.0], ['normal control 2', [[2011, 6, 28], [2011, 7, 5], [2011, 6, 25], 0.045, 1], 'settlement outside first period']], [['regression long period denominator 1', [[2006, 2, 8], [2006, 3, 23], [2006, 3, 1], 0.045, 1], 0.261809], ['regression long period denominator 2', [[2004, 10, 16], [2005, 9, 5], [2004, 11, 30], 0.08, 6], 0.994475], ['partial repair probe 1', [[2020, 11, 13], [2020, 12, 31], [2020, 12, 31], 0.03, 3], 0.391304], ['partial repair probe 2', [[2042, 7, 29], [2043, 1, 31], [2042, 12, 9], 0.0675, 12], 2.459589], ['boundary control 1', [[2024, 1, 10], [2024, 9, 15], [2024, 9, 16], 0.05, 6], 'settlement outside first period'], ['boundary control 2', [[2024, 3, 15], [2024, 9, 15], [2024, 6, 15], 0.05, 6], 1.25], ['normal control 1', [[2041, 6, 16], [2041, 8, 30], [2041, 6, 13], 0.08, 12], 'settlement outside first period'], ['normal control 2', [[2005, 1, 10], [2005, 1, 31], [2005, 1, 10], 0.045, 3], 0.0]], [['regression long period denominator 1', [[2036, 7, 10], [2037, 2, 28], [2037, 2, 16], 0.0675, 6], 4.063545], ['regression long period denominator 2', [[2006, 9, 2], [2007, 3, 12], [2006, 12, 9], 0.045, 6], 1.216205], ['partial repair probe 1', [[2029, 5, 22], [2029, 7, 31], [2029, 7, 11], 0.0675, 6], 0.93232], ['partial repair probe 2', [[2033, 9, 26], [2034, 2, 28], [2033, 10, 19], 0.0675, 3], 0.421875], ['boundary control 1', [[2024, 1, 10], [2024, 9, 15], [2024, 9, 16], 0.05, 6], 'settlement outside first period'], ['boundary control 2', [[2024, 3, 15], [2024, 9, 15], [2024, 6, 15], 0.05, 6], 1.25], ['normal control 1', [[2004, 9, 16], [2004, 9, 30], [2004, 9, 16], 0.045, 3], 0.0], ['normal control 2', [[2035, 5, 9], [2035, 6, 30], [2035, 5, 6], 0.03, 6], 'settlement outside first period']], [['regression long period denominator 1', [[2019, 3, 16], [2019, 4, 30], [2019, 4, 4], 0.03, 1], 0.156989], ['regression long period denominator 2', [[2039, 4, 20], [2039, 6, 30], [2039, 5, 24], 0.02, 1], 0.187097], ['partial repair probe 1', [[2031, 8, 23], [2031, 12, 28], [2031, 9, 3], 0.045, 6], 0.135246], ['partial repair probe 2', [[2017, 9, 1], [2018, 2, 28], [2018, 2, 6], 0.0675, 12], 2.921918], ['boundary control 1', [[2024, 3, 15], [2024, 9, 15], [2024, 6, 15], 0.05, 6], 1.25], ['boundary control 2', [[2024, 1, 10], [2024, 9, 15], [2024, 9, 16], 0.05, 6], 'settlement outside first period'], ['normal control 1', [[2034, 7, 30], [2034, 11, 30], [2034, 7, 27], 0.045, 12], 'settlement outside first period'], ['normal control 2', [[2041, 1, 14], [2041, 1, 24], [2041, 1, 14], 0.03, 1], 0.0]]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(*args), 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
import datetime
from fractions import Fraction
N = 1
observations = []
def solve(issue, first, settle, rate, months):
    def mlen(y, m):
        if m == 2:
            return 29 if (y % 4 == 0 and y % 100 != 0) or y % 400 == 0 else 28
        return 30 if m in (4, 6, 9, 11) else 31
    I = datetime.date(*issue)
    Fc = datetime.date(*first)
    S = datetime.date(*settle)
    if not (I <= S <= Fc):
        return 'settlement outside first period'
    freq = 12 // months
    def back(k):
        t = Fc.year * 12 + Fc.month - 1 - k * months
        y, m = t // 12, t % 12 + 1
        return datetime.date(y, m, min(Fc.day, mlen(y, m)))
    q = [Fc]
    k = 1
    while q[-1] > I:
        q.append(back(k))
        k += 1
    frac = Fraction(0)
    frac = Fraction((S - I).days, (Fc - I).days)
    return round(float(100 * Fraction(str(rate)) / freq * frac), 6)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression long period denominator 1', [[2035, 3, 1], [2036, 10, 31], [2035, 6, 11], 0.08, 12], 2.235616], ['regression long period denominator 2', [[2014, 1, 18], [2014, 6, 30], [2014, 6, 25], 0.0675, 3], 2.927038], ['partial repair probe 1', [[2026, 7, 10], [2027, 7, 24], [2027, 5, 13], 0.045, 12], 3.784932], ['partial repair probe 2', [[2007, 5, 31], [2007, 9, 30], [2007, 9, 10], 0.045, 6], 1.247283], ['boundary control 1', [[2024, 3, 15], [2024, 9, 15], [2024, 6, 15], 0.05, 6], 1.25], ['boundary control 2', [[2024, 1, 10], [2024, 9, 15], [2024, 9, 16], 0.05, 6], 'settlement outside first period'], ['normal control 1', [[2030, 12, 1], [2030, 12, 25], [2030, 11, 28], 0.045, 1], 'settlement outside first period'], ['normal control 2', [[2011, 8, 6], [2013, 1, 29], [2011, 8, 3], 0.045, 6], 'settlement outside first period']], [['regression long period denominator 1', [[2026, 6, 29], [2027, 12, 28], [2027, 3, 29], 0.05, 6], 3.736339], ['regression long period denominator 2', [[2020, 9, 30], [2021, 10, 30], [2021, 7, 11], 0.0675, 6], 5.256148], ['partial repair probe 1', [[2034, 5, 27], [2035, 1, 31], [2034, 9, 6], 0.02, 12], 0.558904], ['partial repair probe 2', [[2005, 3, 11], [2005, 8, 16], [2005, 4, 24], 0.05, 6], 0.607735], ['boundary control 1', [[2024, 3, 15], [2024, 9, 15], [2024, 6, 15], 0.05, 6], 1.25], ['boundary control 2', [[2024, 1, 10], [2024, 9, 15], [2024, 9, 16], 0.05, 6], 'settlement outside first period'], ['normal control 1', [[2021, 4, 20], [2021, 4, 30], [2021, 4, 20], 0.0675, 1], 0.0], ['normal control 2', [[2011, 6, 28], [2011, 7, 5], [2011, 6, 25], 0.045, 1], 'settlement outside first period']], [['regression long period denominator 1', [[2006, 2, 8], [2006, 3, 23], [2006, 3, 1], 0.045, 1], 0.261809], ['regression long period denominator 2', [[2004, 10, 16], [2005, 9, 5], [2004, 11, 30], 0.08, 6], 0.994475], ['partial repair probe 1', [[2020, 11, 13], [2020, 12, 31], [2020, 12, 31], 0.03, 3], 0.391304], ['partial repair probe 2', [[2042, 7, 29], [2043, 1, 31], [2042, 12, 9], 0.0675, 12], 2.459589], ['boundary control 1', [[2024, 1, 10], [2024, 9, 15], [2024, 9, 16], 0.05, 6], 'settlement outside first period'], ['boundary control 2', [[2024, 3, 15], [2024, 9, 15], [2024, 6, 15], 0.05, 6], 1.25], ['normal control 1', [[2041, 6, 16], [2041, 8, 30], [2041, 6, 13], 0.08, 12], 'settlement outside first period'], ['normal control 2', [[2005, 1, 10], [2005, 1, 31], [2005, 1, 10], 0.045, 3], 0.0]], [['regression long period denominator 1', [[2036, 7, 10], [2037, 2, 28], [2037, 2, 16], 0.0675, 6], 4.063545], ['regression long period denominator 2', [[2006, 9, 2], [2007, 3, 12], [2006, 12, 9], 0.045, 6], 1.216205], ['partial repair probe 1', [[2029, 5, 22], [2029, 7, 31], [2029, 7, 11], 0.0675, 6], 0.93232], ['partial repair probe 2', [[2033, 9, 26], [2034, 2, 28], [2033, 10, 19], 0.0675, 3], 0.421875], ['boundary control 1', [[2024, 1, 10], [2024, 9, 15], [2024, 9, 16], 0.05, 6], 'settlement outside first period'], ['boundary control 2', [[2024, 3, 15], [2024, 9, 15], [2024, 6, 15], 0.05, 6], 1.25], ['normal control 1', [[2004, 9, 16], [2004, 9, 30], [2004, 9, 16], 0.045, 3], 0.0], ['normal control 2', [[2035, 5, 9], [2035, 6, 30], [2035, 5, 6], 0.03, 6], 'settlement outside first period']], [['regression long period denominator 1', [[2019, 3, 16], [2019, 4, 30], [2019, 4, 4], 0.03, 1], 0.156989], ['regression long period denominator 2', [[2039, 4, 20], [2039, 6, 30], [2039, 5, 24], 0.02, 1], 0.187097], ['partial repair probe 1', [[2031, 8, 23], [2031, 12, 28], [2031, 9, 3], 0.045, 6], 0.135246], ['partial repair probe 2', [[2017, 9, 1], [2018, 2, 28], [2018, 2, 6], 0.0675, 12], 2.921918], ['boundary control 1', [[2024, 3, 15], [2024, 9, 15], [2024, 6, 15], 0.05, 6], 1.25], ['boundary control 2', [[2024, 1, 10], [2024, 9, 15], [2024, 9, 16], 0.05, 6], 'settlement outside first period'], ['normal control 1', [[2034, 7, 30], [2034, 11, 30], [2034, 7, 27], 0.045, 12], 'settlement outside first period'], ['normal control 2', [[2041, 1, 14], [2041, 1, 24], [2041, 1, 14], 0.03, 1], 0.0]]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(*args), 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:
Accrued interest on long first coupons exceeds the per-period coupon once more than one quasi period has passed.

Inputs issue, first coupon and settlement [y,m,d], annual rate and months per period. Settlement must lie in [issue, first] else return "settlement outside first period". Quasi-coupon dates are generated back from the first coupon in steps of months (day clamped to month length) until one is on or before issue. For each quasi period [start, end), accrued days are those in [max(start, issue), min(end, settle)) and are divided by that quasi period length. Accrued = 100*rate/freq*sum, rounded to 6 decimals.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import datetime
from fractions import Fraction
N = 1
observations = []
def solve(issue, first, settle, rate, months):
    def mlen(y, m):
        if m == 2:
            return 29 if (y % 4 == 0 and y % 100 != 0) or y % 400 == 0 else 28
        return 30 if m in (4, 6, 9, 11) else 31
    I = datetime.date(*issue)
    Fc = datetime.date(*first)
    S = datetime.date(*settle)
    if not (I <= S <= Fc):
        return 'settlement outside first period'
    freq = 12 // months
    def back(k):
        t = Fc.year * 12 + Fc.month - 1 - k * months
        y, m = t // 12, t % 12 + 1
        return datetime.date(y, m, min(Fc.day, mlen(y, m)))
    q = [Fc]
    k = 1
    while q[-1] > I:
        q.append(back(k))
        k += 1
    frac = Fraction(0)
    for j in range(len(q) - 1):
        end, start = q[j], q[j + 1]
        lo = start
        hi = min(end, S)
        if hi > lo:
            frac += Fraction((hi - lo).days, (end - start).days)
    return round(float(100 * Fraction(str(rate)) / freq * frac), 6)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression issue date clipping 1', [[2006, 8, 4], [2006, 9, 30], [2006, 8, 13], 0.05, 3], 0.122283], ['regression issue date clipping 2', [[2038, 5, 29], [2038, 7, 25], [2038, 7, 24], 0.045, 3], 0.692308], ['partial repair probe 1', [[2028, 3, 6], [2028, 4, 26], [2028, 3, 15], 0.03, 1], 0.077586], ['partial repair probe 2', [[2027, 7, 30], [2028, 9, 30], [2028, 5, 25], 0.05, 6], 4.103261], ['boundary control 1', [[2024, 1, 10], [2024, 9, 15], [2024, 9, 16], 0.05, 6], 'settlement outside first period'], ['boundary control 2', [[2024, 3, 15], [2024, 9, 15], [2024, 6, 15], 0.05, 6], 1.25], ['normal control 1', [[2042, 4, 28], [2043, 1, 30], [2042, 4, 25], 0.0675, 3], 'settlement outside first period'], ['normal control 2', [[2044, 7, 14], [2044, 11, 30], [2044, 7, 11], 0.02, 12], 'settlement outside first period']], [['regression issue date clipping 1', [[2044, 7, 14], [2045, 2, 28], [2044, 10, 28], 0.02, 12], 0.579235], ['regression issue date clipping 2', [[2012, 3, 21], [2012, 4, 30], [2012, 4, 2], 0.05, 3], 0.164835], ['partial repair probe 1', [[2026, 5, 8], [2026, 8, 31], [2026, 5, 21], 0.02, 3], 0.070652], ['partial repair probe 2', [[2025, 3, 10], [2026, 2, 21], [2025, 8, 17], 0.08, 6], 3.535912], ['boundary control 1', [[2024, 3, 15], [2024, 9, 15], [2024, 6, 15], 0.05, 6], 1.25], ['boundary control 2', [[2024, 1, 10], [2024, 9, 15], [2024, 9, 16], 0.05, 6], 'settlement outside first period'], ['normal control 1', [[2035, 5, 29], [2035, 6, 6], [2035, 5, 26], 0.0675, 6], 'settlement outside first period'], ['normal control 2', [[2039, 12, 17], [2040, 7, 20], [2039, 12, 14], 0.0675, 3], 'settlement outside first period']], [['regression issue date clipping 1', [[2006, 4, 30], [2007, 1, 26], [2006, 10, 15], 0.03, 3], 1.377359], ['regression issue date clipping 2', [[2023, 8, 31], [2023, 10, 1], [2023, 9, 15], 0.03, 1], 0.124731], ['partial repair probe 1', [[2009, 5, 24], [2010, 7, 10], [2010, 5, 8], 0.0675, 6], 6.451657], ['partial repair probe 2', [[2018, 2, 9], [2018, 5, 31], [2018, 3, 13], 0.03, 3], 0.264312], ['boundary control 1', [[2024, 1, 10], [2024, 9, 15], [2024, 9, 16], 0.05, 6], 'settlement outside first period'], ['boundary control 2', [[2024, 3, 15], [2024, 9, 15], [2024, 6, 15], 0.05, 6], 1.25], ['normal control 1', [[2002, 6, 12], [2003, 1, 5], [2002, 6, 9], 0.03, 6], 'settlement outside first period'], ['normal control 2', [[2036, 11, 9], [2036, 11, 19], [2036, 11, 6], 0.02, 6], 'settlement outside first period']], [['regression issue date clipping 1', [[2034, 5, 16], [2034, 6, 30], [2034, 6, 17], 0.05, 12], 0.438356], ['regression issue date clipping 2', [[2003, 5, 14], [2003, 5, 31], [2003, 5, 14], 0.045, 3], 0.0], ['partial repair probe 1', [[2032, 5, 30], [2032, 8, 31], [2032, 6, 4], 0.05, 1], 0.068996], ['partial repair probe 2', [[2021, 12, 10], [2022, 4, 30], [2022, 1, 18], 0.08, 3], 0.847826], ['boundary control 1', [[2024, 1, 10], [2024, 9, 15], [2024, 9, 16], 0.05, 6], 'settlement outside first period'], ['boundary control 2', [[2024, 3, 15], [2024, 9, 15], [2024, 6, 15], 0.05, 6], 1.25], ['normal control 1', [[2010, 9, 22], [2011, 2, 14], [2010, 9, 19], 0.05, 3], 'settlement outside first period'], ['normal control 2', [[2021, 3, 4], [2021, 5, 30], [2021, 3, 1], 0.045, 3], 'settlement outside first period']], [['regression issue date clipping 1', [[2018, 9, 26], [2019, 1, 30], [2019, 1, 26], 0.08, 3], 2.652174], ['regression issue date clipping 2', [[2001, 4, 14], [2002, 7, 31], [2002, 1, 21], 0.08, 6], 6.169349], ['partial repair probe 1', [[2020, 8, 28], [2020, 10, 22], [2020, 9, 25], 0.0675, 1], 0.509879], ['partial repair probe 2', [[2041, 11, 21], [2044, 4, 12], [2042, 9, 9], 0.02, 12], 1.6], ['boundary control 1', [[2024, 1, 10], [2024, 9, 15], [2024, 9, 16], 0.05, 6], 'settlement outside first period'], ['boundary control 2', [[2024, 3, 15], [2024, 9, 15], [2024, 6, 15], 0.05, 6], 1.25], ['normal control 1', [[2031, 4, 22], [2031, 4, 28], [2031, 4, 19], 0.0675, 3], 'settlement outside first period'], ['normal control 2', [[2014, 9, 23], [2015, 11, 30], [2014, 9, 20], 0.05, 12], 'settlement outside first period']]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(*args), 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
import datetime
from fractions import Fraction
N = 1
observations = []
def solve(issue, first, settle, rate, months):
    def mlen(y, m):
        if m == 2:
            return 29 if (y % 4 == 0 and y % 100 != 0) or y % 400 == 0 else 28
        return 30 if m in (4, 6, 9, 11) else 31
    I = datetime.date(*issue)
    Fc = datetime.date(*first)
    S = datetime.date(*settle)
    if not (I <= S <= Fc):
        return 'settlement outside first period'
    freq = 12 // months
    def back(k):
        t = Fc.year * 12 + Fc.month - 1 - k * months
        y, m = t // 12, t % 12 + 1
        return datetime.date(y, m, min(Fc.day, mlen(y, m)))
    q = [Fc]
    k = 1
    while q[-1] > I:
        q.append(back(k))
        k += 1
    frac = Fraction(0)
    for j in range(len(q) - 1):
        end, start = q[j], q[j + 1]
        lo = max(start, I) if j == 0 else start
        hi = min(end, S)
        if hi > lo:
            frac += Fraction((hi - lo).days, (end - start).days)
    return round(float(100 * Fraction(str(rate)) / freq * frac), 6)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression issue date clipping 1', [[2006, 8, 4], [2006, 9, 30], [2006, 8, 13], 0.05, 3], 0.122283], ['regression issue date clipping 2', [[2038, 5, 29], [2038, 7, 25], [2038, 7, 24], 0.045, 3], 0.692308], ['partial repair probe 1', [[2028, 3, 6], [2028, 4, 26], [2028, 3, 15], 0.03, 1], 0.077586], ['partial repair probe 2', [[2027, 7, 30], [2028, 9, 30], [2028, 5, 25], 0.05, 6], 4.103261], ['boundary control 1', [[2024, 1, 10], [2024, 9, 15], [2024, 9, 16], 0.05, 6], 'settlement outside first period'], ['boundary control 2', [[2024, 3, 15], [2024, 9, 15], [2024, 6, 15], 0.05, 6], 1.25], ['normal control 1', [[2042, 4, 28], [2043, 1, 30], [2042, 4, 25], 0.0675, 3], 'settlement outside first period'], ['normal control 2', [[2044, 7, 14], [2044, 11, 30], [2044, 7, 11], 0.02, 12], 'settlement outside first period']], [['regression issue date clipping 1', [[2044, 7, 14], [2045, 2, 28], [2044, 10, 28], 0.02, 12], 0.579235], ['regression issue date clipping 2', [[2012, 3, 21], [2012, 4, 30], [2012, 4, 2], 0.05, 3], 0.164835], ['partial repair probe 1', [[2026, 5, 8], [2026, 8, 31], [2026, 5, 21], 0.02, 3], 0.070652], ['partial repair probe 2', [[2025, 3, 10], [2026, 2, 21], [2025, 8, 17], 0.08, 6], 3.535912], ['boundary control 1', [[2024, 3, 15], [2024, 9, 15], [2024, 6, 15], 0.05, 6], 1.25], ['boundary control 2', [[2024, 1, 10], [2024, 9, 15], [2024, 9, 16], 0.05, 6], 'settlement outside first period'], ['normal control 1', [[2035, 5, 29], [2035, 6, 6], [2035, 5, 26], 0.0675, 6], 'settlement outside first period'], ['normal control 2', [[2039, 12, 17], [2040, 7, 20], [2039, 12, 14], 0.0675, 3], 'settlement outside first period']], [['regression issue date clipping 1', [[2006, 4, 30], [2007, 1, 26], [2006, 10, 15], 0.03, 3], 1.377359], ['regression issue date clipping 2', [[2023, 8, 31], [2023, 10, 1], [2023, 9, 15], 0.03, 1], 0.124731], ['partial repair probe 1', [[2009, 5, 24], [2010, 7, 10], [2010, 5, 8], 0.0675, 6], 6.451657], ['partial repair probe 2', [[2018, 2, 9], [2018, 5, 31], [2018, 3, 13], 0.03, 3], 0.264312], ['boundary control 1', [[2024, 1, 10], [2024, 9, 15], [2024, 9, 16], 0.05, 6], 'settlement outside first period'], ['boundary control 2', [[2024, 3, 15], [2024, 9, 15], [2024, 6, 15], 0.05, 6], 1.25], ['normal control 1', [[2002, 6, 12], [2003, 1, 5], [2002, 6, 9], 0.03, 6], 'settlement outside first period'], ['normal control 2', [[2036, 11, 9], [2036, 11, 19], [2036, 11, 6], 0.02, 6], 'settlement outside first period']], [['regression issue date clipping 1', [[2034, 5, 16], [2034, 6, 30], [2034, 6, 17], 0.05, 12], 0.438356], ['regression issue date clipping 2', [[2003, 5, 14], [2003, 5, 31], [2003, 5, 14], 0.045, 3], 0.0], ['partial repair probe 1', [[2032, 5, 30], [2032, 8, 31], [2032, 6, 4], 0.05, 1], 0.068996], ['partial repair probe 2', [[2021, 12, 10], [2022, 4, 30], [2022, 1, 18], 0.08, 3], 0.847826], ['boundary control 1', [[2024, 1, 10], [2024, 9, 15], [2024, 9, 16], 0.05, 6], 'settlement outside first period'], ['boundary control 2', [[2024, 3, 15], [2024, 9, 15], [2024, 6, 15], 0.05, 6], 1.25], ['normal control 1', [[2010, 9, 22], [2011, 2, 14], [2010, 9, 19], 0.05, 3], 'settlement outside first period'], ['normal control 2', [[2021, 3, 4], [2021, 5, 30], [2021, 3, 1], 0.045, 3], 'settlement outside first period']], [['regression issue date clipping 1', [[2018, 9, 26], [2019, 1, 30], [2019, 1, 26], 0.08, 3], 2.652174], ['regression issue date clipping 2', [[2001, 4, 14], [2002, 7, 31], [2002, 1, 21], 0.08, 6], 6.169349], ['partial repair probe 1', [[2020, 8, 28], [2020, 10, 22], [2020, 9, 25], 0.0675, 1], 0.509879], ['partial repair probe 2', [[2041, 11, 21], [2044, 4, 12], [2042, 9, 9], 0.02, 12], 1.6], ['boundary control 1', [[2024, 1, 10], [2024, 9, 15], [2024, 9, 16], 0.05, 6], 'settlement outside first period'], ['boundary control 2', [[2024, 3, 15], [2024, 9, 15], [2024, 6, 15], 0.05, 6], 1.25], ['normal control 1', [[2031, 4, 22], [2031, 4, 28], [2031, 4, 19], 0.0675, 3], 'settlement outside first period'], ['normal control 2', [[2014, 9, 23], [2015, 11, 30], [2014, 9, 20], 0.05, 12], 'settlement outside first period']]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(*args), 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:
Accrued interest includes days before the bond existed.

Inputs issue, first coupon and settlement [y,m,d], annual rate and months per period. Settlement must lie in [issue, first] else return "settlement outside first period". Quasi-coupon dates are generated back from the first coupon in steps of months (day clamped to month length) until one is on or before issue. For each quasi period [start, end), accrued days are those in [max(start, issue), min(end, settle)) and are divided by that quasi period length. Accrued = 100*rate/freq*sum, rounded to 6 decimals.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import datetime
from fractions import Fraction
N = 1
observations = []
def solve(issue, first, settle, rate, months):
    def mlen(y, m):
        if m == 2:
            return 29 if (y % 4 == 0 and y % 100 != 0) or y % 400 == 0 else 28
        return 30 if m in (4, 6, 9, 11) else 31
    I = datetime.date(*issue)
    Fc = datetime.date(*first)
    S = datetime.date(*settle)
    if not (I <= S <= Fc):
        return 'settlement outside first period'
    freq = 12 // months
    def back(k):
        t = Fc.year * 12 + Fc.month - 1 - k * months
        y, m = t // 12, t % 12 + 1
        return datetime.date(y, m, min(Fc.day, mlen(y, m)))
    q = [Fc]
    k = 1
    while q[-1] > I:
        q.append(back(k))
        k += 1
    frac = Fraction(0)
    for j in range(len(q) - 1):
        end, start = q[j], q[j + 1]
        lo = max(start, I)
        hi = min(end, S) if j == 0 else end
        if hi > lo:
            frac += Fraction((hi - lo).days, (end - start).days)
    return round(float(100 * Fraction(str(rate)) / freq * frac), 6)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression settlement clipping 1', [[2037, 12, 17], [2038, 8, 31], [2038, 4, 9], 0.08, 3], 2.491787], ['regression settlement clipping 2', [[2042, 11, 10], [2043, 8, 31], [2042, 12, 3], 0.03, 6], 0.190608], ['partial repair probe 1', [[2039, 3, 14], [2040, 10, 23], [2039, 3, 14], 0.045, 6], 0.0], ['partial repair probe 2', [[2043, 10, 16], [2045, 4, 30], [2043, 11, 25], 0.03, 6], 0.327869], ['boundary control 1', [[2024, 1, 10], [2024, 9, 15], [2024, 5, 1], 0.05, 6], 1.531444], ['boundary control 2', [[2024, 3, 15], [2024, 9, 15], [2024, 6, 15], 0.05, 6], 1.25], ['normal control 1', [[2029, 10, 4], [2031, 3, 15], [2031, 3, 1], 0.0675, 6], 9.509669], ['normal control 2', [[2027, 11, 10], [2029, 9, 29], [2027, 11, 7], 0.045, 12], 'settlement outside first period']], [['regression settlement clipping 1', [[2018, 3, 16], [2018, 5, 5], [2018, 3, 16], 0.045, 1], 0.0], ['regression settlement clipping 2', [[2035, 7, 24], [2035, 10, 5], [2035, 8, 15], 0.0675, 1], 0.399194], ['partial repair probe 1', [[2037, 2, 2], [2038, 3, 25], [2037, 2, 2], 0.045, 6], 0.0], ['partial repair probe 2', [[2014, 11, 11], [2015, 1, 31], [2014, 11, 27], 0.05, 1], 0.222222], ['boundary control 1', [[2024, 1, 10], [2024, 9, 15], [2024, 9, 16], 0.05, 6], 'settlement outside first period'], ['boundary control 2', [[2024, 1, 10], [2024, 9, 15], [2024, 5, 1], 0.05, 6], 1.531444], ['normal control 1', [[2029, 11, 15], [2030, 5, 4], [2030, 5, 4], 0.08, 6], 3.756906], ['normal control 2', [[2027, 7, 20], [2028, 1, 29], [2027, 7, 17], 0.03, 3], 'settlement outside first period']], [['regression settlement clipping 1', [[2038, 6, 26], [2038, 9, 19], [2038, 6, 27], 0.08, 1], 0.022222], ['regression settlement clipping 2', [[2034, 9, 8], [2035, 3, 31], [2034, 9, 8], 0.045, 3], 0.0], ['partial repair probe 1', [[2037, 3, 25], [2037, 11, 1], [2037, 3, 25], 0.08, 3], 0.0], ['partial repair probe 2', [[2010, 1, 19], [2010, 11, 1], [2010, 1, 19], 0.03, 3], 0.0], ['boundary control 1', [[2024, 1, 10], [2024, 9, 15], [2024, 9, 16], 0.05, 6], 'settlement outside first period'], ['boundary control 2', [[2024, 1, 10], [2024, 9, 15], [2024, 5, 1], 0.05, 6], 1.531444], ['normal control 1', [[2043, 11, 1], [2043, 11, 12], [2043, 11, 4], 0.0675, 3], 0.055027], ['normal control 2', [[2031, 2, 12], [2031, 2, 28], [2031, 2, 28], 0.0675, 1], 0.290323]], [['regression settlement clipping 1', [[2039, 4, 11], [2039, 10, 15], [2039, 7, 14], 0.03, 3], 0.775092], ['regression settlement clipping 2', [[2032, 12, 15], [2034, 1, 28], [2033, 1, 8], 0.05, 12], 0.327869], ['partial repair probe 1', [[2028, 1, 11], [2028, 11, 18], [2028, 4, 15], 0.045, 3], 1.177174], ['partial repair probe 2', [[2026, 2, 6], [2028, 10, 12], [2026, 9, 29], 0.03, 12], 1.931507], ['boundary control 1', [[2024, 1, 10], [2024, 9, 15], [2024, 9, 16], 0.05, 6], 'settlement outside first period'], ['boundary control 2', [[2024, 3, 15], [2024, 9, 15], [2024, 6, 15], 0.05, 6], 1.25], ['normal control 1', [[2012, 12, 25], [2013, 2, 15], [2013, 2, 15], 0.02, 1], 0.27957], ['normal control 2', [[2001, 2, 18], [2001, 5, 28], [2001, 2, 18], 0.03, 6], 0.0]], [['regression settlement clipping 1', [[2005, 11, 20], [2007, 1, 31], [2006, 3, 21], 0.05, 6], 1.655056], ['regression settlement clipping 2', [[2016, 10, 4], [2018, 4, 26], [2016, 10, 4], 0.045, 12], 0.0], ['partial repair probe 1', [[2001, 1, 21], [2001, 3, 31], [2001, 1, 23], 0.045, 1], 0.024194], ['partial repair probe 2', [[2028, 8, 30], [2030, 2, 28], [2028, 12, 17], 0.05, 6], 1.480978], ['boundary control 1', [[2024, 1, 10], [2024, 9, 15], [2024, 5, 1], 0.05, 6], 1.531444], ['boundary control 2', [[2024, 3, 15], [2024, 9, 15], [2024, 6, 15], 0.05, 6], 1.25], ['normal control 1', [[2021, 5, 19], [2021, 5, 31], [2021, 5, 16], 0.05, 3], 'settlement outside first period'], ['normal control 2', [[2040, 1, 11], [2040, 5, 31], [2040, 1, 11], 0.02, 12], 0.0]]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(*args), 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
import datetime
from fractions import Fraction
N = 1
observations = []
def solve(issue, first, settle, rate, months):
    def mlen(y, m):
        if m == 2:
            return 29 if (y % 4 == 0 and y % 100 != 0) or y % 400 == 0 else 28
        return 30 if m in (4, 6, 9, 11) else 31
    I = datetime.date(*issue)
    Fc = datetime.date(*first)
    S = datetime.date(*settle)
    if not (I <= S <= Fc):
        return 'settlement outside first period'
    freq = 12 // months
    def back(k):
        t = Fc.year * 12 + Fc.month - 1 - k * months
        y, m = t // 12, t % 12 + 1
        return datetime.date(y, m, min(Fc.day, mlen(y, m)))
    q = [Fc]
    k = 1
    while q[-1] > I:
        q.append(back(k))
        k += 1
    frac = Fraction(0)
    for j in range(len(q) - 1):
        end, start = q[j], q[j + 1]
        lo = max(start, I)
        hi = min(end, S) if j <= 1 else end
        if hi > lo:
            frac += Fraction((hi - lo).days, (end - start).days)
    return round(float(100 * Fraction(str(rate)) / freq * frac), 6)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression settlement clipping 1', [[2037, 12, 17], [2038, 8, 31], [2038, 4, 9], 0.08, 3], 2.491787], ['regression settlement clipping 2', [[2042, 11, 10], [2043, 8, 31], [2042, 12, 3], 0.03, 6], 0.190608], ['partial repair probe 1', [[2039, 3, 14], [2040, 10, 23], [2039, 3, 14], 0.045, 6], 0.0], ['partial repair probe 2', [[2043, 10, 16], [2045, 4, 30], [2043, 11, 25], 0.03, 6], 0.327869], ['boundary control 1', [[2024, 1, 10], [2024, 9, 15], [2024, 5, 1], 0.05, 6], 1.531444], ['boundary control 2', [[2024, 3, 15], [2024, 9, 15], [2024, 6, 15], 0.05, 6], 1.25], ['normal control 1', [[2029, 10, 4], [2031, 3, 15], [2031, 3, 1], 0.0675, 6], 9.509669], ['normal control 2', [[2027, 11, 10], [2029, 9, 29], [2027, 11, 7], 0.045, 12], 'settlement outside first period']], [['regression settlement clipping 1', [[2018, 3, 16], [2018, 5, 5], [2018, 3, 16], 0.045, 1], 0.0], ['regression settlement clipping 2', [[2035, 7, 24], [2035, 10, 5], [2035, 8, 15], 0.0675, 1], 0.399194], ['partial repair probe 1', [[2037, 2, 2], [2038, 3, 25], [2037, 2, 2], 0.045, 6], 0.0], ['partial repair probe 2', [[2014, 11, 11], [2015, 1, 31], [2014, 11, 27], 0.05, 1], 0.222222], ['boundary control 1', [[2024, 1, 10], [2024, 9, 15], [2024, 9, 16], 0.05, 6], 'settlement outside first period'], ['boundary control 2', [[2024, 1, 10], [2024, 9, 15], [2024, 5, 1], 0.05, 6], 1.531444], ['normal control 1', [[2029, 11, 15], [2030, 5, 4], [2030, 5, 4], 0.08, 6], 3.756906], ['normal control 2', [[2027, 7, 20], [2028, 1, 29], [2027, 7, 17], 0.03, 3], 'settlement outside first period']], [['regression settlement clipping 1', [[2038, 6, 26], [2038, 9, 19], [2038, 6, 27], 0.08, 1], 0.022222], ['regression settlement clipping 2', [[2034, 9, 8], [2035, 3, 31], [2034, 9, 8], 0.045, 3], 0.0], ['partial repair probe 1', [[2037, 3, 25], [2037, 11, 1], [2037, 3, 25], 0.08, 3], 0.0], ['partial repair probe 2', [[2010, 1, 19], [2010, 11, 1], [2010, 1, 19], 0.03, 3], 0.0], ['boundary control 1', [[2024, 1, 10], [2024, 9, 15], [2024, 9, 16], 0.05, 6], 'settlement outside first period'], ['boundary control 2', [[2024, 1, 10], [2024, 9, 15], [2024, 5, 1], 0.05, 6], 1.531444], ['normal control 1', [[2043, 11, 1], [2043, 11, 12], [2043, 11, 4], 0.0675, 3], 0.055027], ['normal control 2', [[2031, 2, 12], [2031, 2, 28], [2031, 2, 28], 0.0675, 1], 0.290323]], [['regression settlement clipping 1', [[2039, 4, 11], [2039, 10, 15], [2039, 7, 14], 0.03, 3], 0.775092], ['regression settlement clipping 2', [[2032, 12, 15], [2034, 1, 28], [2033, 1, 8], 0.05, 12], 0.327869], ['partial repair probe 1', [[2028, 1, 11], [2028, 11, 18], [2028, 4, 15], 0.045, 3], 1.177174], ['partial repair probe 2', [[2026, 2, 6], [2028, 10, 12], [2026, 9, 29], 0.03, 12], 1.931507], ['boundary control 1', [[2024, 1, 10], [2024, 9, 15], [2024, 9, 16], 0.05, 6], 'settlement outside first period'], ['boundary control 2', [[2024, 3, 15], [2024, 9, 15], [2024, 6, 15], 0.05, 6], 1.25], ['normal control 1', [[2012, 12, 25], [2013, 2, 15], [2013, 2, 15], 0.02, 1], 0.27957], ['normal control 2', [[2001, 2, 18], [2001, 5, 28], [2001, 2, 18], 0.03, 6], 0.0]], [['regression settlement clipping 1', [[2005, 11, 20], [2007, 1, 31], [2006, 3, 21], 0.05, 6], 1.655056], ['regression settlement clipping 2', [[2016, 10, 4], [2018, 4, 26], [2016, 10, 4], 0.045, 12], 0.0], ['partial repair probe 1', [[2001, 1, 21], [2001, 3, 31], [2001, 1, 23], 0.045, 1], 0.024194], ['partial repair probe 2', [[2028, 8, 30], [2030, 2, 28], [2028, 12, 17], 0.05, 6], 1.480978], ['boundary control 1', [[2024, 1, 10], [2024, 9, 15], [2024, 5, 1], 0.05, 6], 1.531444], ['boundary control 2', [[2024, 3, 15], [2024, 9, 15], [2024, 6, 15], 0.05, 6], 1.25], ['normal control 1', [[2021, 5, 19], [2021, 5, 31], [2021, 5, 16], 0.05, 3], 'settlement outside first period'], ['normal control 2', [[2040, 1, 11], [2040, 5, 31], [2040, 1, 11], 0.02, 12], 0.0]]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(*args), 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:
Early settlements in a long first period are charged for quasi periods not yet elapsed.

Inputs issue, first coupon and settlement [y,m,d], annual rate and months per period. Settlement must lie in [issue, first] else return "settlement outside first period". Quasi-coupon dates are generated back from the first coupon in steps of months (day clamped to month length) until one is on or before issue. For each quasi period [start, end), accrued days are those in [max(start, issue), min(end, settle)) and are divided by that quasi period length. Accrued = 100*rate/freq*sum, rounded to 6 decimals.

split: open-access