{"abstract":"A long position shows a loss when spot is above its average.","category":"Currency rounding and FX conversion","checks":6,"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":"Using the absolute position size fixes longs but reports shorts with the wrong sign.","family":"w2-currency_rounding_and_fx_conversion-fx-position-average-rate-unrealized-direction","id":"FA-62046","implementations":{"attempt":{"sha256":"e4299bd60f63cb81c36eba136df14af0b4dc4c0b6f50f9ce0d5eaece2cb7d773","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 = abs(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 unrealized-direction 1', ([[100, '1.10'], [-150, '1.00']], '1.05'),\n   [-50, '1.000000', '-10.00', '-2.50']),\n  ('regression unrealized-direction 2', ([[-30, '1.0833'], [-70, '1.0851']], '1.0800'),\n   [-100, '1.084560', '0.00', '0.46']),\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: 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: three reductions', ([[300, '1.0711'], [-100, '1.0733'], [-100, '1.0745'], [-100, '1.0719']], '1.07'),\n   [0, None, '0.64', '0.00'])],\n [('regression unrealized-direction 1', ([[100, '1.10'], [100, '1.20'], [-50, '1.30']], '1.25'),\n   [150, '1.150000', '7.50', '15.00']),\n  ('regression unrealized-direction 2', ([[50, '1.1'], [-50, '1.2'], [0, '1.3'], [20, '1.4']], '1.5'),\n   [20, '1.400000', '5.00', '2.00']),\n  ('partial repair guard 1', ([[-220, '1.1085'], [310, '1.1162'], [-140, '1.1499']], '1.1267'),\n   [-50, '1.149900', '1.34', '1.16']),\n  ('partial repair guard 2', ([[-580, '1.0680']], '1.1073'), [-580, '1.068000', '0.00', '-22.79']),\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: flip short to long', ([[-40, '1.2'], [100, '1.1']], '1.15'), [60, '1.100000', '4.00', '3.00'])],\n [('regression unrealized-direction 1', ([[-40, '1.2'], [100, '1.1']], '1.15'), [60, '1.100000', '4.00', '3.00']),\n  ('regression unrealized-direction 2', ([[80, '1.1282']], '1.0902'), [80, '1.128200', '0.00', '-3.04']),\n  ('partial repair guard 1',\n   ([[-540, '1.1190'], [-60, '1.0677'], [20, '1.1443'], [-240, '1.1212'], [0, '1.0908']], '1.0791'),\n   [-820, '1.116015', '-0.61', '30.27']),\n  ('partial repair guard 2', ([[-400, '1.1002'], [-30, '1.1375'], [0, '1.0641']], '1.1316'),\n   [-430, '1.102802', '0.00', '-12.38']),\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: 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 [('regression unrealized-direction 1', ([[480, '1.0533'], [0, '1.0736']], '1.1048'),\n   [480, '1.053300', '0.00', '24.72']),\n  ('regression unrealized-direction 2',\n   ([[340, '1.0922'], [380, '1.0595'], [0, '1.1288'], [220, '1.0703'], [220, '1.0901'], [-390, '1.1478']], '1.0752'),\n   [770, '1.076936', '27.64', '-1.34']),\n  ('partial repair guard 1',\n   ([[-450, '1.1009'], [0, '1.1001'], [230, '1.0743'], [0, '1.0884'], [-190, '1.0956'], [30, '1.0635']], '1.0627'),\n   [-380, '1.098444', '7.17', '13.58']),\n  ('partial repair guard 2',\n   ([[-40, '1.1445'], [-570, '1.0711'], [530, '1.1387'], [-450, '1.0688'], [-300, '1.1071']], '1.1211'),\n   [-830, '1.083329', '-33.28', '-31.35']),\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 unrealized-direction 1', ([[270, '1.1098'], [-40, '1.1476']], '1.0552'),\n   [230, '1.109800', '1.51', '-12.56']),\n  ('regression unrealized-direction 2', ([[-90, '1.0708'], [540, '1.1315']], '1.0885'),\n   [450, '1.131500', '-5.46', '-19.35']),\n  ('partial repair guard 1',\n   ([[-460, '1.1380'], [-260, '1.0732'], [-130, '1.1234'], [-300, '1.0815'], [210, '1.0636']], '1.0880'),\n   [-940, '1.106960', '9.11', '17.82']),\n  ('partial repair guard 2', ([[-510, '1.0855']], '1.1262'), [-510, '1.085500', '0.00', '-20.76']),\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":"211738eeb320d2000002d09976a5c2e8da931fec0200f232ad303cbe1def78b9","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 * (avg - Fraction(spot)) 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 unrealized-direction 1', ([[100, '1.10'], [-150, '1.00']], '1.05'),\n   [-50, '1.000000', '-10.00', '-2.50']),\n  ('regression unrealized-direction 2', ([[-30, '1.0833'], [-70, '1.0851']], '1.0800'),\n   [-100, '1.084560', '0.00', '0.46']),\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: 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: three reductions', ([[300, '1.0711'], [-100, '1.0733'], [-100, '1.0745'], [-100, '1.0719']], '1.07'),\n   [0, None, '0.64', '0.00'])],\n [('regression unrealized-direction 1', ([[100, '1.10'], [100, '1.20'], [-50, '1.30']], '1.25'),\n   [150, '1.150000', '7.50', '15.00']),\n  ('regression unrealized-direction 2', ([[50, '1.1'], [-50, '1.2'], [0, '1.3'], [20, '1.4']], '1.5'),\n   [20, '1.400000', '5.00', '2.00']),\n  ('partial repair guard 1', ([[-220, '1.1085'], [310, '1.1162'], [-140, '1.1499']], '1.1267'),\n   [-50, '1.149900', '1.34', '1.16']),\n  ('partial repair guard 2', ([[-580, '1.0680']], '1.1073'), [-580, '1.068000', '0.00', '-22.79']),\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: flip short to long', ([[-40, '1.2'], [100, '1.1']], '1.15'), [60, '1.100000', '4.00', '3.00'])],\n [('regression unrealized-direction 1', ([[-40, '1.2'], [100, '1.1']], '1.15'), [60, '1.100000', '4.00', '3.00']),\n  ('regression unrealized-direction 2', ([[80, '1.1282']], '1.0902'), [80, '1.128200', '0.00', '-3.04']),\n  ('partial repair guard 1',\n   ([[-540, '1.1190'], [-60, '1.0677'], [20, '1.1443'], [-240, '1.1212'], [0, '1.0908']], '1.0791'),\n   [-820, '1.116015', '-0.61', '30.27']),\n  ('partial repair guard 2', ([[-400, '1.1002'], [-30, '1.1375'], [0, '1.0641']], '1.1316'),\n   [-430, '1.102802', '0.00', '-12.38']),\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: 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 [('regression unrealized-direction 1', ([[480, '1.0533'], [0, '1.0736']], '1.1048'),\n   [480, '1.053300', '0.00', '24.72']),\n  ('regression unrealized-direction 2',\n   ([[340, '1.0922'], [380, '1.0595'], [0, '1.1288'], [220, '1.0703'], [220, '1.0901'], [-390, '1.1478']], '1.0752'),\n   [770, '1.076936', '27.64', '-1.34']),\n  ('partial repair guard 1',\n   ([[-450, '1.1009'], [0, '1.1001'], [230, '1.0743'], [0, '1.0884'], [-190, '1.0956'], [30, '1.0635']], '1.0627'),\n   [-380, '1.098444', '7.17', '13.58']),\n  ('partial repair guard 2',\n   ([[-40, '1.1445'], [-570, '1.0711'], [530, '1.1387'], [-450, '1.0688'], [-300, '1.1071']], '1.1211'),\n   [-830, '1.083329', '-33.28', '-31.35']),\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 unrealized-direction 1', ([[270, '1.1098'], [-40, '1.1476']], '1.0552'),\n   [230, '1.109800', '1.51', '-12.56']),\n  ('regression unrealized-direction 2', ([[-90, '1.0708'], [540, '1.1315']], '1.0885'),\n   [450, '1.131500', '-5.46', '-19.35']),\n  ('partial repair guard 1',\n   ([[-460, '1.1380'], [-260, '1.0732'], [-130, '1.1234'], [-300, '1.0815'], [210, '1.0636']], '1.0880'),\n   [-940, '1.106960', '9.11', '17.82']),\n  ('partial repair guard 2', ([[-510, '1.0855']], '1.1262'), [-510, '1.085500', '0.00', '-20.76']),\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":"2c9c75a2c428f331b1429a857dca33ec162f27050a9445c14c87ffd44174caf7","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 unrealized-direction 1', ([[100, '1.10'], [-150, '1.00']], '1.05'),\n   [-50, '1.000000', '-10.00', '-2.50']),\n  ('regression unrealized-direction 2', ([[-30, '1.0833'], [-70, '1.0851']], '1.0800'),\n   [-100, '1.084560', '0.00', '0.46']),\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: 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: three reductions', ([[300, '1.0711'], [-100, '1.0733'], [-100, '1.0745'], [-100, '1.0719']], '1.07'),\n   [0, None, '0.64', '0.00'])],\n [('regression unrealized-direction 1', ([[100, '1.10'], [100, '1.20'], [-50, '1.30']], '1.25'),\n   [150, '1.150000', '7.50', '15.00']),\n  ('regression unrealized-direction 2', ([[50, '1.1'], [-50, '1.2'], [0, '1.3'], [20, '1.4']], '1.5'),\n   [20, '1.400000', '5.00', '2.00']),\n  ('partial repair guard 1', ([[-220, '1.1085'], [310, '1.1162'], [-140, '1.1499']], '1.1267'),\n   [-50, '1.149900', '1.34', '1.16']),\n  ('partial repair guard 2', ([[-580, '1.0680']], '1.1073'), [-580, '1.068000', '0.00', '-22.79']),\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: flip short to long', ([[-40, '1.2'], [100, '1.1']], '1.15'), [60, '1.100000', '4.00', '3.00'])],\n [('regression unrealized-direction 1', ([[-40, '1.2'], [100, '1.1']], '1.15'), [60, '1.100000', '4.00', '3.00']),\n  ('regression unrealized-direction 2', ([[80, '1.1282']], '1.0902'), [80, '1.128200', '0.00', '-3.04']),\n  ('partial repair guard 1',\n   ([[-540, '1.1190'], [-60, '1.0677'], [20, '1.1443'], [-240, '1.1212'], [0, '1.0908']], '1.0791'),\n   [-820, '1.116015', '-0.61', '30.27']),\n  ('partial repair guard 2', ([[-400, '1.1002'], [-30, '1.1375'], [0, '1.0641']], '1.1316'),\n   [-430, '1.102802', '0.00', '-12.38']),\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: 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 [('regression unrealized-direction 1', ([[480, '1.0533'], [0, '1.0736']], '1.1048'),\n   [480, '1.053300', '0.00', '24.72']),\n  ('regression unrealized-direction 2',\n   ([[340, '1.0922'], [380, '1.0595'], [0, '1.1288'], [220, '1.0703'], [220, '1.0901'], [-390, '1.1478']], '1.0752'),\n   [770, '1.076936', '27.64', '-1.34']),\n  ('partial repair guard 1',\n   ([[-450, '1.1009'], [0, '1.1001'], [230, '1.0743'], [0, '1.0884'], [-190, '1.0956'], [30, '1.0635']], '1.0627'),\n   [-380, '1.098444', '7.17', '13.58']),\n  ('partial repair guard 2',\n   ([[-40, '1.1445'], [-570, '1.0711'], [530, '1.1387'], [-450, '1.0688'], [-300, '1.1071']], '1.1211'),\n   [-830, '1.083329', '-33.28', '-31.35']),\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 unrealized-direction 1', ([[270, '1.1098'], [-40, '1.1476']], '1.0552'),\n   [230, '1.109800', '1.51', '-12.56']),\n  ('regression unrealized-direction 2', ([[-90, '1.0708'], [540, '1.1315']], '1.0885'),\n   [450, '1.131500', '-5.46', '-19.35']),\n  ('partial repair guard 1',\n   ([[-460, '1.1380'], [-260, '1.0732'], [-130, '1.1234'], [-300, '1.0815'], [210, '1.0636']], '1.0880'),\n   [-940, '1.106960', '9.11', '17.82']),\n  ('partial repair guard 2', ([[-510, '1.0855']], '1.1262'), [-510, '1.085500', '0.00', '-20.76']),\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-unrealized-direction","generated_at":"2026-09-29T14:47:01.006397+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":"Use pos * (spot - avg), which is signed correctly for longs and shorts.","root_cause":"Unrealized is computed as pos * (avg - spot).","sha256":"1dbccc8d59d0df5b8351b04b8f900292a86399cfbb19d596163c38463828c4d9","title":"Unrealized P&L is measured as average minus spot · case 01","variant":1,"variant_policy":"Five numbered records share a model and may reuse boundary fixtures.","verification":{"attempt":{"elapsed_ms":43.54,"exit_code":1,"observations":[{"actual":[-50,"1.000000","-10.00","2.50"],"check":"regression unrealized-direction 1","expected":[-50,"1.000000","-10.00","-2.50"],"passed":false},{"actual":[-100,"1.084560","0.00","-0.46"],"check":"regression unrealized-direction 2","expected":[-100,"1.084560","0.00","0.46"],"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":[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},{"actual":[0,null,"0.64","0.00"],"check":"control: three reductions","expected":[0,null,"0.64","0.00"],"passed":true}],"passed":false,"stderr":"","stdout":"{\"observations\": [{\"check\": \"regression unrealized-direction 1\", \"actual\": [-50, \"1.000000\", \"-10.00\", \"2.50\"], \"expected\": [-50, \"1.000000\", \"-10.00\", \"-2.50\"], \"passed\": false}, {\"check\": \"regression unrealized-direction 2\", \"actual\": [-100, \"1.084560\", \"0.00\", \"-0.46\"], \"expected\": [-100, \"1.084560\", \"0.00\", \"0.46\"], \"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: 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}, {\"check\": \"control: three reductions\", \"actual\": [0, null, \"0.64\", \"0.00\"], \"expected\": [0, null, \"0.64\", \"0.00\"], \"passed\": true}], \"passed\": false}\n"},"broken":{"elapsed_ms":41.535,"exit_code":1,"observations":[{"actual":[-50,"1.000000","-10.00","2.50"],"check":"regression unrealized-direction 1","expected":[-50,"1.000000","-10.00","-2.50"],"passed":false},{"actual":[-100,"1.084560","0.00","-0.46"],"check":"regression unrealized-direction 2","expected":[-100,"1.084560","0.00","0.46"],"passed":false},{"actual":[150,"1.150000","7.50","-15.00"],"check":"control: add then reduce","expected":[150,"1.150000","7.50","15.00"],"passed":false},{"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},{"actual":[0,null,"0.64","0.00"],"check":"control: three reductions","expected":[0,null,"0.64","0.00"],"passed":true}],"passed":false,"stderr":"","stdout":"{\"observations\": [{\"check\": \"regression unrealized-direction 1\", \"actual\": [-50, \"1.000000\", \"-10.00\", \"2.50\"], \"expected\": [-50, \"1.000000\", \"-10.00\", \"-2.50\"], \"passed\": false}, {\"check\": \"regression unrealized-direction 2\", \"actual\": [-100, \"1.084560\", \"0.00\", \"-0.46\"], \"expected\": [-100, \"1.084560\", \"0.00\", \"0.46\"], \"passed\": false}, {\"check\": \"control: add then reduce\", \"actual\": [150, \"1.150000\", \"7.50\", \"-15.00\"], \"expected\": [150, \"1.150000\", \"7.50\", \"15.00\"], \"passed\": false}, {\"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}, {\"check\": \"control: three reductions\", \"actual\": [0, null, \"0.64\", \"0.00\"], \"expected\": [0, null, \"0.64\", \"0.00\"], \"passed\": true}], \"passed\": false}\n"},"fixed":{"elapsed_ms":43.241,"exit_code":0,"observations":[{"actual":[-50,"1.000000","-10.00","-2.50"],"check":"regression unrealized-direction 1","expected":[-50,"1.000000","-10.00","-2.50"],"passed":true},{"actual":[-100,"1.084560","0.00","0.46"],"check":"regression unrealized-direction 2","expected":[-100,"1.084560","0.00","0.46"],"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":[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},{"actual":[0,null,"0.64","0.00"],"check":"control: three reductions","expected":[0,null,"0.64","0.00"],"passed":true}],"passed":true,"stderr":"","stdout":"{\"observations\": [{\"check\": \"regression unrealized-direction 1\", \"actual\": [-50, \"1.000000\", \"-10.00\", \"-2.50\"], \"expected\": [-50, \"1.000000\", \"-10.00\", \"-2.50\"], \"passed\": true}, {\"check\": \"regression unrealized-direction 2\", \"actual\": [-100, \"1.084560\", \"0.00\", \"0.46\"], \"expected\": [-100, \"1.084560\", \"0.00\", \"0.46\"], \"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: 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}, {\"check\": \"control: three reductions\", \"actual\": [0, null, \"0.64\", \"0.00\"], \"expected\": [0, null, \"0.64\", \"0.00\"], \"passed\": true}], \"passed\": true}\n"}},"verified":true,"visibility":"public"}