FAILURE MAP
← Case archive

FA-84691 / Betting odds conversion / Open access

Cash-out value scaled by profit ratios instead of price ratios · case 01

Offers are far too high or low when prices move.

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

ROOT CAUSE

The valuation uses (price - 1) / (current - 1) instead of price / current.

VERIFIED REPAIR

Scale the stake by price taken over current price for each open leg.

Unsuccessful approach: Using the price ratio for open legs but the profit for settled legs still misvalues multiples.

Case contract

Cash-out offer for a single or multiple back bet. legs rows are [price taken, current] where current is a decimal price for an open leg, "won" or "lost". Any lost leg makes the offer [0, 0]. Otherwise value = stake * product of prices taken / product of current prices of open legs, reduced by margin_pct percent, rounded down to a cent. partial_cents 0 means full cash-out: return [value, 0]. A partial amount above the value returns "invalid"; otherwise return [partial, remaining stake] with remaining = floor(stake * (1 - partial / value)).

Why this case matters

Cash-out and partial cash-out offers are recomputed from live prices on every tick.

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(legs, stake_cents, margin_pct, partial_cents):
    value = Fraction(stake_cents)
    for price, cur in legs:
        if cur == 'lost':
            return [0, 0]
        value *= Fraction(price) - 1
        if cur != 'won':
            value /= Fraction(cur) - 1
    value = value * (100 - Fraction(margin_pct)) / 100
    full = math.floor(value)
    if partial_cents == 0:
        return [full, 0]
    if partial_cents > full:
        return 'invalid'
    remaining = math.floor(stake_cents * (1 - Fraction(partial_cents, full)))
    return [partial_cents, remaining]
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 single shortened', ([['3.00', '2.00']], 1000, '0', 0), [1500, 0]),
  ('control margin applied', ([['3.00', '2.00']], 1000, '5', 0), [1425, 0]),
  ('boundary won leg keeps price', ([['2.00', 'won'], ['2.00', '1.50']], 1000, '0', 0), [2666, 0]),
  ('boundary partial cash out', ([['3.00', '2.00']], 1000, '0', 500), [500, 666]),
  ('control lost leg', ([['2.00', 'lost'], ['2.00', '1.50']], 1000, '0', 0), [0, 0]),
  ('boundary partial above value', ([['2.00', '4.00']], 1000, '0', 600), 'invalid'),
  ('regression: price ratio', ([['3.04', 'won']], 2500, '0', 200), [200, 2434]),
  ('regression: price ratio', ([['4.46', '3.15']], 2500, '7.5', 500), [500, 2118]),
  ('variant scenario 1', ([['3.10', '4.55'], ['2.81', 'lost']], 2500, '0', 800), [0, 0]),
  ('variant scenario 2',
   ([['4.23', '2.69'], ['3.78', 'lost'], ['3.20', '3.35']], 1000, '7.5', 200),
   [0, 0])],
 [('control single shortened', ([['3.00', '2.00']], 1000, '0', 0), [1500, 0]),
  ('control margin applied', ([['3.00', '2.00']], 1000, '5', 0), [1425, 0]),
  ('boundary won leg keeps price', ([['2.00', 'won'], ['2.00', '1.50']], 1000, '0', 0), [2666, 0]),
  ('boundary partial cash out', ([['3.00', '2.00']], 1000, '0', 500), [500, 666]),
  ('control lost leg', ([['2.00', 'lost'], ['2.00', '1.50']], 1000, '0', 0), [0, 0]),
  ('boundary partial above value', ([['2.00', '4.00']], 1000, '0', 600), 'invalid'),
  ('regression: price ratio',
   ([['3.57', '2.52'], ['4.50', '4.68'], ['4.10', '5.08']], 500, '0', 200),
   [200, 317]),
  ('variant scenario 1', ([['2.62', 'lost'], ['2.60', 'won']], 500, '5', 0), [0, 0]),
  ('variant scenario 2', ([['2.11', '4.37']], 2500, '5', 0), [1146, 0])],
 [('control single shortened', ([['3.00', '2.00']], 1000, '0', 0), [1500, 0]),
  ('control margin applied', ([['3.00', '2.00']], 1000, '5', 0), [1425, 0]),
  ('boundary won leg keeps price', ([['2.00', 'won'], ['2.00', '1.50']], 1000, '0', 0), [2666, 0]),
  ('boundary partial cash out', ([['3.00', '2.00']], 1000, '0', 500), [500, 666]),
  ('control lost leg', ([['2.00', 'lost'], ['2.00', '1.50']], 1000, '0', 0), [0, 0]),
  ('boundary partial above value', ([['2.00', '4.00']], 1000, '0', 600), 'invalid'),
  ('regression: price ratio',
   ([['2.58', 'won'], ['4.59', '4.36'], ['2.12', '5.27']], 1000, '7.5', 0),
   [1010, 0]),
  ('variant scenario 1',
   ([['2.10', 'lost'], ['4.52', '4.26'], ['3.40', '4.12']], 1000, '5', 500),
   [0, 0]),
  ('variant scenario 2', ([['4.81', 'lost']], 500, '5', 500), [0, 0])],
 [('control single shortened', ([['3.00', '2.00']], 1000, '0', 0), [1500, 0]),
  ('control margin applied', ([['3.00', '2.00']], 1000, '5', 0), [1425, 0]),
  ('boundary won leg keeps price', ([['2.00', 'won'], ['2.00', '1.50']], 1000, '0', 0), [2666, 0]),
  ('boundary partial cash out', ([['3.00', '2.00']], 1000, '0', 500), [500, 666]),
  ('control lost leg', ([['2.00', 'lost'], ['2.00', '1.50']], 1000, '0', 0), [0, 0]),
  ('boundary partial above value', ([['2.00', '4.00']], 1000, '0', 600), 'invalid'),
  ('regression: price ratio', ([['4.82', '4.94'], ['3.03', '2.37']], 500, '5', 800), 'invalid'),
  ('regression: price ratio', ([['3.37', '3.69']], 1000, '5', 500), [500, 423]),
  ('variant scenario 1', ([['2.71', 'won'], ['4.12', 'lost']], 500, '5', 500), [0, 0]),
  ('variant scenario 2',
   ([['1.37', '4.05'], ['2.46', 'won'], ['3.51', 'lost'], ['2.03', '2.32']], 2500, '0', 0),
   [0, 0])],
 [('control single shortened', ([['3.00', '2.00']], 1000, '0', 0), [1500, 0]),
  ('control margin applied', ([['3.00', '2.00']], 1000, '5', 0), [1425, 0]),
  ('boundary won leg keeps price', ([['2.00', 'won'], ['2.00', '1.50']], 1000, '0', 0), [2666, 0]),
  ('boundary partial cash out', ([['3.00', '2.00']], 1000, '0', 500), [500, 666]),
  ('control lost leg', ([['2.00', 'lost'], ['2.00', '1.50']], 1000, '0', 0), [0, 0]),
  ('boundary partial above value', ([['2.00', '4.00']], 1000, '0', 600), 'invalid'),
  ('regression: price ratio', ([['2.66', '3.93']], 500, '7.5', 0), [313, 0]),
  ('variant scenario 1',
   ([['4.87', '2.93'], ['1.43', '5.36'], ['2.11', 'lost']], 2500, '7.5', 200),
   [0, 0]),
  ('variant scenario 2',
   ([['4.96', '3.65'], ['3.57', 'lost'], ['3.36', 'won'], ['4.39', 'lost']], 500, '0', 0),
   [0, 0])]]
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 single shortened[2000, 0][1500, 0]Failed
control margin applied[1900, 0][1425, 0]Failed
boundary won leg keeps price[2000, 0][2666, 0]Failed
boundary partial cash out[500, 750][500, 666]Failed
control lost leg[0, 0][0, 0]Passed
boundary partial above valueinvalidinvalidPassed
regression: price ratio[200, 2401][200, 2434]Failed
regression: price ratio[500, 2164][500, 2118]Failed
variant scenario 1[0, 0][0, 0]Passed
variant scenario 2[0, 0][0, 0]Passed

SHA-256 / 0388d12c7b0b41bf847afcd8072e015f5316707f7d9c4ac42a29cb136d5e33f1

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(legs, stake_cents, margin_pct, partial_cents):
    value = Fraction(stake_cents)
    for price, cur in legs:
        if cur == 'lost':
            return [0, 0]
        value *= Fraction(price)
        if cur != 'won':
            value /= Fraction(cur) - 1
    value = value * (100 - Fraction(margin_pct)) / 100
    full = math.floor(value)
    if partial_cents == 0:
        return [full, 0]
    if partial_cents > full:
        return 'invalid'
    remaining = math.floor(stake_cents * (1 - Fraction(partial_cents, full)))
    return [partial_cents, remaining]
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 single shortened', ([['3.00', '2.00']], 1000, '0', 0), [1500, 0]),
  ('control margin applied', ([['3.00', '2.00']], 1000, '5', 0), [1425, 0]),
  ('boundary won leg keeps price', ([['2.00', 'won'], ['2.00', '1.50']], 1000, '0', 0), [2666, 0]),
  ('boundary partial cash out', ([['3.00', '2.00']], 1000, '0', 500), [500, 666]),
  ('control lost leg', ([['2.00', 'lost'], ['2.00', '1.50']], 1000, '0', 0), [0, 0]),
  ('boundary partial above value', ([['2.00', '4.00']], 1000, '0', 600), 'invalid'),
  ('regression: price ratio', ([['3.04', 'won']], 2500, '0', 200), [200, 2434]),
  ('regression: price ratio', ([['4.46', '3.15']], 2500, '7.5', 500), [500, 2118]),
  ('variant scenario 1', ([['3.10', '4.55'], ['2.81', 'lost']], 2500, '0', 800), [0, 0]),
  ('variant scenario 2',
   ([['4.23', '2.69'], ['3.78', 'lost'], ['3.20', '3.35']], 1000, '7.5', 200),
   [0, 0])],
 [('control single shortened', ([['3.00', '2.00']], 1000, '0', 0), [1500, 0]),
  ('control margin applied', ([['3.00', '2.00']], 1000, '5', 0), [1425, 0]),
  ('boundary won leg keeps price', ([['2.00', 'won'], ['2.00', '1.50']], 1000, '0', 0), [2666, 0]),
  ('boundary partial cash out', ([['3.00', '2.00']], 1000, '0', 500), [500, 666]),
  ('control lost leg', ([['2.00', 'lost'], ['2.00', '1.50']], 1000, '0', 0), [0, 0]),
  ('boundary partial above value', ([['2.00', '4.00']], 1000, '0', 600), 'invalid'),
  ('regression: price ratio',
   ([['3.57', '2.52'], ['4.50', '4.68'], ['4.10', '5.08']], 500, '0', 200),
   [200, 317]),
  ('variant scenario 1', ([['2.62', 'lost'], ['2.60', 'won']], 500, '5', 0), [0, 0]),
  ('variant scenario 2', ([['2.11', '4.37']], 2500, '5', 0), [1146, 0])],
 [('control single shortened', ([['3.00', '2.00']], 1000, '0', 0), [1500, 0]),
  ('control margin applied', ([['3.00', '2.00']], 1000, '5', 0), [1425, 0]),
  ('boundary won leg keeps price', ([['2.00', 'won'], ['2.00', '1.50']], 1000, '0', 0), [2666, 0]),
  ('boundary partial cash out', ([['3.00', '2.00']], 1000, '0', 500), [500, 666]),
  ('control lost leg', ([['2.00', 'lost'], ['2.00', '1.50']], 1000, '0', 0), [0, 0]),
  ('boundary partial above value', ([['2.00', '4.00']], 1000, '0', 600), 'invalid'),
  ('regression: price ratio',
   ([['2.58', 'won'], ['4.59', '4.36'], ['2.12', '5.27']], 1000, '7.5', 0),
   [1010, 0]),
  ('variant scenario 1',
   ([['2.10', 'lost'], ['4.52', '4.26'], ['3.40', '4.12']], 1000, '5', 500),
   [0, 0]),
  ('variant scenario 2', ([['4.81', 'lost']], 500, '5', 500), [0, 0])],
 [('control single shortened', ([['3.00', '2.00']], 1000, '0', 0), [1500, 0]),
  ('control margin applied', ([['3.00', '2.00']], 1000, '5', 0), [1425, 0]),
  ('boundary won leg keeps price', ([['2.00', 'won'], ['2.00', '1.50']], 1000, '0', 0), [2666, 0]),
  ('boundary partial cash out', ([['3.00', '2.00']], 1000, '0', 500), [500, 666]),
  ('control lost leg', ([['2.00', 'lost'], ['2.00', '1.50']], 1000, '0', 0), [0, 0]),
  ('boundary partial above value', ([['2.00', '4.00']], 1000, '0', 600), 'invalid'),
  ('regression: price ratio', ([['4.82', '4.94'], ['3.03', '2.37']], 500, '5', 800), 'invalid'),
  ('regression: price ratio', ([['3.37', '3.69']], 1000, '5', 500), [500, 423]),
  ('variant scenario 1', ([['2.71', 'won'], ['4.12', 'lost']], 500, '5', 500), [0, 0]),
  ('variant scenario 2',
   ([['1.37', '4.05'], ['2.46', 'won'], ['3.51', 'lost'], ['2.03', '2.32']], 2500, '0', 0),
   [0, 0])],
 [('control single shortened', ([['3.00', '2.00']], 1000, '0', 0), [1500, 0]),
  ('control margin applied', ([['3.00', '2.00']], 1000, '5', 0), [1425, 0]),
  ('boundary won leg keeps price', ([['2.00', 'won'], ['2.00', '1.50']], 1000, '0', 0), [2666, 0]),
  ('boundary partial cash out', ([['3.00', '2.00']], 1000, '0', 500), [500, 666]),
  ('control lost leg', ([['2.00', 'lost'], ['2.00', '1.50']], 1000, '0', 0), [0, 0]),
  ('boundary partial above value', ([['2.00', '4.00']], 1000, '0', 600), 'invalid'),
  ('regression: price ratio', ([['2.66', '3.93']], 500, '7.5', 0), [313, 0]),
  ('variant scenario 1',
   ([['4.87', '2.93'], ['1.43', '5.36'], ['2.11', 'lost']], 2500, '7.5', 200),
   [0, 0]),
  ('variant scenario 2',
   ([['4.96', '3.65'], ['3.57', 'lost'], ['3.36', 'won'], ['4.39', 'lost']], 500, '0', 0),
   [0, 0])]]
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 single shortened[3000, 0][1500, 0]Failed
control margin applied[2850, 0][1425, 0]Failed
boundary won leg keeps price[8000, 0][2666, 0]Failed
boundary partial cash out[500, 833][500, 666]Failed
control lost leg[0, 0][0, 0]Passed
boundary partial above value[600, 99]invalidFailed
regression: price ratio[200, 2434][200, 2434]Passed
regression: price ratio[500, 2239][500, 2118]Failed
variant scenario 1[0, 0][0, 0]Passed
variant scenario 2[0, 0][0, 0]Passed

SHA-256 / ea320b2c702d79d96efd070266e8500b8973f66ea96994021a6142a2e24fad67

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(legs, stake_cents, margin_pct, partial_cents):
    value = Fraction(stake_cents)
    for price, cur in legs:
        if cur == 'lost':
            return [0, 0]
        value *= Fraction(price)
        if cur != 'won':
            value /= Fraction(cur)
    value = value * (100 - Fraction(margin_pct)) / 100
    full = math.floor(value)
    if partial_cents == 0:
        return [full, 0]
    if partial_cents > full:
        return 'invalid'
    remaining = math.floor(stake_cents * (1 - Fraction(partial_cents, full)))
    return [partial_cents, remaining]
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 single shortened', ([['3.00', '2.00']], 1000, '0', 0), [1500, 0]),
  ('control margin applied', ([['3.00', '2.00']], 1000, '5', 0), [1425, 0]),
  ('boundary won leg keeps price', ([['2.00', 'won'], ['2.00', '1.50']], 1000, '0', 0), [2666, 0]),
  ('boundary partial cash out', ([['3.00', '2.00']], 1000, '0', 500), [500, 666]),
  ('control lost leg', ([['2.00', 'lost'], ['2.00', '1.50']], 1000, '0', 0), [0, 0]),
  ('boundary partial above value', ([['2.00', '4.00']], 1000, '0', 600), 'invalid'),
  ('regression: price ratio', ([['3.04', 'won']], 2500, '0', 200), [200, 2434]),
  ('regression: price ratio', ([['4.46', '3.15']], 2500, '7.5', 500), [500, 2118]),
  ('variant scenario 1', ([['3.10', '4.55'], ['2.81', 'lost']], 2500, '0', 800), [0, 0]),
  ('variant scenario 2',
   ([['4.23', '2.69'], ['3.78', 'lost'], ['3.20', '3.35']], 1000, '7.5', 200),
   [0, 0])],
 [('control single shortened', ([['3.00', '2.00']], 1000, '0', 0), [1500, 0]),
  ('control margin applied', ([['3.00', '2.00']], 1000, '5', 0), [1425, 0]),
  ('boundary won leg keeps price', ([['2.00', 'won'], ['2.00', '1.50']], 1000, '0', 0), [2666, 0]),
  ('boundary partial cash out', ([['3.00', '2.00']], 1000, '0', 500), [500, 666]),
  ('control lost leg', ([['2.00', 'lost'], ['2.00', '1.50']], 1000, '0', 0), [0, 0]),
  ('boundary partial above value', ([['2.00', '4.00']], 1000, '0', 600), 'invalid'),
  ('regression: price ratio',
   ([['3.57', '2.52'], ['4.50', '4.68'], ['4.10', '5.08']], 500, '0', 200),
   [200, 317]),
  ('variant scenario 1', ([['2.62', 'lost'], ['2.60', 'won']], 500, '5', 0), [0, 0]),
  ('variant scenario 2', ([['2.11', '4.37']], 2500, '5', 0), [1146, 0])],
 [('control single shortened', ([['3.00', '2.00']], 1000, '0', 0), [1500, 0]),
  ('control margin applied', ([['3.00', '2.00']], 1000, '5', 0), [1425, 0]),
  ('boundary won leg keeps price', ([['2.00', 'won'], ['2.00', '1.50']], 1000, '0', 0), [2666, 0]),
  ('boundary partial cash out', ([['3.00', '2.00']], 1000, '0', 500), [500, 666]),
  ('control lost leg', ([['2.00', 'lost'], ['2.00', '1.50']], 1000, '0', 0), [0, 0]),
  ('boundary partial above value', ([['2.00', '4.00']], 1000, '0', 600), 'invalid'),
  ('regression: price ratio',
   ([['2.58', 'won'], ['4.59', '4.36'], ['2.12', '5.27']], 1000, '7.5', 0),
   [1010, 0]),
  ('variant scenario 1',
   ([['2.10', 'lost'], ['4.52', '4.26'], ['3.40', '4.12']], 1000, '5', 500),
   [0, 0]),
  ('variant scenario 2', ([['4.81', 'lost']], 500, '5', 500), [0, 0])],
 [('control single shortened', ([['3.00', '2.00']], 1000, '0', 0), [1500, 0]),
  ('control margin applied', ([['3.00', '2.00']], 1000, '5', 0), [1425, 0]),
  ('boundary won leg keeps price', ([['2.00', 'won'], ['2.00', '1.50']], 1000, '0', 0), [2666, 0]),
  ('boundary partial cash out', ([['3.00', '2.00']], 1000, '0', 500), [500, 666]),
  ('control lost leg', ([['2.00', 'lost'], ['2.00', '1.50']], 1000, '0', 0), [0, 0]),
  ('boundary partial above value', ([['2.00', '4.00']], 1000, '0', 600), 'invalid'),
  ('regression: price ratio', ([['4.82', '4.94'], ['3.03', '2.37']], 500, '5', 800), 'invalid'),
  ('regression: price ratio', ([['3.37', '3.69']], 1000, '5', 500), [500, 423]),
  ('variant scenario 1', ([['2.71', 'won'], ['4.12', 'lost']], 500, '5', 500), [0, 0]),
  ('variant scenario 2',
   ([['1.37', '4.05'], ['2.46', 'won'], ['3.51', 'lost'], ['2.03', '2.32']], 2500, '0', 0),
   [0, 0])],
 [('control single shortened', ([['3.00', '2.00']], 1000, '0', 0), [1500, 0]),
  ('control margin applied', ([['3.00', '2.00']], 1000, '5', 0), [1425, 0]),
  ('boundary won leg keeps price', ([['2.00', 'won'], ['2.00', '1.50']], 1000, '0', 0), [2666, 0]),
  ('boundary partial cash out', ([['3.00', '2.00']], 1000, '0', 500), [500, 666]),
  ('control lost leg', ([['2.00', 'lost'], ['2.00', '1.50']], 1000, '0', 0), [0, 0]),
  ('boundary partial above value', ([['2.00', '4.00']], 1000, '0', 600), 'invalid'),
  ('regression: price ratio', ([['2.66', '3.93']], 500, '7.5', 0), [313, 0]),
  ('variant scenario 1',
   ([['4.87', '2.93'], ['1.43', '5.36'], ['2.11', 'lost']], 2500, '7.5', 200),
   [0, 0]),
  ('variant scenario 2',
   ([['4.96', '3.65'], ['3.57', 'lost'], ['3.36', 'won'], ['4.39', 'lost']], 500, '0', 0),
   [0, 0])]]
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 single shortened[1500, 0][1500, 0]Passed
control margin applied[1425, 0][1425, 0]Passed
boundary won leg keeps price[2666, 0][2666, 0]Passed
boundary partial cash out[500, 666][500, 666]Passed
control lost leg[0, 0][0, 0]Passed
boundary partial above valueinvalidinvalidPassed
regression: price ratio[200, 2434][200, 2434]Passed
regression: price ratio[500, 2118][500, 2118]Passed
variant scenario 1[0, 0][0, 0]Passed
variant scenario 2[0, 0][0, 0]Passed

SHA-256 / 759ed7a237cacfd445ded912cbb0a8ee8a4c1781365c5e3de5eb5b7234424eeb

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:33.308106+00:00.

Case digest / 70f0a4f1a202d4d1a4925fa0ffd06787f6ec31676adcb0e4b6d4332cea3dd1bd