FAILURE MAP
← Case archive

FA-60976 / Bond day-count conventions / Open access

Backward coupon schedule generation: the stub test measures the first regular period instead of the stub · case 01

Short front stubs survive while normal first coupons can be discarded.

Verified by executionVariant 1 · 8 checks per implementationDownload source bundle ↓JSON ↗

ROOT CAUSE

The removal test compares the second and first coupon dates rather than issue and first coupon.

VERIFIED REPAIR

Measure days from the issue date to the first remaining coupon date.

Unsuccessful approach: Scaling the 15-day threshold by the period months removes ordinary short stubs.

Case contract

Inputs issue and maturity [y,m,d], months per period and an end-of-month flag. Unadjusted coupon dates are generated backward from maturity: the k-th date is maturity shifted back k*months calendar months, keeping the maturity day clamped to the month length; if the flag is set and maturity is the last day of its month, every date is the last day of its month. Dates on or before issue are dropped. If more than one date remains and the first is fewer than 15 days after issue, it is removed (long first coupon). Return the dates ascending.

Why this case matters

Bond accrual and pricing systems depend on exact day-count arithmetic; a single-day error changes settlement cash.

1 / The failure

Exit 1
"""Failure Map reference implementation. Python standard library only."""
import json
import datetime
from fractions import Fraction
N = 1
observations = []
def solve(issue, maturity, months, eom):
    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
    def shift(y, m, k):
        t = y * 12 + (m - 1) - k
        return t // 12, t % 12 + 1
    I = datetime.date(*issue)
    my, mm, md = maturity
    end_eom = md == mlen(my, mm)
    out = []
    k = 0
    while True:
        y, m = shift(my, mm, k * months)
        d = mlen(y, m) if (eom and end_eom) else min(md, mlen(y, m))
        if datetime.date(y, m, d) <= I:
            break
        out.append([y, m, d])
        k += 1
    out.reverse()
    if len(out) > 1 and (datetime.date(*out[1]) - datetime.date(*out[0])).days < 15:
        out.pop(0)
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression short stub measure 1', [[2038, 11, 16], [2039, 1, 31], 1, False], [[2038, 12, 31], [2039, 1, 31]]], ['regression short stub measure 2', [[2016, 6, 23], [2017, 3, 30], 3, True], [[2016, 9, 30], [2016, 12, 30], [2017, 3, 30]]], ['partial repair probe 1', [[2021, 10, 9], [2022, 11, 30], 6, False], [[2021, 11, 30], [2022, 5, 30], [2022, 11, 30]]], ['partial repair probe 2', [[2024, 1, 10], [2025, 8, 31], 6, False], [[2024, 2, 29], [2024, 8, 31], [2025, 2, 28], [2025, 8, 31]]], ['boundary control 1', [[2024, 3, 15], [2025, 3, 15], 3, False], [[2024, 6, 15], [2024, 9, 15], [2024, 12, 15], [2025, 3, 15]]], ['normal control 1', [[2024, 7, 26], [2024, 7, 31], 6, True], [[2024, 7, 31]]], ['normal control 2', [[2011, 11, 18], [2013, 5, 2], 6, True], [[2012, 5, 2], [2012, 11, 2], [2013, 5, 2]]], ['normal control 3', [[2024, 3, 19], [2027, 3, 3], 6, False], [[2024, 9, 3], [2025, 3, 3], [2025, 9, 3], [2026, 3, 3], [2026, 9, 3], [2027, 3, 3]]]], [['regression short stub measure 1', [[2026, 2, 25], [2029, 2, 28], 6, False], [[2026, 8, 28], [2027, 2, 28], [2027, 8, 28], [2028, 2, 28], [2028, 8, 28], [2029, 2, 28]]], ['regression short stub measure 2', [[2019, 4, 16], [2021, 11, 30], 1, False], [[2019, 5, 30], [2019, 6, 30], [2019, 7, 30], [2019, 8, 30], [2019, 9, 30], [2019, 10, 30], [2019, 11, 30], [2019, 12, 30], [2020, 1, 30], [2020, 2, 29], [2020, 3, 30], [2020, 4, 30], [2020, 5, 30], [2020, 6, 30], [2020, 7, 30], [2020, 8, 30], [2020, 9, 30], [2020, 10, 30], [2020, 11, 30], [2020, 12, 30], [2021, 1, 30], [2021, 2, 28], [2021, 3, 30], [2021, 4, 30], [2021, 5, 30], [2021, 6, 30], [2021, 7, 30], [2021, 8, 30], [2021, 9, 30], [2021, 10, 30], [2021, 11, 30]]], ['partial repair probe 1', [[2016, 8, 31], [2018, 6, 30], 3, True], [[2016, 9, 30], [2016, 12, 31], [2017, 3, 31], [2017, 6, 30], [2017, 9, 30], [2017, 12, 31], [2018, 3, 31], [2018, 6, 30]]], ['partial repair probe 2', [[2001, 11, 22], [2004, 12, 31], 12, True], [[2001, 12, 31], [2002, 12, 31], [2003, 12, 31], [2004, 12, 31]]], ['boundary control 1', [[2024, 3, 15], [2025, 3, 15], 3, False], [[2024, 6, 15], [2024, 9, 15], [2024, 12, 15], [2025, 3, 15]]], ['normal control 1', [[2039, 12, 16], [2040, 11, 30], 6, True], [[2040, 5, 31], [2040, 11, 30]]], ['normal control 2', [[2009, 12, 3], [2011, 10, 31], 12, True], [[2010, 10, 31], [2011, 10, 31]]], ['normal control 3', [[2027, 9, 13], [2028, 5, 29], 3, True], [[2027, 11, 29], [2028, 2, 29], [2028, 5, 29]]]], [['regression short stub measure 1', [[2035, 4, 18], [2036, 7, 30], 3, True], [[2035, 7, 30], [2035, 10, 30], [2036, 1, 30], [2036, 4, 30], [2036, 7, 30]]], ['regression short stub measure 2', [[2006, 12, 22], [2008, 12, 31], 12, True], [[2007, 12, 31], [2008, 12, 31]]], ['partial repair probe 1', [[2027, 7, 24], [2027, 11, 30], 3, True], [[2027, 8, 31], [2027, 11, 30]]], ['partial repair probe 2', [[2022, 9, 7], [2023, 9, 30], 6, True], [[2022, 9, 30], [2023, 3, 31], [2023, 9, 30]]], ['boundary control 1', [[2024, 3, 15], [2025, 3, 15], 3, False], [[2024, 6, 15], [2024, 9, 15], [2024, 12, 15], [2025, 3, 15]]], ['normal control 1', [[2010, 3, 16], [2011, 5, 31], 3, True], [[2010, 5, 31], [2010, 8, 31], [2010, 11, 30], [2011, 2, 28], [2011, 5, 31]]], ['normal control 2', [[2013, 2, 6], [2014, 7, 31], 6, True], [[2013, 7, 31], [2014, 1, 31], [2014, 7, 31]]], ['normal control 3', [[2023, 12, 19], [2026, 9, 30], 6, True], [[2024, 3, 31], [2024, 9, 30], [2025, 3, 31], [2025, 9, 30], [2026, 3, 31], [2026, 9, 30]]]], [['regression short stub measure 1', [[2029, 4, 27], [2029, 10, 31], 6, True], [[2029, 10, 31]]], ['regression short stub measure 2', [[2007, 12, 1], [2008, 6, 5], 6, True], [[2008, 6, 5]]], ['partial repair probe 1', [[2011, 7, 20], [2013, 12, 31], 12, True], [[2011, 12, 31], [2012, 12, 31], [2013, 12, 31]]], ['partial repair probe 2', [[2011, 9, 2], [2014, 4, 30], 6, True], [[2011, 10, 31], [2012, 4, 30], [2012, 10, 31], [2013, 4, 30], [2013, 10, 31], [2014, 4, 30]]], ['boundary control 1', [[2024, 3, 15], [2025, 3, 15], 3, False], [[2024, 6, 15], [2024, 9, 15], [2024, 12, 15], [2025, 3, 15]]], ['normal control 1', [[2030, 10, 1], [2032, 4, 1], 6, True], [[2031, 4, 1], [2031, 10, 1], [2032, 4, 1]]], ['normal control 2', [[2004, 4, 15], [2006, 9, 30], 3, False], [[2004, 6, 30], [2004, 9, 30], [2004, 12, 30], [2005, 3, 30], [2005, 6, 30], [2005, 9, 30], [2005, 12, 30], [2006, 3, 30], [2006, 6, 30], [2006, 9, 30]]], ['normal control 3', [[2023, 6, 1], [2026, 1, 31], 12, False], [[2024, 1, 31], [2025, 1, 31], [2026, 1, 31]]]], [['regression short stub measure 1', [[2006, 10, 24], [2009, 7, 28], 1, False], [[2006, 11, 28], [2006, 12, 28], [2007, 1, 28], [2007, 2, 28], [2007, 3, 28], [2007, 4, 28], [2007, 5, 28], [2007, 6, 28], [2007, 7, 28], [2007, 8, 28], [2007, 9, 28], [2007, 10, 28], [2007, 11, 28], [2007, 12, 28], [2008, 1, 28], [2008, 2, 28], [2008, 3, 28], [2008, 4, 28], [2008, 5, 28], [2008, 6, 28], [2008, 7, 28], [2008, 8, 28], [2008, 9, 28], [2008, 10, 28], [2008, 11, 28], [2008, 12, 28], [2009, 1, 28], [2009, 2, 28], [2009, 3, 28], [2009, 4, 28], [2009, 5, 28], [2009, 6, 28], [2009, 7, 28]]], ['regression short stub measure 2', [[2028, 4, 18], [2028, 8, 1], 3, False], [[2028, 8, 1]]], ['partial repair probe 1', [[2017, 3, 15], [2020, 4, 30], 6, False], [[2017, 4, 30], [2017, 10, 30], [2018, 4, 30], [2018, 10, 30], [2019, 4, 30], [2019, 10, 30], [2020, 4, 30]]], ['partial repair probe 2', [[2006, 9, 2], [2010, 9, 30], 12, False], [[2006, 9, 30], [2007, 9, 30], [2008, 9, 30], [2009, 9, 30], [2010, 9, 30]]], ['boundary control 1', [[2024, 3, 15], [2025, 3, 15], 3, False], [[2024, 6, 15], [2024, 9, 15], [2024, 12, 15], [2025, 3, 15]]], ['normal control 1', [[2018, 6, 13], [2018, 6, 30], 12, False], [[2018, 6, 30]]], ['normal control 2', [[2016, 8, 16], [2018, 7, 31], 6, True], [[2017, 1, 31], [2017, 7, 31], [2018, 1, 31], [2018, 7, 31]]], ['normal control 3', [[2025, 2, 7], [2026, 7, 21], 6, False], [[2025, 7, 21], [2026, 1, 21], [2026, 7, 21]]]]]
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)
Boundary fixtureActualExpectedOutcome
regression short stub measure 1[[2038, 11, 30], [2038, 12, 31], [2039, 1, 31]][[2038, 12, 31], [2039, 1, 31]]Failed
regression short stub measure 2[[2016, 6, 30], [2016, 9, 30], [2016, 12, 30], [2017, 3, 30]][[2016, 9, 30], [2016, 12, 30], [2017, 3, 30]]Failed
partial repair probe 1[[2021, 11, 30], [2022, 5, 30], [2022, 11, 30]][[2021, 11, 30], [2022, 5, 30], [2022, 11, 30]]Passed
partial repair probe 2[[2024, 2, 29], [2024, 8, 31], [2025, 2, 28], [2025, 8, 31]][[2024, 2, 29], [2024, 8, 31], [2025, 2, 28], [2025, 8, 31]]Passed
boundary control 1[[2024, 6, 15], [2024, 9, 15], [2024, 12, 15], [2025, 3, 15]][[2024, 6, 15], [2024, 9, 15], [2024, 12, 15], [2025, 3, 15]]Passed
normal control 1[[2024, 7, 31]][[2024, 7, 31]]Passed
normal control 2[[2012, 5, 2], [2012, 11, 2], [2013, 5, 2]][[2012, 5, 2], [2012, 11, 2], [2013, 5, 2]]Passed
normal control 3[[2024, 9, 3], [2025, 3, 3], [2025, 9, 3], [2026, 3, 3], [2026, 9, 3], [2027, 3, 3]][[2024, 9, 3], [2025, 3, 3], [2025, 9, 3], [2026, 3, 3], [2026, 9, 3], [2027, 3, 3]]Passed

SHA-256 / d1e73cfb4b2308753c87f82ec5a9081ce8fea54e19a0cd03c313d002e9ffca9a

2 / The unsuccessful fix

Exit 1
"""Failure Map reference implementation. Python standard library only."""
import json
import datetime
from fractions import Fraction
N = 1
observations = []
def solve(issue, maturity, months, eom):
    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
    def shift(y, m, k):
        t = y * 12 + (m - 1) - k
        return t // 12, t % 12 + 1
    I = datetime.date(*issue)
    my, mm, md = maturity
    end_eom = md == mlen(my, mm)
    out = []
    k = 0
    while True:
        y, m = shift(my, mm, k * months)
        d = mlen(y, m) if (eom and end_eom) else min(md, mlen(y, m))
        if datetime.date(y, m, d) <= I:
            break
        out.append([y, m, d])
        k += 1
    out.reverse()
    if len(out) > 1 and (datetime.date(*out[0]) - I).days < 15 * months:
        out.pop(0)
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression short stub measure 1', [[2038, 11, 16], [2039, 1, 31], 1, False], [[2038, 12, 31], [2039, 1, 31]]], ['regression short stub measure 2', [[2016, 6, 23], [2017, 3, 30], 3, True], [[2016, 9, 30], [2016, 12, 30], [2017, 3, 30]]], ['partial repair probe 1', [[2021, 10, 9], [2022, 11, 30], 6, False], [[2021, 11, 30], [2022, 5, 30], [2022, 11, 30]]], ['partial repair probe 2', [[2024, 1, 10], [2025, 8, 31], 6, False], [[2024, 2, 29], [2024, 8, 31], [2025, 2, 28], [2025, 8, 31]]], ['boundary control 1', [[2024, 3, 15], [2025, 3, 15], 3, False], [[2024, 6, 15], [2024, 9, 15], [2024, 12, 15], [2025, 3, 15]]], ['normal control 1', [[2024, 7, 26], [2024, 7, 31], 6, True], [[2024, 7, 31]]], ['normal control 2', [[2011, 11, 18], [2013, 5, 2], 6, True], [[2012, 5, 2], [2012, 11, 2], [2013, 5, 2]]], ['normal control 3', [[2024, 3, 19], [2027, 3, 3], 6, False], [[2024, 9, 3], [2025, 3, 3], [2025, 9, 3], [2026, 3, 3], [2026, 9, 3], [2027, 3, 3]]]], [['regression short stub measure 1', [[2026, 2, 25], [2029, 2, 28], 6, False], [[2026, 8, 28], [2027, 2, 28], [2027, 8, 28], [2028, 2, 28], [2028, 8, 28], [2029, 2, 28]]], ['regression short stub measure 2', [[2019, 4, 16], [2021, 11, 30], 1, False], [[2019, 5, 30], [2019, 6, 30], [2019, 7, 30], [2019, 8, 30], [2019, 9, 30], [2019, 10, 30], [2019, 11, 30], [2019, 12, 30], [2020, 1, 30], [2020, 2, 29], [2020, 3, 30], [2020, 4, 30], [2020, 5, 30], [2020, 6, 30], [2020, 7, 30], [2020, 8, 30], [2020, 9, 30], [2020, 10, 30], [2020, 11, 30], [2020, 12, 30], [2021, 1, 30], [2021, 2, 28], [2021, 3, 30], [2021, 4, 30], [2021, 5, 30], [2021, 6, 30], [2021, 7, 30], [2021, 8, 30], [2021, 9, 30], [2021, 10, 30], [2021, 11, 30]]], ['partial repair probe 1', [[2016, 8, 31], [2018, 6, 30], 3, True], [[2016, 9, 30], [2016, 12, 31], [2017, 3, 31], [2017, 6, 30], [2017, 9, 30], [2017, 12, 31], [2018, 3, 31], [2018, 6, 30]]], ['partial repair probe 2', [[2001, 11, 22], [2004, 12, 31], 12, True], [[2001, 12, 31], [2002, 12, 31], [2003, 12, 31], [2004, 12, 31]]], ['boundary control 1', [[2024, 3, 15], [2025, 3, 15], 3, False], [[2024, 6, 15], [2024, 9, 15], [2024, 12, 15], [2025, 3, 15]]], ['normal control 1', [[2039, 12, 16], [2040, 11, 30], 6, True], [[2040, 5, 31], [2040, 11, 30]]], ['normal control 2', [[2009, 12, 3], [2011, 10, 31], 12, True], [[2010, 10, 31], [2011, 10, 31]]], ['normal control 3', [[2027, 9, 13], [2028, 5, 29], 3, True], [[2027, 11, 29], [2028, 2, 29], [2028, 5, 29]]]], [['regression short stub measure 1', [[2035, 4, 18], [2036, 7, 30], 3, True], [[2035, 7, 30], [2035, 10, 30], [2036, 1, 30], [2036, 4, 30], [2036, 7, 30]]], ['regression short stub measure 2', [[2006, 12, 22], [2008, 12, 31], 12, True], [[2007, 12, 31], [2008, 12, 31]]], ['partial repair probe 1', [[2027, 7, 24], [2027, 11, 30], 3, True], [[2027, 8, 31], [2027, 11, 30]]], ['partial repair probe 2', [[2022, 9, 7], [2023, 9, 30], 6, True], [[2022, 9, 30], [2023, 3, 31], [2023, 9, 30]]], ['boundary control 1', [[2024, 3, 15], [2025, 3, 15], 3, False], [[2024, 6, 15], [2024, 9, 15], [2024, 12, 15], [2025, 3, 15]]], ['normal control 1', [[2010, 3, 16], [2011, 5, 31], 3, True], [[2010, 5, 31], [2010, 8, 31], [2010, 11, 30], [2011, 2, 28], [2011, 5, 31]]], ['normal control 2', [[2013, 2, 6], [2014, 7, 31], 6, True], [[2013, 7, 31], [2014, 1, 31], [2014, 7, 31]]], ['normal control 3', [[2023, 12, 19], [2026, 9, 30], 6, True], [[2024, 3, 31], [2024, 9, 30], [2025, 3, 31], [2025, 9, 30], [2026, 3, 31], [2026, 9, 30]]]], [['regression short stub measure 1', [[2029, 4, 27], [2029, 10, 31], 6, True], [[2029, 10, 31]]], ['regression short stub measure 2', [[2007, 12, 1], [2008, 6, 5], 6, True], [[2008, 6, 5]]], ['partial repair probe 1', [[2011, 7, 20], [2013, 12, 31], 12, True], [[2011, 12, 31], [2012, 12, 31], [2013, 12, 31]]], ['partial repair probe 2', [[2011, 9, 2], [2014, 4, 30], 6, True], [[2011, 10, 31], [2012, 4, 30], [2012, 10, 31], [2013, 4, 30], [2013, 10, 31], [2014, 4, 30]]], ['boundary control 1', [[2024, 3, 15], [2025, 3, 15], 3, False], [[2024, 6, 15], [2024, 9, 15], [2024, 12, 15], [2025, 3, 15]]], ['normal control 1', [[2030, 10, 1], [2032, 4, 1], 6, True], [[2031, 4, 1], [2031, 10, 1], [2032, 4, 1]]], ['normal control 2', [[2004, 4, 15], [2006, 9, 30], 3, False], [[2004, 6, 30], [2004, 9, 30], [2004, 12, 30], [2005, 3, 30], [2005, 6, 30], [2005, 9, 30], [2005, 12, 30], [2006, 3, 30], [2006, 6, 30], [2006, 9, 30]]], ['normal control 3', [[2023, 6, 1], [2026, 1, 31], 12, False], [[2024, 1, 31], [2025, 1, 31], [2026, 1, 31]]]], [['regression short stub measure 1', [[2006, 10, 24], [2009, 7, 28], 1, False], [[2006, 11, 28], [2006, 12, 28], [2007, 1, 28], [2007, 2, 28], [2007, 3, 28], [2007, 4, 28], [2007, 5, 28], [2007, 6, 28], [2007, 7, 28], [2007, 8, 28], [2007, 9, 28], [2007, 10, 28], [2007, 11, 28], [2007, 12, 28], [2008, 1, 28], [2008, 2, 28], [2008, 3, 28], [2008, 4, 28], [2008, 5, 28], [2008, 6, 28], [2008, 7, 28], [2008, 8, 28], [2008, 9, 28], [2008, 10, 28], [2008, 11, 28], [2008, 12, 28], [2009, 1, 28], [2009, 2, 28], [2009, 3, 28], [2009, 4, 28], [2009, 5, 28], [2009, 6, 28], [2009, 7, 28]]], ['regression short stub measure 2', [[2028, 4, 18], [2028, 8, 1], 3, False], [[2028, 8, 1]]], ['partial repair probe 1', [[2017, 3, 15], [2020, 4, 30], 6, False], [[2017, 4, 30], [2017, 10, 30], [2018, 4, 30], [2018, 10, 30], [2019, 4, 30], [2019, 10, 30], [2020, 4, 30]]], ['partial repair probe 2', [[2006, 9, 2], [2010, 9, 30], 12, False], [[2006, 9, 30], [2007, 9, 30], [2008, 9, 30], [2009, 9, 30], [2010, 9, 30]]], ['boundary control 1', [[2024, 3, 15], [2025, 3, 15], 3, False], [[2024, 6, 15], [2024, 9, 15], [2024, 12, 15], [2025, 3, 15]]], ['normal control 1', [[2018, 6, 13], [2018, 6, 30], 12, False], [[2018, 6, 30]]], ['normal control 2', [[2016, 8, 16], [2018, 7, 31], 6, True], [[2017, 1, 31], [2017, 7, 31], [2018, 1, 31], [2018, 7, 31]]], ['normal control 3', [[2025, 2, 7], [2026, 7, 21], 6, False], [[2025, 7, 21], [2026, 1, 21], [2026, 7, 21]]]]]
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)
Boundary fixtureActualExpectedOutcome
regression short stub measure 1[[2038, 12, 31], [2039, 1, 31]][[2038, 12, 31], [2039, 1, 31]]Passed
regression short stub measure 2[[2016, 9, 30], [2016, 12, 30], [2017, 3, 30]][[2016, 9, 30], [2016, 12, 30], [2017, 3, 30]]Passed
partial repair probe 1[[2022, 5, 30], [2022, 11, 30]][[2021, 11, 30], [2022, 5, 30], [2022, 11, 30]]Failed
partial repair probe 2[[2024, 8, 31], [2025, 2, 28], [2025, 8, 31]][[2024, 2, 29], [2024, 8, 31], [2025, 2, 28], [2025, 8, 31]]Failed
boundary control 1[[2024, 6, 15], [2024, 9, 15], [2024, 12, 15], [2025, 3, 15]][[2024, 6, 15], [2024, 9, 15], [2024, 12, 15], [2025, 3, 15]]Passed
normal control 1[[2024, 7, 31]][[2024, 7, 31]]Passed
normal control 2[[2012, 5, 2], [2012, 11, 2], [2013, 5, 2]][[2012, 5, 2], [2012, 11, 2], [2013, 5, 2]]Passed
normal control 3[[2024, 9, 3], [2025, 3, 3], [2025, 9, 3], [2026, 3, 3], [2026, 9, 3], [2027, 3, 3]][[2024, 9, 3], [2025, 3, 3], [2025, 9, 3], [2026, 3, 3], [2026, 9, 3], [2027, 3, 3]]Passed

SHA-256 / aadaaec65667a07a84f52cbceaf631377e2b13a8d07f43bdb1ae87d0d86c2542

3 / The verified repair

Exit 0
"""Failure Map reference implementation. Python standard library only."""
import json
import datetime
from fractions import Fraction
N = 1
observations = []
def solve(issue, maturity, months, eom):
    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
    def shift(y, m, k):
        t = y * 12 + (m - 1) - k
        return t // 12, t % 12 + 1
    I = datetime.date(*issue)
    my, mm, md = maturity
    end_eom = md == mlen(my, mm)
    out = []
    k = 0
    while True:
        y, m = shift(my, mm, k * months)
        d = mlen(y, m) if (eom and end_eom) else min(md, mlen(y, m))
        if datetime.date(y, m, d) <= I:
            break
        out.append([y, m, d])
        k += 1
    out.reverse()
    if len(out) > 1 and (datetime.date(*out[0]) - I).days < 15:
        out.pop(0)
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression short stub measure 1', [[2038, 11, 16], [2039, 1, 31], 1, False], [[2038, 12, 31], [2039, 1, 31]]], ['regression short stub measure 2', [[2016, 6, 23], [2017, 3, 30], 3, True], [[2016, 9, 30], [2016, 12, 30], [2017, 3, 30]]], ['partial repair probe 1', [[2021, 10, 9], [2022, 11, 30], 6, False], [[2021, 11, 30], [2022, 5, 30], [2022, 11, 30]]], ['partial repair probe 2', [[2024, 1, 10], [2025, 8, 31], 6, False], [[2024, 2, 29], [2024, 8, 31], [2025, 2, 28], [2025, 8, 31]]], ['boundary control 1', [[2024, 3, 15], [2025, 3, 15], 3, False], [[2024, 6, 15], [2024, 9, 15], [2024, 12, 15], [2025, 3, 15]]], ['normal control 1', [[2024, 7, 26], [2024, 7, 31], 6, True], [[2024, 7, 31]]], ['normal control 2', [[2011, 11, 18], [2013, 5, 2], 6, True], [[2012, 5, 2], [2012, 11, 2], [2013, 5, 2]]], ['normal control 3', [[2024, 3, 19], [2027, 3, 3], 6, False], [[2024, 9, 3], [2025, 3, 3], [2025, 9, 3], [2026, 3, 3], [2026, 9, 3], [2027, 3, 3]]]], [['regression short stub measure 1', [[2026, 2, 25], [2029, 2, 28], 6, False], [[2026, 8, 28], [2027, 2, 28], [2027, 8, 28], [2028, 2, 28], [2028, 8, 28], [2029, 2, 28]]], ['regression short stub measure 2', [[2019, 4, 16], [2021, 11, 30], 1, False], [[2019, 5, 30], [2019, 6, 30], [2019, 7, 30], [2019, 8, 30], [2019, 9, 30], [2019, 10, 30], [2019, 11, 30], [2019, 12, 30], [2020, 1, 30], [2020, 2, 29], [2020, 3, 30], [2020, 4, 30], [2020, 5, 30], [2020, 6, 30], [2020, 7, 30], [2020, 8, 30], [2020, 9, 30], [2020, 10, 30], [2020, 11, 30], [2020, 12, 30], [2021, 1, 30], [2021, 2, 28], [2021, 3, 30], [2021, 4, 30], [2021, 5, 30], [2021, 6, 30], [2021, 7, 30], [2021, 8, 30], [2021, 9, 30], [2021, 10, 30], [2021, 11, 30]]], ['partial repair probe 1', [[2016, 8, 31], [2018, 6, 30], 3, True], [[2016, 9, 30], [2016, 12, 31], [2017, 3, 31], [2017, 6, 30], [2017, 9, 30], [2017, 12, 31], [2018, 3, 31], [2018, 6, 30]]], ['partial repair probe 2', [[2001, 11, 22], [2004, 12, 31], 12, True], [[2001, 12, 31], [2002, 12, 31], [2003, 12, 31], [2004, 12, 31]]], ['boundary control 1', [[2024, 3, 15], [2025, 3, 15], 3, False], [[2024, 6, 15], [2024, 9, 15], [2024, 12, 15], [2025, 3, 15]]], ['normal control 1', [[2039, 12, 16], [2040, 11, 30], 6, True], [[2040, 5, 31], [2040, 11, 30]]], ['normal control 2', [[2009, 12, 3], [2011, 10, 31], 12, True], [[2010, 10, 31], [2011, 10, 31]]], ['normal control 3', [[2027, 9, 13], [2028, 5, 29], 3, True], [[2027, 11, 29], [2028, 2, 29], [2028, 5, 29]]]], [['regression short stub measure 1', [[2035, 4, 18], [2036, 7, 30], 3, True], [[2035, 7, 30], [2035, 10, 30], [2036, 1, 30], [2036, 4, 30], [2036, 7, 30]]], ['regression short stub measure 2', [[2006, 12, 22], [2008, 12, 31], 12, True], [[2007, 12, 31], [2008, 12, 31]]], ['partial repair probe 1', [[2027, 7, 24], [2027, 11, 30], 3, True], [[2027, 8, 31], [2027, 11, 30]]], ['partial repair probe 2', [[2022, 9, 7], [2023, 9, 30], 6, True], [[2022, 9, 30], [2023, 3, 31], [2023, 9, 30]]], ['boundary control 1', [[2024, 3, 15], [2025, 3, 15], 3, False], [[2024, 6, 15], [2024, 9, 15], [2024, 12, 15], [2025, 3, 15]]], ['normal control 1', [[2010, 3, 16], [2011, 5, 31], 3, True], [[2010, 5, 31], [2010, 8, 31], [2010, 11, 30], [2011, 2, 28], [2011, 5, 31]]], ['normal control 2', [[2013, 2, 6], [2014, 7, 31], 6, True], [[2013, 7, 31], [2014, 1, 31], [2014, 7, 31]]], ['normal control 3', [[2023, 12, 19], [2026, 9, 30], 6, True], [[2024, 3, 31], [2024, 9, 30], [2025, 3, 31], [2025, 9, 30], [2026, 3, 31], [2026, 9, 30]]]], [['regression short stub measure 1', [[2029, 4, 27], [2029, 10, 31], 6, True], [[2029, 10, 31]]], ['regression short stub measure 2', [[2007, 12, 1], [2008, 6, 5], 6, True], [[2008, 6, 5]]], ['partial repair probe 1', [[2011, 7, 20], [2013, 12, 31], 12, True], [[2011, 12, 31], [2012, 12, 31], [2013, 12, 31]]], ['partial repair probe 2', [[2011, 9, 2], [2014, 4, 30], 6, True], [[2011, 10, 31], [2012, 4, 30], [2012, 10, 31], [2013, 4, 30], [2013, 10, 31], [2014, 4, 30]]], ['boundary control 1', [[2024, 3, 15], [2025, 3, 15], 3, False], [[2024, 6, 15], [2024, 9, 15], [2024, 12, 15], [2025, 3, 15]]], ['normal control 1', [[2030, 10, 1], [2032, 4, 1], 6, True], [[2031, 4, 1], [2031, 10, 1], [2032, 4, 1]]], ['normal control 2', [[2004, 4, 15], [2006, 9, 30], 3, False], [[2004, 6, 30], [2004, 9, 30], [2004, 12, 30], [2005, 3, 30], [2005, 6, 30], [2005, 9, 30], [2005, 12, 30], [2006, 3, 30], [2006, 6, 30], [2006, 9, 30]]], ['normal control 3', [[2023, 6, 1], [2026, 1, 31], 12, False], [[2024, 1, 31], [2025, 1, 31], [2026, 1, 31]]]], [['regression short stub measure 1', [[2006, 10, 24], [2009, 7, 28], 1, False], [[2006, 11, 28], [2006, 12, 28], [2007, 1, 28], [2007, 2, 28], [2007, 3, 28], [2007, 4, 28], [2007, 5, 28], [2007, 6, 28], [2007, 7, 28], [2007, 8, 28], [2007, 9, 28], [2007, 10, 28], [2007, 11, 28], [2007, 12, 28], [2008, 1, 28], [2008, 2, 28], [2008, 3, 28], [2008, 4, 28], [2008, 5, 28], [2008, 6, 28], [2008, 7, 28], [2008, 8, 28], [2008, 9, 28], [2008, 10, 28], [2008, 11, 28], [2008, 12, 28], [2009, 1, 28], [2009, 2, 28], [2009, 3, 28], [2009, 4, 28], [2009, 5, 28], [2009, 6, 28], [2009, 7, 28]]], ['regression short stub measure 2', [[2028, 4, 18], [2028, 8, 1], 3, False], [[2028, 8, 1]]], ['partial repair probe 1', [[2017, 3, 15], [2020, 4, 30], 6, False], [[2017, 4, 30], [2017, 10, 30], [2018, 4, 30], [2018, 10, 30], [2019, 4, 30], [2019, 10, 30], [2020, 4, 30]]], ['partial repair probe 2', [[2006, 9, 2], [2010, 9, 30], 12, False], [[2006, 9, 30], [2007, 9, 30], [2008, 9, 30], [2009, 9, 30], [2010, 9, 30]]], ['boundary control 1', [[2024, 3, 15], [2025, 3, 15], 3, False], [[2024, 6, 15], [2024, 9, 15], [2024, 12, 15], [2025, 3, 15]]], ['normal control 1', [[2018, 6, 13], [2018, 6, 30], 12, False], [[2018, 6, 30]]], ['normal control 2', [[2016, 8, 16], [2018, 7, 31], 6, True], [[2017, 1, 31], [2017, 7, 31], [2018, 1, 31], [2018, 7, 31]]], ['normal control 3', [[2025, 2, 7], [2026, 7, 21], 6, False], [[2025, 7, 21], [2026, 1, 21], [2026, 7, 21]]]]]
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)
Boundary fixtureActualExpectedOutcome
regression short stub measure 1[[2038, 12, 31], [2039, 1, 31]][[2038, 12, 31], [2039, 1, 31]]Passed
regression short stub measure 2[[2016, 9, 30], [2016, 12, 30], [2017, 3, 30]][[2016, 9, 30], [2016, 12, 30], [2017, 3, 30]]Passed
partial repair probe 1[[2021, 11, 30], [2022, 5, 30], [2022, 11, 30]][[2021, 11, 30], [2022, 5, 30], [2022, 11, 30]]Passed
partial repair probe 2[[2024, 2, 29], [2024, 8, 31], [2025, 2, 28], [2025, 8, 31]][[2024, 2, 29], [2024, 8, 31], [2025, 2, 28], [2025, 8, 31]]Passed
boundary control 1[[2024, 6, 15], [2024, 9, 15], [2024, 12, 15], [2025, 3, 15]][[2024, 6, 15], [2024, 9, 15], [2024, 12, 15], [2025, 3, 15]]Passed
normal control 1[[2024, 7, 31]][[2024, 7, 31]]Passed
normal control 2[[2012, 5, 2], [2012, 11, 2], [2013, 5, 2]][[2012, 5, 2], [2012, 11, 2], [2013, 5, 2]]Passed
normal control 3[[2024, 9, 3], [2025, 3, 3], [2025, 9, 3], [2026, 3, 3], [2026, 9, 3], [2027, 3, 3]][[2024, 9, 3], [2025, 3, 3], [2025, 9, 3], [2026, 3, 3], [2026, 9, 3], [2027, 3, 3]]Passed

SHA-256 / 4108b5626471cc7098f5a5eca33f13cf2160d868f1d7ba444bf30814dc0b519f

Verification & scope

A deterministic toy contract stated explicitly in the contract field; no claim of conformance to any published convention text. This reproducer isolates one failure mechanism. Results cover the supplied fixtures. Variants within a family share a test contract and should remain grouped when constructing evaluation splits. Related mechanisms with a shared evaluation_group must also remain together; these controlled models are not independent production incidents.

Observations recorded using Python 3.12.14 at 2026-09-29T14:46:50.681631+00:00.

Case digest / 094fb147f86ad6a309ce024857f80576bfda2ff8b787bec8681bac6267036be4