FA-61121 / Bond day-count conventions / Open access
Discount-basis bill price and bond-equivalent yield: the negative root of the quadratic is returned · case 01
Long-dated bills report a negative bond-equivalent yield.
ROOT CAUSE
The quadratic solution subtracts the square root.
VERIFIED REPAIR
Take the positive root (-b + sqrt(b^2 - 4ac))/(2a).
Unsuccessful approach: Flipping the sign inside the discriminant gives a positive but wrong yield.
Case contract
Inputs settlement and maturity [y,m,d] (1 to 364 days apart) and discount rate d. t = days. Price = 100*(1 - d*t/360). Year basis B is 366 if a 29 February lies in (settle, settle+365 days], else 365. For t <= B/2, BEY = B*d/(360 - d*t); otherwise BEY solves the quadratic with a = t/(2B) - 0.25, b = t/B, c = (price-100)/price, taking (-b + sqrt(b^2 - 4ac))/(2a). Return [price rounded 6, BEY rounded 8].
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
import math
N = 1
observations = []
def solve(settle, maturity, d):
S = datetime.date(*settle)
M = datetime.date(*maturity)
t = (M - S).days
def leap(y):
return (y % 4 == 0 and y % 100 != 0) or y % 400 == 0
horizon = S + datetime.timedelta(days=365)
basis = 366 if any(leap(y) and S < datetime.date(y, 2, 29) <= horizon for y in (S.year, S.year + 1)) else 365
price = 100 * (1 - d * t / 360)
if t <= basis / 2:
bey = basis * d / (360 - d * t)
else:
a = t / (2 * basis) - 0.25
b = t / basis
c = (price - 100) / price
bey = (-b - math.sqrt(b * b - 4 * a * c)) / (2 * a)
return [round(price, 6), round(bey, 8)]
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression quadratic root selection 1', [[2049, 2, 28], [2049, 8, 30], 0.01], [99.491667, 0.01019055]], ['regression quadratic root selection 2', [[2082, 11, 15], [2083, 5, 17], 0.0525], [97.33125, 0.05468459]], ['partial repair probe 1', [[2050, 11, 30], [2051, 11, 29], 0.08], [91.911111, 0.08638888]], ['partial repair probe 2', [[2089, 3, 11], [2089, 9, 10], 0.08], [95.933333, 0.08453969]], ['boundary control 1', [[2023, 1, 1], [2023, 1, 2], 0.05], [99.986111, 0.05070149]], ['boundary control 2', [[2023, 5, 1], [2023, 10, 31], 0.05], [97.458333, 0.05215904]], ['normal control 1', [[2023, 12, 15], [2024, 6, 13], 0.0435], [97.812917, 0.04521386]], ['normal control 2', [[2090, 7, 29], [2091, 1, 27], 0.0525], [97.345833, 0.05468048]]], [['regression quadratic root selection 1', [[2100, 12, 28], [2101, 6, 29], 0.025], [98.729167, 0.02567259]], ['regression quadratic root selection 2', [[2002, 11, 1], [2003, 5, 3], 0.0525], [97.33125, 0.05468459]], ['partial repair probe 1', [[2090, 3, 8], [2091, 3, 7], 0.0435], [95.601667, 0.04561452]], ['partial repair probe 2', [[2013, 8, 17], [2014, 2, 16], 0.08], [95.933333, 0.08453969]], ['boundary control 1', [[2023, 5, 1], [2023, 10, 30], 0.05], [97.472222, 0.05215161]], ['boundary control 2', [[2023, 1, 1], [2023, 1, 2], 0.05], [99.986111, 0.05070149]], ['normal control 1', [[2099, 3, 1], [2099, 8, 29], 0.08], [95.977778, 0.0845103]], ['normal control 2', [[2081, 5, 27], [2081, 9, 1], 0.0435], [98.827917, 0.04462724]]], [['regression quadratic root selection 1', [[2099, 3, 28], [2100, 3, 27], 0.01], [98.988889, 0.01021643]], ['regression quadratic root selection 2', [[2065, 8, 13], [2066, 8, 12], 0.0435], [95.601667, 0.04561452]], ['partial repair probe 1', [[2073, 4, 5], [2073, 10, 5], 0.01], [99.491667, 0.01019055]], ['partial repair probe 2', [[1998, 12, 30], [1999, 11, 28], 0.0435], [95.97625, 0.04548568]], ['boundary control 1', [[2023, 5, 1], [2023, 10, 31], 0.05], [97.458333, 0.05215904]], ['boundary control 2', [[2023, 1, 1], [2023, 1, 2], 0.05], [99.986111, 0.05070149]], ['normal control 1', [[2075, 1, 30], [2075, 7, 31], 0.0525], [97.345833, 0.05468048]], ['normal control 2', [[2077, 9, 11], [2078, 3, 12], 0.01], [99.494444, 0.01019041]]], [['regression quadratic root selection 1', [[2070, 4, 30], [2070, 10, 30], 0.08], [95.933333, 0.08453969]], ['regression quadratic root selection 2', [[2100, 12, 15], [2101, 6, 16], 0.08], [95.933333, 0.08453969]], ['partial repair probe 1', [[2074, 4, 20], [2074, 10, 21], 0.0435], [97.776667, 0.04509876]], ['partial repair probe 2', [[2071, 7, 14], [2072, 7, 12], 0.001], [99.898889, 0.00101744]], ['boundary control 1', [[2023, 5, 1], [2023, 10, 31], 0.05], [97.458333, 0.05215904]], ['boundary control 2', [[2023, 5, 1], [2023, 10, 30], 0.05], [97.472222, 0.05215161]], ['normal control 1', [[2032, 2, 5], [2032, 8, 6], 0.025], [98.729167, 0.02574383]], ['normal control 2', [[2027, 12, 1], [2028, 6, 1], 0.025], [98.729167, 0.02574383]]], [['regression quadratic root selection 1', [[2093, 10, 27], [2094, 5, 1], 0.025], [98.708333, 0.02567271]], ['regression quadratic root selection 2', [[2004, 2, 29], [2005, 2, 27], 0.08], [91.911111, 0.08638888]], ['partial repair probe 1', [[2100, 1, 28], [2100, 7, 31], 0.0435], [97.776667, 0.04509876]], ['partial repair probe 2', [[2099, 3, 1], [2100, 2, 28], 0.025], [97.472222, 0.02583812]], ['boundary control 1', [[2023, 5, 1], [2023, 10, 30], 0.05], [97.472222, 0.05215161]], ['boundary control 2', [[2023, 1, 1], [2023, 1, 2], 0.05], [99.986111, 0.05070149]], ['normal control 1', [[2095, 3, 5], [2095, 9, 3], 0.001], [99.949444, 0.00101718]], ['normal control 2', [[2045, 1, 1], [2045, 7, 1], 0.025], [98.743056, 0.02566988]]]]
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 quadratic root selection 1 | [99.491667, -732.01019055] | [99.491667, 0.01019055] | Failed |
| regression quadratic root selection 2 | [97.33125, -732.05468459] | [97.33125, 0.05468459] | Failed |
| partial repair probe 1 | [91.911111, -4.09740817] | [91.911111, 0.08638888] | Failed |
| partial repair probe 2 | [95.933333, -732.08453969] | [95.933333, 0.08453969] | Failed |
| boundary control 1 | [99.986111, 0.05070149] | [99.986111, 0.05070149] | Passed |
| boundary control 2 | [97.458333, 0.05215904] | [97.458333, 0.05215904] | Passed |
| normal control 1 | [97.812917, 0.04521386] | [97.812917, 0.04521386] | Passed |
| normal control 2 | [97.345833, 0.05468048] | [97.345833, 0.05468048] | Passed |
SHA-256 / 36e9af74dd0014505a03146bf9f291e995767429f7b5e04ae82b86fc195535c1
2 / The unsuccessful fix
Exit 1"""Failure Map reference implementation. Python standard library only."""
import json
import datetime
import math
N = 1
observations = []
def solve(settle, maturity, d):
S = datetime.date(*settle)
M = datetime.date(*maturity)
t = (M - S).days
def leap(y):
return (y % 4 == 0 and y % 100 != 0) or y % 400 == 0
horizon = S + datetime.timedelta(days=365)
basis = 366 if any(leap(y) and S < datetime.date(y, 2, 29) <= horizon for y in (S.year, S.year + 1)) else 365
price = 100 * (1 - d * t / 360)
if t <= basis / 2:
bey = basis * d / (360 - d * t)
else:
a = t / (2 * basis) - 0.25
b = t / basis
c = (price - 100) / price
bey = (-b + math.sqrt(b * b + 4 * a * c)) / (2 * a)
return [round(price, 6), round(bey, 8)]
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression quadratic root selection 1', [[2049, 2, 28], [2049, 8, 30], 0.01], [99.491667, 0.01019055]], ['regression quadratic root selection 2', [[2082, 11, 15], [2083, 5, 17], 0.0525], [97.33125, 0.05468459]], ['partial repair probe 1', [[2050, 11, 30], [2051, 11, 29], 0.08], [91.911111, 0.08638888]], ['partial repair probe 2', [[2089, 3, 11], [2089, 9, 10], 0.08], [95.933333, 0.08453969]], ['boundary control 1', [[2023, 1, 1], [2023, 1, 2], 0.05], [99.986111, 0.05070149]], ['boundary control 2', [[2023, 5, 1], [2023, 10, 31], 0.05], [97.458333, 0.05215904]], ['normal control 1', [[2023, 12, 15], [2024, 6, 13], 0.0435], [97.812917, 0.04521386]], ['normal control 2', [[2090, 7, 29], [2091, 1, 27], 0.0525], [97.345833, 0.05468048]]], [['regression quadratic root selection 1', [[2100, 12, 28], [2101, 6, 29], 0.025], [98.729167, 0.02567259]], ['regression quadratic root selection 2', [[2002, 11, 1], [2003, 5, 3], 0.0525], [97.33125, 0.05468459]], ['partial repair probe 1', [[2090, 3, 8], [2091, 3, 7], 0.0435], [95.601667, 0.04561452]], ['partial repair probe 2', [[2013, 8, 17], [2014, 2, 16], 0.08], [95.933333, 0.08453969]], ['boundary control 1', [[2023, 5, 1], [2023, 10, 30], 0.05], [97.472222, 0.05215161]], ['boundary control 2', [[2023, 1, 1], [2023, 1, 2], 0.05], [99.986111, 0.05070149]], ['normal control 1', [[2099, 3, 1], [2099, 8, 29], 0.08], [95.977778, 0.0845103]], ['normal control 2', [[2081, 5, 27], [2081, 9, 1], 0.0435], [98.827917, 0.04462724]]], [['regression quadratic root selection 1', [[2099, 3, 28], [2100, 3, 27], 0.01], [98.988889, 0.01021643]], ['regression quadratic root selection 2', [[2065, 8, 13], [2066, 8, 12], 0.0435], [95.601667, 0.04561452]], ['partial repair probe 1', [[2073, 4, 5], [2073, 10, 5], 0.01], [99.491667, 0.01019055]], ['partial repair probe 2', [[1998, 12, 30], [1999, 11, 28], 0.0435], [95.97625, 0.04548568]], ['boundary control 1', [[2023, 5, 1], [2023, 10, 31], 0.05], [97.458333, 0.05215904]], ['boundary control 2', [[2023, 1, 1], [2023, 1, 2], 0.05], [99.986111, 0.05070149]], ['normal control 1', [[2075, 1, 30], [2075, 7, 31], 0.0525], [97.345833, 0.05468048]], ['normal control 2', [[2077, 9, 11], [2078, 3, 12], 0.01], [99.494444, 0.01019041]]], [['regression quadratic root selection 1', [[2070, 4, 30], [2070, 10, 30], 0.08], [95.933333, 0.08453969]], ['regression quadratic root selection 2', [[2100, 12, 15], [2101, 6, 16], 0.08], [95.933333, 0.08453969]], ['partial repair probe 1', [[2074, 4, 20], [2074, 10, 21], 0.0435], [97.776667, 0.04509876]], ['partial repair probe 2', [[2071, 7, 14], [2072, 7, 12], 0.001], [99.898889, 0.00101744]], ['boundary control 1', [[2023, 5, 1], [2023, 10, 31], 0.05], [97.458333, 0.05215904]], ['boundary control 2', [[2023, 5, 1], [2023, 10, 30], 0.05], [97.472222, 0.05215161]], ['normal control 1', [[2032, 2, 5], [2032, 8, 6], 0.025], [98.729167, 0.02574383]], ['normal control 2', [[2027, 12, 1], [2028, 6, 1], 0.025], [98.729167, 0.02574383]]], [['regression quadratic root selection 1', [[2093, 10, 27], [2094, 5, 1], 0.025], [98.708333, 0.02567271]], ['regression quadratic root selection 2', [[2004, 2, 29], [2005, 2, 27], 0.08], [91.911111, 0.08638888]], ['partial repair probe 1', [[2100, 1, 28], [2100, 7, 31], 0.0435], [97.776667, 0.04509876]], ['partial repair probe 2', [[2099, 3, 1], [2100, 2, 28], 0.025], [97.472222, 0.02583812]], ['boundary control 1', [[2023, 5, 1], [2023, 10, 30], 0.05], [97.472222, 0.05215161]], ['boundary control 2', [[2023, 1, 1], [2023, 1, 2], 0.05], [99.986111, 0.05070149]], ['normal control 1', [[2095, 3, 5], [2095, 9, 3], 0.001], [99.949444, 0.00101718]], ['normal control 2', [[2045, 1, 1], [2045, 7, 1], 0.025], [98.743056, 0.02566988]]]]
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 quadratic root selection 1 | [99.491667, -0.01019083] | [99.491667, 0.01019055] | Failed |
| regression quadratic root selection 2 | [97.33125, -0.05469276] | [97.33125, 0.05468459] | Failed |
| partial repair probe 1 | [91.911111, -0.09028161] | [91.911111, 0.08638888] | Failed |
| partial repair probe 2 | [95.933333, -0.08455922] | [95.933333, 0.08453969] | Failed |
| boundary control 1 | [99.986111, 0.05070149] | [99.986111, 0.05070149] | Passed |
| boundary control 2 | [97.458333, 0.05215904] | [97.458333, 0.05215904] | Passed |
| normal control 1 | [97.812917, 0.04521386] | [97.812917, 0.04521386] | Passed |
| normal control 2 | [97.345833, 0.05468048] | [97.345833, 0.05468048] | Passed |
SHA-256 / 068e7e92ac029df61547231f83e7587e00c9b9c6c8ad120ff2f83bcba8ce2b82
3 / The verified repair
Exit 0"""Failure Map reference implementation. Python standard library only."""
import json
import datetime
import math
N = 1
observations = []
def solve(settle, maturity, d):
S = datetime.date(*settle)
M = datetime.date(*maturity)
t = (M - S).days
def leap(y):
return (y % 4 == 0 and y % 100 != 0) or y % 400 == 0
horizon = S + datetime.timedelta(days=365)
basis = 366 if any(leap(y) and S < datetime.date(y, 2, 29) <= horizon for y in (S.year, S.year + 1)) else 365
price = 100 * (1 - d * t / 360)
if t <= basis / 2:
bey = basis * d / (360 - d * t)
else:
a = t / (2 * basis) - 0.25
b = t / basis
c = (price - 100) / price
bey = (-b + math.sqrt(b * b - 4 * a * c)) / (2 * a)
return [round(price, 6), round(bey, 8)]
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression quadratic root selection 1', [[2049, 2, 28], [2049, 8, 30], 0.01], [99.491667, 0.01019055]], ['regression quadratic root selection 2', [[2082, 11, 15], [2083, 5, 17], 0.0525], [97.33125, 0.05468459]], ['partial repair probe 1', [[2050, 11, 30], [2051, 11, 29], 0.08], [91.911111, 0.08638888]], ['partial repair probe 2', [[2089, 3, 11], [2089, 9, 10], 0.08], [95.933333, 0.08453969]], ['boundary control 1', [[2023, 1, 1], [2023, 1, 2], 0.05], [99.986111, 0.05070149]], ['boundary control 2', [[2023, 5, 1], [2023, 10, 31], 0.05], [97.458333, 0.05215904]], ['normal control 1', [[2023, 12, 15], [2024, 6, 13], 0.0435], [97.812917, 0.04521386]], ['normal control 2', [[2090, 7, 29], [2091, 1, 27], 0.0525], [97.345833, 0.05468048]]], [['regression quadratic root selection 1', [[2100, 12, 28], [2101, 6, 29], 0.025], [98.729167, 0.02567259]], ['regression quadratic root selection 2', [[2002, 11, 1], [2003, 5, 3], 0.0525], [97.33125, 0.05468459]], ['partial repair probe 1', [[2090, 3, 8], [2091, 3, 7], 0.0435], [95.601667, 0.04561452]], ['partial repair probe 2', [[2013, 8, 17], [2014, 2, 16], 0.08], [95.933333, 0.08453969]], ['boundary control 1', [[2023, 5, 1], [2023, 10, 30], 0.05], [97.472222, 0.05215161]], ['boundary control 2', [[2023, 1, 1], [2023, 1, 2], 0.05], [99.986111, 0.05070149]], ['normal control 1', [[2099, 3, 1], [2099, 8, 29], 0.08], [95.977778, 0.0845103]], ['normal control 2', [[2081, 5, 27], [2081, 9, 1], 0.0435], [98.827917, 0.04462724]]], [['regression quadratic root selection 1', [[2099, 3, 28], [2100, 3, 27], 0.01], [98.988889, 0.01021643]], ['regression quadratic root selection 2', [[2065, 8, 13], [2066, 8, 12], 0.0435], [95.601667, 0.04561452]], ['partial repair probe 1', [[2073, 4, 5], [2073, 10, 5], 0.01], [99.491667, 0.01019055]], ['partial repair probe 2', [[1998, 12, 30], [1999, 11, 28], 0.0435], [95.97625, 0.04548568]], ['boundary control 1', [[2023, 5, 1], [2023, 10, 31], 0.05], [97.458333, 0.05215904]], ['boundary control 2', [[2023, 1, 1], [2023, 1, 2], 0.05], [99.986111, 0.05070149]], ['normal control 1', [[2075, 1, 30], [2075, 7, 31], 0.0525], [97.345833, 0.05468048]], ['normal control 2', [[2077, 9, 11], [2078, 3, 12], 0.01], [99.494444, 0.01019041]]], [['regression quadratic root selection 1', [[2070, 4, 30], [2070, 10, 30], 0.08], [95.933333, 0.08453969]], ['regression quadratic root selection 2', [[2100, 12, 15], [2101, 6, 16], 0.08], [95.933333, 0.08453969]], ['partial repair probe 1', [[2074, 4, 20], [2074, 10, 21], 0.0435], [97.776667, 0.04509876]], ['partial repair probe 2', [[2071, 7, 14], [2072, 7, 12], 0.001], [99.898889, 0.00101744]], ['boundary control 1', [[2023, 5, 1], [2023, 10, 31], 0.05], [97.458333, 0.05215904]], ['boundary control 2', [[2023, 5, 1], [2023, 10, 30], 0.05], [97.472222, 0.05215161]], ['normal control 1', [[2032, 2, 5], [2032, 8, 6], 0.025], [98.729167, 0.02574383]], ['normal control 2', [[2027, 12, 1], [2028, 6, 1], 0.025], [98.729167, 0.02574383]]], [['regression quadratic root selection 1', [[2093, 10, 27], [2094, 5, 1], 0.025], [98.708333, 0.02567271]], ['regression quadratic root selection 2', [[2004, 2, 29], [2005, 2, 27], 0.08], [91.911111, 0.08638888]], ['partial repair probe 1', [[2100, 1, 28], [2100, 7, 31], 0.0435], [97.776667, 0.04509876]], ['partial repair probe 2', [[2099, 3, 1], [2100, 2, 28], 0.025], [97.472222, 0.02583812]], ['boundary control 1', [[2023, 5, 1], [2023, 10, 30], 0.05], [97.472222, 0.05215161]], ['boundary control 2', [[2023, 1, 1], [2023, 1, 2], 0.05], [99.986111, 0.05070149]], ['normal control 1', [[2095, 3, 5], [2095, 9, 3], 0.001], [99.949444, 0.00101718]], ['normal control 2', [[2045, 1, 1], [2045, 7, 1], 0.025], [98.743056, 0.02566988]]]]
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 quadratic root selection 1 | [99.491667, 0.01019055] | [99.491667, 0.01019055] | Passed |
| regression quadratic root selection 2 | [97.33125, 0.05468459] | [97.33125, 0.05468459] | Passed |
| partial repair probe 1 | [91.911111, 0.08638888] | [91.911111, 0.08638888] | Passed |
| partial repair probe 2 | [95.933333, 0.08453969] | [95.933333, 0.08453969] | Passed |
| boundary control 1 | [99.986111, 0.05070149] | [99.986111, 0.05070149] | Passed |
| boundary control 2 | [97.458333, 0.05215904] | [97.458333, 0.05215904] | Passed |
| normal control 1 | [97.812917, 0.04521386] | [97.812917, 0.04521386] | Passed |
| normal control 2 | [97.345833, 0.05468048] | [97.345833, 0.05468048] | Passed |
SHA-256 / 45c143426c677d1f7f711b5e827816abb60069b4beb79b4618e7d880cece5b04
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.131267+00:00.
Case digest / a6f239d5b9122bec1b0236f3253021f05cc9daa3d21ecc574a755d19ff295d36