FAILURE MAP
← Case archive

FA-84561 / Betting odds conversion / Open access

Negative Kelly fraction not floored at zero · case 01

A bet without an edge reports a negative fraction or a negative stake.

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

ROOT CAUSE

The negative Kelly fraction is never clamped.

VERIFIED REPAIR

Floor the full Kelly fraction at zero before using or reporting it.

Unsuccessful approach: Clamping only the stake still reports a negative Kelly fraction.

Case contract

Kelly staking. With b = price - 1, p = prob and q = 1 - p, the full Kelly fraction is (b * p - q) / b, floored at 0 when the edge is not positive. The stake is bankroll * min(full Kelly * fraction, max_pct / 100), rounded down to a cent. Return [full Kelly fraction rounded half up to four decimals as a string, stake cents].

Why this case matters

Bankroll tools size stakes with fractional Kelly and a hard cap.

1 / The failure

Exit 1
"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
import math
N = 1
observations = []
def solve(prob, price, fraction, bankroll_cents, max_pct):
    p = Fraction(prob)
    b = Fraction(price) - 1
    q = 1 - p
    k = (b * p - q) / b
    use = min(k * Fraction(fraction), Fraction(max_pct) / 100)
    stake = math.floor(bankroll_cents * use)
    r = math.floor(k * 10000 + Fraction(1, 2))
    return ['%d.%04d' % (r // 10000, r % 10000), stake]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
def run(args):
    try:
        return solve(*args)
    except Exception as exc:
        return 'raised ' + type(exc).__name__
cases = [[('control even-money edge', ('0.55', '2.00', '1', 100000, '100'), ['0.1000', 10000]),
  ('control half kelly', ('0.55', '2.00', '0.5', 100000, '100'), ['0.1000', 5000]),
  ('boundary capped stake', ('0.60', '2.00', '1', 100000, '5'), ['0.2000', 5000]),
  ('boundary no edge', ('0.40', '2.00', '1', 100000, '5'), ['0.0000', 0]),
  ('control underdog edge', ('0.30', '4.00', '1', 100000, '100'), ['0.0667', 6666]),
  ('regression: negative edge clamp', ('0.55', '1.76', '0.5', 50000, '100'), ['0.0000', 0]),
  ('variant scenario 1', ('0.60', '2.27', '1', 100000, '10'), ['0.2850', 10000]),
  ('variant scenario 2', ('0.55', '3.87', '0.25', 50000, '2'), ['0.3932', 1000])],
 [('control even-money edge', ('0.55', '2.00', '1', 100000, '100'), ['0.1000', 10000]),
  ('control half kelly', ('0.55', '2.00', '0.5', 100000, '100'), ['0.1000', 5000]),
  ('boundary capped stake', ('0.60', '2.00', '1', 100000, '5'), ['0.2000', 5000]),
  ('boundary no edge', ('0.40', '2.00', '1', 100000, '5'), ['0.0000', 0]),
  ('control underdog edge', ('0.30', '4.00', '1', 100000, '100'), ['0.0667', 6666]),
  ('regression: negative edge clamp', ('0.50', '1.85', '1', 12345, '10'), ['0.0000', 0]),
  ('variant scenario 1', ('0.60', '3.34', '0.5', 50000, '10'), ['0.4291', 5000]),
  ('variant scenario 2', ('0.55', '5.29', '0.25', 100000, '2'), ['0.4451', 2000])],
 [('control even-money edge', ('0.55', '2.00', '1', 100000, '100'), ['0.1000', 10000]),
  ('control half kelly', ('0.55', '2.00', '0.5', 100000, '100'), ['0.1000', 5000]),
  ('boundary capped stake', ('0.60', '2.00', '1', 100000, '5'), ['0.2000', 5000]),
  ('boundary no edge', ('0.40', '2.00', '1', 100000, '5'), ['0.0000', 0]),
  ('control underdog edge', ('0.30', '4.00', '1', 100000, '100'), ['0.0667', 6666]),
  ('regression: negative edge clamp', ('0.50', '1.79', '0.25', 100000, '5'), ['0.0000', 0]),
  ('variant scenario 1', ('0.73', '4.25', '0.25', 12345, '100'), ['0.6469', 1996]),
  ('variant scenario 2', ('0.50', '5.61', '0.25', 12345, '2'), ['0.3915', 246])],
 [('control even-money edge', ('0.55', '2.00', '1', 100000, '100'), ['0.1000', 10000]),
  ('control half kelly', ('0.55', '2.00', '0.5', 100000, '100'), ['0.1000', 5000]),
  ('boundary capped stake', ('0.60', '2.00', '1', 100000, '5'), ['0.2000', 5000]),
  ('boundary no edge', ('0.40', '2.00', '1', 100000, '5'), ['0.0000', 0]),
  ('control underdog edge', ('0.30', '4.00', '1', 100000, '100'), ['0.0667', 6666]),
  ('regression: negative edge clamp', ('0.50', '1.43', '0.5', 50000, '100'), ['0.0000', 0]),
  ('variant scenario 1', ('0.55', '5.15', '0.5', 100000, '2'), ['0.4416', 2000]),
  ('variant scenario 2', ('0.60', '4.44', '0.5', 100000, '100'), ['0.4837', 24186])],
 [('control even-money edge', ('0.55', '2.00', '1', 100000, '100'), ['0.1000', 10000]),
  ('control half kelly', ('0.55', '2.00', '0.5', 100000, '100'), ['0.1000', 5000]),
  ('boundary capped stake', ('0.60', '2.00', '1', 100000, '5'), ['0.2000', 5000]),
  ('boundary no edge', ('0.40', '2.00', '1', 100000, '5'), ['0.0000', 0]),
  ('control underdog edge', ('0.30', '4.00', '1', 100000, '100'), ['0.0667', 6666]),
  ('regression: negative edge clamp', ('0.50', '1.63', '0.25', 100000, '100'), ['0.0000', 0]),
  ('variant scenario 1', ('0.39', '3.57', '1', 12345, '100'), ['0.1526', 1884]),
  ('variant scenario 2', ('0.50', '4.50', '1', 50000, '2'), ['0.3571', 1000])]]
for label, args, expected in cases[N - 1]:
    check(label, run(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
control even-money edge['0.1000', 10000]['0.1000', 10000]Passed
control half kelly['0.1000', 5000]['0.1000', 5000]Passed
boundary capped stake['0.2000', 5000]['0.2000', 5000]Passed
boundary no edge['-1.8000', -20000]['0.0000', 0]Failed
control underdog edge['0.0667', 6666]['0.0667', 6666]Passed
regression: negative edge clamp['-1.9579', -1053]['0.0000', 0]Failed
variant scenario 1['0.2850', 10000]['0.2850', 10000]Passed
variant scenario 2['0.3932', 1000]['0.3932', 1000]Passed

SHA-256 / b1c5286b37f993d45d714cba23467790057df419d24003288a9e4b525f581414

2 / The unsuccessful fix

Exit 1
"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
import math
N = 1
observations = []
def solve(prob, price, fraction, bankroll_cents, max_pct):
    p = Fraction(prob)
    b = Fraction(price) - 1
    q = 1 - p
    k = (b * p - q) / b
    use = max(0, min(k * Fraction(fraction), Fraction(max_pct) / 100))
    stake = math.floor(bankroll_cents * use)
    r = math.floor(k * 10000 + Fraction(1, 2))
    return ['%d.%04d' % (r // 10000, r % 10000), stake]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
def run(args):
    try:
        return solve(*args)
    except Exception as exc:
        return 'raised ' + type(exc).__name__
cases = [[('control even-money edge', ('0.55', '2.00', '1', 100000, '100'), ['0.1000', 10000]),
  ('control half kelly', ('0.55', '2.00', '0.5', 100000, '100'), ['0.1000', 5000]),
  ('boundary capped stake', ('0.60', '2.00', '1', 100000, '5'), ['0.2000', 5000]),
  ('boundary no edge', ('0.40', '2.00', '1', 100000, '5'), ['0.0000', 0]),
  ('control underdog edge', ('0.30', '4.00', '1', 100000, '100'), ['0.0667', 6666]),
  ('regression: negative edge clamp', ('0.55', '1.76', '0.5', 50000, '100'), ['0.0000', 0]),
  ('variant scenario 1', ('0.60', '2.27', '1', 100000, '10'), ['0.2850', 10000]),
  ('variant scenario 2', ('0.55', '3.87', '0.25', 50000, '2'), ['0.3932', 1000])],
 [('control even-money edge', ('0.55', '2.00', '1', 100000, '100'), ['0.1000', 10000]),
  ('control half kelly', ('0.55', '2.00', '0.5', 100000, '100'), ['0.1000', 5000]),
  ('boundary capped stake', ('0.60', '2.00', '1', 100000, '5'), ['0.2000', 5000]),
  ('boundary no edge', ('0.40', '2.00', '1', 100000, '5'), ['0.0000', 0]),
  ('control underdog edge', ('0.30', '4.00', '1', 100000, '100'), ['0.0667', 6666]),
  ('regression: negative edge clamp', ('0.50', '1.85', '1', 12345, '10'), ['0.0000', 0]),
  ('variant scenario 1', ('0.60', '3.34', '0.5', 50000, '10'), ['0.4291', 5000]),
  ('variant scenario 2', ('0.55', '5.29', '0.25', 100000, '2'), ['0.4451', 2000])],
 [('control even-money edge', ('0.55', '2.00', '1', 100000, '100'), ['0.1000', 10000]),
  ('control half kelly', ('0.55', '2.00', '0.5', 100000, '100'), ['0.1000', 5000]),
  ('boundary capped stake', ('0.60', '2.00', '1', 100000, '5'), ['0.2000', 5000]),
  ('boundary no edge', ('0.40', '2.00', '1', 100000, '5'), ['0.0000', 0]),
  ('control underdog edge', ('0.30', '4.00', '1', 100000, '100'), ['0.0667', 6666]),
  ('regression: negative edge clamp', ('0.50', '1.79', '0.25', 100000, '5'), ['0.0000', 0]),
  ('variant scenario 1', ('0.73', '4.25', '0.25', 12345, '100'), ['0.6469', 1996]),
  ('variant scenario 2', ('0.50', '5.61', '0.25', 12345, '2'), ['0.3915', 246])],
 [('control even-money edge', ('0.55', '2.00', '1', 100000, '100'), ['0.1000', 10000]),
  ('control half kelly', ('0.55', '2.00', '0.5', 100000, '100'), ['0.1000', 5000]),
  ('boundary capped stake', ('0.60', '2.00', '1', 100000, '5'), ['0.2000', 5000]),
  ('boundary no edge', ('0.40', '2.00', '1', 100000, '5'), ['0.0000', 0]),
  ('control underdog edge', ('0.30', '4.00', '1', 100000, '100'), ['0.0667', 6666]),
  ('regression: negative edge clamp', ('0.50', '1.43', '0.5', 50000, '100'), ['0.0000', 0]),
  ('variant scenario 1', ('0.55', '5.15', '0.5', 100000, '2'), ['0.4416', 2000]),
  ('variant scenario 2', ('0.60', '4.44', '0.5', 100000, '100'), ['0.4837', 24186])],
 [('control even-money edge', ('0.55', '2.00', '1', 100000, '100'), ['0.1000', 10000]),
  ('control half kelly', ('0.55', '2.00', '0.5', 100000, '100'), ['0.1000', 5000]),
  ('boundary capped stake', ('0.60', '2.00', '1', 100000, '5'), ['0.2000', 5000]),
  ('boundary no edge', ('0.40', '2.00', '1', 100000, '5'), ['0.0000', 0]),
  ('control underdog edge', ('0.30', '4.00', '1', 100000, '100'), ['0.0667', 6666]),
  ('regression: negative edge clamp', ('0.50', '1.63', '0.25', 100000, '100'), ['0.0000', 0]),
  ('variant scenario 1', ('0.39', '3.57', '1', 12345, '100'), ['0.1526', 1884]),
  ('variant scenario 2', ('0.50', '4.50', '1', 50000, '2'), ['0.3571', 1000])]]
for label, args, expected in cases[N - 1]:
    check(label, run(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
control even-money edge['0.1000', 10000]['0.1000', 10000]Passed
control half kelly['0.1000', 5000]['0.1000', 5000]Passed
boundary capped stake['0.2000', 5000]['0.2000', 5000]Passed
boundary no edge['-1.8000', 0]['0.0000', 0]Failed
control underdog edge['0.0667', 6666]['0.0667', 6666]Passed
regression: negative edge clamp['-1.9579', 0]['0.0000', 0]Failed
variant scenario 1['0.2850', 10000]['0.2850', 10000]Passed
variant scenario 2['0.3932', 1000]['0.3932', 1000]Passed

SHA-256 / fb1e166c350ba9963a94dc4d7600137eec4f66e6577337f5dd5ed4741a6ebff0

3 / The verified repair

Exit 0
"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
import math
N = 1
observations = []
def solve(prob, price, fraction, bankroll_cents, max_pct):
    p = Fraction(prob)
    b = Fraction(price) - 1
    q = 1 - p
    k = (b * p - q) / b
    if k < 0:
        k = Fraction(0)
    use = min(k * Fraction(fraction), Fraction(max_pct) / 100)
    stake = math.floor(bankroll_cents * use)
    r = math.floor(k * 10000 + Fraction(1, 2))
    return ['%d.%04d' % (r // 10000, r % 10000), stake]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
def run(args):
    try:
        return solve(*args)
    except Exception as exc:
        return 'raised ' + type(exc).__name__
cases = [[('control even-money edge', ('0.55', '2.00', '1', 100000, '100'), ['0.1000', 10000]),
  ('control half kelly', ('0.55', '2.00', '0.5', 100000, '100'), ['0.1000', 5000]),
  ('boundary capped stake', ('0.60', '2.00', '1', 100000, '5'), ['0.2000', 5000]),
  ('boundary no edge', ('0.40', '2.00', '1', 100000, '5'), ['0.0000', 0]),
  ('control underdog edge', ('0.30', '4.00', '1', 100000, '100'), ['0.0667', 6666]),
  ('regression: negative edge clamp', ('0.55', '1.76', '0.5', 50000, '100'), ['0.0000', 0]),
  ('variant scenario 1', ('0.60', '2.27', '1', 100000, '10'), ['0.2850', 10000]),
  ('variant scenario 2', ('0.55', '3.87', '0.25', 50000, '2'), ['0.3932', 1000])],
 [('control even-money edge', ('0.55', '2.00', '1', 100000, '100'), ['0.1000', 10000]),
  ('control half kelly', ('0.55', '2.00', '0.5', 100000, '100'), ['0.1000', 5000]),
  ('boundary capped stake', ('0.60', '2.00', '1', 100000, '5'), ['0.2000', 5000]),
  ('boundary no edge', ('0.40', '2.00', '1', 100000, '5'), ['0.0000', 0]),
  ('control underdog edge', ('0.30', '4.00', '1', 100000, '100'), ['0.0667', 6666]),
  ('regression: negative edge clamp', ('0.50', '1.85', '1', 12345, '10'), ['0.0000', 0]),
  ('variant scenario 1', ('0.60', '3.34', '0.5', 50000, '10'), ['0.4291', 5000]),
  ('variant scenario 2', ('0.55', '5.29', '0.25', 100000, '2'), ['0.4451', 2000])],
 [('control even-money edge', ('0.55', '2.00', '1', 100000, '100'), ['0.1000', 10000]),
  ('control half kelly', ('0.55', '2.00', '0.5', 100000, '100'), ['0.1000', 5000]),
  ('boundary capped stake', ('0.60', '2.00', '1', 100000, '5'), ['0.2000', 5000]),
  ('boundary no edge', ('0.40', '2.00', '1', 100000, '5'), ['0.0000', 0]),
  ('control underdog edge', ('0.30', '4.00', '1', 100000, '100'), ['0.0667', 6666]),
  ('regression: negative edge clamp', ('0.50', '1.79', '0.25', 100000, '5'), ['0.0000', 0]),
  ('variant scenario 1', ('0.73', '4.25', '0.25', 12345, '100'), ['0.6469', 1996]),
  ('variant scenario 2', ('0.50', '5.61', '0.25', 12345, '2'), ['0.3915', 246])],
 [('control even-money edge', ('0.55', '2.00', '1', 100000, '100'), ['0.1000', 10000]),
  ('control half kelly', ('0.55', '2.00', '0.5', 100000, '100'), ['0.1000', 5000]),
  ('boundary capped stake', ('0.60', '2.00', '1', 100000, '5'), ['0.2000', 5000]),
  ('boundary no edge', ('0.40', '2.00', '1', 100000, '5'), ['0.0000', 0]),
  ('control underdog edge', ('0.30', '4.00', '1', 100000, '100'), ['0.0667', 6666]),
  ('regression: negative edge clamp', ('0.50', '1.43', '0.5', 50000, '100'), ['0.0000', 0]),
  ('variant scenario 1', ('0.55', '5.15', '0.5', 100000, '2'), ['0.4416', 2000]),
  ('variant scenario 2', ('0.60', '4.44', '0.5', 100000, '100'), ['0.4837', 24186])],
 [('control even-money edge', ('0.55', '2.00', '1', 100000, '100'), ['0.1000', 10000]),
  ('control half kelly', ('0.55', '2.00', '0.5', 100000, '100'), ['0.1000', 5000]),
  ('boundary capped stake', ('0.60', '2.00', '1', 100000, '5'), ['0.2000', 5000]),
  ('boundary no edge', ('0.40', '2.00', '1', 100000, '5'), ['0.0000', 0]),
  ('control underdog edge', ('0.30', '4.00', '1', 100000, '100'), ['0.0667', 6666]),
  ('regression: negative edge clamp', ('0.50', '1.63', '0.25', 100000, '100'), ['0.0000', 0]),
  ('variant scenario 1', ('0.39', '3.57', '1', 12345, '100'), ['0.1526', 1884]),
  ('variant scenario 2', ('0.50', '4.50', '1', 50000, '2'), ['0.3571', 1000])]]
for label, args, expected in cases[N - 1]:
    check(label, run(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
control even-money edge['0.1000', 10000]['0.1000', 10000]Passed
control half kelly['0.1000', 5000]['0.1000', 5000]Passed
boundary capped stake['0.2000', 5000]['0.2000', 5000]Passed
boundary no edge['0.0000', 0]['0.0000', 0]Passed
control underdog edge['0.0667', 6666]['0.0667', 6666]Passed
regression: negative edge clamp['0.0000', 0]['0.0000', 0]Passed
variant scenario 1['0.2850', 10000]['0.2850', 10000]Passed
variant scenario 2['0.3932', 1000]['0.3932', 1000]Passed

SHA-256 / 53bf67228da9f321a6e0c0de9f5a35d1beee1a96f75473d3ad49aa6de7e4fc83

Verification & scope

Stipulated, bounded toy contract stated in the contract field; not a claim of conformance with any operator, exchange or regulator rule set. 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:50:31.994565+00:00.

Case digest / 2220937f318307d6117d891340e7f1db56c9cd4147be3df6ba30824de19d8c30