FA-61911 / Currency rounding and FX conversion / Open access
A locked quote with equal bid and ask is rejected as crossed · case 01
Legitimate zero-spread promotional quotes fail with ERR:crossed-quote.
ROOT CAUSE
The crossed-quote guard uses b >= a instead of b > a.
VERIFIED REPAIR
Reject only quotes whose bid strictly exceeds the ask.
Unsuccessful approach: Dropping the guard entirely accepts crossed quotes and trades at an inverted spread.
Case contract
solve(side, amount, ccy, pair, bid, ask): pair is six letters BASEQUOTE; side is the customer's action on the base currency ('buy' or 'sell'). The dealer sells base at ask and buys at bid. If amount is in base, the counter amount in quote is amount*rate; if in quote, the counter amount in base is amount/rate. Amounts the customer pays are rounded up (ceiling) and amounts the customer receives are rounded down (floor) at the counter currency exponent (JPY 0, KWD 3, else 2). Return [counter_amount, counter_ccy]; errors: 'ERR:side', 'ERR:crossed-quote' when bid > ask (bid == ask is valid), 'ERR:currency-not-in-pair'.
Why this case matters
Currency amounts must be rounded at the right stage and in the right unit, or ledgers, quotes and settlements drift by minor units.
1 / The failure
Exit 1"""Failure Map reference implementation. Python standard library only."""
import json
from decimal import Decimal, ROUND_HALF_EVEN, ROUND_HALF_UP, ROUND_FLOOR, ROUND_CEILING, ROUND_DOWN, ROUND_UP, ROUND_HALF_DOWN
N = 1
observations = []
def solve(side, amount, ccy, pair, bid, ask):
exps = {'JPY': 0, 'KWD': 3}
base, quote = pair[:3], pair[3:]
if side not in ('buy', 'sell'): return 'ERR:side'
b, a = Decimal(bid), Decimal(ask)
if b >= a: return 'ERR:crossed-quote'
r = a if side == 'buy' else b
x = Decimal(amount)
if ccy == base:
out, oc = x * r, quote
pays = side == 'buy'
elif ccy == quote:
out, oc = x / r, base
pays = side == 'sell'
else:
return 'ERR:currency-not-in-pair'
mode = ROUND_CEILING if pays else ROUND_FLOOR
return [format(out.quantize(Decimal(1).scaleb(-exps.get(oc, 2)), rounding=mode), 'f'), oc]
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression locked-quote 1', ('sell', '250', 'GBP', 'GBPUSD', '1.2650', '1.2650'), ['316.25', 'USD']),
('regression locked-quote 2', ('buy', '61902', 'USD', 'EURUSD', '90.2139', '90.2139'), ['686.16', 'EUR']),
('partial repair guard 1', ('buy', '5', 'EUR', 'EURUSD', '1.2', '1.1'), 'ERR:crossed-quote'),
('control: buy base in base', ('buy', '1000', 'EUR', 'EURUSD', '1.0831', '1.0835'), ['1083.50', 'USD']),
('control: sell base in base', ('sell', '1000', 'EUR', 'EURUSD', '1.0831', '1.0835'), ['1083.10', 'USD']),
('control: spend quote', ('buy', '100', 'USD', 'EURUSD', '1.0831', '1.0835'), ['92.29', 'EUR']),
('control: receive quote', ('sell', '100', 'USD', 'EURUSD', '1.0831', '1.0835'), ['92.33', 'EUR'])],
[('regression locked-quote 1', ('buy', '9242.03', 'USD', 'USDKWD', '102.3192', '102.3192'), ['945637.116', 'KWD']),
('regression locked-quote 2', ('sell', '43841.09', 'USD', 'GBPUSD', '40.6095', '40.6095'), ['1079.58', 'GBP']),
('partial repair guard 1', ('buy', '5', 'EUR', 'EURUSD', '1.2', '1.1'), 'ERR:crossed-quote'),
('control: receive quote', ('sell', '100', 'USD', 'EURUSD', '1.0831', '1.0835'), ['92.33', 'EUR']),
('control: yen counter', ('buy', '10.01', 'USD', 'USDJPY', '151.20', '151.24'), ['1514', 'JPY']),
('control: locked quote', ('sell', '250', 'GBP', 'GBPUSD', '1.2650', '1.2650'), ['316.25', 'USD']),
('control: foreign currency', ('buy', '5', 'CHF', 'EURUSD', '1.08', '1.09'), 'ERR:currency-not-in-pair')],
[('regression locked-quote 1', ('sell', '71412', 'KWD', 'KWDUSD', '24.3260', '24.3260'), ['1737168.31', 'USD']),
('regression locked-quote 2', ('sell', '40482', 'KWD', 'USDKWD', '85.5377', '85.5377'), ['473.27', 'USD']),
('partial repair guard 1', ('buy', '5', 'EUR', 'EURUSD', '1.2', '1.1'), 'ERR:crossed-quote'),
('control: foreign currency', ('buy', '5', 'CHF', 'EURUSD', '1.08', '1.09'), 'ERR:currency-not-in-pair'),
('control: dinar counter', ('sell', '77.77', 'USD', 'KWDUSD', '3.2520', '3.2561'), ['23.915', 'KWD']),
('control: bad side', ('hold', '5', 'EUR', 'EURUSD', '1.08', '1.09'), 'ERR:side'),
('control: buy base in base', ('buy', '1000', 'EUR', 'EURUSD', '1.0831', '1.0835'), ['1083.50', 'USD'])],
[('regression locked-quote 1', ('sell', '36252', 'USD', 'KWDUSD', '151.2728', '151.2728'), ['239.647', 'KWD']),
('regression locked-quote 2', ('buy', '55623', 'JPY', 'EURJPY', '87.3553', '87.3553'), ['636.74', 'EUR']),
('partial repair guard 1', ('buy', '5', 'EUR', 'EURUSD', '1.2', '1.1'), 'ERR:crossed-quote'),
('control: bad side', ('hold', '5', 'EUR', 'EURUSD', '1.08', '1.09'), 'ERR:side'),
('control: buy base in base', ('buy', '1000', 'EUR', 'EURUSD', '1.0831', '1.0835'), ['1083.50', 'USD']),
('control: sell base in base', ('sell', '1000', 'EUR', 'EURUSD', '1.0831', '1.0835'), ['1083.10', 'USD']),
('control: spend quote', ('buy', '100', 'USD', 'EURUSD', '1.0831', '1.0835'), ['92.29', 'EUR'])],
[('regression locked-quote 1', ('sell', '94639.83', 'USD', 'KWDUSD', '80.9904', '80.9904'), ['1168.532', 'KWD']),
('regression locked-quote 2', ('sell', '22683.50', 'USD', 'GBPUSD', '155.5065', '155.5065'), ['145.87', 'GBP']),
('partial repair guard 1', ('buy', '5', 'EUR', 'EURUSD', '1.2', '1.1'), 'ERR:crossed-quote'),
('control: spend quote', ('buy', '100', 'USD', 'EURUSD', '1.0831', '1.0835'), ['92.29', 'EUR']),
('control: receive quote', ('sell', '100', 'USD', 'EURUSD', '1.0831', '1.0835'), ['92.33', 'EUR']),
('control: yen counter', ('buy', '10.01', 'USD', 'USDJPY', '151.20', '151.24'), ['1514', 'JPY']),
('control: locked quote', ('sell', '250', 'GBP', 'GBPUSD', '1.2650', '1.2650'), ['316.25', 'USD'])]]
for label, args, expected in cases[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 locked-quote 1 | ERR:crossed-quote | ['316.25', 'USD'] | Failed |
| regression locked-quote 2 | ERR:crossed-quote | ['686.16', 'EUR'] | Failed |
| partial repair guard 1 | ERR:crossed-quote | ERR:crossed-quote | Passed |
| control: buy base in base | ['1083.50', 'USD'] | ['1083.50', 'USD'] | Passed |
| control: sell base in base | ['1083.10', 'USD'] | ['1083.10', 'USD'] | Passed |
| control: spend quote | ['92.29', 'EUR'] | ['92.29', 'EUR'] | Passed |
| control: receive quote | ['92.33', 'EUR'] | ['92.33', 'EUR'] | Passed |
SHA-256 / 9d43b5ef6fbc69ae65fab45fbd2b6b8624697441a7d79edd4b6b52f969e20d11
2 / The unsuccessful fix
Exit 1"""Failure Map reference implementation. Python standard library only."""
import json
from decimal import Decimal, ROUND_HALF_EVEN, ROUND_HALF_UP, ROUND_FLOOR, ROUND_CEILING, ROUND_DOWN, ROUND_UP, ROUND_HALF_DOWN
N = 1
observations = []
def solve(side, amount, ccy, pair, bid, ask):
exps = {'JPY': 0, 'KWD': 3}
base, quote = pair[:3], pair[3:]
if side not in ('buy', 'sell'): return 'ERR:side'
b, a = Decimal(bid), Decimal(ask)
pass
r = a if side == 'buy' else b
x = Decimal(amount)
if ccy == base:
out, oc = x * r, quote
pays = side == 'buy'
elif ccy == quote:
out, oc = x / r, base
pays = side == 'sell'
else:
return 'ERR:currency-not-in-pair'
mode = ROUND_CEILING if pays else ROUND_FLOOR
return [format(out.quantize(Decimal(1).scaleb(-exps.get(oc, 2)), rounding=mode), 'f'), oc]
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression locked-quote 1', ('sell', '250', 'GBP', 'GBPUSD', '1.2650', '1.2650'), ['316.25', 'USD']),
('regression locked-quote 2', ('buy', '61902', 'USD', 'EURUSD', '90.2139', '90.2139'), ['686.16', 'EUR']),
('partial repair guard 1', ('buy', '5', 'EUR', 'EURUSD', '1.2', '1.1'), 'ERR:crossed-quote'),
('control: buy base in base', ('buy', '1000', 'EUR', 'EURUSD', '1.0831', '1.0835'), ['1083.50', 'USD']),
('control: sell base in base', ('sell', '1000', 'EUR', 'EURUSD', '1.0831', '1.0835'), ['1083.10', 'USD']),
('control: spend quote', ('buy', '100', 'USD', 'EURUSD', '1.0831', '1.0835'), ['92.29', 'EUR']),
('control: receive quote', ('sell', '100', 'USD', 'EURUSD', '1.0831', '1.0835'), ['92.33', 'EUR'])],
[('regression locked-quote 1', ('buy', '9242.03', 'USD', 'USDKWD', '102.3192', '102.3192'), ['945637.116', 'KWD']),
('regression locked-quote 2', ('sell', '43841.09', 'USD', 'GBPUSD', '40.6095', '40.6095'), ['1079.58', 'GBP']),
('partial repair guard 1', ('buy', '5', 'EUR', 'EURUSD', '1.2', '1.1'), 'ERR:crossed-quote'),
('control: receive quote', ('sell', '100', 'USD', 'EURUSD', '1.0831', '1.0835'), ['92.33', 'EUR']),
('control: yen counter', ('buy', '10.01', 'USD', 'USDJPY', '151.20', '151.24'), ['1514', 'JPY']),
('control: locked quote', ('sell', '250', 'GBP', 'GBPUSD', '1.2650', '1.2650'), ['316.25', 'USD']),
('control: foreign currency', ('buy', '5', 'CHF', 'EURUSD', '1.08', '1.09'), 'ERR:currency-not-in-pair')],
[('regression locked-quote 1', ('sell', '71412', 'KWD', 'KWDUSD', '24.3260', '24.3260'), ['1737168.31', 'USD']),
('regression locked-quote 2', ('sell', '40482', 'KWD', 'USDKWD', '85.5377', '85.5377'), ['473.27', 'USD']),
('partial repair guard 1', ('buy', '5', 'EUR', 'EURUSD', '1.2', '1.1'), 'ERR:crossed-quote'),
('control: foreign currency', ('buy', '5', 'CHF', 'EURUSD', '1.08', '1.09'), 'ERR:currency-not-in-pair'),
('control: dinar counter', ('sell', '77.77', 'USD', 'KWDUSD', '3.2520', '3.2561'), ['23.915', 'KWD']),
('control: bad side', ('hold', '5', 'EUR', 'EURUSD', '1.08', '1.09'), 'ERR:side'),
('control: buy base in base', ('buy', '1000', 'EUR', 'EURUSD', '1.0831', '1.0835'), ['1083.50', 'USD'])],
[('regression locked-quote 1', ('sell', '36252', 'USD', 'KWDUSD', '151.2728', '151.2728'), ['239.647', 'KWD']),
('regression locked-quote 2', ('buy', '55623', 'JPY', 'EURJPY', '87.3553', '87.3553'), ['636.74', 'EUR']),
('partial repair guard 1', ('buy', '5', 'EUR', 'EURUSD', '1.2', '1.1'), 'ERR:crossed-quote'),
('control: bad side', ('hold', '5', 'EUR', 'EURUSD', '1.08', '1.09'), 'ERR:side'),
('control: buy base in base', ('buy', '1000', 'EUR', 'EURUSD', '1.0831', '1.0835'), ['1083.50', 'USD']),
('control: sell base in base', ('sell', '1000', 'EUR', 'EURUSD', '1.0831', '1.0835'), ['1083.10', 'USD']),
('control: spend quote', ('buy', '100', 'USD', 'EURUSD', '1.0831', '1.0835'), ['92.29', 'EUR'])],
[('regression locked-quote 1', ('sell', '94639.83', 'USD', 'KWDUSD', '80.9904', '80.9904'), ['1168.532', 'KWD']),
('regression locked-quote 2', ('sell', '22683.50', 'USD', 'GBPUSD', '155.5065', '155.5065'), ['145.87', 'GBP']),
('partial repair guard 1', ('buy', '5', 'EUR', 'EURUSD', '1.2', '1.1'), 'ERR:crossed-quote'),
('control: spend quote', ('buy', '100', 'USD', 'EURUSD', '1.0831', '1.0835'), ['92.29', 'EUR']),
('control: receive quote', ('sell', '100', 'USD', 'EURUSD', '1.0831', '1.0835'), ['92.33', 'EUR']),
('control: yen counter', ('buy', '10.01', 'USD', 'USDJPY', '151.20', '151.24'), ['1514', 'JPY']),
('control: locked quote', ('sell', '250', 'GBP', 'GBPUSD', '1.2650', '1.2650'), ['316.25', 'USD'])]]
for label, args, expected in cases[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 locked-quote 1 | ['316.25', 'USD'] | ['316.25', 'USD'] | Passed |
| regression locked-quote 2 | ['686.16', 'EUR'] | ['686.16', 'EUR'] | Passed |
| partial repair guard 1 | ['5.50', 'USD'] | ERR:crossed-quote | Failed |
| control: buy base in base | ['1083.50', 'USD'] | ['1083.50', 'USD'] | Passed |
| control: sell base in base | ['1083.10', 'USD'] | ['1083.10', 'USD'] | Passed |
| control: spend quote | ['92.29', 'EUR'] | ['92.29', 'EUR'] | Passed |
| control: receive quote | ['92.33', 'EUR'] | ['92.33', 'EUR'] | Passed |
SHA-256 / fb1b325fddcc3a59094876931069ad364b59cdc15de959492b3a02ff91ecaf72
3 / The verified repair
Exit 0"""Failure Map reference implementation. Python standard library only."""
import json
from decimal import Decimal, ROUND_HALF_EVEN, ROUND_HALF_UP, ROUND_FLOOR, ROUND_CEILING, ROUND_DOWN, ROUND_UP, ROUND_HALF_DOWN
N = 1
observations = []
def solve(side, amount, ccy, pair, bid, ask):
exps = {'JPY': 0, 'KWD': 3}
base, quote = pair[:3], pair[3:]
if side not in ('buy', 'sell'): return 'ERR:side'
b, a = Decimal(bid), Decimal(ask)
if b > a: return 'ERR:crossed-quote'
r = a if side == 'buy' else b
x = Decimal(amount)
if ccy == base:
out, oc = x * r, quote
pays = side == 'buy'
elif ccy == quote:
out, oc = x / r, base
pays = side == 'sell'
else:
return 'ERR:currency-not-in-pair'
mode = ROUND_CEILING if pays else ROUND_FLOOR
return [format(out.quantize(Decimal(1).scaleb(-exps.get(oc, 2)), rounding=mode), 'f'), oc]
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression locked-quote 1', ('sell', '250', 'GBP', 'GBPUSD', '1.2650', '1.2650'), ['316.25', 'USD']),
('regression locked-quote 2', ('buy', '61902', 'USD', 'EURUSD', '90.2139', '90.2139'), ['686.16', 'EUR']),
('partial repair guard 1', ('buy', '5', 'EUR', 'EURUSD', '1.2', '1.1'), 'ERR:crossed-quote'),
('control: buy base in base', ('buy', '1000', 'EUR', 'EURUSD', '1.0831', '1.0835'), ['1083.50', 'USD']),
('control: sell base in base', ('sell', '1000', 'EUR', 'EURUSD', '1.0831', '1.0835'), ['1083.10', 'USD']),
('control: spend quote', ('buy', '100', 'USD', 'EURUSD', '1.0831', '1.0835'), ['92.29', 'EUR']),
('control: receive quote', ('sell', '100', 'USD', 'EURUSD', '1.0831', '1.0835'), ['92.33', 'EUR'])],
[('regression locked-quote 1', ('buy', '9242.03', 'USD', 'USDKWD', '102.3192', '102.3192'), ['945637.116', 'KWD']),
('regression locked-quote 2', ('sell', '43841.09', 'USD', 'GBPUSD', '40.6095', '40.6095'), ['1079.58', 'GBP']),
('partial repair guard 1', ('buy', '5', 'EUR', 'EURUSD', '1.2', '1.1'), 'ERR:crossed-quote'),
('control: receive quote', ('sell', '100', 'USD', 'EURUSD', '1.0831', '1.0835'), ['92.33', 'EUR']),
('control: yen counter', ('buy', '10.01', 'USD', 'USDJPY', '151.20', '151.24'), ['1514', 'JPY']),
('control: locked quote', ('sell', '250', 'GBP', 'GBPUSD', '1.2650', '1.2650'), ['316.25', 'USD']),
('control: foreign currency', ('buy', '5', 'CHF', 'EURUSD', '1.08', '1.09'), 'ERR:currency-not-in-pair')],
[('regression locked-quote 1', ('sell', '71412', 'KWD', 'KWDUSD', '24.3260', '24.3260'), ['1737168.31', 'USD']),
('regression locked-quote 2', ('sell', '40482', 'KWD', 'USDKWD', '85.5377', '85.5377'), ['473.27', 'USD']),
('partial repair guard 1', ('buy', '5', 'EUR', 'EURUSD', '1.2', '1.1'), 'ERR:crossed-quote'),
('control: foreign currency', ('buy', '5', 'CHF', 'EURUSD', '1.08', '1.09'), 'ERR:currency-not-in-pair'),
('control: dinar counter', ('sell', '77.77', 'USD', 'KWDUSD', '3.2520', '3.2561'), ['23.915', 'KWD']),
('control: bad side', ('hold', '5', 'EUR', 'EURUSD', '1.08', '1.09'), 'ERR:side'),
('control: buy base in base', ('buy', '1000', 'EUR', 'EURUSD', '1.0831', '1.0835'), ['1083.50', 'USD'])],
[('regression locked-quote 1', ('sell', '36252', 'USD', 'KWDUSD', '151.2728', '151.2728'), ['239.647', 'KWD']),
('regression locked-quote 2', ('buy', '55623', 'JPY', 'EURJPY', '87.3553', '87.3553'), ['636.74', 'EUR']),
('partial repair guard 1', ('buy', '5', 'EUR', 'EURUSD', '1.2', '1.1'), 'ERR:crossed-quote'),
('control: bad side', ('hold', '5', 'EUR', 'EURUSD', '1.08', '1.09'), 'ERR:side'),
('control: buy base in base', ('buy', '1000', 'EUR', 'EURUSD', '1.0831', '1.0835'), ['1083.50', 'USD']),
('control: sell base in base', ('sell', '1000', 'EUR', 'EURUSD', '1.0831', '1.0835'), ['1083.10', 'USD']),
('control: spend quote', ('buy', '100', 'USD', 'EURUSD', '1.0831', '1.0835'), ['92.29', 'EUR'])],
[('regression locked-quote 1', ('sell', '94639.83', 'USD', 'KWDUSD', '80.9904', '80.9904'), ['1168.532', 'KWD']),
('regression locked-quote 2', ('sell', '22683.50', 'USD', 'GBPUSD', '155.5065', '155.5065'), ['145.87', 'GBP']),
('partial repair guard 1', ('buy', '5', 'EUR', 'EURUSD', '1.2', '1.1'), 'ERR:crossed-quote'),
('control: spend quote', ('buy', '100', 'USD', 'EURUSD', '1.0831', '1.0835'), ['92.29', 'EUR']),
('control: receive quote', ('sell', '100', 'USD', 'EURUSD', '1.0831', '1.0835'), ['92.33', 'EUR']),
('control: yen counter', ('buy', '10.01', 'USD', 'USDJPY', '151.20', '151.24'), ['1514', 'JPY']),
('control: locked quote', ('sell', '250', 'GBP', 'GBPUSD', '1.2650', '1.2650'), ['316.25', 'USD'])]]
for label, args, expected in cases[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 locked-quote 1 | ['316.25', 'USD'] | ['316.25', 'USD'] | Passed |
| regression locked-quote 2 | ['686.16', 'EUR'] | ['686.16', 'EUR'] | Passed |
| partial repair guard 1 | ERR:crossed-quote | ERR:crossed-quote | Passed |
| control: buy base in base | ['1083.50', 'USD'] | ['1083.50', 'USD'] | Passed |
| control: sell base in base | ['1083.10', 'USD'] | ['1083.10', 'USD'] | Passed |
| control: spend quote | ['92.29', 'EUR'] | ['92.29', 'EUR'] | Passed |
| control: receive quote | ['92.33', 'EUR'] | ['92.33', 'EUR'] | Passed |
SHA-256 / cbe0e263746ac4e91e0f18768dbeecd4df03d746a479345def9c026f67d5b9b2
Verification & scope
A deterministic, bounded teaching model with a stipulated toy contract; it makes no claim of conformance to any real regulation, standard, or institution's rules. 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:59.687902+00:00.
Case digest / b2f47e9685da17290fa345b909e4b8524348114d3b58632e99c8ec8416af7374