FA-61671 / Options payoff and settlement / Open access
FIFO realized P&L for option trades: the excess of a flipping trade is dropped · case 01
Selling more than the long position closes it but never opens the short.
ROOT CAUSE
A new lot is opened only when nothing was matched.
VERIFIED REPAIR
Open a lot for any unmatched remainder in the trade direction.
Unsuccessful approach: Opening the remainder without its sign turns a flip to short into a long lot.
Case 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].
Why this case matters
Option expiry, exercise and settlement engines move cash and shares; a wrong branch misstates obligations.
1 / The failure
Exit 1"""Failure Map reference implementation. Python standard library only."""
import json
import collections
N = 1
observations = []
def solve(trades, multiplier, fee):
lots = collections.deque()
realized = 0
fees = 0
fee_c = round(fee * 100)
for side, qty, price in trades:
p = round(price * 100)
sgn = 1 if side == 'B' else -1
fees += qty * fee_c
left = qty
while left and lots and (lots[0][0] > 0) != (sgn > 0):
lot = lots[0]
m = min(left, abs(lot[0]))
direction = 1 if lot[0] > 0 else -1
realized += (p - lot[1]) * m * direction
lot[0] -= m * direction
left -= m
if lot[0] == 0:
lots.popleft()
if left == qty:
lots.append([sgn * left, p])
pos = sum(l[0] for l in lots)
return [pos, realized * multiplier / 100, fees / 100]
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression position flip remainder 1', [[['B', 1, 1.2], ['B', 5, 0.05], ['S', 5, 0.85], ['B', 2, 4.1], ['S', 5, 4.1], ['S', 5, 0.05]], 100, 0.0], [-7, 690.0, 0.0]], ['regression position flip remainder 2', [[['B', 3, 2.05], ['S', 5, 0.85], ['S', 3, 4.1], ['S', 1, 0.05], ['B', 5, 0.05]], 100, 0.0], [-1, 1015.0, 0.0]], ['partial repair probe 1', [[['S', 1, 2.05], ['B', 1, 0.05]], 10, 0.0], [0, 20.0, 0.0]], ['partial repair probe 2', [[['S', 3, 2.05]], 100, 0.65], [-3, 0.0, 1.95]], ['normal control 1', [[['B', 3, 3.5], ['B', 3, 3.5], ['S', 2, 0.85]], 100, 0.0], [4, -530.0, 0.0]], ['normal control 2', [[['B', 1, 0.05], ['B', 2, 4.1], ['S', 3, 0.05]], 10, 0.65], [0, -81.0, 3.9]], ['normal control 3', [[['B', 2, 3.5]], 100, 0.0], [2, 0.0, 0.0]], ['normal control 4', [[['B', 5, 2.05], ['S', 5, 0.05], ['B', 3, 0.05], ['B', 3, 0.05], ['S', 3, 3.5]], 10, 1.0], [3, 3.5, 19.0]]], [['regression position flip remainder 1', [[['B', 3, 1.2], ['B', 1, 4.1], ['S', 2, 3.5], ['B', 3, 4.1], ['S', 2, 2.05], ['S', 5, 0.05]], 100, 0.0], [-2, -875.0, 0.0]], ['regression position flip remainder 2', [[['B', 2, 0.85], ['S', 1, 3.5], ['B', 2, 1.2], ['S', 2, 0.85], ['S', 2, 3.5]], 10, 0.65], [-1, 46.0, 5.85]], ['partial repair probe 1', [[['S', 5, 0.85], ['S', 2, 0.05], ['B', 2, 0.05], ['B', 5, 2.05], ['B', 5, 1.2], ['B', 5, 0.05]], 10, 1.0], [10, -60.0, 24.0]], ['partial repair probe 2', [[['S', 3, 1.2], ['S', 3, 2.05], ['B', 3, 0.05], ['S', 3, 1.2]], 100, 1.0], [-6, 345.0, 12.0]], ['normal control 1', [[['B', 3, 4.1], ['B', 2, 0.85]], 10, 0.0], [5, 0.0, 0.0]], ['normal control 2', [[['B', 5, 2.05], ['B', 2, 2.05]], 10, 0.0], [7, 0.0, 0.0]], ['normal control 3', [[['B', 1, 0.05]], 100, 0.65], [1, 0.0, 0.65]], ['normal control 4', [[['B', 2, 4.1], ['S', 1, 1.2], ['S', 1, 0.05], ['B', 2, 2.05]], 100, 0.65], [2, -695.0, 3.9]]], [['regression position flip remainder 1', [[['S', 2, 3.5], ['B', 5, 0.85], ['B', 5, 3.5], ['S', 5, 3.5]], 100, 1.0], [3, 1325.0, 17.0]], ['regression position flip remainder 2', [[['S', 2, 3.5], ['B', 2, 2.05], ['B', 1, 2.05], ['S', 5, 0.05], ['B', 2, 3.5], ['S', 3, 0.05]], 100, 0.0], [-5, -600.0, 0.0]], ['partial repair probe 1', [[['S', 2, 2.05]], 10, 1.0], [-2, 0.0, 2.0]], ['partial repair probe 2', [[['S', 1, 0.05]], 10, 1.0], [-1, 0.0, 1.0]], ['normal control 1', [[['B', 2, 1.2], ['B', 2, 3.5], ['S', 1, 2.05], ['B', 5, 2.05], ['S', 3, 0.05]], 100, 0.0], [5, -720.0, 0.0]], ['normal control 2', [[['B', 1, 0.85], ['B', 5, 1.2], ['S', 3, 3.5], ['B', 1, 3.5]], 100, 0.65], [4, 725.0, 6.5]], ['normal control 3', [[['B', 1, 0.85], ['B', 2, 2.05], ['S', 2, 3.5], ['B', 3, 1.2], ['B', 5, 0.85]], 10, 1.0], [9, 41.0, 13.0]], ['normal control 4', [[['B', 3, 1.2]], 100, 0.65], [3, 0.0, 1.95]]], [['regression position flip remainder 1', [[['B', 2, 4.1], ['S', 3, 2.05], ['B', 2, 2.05]], 100, 0.65], [1, -410.0, 4.55]], ['regression position flip remainder 2', [[['S', 2, 2.05], ['B', 1, 2.05], ['S', 1, 2.05], ['B', 3, 1.2], ['S', 2, 1.2]], 100, 0.0], [-1, 170.0, 0.0]], ['partial repair probe 1', [[['S', 1, 1.2], ['S', 2, 2.05], ['S', 1, 0.85], ['S', 1, 0.05], ['B', 1, 4.1]], 100, 0.0], [-4, -290.0, 0.0]], ['partial repair probe 2', [[['S', 3, 0.05], ['S', 1, 3.5]], 10, 0.65], [-4, 0.0, 2.6]], ['normal control 1', [[['B', 3, 0.85], ['S', 3, 2.05], ['B', 2, 3.5]], 10, 0.65], [2, 36.0, 5.2]], ['normal control 2', [[['B', 5, 3.5], ['S', 5, 3.5]], 100, 0.0], [0, 0.0, 0.0]], ['normal control 3', [[['B', 3, 3.5], ['B', 2, 3.5], ['B', 2, 1.2], ['S', 3, 2.05]], 10, 0.65], [4, -43.5, 6.5]], ['normal control 4', [[['B', 5, 0.85], ['S', 1, 0.85], ['S', 1, 2.05], ['S', 3, 0.05], ['B', 1, 2.05]], 10, 0.65], [1, -12.0, 7.15]]], [['regression position flip remainder 1', [[['B', 2, 1.2], ['S', 3, 0.85]], 10, 1.0], [-1, -7.0, 5.0]], ['regression position flip remainder 2', [[['B', 1, 0.05], ['S', 3, 4.1]], 10, 1.0], [-2, 40.5, 4.0]], ['partial repair probe 1', [[['S', 3, 3.5], ['S', 1, 2.05], ['S', 3, 0.05], ['S', 2, 1.2], ['B', 1, 0.85]], 100, 0.65], [-8, 265.0, 6.5]], ['partial repair probe 2', [[['S', 1, 4.1]], 10, 0.65], [-1, 0.0, 0.65]], ['normal control 1', [[['B', 1, 4.1]], 10, 0.0], [1, 0.0, 0.0]], ['normal control 2', [[['B', 3, 0.05], ['S', 1, 4.1], ['B', 2, 2.05], ['B', 5, 4.1]], 10, 0.0], [9, 40.5, 0.0]], ['normal control 3', [[['B', 5, 4.1], ['B', 2, 1.2], ['B', 5, 3.5], ['S', 2, 0.05]], 10, 0.0], [10, -81.0, 0.0]], ['normal control 4', [[['B', 2, 2.05]], 10, 0.65], [2, 0.0, 1.3]]]]
for label, args, expected in fixtures[N-1]:
check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
| Boundary fixture | Actual | Expected | Outcome |
|---|---|---|---|
| regression position flip remainder 1 | [-5, 690.0, 0.0] | [-7, 690.0, 0.0] | Failed |
| regression position flip remainder 2 | [0, 855.0, 0.0] | [-1, 1015.0, 0.0] | Failed |
| partial repair probe 1 | [0, 20.0, 0.0] | [0, 20.0, 0.0] | Passed |
| partial repair probe 2 | [-3, 0.0, 1.95] | [-3, 0.0, 1.95] | Passed |
| normal control 1 | [4, -530.0, 0.0] | [4, -530.0, 0.0] | Passed |
| normal control 2 | [0, -81.0, 3.9] | [0, -81.0, 3.9] | Passed |
| normal control 3 | [2, 0.0, 0.0] | [2, 0.0, 0.0] | Passed |
| normal control 4 | [3, 3.5, 19.0] | [3, 3.5, 19.0] | Passed |
SHA-256 / e648b2ff7aa0789d2edb780b7b8e49227405f2453541c3e9dfe7fcdf00d36ce0
2 / The unsuccessful fix
Exit 1"""Failure Map reference implementation. Python standard library only."""
import json
import collections
N = 1
observations = []
def solve(trades, multiplier, fee):
lots = collections.deque()
realized = 0
fees = 0
fee_c = round(fee * 100)
for side, qty, price in trades:
p = round(price * 100)
sgn = 1 if side == 'B' else -1
fees += qty * fee_c
left = qty
while left and lots and (lots[0][0] > 0) != (sgn > 0):
lot = lots[0]
m = min(left, abs(lot[0]))
direction = 1 if lot[0] > 0 else -1
realized += (p - lot[1]) * m * direction
lot[0] -= m * direction
left -= m
if lot[0] == 0:
lots.popleft()
if left:
lots.append([left, p])
pos = sum(l[0] for l in lots)
return [pos, realized * multiplier / 100, fees / 100]
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression position flip remainder 1', [[['B', 1, 1.2], ['B', 5, 0.05], ['S', 5, 0.85], ['B', 2, 4.1], ['S', 5, 4.1], ['S', 5, 0.05]], 100, 0.0], [-7, 690.0, 0.0]], ['regression position flip remainder 2', [[['B', 3, 2.05], ['S', 5, 0.85], ['S', 3, 4.1], ['S', 1, 0.05], ['B', 5, 0.05]], 100, 0.0], [-1, 1015.0, 0.0]], ['partial repair probe 1', [[['S', 1, 2.05], ['B', 1, 0.05]], 10, 0.0], [0, 20.0, 0.0]], ['partial repair probe 2', [[['S', 3, 2.05]], 100, 0.65], [-3, 0.0, 1.95]], ['normal control 1', [[['B', 3, 3.5], ['B', 3, 3.5], ['S', 2, 0.85]], 100, 0.0], [4, -530.0, 0.0]], ['normal control 2', [[['B', 1, 0.05], ['B', 2, 4.1], ['S', 3, 0.05]], 10, 0.65], [0, -81.0, 3.9]], ['normal control 3', [[['B', 2, 3.5]], 100, 0.0], [2, 0.0, 0.0]], ['normal control 4', [[['B', 5, 2.05], ['S', 5, 0.05], ['B', 3, 0.05], ['B', 3, 0.05], ['S', 3, 3.5]], 10, 1.0], [3, 3.5, 19.0]]], [['regression position flip remainder 1', [[['B', 3, 1.2], ['B', 1, 4.1], ['S', 2, 3.5], ['B', 3, 4.1], ['S', 2, 2.05], ['S', 5, 0.05]], 100, 0.0], [-2, -875.0, 0.0]], ['regression position flip remainder 2', [[['B', 2, 0.85], ['S', 1, 3.5], ['B', 2, 1.2], ['S', 2, 0.85], ['S', 2, 3.5]], 10, 0.65], [-1, 46.0, 5.85]], ['partial repair probe 1', [[['S', 5, 0.85], ['S', 2, 0.05], ['B', 2, 0.05], ['B', 5, 2.05], ['B', 5, 1.2], ['B', 5, 0.05]], 10, 1.0], [10, -60.0, 24.0]], ['partial repair probe 2', [[['S', 3, 1.2], ['S', 3, 2.05], ['B', 3, 0.05], ['S', 3, 1.2]], 100, 1.0], [-6, 345.0, 12.0]], ['normal control 1', [[['B', 3, 4.1], ['B', 2, 0.85]], 10, 0.0], [5, 0.0, 0.0]], ['normal control 2', [[['B', 5, 2.05], ['B', 2, 2.05]], 10, 0.0], [7, 0.0, 0.0]], ['normal control 3', [[['B', 1, 0.05]], 100, 0.65], [1, 0.0, 0.65]], ['normal control 4', [[['B', 2, 4.1], ['S', 1, 1.2], ['S', 1, 0.05], ['B', 2, 2.05]], 100, 0.65], [2, -695.0, 3.9]]], [['regression position flip remainder 1', [[['S', 2, 3.5], ['B', 5, 0.85], ['B', 5, 3.5], ['S', 5, 3.5]], 100, 1.0], [3, 1325.0, 17.0]], ['regression position flip remainder 2', [[['S', 2, 3.5], ['B', 2, 2.05], ['B', 1, 2.05], ['S', 5, 0.05], ['B', 2, 3.5], ['S', 3, 0.05]], 100, 0.0], [-5, -600.0, 0.0]], ['partial repair probe 1', [[['S', 2, 2.05]], 10, 1.0], [-2, 0.0, 2.0]], ['partial repair probe 2', [[['S', 1, 0.05]], 10, 1.0], [-1, 0.0, 1.0]], ['normal control 1', [[['B', 2, 1.2], ['B', 2, 3.5], ['S', 1, 2.05], ['B', 5, 2.05], ['S', 3, 0.05]], 100, 0.0], [5, -720.0, 0.0]], ['normal control 2', [[['B', 1, 0.85], ['B', 5, 1.2], ['S', 3, 3.5], ['B', 1, 3.5]], 100, 0.65], [4, 725.0, 6.5]], ['normal control 3', [[['B', 1, 0.85], ['B', 2, 2.05], ['S', 2, 3.5], ['B', 3, 1.2], ['B', 5, 0.85]], 10, 1.0], [9, 41.0, 13.0]], ['normal control 4', [[['B', 3, 1.2]], 100, 0.65], [3, 0.0, 1.95]]], [['regression position flip remainder 1', [[['B', 2, 4.1], ['S', 3, 2.05], ['B', 2, 2.05]], 100, 0.65], [1, -410.0, 4.55]], ['regression position flip remainder 2', [[['S', 2, 2.05], ['B', 1, 2.05], ['S', 1, 2.05], ['B', 3, 1.2], ['S', 2, 1.2]], 100, 0.0], [-1, 170.0, 0.0]], ['partial repair probe 1', [[['S', 1, 1.2], ['S', 2, 2.05], ['S', 1, 0.85], ['S', 1, 0.05], ['B', 1, 4.1]], 100, 0.0], [-4, -290.0, 0.0]], ['partial repair probe 2', [[['S', 3, 0.05], ['S', 1, 3.5]], 10, 0.65], [-4, 0.0, 2.6]], ['normal control 1', [[['B', 3, 0.85], ['S', 3, 2.05], ['B', 2, 3.5]], 10, 0.65], [2, 36.0, 5.2]], ['normal control 2', [[['B', 5, 3.5], ['S', 5, 3.5]], 100, 0.0], [0, 0.0, 0.0]], ['normal control 3', [[['B', 3, 3.5], ['B', 2, 3.5], ['B', 2, 1.2], ['S', 3, 2.05]], 10, 0.65], [4, -43.5, 6.5]], ['normal control 4', [[['B', 5, 0.85], ['S', 1, 0.85], ['S', 1, 2.05], ['S', 3, 0.05], ['B', 1, 2.05]], 10, 0.65], [1, -12.0, 7.15]]], [['regression position flip remainder 1', [[['B', 2, 1.2], ['S', 3, 0.85]], 10, 1.0], [-1, -7.0, 5.0]], ['regression position flip remainder 2', [[['B', 1, 0.05], ['S', 3, 4.1]], 10, 1.0], [-2, 40.5, 4.0]], ['partial repair probe 1', [[['S', 3, 3.5], ['S', 1, 2.05], ['S', 3, 0.05], ['S', 2, 1.2], ['B', 1, 0.85]], 100, 0.65], [-8, 265.0, 6.5]], ['partial repair probe 2', [[['S', 1, 4.1]], 10, 0.65], [-1, 0.0, 0.65]], ['normal control 1', [[['B', 1, 4.1]], 10, 0.0], [1, 0.0, 0.0]], ['normal control 2', [[['B', 3, 0.05], ['S', 1, 4.1], ['B', 2, 2.05], ['B', 5, 4.1]], 10, 0.0], [9, 40.5, 0.0]], ['normal control 3', [[['B', 5, 4.1], ['B', 2, 1.2], ['B', 5, 3.5], ['S', 2, 0.05]], 10, 0.0], [10, -81.0, 0.0]], ['normal control 4', [[['B', 2, 2.05]], 10, 0.65], [2, 0.0, 1.3]]]]
for label, args, expected in fixtures[N-1]:
check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
| Boundary fixture | Actual | Expected | Outcome |
|---|---|---|---|
| regression position flip remainder 1 | [3, -120.0, 0.0] | [-7, 690.0, 0.0] | Failed |
| regression position flip remainder 2 | [5, -115.0, 0.0] | [-1, 1015.0, 0.0] | Failed |
| partial repair probe 1 | [2, 0.0, 0.0] | [0, 20.0, 0.0] | Failed |
| partial repair probe 2 | [3, 0.0, 1.95] | [-3, 0.0, 1.95] | Failed |
| normal control 1 | [4, -530.0, 0.0] | [4, -530.0, 0.0] | Passed |
| normal control 2 | [0, -81.0, 3.9] | [0, -81.0, 3.9] | Passed |
| normal control 3 | [2, 0.0, 0.0] | [2, 0.0, 0.0] | Passed |
| normal control 4 | [3, 3.5, 19.0] | [3, 3.5, 19.0] | Passed |
SHA-256 / 897fc082c7cc518768d3219041e4de7f708a4a058d5de8533a6372d34a9108c1
3 / The verified repair
Exit 0"""Failure Map reference implementation. Python standard library only."""
import json
import collections
N = 1
observations = []
def solve(trades, multiplier, fee):
lots = collections.deque()
realized = 0
fees = 0
fee_c = round(fee * 100)
for side, qty, price in trades:
p = round(price * 100)
sgn = 1 if side == 'B' else -1
fees += qty * fee_c
left = qty
while left and lots and (lots[0][0] > 0) != (sgn > 0):
lot = lots[0]
m = min(left, abs(lot[0]))
direction = 1 if lot[0] > 0 else -1
realized += (p - lot[1]) * m * direction
lot[0] -= m * direction
left -= m
if lot[0] == 0:
lots.popleft()
if left:
lots.append([sgn * left, p])
pos = sum(l[0] for l in lots)
return [pos, realized * multiplier / 100, fees / 100]
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression position flip remainder 1', [[['B', 1, 1.2], ['B', 5, 0.05], ['S', 5, 0.85], ['B', 2, 4.1], ['S', 5, 4.1], ['S', 5, 0.05]], 100, 0.0], [-7, 690.0, 0.0]], ['regression position flip remainder 2', [[['B', 3, 2.05], ['S', 5, 0.85], ['S', 3, 4.1], ['S', 1, 0.05], ['B', 5, 0.05]], 100, 0.0], [-1, 1015.0, 0.0]], ['partial repair probe 1', [[['S', 1, 2.05], ['B', 1, 0.05]], 10, 0.0], [0, 20.0, 0.0]], ['partial repair probe 2', [[['S', 3, 2.05]], 100, 0.65], [-3, 0.0, 1.95]], ['normal control 1', [[['B', 3, 3.5], ['B', 3, 3.5], ['S', 2, 0.85]], 100, 0.0], [4, -530.0, 0.0]], ['normal control 2', [[['B', 1, 0.05], ['B', 2, 4.1], ['S', 3, 0.05]], 10, 0.65], [0, -81.0, 3.9]], ['normal control 3', [[['B', 2, 3.5]], 100, 0.0], [2, 0.0, 0.0]], ['normal control 4', [[['B', 5, 2.05], ['S', 5, 0.05], ['B', 3, 0.05], ['B', 3, 0.05], ['S', 3, 3.5]], 10, 1.0], [3, 3.5, 19.0]]], [['regression position flip remainder 1', [[['B', 3, 1.2], ['B', 1, 4.1], ['S', 2, 3.5], ['B', 3, 4.1], ['S', 2, 2.05], ['S', 5, 0.05]], 100, 0.0], [-2, -875.0, 0.0]], ['regression position flip remainder 2', [[['B', 2, 0.85], ['S', 1, 3.5], ['B', 2, 1.2], ['S', 2, 0.85], ['S', 2, 3.5]], 10, 0.65], [-1, 46.0, 5.85]], ['partial repair probe 1', [[['S', 5, 0.85], ['S', 2, 0.05], ['B', 2, 0.05], ['B', 5, 2.05], ['B', 5, 1.2], ['B', 5, 0.05]], 10, 1.0], [10, -60.0, 24.0]], ['partial repair probe 2', [[['S', 3, 1.2], ['S', 3, 2.05], ['B', 3, 0.05], ['S', 3, 1.2]], 100, 1.0], [-6, 345.0, 12.0]], ['normal control 1', [[['B', 3, 4.1], ['B', 2, 0.85]], 10, 0.0], [5, 0.0, 0.0]], ['normal control 2', [[['B', 5, 2.05], ['B', 2, 2.05]], 10, 0.0], [7, 0.0, 0.0]], ['normal control 3', [[['B', 1, 0.05]], 100, 0.65], [1, 0.0, 0.65]], ['normal control 4', [[['B', 2, 4.1], ['S', 1, 1.2], ['S', 1, 0.05], ['B', 2, 2.05]], 100, 0.65], [2, -695.0, 3.9]]], [['regression position flip remainder 1', [[['S', 2, 3.5], ['B', 5, 0.85], ['B', 5, 3.5], ['S', 5, 3.5]], 100, 1.0], [3, 1325.0, 17.0]], ['regression position flip remainder 2', [[['S', 2, 3.5], ['B', 2, 2.05], ['B', 1, 2.05], ['S', 5, 0.05], ['B', 2, 3.5], ['S', 3, 0.05]], 100, 0.0], [-5, -600.0, 0.0]], ['partial repair probe 1', [[['S', 2, 2.05]], 10, 1.0], [-2, 0.0, 2.0]], ['partial repair probe 2', [[['S', 1, 0.05]], 10, 1.0], [-1, 0.0, 1.0]], ['normal control 1', [[['B', 2, 1.2], ['B', 2, 3.5], ['S', 1, 2.05], ['B', 5, 2.05], ['S', 3, 0.05]], 100, 0.0], [5, -720.0, 0.0]], ['normal control 2', [[['B', 1, 0.85], ['B', 5, 1.2], ['S', 3, 3.5], ['B', 1, 3.5]], 100, 0.65], [4, 725.0, 6.5]], ['normal control 3', [[['B', 1, 0.85], ['B', 2, 2.05], ['S', 2, 3.5], ['B', 3, 1.2], ['B', 5, 0.85]], 10, 1.0], [9, 41.0, 13.0]], ['normal control 4', [[['B', 3, 1.2]], 100, 0.65], [3, 0.0, 1.95]]], [['regression position flip remainder 1', [[['B', 2, 4.1], ['S', 3, 2.05], ['B', 2, 2.05]], 100, 0.65], [1, -410.0, 4.55]], ['regression position flip remainder 2', [[['S', 2, 2.05], ['B', 1, 2.05], ['S', 1, 2.05], ['B', 3, 1.2], ['S', 2, 1.2]], 100, 0.0], [-1, 170.0, 0.0]], ['partial repair probe 1', [[['S', 1, 1.2], ['S', 2, 2.05], ['S', 1, 0.85], ['S', 1, 0.05], ['B', 1, 4.1]], 100, 0.0], [-4, -290.0, 0.0]], ['partial repair probe 2', [[['S', 3, 0.05], ['S', 1, 3.5]], 10, 0.65], [-4, 0.0, 2.6]], ['normal control 1', [[['B', 3, 0.85], ['S', 3, 2.05], ['B', 2, 3.5]], 10, 0.65], [2, 36.0, 5.2]], ['normal control 2', [[['B', 5, 3.5], ['S', 5, 3.5]], 100, 0.0], [0, 0.0, 0.0]], ['normal control 3', [[['B', 3, 3.5], ['B', 2, 3.5], ['B', 2, 1.2], ['S', 3, 2.05]], 10, 0.65], [4, -43.5, 6.5]], ['normal control 4', [[['B', 5, 0.85], ['S', 1, 0.85], ['S', 1, 2.05], ['S', 3, 0.05], ['B', 1, 2.05]], 10, 0.65], [1, -12.0, 7.15]]], [['regression position flip remainder 1', [[['B', 2, 1.2], ['S', 3, 0.85]], 10, 1.0], [-1, -7.0, 5.0]], ['regression position flip remainder 2', [[['B', 1, 0.05], ['S', 3, 4.1]], 10, 1.0], [-2, 40.5, 4.0]], ['partial repair probe 1', [[['S', 3, 3.5], ['S', 1, 2.05], ['S', 3, 0.05], ['S', 2, 1.2], ['B', 1, 0.85]], 100, 0.65], [-8, 265.0, 6.5]], ['partial repair probe 2', [[['S', 1, 4.1]], 10, 0.65], [-1, 0.0, 0.65]], ['normal control 1', [[['B', 1, 4.1]], 10, 0.0], [1, 0.0, 0.0]], ['normal control 2', [[['B', 3, 0.05], ['S', 1, 4.1], ['B', 2, 2.05], ['B', 5, 4.1]], 10, 0.0], [9, 40.5, 0.0]], ['normal control 3', [[['B', 5, 4.1], ['B', 2, 1.2], ['B', 5, 3.5], ['S', 2, 0.05]], 10, 0.0], [10, -81.0, 0.0]], ['normal control 4', [[['B', 2, 2.05]], 10, 0.65], [2, 0.0, 1.3]]]]
for label, args, expected in fixtures[N-1]:
check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
| Boundary fixture | Actual | Expected | Outcome |
|---|---|---|---|
| regression position flip remainder 1 | [-7, 690.0, 0.0] | [-7, 690.0, 0.0] | Passed |
| regression position flip remainder 2 | [-1, 1015.0, 0.0] | [-1, 1015.0, 0.0] | Passed |
| partial repair probe 1 | [0, 20.0, 0.0] | [0, 20.0, 0.0] | Passed |
| partial repair probe 2 | [-3, 0.0, 1.95] | [-3, 0.0, 1.95] | Passed |
| normal control 1 | [4, -530.0, 0.0] | [4, -530.0, 0.0] | Passed |
| normal control 2 | [0, -81.0, 3.9] | [0, -81.0, 3.9] | Passed |
| normal control 3 | [2, 0.0, 0.0] | [2, 0.0, 0.0] | Passed |
| normal control 4 | [3, 3.5, 19.0] | [3, 3.5, 19.0] | Passed |
SHA-256 / f823c7f54cf5082e827ea8dea35df33630ec07c2193eff151f220b028f8bc3e9
Verification & scope
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.
Observations recorded using Python 3.12.14 at 2026-09-29T14:46:57.435711+00:00.
Case digest / 53706e850f010411a0a791e040a753d8b7e82087c20e6dfa10888d0d88b04625