FAILURE MAP
← Case archive

FA-61756 / Options payoff and settlement / Open access

Delta hedge order sized in lots: the existing share position is ignored · case 01

Rehedging buys the full target again.

Verified by executionVariant 1 · 8 checks per implementationDownload source bundle ↓JSON ↗

ROOT CAUSE

The order equals the target without subtracting existing shares.

VERIFIED REPAIR

Trade the difference between target and existing shares.

Unsuccessful approach: Adding the existing shares doubles the offset in the wrong direction.

Case contract

Inputs positions [kind, signed contracts, absolute delta], multiplier, lot size and existing shares. Put delta is negative. Exposure = sum(sign*delta*contracts*multiplier); target shares = -exposure; the order is target - existing, rounded to whole lots with halves away from zero. Return the signed share quantity.

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 math
from fractions import Fraction
N = 1
observations = []
def solve(positions, multiplier, lot, existing):
    exposure = Fraction(0)
    for kind, c, d in positions:
        sgn = -1 if kind == 'P' else 1
        exposure += sgn * Fraction(str(d)) * c * multiplier
    target = -exposure
    trade = target
    lots = trade / lot
    n = math.floor(abs(lots) + Fraction(1, 2))
    return int((n if lots >= 0 else -n) * lot)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression existing hedge offset 1', [[['C', 5, 0.75], ['C', -3, 0.75]], 100, 50, 75], -250], ['regression existing hedge offset 2', [[['C', -3, 0.6]], 100, 50, 75], 100], ['partial repair probe 1', [[['C', 5, 0.25], ['C', -3, 0.6]], 10, 100, 50], 0], ['partial repair probe 2', [[['C', -1, 0.05], ['P', 2, 0.05], ['P', 1, 0.05], ['P', 1, 0.5]], 10, 100, 50], 0], ['boundary control 1', [[['C', 1, 0.5]], 100, 100, 0], -100], ['boundary control 2', [[['P', 1, 0.25]], 100, 50, 0], 50], ['normal control 1', [[['C', 10, 0.35]], 100, 100, 0], -400], ['normal control 2', [[['P', 2, 0.75], ['C', 10, 0.5], ['C', -1, 0.05], ['P', 10, 0.75]], 100, 25, 0], 400]], [['regression existing hedge offset 1', [[['C', 1, 0.25], ['P', 10, 0.25], ['P', -3, 0.35], ['C', 10, 0.05]], 100, 25, 100], -25], ['regression existing hedge offset 2', [[['P', -3, 0.05], ['C', 2, 0.6]], 10, 25, 75], -100], ['partial repair probe 1', [[['C', 10, 0.5]], 10, 100, 50], -100], ['partial repair probe 2', [[['C', 10, 0.35]], 100, 100, 75], -400], ['boundary control 1', [[['C', 1, 0.5]], 100, 100, 0], -100], ['boundary control 2', [[['P', 1, 0.25]], 100, 50, 0], 50], ['normal control 1', [[['P', -3, 0.75], ['P', 1, 0.05]], 100, 50, 0], -200], ['normal control 2', [[['P', 2, 0.75], ['P', -3, 0.6], ['C', 2, 0.25], ['C', -3, 0.5]], 10, 25, 0], 0]], [['regression existing hedge offset 1', [[['P', 1, 0.35]], 10, 25, 50], -50], ['regression existing hedge offset 2', [[['P', 2, 0.5], ['P', 5, 0.5]], 100, 100, -250], 600], ['partial repair probe 1', [[['C', -3, 0.5], ['P', 10, 0.25]], 100, 100, 50], 400], ['partial repair probe 2', [[['C', 10, 0.6], ['C', 1, 0.25], ['C', 1, 0.25], ['P', 1, 0.35]], 10, 100, 75], -100], ['boundary control 1', [[['P', 1, 0.25]], 100, 50, 0], 50], ['boundary control 2', [[['C', 1, 0.5]], 100, 100, 0], -100], ['normal control 1', [[['P', -3, 0.25], ['P', -1, 0.5], ['C', 5, 0.5]], 10, 100, 0], 0], ['normal control 2', [[['C', 5, 0.75], ['P', 10, 0.35], ['P', 1, 0.5]], 10, 25, 0], 0]], [['regression existing hedge offset 1', [[['P', 10, 0.5], ['C', -3, 0.6], ['C', -3, 0.35]], 100, 25, 50], 725], ['regression existing hedge offset 2', [[['C', 1, 0.05], ['C', 5, 0.35], ['P', -3, 0.5], ['P', 1, 0.5]], 10, 25, 75], -100], ['partial repair probe 1', [[['P', 5, 0.75], ['P', 5, 0.25], ['P', 5, 0.6]], 100, 100, 50], 800], ['partial repair probe 2', [[['P', -3, 0.6], ['P', -3, 0.35], ['P', 10, 0.05], ['C', 10, 0.6]], 10, 100, 50], -100], ['boundary control 1', [[['C', 1, 0.5]], 100, 100, 0], -100], ['boundary control 2', [[['P', 1, 0.25]], 100, 50, 0], 50], ['normal control 1', [[['P', 10, 0.75], ['P', -3, 0.25], ['C', 1, 0.75]], 10, 50, 0], 50], ['normal control 2', [[['P', 10, 0.5]], 100, 100, 0], 500]], [['regression existing hedge offset 1', [[['P', -1, 0.6], ['C', -1, 0.35], ['P', 2, 0.5], ['P', -1, 0.05]], 100, 25, 50], 25], ['regression existing hedge offset 2', [[['C', 10, 0.05], ['P', 1, 0.25]], 100, 25, 75], -100], ['partial repair probe 1', [[['P', -3, 0.35], ['P', 2, 0.75], ['P', 1, 0.25], ['C', -1, 0.35]], 10, 100, 50], 0], ['partial repair probe 2', [[['P', -1, 0.75], ['P', -1, 0.25], ['C', -3, 0.6]], 10, 100, 50], 0], ['boundary control 1', [[['P', 1, 0.25]], 100, 50, 0], 50], ['boundary control 2', [[['C', 1, 0.5]], 100, 100, 0], -100], ['normal control 1', [[['P', 2, 0.25], ['C', 10, 0.35], ['C', 1, 0.6], ['C', 5, 0.25]], 100, 100, 0], -500], ['normal control 2', [[['C', 5, 0.6], ['P', 5, 0.35], ['P', -1, 0.5], ['P', 1, 0.05]], 100, 100, 0], -200]]]
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 fixtureActualExpectedOutcome
regression existing hedge offset 1-150-250Failed
regression existing hedge offset 2200100Failed
partial repair probe 100Passed
partial repair probe 200Passed
boundary control 1-100-100Passed
boundary control 25050Passed
normal control 1-400-400Passed
normal control 2400400Passed

SHA-256 / 4f1c6aca714fe34e03517e0b96863ca4c134e8747902b102350d91d09a9e65f8

2 / The unsuccessful fix

Exit 1
"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(positions, multiplier, lot, existing):
    exposure = Fraction(0)
    for kind, c, d in positions:
        sgn = -1 if kind == 'P' else 1
        exposure += sgn * Fraction(str(d)) * c * multiplier
    target = -exposure
    trade = target + existing
    lots = trade / lot
    n = math.floor(abs(lots) + Fraction(1, 2))
    return int((n if lots >= 0 else -n) * lot)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression existing hedge offset 1', [[['C', 5, 0.75], ['C', -3, 0.75]], 100, 50, 75], -250], ['regression existing hedge offset 2', [[['C', -3, 0.6]], 100, 50, 75], 100], ['partial repair probe 1', [[['C', 5, 0.25], ['C', -3, 0.6]], 10, 100, 50], 0], ['partial repair probe 2', [[['C', -1, 0.05], ['P', 2, 0.05], ['P', 1, 0.05], ['P', 1, 0.5]], 10, 100, 50], 0], ['boundary control 1', [[['C', 1, 0.5]], 100, 100, 0], -100], ['boundary control 2', [[['P', 1, 0.25]], 100, 50, 0], 50], ['normal control 1', [[['C', 10, 0.35]], 100, 100, 0], -400], ['normal control 2', [[['P', 2, 0.75], ['C', 10, 0.5], ['C', -1, 0.05], ['P', 10, 0.75]], 100, 25, 0], 400]], [['regression existing hedge offset 1', [[['C', 1, 0.25], ['P', 10, 0.25], ['P', -3, 0.35], ['C', 10, 0.05]], 100, 25, 100], -25], ['regression existing hedge offset 2', [[['P', -3, 0.05], ['C', 2, 0.6]], 10, 25, 75], -100], ['partial repair probe 1', [[['C', 10, 0.5]], 10, 100, 50], -100], ['partial repair probe 2', [[['C', 10, 0.35]], 100, 100, 75], -400], ['boundary control 1', [[['C', 1, 0.5]], 100, 100, 0], -100], ['boundary control 2', [[['P', 1, 0.25]], 100, 50, 0], 50], ['normal control 1', [[['P', -3, 0.75], ['P', 1, 0.05]], 100, 50, 0], -200], ['normal control 2', [[['P', 2, 0.75], ['P', -3, 0.6], ['C', 2, 0.25], ['C', -3, 0.5]], 10, 25, 0], 0]], [['regression existing hedge offset 1', [[['P', 1, 0.35]], 10, 25, 50], -50], ['regression existing hedge offset 2', [[['P', 2, 0.5], ['P', 5, 0.5]], 100, 100, -250], 600], ['partial repair probe 1', [[['C', -3, 0.5], ['P', 10, 0.25]], 100, 100, 50], 400], ['partial repair probe 2', [[['C', 10, 0.6], ['C', 1, 0.25], ['C', 1, 0.25], ['P', 1, 0.35]], 10, 100, 75], -100], ['boundary control 1', [[['P', 1, 0.25]], 100, 50, 0], 50], ['boundary control 2', [[['C', 1, 0.5]], 100, 100, 0], -100], ['normal control 1', [[['P', -3, 0.25], ['P', -1, 0.5], ['C', 5, 0.5]], 10, 100, 0], 0], ['normal control 2', [[['C', 5, 0.75], ['P', 10, 0.35], ['P', 1, 0.5]], 10, 25, 0], 0]], [['regression existing hedge offset 1', [[['P', 10, 0.5], ['C', -3, 0.6], ['C', -3, 0.35]], 100, 25, 50], 725], ['regression existing hedge offset 2', [[['C', 1, 0.05], ['C', 5, 0.35], ['P', -3, 0.5], ['P', 1, 0.5]], 10, 25, 75], -100], ['partial repair probe 1', [[['P', 5, 0.75], ['P', 5, 0.25], ['P', 5, 0.6]], 100, 100, 50], 800], ['partial repair probe 2', [[['P', -3, 0.6], ['P', -3, 0.35], ['P', 10, 0.05], ['C', 10, 0.6]], 10, 100, 50], -100], ['boundary control 1', [[['C', 1, 0.5]], 100, 100, 0], -100], ['boundary control 2', [[['P', 1, 0.25]], 100, 50, 0], 50], ['normal control 1', [[['P', 10, 0.75], ['P', -3, 0.25], ['C', 1, 0.75]], 10, 50, 0], 50], ['normal control 2', [[['P', 10, 0.5]], 100, 100, 0], 500]], [['regression existing hedge offset 1', [[['P', -1, 0.6], ['C', -1, 0.35], ['P', 2, 0.5], ['P', -1, 0.05]], 100, 25, 50], 25], ['regression existing hedge offset 2', [[['C', 10, 0.05], ['P', 1, 0.25]], 100, 25, 75], -100], ['partial repair probe 1', [[['P', -3, 0.35], ['P', 2, 0.75], ['P', 1, 0.25], ['C', -1, 0.35]], 10, 100, 50], 0], ['partial repair probe 2', [[['P', -1, 0.75], ['P', -1, 0.25], ['C', -3, 0.6]], 10, 100, 50], 0], ['boundary control 1', [[['P', 1, 0.25]], 100, 50, 0], 50], ['boundary control 2', [[['C', 1, 0.5]], 100, 100, 0], -100], ['normal control 1', [[['P', 2, 0.25], ['C', 10, 0.35], ['C', 1, 0.6], ['C', 5, 0.25]], 100, 100, 0], -500], ['normal control 2', [[['C', 5, 0.6], ['P', 5, 0.35], ['P', -1, 0.5], ['P', 1, 0.05]], 100, 100, 0], -200]]]
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 fixtureActualExpectedOutcome
regression existing hedge offset 1-100-250Failed
regression existing hedge offset 2250100Failed
partial repair probe 11000Failed
partial repair probe 21000Failed
boundary control 1-100-100Passed
boundary control 25050Passed
normal control 1-400-400Passed
normal control 2400400Passed

SHA-256 / 27c03022ceb30318f92c6c6620728823ebca3bb37f6b20651154e96568854847

3 / The verified repair

Exit 0
"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(positions, multiplier, lot, existing):
    exposure = Fraction(0)
    for kind, c, d in positions:
        sgn = -1 if kind == 'P' else 1
        exposure += sgn * Fraction(str(d)) * c * multiplier
    target = -exposure
    trade = target - existing
    lots = trade / lot
    n = math.floor(abs(lots) + Fraction(1, 2))
    return int((n if lots >= 0 else -n) * lot)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression existing hedge offset 1', [[['C', 5, 0.75], ['C', -3, 0.75]], 100, 50, 75], -250], ['regression existing hedge offset 2', [[['C', -3, 0.6]], 100, 50, 75], 100], ['partial repair probe 1', [[['C', 5, 0.25], ['C', -3, 0.6]], 10, 100, 50], 0], ['partial repair probe 2', [[['C', -1, 0.05], ['P', 2, 0.05], ['P', 1, 0.05], ['P', 1, 0.5]], 10, 100, 50], 0], ['boundary control 1', [[['C', 1, 0.5]], 100, 100, 0], -100], ['boundary control 2', [[['P', 1, 0.25]], 100, 50, 0], 50], ['normal control 1', [[['C', 10, 0.35]], 100, 100, 0], -400], ['normal control 2', [[['P', 2, 0.75], ['C', 10, 0.5], ['C', -1, 0.05], ['P', 10, 0.75]], 100, 25, 0], 400]], [['regression existing hedge offset 1', [[['C', 1, 0.25], ['P', 10, 0.25], ['P', -3, 0.35], ['C', 10, 0.05]], 100, 25, 100], -25], ['regression existing hedge offset 2', [[['P', -3, 0.05], ['C', 2, 0.6]], 10, 25, 75], -100], ['partial repair probe 1', [[['C', 10, 0.5]], 10, 100, 50], -100], ['partial repair probe 2', [[['C', 10, 0.35]], 100, 100, 75], -400], ['boundary control 1', [[['C', 1, 0.5]], 100, 100, 0], -100], ['boundary control 2', [[['P', 1, 0.25]], 100, 50, 0], 50], ['normal control 1', [[['P', -3, 0.75], ['P', 1, 0.05]], 100, 50, 0], -200], ['normal control 2', [[['P', 2, 0.75], ['P', -3, 0.6], ['C', 2, 0.25], ['C', -3, 0.5]], 10, 25, 0], 0]], [['regression existing hedge offset 1', [[['P', 1, 0.35]], 10, 25, 50], -50], ['regression existing hedge offset 2', [[['P', 2, 0.5], ['P', 5, 0.5]], 100, 100, -250], 600], ['partial repair probe 1', [[['C', -3, 0.5], ['P', 10, 0.25]], 100, 100, 50], 400], ['partial repair probe 2', [[['C', 10, 0.6], ['C', 1, 0.25], ['C', 1, 0.25], ['P', 1, 0.35]], 10, 100, 75], -100], ['boundary control 1', [[['P', 1, 0.25]], 100, 50, 0], 50], ['boundary control 2', [[['C', 1, 0.5]], 100, 100, 0], -100], ['normal control 1', [[['P', -3, 0.25], ['P', -1, 0.5], ['C', 5, 0.5]], 10, 100, 0], 0], ['normal control 2', [[['C', 5, 0.75], ['P', 10, 0.35], ['P', 1, 0.5]], 10, 25, 0], 0]], [['regression existing hedge offset 1', [[['P', 10, 0.5], ['C', -3, 0.6], ['C', -3, 0.35]], 100, 25, 50], 725], ['regression existing hedge offset 2', [[['C', 1, 0.05], ['C', 5, 0.35], ['P', -3, 0.5], ['P', 1, 0.5]], 10, 25, 75], -100], ['partial repair probe 1', [[['P', 5, 0.75], ['P', 5, 0.25], ['P', 5, 0.6]], 100, 100, 50], 800], ['partial repair probe 2', [[['P', -3, 0.6], ['P', -3, 0.35], ['P', 10, 0.05], ['C', 10, 0.6]], 10, 100, 50], -100], ['boundary control 1', [[['C', 1, 0.5]], 100, 100, 0], -100], ['boundary control 2', [[['P', 1, 0.25]], 100, 50, 0], 50], ['normal control 1', [[['P', 10, 0.75], ['P', -3, 0.25], ['C', 1, 0.75]], 10, 50, 0], 50], ['normal control 2', [[['P', 10, 0.5]], 100, 100, 0], 500]], [['regression existing hedge offset 1', [[['P', -1, 0.6], ['C', -1, 0.35], ['P', 2, 0.5], ['P', -1, 0.05]], 100, 25, 50], 25], ['regression existing hedge offset 2', [[['C', 10, 0.05], ['P', 1, 0.25]], 100, 25, 75], -100], ['partial repair probe 1', [[['P', -3, 0.35], ['P', 2, 0.75], ['P', 1, 0.25], ['C', -1, 0.35]], 10, 100, 50], 0], ['partial repair probe 2', [[['P', -1, 0.75], ['P', -1, 0.25], ['C', -3, 0.6]], 10, 100, 50], 0], ['boundary control 1', [[['P', 1, 0.25]], 100, 50, 0], 50], ['boundary control 2', [[['C', 1, 0.5]], 100, 100, 0], -100], ['normal control 1', [[['P', 2, 0.25], ['C', 10, 0.35], ['C', 1, 0.6], ['C', 5, 0.25]], 100, 100, 0], -500], ['normal control 2', [[['C', 5, 0.6], ['P', 5, 0.35], ['P', -1, 0.5], ['P', 1, 0.05]], 100, 100, 0], -200]]]
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 fixtureActualExpectedOutcome
regression existing hedge offset 1-250-250Passed
regression existing hedge offset 2100100Passed
partial repair probe 100Passed
partial repair probe 200Passed
boundary control 1-100-100Passed
boundary control 25050Passed
normal control 1-400-400Passed
normal control 2400400Passed

SHA-256 / 5e3d063a997d94ccbbdae42c2eb66a2c301c7c2ac770115bc3633bab0d0f5584

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:58.157003+00:00.

Case digest / 9f624ce800b090058d04d5cc0d55411d2233ba5717fc07b29605a5d402238b02