{"abstract":"Buying back a short option at a lower premium records a loss.","category":"Options payoff and settlement","checks":8,"contract":"Inputs trades [side B/S, contracts, premium], multiplier and fee per contract. Positions may be long or short. Each trade first closes opposite-direction lots oldest first; realized P&L per matched contract is (close - open) for long lots and (open - close) for short lots, times the multiplier. Any remainder opens a new lot in the trade direction. Fees = contracts traded * fee. Work in cents; return [net position, realized, fees].","evaluation_group":"w2-options_payoff_and_settlement-fifo-option-pnl","failed_approach":"Always using open minus close inverts the long-lot result instead.","family":"w2-options_payoff_and_settlement-fifo-option-pnl-short-lot-pnl-sign","id":"FA-61661","implementations":{"attempt":{"sha256":"1b6f1a5304954e6464a758ab69b7db49969636aae60ad91e310fe6f16e091e19","source":"\"\"\"Failure Map reference implementation. Python standard library only.\"\"\"\nimport json\nimport collections\nN = 1\nobservations = []\ndef solve(trades, multiplier, fee):\n    lots = collections.deque()\n    realized = 0\n    fees = 0\n    fee_c = round(fee * 100)\n    for side, qty, price in trades:\n        p = round(price * 100)\n        sgn = 1 if side == 'B' else -1\n        fees += qty * fee_c\n        left = qty\n        while left and lots and (lots[0][0] > 0) != (sgn > 0):\n            lot = lots[0]\n            m = min(left, abs(lot[0]))\n            direction = 1 if lot[0] > 0 else -1\n            realized += (lot[1] - p) * m\n            lot[0] -= m * direction\n            left -= m\n            if lot[0] == 0:\n                lots.popleft()\n        if left:\n            lots.append([sgn * left, p])\n    pos = sum(l[0] for l in lots)\n    return [pos, realized * multiplier / 100, fees / 100]\ndef check(label, actual, expected):\n    observations.append({\"check\": label, \"actual\": actual, \"expected\": expected, \"passed\": actual == expected})\nfixtures = [[['regression short lot pnl sign 1', [[['B', 2, 4.1], ['S', 3, 0.05], ['S', 5, 0.05], ['B', 1, 0.85], ['S', 3, 0.85]], 100, 0.0], [-8, -890.0, 0.0]], ['regression short lot pnl sign 2', [[['S', 3, 4.1], ['B', 5, 1.2], ['S', 2, 0.85]], 100, 1.0], [0, 800.0, 10.0]], ['partial repair probe 1', [[['B', 5, 0.05], ['B', 1, 3.5], ['B', 5, 0.05], ['B', 2, 1.2], ['S', 3, 3.5], ['B', 5, 2.05]], 100, 0.0], [15, 1035.0, 0.0]], ['partial repair probe 2', [[['B', 1, 1.2], ['B', 3, 4.1], ['B', 3, 3.5], ['B', 1, 2.05], ['S', 5, 0.05], ['S', 5, 1.2]], 100, 0.0], [-2, -2220.0, 0.0]], ['normal control 1', [[['S', 1, 2.05], ['S', 5, 3.5], ['S', 1, 1.2], ['S', 3, 4.1], ['S', 3, 4.1]], 100, 1.0], [-13, 0.0, 13.0]], ['normal control 2', [[['B', 5, 0.85], ['B', 2, 4.1], ['B', 3, 0.85], ['B', 3, 0.85], ['B', 2, 2.05]], 10, 0.0], [15, 0.0, 0.0]], ['normal control 3', [[['S', 5, 0.05], ['S', 1, 2.05], ['B', 5, 0.05]], 10, 1.0], [-1, 0.0, 11.0]], ['normal control 4', [[['S', 2, 0.05], ['B', 2, 0.05]], 100, 0.65], [0, 0.0, 2.6]]], [['regression short lot pnl sign 1', [[['S', 3, 2.05], ['B', 5, 4.1]], 100, 0.0], [2, -615.0, 0.0]], ['regression short lot pnl sign 2', [[['S', 2, 0.05], ['B', 5, 2.05], ['S', 5, 1.2], ['S', 5, 1.2], ['S', 3, 0.85]], 10, 1.0], [-10, -65.5, 20.0]], ['partial repair probe 1', [[['B', 3, 1.2], ['B', 5, 0.85], ['S', 3, 0.05], ['S', 3, 2.05]], 100, 1.0], [2, 15.0, 14.0]], ['partial repair probe 2', [[['S', 1, 2.05], ['B', 5, 2.05], ['B', 3, 3.5], ['S', 2, 4.1]], 100, 1.0], [5, 410.0, 11.0]], ['normal control 1', [[['B', 3, 0.05], ['B', 1, 4.1]], 10, 0.65], [4, 0.0, 2.6]], ['normal control 2', [[['S', 5, 0.05], ['S', 5, 0.85], ['S', 2, 4.1], ['S', 2, 3.5]], 10, 0.65], [-14, 0.0, 9.1]], ['normal control 3', [[['B', 1, 0.05], ['B', 2, 2.05]], 100, 1.0], [3, 0.0, 3.0]], ['normal control 4', [[['B', 1, 4.1]], 100, 0.65], [1, 0.0, 0.65]]], [['regression short lot pnl sign 1', [[['B', 3, 4.1], ['S', 5, 0.05], ['S', 1, 2.05], ['S', 1, 4.1], ['B', 2, 0.85], ['B', 5, 0.05]], 100, 1.0], [3, -770.0, 17.0]], ['regression short lot pnl sign 2', [[['S', 3, 3.5], ['B', 1, 2.05], ['B', 5, 3.5], ['S', 3, 3.5], ['S', 5, 0.05]], 100, 0.0], [-5, 145.0, 0.0]], ['partial repair probe 1', [[['B', 3, 1.2], ['S', 1, 4.1], ['S', 2, 3.5]], 10, 0.0], [0, 75.0, 0.0]], ['partial repair probe 2', [[['B', 5, 3.5], ['B', 3, 2.05], ['B', 5, 0.85], ['S', 1, 3.5], ['B', 1, 4.1], ['S', 3, 0.85]], 10, 1.0], [10, -79.5, 18.0]], ['normal control 1', [[['B', 1, 0.85], ['B', 5, 0.05]], 10, 0.0], [6, 0.0, 0.0]], ['normal control 2', [[['S', 2, 0.05]], 10, 0.0], [-2, 0.0, 0.0]], ['normal control 3', [[['S', 5, 0.85], ['S', 5, 0.85], ['S', 2, 3.5], ['B', 5, 0.85], ['S', 3, 1.2], ['B', 3, 0.85]], 100, 1.0], [-7, 0.0, 23.0]], ['normal control 4', [[['B', 1, 0.85], ['B', 3, 4.1], ['B', 2, 2.05], ['B', 3, 0.85], ['B', 3, 3.5]], 10, 0.65], [12, 0.0, 7.8]]], [['regression short lot pnl sign 1', [[['B', 5, 4.1], ['S', 5, 0.85], ['S', 3, 0.05], ['S', 2, 1.2], ['B', 5, 3.5], ['B', 3, 4.1]], 10, 1.0], [3, -312.0, 23.0]], ['regression short lot pnl sign 2', [[['B', 1, 1.2], ['S', 2, 3.5], ['S', 1, 1.2], ['B', 3, 1.2]], 100, 1.0], [1, 460.0, 7.0]], ['partial repair probe 1', [[['B', 3, 0.05], ['B', 3, 0.05], ['S', 5, 2.05], ['B', 5, 3.5], ['B', 2, 3.5], ['B', 2, 0.85]], 10, 0.0], [10, 100.0, 0.0]], ['partial repair probe 2', [[['B', 1, 4.1], ['B', 1, 1.2], ['S', 2, 3.5]], 100, 0.65], [0, 170.0, 2.6]], ['normal control 1', [[['B', 5, 0.05]], 100, 0.65], [5, 0.0, 3.25]], ['normal control 2', [[['B', 5, 0.05], ['B', 1, 2.05]], 10, 0.0], [6, 0.0, 0.0]], ['normal control 3', [[['B', 5, 4.1], ['B', 2, 4.1]], 10, 0.0], [7, 0.0, 0.0]], ['normal control 4', [[['S', 5, 2.05], ['B', 3, 2.05], ['B', 5, 2.05]], 100, 0.65], [3, 0.0, 8.45]]], [['regression short lot pnl sign 1', [[['S', 2, 0.05], ['B', 3, 2.05], ['B', 5, 0.05]], 100, 1.0], [6, -400.0, 10.0]], ['regression short lot pnl sign 2', [[['S', 2, 1.2], ['B', 2, 2.05], ['S', 2, 0.85]], 100, 0.0], [-2, -170.0, 0.0]], ['partial repair probe 1', [[['S', 1, 0.05], ['B', 1, 0.05], ['B', 2, 2.05], ['S', 5, 1.2], ['S', 3, 3.5]], 10, 1.0], [-6, -17.0, 12.0]], ['partial repair probe 2', [[['B', 5, 1.2], ['S', 2, 0.85], ['S', 5, 0.85]], 10, 1.0], [-2, -17.5, 12.0]], ['normal control 1', [[['B', 5, 0.05], ['B', 1, 0.85], ['B', 3, 0.05], ['B', 2, 2.05]], 10, 0.0], [11, 0.0, 0.0]], ['normal control 2', [[['S', 5, 1.2], ['S', 5, 4.1]], 100, 0.65], [-10, 0.0, 6.5]], ['normal control 3', [[['B', 1, 0.05], ['B', 2, 1.2], ['B', 2, 0.05]], 100, 0.0], [5, 0.0, 0.0]], ['normal control 4', [[['S', 1, 4.1], ['S', 3, 4.1]], 10, 0.0], [-4, 0.0, 0.0]]]]\nfor label, args, expected in fixtures[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":"be317b9d6506d6b7778a9b5b23e982328101beec9d25444da06862ed718394d4","source":"\"\"\"Failure Map reference implementation. Python standard library only.\"\"\"\nimport json\nimport collections\nN = 1\nobservations = []\ndef solve(trades, multiplier, fee):\n    lots = collections.deque()\n    realized = 0\n    fees = 0\n    fee_c = round(fee * 100)\n    for side, qty, price in trades:\n        p = round(price * 100)\n        sgn = 1 if side == 'B' else -1\n        fees += qty * fee_c\n        left = qty\n        while left and lots and (lots[0][0] > 0) != (sgn > 0):\n            lot = lots[0]\n            m = min(left, abs(lot[0]))\n            direction = 1 if lot[0] > 0 else -1\n            realized += (p - lot[1]) * m\n            lot[0] -= m * direction\n            left -= m\n            if lot[0] == 0:\n                lots.popleft()\n        if left:\n            lots.append([sgn * left, p])\n    pos = sum(l[0] for l in lots)\n    return [pos, realized * multiplier / 100, fees / 100]\ndef check(label, actual, expected):\n    observations.append({\"check\": label, \"actual\": actual, \"expected\": expected, \"passed\": actual == expected})\nfixtures = [[['regression short lot pnl sign 1', [[['B', 2, 4.1], ['S', 3, 0.05], ['S', 5, 0.05], ['B', 1, 0.85], ['S', 3, 0.85]], 100, 0.0], [-8, -890.0, 0.0]], ['regression short lot pnl sign 2', [[['S', 3, 4.1], ['B', 5, 1.2], ['S', 2, 0.85]], 100, 1.0], [0, 800.0, 10.0]], ['partial repair probe 1', [[['B', 5, 0.05], ['B', 1, 3.5], ['B', 5, 0.05], ['B', 2, 1.2], ['S', 3, 3.5], ['B', 5, 2.05]], 100, 0.0], [15, 1035.0, 0.0]], ['partial repair probe 2', [[['B', 1, 1.2], ['B', 3, 4.1], ['B', 3, 3.5], ['B', 1, 2.05], ['S', 5, 0.05], ['S', 5, 1.2]], 100, 0.0], [-2, -2220.0, 0.0]], ['normal control 1', [[['S', 1, 2.05], ['S', 5, 3.5], ['S', 1, 1.2], ['S', 3, 4.1], ['S', 3, 4.1]], 100, 1.0], [-13, 0.0, 13.0]], ['normal control 2', [[['B', 5, 0.85], ['B', 2, 4.1], ['B', 3, 0.85], ['B', 3, 0.85], ['B', 2, 2.05]], 10, 0.0], [15, 0.0, 0.0]], ['normal control 3', [[['S', 5, 0.05], ['S', 1, 2.05], ['B', 5, 0.05]], 10, 1.0], [-1, 0.0, 11.0]], ['normal control 4', [[['S', 2, 0.05], ['B', 2, 0.05]], 100, 0.65], [0, 0.0, 2.6]]], [['regression short lot pnl sign 1', [[['S', 3, 2.05], ['B', 5, 4.1]], 100, 0.0], [2, -615.0, 0.0]], ['regression short lot pnl sign 2', [[['S', 2, 0.05], ['B', 5, 2.05], ['S', 5, 1.2], ['S', 5, 1.2], ['S', 3, 0.85]], 10, 1.0], [-10, -65.5, 20.0]], ['partial repair probe 1', [[['B', 3, 1.2], ['B', 5, 0.85], ['S', 3, 0.05], ['S', 3, 2.05]], 100, 1.0], [2, 15.0, 14.0]], ['partial repair probe 2', [[['S', 1, 2.05], ['B', 5, 2.05], ['B', 3, 3.5], ['S', 2, 4.1]], 100, 1.0], [5, 410.0, 11.0]], ['normal control 1', [[['B', 3, 0.05], ['B', 1, 4.1]], 10, 0.65], [4, 0.0, 2.6]], ['normal control 2', [[['S', 5, 0.05], ['S', 5, 0.85], ['S', 2, 4.1], ['S', 2, 3.5]], 10, 0.65], [-14, 0.0, 9.1]], ['normal control 3', [[['B', 1, 0.05], ['B', 2, 2.05]], 100, 1.0], [3, 0.0, 3.0]], ['normal control 4', [[['B', 1, 4.1]], 100, 0.65], [1, 0.0, 0.65]]], [['regression short lot pnl sign 1', [[['B', 3, 4.1], ['S', 5, 0.05], ['S', 1, 2.05], ['S', 1, 4.1], ['B', 2, 0.85], ['B', 5, 0.05]], 100, 1.0], [3, -770.0, 17.0]], ['regression short lot pnl sign 2', [[['S', 3, 3.5], ['B', 1, 2.05], ['B', 5, 3.5], ['S', 3, 3.5], ['S', 5, 0.05]], 100, 0.0], [-5, 145.0, 0.0]], ['partial repair probe 1', [[['B', 3, 1.2], ['S', 1, 4.1], ['S', 2, 3.5]], 10, 0.0], [0, 75.0, 0.0]], ['partial repair probe 2', [[['B', 5, 3.5], ['B', 3, 2.05], ['B', 5, 0.85], ['S', 1, 3.5], ['B', 1, 4.1], ['S', 3, 0.85]], 10, 1.0], [10, -79.5, 18.0]], ['normal control 1', [[['B', 1, 0.85], ['B', 5, 0.05]], 10, 0.0], [6, 0.0, 0.0]], ['normal control 2', [[['S', 2, 0.05]], 10, 0.0], [-2, 0.0, 0.0]], ['normal control 3', [[['S', 5, 0.85], ['S', 5, 0.85], ['S', 2, 3.5], ['B', 5, 0.85], ['S', 3, 1.2], ['B', 3, 0.85]], 100, 1.0], [-7, 0.0, 23.0]], ['normal control 4', [[['B', 1, 0.85], ['B', 3, 4.1], ['B', 2, 2.05], ['B', 3, 0.85], ['B', 3, 3.5]], 10, 0.65], [12, 0.0, 7.8]]], [['regression short lot pnl sign 1', [[['B', 5, 4.1], ['S', 5, 0.85], ['S', 3, 0.05], ['S', 2, 1.2], ['B', 5, 3.5], ['B', 3, 4.1]], 10, 1.0], [3, -312.0, 23.0]], ['regression short lot pnl sign 2', [[['B', 1, 1.2], ['S', 2, 3.5], ['S', 1, 1.2], ['B', 3, 1.2]], 100, 1.0], [1, 460.0, 7.0]], ['partial repair probe 1', [[['B', 3, 0.05], ['B', 3, 0.05], ['S', 5, 2.05], ['B', 5, 3.5], ['B', 2, 3.5], ['B', 2, 0.85]], 10, 0.0], [10, 100.0, 0.0]], ['partial repair probe 2', [[['B', 1, 4.1], ['B', 1, 1.2], ['S', 2, 3.5]], 100, 0.65], [0, 170.0, 2.6]], ['normal control 1', [[['B', 5, 0.05]], 100, 0.65], [5, 0.0, 3.25]], ['normal control 2', [[['B', 5, 0.05], ['B', 1, 2.05]], 10, 0.0], [6, 0.0, 0.0]], ['normal control 3', [[['B', 5, 4.1], ['B', 2, 4.1]], 10, 0.0], [7, 0.0, 0.0]], ['normal control 4', [[['S', 5, 2.05], ['B', 3, 2.05], ['B', 5, 2.05]], 100, 0.65], [3, 0.0, 8.45]]], [['regression short lot pnl sign 1', [[['S', 2, 0.05], ['B', 3, 2.05], ['B', 5, 0.05]], 100, 1.0], [6, -400.0, 10.0]], ['regression short lot pnl sign 2', [[['S', 2, 1.2], ['B', 2, 2.05], ['S', 2, 0.85]], 100, 0.0], [-2, -170.0, 0.0]], ['partial repair probe 1', [[['S', 1, 0.05], ['B', 1, 0.05], ['B', 2, 2.05], ['S', 5, 1.2], ['S', 3, 3.5]], 10, 1.0], [-6, -17.0, 12.0]], ['partial repair probe 2', [[['B', 5, 1.2], ['S', 2, 0.85], ['S', 5, 0.85]], 10, 1.0], [-2, -17.5, 12.0]], ['normal control 1', [[['B', 5, 0.05], ['B', 1, 0.85], ['B', 3, 0.05], ['B', 2, 2.05]], 10, 0.0], [11, 0.0, 0.0]], ['normal control 2', [[['S', 5, 1.2], ['S', 5, 4.1]], 100, 0.65], [-10, 0.0, 6.5]], ['normal control 3', [[['B', 1, 0.05], ['B', 2, 1.2], ['B', 2, 0.05]], 100, 0.0], [5, 0.0, 0.0]], ['normal control 4', [[['S', 1, 4.1], ['S', 3, 4.1]], 10, 0.0], [-4, 0.0, 0.0]]]]\nfor label, args, expected in fixtures[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":"039146e25a07a178da680fb76755c25551bfc4ab9b59d77cfa9c9d71bac92717","source":"\"\"\"Failure Map reference implementation. Python standard library only.\"\"\"\nimport json\nimport collections\nN = 1\nobservations = []\ndef solve(trades, multiplier, fee):\n    lots = collections.deque()\n    realized = 0\n    fees = 0\n    fee_c = round(fee * 100)\n    for side, qty, price in trades:\n        p = round(price * 100)\n        sgn = 1 if side == 'B' else -1\n        fees += qty * fee_c\n        left = qty\n        while left and lots and (lots[0][0] > 0) != (sgn > 0):\n            lot = lots[0]\n            m = min(left, abs(lot[0]))\n            direction = 1 if lot[0] > 0 else -1\n            realized += (p - lot[1]) * m * direction\n            lot[0] -= m * direction\n            left -= m\n            if lot[0] == 0:\n                lots.popleft()\n        if left:\n            lots.append([sgn * left, p])\n    pos = sum(l[0] for l in lots)\n    return [pos, realized * multiplier / 100, fees / 100]\ndef check(label, actual, expected):\n    observations.append({\"check\": label, \"actual\": actual, \"expected\": expected, \"passed\": actual == expected})\nfixtures = [[['regression short lot pnl sign 1', [[['B', 2, 4.1], ['S', 3, 0.05], ['S', 5, 0.05], ['B', 1, 0.85], ['S', 3, 0.85]], 100, 0.0], [-8, -890.0, 0.0]], ['regression short lot pnl sign 2', [[['S', 3, 4.1], ['B', 5, 1.2], ['S', 2, 0.85]], 100, 1.0], [0, 800.0, 10.0]], ['partial repair probe 1', [[['B', 5, 0.05], ['B', 1, 3.5], ['B', 5, 0.05], ['B', 2, 1.2], ['S', 3, 3.5], ['B', 5, 2.05]], 100, 0.0], [15, 1035.0, 0.0]], ['partial repair probe 2', [[['B', 1, 1.2], ['B', 3, 4.1], ['B', 3, 3.5], ['B', 1, 2.05], ['S', 5, 0.05], ['S', 5, 1.2]], 100, 0.0], [-2, -2220.0, 0.0]], ['normal control 1', [[['S', 1, 2.05], ['S', 5, 3.5], ['S', 1, 1.2], ['S', 3, 4.1], ['S', 3, 4.1]], 100, 1.0], [-13, 0.0, 13.0]], ['normal control 2', [[['B', 5, 0.85], ['B', 2, 4.1], ['B', 3, 0.85], ['B', 3, 0.85], ['B', 2, 2.05]], 10, 0.0], [15, 0.0, 0.0]], ['normal control 3', [[['S', 5, 0.05], ['S', 1, 2.05], ['B', 5, 0.05]], 10, 1.0], [-1, 0.0, 11.0]], ['normal control 4', [[['S', 2, 0.05], ['B', 2, 0.05]], 100, 0.65], [0, 0.0, 2.6]]], [['regression short lot pnl sign 1', [[['S', 3, 2.05], ['B', 5, 4.1]], 100, 0.0], [2, -615.0, 0.0]], ['regression short lot pnl sign 2', [[['S', 2, 0.05], ['B', 5, 2.05], ['S', 5, 1.2], ['S', 5, 1.2], ['S', 3, 0.85]], 10, 1.0], [-10, -65.5, 20.0]], ['partial repair probe 1', [[['B', 3, 1.2], ['B', 5, 0.85], ['S', 3, 0.05], ['S', 3, 2.05]], 100, 1.0], [2, 15.0, 14.0]], ['partial repair probe 2', [[['S', 1, 2.05], ['B', 5, 2.05], ['B', 3, 3.5], ['S', 2, 4.1]], 100, 1.0], [5, 410.0, 11.0]], ['normal control 1', [[['B', 3, 0.05], ['B', 1, 4.1]], 10, 0.65], [4, 0.0, 2.6]], ['normal control 2', [[['S', 5, 0.05], ['S', 5, 0.85], ['S', 2, 4.1], ['S', 2, 3.5]], 10, 0.65], [-14, 0.0, 9.1]], ['normal control 3', [[['B', 1, 0.05], ['B', 2, 2.05]], 100, 1.0], [3, 0.0, 3.0]], ['normal control 4', [[['B', 1, 4.1]], 100, 0.65], [1, 0.0, 0.65]]], [['regression short lot pnl sign 1', [[['B', 3, 4.1], ['S', 5, 0.05], ['S', 1, 2.05], ['S', 1, 4.1], ['B', 2, 0.85], ['B', 5, 0.05]], 100, 1.0], [3, -770.0, 17.0]], ['regression short lot pnl sign 2', [[['S', 3, 3.5], ['B', 1, 2.05], ['B', 5, 3.5], ['S', 3, 3.5], ['S', 5, 0.05]], 100, 0.0], [-5, 145.0, 0.0]], ['partial repair probe 1', [[['B', 3, 1.2], ['S', 1, 4.1], ['S', 2, 3.5]], 10, 0.0], [0, 75.0, 0.0]], ['partial repair probe 2', [[['B', 5, 3.5], ['B', 3, 2.05], ['B', 5, 0.85], ['S', 1, 3.5], ['B', 1, 4.1], ['S', 3, 0.85]], 10, 1.0], [10, -79.5, 18.0]], ['normal control 1', [[['B', 1, 0.85], ['B', 5, 0.05]], 10, 0.0], [6, 0.0, 0.0]], ['normal control 2', [[['S', 2, 0.05]], 10, 0.0], [-2, 0.0, 0.0]], ['normal control 3', [[['S', 5, 0.85], ['S', 5, 0.85], ['S', 2, 3.5], ['B', 5, 0.85], ['S', 3, 1.2], ['B', 3, 0.85]], 100, 1.0], [-7, 0.0, 23.0]], ['normal control 4', [[['B', 1, 0.85], ['B', 3, 4.1], ['B', 2, 2.05], ['B', 3, 0.85], ['B', 3, 3.5]], 10, 0.65], [12, 0.0, 7.8]]], [['regression short lot pnl sign 1', [[['B', 5, 4.1], ['S', 5, 0.85], ['S', 3, 0.05], ['S', 2, 1.2], ['B', 5, 3.5], ['B', 3, 4.1]], 10, 1.0], [3, -312.0, 23.0]], ['regression short lot pnl sign 2', [[['B', 1, 1.2], ['S', 2, 3.5], ['S', 1, 1.2], ['B', 3, 1.2]], 100, 1.0], [1, 460.0, 7.0]], ['partial repair probe 1', [[['B', 3, 0.05], ['B', 3, 0.05], ['S', 5, 2.05], ['B', 5, 3.5], ['B', 2, 3.5], ['B', 2, 0.85]], 10, 0.0], [10, 100.0, 0.0]], ['partial repair probe 2', [[['B', 1, 4.1], ['B', 1, 1.2], ['S', 2, 3.5]], 100, 0.65], [0, 170.0, 2.6]], ['normal control 1', [[['B', 5, 0.05]], 100, 0.65], [5, 0.0, 3.25]], ['normal control 2', [[['B', 5, 0.05], ['B', 1, 2.05]], 10, 0.0], [6, 0.0, 0.0]], ['normal control 3', [[['B', 5, 4.1], ['B', 2, 4.1]], 10, 0.0], [7, 0.0, 0.0]], ['normal control 4', [[['S', 5, 2.05], ['B', 3, 2.05], ['B', 5, 2.05]], 100, 0.65], [3, 0.0, 8.45]]], [['regression short lot pnl sign 1', [[['S', 2, 0.05], ['B', 3, 2.05], ['B', 5, 0.05]], 100, 1.0], [6, -400.0, 10.0]], ['regression short lot pnl sign 2', [[['S', 2, 1.2], ['B', 2, 2.05], ['S', 2, 0.85]], 100, 0.0], [-2, -170.0, 0.0]], ['partial repair probe 1', [[['S', 1, 0.05], ['B', 1, 0.05], ['B', 2, 2.05], ['S', 5, 1.2], ['S', 3, 3.5]], 10, 1.0], [-6, -17.0, 12.0]], ['partial repair probe 2', [[['B', 5, 1.2], ['S', 2, 0.85], ['S', 5, 0.85]], 10, 1.0], [-2, -17.5, 12.0]], ['normal control 1', [[['B', 5, 0.05], ['B', 1, 0.85], ['B', 3, 0.05], ['B', 2, 2.05]], 10, 0.0], [11, 0.0, 0.0]], ['normal control 2', [[['S', 5, 1.2], ['S', 5, 4.1]], 100, 0.65], [-10, 0.0, 6.5]], ['normal control 3', [[['B', 1, 0.05], ['B', 2, 1.2], ['B', 2, 0.05]], 100, 0.0], [5, 0.0, 0.0]], ['normal control 4', [[['S', 1, 4.1], ['S', 3, 4.1]], 10, 0.0], [-4, 0.0, 0.0]]]]\nfor label, args, expected in fixtures[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 toy contract stated explicitly in the contract field; no claim of conformance to any exchange or clearing rulebook. 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-options_payoff_and_settlement-fifo-option-pnl-short-lot-pnl-sign","generated_at":"2026-09-29T14:46:57.375691+00:00","license":"CC0-1.0","python":"3.12.14","seed":1,"split":"open-access"},"relevance":"Option expiry, exercise and settlement engines move cash and shares; a wrong branch misstates obligations.","repair":"Multiply by +1 for long lots and -1 for short lots.","root_cause":"The realized amount ignores the direction of the lot being closed.","sha256":"1edc10605d518cd2834173b6c4b1d26259d44d2a36b324767f66556d7ee9002f","title":"FIFO realized P&L for option trades: closing a short lot books the price change with the long sign · case 01","variant":1,"variant_policy":"Five numbered records share a model and may reuse boundary fixtures.","verification":{"attempt":{"elapsed_ms":42.361,"exit_code":1,"observations":[{"actual":[-8,730.0,0.0],"check":"regression short lot pnl sign 1","expected":[-8,-890.0,0.0],"passed":false},{"actual":[0,940.0,10.0],"check":"regression short lot pnl sign 2","expected":[0,800.0,10.0],"passed":false},{"actual":[15,-1035.0,0.0],"check":"partial repair probe 1","expected":[15,1035.0,0.0],"passed":false},{"actual":[-2,2220.0,0.0],"check":"partial repair probe 2","expected":[-2,-2220.0,0.0],"passed":false},{"actual":[-13,0.0,13.0],"check":"normal control 1","expected":[-13,0.0,13.0],"passed":true},{"actual":[15,0.0,0.0],"check":"normal control 2","expected":[15,0.0,0.0],"passed":true},{"actual":[-1,0.0,11.0],"check":"normal control 3","expected":[-1,0.0,11.0],"passed":true},{"actual":[0,0.0,2.6],"check":"normal control 4","expected":[0,0.0,2.6],"passed":true}],"passed":false,"stderr":"","stdout":"{\"observations\": [{\"check\": \"regression short lot pnl sign 1\", \"actual\": [-8, 730.0, 0.0], \"expected\": [-8, -890.0, 0.0], \"passed\": false}, {\"check\": \"regression short lot pnl sign 2\", \"actual\": [0, 940.0, 10.0], \"expected\": [0, 800.0, 10.0], \"passed\": false}, {\"check\": \"partial repair probe 1\", \"actual\": [15, -1035.0, 0.0], \"expected\": [15, 1035.0, 0.0], \"passed\": false}, {\"check\": \"partial repair probe 2\", \"actual\": [-2, 2220.0, 0.0], \"expected\": [-2, -2220.0, 0.0], \"passed\": false}, {\"check\": \"normal control 1\", \"actual\": [-13, 0.0, 13.0], \"expected\": [-13, 0.0, 13.0], \"passed\": true}, {\"check\": \"normal control 2\", \"actual\": [15, 0.0, 0.0], \"expected\": [15, 0.0, 0.0], \"passed\": true}, {\"check\": \"normal control 3\", \"actual\": [-1, 0.0, 11.0], \"expected\": [-1, 0.0, 11.0], \"passed\": true}, {\"check\": \"normal control 4\", \"actual\": [0, 0.0, 2.6], \"expected\": [0, 0.0, 2.6], \"passed\": true}], \"passed\": false}\n"},"broken":{"elapsed_ms":40.57,"exit_code":1,"observations":[{"actual":[-8,-730.0,0.0],"check":"regression short lot pnl sign 1","expected":[-8,-890.0,0.0],"passed":false},{"actual":[0,-940.0,10.0],"check":"regression short lot pnl sign 2","expected":[0,800.0,10.0],"passed":false},{"actual":[15,1035.0,0.0],"check":"partial repair probe 1","expected":[15,1035.0,0.0],"passed":true},{"actual":[-2,-2220.0,0.0],"check":"partial repair probe 2","expected":[-2,-2220.0,0.0],"passed":true},{"actual":[-13,0.0,13.0],"check":"normal control 1","expected":[-13,0.0,13.0],"passed":true},{"actual":[15,0.0,0.0],"check":"normal control 2","expected":[15,0.0,0.0],"passed":true},{"actual":[-1,0.0,11.0],"check":"normal control 3","expected":[-1,0.0,11.0],"passed":true},{"actual":[0,0.0,2.6],"check":"normal control 4","expected":[0,0.0,2.6],"passed":true}],"passed":false,"stderr":"","stdout":"{\"observations\": [{\"check\": \"regression short lot pnl sign 1\", \"actual\": [-8, -730.0, 0.0], \"expected\": [-8, -890.0, 0.0], \"passed\": false}, {\"check\": \"regression short lot pnl sign 2\", \"actual\": [0, -940.0, 10.0], \"expected\": [0, 800.0, 10.0], \"passed\": false}, {\"check\": \"partial repair probe 1\", \"actual\": [15, 1035.0, 0.0], \"expected\": [15, 1035.0, 0.0], \"passed\": true}, {\"check\": \"partial repair probe 2\", \"actual\": [-2, -2220.0, 0.0], \"expected\": [-2, -2220.0, 0.0], \"passed\": true}, {\"check\": \"normal control 1\", \"actual\": [-13, 0.0, 13.0], \"expected\": [-13, 0.0, 13.0], \"passed\": true}, {\"check\": \"normal control 2\", \"actual\": [15, 0.0, 0.0], \"expected\": [15, 0.0, 0.0], \"passed\": true}, {\"check\": \"normal control 3\", \"actual\": [-1, 0.0, 11.0], \"expected\": [-1, 0.0, 11.0], \"passed\": true}, {\"check\": \"normal control 4\", \"actual\": [0, 0.0, 2.6], \"expected\": [0, 0.0, 2.6], \"passed\": true}], \"passed\": false}\n"},"fixed":{"elapsed_ms":41.664,"exit_code":0,"observations":[{"actual":[-8,-890.0,0.0],"check":"regression short lot pnl sign 1","expected":[-8,-890.0,0.0],"passed":true},{"actual":[0,800.0,10.0],"check":"regression short lot pnl sign 2","expected":[0,800.0,10.0],"passed":true},{"actual":[15,1035.0,0.0],"check":"partial repair probe 1","expected":[15,1035.0,0.0],"passed":true},{"actual":[-2,-2220.0,0.0],"check":"partial repair probe 2","expected":[-2,-2220.0,0.0],"passed":true},{"actual":[-13,0.0,13.0],"check":"normal control 1","expected":[-13,0.0,13.0],"passed":true},{"actual":[15,0.0,0.0],"check":"normal control 2","expected":[15,0.0,0.0],"passed":true},{"actual":[-1,0.0,11.0],"check":"normal control 3","expected":[-1,0.0,11.0],"passed":true},{"actual":[0,0.0,2.6],"check":"normal control 4","expected":[0,0.0,2.6],"passed":true}],"passed":true,"stderr":"","stdout":"{\"observations\": [{\"check\": \"regression short lot pnl sign 1\", \"actual\": [-8, -890.0, 0.0], \"expected\": [-8, -890.0, 0.0], \"passed\": true}, {\"check\": \"regression short lot pnl sign 2\", \"actual\": [0, 800.0, 10.0], \"expected\": [0, 800.0, 10.0], \"passed\": true}, {\"check\": \"partial repair probe 1\", \"actual\": [15, 1035.0, 0.0], \"expected\": [15, 1035.0, 0.0], \"passed\": true}, {\"check\": \"partial repair probe 2\", \"actual\": [-2, -2220.0, 0.0], \"expected\": [-2, -2220.0, 0.0], \"passed\": true}, {\"check\": \"normal control 1\", \"actual\": [-13, 0.0, 13.0], \"expected\": [-13, 0.0, 13.0], \"passed\": true}, {\"check\": \"normal control 2\", \"actual\": [15, 0.0, 0.0], \"expected\": [15, 0.0, 0.0], \"passed\": true}, {\"check\": \"normal control 3\", \"actual\": [-1, 0.0, 11.0], \"expected\": [-1, 0.0, 11.0], \"passed\": true}, {\"check\": \"normal control 4\", \"actual\": [0, 0.0, 2.6], \"expected\": [0, 0.0, 2.6], \"passed\": true}], \"passed\": true}\n"}},"verified":true,"visibility":"public"}