FA-61896 / Currency rounding and FX conversion / Open access
A customer purchase is priced at the dealer's bid · case 01
Customers buying euros are charged the lower bid rate, giving away the spread.
ROOT CAUSE
The side-to-rate mapping is inverted: buy uses bid and sell uses ask.
THE FAILURE
The side-to-rate mapping is inverted: buy uses bid and sell uses ask.
Unsuccessful approach: Using the ask for every side fixes purchases but overpays customers who sell.
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 = b if side == 'buy' else a
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 dealer-side-rate 1', ('buy', '1000', 'EUR', 'EURUSD', '1.0831', '1.0835'), ['1083.50', 'USD']),
('regression dealer-side-rate 2', ('sell', '1000', 'EUR', 'EURUSD', '1.0831', '1.0835'), ['1083.10', 'USD']),
('partial repair guard 2', ('sell', '100', 'USD', 'EURUSD', '1.0831', '1.0835'), ['92.33', 'EUR']),
('control: spend quote', ('buy', '100', 'USD', 'EURUSD', '1.0831', '1.0835'), ['92.29', '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: crossed quote', ('buy', '5', 'EUR', 'EURUSD', '1.2', '1.1'), 'ERR:crossed-quote')],
[('regression dealer-side-rate 1', ('buy', '100', 'USD', 'EURUSD', '1.0831', '1.0835'), ['92.29', 'EUR']),
('regression dealer-side-rate 2', ('sell', '100', 'USD', 'EURUSD', '1.0831', '1.0835'), ['92.33', 'EUR']),
('partial repair guard 1', ('sell', '77.77', 'USD', 'KWDUSD', '3.2520', '3.2561'), ['23.915', 'KWD']),
('partial repair guard 2', ('sell', '30057', 'USD', 'EURUSD', '76.9818', '76.9826'), ['390.45', '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: crossed quote', ('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')],
[('regression dealer-side-rate 1', ('sell', '77.77', 'USD', 'KWDUSD', '3.2520', '3.2561'), ['23.915', 'KWD']),
('regression dealer-side-rate 2', ('sell', '30057', 'USD', 'EURUSD', '76.9818', '76.9826'), ['390.45', 'EUR']),
('partial repair guard 1', ('sell', '57233.77', 'EUR', 'EURUSD', '20.7344', '20.7378'), ['1186707.88', 'USD']),
('partial repair guard 2', ('sell', '20310', 'EUR', 'EURJPY', '13.3392', '13.3438'), ['270919', 'JPY']),
('control: crossed quote', ('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: 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 dealer-side-rate 1', ('sell', '57233.77', 'EUR', 'EURUSD', '20.7344', '20.7378'), ['1186707.88', 'USD']),
('regression dealer-side-rate 2', ('sell', '20310', 'EUR', 'EURJPY', '13.3392', '13.3438'), ['270919', 'JPY']),
('partial repair guard 1', ('sell', '50691', 'JPY', 'USDJPY', '61.7254', '61.7302'), ['821.24', 'USD']),
('partial repair guard 2', ('sell', '27002', 'KWD', 'KWDUSD', '127.8499', '127.8515'), ['3452202.99', 'USD']),
('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 dealer-side-rate 1', ('sell', '50691', 'JPY', 'USDJPY', '61.7254', '61.7302'), ['821.24', 'USD']),
('regression dealer-side-rate 2', ('sell', '27002', 'KWD', 'KWDUSD', '127.8499', '127.8515'), ['3452202.99', 'USD']),
('partial repair guard 1', ('sell', '39619.07', 'USD', 'USDJPY', '122.3532', '122.3540'), ['4847519', 'JPY']),
('partial repair guard 2', ('sell', '69613.58', 'USD', 'EURUSD', '41.9786', '41.9808'), ['1658.32', 'EUR']),
('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 dealer-side-rate 1 | ['1083.10', 'USD'] | ['1083.50', 'USD'] | Failed |
| regression dealer-side-rate 2 | ['1083.50', 'USD'] | ['1083.10', 'USD'] | Failed |
| partial repair guard 2 | ['92.30', 'EUR'] | ['92.33', 'EUR'] | Failed |
| control: spend quote | ['92.32', 'EUR'] | ['92.29', 'EUR'] | Failed |
| control: yen counter | ['1514', 'JPY'] | ['1514', 'JPY'] | Passed |
| control: locked quote | ['316.25', 'USD'] | ['316.25', 'USD'] | Passed |
| control: crossed quote | ERR:crossed-quote | ERR:crossed-quote | Passed |
SHA-256 / ed17c966fb51b0165905b58dced29714e5f1563ab92c54dd5a8077fb6d7c9d79
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)
if b > a: return 'ERR:crossed-quote'
r = a
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 dealer-side-rate 1', ('buy', '1000', 'EUR', 'EURUSD', '1.0831', '1.0835'), ['1083.50', 'USD']),
('regression dealer-side-rate 2', ('sell', '1000', 'EUR', 'EURUSD', '1.0831', '1.0835'), ['1083.10', 'USD']),
('partial repair guard 2', ('sell', '100', 'USD', 'EURUSD', '1.0831', '1.0835'), ['92.33', 'EUR']),
('control: spend quote', ('buy', '100', 'USD', 'EURUSD', '1.0831', '1.0835'), ['92.29', '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: crossed quote', ('buy', '5', 'EUR', 'EURUSD', '1.2', '1.1'), 'ERR:crossed-quote')],
[('regression dealer-side-rate 1', ('buy', '100', 'USD', 'EURUSD', '1.0831', '1.0835'), ['92.29', 'EUR']),
('regression dealer-side-rate 2', ('sell', '100', 'USD', 'EURUSD', '1.0831', '1.0835'), ['92.33', 'EUR']),
('partial repair guard 1', ('sell', '77.77', 'USD', 'KWDUSD', '3.2520', '3.2561'), ['23.915', 'KWD']),
('partial repair guard 2', ('sell', '30057', 'USD', 'EURUSD', '76.9818', '76.9826'), ['390.45', '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: crossed quote', ('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')],
[('regression dealer-side-rate 1', ('sell', '77.77', 'USD', 'KWDUSD', '3.2520', '3.2561'), ['23.915', 'KWD']),
('regression dealer-side-rate 2', ('sell', '30057', 'USD', 'EURUSD', '76.9818', '76.9826'), ['390.45', 'EUR']),
('partial repair guard 1', ('sell', '57233.77', 'EUR', 'EURUSD', '20.7344', '20.7378'), ['1186707.88', 'USD']),
('partial repair guard 2', ('sell', '20310', 'EUR', 'EURJPY', '13.3392', '13.3438'), ['270919', 'JPY']),
('control: crossed quote', ('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: 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 dealer-side-rate 1', ('sell', '57233.77', 'EUR', 'EURUSD', '20.7344', '20.7378'), ['1186707.88', 'USD']),
('regression dealer-side-rate 2', ('sell', '20310', 'EUR', 'EURJPY', '13.3392', '13.3438'), ['270919', 'JPY']),
('partial repair guard 1', ('sell', '50691', 'JPY', 'USDJPY', '61.7254', '61.7302'), ['821.24', 'USD']),
('partial repair guard 2', ('sell', '27002', 'KWD', 'KWDUSD', '127.8499', '127.8515'), ['3452202.99', 'USD']),
('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 dealer-side-rate 1', ('sell', '50691', 'JPY', 'USDJPY', '61.7254', '61.7302'), ['821.24', 'USD']),
('regression dealer-side-rate 2', ('sell', '27002', 'KWD', 'KWDUSD', '127.8499', '127.8515'), ['3452202.99', 'USD']),
('partial repair guard 1', ('sell', '39619.07', 'USD', 'USDJPY', '122.3532', '122.3540'), ['4847519', 'JPY']),
('partial repair guard 2', ('sell', '69613.58', 'USD', 'EURUSD', '41.9786', '41.9808'), ['1658.32', 'EUR']),
('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 dealer-side-rate 1 | ['1083.50', 'USD'] | ['1083.50', 'USD'] | Passed |
| regression dealer-side-rate 2 | ['1083.50', 'USD'] | ['1083.10', 'USD'] | Failed |
| partial repair guard 2 | ['92.30', 'EUR'] | ['92.33', 'EUR'] | Failed |
| control: spend quote | ['92.29', 'EUR'] | ['92.29', 'EUR'] | Passed |
| control: yen counter | ['1514', 'JPY'] | ['1514', 'JPY'] | Passed |
| control: locked quote | ['316.25', 'USD'] | ['316.25', 'USD'] | Passed |
| control: crossed quote | ERR:crossed-quote | ERR:crossed-quote | Passed |
SHA-256 / ff47e6cc69e2b3a23dfa671e273721e57ae180e81077881c6412bb35aedc3802
HELD IN THE MEMBER ARCHIVE
The verified repair and its recorded checks are member-only.
This mechanism has 7 recorded checks per implementation. The open-access tier publishes the failure and the unsuccessful fix; the repaired source that passes every check, and the observations that prove it, are available to members.
Every case sharing this mechanism uses the same contract and the same repair, so this one record is held back for all of them.
Member access is invitation-based. Sign in with your invited account to inspect the repair.
Sign in to the archive ↗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.451475+00:00.
Case digest / 9b85375f6e0d21e535611e36cc0976121dd67d36419249ded2df92cc210071f4