FA-61141 / Bond day-count conventions / Open access
Inflation-linked reference index interpolation: the reference CPI is truncated instead of rounded · case 01
Reference indexes and the ratios computed from them are low by up to one unit in the fifth decimal.
ROOT CAUSE
The reference CPI quantization uses ROUND_DOWN.
VERIFIED REPAIR
Round the reference CPI half-up to 5 decimals before computing the ratio.
Unsuccessful approach: Rounding half-up to 4 decimals uses the wrong published precision.
Case contract
Inputs a date [y,m,d], a map "YYYY-MM" to CPI level and a base index. RefCPI = CPI(m-3) + (d-1)/days_in_month(m) * (CPI(m-2) - CPI(m-3)), computed in Decimal and rounded half-up to 5 decimals; the index ratio is RefCPI/base rounded half-up to 5 decimals. Return both as strings.
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
from decimal import Decimal, ROUND_HALF_UP, ROUND_DOWN
N = 1
observations = []
def solve(date, cpi, base):
y, m, d = date
def key(k):
t = y * 12 + (m - 1) - k
return '%04d-%02d' % (t // 12, t % 12 + 1)
def mlen(yy, mm):
if mm == 2:
return 29 if (yy % 4 == 0 and yy % 100 != 0) or yy % 400 == 0 else 28
return 30 if mm in (4, 6, 9, 11) else 31
c3 = Decimal(str(cpi[key(3)]))
c2 = Decimal(str(cpi[key(2)]))
ref = c3 + Decimal(d - 1) / Decimal(mlen(y, m)) * (c2 - c3)
q = Decimal('0.00001')
ref = ref.quantize(q, rounding=ROUND_DOWN)
ratio = (ref / Decimal(str(base))).quantize(q, rounding=ROUND_HALF_UP)
return [str(ref), str(ratio)]
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression reference index rounding 1', [[2022, 1, 31], {'2021-08': 246.088, '2021-09': 247.687, '2021-10': 246.894, '2021-11': 247.019, '2021-12': 246.679}, 206.18655], ['247.01497', '1.19802']], ['regression reference index rounding 2', [[2032, 3, 15], {'2031-10': 234.419, '2031-11': 235.923, '2031-12': 236.197, '2032-01': 235.705, '2032-02': 236.197}, 248.75503], ['235.97481', '0.94862']], ['partial repair probe 1', [[2032, 10, 31], {'2032-05': 296.417, '2032-06': 297.369, '2032-07': 298.508, '2032-08': 298.679, '2032-09': 299.803}, 263.01525], ['298.67348', '1.13557']], ['partial repair probe 2', [[2032, 10, 1], {'2032-05': 246.977, '2032-06': 247.244, '2032-07': 246.508, '2032-08': 247.152, '2032-09': 247.292}, 245.74888], ['246.50800', '1.00309']], ['normal control 1', [[2022, 6, 1], {'2022-01': 222.976, '2022-02': 222.986, '2022-03': 222.477, '2022-04': 222.009, '2022-05': 221.325}, 256.95683], ['222.47700', '0.86581']], ['normal control 2', [[2018, 4, 1], {'2017-11': 226.547, '2017-12': 227.974, '2018-01': 228.196, '2018-02': 229.764, '2018-03': 231.228}, 264.18312], ['228.19600', '0.86378']], ['normal control 3', [[2028, 1, 31], {'2027-08': 313.578, '2027-09': 312.97, '2027-10': 313.197, '2027-11': 313.397, '2027-12': 312.946}, 189.52171], ['313.39055', '1.65359']], ['normal control 4', [[2012, 4, 15], {'2011-11': 238.698, '2011-12': 240.174, '2012-01': 240.993, '2012-02': 241.045, '2012-03': 241.809}, 204.69036], ['241.01727', '1.17747']]], [['regression reference index rounding 1', [[2030, 8, 19], {'2030-03': 283.547, '2030-04': 282.777, '2030-05': 283.264, '2030-06': 283.136, '2030-07': 284.622}, 288.22473], ['283.18968', '0.98253']], ['regression reference index rounding 2', [[2019, 2, 28], {'2018-09': 305.912, '2018-10': 306.237, '2018-11': 306.146, '2018-12': 306.267, '2019-01': 305.747}, 292.6867], ['306.26268', '1.04638']], ['partial repair probe 1', [[2029, 12, 31], {'2029-07': 256.067, '2029-08': 255.407, '2029-09': 255.998, '2029-10': 255.249, '2029-11': 256.708}, 201.2087], ['255.27316', '1.26870']], ['partial repair probe 2', [[2020, 8, 1], {'2020-03': 316.669, '2020-04': 315.887, '2020-05': 315.471, '2020-06': 316.757, '2020-07': 317.879}, 201.68608], ['315.47100', '1.56417']], ['normal control 1', [[2028, 12, 1], {'2028-07': 238.512, '2028-08': 239.828, '2028-09': 240.729, '2028-10': 241.321, '2028-11': 242.146}, 256.77707], ['240.72900', '0.93750']], ['normal control 2', [[2018, 11, 15], {'2018-06': 260.587, '2018-07': 261.767, '2018-08': 262.213, '2018-09': 263.624, '2018-10': 264.706}, 181.82643], ['262.87147', '1.44573']], ['normal control 3', [[2017, 8, 1], {'2017-03': 276.809, '2017-04': 276.044, '2017-05': 276.743, '2017-06': 276.576, '2017-07': 277.923}, 222.18954], ['276.74300', '1.24553']], ['normal control 4', [[2019, 10, 15], {'2019-05': 269.515, '2019-06': 268.812, '2019-07': 268.827, '2019-08': 269.606, '2019-09': 269.641}, 232.2331], ['269.17881', '1.15909']]], [['regression reference index rounding 1', [[2013, 11, 15], {'2013-06': 229.95, '2013-07': 229.624, '2013-08': 229.336, '2013-09': 230.465, '2013-10': 231.034}, 194.71717], ['229.86287', '1.18050']], ['regression reference index rounding 2', [[2020, 5, 31], {'2019-12': 255.988, '2020-01': 256.797, '2020-02': 258.054, '2020-03': 257.86, '2020-04': 257.284}, 201.84005], ['257.86626', '1.27758']], ['partial repair probe 1', [[2025, 4, 1], {'2024-11': 308.165, '2024-12': 309.717, '2025-01': 310.919, '2025-02': 311.079, '2025-03': 311.8}, 186.95418], ['310.91900', '1.66308']], ['partial repair probe 2', [[2026, 1, 1], {'2025-08': 252.82, '2025-09': 253.87, '2025-10': 253.108, '2025-11': 253.646, '2025-12': 252.871}, 244.54067], ['253.10800', '1.03503']], ['normal control 1', [[2012, 2, 3], {'2011-09': 317.018, '2011-10': 318.558, '2011-11': 319.394, '2011-12': 320.96, '2012-01': 320.718}, 265.52812], ['319.50200', '1.20327']], ['normal control 2', [[2012, 2, 29], {'2011-09': 301.103, '2011-10': 301.173, '2011-11': 302.482, '2011-12': 302.318, '2012-01': 303.787}, 231.53825], ['302.32366', '1.30572']], ['normal control 3', [[2026, 9, 30], {'2026-04': 291.539, '2026-05': 292.942, '2026-06': 293.134, '2026-07': 293.038, '2026-08': 293.049}, 198.43427], ['293.04120', '1.47677']], ['normal control 4', [[2027, 7, 15], {'2027-02': 258.484, '2027-03': 257.855, '2027-04': 257.353, '2027-05': 257.064, '2027-06': 256.335}, 290.86364], ['257.22248', '0.88434']]], [['regression reference index rounding 1', [[2031, 10, 21], {'2031-05': 264.247, '2031-06': 263.992, '2031-07': 264.745, '2031-08': 266.298, '2031-09': 265.595}, 218.76275], ['265.74694', '1.21477']], ['regression reference index rounding 2', [[2029, 3, 31], {'2028-10': 224.854, '2028-11': 225.061, '2028-12': 225.601, '2029-01': 227.125, '2029-02': 227.807}, 274.82869], ['227.07584', '0.82625']], ['partial repair probe 1', [[2029, 1, 21], {'2028-08': 311.624, '2028-09': 312.738, '2028-10': 312.642, '2028-11': 312.83, '2028-12': 312.494}, 230.61703], ['312.76329', '1.35620']], ['partial repair probe 2', [[2031, 8, 1], {'2031-03': 275.768, '2031-04': 276.379, '2031-05': 277.373, '2031-06': 278.048, '2031-07': 277.731}, 236.8429], ['277.37300', '1.17113']], ['normal control 1', [[2030, 10, 1], {'2030-05': 236.322, '2030-06': 236.687, '2030-07': 236.394, '2030-08': 236.247, '2030-09': 237.224}, 282.94886], ['236.39400', '0.83547']], ['normal control 2', [[2027, 12, 1], {'2027-07': 256.454, '2027-08': 256.606, '2027-09': 255.912, '2027-10': 255.676, '2027-11': 255.939}, 207.32469], ['255.91200', '1.23435']], ['normal control 3', [[2023, 9, 1], {'2023-04': 242.661, '2023-05': 243.043, '2023-06': 243.301, '2023-07': 244.736, '2023-08': 244.237}, 204.88584], ['243.30100', '1.18750']], ['normal control 4', [[2019, 12, 31], {'2019-07': 282.341, '2019-08': 283.135, '2019-09': 282.936, '2019-10': 284.17, '2019-11': 283.783}, 254.07667], ['284.13019', '1.11829']]], [['regression reference index rounding 1', [[2025, 7, 6], {'2025-02': 232.398, '2025-03': 233.163, '2025-04': 233.332, '2025-05': 234.39, '2025-06': 235.922}, 291.62801], ['233.50265', '0.80069']], ['regression reference index rounding 2', [[2012, 5, 31], {'2011-12': 313.379, '2012-01': 314.298, '2012-02': 313.942, '2012-03': 313.686, '2012-04': 314.576}, 209.70911], ['313.69426', '1.49585']], ['partial repair probe 1', [[2014, 4, 28], {'2013-11': 308.173, '2013-12': 309.169, '2014-01': 308.603, '2014-02': 308.602, '2014-03': 309.039}, 202.68851], ['308.60210', '1.52254']], ['partial repair probe 2', [[2027, 8, 14], {'2027-03': 291.889, '2027-04': 292.578, '2027-05': 293.552, '2027-06': 294.883, '2027-07': 295.128}, 220.28968], ['294.11016', '1.33511']], ['normal control 1', [[2015, 1, 15], {'2014-08': 220.336, '2014-09': 220.376, '2014-10': 221.566, '2014-11': 222.529, '2014-12': 222.455}, 272.67636], ['222.00090', '0.81416']], ['normal control 2', [[2032, 11, 1], {'2032-06': 306.917, '2032-07': 306.54, '2032-08': 306.162, '2032-09': 305.523, '2032-10': 305.227}, 208.92478], ['306.16200', '1.46542']], ['normal control 3', [[2020, 4, 1], {'2019-11': 307.143, '2019-12': 307.141, '2020-01': 307.222, '2020-02': 308.194, '2020-03': 307.778}, 249.65647], ['307.22200', '1.23058']], ['normal control 4', [[2027, 7, 31], {'2027-02': 222.876, '2027-03': 223.14, '2027-04': 223.516, '2027-05': 223.019, '2027-06': 224.147}, 256.22337], ['223.03503', '0.87047']]]]
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 fixture | Actual | Expected | Outcome |
|---|---|---|---|
| regression reference index rounding 1 | ['247.01496', '1.19802'] | ['247.01497', '1.19802'] | Failed |
| regression reference index rounding 2 | ['235.97480', '0.94862'] | ['235.97481', '0.94862'] | Failed |
| partial repair probe 1 | ['298.67348', '1.13557'] | ['298.67348', '1.13557'] | Passed |
| partial repair probe 2 | ['246.50800', '1.00309'] | ['246.50800', '1.00309'] | Passed |
| normal control 1 | ['222.47700', '0.86581'] | ['222.47700', '0.86581'] | Passed |
| normal control 2 | ['228.19600', '0.86378'] | ['228.19600', '0.86378'] | Passed |
| normal control 3 | ['313.39054', '1.65359'] | ['313.39055', '1.65359'] | Failed |
| normal control 4 | ['241.01726', '1.17747'] | ['241.01727', '1.17747'] | Failed |
SHA-256 / a11c5e09b17bad37bdb5031eb525bc118eb2080ed4eae2241da3b90620f69820
2 / The unsuccessful fix
Exit 1"""Failure Map reference implementation. Python standard library only."""
import json
from decimal import Decimal, ROUND_HALF_UP, ROUND_DOWN
N = 1
observations = []
def solve(date, cpi, base):
y, m, d = date
def key(k):
t = y * 12 + (m - 1) - k
return '%04d-%02d' % (t // 12, t % 12 + 1)
def mlen(yy, mm):
if mm == 2:
return 29 if (yy % 4 == 0 and yy % 100 != 0) or yy % 400 == 0 else 28
return 30 if mm in (4, 6, 9, 11) else 31
c3 = Decimal(str(cpi[key(3)]))
c2 = Decimal(str(cpi[key(2)]))
ref = c3 + Decimal(d - 1) / Decimal(mlen(y, m)) * (c2 - c3)
q = Decimal('0.00001')
ref = ref.quantize(Decimal('0.0001'), rounding=ROUND_HALF_UP)
ratio = (ref / Decimal(str(base))).quantize(q, rounding=ROUND_HALF_UP)
return [str(ref), str(ratio)]
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression reference index rounding 1', [[2022, 1, 31], {'2021-08': 246.088, '2021-09': 247.687, '2021-10': 246.894, '2021-11': 247.019, '2021-12': 246.679}, 206.18655], ['247.01497', '1.19802']], ['regression reference index rounding 2', [[2032, 3, 15], {'2031-10': 234.419, '2031-11': 235.923, '2031-12': 236.197, '2032-01': 235.705, '2032-02': 236.197}, 248.75503], ['235.97481', '0.94862']], ['partial repair probe 1', [[2032, 10, 31], {'2032-05': 296.417, '2032-06': 297.369, '2032-07': 298.508, '2032-08': 298.679, '2032-09': 299.803}, 263.01525], ['298.67348', '1.13557']], ['partial repair probe 2', [[2032, 10, 1], {'2032-05': 246.977, '2032-06': 247.244, '2032-07': 246.508, '2032-08': 247.152, '2032-09': 247.292}, 245.74888], ['246.50800', '1.00309']], ['normal control 1', [[2022, 6, 1], {'2022-01': 222.976, '2022-02': 222.986, '2022-03': 222.477, '2022-04': 222.009, '2022-05': 221.325}, 256.95683], ['222.47700', '0.86581']], ['normal control 2', [[2018, 4, 1], {'2017-11': 226.547, '2017-12': 227.974, '2018-01': 228.196, '2018-02': 229.764, '2018-03': 231.228}, 264.18312], ['228.19600', '0.86378']], ['normal control 3', [[2028, 1, 31], {'2027-08': 313.578, '2027-09': 312.97, '2027-10': 313.197, '2027-11': 313.397, '2027-12': 312.946}, 189.52171], ['313.39055', '1.65359']], ['normal control 4', [[2012, 4, 15], {'2011-11': 238.698, '2011-12': 240.174, '2012-01': 240.993, '2012-02': 241.045, '2012-03': 241.809}, 204.69036], ['241.01727', '1.17747']]], [['regression reference index rounding 1', [[2030, 8, 19], {'2030-03': 283.547, '2030-04': 282.777, '2030-05': 283.264, '2030-06': 283.136, '2030-07': 284.622}, 288.22473], ['283.18968', '0.98253']], ['regression reference index rounding 2', [[2019, 2, 28], {'2018-09': 305.912, '2018-10': 306.237, '2018-11': 306.146, '2018-12': 306.267, '2019-01': 305.747}, 292.6867], ['306.26268', '1.04638']], ['partial repair probe 1', [[2029, 12, 31], {'2029-07': 256.067, '2029-08': 255.407, '2029-09': 255.998, '2029-10': 255.249, '2029-11': 256.708}, 201.2087], ['255.27316', '1.26870']], ['partial repair probe 2', [[2020, 8, 1], {'2020-03': 316.669, '2020-04': 315.887, '2020-05': 315.471, '2020-06': 316.757, '2020-07': 317.879}, 201.68608], ['315.47100', '1.56417']], ['normal control 1', [[2028, 12, 1], {'2028-07': 238.512, '2028-08': 239.828, '2028-09': 240.729, '2028-10': 241.321, '2028-11': 242.146}, 256.77707], ['240.72900', '0.93750']], ['normal control 2', [[2018, 11, 15], {'2018-06': 260.587, '2018-07': 261.767, '2018-08': 262.213, '2018-09': 263.624, '2018-10': 264.706}, 181.82643], ['262.87147', '1.44573']], ['normal control 3', [[2017, 8, 1], {'2017-03': 276.809, '2017-04': 276.044, '2017-05': 276.743, '2017-06': 276.576, '2017-07': 277.923}, 222.18954], ['276.74300', '1.24553']], ['normal control 4', [[2019, 10, 15], {'2019-05': 269.515, '2019-06': 268.812, '2019-07': 268.827, '2019-08': 269.606, '2019-09': 269.641}, 232.2331], ['269.17881', '1.15909']]], [['regression reference index rounding 1', [[2013, 11, 15], {'2013-06': 229.95, '2013-07': 229.624, '2013-08': 229.336, '2013-09': 230.465, '2013-10': 231.034}, 194.71717], ['229.86287', '1.18050']], ['regression reference index rounding 2', [[2020, 5, 31], {'2019-12': 255.988, '2020-01': 256.797, '2020-02': 258.054, '2020-03': 257.86, '2020-04': 257.284}, 201.84005], ['257.86626', '1.27758']], ['partial repair probe 1', [[2025, 4, 1], {'2024-11': 308.165, '2024-12': 309.717, '2025-01': 310.919, '2025-02': 311.079, '2025-03': 311.8}, 186.95418], ['310.91900', '1.66308']], ['partial repair probe 2', [[2026, 1, 1], {'2025-08': 252.82, '2025-09': 253.87, '2025-10': 253.108, '2025-11': 253.646, '2025-12': 252.871}, 244.54067], ['253.10800', '1.03503']], ['normal control 1', [[2012, 2, 3], {'2011-09': 317.018, '2011-10': 318.558, '2011-11': 319.394, '2011-12': 320.96, '2012-01': 320.718}, 265.52812], ['319.50200', '1.20327']], ['normal control 2', [[2012, 2, 29], {'2011-09': 301.103, '2011-10': 301.173, '2011-11': 302.482, '2011-12': 302.318, '2012-01': 303.787}, 231.53825], ['302.32366', '1.30572']], ['normal control 3', [[2026, 9, 30], {'2026-04': 291.539, '2026-05': 292.942, '2026-06': 293.134, '2026-07': 293.038, '2026-08': 293.049}, 198.43427], ['293.04120', '1.47677']], ['normal control 4', [[2027, 7, 15], {'2027-02': 258.484, '2027-03': 257.855, '2027-04': 257.353, '2027-05': 257.064, '2027-06': 256.335}, 290.86364], ['257.22248', '0.88434']]], [['regression reference index rounding 1', [[2031, 10, 21], {'2031-05': 264.247, '2031-06': 263.992, '2031-07': 264.745, '2031-08': 266.298, '2031-09': 265.595}, 218.76275], ['265.74694', '1.21477']], ['regression reference index rounding 2', [[2029, 3, 31], {'2028-10': 224.854, '2028-11': 225.061, '2028-12': 225.601, '2029-01': 227.125, '2029-02': 227.807}, 274.82869], ['227.07584', '0.82625']], ['partial repair probe 1', [[2029, 1, 21], {'2028-08': 311.624, '2028-09': 312.738, '2028-10': 312.642, '2028-11': 312.83, '2028-12': 312.494}, 230.61703], ['312.76329', '1.35620']], ['partial repair probe 2', [[2031, 8, 1], {'2031-03': 275.768, '2031-04': 276.379, '2031-05': 277.373, '2031-06': 278.048, '2031-07': 277.731}, 236.8429], ['277.37300', '1.17113']], ['normal control 1', [[2030, 10, 1], {'2030-05': 236.322, '2030-06': 236.687, '2030-07': 236.394, '2030-08': 236.247, '2030-09': 237.224}, 282.94886], ['236.39400', '0.83547']], ['normal control 2', [[2027, 12, 1], {'2027-07': 256.454, '2027-08': 256.606, '2027-09': 255.912, '2027-10': 255.676, '2027-11': 255.939}, 207.32469], ['255.91200', '1.23435']], ['normal control 3', [[2023, 9, 1], {'2023-04': 242.661, '2023-05': 243.043, '2023-06': 243.301, '2023-07': 244.736, '2023-08': 244.237}, 204.88584], ['243.30100', '1.18750']], ['normal control 4', [[2019, 12, 31], {'2019-07': 282.341, '2019-08': 283.135, '2019-09': 282.936, '2019-10': 284.17, '2019-11': 283.783}, 254.07667], ['284.13019', '1.11829']]], [['regression reference index rounding 1', [[2025, 7, 6], {'2025-02': 232.398, '2025-03': 233.163, '2025-04': 233.332, '2025-05': 234.39, '2025-06': 235.922}, 291.62801], ['233.50265', '0.80069']], ['regression reference index rounding 2', [[2012, 5, 31], {'2011-12': 313.379, '2012-01': 314.298, '2012-02': 313.942, '2012-03': 313.686, '2012-04': 314.576}, 209.70911], ['313.69426', '1.49585']], ['partial repair probe 1', [[2014, 4, 28], {'2013-11': 308.173, '2013-12': 309.169, '2014-01': 308.603, '2014-02': 308.602, '2014-03': 309.039}, 202.68851], ['308.60210', '1.52254']], ['partial repair probe 2', [[2027, 8, 14], {'2027-03': 291.889, '2027-04': 292.578, '2027-05': 293.552, '2027-06': 294.883, '2027-07': 295.128}, 220.28968], ['294.11016', '1.33511']], ['normal control 1', [[2015, 1, 15], {'2014-08': 220.336, '2014-09': 220.376, '2014-10': 221.566, '2014-11': 222.529, '2014-12': 222.455}, 272.67636], ['222.00090', '0.81416']], ['normal control 2', [[2032, 11, 1], {'2032-06': 306.917, '2032-07': 306.54, '2032-08': 306.162, '2032-09': 305.523, '2032-10': 305.227}, 208.92478], ['306.16200', '1.46542']], ['normal control 3', [[2020, 4, 1], {'2019-11': 307.143, '2019-12': 307.141, '2020-01': 307.222, '2020-02': 308.194, '2020-03': 307.778}, 249.65647], ['307.22200', '1.23058']], ['normal control 4', [[2027, 7, 31], {'2027-02': 222.876, '2027-03': 223.14, '2027-04': 223.516, '2027-05': 223.019, '2027-06': 224.147}, 256.22337], ['223.03503', '0.87047']]]]
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 fixture | Actual | Expected | Outcome |
|---|---|---|---|
| regression reference index rounding 1 | ['247.0150', '1.19802'] | ['247.01497', '1.19802'] | Failed |
| regression reference index rounding 2 | ['235.9748', '0.94862'] | ['235.97481', '0.94862'] | Failed |
| partial repair probe 1 | ['298.6735', '1.13557'] | ['298.67348', '1.13557'] | Failed |
| partial repair probe 2 | ['246.5080', '1.00309'] | ['246.50800', '1.00309'] | Failed |
| normal control 1 | ['222.4770', '0.86581'] | ['222.47700', '0.86581'] | Failed |
| normal control 2 | ['228.1960', '0.86378'] | ['228.19600', '0.86378'] | Failed |
| normal control 3 | ['313.3905', '1.65359'] | ['313.39055', '1.65359'] | Failed |
| normal control 4 | ['241.0173', '1.17747'] | ['241.01727', '1.17747'] | Failed |
SHA-256 / 4e50d1c0b57e78587162636287e1d0a2a25cb48ace980a43d023c00e6ddaae29
3 / The verified repair
Exit 0"""Failure Map reference implementation. Python standard library only."""
import json
from decimal import Decimal, ROUND_HALF_UP, ROUND_DOWN
N = 1
observations = []
def solve(date, cpi, base):
y, m, d = date
def key(k):
t = y * 12 + (m - 1) - k
return '%04d-%02d' % (t // 12, t % 12 + 1)
def mlen(yy, mm):
if mm == 2:
return 29 if (yy % 4 == 0 and yy % 100 != 0) or yy % 400 == 0 else 28
return 30 if mm in (4, 6, 9, 11) else 31
c3 = Decimal(str(cpi[key(3)]))
c2 = Decimal(str(cpi[key(2)]))
ref = c3 + Decimal(d - 1) / Decimal(mlen(y, m)) * (c2 - c3)
q = Decimal('0.00001')
ref = ref.quantize(q, rounding=ROUND_HALF_UP)
ratio = (ref / Decimal(str(base))).quantize(q, rounding=ROUND_HALF_UP)
return [str(ref), str(ratio)]
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression reference index rounding 1', [[2022, 1, 31], {'2021-08': 246.088, '2021-09': 247.687, '2021-10': 246.894, '2021-11': 247.019, '2021-12': 246.679}, 206.18655], ['247.01497', '1.19802']], ['regression reference index rounding 2', [[2032, 3, 15], {'2031-10': 234.419, '2031-11': 235.923, '2031-12': 236.197, '2032-01': 235.705, '2032-02': 236.197}, 248.75503], ['235.97481', '0.94862']], ['partial repair probe 1', [[2032, 10, 31], {'2032-05': 296.417, '2032-06': 297.369, '2032-07': 298.508, '2032-08': 298.679, '2032-09': 299.803}, 263.01525], ['298.67348', '1.13557']], ['partial repair probe 2', [[2032, 10, 1], {'2032-05': 246.977, '2032-06': 247.244, '2032-07': 246.508, '2032-08': 247.152, '2032-09': 247.292}, 245.74888], ['246.50800', '1.00309']], ['normal control 1', [[2022, 6, 1], {'2022-01': 222.976, '2022-02': 222.986, '2022-03': 222.477, '2022-04': 222.009, '2022-05': 221.325}, 256.95683], ['222.47700', '0.86581']], ['normal control 2', [[2018, 4, 1], {'2017-11': 226.547, '2017-12': 227.974, '2018-01': 228.196, '2018-02': 229.764, '2018-03': 231.228}, 264.18312], ['228.19600', '0.86378']], ['normal control 3', [[2028, 1, 31], {'2027-08': 313.578, '2027-09': 312.97, '2027-10': 313.197, '2027-11': 313.397, '2027-12': 312.946}, 189.52171], ['313.39055', '1.65359']], ['normal control 4', [[2012, 4, 15], {'2011-11': 238.698, '2011-12': 240.174, '2012-01': 240.993, '2012-02': 241.045, '2012-03': 241.809}, 204.69036], ['241.01727', '1.17747']]], [['regression reference index rounding 1', [[2030, 8, 19], {'2030-03': 283.547, '2030-04': 282.777, '2030-05': 283.264, '2030-06': 283.136, '2030-07': 284.622}, 288.22473], ['283.18968', '0.98253']], ['regression reference index rounding 2', [[2019, 2, 28], {'2018-09': 305.912, '2018-10': 306.237, '2018-11': 306.146, '2018-12': 306.267, '2019-01': 305.747}, 292.6867], ['306.26268', '1.04638']], ['partial repair probe 1', [[2029, 12, 31], {'2029-07': 256.067, '2029-08': 255.407, '2029-09': 255.998, '2029-10': 255.249, '2029-11': 256.708}, 201.2087], ['255.27316', '1.26870']], ['partial repair probe 2', [[2020, 8, 1], {'2020-03': 316.669, '2020-04': 315.887, '2020-05': 315.471, '2020-06': 316.757, '2020-07': 317.879}, 201.68608], ['315.47100', '1.56417']], ['normal control 1', [[2028, 12, 1], {'2028-07': 238.512, '2028-08': 239.828, '2028-09': 240.729, '2028-10': 241.321, '2028-11': 242.146}, 256.77707], ['240.72900', '0.93750']], ['normal control 2', [[2018, 11, 15], {'2018-06': 260.587, '2018-07': 261.767, '2018-08': 262.213, '2018-09': 263.624, '2018-10': 264.706}, 181.82643], ['262.87147', '1.44573']], ['normal control 3', [[2017, 8, 1], {'2017-03': 276.809, '2017-04': 276.044, '2017-05': 276.743, '2017-06': 276.576, '2017-07': 277.923}, 222.18954], ['276.74300', '1.24553']], ['normal control 4', [[2019, 10, 15], {'2019-05': 269.515, '2019-06': 268.812, '2019-07': 268.827, '2019-08': 269.606, '2019-09': 269.641}, 232.2331], ['269.17881', '1.15909']]], [['regression reference index rounding 1', [[2013, 11, 15], {'2013-06': 229.95, '2013-07': 229.624, '2013-08': 229.336, '2013-09': 230.465, '2013-10': 231.034}, 194.71717], ['229.86287', '1.18050']], ['regression reference index rounding 2', [[2020, 5, 31], {'2019-12': 255.988, '2020-01': 256.797, '2020-02': 258.054, '2020-03': 257.86, '2020-04': 257.284}, 201.84005], ['257.86626', '1.27758']], ['partial repair probe 1', [[2025, 4, 1], {'2024-11': 308.165, '2024-12': 309.717, '2025-01': 310.919, '2025-02': 311.079, '2025-03': 311.8}, 186.95418], ['310.91900', '1.66308']], ['partial repair probe 2', [[2026, 1, 1], {'2025-08': 252.82, '2025-09': 253.87, '2025-10': 253.108, '2025-11': 253.646, '2025-12': 252.871}, 244.54067], ['253.10800', '1.03503']], ['normal control 1', [[2012, 2, 3], {'2011-09': 317.018, '2011-10': 318.558, '2011-11': 319.394, '2011-12': 320.96, '2012-01': 320.718}, 265.52812], ['319.50200', '1.20327']], ['normal control 2', [[2012, 2, 29], {'2011-09': 301.103, '2011-10': 301.173, '2011-11': 302.482, '2011-12': 302.318, '2012-01': 303.787}, 231.53825], ['302.32366', '1.30572']], ['normal control 3', [[2026, 9, 30], {'2026-04': 291.539, '2026-05': 292.942, '2026-06': 293.134, '2026-07': 293.038, '2026-08': 293.049}, 198.43427], ['293.04120', '1.47677']], ['normal control 4', [[2027, 7, 15], {'2027-02': 258.484, '2027-03': 257.855, '2027-04': 257.353, '2027-05': 257.064, '2027-06': 256.335}, 290.86364], ['257.22248', '0.88434']]], [['regression reference index rounding 1', [[2031, 10, 21], {'2031-05': 264.247, '2031-06': 263.992, '2031-07': 264.745, '2031-08': 266.298, '2031-09': 265.595}, 218.76275], ['265.74694', '1.21477']], ['regression reference index rounding 2', [[2029, 3, 31], {'2028-10': 224.854, '2028-11': 225.061, '2028-12': 225.601, '2029-01': 227.125, '2029-02': 227.807}, 274.82869], ['227.07584', '0.82625']], ['partial repair probe 1', [[2029, 1, 21], {'2028-08': 311.624, '2028-09': 312.738, '2028-10': 312.642, '2028-11': 312.83, '2028-12': 312.494}, 230.61703], ['312.76329', '1.35620']], ['partial repair probe 2', [[2031, 8, 1], {'2031-03': 275.768, '2031-04': 276.379, '2031-05': 277.373, '2031-06': 278.048, '2031-07': 277.731}, 236.8429], ['277.37300', '1.17113']], ['normal control 1', [[2030, 10, 1], {'2030-05': 236.322, '2030-06': 236.687, '2030-07': 236.394, '2030-08': 236.247, '2030-09': 237.224}, 282.94886], ['236.39400', '0.83547']], ['normal control 2', [[2027, 12, 1], {'2027-07': 256.454, '2027-08': 256.606, '2027-09': 255.912, '2027-10': 255.676, '2027-11': 255.939}, 207.32469], ['255.91200', '1.23435']], ['normal control 3', [[2023, 9, 1], {'2023-04': 242.661, '2023-05': 243.043, '2023-06': 243.301, '2023-07': 244.736, '2023-08': 244.237}, 204.88584], ['243.30100', '1.18750']], ['normal control 4', [[2019, 12, 31], {'2019-07': 282.341, '2019-08': 283.135, '2019-09': 282.936, '2019-10': 284.17, '2019-11': 283.783}, 254.07667], ['284.13019', '1.11829']]], [['regression reference index rounding 1', [[2025, 7, 6], {'2025-02': 232.398, '2025-03': 233.163, '2025-04': 233.332, '2025-05': 234.39, '2025-06': 235.922}, 291.62801], ['233.50265', '0.80069']], ['regression reference index rounding 2', [[2012, 5, 31], {'2011-12': 313.379, '2012-01': 314.298, '2012-02': 313.942, '2012-03': 313.686, '2012-04': 314.576}, 209.70911], ['313.69426', '1.49585']], ['partial repair probe 1', [[2014, 4, 28], {'2013-11': 308.173, '2013-12': 309.169, '2014-01': 308.603, '2014-02': 308.602, '2014-03': 309.039}, 202.68851], ['308.60210', '1.52254']], ['partial repair probe 2', [[2027, 8, 14], {'2027-03': 291.889, '2027-04': 292.578, '2027-05': 293.552, '2027-06': 294.883, '2027-07': 295.128}, 220.28968], ['294.11016', '1.33511']], ['normal control 1', [[2015, 1, 15], {'2014-08': 220.336, '2014-09': 220.376, '2014-10': 221.566, '2014-11': 222.529, '2014-12': 222.455}, 272.67636], ['222.00090', '0.81416']], ['normal control 2', [[2032, 11, 1], {'2032-06': 306.917, '2032-07': 306.54, '2032-08': 306.162, '2032-09': 305.523, '2032-10': 305.227}, 208.92478], ['306.16200', '1.46542']], ['normal control 3', [[2020, 4, 1], {'2019-11': 307.143, '2019-12': 307.141, '2020-01': 307.222, '2020-02': 308.194, '2020-03': 307.778}, 249.65647], ['307.22200', '1.23058']], ['normal control 4', [[2027, 7, 31], {'2027-02': 222.876, '2027-03': 223.14, '2027-04': 223.516, '2027-05': 223.019, '2027-06': 224.147}, 256.22337], ['223.03503', '0.87047']]]]
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 fixture | Actual | Expected | Outcome |
|---|---|---|---|
| regression reference index rounding 1 | ['247.01497', '1.19802'] | ['247.01497', '1.19802'] | Passed |
| regression reference index rounding 2 | ['235.97481', '0.94862'] | ['235.97481', '0.94862'] | Passed |
| partial repair probe 1 | ['298.67348', '1.13557'] | ['298.67348', '1.13557'] | Passed |
| partial repair probe 2 | ['246.50800', '1.00309'] | ['246.50800', '1.00309'] | Passed |
| normal control 1 | ['222.47700', '0.86581'] | ['222.47700', '0.86581'] | Passed |
| normal control 2 | ['228.19600', '0.86378'] | ['228.19600', '0.86378'] | Passed |
| normal control 3 | ['313.39055', '1.65359'] | ['313.39055', '1.65359'] | Passed |
| normal control 4 | ['241.01727', '1.17747'] | ['241.01727', '1.17747'] | Passed |
SHA-256 / c81298473a215dd12ebfe90cb5bc9b7564fc94b78019c59a1938d8e2f4297bfc
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:52.405073+00:00.
Case digest / 9da42ea9d0d17ae6ed74f0b4fd55f573713c3251c3f67d3fe10bdad7ea850ceb