{"abstract":"Customers buying euros are charged the lower bid rate, giving away the spread.","category":"Currency rounding and FX conversion","checks":7,"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'.","contract_signature":"side, amount, ccy, pair, bid, ask","evaluation_group":"w2-currency_rounding_and_fx_conversion-bid-ask-customer-conversion","failed_approach":"Using the ask for every side fixes purchases but overpays customers who sell.","family":"w2-currency_rounding_and_fx_conversion-bid-ask-customer-conversion-dealer-side-rate","id":"FA-61896","implementations":{"attempt":{"sha256":"ff47e6cc69e2b3a23dfa671e273721e57ae180e81077881c6412bb35aedc3802","source":"\"\"\"Failure Map reference implementation. Python standard library only.\"\"\"\nimport json\nfrom decimal import Decimal, ROUND_HALF_EVEN, ROUND_HALF_UP, ROUND_FLOOR, ROUND_CEILING, ROUND_DOWN, ROUND_UP, ROUND_HALF_DOWN\nN = 1\nobservations = []\ndef solve(side, amount, ccy, pair, bid, ask):\n    exps = {'JPY': 0, 'KWD': 3}\n    base, quote = pair[:3], pair[3:]\n    if side not in ('buy', 'sell'): return 'ERR:side'\n    b, a = Decimal(bid), Decimal(ask)\n    if b > a: return 'ERR:crossed-quote'\n    r = a\n    x = Decimal(amount)\n    if ccy == base:\n        out, oc = x * r, quote\n        pays = side == 'buy'\n    elif ccy == quote:\n        out, oc = x / r, base\n        pays = side == 'sell'\n    else:\n        return 'ERR:currency-not-in-pair'\n    mode = ROUND_CEILING if pays else ROUND_FLOOR\n    return [format(out.quantize(Decimal(1).scaleb(-exps.get(oc, 2)), rounding=mode), 'f'), oc]\ndef check(label, actual, expected):\n    observations.append({\"check\": label, \"actual\": actual, \"expected\": expected, \"passed\": actual == expected})\ncases = [[('regression dealer-side-rate 1', ('buy', '1000', 'EUR', 'EURUSD', '1.0831', '1.0835'), ['1083.50', 'USD']),\n  ('regression dealer-side-rate 2', ('sell', '1000', 'EUR', 'EURUSD', '1.0831', '1.0835'), ['1083.10', 'USD']),\n  ('partial repair guard 2', ('sell', '100', 'USD', 'EURUSD', '1.0831', '1.0835'), ['92.33', 'EUR']),\n  ('control: spend quote', ('buy', '100', 'USD', 'EURUSD', '1.0831', '1.0835'), ['92.29', 'EUR']),\n  ('control: yen counter', ('buy', '10.01', 'USD', 'USDJPY', '151.20', '151.24'), ['1514', 'JPY']),\n  ('control: locked quote', ('sell', '250', 'GBP', 'GBPUSD', '1.2650', '1.2650'), ['316.25', 'USD']),\n  ('control: crossed quote', ('buy', '5', 'EUR', 'EURUSD', '1.2', '1.1'), 'ERR:crossed-quote')],\n [('regression dealer-side-rate 1', ('buy', '100', 'USD', 'EURUSD', '1.0831', '1.0835'), ['92.29', 'EUR']),\n  ('regression dealer-side-rate 2', ('sell', '100', 'USD', 'EURUSD', '1.0831', '1.0835'), ['92.33', 'EUR']),\n  ('partial repair guard 1', ('sell', '77.77', 'USD', 'KWDUSD', '3.2520', '3.2561'), ['23.915', 'KWD']),\n  ('partial repair guard 2', ('sell', '30057', 'USD', 'EURUSD', '76.9818', '76.9826'), ['390.45', 'EUR']),\n  ('control: yen counter', ('buy', '10.01', 'USD', 'USDJPY', '151.20', '151.24'), ['1514', 'JPY']),\n  ('control: locked quote', ('sell', '250', 'GBP', 'GBPUSD', '1.2650', '1.2650'), ['316.25', 'USD']),\n  ('control: crossed quote', ('buy', '5', 'EUR', 'EURUSD', '1.2', '1.1'), 'ERR:crossed-quote'),\n  ('control: foreign currency', ('buy', '5', 'CHF', 'EURUSD', '1.08', '1.09'), 'ERR:currency-not-in-pair')],\n [('regression dealer-side-rate 1', ('sell', '77.77', 'USD', 'KWDUSD', '3.2520', '3.2561'), ['23.915', 'KWD']),\n  ('regression dealer-side-rate 2', ('sell', '30057', 'USD', 'EURUSD', '76.9818', '76.9826'), ['390.45', 'EUR']),\n  ('partial repair guard 1', ('sell', '57233.77', 'EUR', 'EURUSD', '20.7344', '20.7378'), ['1186707.88', 'USD']),\n  ('partial repair guard 2', ('sell', '20310', 'EUR', 'EURJPY', '13.3392', '13.3438'), ['270919', 'JPY']),\n  ('control: crossed quote', ('buy', '5', 'EUR', 'EURUSD', '1.2', '1.1'), 'ERR:crossed-quote'),\n  ('control: foreign currency', ('buy', '5', 'CHF', 'EURUSD', '1.08', '1.09'), 'ERR:currency-not-in-pair'),\n  ('control: bad side', ('hold', '5', 'EUR', 'EURUSD', '1.08', '1.09'), 'ERR:side'),\n  ('control: buy base in base', ('buy', '1000', 'EUR', 'EURUSD', '1.0831', '1.0835'), ['1083.50', 'USD'])],\n [('regression dealer-side-rate 1', ('sell', '57233.77', 'EUR', 'EURUSD', '20.7344', '20.7378'), ['1186707.88', 'USD']),\n  ('regression dealer-side-rate 2', ('sell', '20310', 'EUR', 'EURJPY', '13.3392', '13.3438'), ['270919', 'JPY']),\n  ('partial repair guard 1', ('sell', '50691', 'JPY', 'USDJPY', '61.7254', '61.7302'), ['821.24', 'USD']),\n  ('partial repair guard 2', ('sell', '27002', 'KWD', 'KWDUSD', '127.8499', '127.8515'), ['3452202.99', 'USD']),\n  ('control: bad side', ('hold', '5', 'EUR', 'EURUSD', '1.08', '1.09'), 'ERR:side'),\n  ('control: buy base in base', ('buy', '1000', 'EUR', 'EURUSD', '1.0831', '1.0835'), ['1083.50', 'USD']),\n  ('control: sell base in base', ('sell', '1000', 'EUR', 'EURUSD', '1.0831', '1.0835'), ['1083.10', 'USD']),\n  ('control: spend quote', ('buy', '100', 'USD', 'EURUSD', '1.0831', '1.0835'), ['92.29', 'EUR'])],\n [('regression dealer-side-rate 1', ('sell', '50691', 'JPY', 'USDJPY', '61.7254', '61.7302'), ['821.24', 'USD']),\n  ('regression dealer-side-rate 2', ('sell', '27002', 'KWD', 'KWDUSD', '127.8499', '127.8515'), ['3452202.99', 'USD']),\n  ('partial repair guard 1', ('sell', '39619.07', 'USD', 'USDJPY', '122.3532', '122.3540'), ['4847519', 'JPY']),\n  ('partial repair guard 2', ('sell', '69613.58', 'USD', 'EURUSD', '41.9786', '41.9808'), ['1658.32', 'EUR']),\n  ('control: spend quote', ('buy', '100', 'USD', 'EURUSD', '1.0831', '1.0835'), ['92.29', 'EUR']),\n  ('control: receive quote', ('sell', '100', 'USD', 'EURUSD', '1.0831', '1.0835'), ['92.33', 'EUR']),\n  ('control: yen counter', ('buy', '10.01', 'USD', 'USDJPY', '151.20', '151.24'), ['1514', 'JPY']),\n  ('control: locked quote', ('sell', '250', 'GBP', 'GBPUSD', '1.2650', '1.2650'), ['316.25', 'USD'])]]\nfor label, args, expected in cases[N - 1]:\n    check(label, solve(*args), expected)\nprint(json.dumps({\"observations\": observations, \"passed\": all(x[\"passed\"] for x in observations)}, ensure_ascii=False))\nraise SystemExit(0 if all(x[\"passed\"] for x in observations) else 1)\n"},"broken":{"sha256":"ed17c966fb51b0165905b58dced29714e5f1563ab92c54dd5a8077fb6d7c9d79","source":"\"\"\"Failure Map reference implementation. Python standard library only.\"\"\"\nimport json\nfrom decimal import Decimal, ROUND_HALF_EVEN, ROUND_HALF_UP, ROUND_FLOOR, ROUND_CEILING, ROUND_DOWN, ROUND_UP, ROUND_HALF_DOWN\nN = 1\nobservations = []\ndef solve(side, amount, ccy, pair, bid, ask):\n    exps = {'JPY': 0, 'KWD': 3}\n    base, quote = pair[:3], pair[3:]\n    if side not in ('buy', 'sell'): return 'ERR:side'\n    b, a = Decimal(bid), Decimal(ask)\n    if b > a: return 'ERR:crossed-quote'\n    r = b if side == 'buy' else a\n    x = Decimal(amount)\n    if ccy == base:\n        out, oc = x * r, quote\n        pays = side == 'buy'\n    elif ccy == quote:\n        out, oc = x / r, base\n        pays = side == 'sell'\n    else:\n        return 'ERR:currency-not-in-pair'\n    mode = ROUND_CEILING if pays else ROUND_FLOOR\n    return [format(out.quantize(Decimal(1).scaleb(-exps.get(oc, 2)), rounding=mode), 'f'), oc]\ndef check(label, actual, expected):\n    observations.append({\"check\": label, \"actual\": actual, \"expected\": expected, \"passed\": actual == expected})\ncases = [[('regression dealer-side-rate 1', ('buy', '1000', 'EUR', 'EURUSD', '1.0831', '1.0835'), ['1083.50', 'USD']),\n  ('regression dealer-side-rate 2', ('sell', '1000', 'EUR', 'EURUSD', '1.0831', '1.0835'), ['1083.10', 'USD']),\n  ('partial repair guard 2', ('sell', '100', 'USD', 'EURUSD', '1.0831', '1.0835'), ['92.33', 'EUR']),\n  ('control: spend quote', ('buy', '100', 'USD', 'EURUSD', '1.0831', '1.0835'), ['92.29', 'EUR']),\n  ('control: yen counter', ('buy', '10.01', 'USD', 'USDJPY', '151.20', '151.24'), ['1514', 'JPY']),\n  ('control: locked quote', ('sell', '250', 'GBP', 'GBPUSD', '1.2650', '1.2650'), ['316.25', 'USD']),\n  ('control: crossed quote', ('buy', '5', 'EUR', 'EURUSD', '1.2', '1.1'), 'ERR:crossed-quote')],\n [('regression dealer-side-rate 1', ('buy', '100', 'USD', 'EURUSD', '1.0831', '1.0835'), ['92.29', 'EUR']),\n  ('regression dealer-side-rate 2', ('sell', '100', 'USD', 'EURUSD', '1.0831', '1.0835'), ['92.33', 'EUR']),\n  ('partial repair guard 1', ('sell', '77.77', 'USD', 'KWDUSD', '3.2520', '3.2561'), ['23.915', 'KWD']),\n  ('partial repair guard 2', ('sell', '30057', 'USD', 'EURUSD', '76.9818', '76.9826'), ['390.45', 'EUR']),\n  ('control: yen counter', ('buy', '10.01', 'USD', 'USDJPY', '151.20', '151.24'), ['1514', 'JPY']),\n  ('control: locked quote', ('sell', '250', 'GBP', 'GBPUSD', '1.2650', '1.2650'), ['316.25', 'USD']),\n  ('control: crossed quote', ('buy', '5', 'EUR', 'EURUSD', '1.2', '1.1'), 'ERR:crossed-quote'),\n  ('control: foreign currency', ('buy', '5', 'CHF', 'EURUSD', '1.08', '1.09'), 'ERR:currency-not-in-pair')],\n [('regression dealer-side-rate 1', ('sell', '77.77', 'USD', 'KWDUSD', '3.2520', '3.2561'), ['23.915', 'KWD']),\n  ('regression dealer-side-rate 2', ('sell', '30057', 'USD', 'EURUSD', '76.9818', '76.9826'), ['390.45', 'EUR']),\n  ('partial repair guard 1', ('sell', '57233.77', 'EUR', 'EURUSD', '20.7344', '20.7378'), ['1186707.88', 'USD']),\n  ('partial repair guard 2', ('sell', '20310', 'EUR', 'EURJPY', '13.3392', '13.3438'), ['270919', 'JPY']),\n  ('control: crossed quote', ('buy', '5', 'EUR', 'EURUSD', '1.2', '1.1'), 'ERR:crossed-quote'),\n  ('control: foreign currency', ('buy', '5', 'CHF', 'EURUSD', '1.08', '1.09'), 'ERR:currency-not-in-pair'),\n  ('control: bad side', ('hold', '5', 'EUR', 'EURUSD', '1.08', '1.09'), 'ERR:side'),\n  ('control: buy base in base', ('buy', '1000', 'EUR', 'EURUSD', '1.0831', '1.0835'), ['1083.50', 'USD'])],\n [('regression dealer-side-rate 1', ('sell', '57233.77', 'EUR', 'EURUSD', '20.7344', '20.7378'), ['1186707.88', 'USD']),\n  ('regression dealer-side-rate 2', ('sell', '20310', 'EUR', 'EURJPY', '13.3392', '13.3438'), ['270919', 'JPY']),\n  ('partial repair guard 1', ('sell', '50691', 'JPY', 'USDJPY', '61.7254', '61.7302'), ['821.24', 'USD']),\n  ('partial repair guard 2', ('sell', '27002', 'KWD', 'KWDUSD', '127.8499', '127.8515'), ['3452202.99', 'USD']),\n  ('control: bad side', ('hold', '5', 'EUR', 'EURUSD', '1.08', '1.09'), 'ERR:side'),\n  ('control: buy base in base', ('buy', '1000', 'EUR', 'EURUSD', '1.0831', '1.0835'), ['1083.50', 'USD']),\n  ('control: sell base in base', ('sell', '1000', 'EUR', 'EURUSD', '1.0831', '1.0835'), ['1083.10', 'USD']),\n  ('control: spend quote', ('buy', '100', 'USD', 'EURUSD', '1.0831', '1.0835'), ['92.29', 'EUR'])],\n [('regression dealer-side-rate 1', ('sell', '50691', 'JPY', 'USDJPY', '61.7254', '61.7302'), ['821.24', 'USD']),\n  ('regression dealer-side-rate 2', ('sell', '27002', 'KWD', 'KWDUSD', '127.8499', '127.8515'), ['3452202.99', 'USD']),\n  ('partial repair guard 1', ('sell', '39619.07', 'USD', 'USDJPY', '122.3532', '122.3540'), ['4847519', 'JPY']),\n  ('partial repair guard 2', ('sell', '69613.58', 'USD', 'EURUSD', '41.9786', '41.9808'), ['1658.32', 'EUR']),\n  ('control: spend quote', ('buy', '100', 'USD', 'EURUSD', '1.0831', '1.0835'), ['92.29', 'EUR']),\n  ('control: receive quote', ('sell', '100', 'USD', 'EURUSD', '1.0831', '1.0835'), ['92.33', 'EUR']),\n  ('control: yen counter', ('buy', '10.01', 'USD', 'USDJPY', '151.20', '151.24'), ['1514', 'JPY']),\n  ('control: locked quote', ('sell', '250', 'GBP', 'GBPUSD', '1.2650', '1.2650'), ['316.25', 'USD'])]]\nfor label, args, expected in cases[N - 1]:\n    check(label, solve(*args), expected)\nprint(json.dumps({\"observations\": observations, \"passed\": all(x[\"passed\"] for x in observations)}, ensure_ascii=False))\nraise SystemExit(0 if all(x[\"passed\"] for x in observations) else 1)\n"}},"limitations":"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.","method":"Deterministic executable model with adversarial boundary fixtures.","provenance":{"created_by":"Failure Map","dependencies":"Python standard library","family":"w2-currency_rounding_and_fx_conversion-bid-ask-customer-conversion-dealer-side-rate","generated_at":"2026-09-29T14:46:59.451475+00:00","license":"CC0-1.0","python":"3.12.14","seed":1,"split":"open-access"},"relevance":"Currency amounts must be rounded at the right stage and in the right unit, or ledgers, quotes and settlements drift by minor units.","root_cause":"The side-to-rate mapping is inverted: buy uses bid and sell uses ask.","sha256":"9b85375f6e0d21e535611e36cc0976121dd67d36419249ded2df92cc210071f4","title":"A customer purchase is priced at the dealer's bid · case 01","variant":1,"variant_policy":"Five numbered records share a model and may reuse boundary fixtures.","verified":true,"visibility":"public","verification":{"attempt":{"elapsed_ms":43.222,"exit_code":1,"observations":[{"actual":["1083.50","USD"],"check":"regression dealer-side-rate 1","expected":["1083.50","USD"],"passed":true},{"actual":["1083.50","USD"],"check":"regression dealer-side-rate 2","expected":["1083.10","USD"],"passed":false},{"actual":["92.30","EUR"],"check":"partial repair guard 2","expected":["92.33","EUR"],"passed":false},{"actual":["92.29","EUR"],"check":"control: spend quote","expected":["92.29","EUR"],"passed":true},{"actual":["1514","JPY"],"check":"control: yen counter","expected":["1514","JPY"],"passed":true},{"actual":["316.25","USD"],"check":"control: locked quote","expected":["316.25","USD"],"passed":true},{"actual":"ERR:crossed-quote","check":"control: crossed quote","expected":"ERR:crossed-quote","passed":true}],"passed":false,"stderr":"","stdout":"{\"observations\": [{\"check\": \"regression dealer-side-rate 1\", \"actual\": [\"1083.50\", \"USD\"], \"expected\": [\"1083.50\", \"USD\"], \"passed\": true}, {\"check\": \"regression dealer-side-rate 2\", \"actual\": [\"1083.50\", \"USD\"], \"expected\": [\"1083.10\", \"USD\"], \"passed\": false}, {\"check\": \"partial repair guard 2\", \"actual\": [\"92.30\", \"EUR\"], \"expected\": [\"92.33\", \"EUR\"], \"passed\": false}, {\"check\": \"control: spend quote\", \"actual\": [\"92.29\", \"EUR\"], \"expected\": [\"92.29\", \"EUR\"], \"passed\": true}, {\"check\": \"control: yen counter\", \"actual\": [\"1514\", \"JPY\"], \"expected\": [\"1514\", \"JPY\"], \"passed\": true}, {\"check\": \"control: locked quote\", \"actual\": [\"316.25\", \"USD\"], \"expected\": [\"316.25\", \"USD\"], \"passed\": true}, {\"check\": \"control: crossed quote\", \"actual\": \"ERR:crossed-quote\", \"expected\": \"ERR:crossed-quote\", \"passed\": true}], \"passed\": false}\n"},"broken":{"elapsed_ms":42.147,"exit_code":1,"observations":[{"actual":["1083.10","USD"],"check":"regression dealer-side-rate 1","expected":["1083.50","USD"],"passed":false},{"actual":["1083.50","USD"],"check":"regression dealer-side-rate 2","expected":["1083.10","USD"],"passed":false},{"actual":["92.30","EUR"],"check":"partial repair guard 2","expected":["92.33","EUR"],"passed":false},{"actual":["92.32","EUR"],"check":"control: spend quote","expected":["92.29","EUR"],"passed":false},{"actual":["1514","JPY"],"check":"control: yen counter","expected":["1514","JPY"],"passed":true},{"actual":["316.25","USD"],"check":"control: locked quote","expected":["316.25","USD"],"passed":true},{"actual":"ERR:crossed-quote","check":"control: crossed quote","expected":"ERR:crossed-quote","passed":true}],"passed":false,"stderr":"","stdout":"{\"observations\": [{\"check\": \"regression dealer-side-rate 1\", \"actual\": [\"1083.10\", \"USD\"], \"expected\": [\"1083.50\", \"USD\"], \"passed\": false}, {\"check\": \"regression dealer-side-rate 2\", \"actual\": [\"1083.50\", \"USD\"], \"expected\": [\"1083.10\", \"USD\"], \"passed\": false}, {\"check\": \"partial repair guard 2\", \"actual\": [\"92.30\", \"EUR\"], \"expected\": [\"92.33\", \"EUR\"], \"passed\": false}, {\"check\": \"control: spend quote\", \"actual\": [\"92.32\", \"EUR\"], \"expected\": [\"92.29\", \"EUR\"], \"passed\": false}, {\"check\": \"control: yen counter\", \"actual\": [\"1514\", \"JPY\"], \"expected\": [\"1514\", \"JPY\"], \"passed\": true}, {\"check\": \"control: locked quote\", \"actual\": [\"316.25\", \"USD\"], \"expected\": [\"316.25\", \"USD\"], \"passed\": true}, {\"check\": \"control: crossed quote\", \"actual\": \"ERR:crossed-quote\", \"expected\": \"ERR:crossed-quote\", \"passed\": true}], \"passed\": false}\n"}},"member_only":{"stages":["fixed"],"fields":["implementations.fixed","verification.fixed","harness","repair"],"note":"The verified repair, its recorded checks, the repair description, and the scoring harness are available to members."}}