{"abstract":"Several small closes accumulate a cent-level discrepancy against the exact realized total.","category":"Currency rounding and FX conversion","checks":7,"contract":"solve(trades, spot): trades are [qty, rate] in foreign units (buy positive, sell negative) at home-per-foreign decimal rates. Adding in the position's direction updates the weighted average rate; reducing realizes closed_qty * (rate - avg) * sign(position) without changing avg; a flip realizes the closed part and opens the remainder at the trade rate; a flat position has no average. Zero-quantity trades are ignored. Unrealized = position * (spot - avg). Return [position, avg to 6 dp or None, realized to 2 dp, unrealized to 2 dp], rounded half-even only at output with unsigned zeros.","evaluation_group":"w2-currency_rounding_and_fx_conversion-fx-position-average-rate","failed_approach":"Rounding the running total to four decimals still compounds per-trade rounding error.","family":"w2-currency_rounding_and_fx_conversion-fx-position-average-rate-realized-accumulation-rounding","id":"FA-62056","implementations":{"attempt":{"sha256":"106b4b6f4a5a547a4653133f4e8ab9efc9d3cd665c65e9ee61b51bd72b8422bd","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\nfrom fractions import Fraction\nN = 1\nobservations = []\ndef solve(trades, spot):\n    def fmt(fr, e):\n        d = (Decimal(fr.numerator) / Decimal(fr.denominator)).quantize(Decimal(1).scaleb(-e), rounding=ROUND_HALF_EVEN)\n        return format(abs(d) if d == 0 else d, 'f')\n    pos, avg, realized = 0, None, Fraction(0)\n    for qty, rate in trades:\n        r = Fraction(rate)\n        if qty == 0: continue\n        if pos == 0 or (pos > 0) == (qty > 0):\n            avg = r if pos == 0 else (abs(pos) * avg + abs(qty) * r) / (abs(pos) + abs(qty))\n            pos += qty\n        else:\n            closed = min(abs(qty), abs(pos))\n            sgn = 1 if pos > 0 else -1\n            realized += closed * (r - avg) * sgn\n            realized = Fraction(fmt(realized, 4))\n            pos += qty\n            if pos == 0: avg = None\n            elif (pos > 0) != (sgn > 0): avg = r\n    unreal = pos * (Fraction(spot) - avg) if pos else Fraction(0)\n    return [pos, None if avg is None else fmt(avg, 6), fmt(realized, 2), fmt(unreal, 2)]\ndef check(label, actual, expected):\n    observations.append({\"check\": label, \"actual\": actual, \"expected\": expected, \"passed\": actual == expected})\ncases = [[('regression realized-accumulation-rounding 1', ([[3, '1'], [-1, '1.005'], [-1, '1.005'], [-1, '1.005']], '1'),\n   [0, None, '0.02', '0.00']),\n  ('regression realized-accumulation-rounding 2', ([[2, '1'], [-1, '1.00252'], [-1, '1.00251']], '1'),\n   [0, None, '0.01', '0.00']),\n  ('partial repair guard 1', ([[1, '1'], [-1, '1.00502']], '1'), [0, None, '0.01', '0.00']),\n  ('control: add then reduce', ([[100, '1.10'], [100, '1.20'], [-50, '1.30']], '1.25'),\n   [150, '1.150000', '7.50', '15.00']),\n  ('control: flip long to short', ([[100, '1.10'], [-150, '1.00']], '1.05'), [-50, '1.000000', '-10.00', '-2.50']),\n  ('control: close short', ([[-100, '1.10'], [100, '1.00']], '1.05'), [0, None, '10.00', '0.00']),\n  ('control: zero trade only', ([[0, '1.10']], '1.05'), [0, None, '0.00', '0.00'])],\n [('regression realized-accumulation-rounding 1',\n   ([[-160, '1.1445'], [370, '1.0518'], [470, '1.1207'], [-420, '1.1186'], [0, '1.1436'], [-430, '1.0692']], '1.1002'),\n   [-170, '1.069200', '15.03', '-5.27']),\n  ('regression realized-accumulation-rounding 2',\n   ([[-440, '1.1376'], [320, '1.1062'], [-500, '1.1066'], [0, '1.0745'], [-450, '1.0551'], [560, '1.0788']], '1.1271'),\n   [-510, '1.088418', '15.43', '-19.73']),\n  ('partial repair guard 1', ([[1, '1'], [-1, '1.00502']], '1'), [0, None, '0.01', '0.00']),\n  ('partial repair guard 2', ([[2, '1'], [-1, '1.00252'], [-1, '1.00251']], '1'), [0, None, '0.01', '0.00']),\n  ('control: zero trade only', ([[0, '1.10']], '1.05'), [0, None, '0.00', '0.00']),\n  ('control: short add', ([[-30, '1.0833'], [-70, '1.0851']], '1.0800'), [-100, '1.084560', '0.00', '0.46']),\n  ('control: three reductions', ([[300, '1.0711'], [-100, '1.0733'], [-100, '1.0745'], [-100, '1.0719']], '1.07'),\n   [0, None, '0.64', '0.00']),\n  ('control: zero between', ([[50, '1.1'], [-50, '1.2'], [0, '1.3'], [20, '1.4']], '1.5'),\n   [20, '1.400000', '5.00', '2.00'])],\n [('regression realized-accumulation-rounding 1', ([[500, '1.1350'], [-210, '1.0625'], [-530, '1.1133']], '1.1442'),\n   [-240, '1.113300', '-21.52', '-7.42']),\n  ('regression realized-accumulation-rounding 2',\n   ([[420, '1.0549'], [-340, '1.1155'], [-600, '1.1019'], [120, '1.0728'], [120, '1.0952'], [300, '1.0728']], '1.1408'),\n   [20, '1.072800', '36.81', '1.36']),\n  ('partial repair guard 1', ([[1, '1'], [-1, '1.00502']], '1'), [0, None, '0.01', '0.00']),\n  ('partial repair guard 2', ([[2, '1'], [-1, '1.00252'], [-1, '1.00251']], '1'), [0, None, '0.01', '0.00']),\n  ('control: zero between', ([[50, '1.1'], [-50, '1.2'], [0, '1.3'], [20, '1.4']], '1.5'),\n   [20, '1.400000', '5.00', '2.00']),\n  ('control: flip short to long', ([[-40, '1.2'], [100, '1.1']], '1.15'), [60, '1.100000', '4.00', '3.00']),\n  ('control: add then reduce', ([[100, '1.10'], [100, '1.20'], [-50, '1.30']], '1.25'),\n   [150, '1.150000', '7.50', '15.00']),\n  ('control: flip long to short', ([[100, '1.10'], [-150, '1.00']], '1.05'), [-50, '1.000000', '-10.00', '-2.50'])],\n [('regression realized-accumulation-rounding 1',\n   ([[-330, '1.0644'], [460, '1.1022'], [130, '1.1361'], [0, '1.0789'], [-160, '1.0850']], '1.0640'),\n   [100, '1.119150', '-17.94', '-5.52']),\n  ('regression realized-accumulation-rounding 2', ([[10, '1.1411'], [-370, '1.0726'], [50, '1.0616']], '1.1081'),\n   [-310, '1.072600', '-0.14', '-11.00']),\n  ('partial repair guard 1', ([[1, '1'], [-1, '1.00502']], '1'), [0, None, '0.01', '0.00']),\n  ('partial repair guard 2', ([[2, '1'], [-1, '1.00252'], [-1, '1.00251']], '1'), [0, None, '0.01', '0.00']),\n  ('control: flip long to short', ([[100, '1.10'], [-150, '1.00']], '1.05'), [-50, '1.000000', '-10.00', '-2.50']),\n  ('control: close short', ([[-100, '1.10'], [100, '1.00']], '1.05'), [0, None, '10.00', '0.00']),\n  ('control: zero trade only', ([[0, '1.10']], '1.05'), [0, None, '0.00', '0.00']),\n  ('control: short add', ([[-30, '1.0833'], [-70, '1.0851']], '1.0800'), [-100, '1.084560', '0.00', '0.46'])],\n [('regression realized-accumulation-rounding 1',\n   ([[120, '1.1265'], [-100, '1.1177'], [270, '1.1372'], [-530, '1.1150'], [510, '1.0931'], [-490, '1.0584']],\n    '1.1400'),\n   [-220, '1.058400', '-11.22', '-17.95']),\n  ('regression realized-accumulation-rounding 2',\n   ([[460, '1.0523'], [340, '1.1064'], [-460, '1.1068'], [0, '1.1268'], [-560, '1.0903'], [190, '1.0925']], '1.0886'),\n   [-30, '1.090300', '19.18', '0.05']),\n  ('partial repair guard 1', ([[1, '1'], [-1, '1.00502']], '1'), [0, None, '0.01', '0.00']),\n  ('partial repair guard 2', ([[2, '1'], [-1, '1.00252'], [-1, '1.00251']], '1'), [0, None, '0.01', '0.00']),\n  ('control: short add', ([[-30, '1.0833'], [-70, '1.0851']], '1.0800'), [-100, '1.084560', '0.00', '0.46']),\n  ('control: three reductions', ([[300, '1.0711'], [-100, '1.0733'], [-100, '1.0745'], [-100, '1.0719']], '1.07'),\n   [0, None, '0.64', '0.00']),\n  ('control: zero between', ([[50, '1.1'], [-50, '1.2'], [0, '1.3'], [20, '1.4']], '1.5'),\n   [20, '1.400000', '5.00', '2.00']),\n  ('control: flip short to long', ([[-40, '1.2'], [100, '1.1']], '1.15'), [60, '1.100000', '4.00', '3.00'])]]\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":"065e7b7bdcbd520e824f3a8706452a86dd1499ad11d5ed3487e92146ec0d73e7","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\nfrom fractions import Fraction\nN = 1\nobservations = []\ndef solve(trades, spot):\n    def fmt(fr, e):\n        d = (Decimal(fr.numerator) / Decimal(fr.denominator)).quantize(Decimal(1).scaleb(-e), rounding=ROUND_HALF_EVEN)\n        return format(abs(d) if d == 0 else d, 'f')\n    pos, avg, realized = 0, None, Fraction(0)\n    for qty, rate in trades:\n        r = Fraction(rate)\n        if qty == 0: continue\n        if pos == 0 or (pos > 0) == (qty > 0):\n            avg = r if pos == 0 else (abs(pos) * avg + abs(qty) * r) / (abs(pos) + abs(qty))\n            pos += qty\n        else:\n            closed = min(abs(qty), abs(pos))\n            sgn = 1 if pos > 0 else -1\n            realized += closed * (r - avg) * sgn\n            realized = Fraction(fmt(realized, 2))\n            pos += qty\n            if pos == 0: avg = None\n            elif (pos > 0) != (sgn > 0): avg = r\n    unreal = pos * (Fraction(spot) - avg) if pos else Fraction(0)\n    return [pos, None if avg is None else fmt(avg, 6), fmt(realized, 2), fmt(unreal, 2)]\ndef check(label, actual, expected):\n    observations.append({\"check\": label, \"actual\": actual, \"expected\": expected, \"passed\": actual == expected})\ncases = [[('regression realized-accumulation-rounding 1', ([[3, '1'], [-1, '1.005'], [-1, '1.005'], [-1, '1.005']], '1'),\n   [0, None, '0.02', '0.00']),\n  ('regression realized-accumulation-rounding 2', ([[2, '1'], [-1, '1.00252'], [-1, '1.00251']], '1'),\n   [0, None, '0.01', '0.00']),\n  ('partial repair guard 1', ([[1, '1'], [-1, '1.00502']], '1'), [0, None, '0.01', '0.00']),\n  ('control: add then reduce', ([[100, '1.10'], [100, '1.20'], [-50, '1.30']], '1.25'),\n   [150, '1.150000', '7.50', '15.00']),\n  ('control: flip long to short', ([[100, '1.10'], [-150, '1.00']], '1.05'), [-50, '1.000000', '-10.00', '-2.50']),\n  ('control: close short', ([[-100, '1.10'], [100, '1.00']], '1.05'), [0, None, '10.00', '0.00']),\n  ('control: zero trade only', ([[0, '1.10']], '1.05'), [0, None, '0.00', '0.00'])],\n [('regression realized-accumulation-rounding 1',\n   ([[-160, '1.1445'], [370, '1.0518'], [470, '1.1207'], [-420, '1.1186'], [0, '1.1436'], [-430, '1.0692']], '1.1002'),\n   [-170, '1.069200', '15.03', '-5.27']),\n  ('regression realized-accumulation-rounding 2',\n   ([[-440, '1.1376'], [320, '1.1062'], [-500, '1.1066'], [0, '1.0745'], [-450, '1.0551'], [560, '1.0788']], '1.1271'),\n   [-510, '1.088418', '15.43', '-19.73']),\n  ('partial repair guard 1', ([[1, '1'], [-1, '1.00502']], '1'), [0, None, '0.01', '0.00']),\n  ('partial repair guard 2', ([[2, '1'], [-1, '1.00252'], [-1, '1.00251']], '1'), [0, None, '0.01', '0.00']),\n  ('control: zero trade only', ([[0, '1.10']], '1.05'), [0, None, '0.00', '0.00']),\n  ('control: short add', ([[-30, '1.0833'], [-70, '1.0851']], '1.0800'), [-100, '1.084560', '0.00', '0.46']),\n  ('control: three reductions', ([[300, '1.0711'], [-100, '1.0733'], [-100, '1.0745'], [-100, '1.0719']], '1.07'),\n   [0, None, '0.64', '0.00']),\n  ('control: zero between', ([[50, '1.1'], [-50, '1.2'], [0, '1.3'], [20, '1.4']], '1.5'),\n   [20, '1.400000', '5.00', '2.00'])],\n [('regression realized-accumulation-rounding 1', ([[500, '1.1350'], [-210, '1.0625'], [-530, '1.1133']], '1.1442'),\n   [-240, '1.113300', '-21.52', '-7.42']),\n  ('regression realized-accumulation-rounding 2',\n   ([[420, '1.0549'], [-340, '1.1155'], [-600, '1.1019'], [120, '1.0728'], [120, '1.0952'], [300, '1.0728']], '1.1408'),\n   [20, '1.072800', '36.81', '1.36']),\n  ('partial repair guard 1', ([[1, '1'], [-1, '1.00502']], '1'), [0, None, '0.01', '0.00']),\n  ('partial repair guard 2', ([[2, '1'], [-1, '1.00252'], [-1, '1.00251']], '1'), [0, None, '0.01', '0.00']),\n  ('control: zero between', ([[50, '1.1'], [-50, '1.2'], [0, '1.3'], [20, '1.4']], '1.5'),\n   [20, '1.400000', '5.00', '2.00']),\n  ('control: flip short to long', ([[-40, '1.2'], [100, '1.1']], '1.15'), [60, '1.100000', '4.00', '3.00']),\n  ('control: add then reduce', ([[100, '1.10'], [100, '1.20'], [-50, '1.30']], '1.25'),\n   [150, '1.150000', '7.50', '15.00']),\n  ('control: flip long to short', ([[100, '1.10'], [-150, '1.00']], '1.05'), [-50, '1.000000', '-10.00', '-2.50'])],\n [('regression realized-accumulation-rounding 1',\n   ([[-330, '1.0644'], [460, '1.1022'], [130, '1.1361'], [0, '1.0789'], [-160, '1.0850']], '1.0640'),\n   [100, '1.119150', '-17.94', '-5.52']),\n  ('regression realized-accumulation-rounding 2', ([[10, '1.1411'], [-370, '1.0726'], [50, '1.0616']], '1.1081'),\n   [-310, '1.072600', '-0.14', '-11.00']),\n  ('partial repair guard 1', ([[1, '1'], [-1, '1.00502']], '1'), [0, None, '0.01', '0.00']),\n  ('partial repair guard 2', ([[2, '1'], [-1, '1.00252'], [-1, '1.00251']], '1'), [0, None, '0.01', '0.00']),\n  ('control: flip long to short', ([[100, '1.10'], [-150, '1.00']], '1.05'), [-50, '1.000000', '-10.00', '-2.50']),\n  ('control: close short', ([[-100, '1.10'], [100, '1.00']], '1.05'), [0, None, '10.00', '0.00']),\n  ('control: zero trade only', ([[0, '1.10']], '1.05'), [0, None, '0.00', '0.00']),\n  ('control: short add', ([[-30, '1.0833'], [-70, '1.0851']], '1.0800'), [-100, '1.084560', '0.00', '0.46'])],\n [('regression realized-accumulation-rounding 1',\n   ([[120, '1.1265'], [-100, '1.1177'], [270, '1.1372'], [-530, '1.1150'], [510, '1.0931'], [-490, '1.0584']],\n    '1.1400'),\n   [-220, '1.058400', '-11.22', '-17.95']),\n  ('regression realized-accumulation-rounding 2',\n   ([[460, '1.0523'], [340, '1.1064'], [-460, '1.1068'], [0, '1.1268'], [-560, '1.0903'], [190, '1.0925']], '1.0886'),\n   [-30, '1.090300', '19.18', '0.05']),\n  ('partial repair guard 1', ([[1, '1'], [-1, '1.00502']], '1'), [0, None, '0.01', '0.00']),\n  ('partial repair guard 2', ([[2, '1'], [-1, '1.00252'], [-1, '1.00251']], '1'), [0, None, '0.01', '0.00']),\n  ('control: short add', ([[-30, '1.0833'], [-70, '1.0851']], '1.0800'), [-100, '1.084560', '0.00', '0.46']),\n  ('control: three reductions', ([[300, '1.0711'], [-100, '1.0733'], [-100, '1.0745'], [-100, '1.0719']], '1.07'),\n   [0, None, '0.64', '0.00']),\n  ('control: zero between', ([[50, '1.1'], [-50, '1.2'], [0, '1.3'], [20, '1.4']], '1.5'),\n   [20, '1.400000', '5.00', '2.00']),\n  ('control: flip short to long', ([[-40, '1.2'], [100, '1.1']], '1.15'), [60, '1.100000', '4.00', '3.00'])]]\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"},"fixed":{"sha256":"c86f188a9d4c47aa91a5a3fccc86736ce29d798fc00672a4ee54568cb412e212","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\nfrom fractions import Fraction\nN = 1\nobservations = []\ndef solve(trades, spot):\n    def fmt(fr, e):\n        d = (Decimal(fr.numerator) / Decimal(fr.denominator)).quantize(Decimal(1).scaleb(-e), rounding=ROUND_HALF_EVEN)\n        return format(abs(d) if d == 0 else d, 'f')\n    pos, avg, realized = 0, None, Fraction(0)\n    for qty, rate in trades:\n        r = Fraction(rate)\n        if qty == 0: continue\n        if pos == 0 or (pos > 0) == (qty > 0):\n            avg = r if pos == 0 else (abs(pos) * avg + abs(qty) * r) / (abs(pos) + abs(qty))\n            pos += qty\n        else:\n            closed = min(abs(qty), abs(pos))\n            sgn = 1 if pos > 0 else -1\n            realized += closed * (r - avg) * sgn\n            pos += qty\n            if pos == 0: avg = None\n            elif (pos > 0) != (sgn > 0): avg = r\n    unreal = pos * (Fraction(spot) - avg) if pos else Fraction(0)\n    return [pos, None if avg is None else fmt(avg, 6), fmt(realized, 2), fmt(unreal, 2)]\ndef check(label, actual, expected):\n    observations.append({\"check\": label, \"actual\": actual, \"expected\": expected, \"passed\": actual == expected})\ncases = [[('regression realized-accumulation-rounding 1', ([[3, '1'], [-1, '1.005'], [-1, '1.005'], [-1, '1.005']], '1'),\n   [0, None, '0.02', '0.00']),\n  ('regression realized-accumulation-rounding 2', ([[2, '1'], [-1, '1.00252'], [-1, '1.00251']], '1'),\n   [0, None, '0.01', '0.00']),\n  ('partial repair guard 1', ([[1, '1'], [-1, '1.00502']], '1'), [0, None, '0.01', '0.00']),\n  ('control: add then reduce', ([[100, '1.10'], [100, '1.20'], [-50, '1.30']], '1.25'),\n   [150, '1.150000', '7.50', '15.00']),\n  ('control: flip long to short', ([[100, '1.10'], [-150, '1.00']], '1.05'), [-50, '1.000000', '-10.00', '-2.50']),\n  ('control: close short', ([[-100, '1.10'], [100, '1.00']], '1.05'), [0, None, '10.00', '0.00']),\n  ('control: zero trade only', ([[0, '1.10']], '1.05'), [0, None, '0.00', '0.00'])],\n [('regression realized-accumulation-rounding 1',\n   ([[-160, '1.1445'], [370, '1.0518'], [470, '1.1207'], [-420, '1.1186'], [0, '1.1436'], [-430, '1.0692']], '1.1002'),\n   [-170, '1.069200', '15.03', '-5.27']),\n  ('regression realized-accumulation-rounding 2',\n   ([[-440, '1.1376'], [320, '1.1062'], [-500, '1.1066'], [0, '1.0745'], [-450, '1.0551'], [560, '1.0788']], '1.1271'),\n   [-510, '1.088418', '15.43', '-19.73']),\n  ('partial repair guard 1', ([[1, '1'], [-1, '1.00502']], '1'), [0, None, '0.01', '0.00']),\n  ('partial repair guard 2', ([[2, '1'], [-1, '1.00252'], [-1, '1.00251']], '1'), [0, None, '0.01', '0.00']),\n  ('control: zero trade only', ([[0, '1.10']], '1.05'), [0, None, '0.00', '0.00']),\n  ('control: short add', ([[-30, '1.0833'], [-70, '1.0851']], '1.0800'), [-100, '1.084560', '0.00', '0.46']),\n  ('control: three reductions', ([[300, '1.0711'], [-100, '1.0733'], [-100, '1.0745'], [-100, '1.0719']], '1.07'),\n   [0, None, '0.64', '0.00']),\n  ('control: zero between', ([[50, '1.1'], [-50, '1.2'], [0, '1.3'], [20, '1.4']], '1.5'),\n   [20, '1.400000', '5.00', '2.00'])],\n [('regression realized-accumulation-rounding 1', ([[500, '1.1350'], [-210, '1.0625'], [-530, '1.1133']], '1.1442'),\n   [-240, '1.113300', '-21.52', '-7.42']),\n  ('regression realized-accumulation-rounding 2',\n   ([[420, '1.0549'], [-340, '1.1155'], [-600, '1.1019'], [120, '1.0728'], [120, '1.0952'], [300, '1.0728']], '1.1408'),\n   [20, '1.072800', '36.81', '1.36']),\n  ('partial repair guard 1', ([[1, '1'], [-1, '1.00502']], '1'), [0, None, '0.01', '0.00']),\n  ('partial repair guard 2', ([[2, '1'], [-1, '1.00252'], [-1, '1.00251']], '1'), [0, None, '0.01', '0.00']),\n  ('control: zero between', ([[50, '1.1'], [-50, '1.2'], [0, '1.3'], [20, '1.4']], '1.5'),\n   [20, '1.400000', '5.00', '2.00']),\n  ('control: flip short to long', ([[-40, '1.2'], [100, '1.1']], '1.15'), [60, '1.100000', '4.00', '3.00']),\n  ('control: add then reduce', ([[100, '1.10'], [100, '1.20'], [-50, '1.30']], '1.25'),\n   [150, '1.150000', '7.50', '15.00']),\n  ('control: flip long to short', ([[100, '1.10'], [-150, '1.00']], '1.05'), [-50, '1.000000', '-10.00', '-2.50'])],\n [('regression realized-accumulation-rounding 1',\n   ([[-330, '1.0644'], [460, '1.1022'], [130, '1.1361'], [0, '1.0789'], [-160, '1.0850']], '1.0640'),\n   [100, '1.119150', '-17.94', '-5.52']),\n  ('regression realized-accumulation-rounding 2', ([[10, '1.1411'], [-370, '1.0726'], [50, '1.0616']], '1.1081'),\n   [-310, '1.072600', '-0.14', '-11.00']),\n  ('partial repair guard 1', ([[1, '1'], [-1, '1.00502']], '1'), [0, None, '0.01', '0.00']),\n  ('partial repair guard 2', ([[2, '1'], [-1, '1.00252'], [-1, '1.00251']], '1'), [0, None, '0.01', '0.00']),\n  ('control: flip long to short', ([[100, '1.10'], [-150, '1.00']], '1.05'), [-50, '1.000000', '-10.00', '-2.50']),\n  ('control: close short', ([[-100, '1.10'], [100, '1.00']], '1.05'), [0, None, '10.00', '0.00']),\n  ('control: zero trade only', ([[0, '1.10']], '1.05'), [0, None, '0.00', '0.00']),\n  ('control: short add', ([[-30, '1.0833'], [-70, '1.0851']], '1.0800'), [-100, '1.084560', '0.00', '0.46'])],\n [('regression realized-accumulation-rounding 1',\n   ([[120, '1.1265'], [-100, '1.1177'], [270, '1.1372'], [-530, '1.1150'], [510, '1.0931'], [-490, '1.0584']],\n    '1.1400'),\n   [-220, '1.058400', '-11.22', '-17.95']),\n  ('regression realized-accumulation-rounding 2',\n   ([[460, '1.0523'], [340, '1.1064'], [-460, '1.1068'], [0, '1.1268'], [-560, '1.0903'], [190, '1.0925']], '1.0886'),\n   [-30, '1.090300', '19.18', '0.05']),\n  ('partial repair guard 1', ([[1, '1'], [-1, '1.00502']], '1'), [0, None, '0.01', '0.00']),\n  ('partial repair guard 2', ([[2, '1'], [-1, '1.00252'], [-1, '1.00251']], '1'), [0, None, '0.01', '0.00']),\n  ('control: short add', ([[-30, '1.0833'], [-70, '1.0851']], '1.0800'), [-100, '1.084560', '0.00', '0.46']),\n  ('control: three reductions', ([[300, '1.0711'], [-100, '1.0733'], [-100, '1.0745'], [-100, '1.0719']], '1.07'),\n   [0, None, '0.64', '0.00']),\n  ('control: zero between', ([[50, '1.1'], [-50, '1.2'], [0, '1.3'], [20, '1.4']], '1.5'),\n   [20, '1.400000', '5.00', '2.00']),\n  ('control: flip short to long', ([[-40, '1.2'], [100, '1.1']], '1.15'), [60, '1.100000', '4.00', '3.00'])]]\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-fx-position-average-rate-realized-accumulation-rounding","generated_at":"2026-09-29T14:47:01.026588+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.","repair":"Accumulate realized P&L exactly and round only when reporting.","root_cause":"The running realized amount is quantized to two decimals after each reduction.","sha256":"48b9d8ba21dca9bed01491ea8d3ee16ab0b15ab7f8b664b92c479e67765a2f1c","title":"Realized P&L is rounded to cents after every closing trade · case 01","variant":1,"variant_policy":"Five numbered records share a model and may reuse boundary fixtures.","verification":{"attempt":{"elapsed_ms":44.152,"exit_code":1,"observations":[{"actual":[0,null,"0.02","0.00"],"check":"regression realized-accumulation-rounding 1","expected":[0,null,"0.02","0.00"],"passed":true},{"actual":[0,null,"0.00","0.00"],"check":"regression realized-accumulation-rounding 2","expected":[0,null,"0.01","0.00"],"passed":false},{"actual":[0,null,"0.00","0.00"],"check":"partial repair guard 1","expected":[0,null,"0.01","0.00"],"passed":false},{"actual":[150,"1.150000","7.50","15.00"],"check":"control: add then reduce","expected":[150,"1.150000","7.50","15.00"],"passed":true},{"actual":[-50,"1.000000","-10.00","-2.50"],"check":"control: flip long to short","expected":[-50,"1.000000","-10.00","-2.50"],"passed":true},{"actual":[0,null,"10.00","0.00"],"check":"control: close short","expected":[0,null,"10.00","0.00"],"passed":true},{"actual":[0,null,"0.00","0.00"],"check":"control: zero trade only","expected":[0,null,"0.00","0.00"],"passed":true}],"passed":false,"stderr":"","stdout":"{\"observations\": [{\"check\": \"regression realized-accumulation-rounding 1\", \"actual\": [0, null, \"0.02\", \"0.00\"], \"expected\": [0, null, \"0.02\", \"0.00\"], \"passed\": true}, {\"check\": \"regression realized-accumulation-rounding 2\", \"actual\": [0, null, \"0.00\", \"0.00\"], \"expected\": [0, null, \"0.01\", \"0.00\"], \"passed\": false}, {\"check\": \"partial repair guard 1\", \"actual\": [0, null, \"0.00\", \"0.00\"], \"expected\": [0, null, \"0.01\", \"0.00\"], \"passed\": false}, {\"check\": \"control: add then reduce\", \"actual\": [150, \"1.150000\", \"7.50\", \"15.00\"], \"expected\": [150, \"1.150000\", \"7.50\", \"15.00\"], \"passed\": true}, {\"check\": \"control: flip long to short\", \"actual\": [-50, \"1.000000\", \"-10.00\", \"-2.50\"], \"expected\": [-50, \"1.000000\", \"-10.00\", \"-2.50\"], \"passed\": true}, {\"check\": \"control: close short\", \"actual\": [0, null, \"10.00\", \"0.00\"], \"expected\": [0, null, \"10.00\", \"0.00\"], \"passed\": true}, {\"check\": \"control: zero trade only\", \"actual\": [0, null, \"0.00\", \"0.00\"], \"expected\": [0, null, \"0.00\", \"0.00\"], \"passed\": true}], \"passed\": false}\n"},"broken":{"elapsed_ms":42.246,"exit_code":1,"observations":[{"actual":[0,null,"0.00","0.00"],"check":"regression realized-accumulation-rounding 1","expected":[0,null,"0.02","0.00"],"passed":false},{"actual":[0,null,"0.00","0.00"],"check":"regression realized-accumulation-rounding 2","expected":[0,null,"0.01","0.00"],"passed":false},{"actual":[0,null,"0.01","0.00"],"check":"partial repair guard 1","expected":[0,null,"0.01","0.00"],"passed":true},{"actual":[150,"1.150000","7.50","15.00"],"check":"control: add then reduce","expected":[150,"1.150000","7.50","15.00"],"passed":true},{"actual":[-50,"1.000000","-10.00","-2.50"],"check":"control: flip long to short","expected":[-50,"1.000000","-10.00","-2.50"],"passed":true},{"actual":[0,null,"10.00","0.00"],"check":"control: close short","expected":[0,null,"10.00","0.00"],"passed":true},{"actual":[0,null,"0.00","0.00"],"check":"control: zero trade only","expected":[0,null,"0.00","0.00"],"passed":true}],"passed":false,"stderr":"","stdout":"{\"observations\": [{\"check\": \"regression realized-accumulation-rounding 1\", \"actual\": [0, null, \"0.00\", \"0.00\"], \"expected\": [0, null, \"0.02\", \"0.00\"], \"passed\": false}, {\"check\": \"regression realized-accumulation-rounding 2\", \"actual\": [0, null, \"0.00\", \"0.00\"], \"expected\": [0, null, \"0.01\", \"0.00\"], \"passed\": false}, {\"check\": \"partial repair guard 1\", \"actual\": [0, null, \"0.01\", \"0.00\"], \"expected\": [0, null, \"0.01\", \"0.00\"], \"passed\": true}, {\"check\": \"control: add then reduce\", \"actual\": [150, \"1.150000\", \"7.50\", \"15.00\"], \"expected\": [150, \"1.150000\", \"7.50\", \"15.00\"], \"passed\": true}, {\"check\": \"control: flip long to short\", \"actual\": [-50, \"1.000000\", \"-10.00\", \"-2.50\"], \"expected\": [-50, \"1.000000\", \"-10.00\", \"-2.50\"], \"passed\": true}, {\"check\": \"control: close short\", \"actual\": [0, null, \"10.00\", \"0.00\"], \"expected\": [0, null, \"10.00\", \"0.00\"], \"passed\": true}, {\"check\": \"control: zero trade only\", \"actual\": [0, null, \"0.00\", \"0.00\"], \"expected\": [0, null, \"0.00\", \"0.00\"], \"passed\": true}], \"passed\": false}\n"},"fixed":{"elapsed_ms":45.689,"exit_code":0,"observations":[{"actual":[0,null,"0.02","0.00"],"check":"regression realized-accumulation-rounding 1","expected":[0,null,"0.02","0.00"],"passed":true},{"actual":[0,null,"0.01","0.00"],"check":"regression realized-accumulation-rounding 2","expected":[0,null,"0.01","0.00"],"passed":true},{"actual":[0,null,"0.01","0.00"],"check":"partial repair guard 1","expected":[0,null,"0.01","0.00"],"passed":true},{"actual":[150,"1.150000","7.50","15.00"],"check":"control: add then reduce","expected":[150,"1.150000","7.50","15.00"],"passed":true},{"actual":[-50,"1.000000","-10.00","-2.50"],"check":"control: flip long to short","expected":[-50,"1.000000","-10.00","-2.50"],"passed":true},{"actual":[0,null,"10.00","0.00"],"check":"control: close short","expected":[0,null,"10.00","0.00"],"passed":true},{"actual":[0,null,"0.00","0.00"],"check":"control: zero trade only","expected":[0,null,"0.00","0.00"],"passed":true}],"passed":true,"stderr":"","stdout":"{\"observations\": [{\"check\": \"regression realized-accumulation-rounding 1\", \"actual\": [0, null, \"0.02\", \"0.00\"], \"expected\": [0, null, \"0.02\", \"0.00\"], \"passed\": true}, {\"check\": \"regression realized-accumulation-rounding 2\", \"actual\": [0, null, \"0.01\", \"0.00\"], \"expected\": [0, null, \"0.01\", \"0.00\"], \"passed\": true}, {\"check\": \"partial repair guard 1\", \"actual\": [0, null, \"0.01\", \"0.00\"], \"expected\": [0, null, \"0.01\", \"0.00\"], \"passed\": true}, {\"check\": \"control: add then reduce\", \"actual\": [150, \"1.150000\", \"7.50\", \"15.00\"], \"expected\": [150, \"1.150000\", \"7.50\", \"15.00\"], \"passed\": true}, {\"check\": \"control: flip long to short\", \"actual\": [-50, \"1.000000\", \"-10.00\", \"-2.50\"], \"expected\": [-50, \"1.000000\", \"-10.00\", \"-2.50\"], \"passed\": true}, {\"check\": \"control: close short\", \"actual\": [0, null, \"10.00\", \"0.00\"], \"expected\": [0, null, \"10.00\", \"0.00\"], \"passed\": true}, {\"check\": \"control: zero trade only\", \"actual\": [0, null, \"0.00\", \"0.00\"], \"expected\": [0, null, \"0.00\", \"0.00\"], \"passed\": true}], \"passed\": true}\n"}},"verified":true,"visibility":"public"}