broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(exercised, shorts, method):
    total = sum(q for _, q, _ in shorts)
    alloc = {}
    if method == 'fifo':
        left = exercised
        for acct, q, seq in sorted(shorts, key=lambda s: s[2]):
            take = min(q, left)
            alloc[acct] = alloc.get(acct, 0) + take
            left -= take
    else:
        rem = []
        for acct, q, seq in shorts:
            alloc[acct] = alloc.get(acct, 0) + exercised * q // total
            rem.append((-(exercised * q % total), seq, acct))
        left = exercised - sum(alloc.values())
        pass
    return sorted([a, n] for a, n in alloc.items() if n > 0)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression remainder distribution 1', [24, [['A1', 10, 8], ['D4', 5, 17], ['F6', 10, 11]], 'pro-rata'], [['A1', 10], ['D4', 5], ['F6', 9]]], ['regression remainder distribution 2', [39, [['D4', 10, 1], ['C3', 10, 3], ['E5', 10, 9], ['A1', 7, 16], ['B2', 10, 12]], 'pro-rata'], [['A1', 6], ['B2', 8], ['C3', 8], ['D4', 9], ['E5', 8]]], ['partial repair probe 1', [10, [['D4', 5, 14], ['F6', 10, 8], ['A1', 3, 1], ['E5', 1, 16], ['B2', 2, 2]], 'pro-rata'], [['A1', 1], ['B2', 1], ['D4', 2], ['E5', 1], ['F6', 5]]], ['partial repair probe 2', [9, [['F6', 1, 11], ['C3', 5, 10], ['E5', 7, 2], ['B2', 5, 12]], 'pro-rata'], [['B2', 2], ['C3', 3], ['E5', 4]]], ['boundary control 1', [2, [['A1', 5, 2], ['B2', 5, 1]], 'fifo'], [['B2', 2]]], ['boundary control 2', [3, [['A1', 1, 1], ['B2', 1, 2], ['C3', 1, 3]], 'pro-rata'], [['A1', 1], ['B2', 1], ['C3', 1]]], ['normal control 1', [2, [['A1', 5, 14]], 'pro-rata'], [['A1', 2]]], ['normal control 2', [3, [['E5', 3, 1]], 'pro-rata'], [['E5', 3]]]], [['regression remainder distribution 1', [9, [['B2', 2, 12], ['E5', 3, 3], ['A1', 7, 17], ['C3', 5, 5]], 'pro-rata'], [['A1', 4], ['B2', 1], ['C3', 3], ['E5', 1]]], ['regression remainder distribution 2', [14, [['C3', 2, 5], ['D4', 5, 11], ['E5', 3, 17], ['A1', 10, 13], ['B2', 10, 18]], 'pro-rata'], [['A1', 5], ['B2', 5], ['C3', 1], ['D4', 2], ['E5', 1]]], ['partial repair probe 1', [21, [['D4', 1, 15], ['E5', 5, 6], ['F6', 7, 19], ['B2', 2, 11], ['A1', 10, 4]], 'pro-rata'], [['A1', 8], ['B2', 2], ['D4', 1], ['E5', 4], ['F6', 6]]], ['partial repair probe 2', [12, [['A1', 1, 16], ['F6', 5, 18], ['D4', 2, 7], ['B2', 7, 3], ['C3', 2, 19]], 'pro-rata'], [['A1', 1], ['B2', 5], ['C3', 1], ['D4', 1], ['F6', 4]]], ['boundary control 1', [3, [['A1', 1, 1], ['B2', 1, 2], ['C3', 1, 3]], 'pro-rata'], [['A1', 1], ['B2', 1], ['C3', 1]]], ['boundary control 2', [2, [['A1', 5, 2], ['B2', 5, 1]], 'fifo'], [['B2', 2]]], ['normal control 1', [2, [['B2', 3, 13], ['F6', 1, 17], ['A1', 2, 1], ['C3', 3, 4], ['E5', 2, 3]], 'fifo'], [['A1', 2]]], ['normal control 2', [5, [['F6', 7, 2]], 'fifo'], [['F6', 5]]]], [['regression remainder distribution 1', [1, [['F6', 1, 8], ['C3', 3, 7], ['A1', 3, 14], ['B2', 2, 10]], 'pro-rata'], [['C3', 1]]], ['regression remainder distribution 2', [12, [['D4', 7, 17], ['C3', 3, 13], ['A1', 7, 8], ['B2', 1, 2], ['F6', 2, 9]], 'pro-rata'], [['A1', 4], ['B2', 1], ['C3', 2], ['D4', 4], ['F6', 1]]], ['partial repair probe 1', [2, [['E5', 1, 5], ['F6', 5, 9], ['B2', 5, 17]], 'pro-rata'], [['B2', 1], ['F6', 1]]], ['partial repair probe 2', [6, [['D4', 3, 11], ['F6', 3, 15], ['C3', 3, 18], ['B2', 5, 16], ['A1', 2, 6]], 'pro-rata'], [['A1', 1], ['B2', 2], ['C3', 1], ['D4', 1], ['F6', 1]]], ['boundary control 1', [3, [['A1', 1, 1], ['B2', 1, 2], ['C3', 1, 3]], 'pro-rata'], [['A1', 1], ['B2', 1], ['C3', 1]]], ['boundary control 2', [2, [['A1', 5, 2], ['B2', 5, 1]], 'fifo'], [['B2', 2]]], ['normal control 1', [20, [['D4', 10, 17], ['C3', 2, 3], ['F6', 3, 5], ['A1', 5, 7]], 'pro-rata'], [['A1', 5], ['C3', 2], ['D4', 10], ['F6', 3]]], ['normal control 2', [9, [['F6', 5, 5], ['E5', 10, 3], ['B2', 3, 19]], 'fifo'], [['E5', 9]]]], [['regression remainder distribution 1', [4, [['D4', 2, 5], ['A1', 5, 9], ['E5', 7, 14]], 'pro-rata'], [['A1', 1], ['D4', 1], ['E5', 2]]], ['regression remainder distribution 2', [5, [['B2', 1, 5], ['F6', 2, 19], ['D4', 2, 18], ['A1', 3, 6], ['C3', 5, 4]], 'pro-rata'], [['A1', 1], ['C3', 2], ['D4', 1], ['F6', 1]]], ['partial repair probe 1', [17, [['B2', 3, 7], ['A1', 10, 3], ['F6', 5, 14]], 'pro-rata'], [['A1', 9], ['B2', 3], ['F6', 5]]], ['partial repair probe 2', [27, [['C3', 10, 15], ['F6', 7, 1], ['D4', 5, 9], ['B2', 7, 18]], 'pro-rata'], [['B2', 6], ['C3', 9], ['D4', 5], ['F6', 7]]], ['boundary control 1', [2, [['A1', 5, 2], ['B2', 5, 1]], 'fifo'], [['B2', 2]]], ['boundary control 2', [3, [['A1', 1, 1], ['B2', 1, 2], ['C3', 1, 3]], 'pro-rata'], [['A1', 1], ['B2', 1], ['C3', 1]]], ['normal control 1', [1, [['A1', 1, 17]], 'pro-rata'], [['A1', 1]]], ['normal control 2', [12, [['D4', 3, 14], ['E5', 5, 15], ['C3', 1, 17], ['F6', 3, 8]], 'pro-rata'], [['C3', 1], ['D4', 3], ['E5', 5], ['F6', 3]]]], [['regression remainder distribution 1', [2, [['E5', 5, 12], ['D4', 10, 13], ['B2', 1, 3]], 'pro-rata'], [['D4', 1], ['E5', 1]]], ['regression remainder distribution 2', [4, [['B2', 3, 14], ['A1', 5, 1], ['C3', 1, 15]], 'pro-rata'], [['A1', 2], ['B2', 1], ['C3', 1]]], ['partial repair probe 1', [4, [['B2', 3, 13], ['F6', 5, 19], ['D4', 7, 1]], 'pro-rata'], [['B2', 1], ['D4', 2], ['F6', 1]]], ['partial repair probe 2', [7, [['B2', 10, 18], ['C3', 7, 3]], 'pro-rata'], [['B2', 4], ['C3', 3]]], ['boundary control 1', [2, [['A1', 5, 2], ['B2', 5, 1]], 'fifo'], [['B2', 2]]], ['boundary control 2', [3, [['A1', 1, 1], ['B2', 1, 2], ['C3', 1, 3]], 'pro-rata'], [['A1', 1], ['B2', 1], ['C3', 1]]], ['normal control 1', [8, [['A1', 2, 17], ['E5', 5, 8], ['C3', 2, 3], ['B2', 1, 14]], 'fifo'], [['B2', 1], ['C3', 2], ['E5', 5]]], ['normal control 2', [14, [['A1', 7, 18], ['B2', 1, 5], ['D4', 10, 12], ['E5', 1, 14]], 'fifo'], [['A1', 2], ['B2', 1], ['D4', 10], ['E5', 1]]]]]
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)

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(exercised, shorts, method):
    total = sum(q for _, q, _ in shorts)
    alloc = {}
    if method == 'fifo':
        left = exercised
        for acct, q, seq in sorted(shorts, key=lambda s: s[2]):
            take = min(q, left)
            alloc[acct] = alloc.get(acct, 0) + take
            left -= take
    else:
        rem = []
        for acct, q, seq in shorts:
            alloc[acct] = alloc.get(acct, 0) + exercised * q // total
            rem.append((-(exercised * q % total), seq, acct))
        left = exercised - sum(alloc.values())
        alloc[max(shorts, key=lambda s: s[1])[0]] += left
    return sorted([a, n] for a, n in alloc.items() if n > 0)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression remainder distribution 1', [24, [['A1', 10, 8], ['D4', 5, 17], ['F6', 10, 11]], 'pro-rata'], [['A1', 10], ['D4', 5], ['F6', 9]]], ['regression remainder distribution 2', [39, [['D4', 10, 1], ['C3', 10, 3], ['E5', 10, 9], ['A1', 7, 16], ['B2', 10, 12]], 'pro-rata'], [['A1', 6], ['B2', 8], ['C3', 8], ['D4', 9], ['E5', 8]]], ['partial repair probe 1', [10, [['D4', 5, 14], ['F6', 10, 8], ['A1', 3, 1], ['E5', 1, 16], ['B2', 2, 2]], 'pro-rata'], [['A1', 1], ['B2', 1], ['D4', 2], ['E5', 1], ['F6', 5]]], ['partial repair probe 2', [9, [['F6', 1, 11], ['C3', 5, 10], ['E5', 7, 2], ['B2', 5, 12]], 'pro-rata'], [['B2', 2], ['C3', 3], ['E5', 4]]], ['boundary control 1', [2, [['A1', 5, 2], ['B2', 5, 1]], 'fifo'], [['B2', 2]]], ['boundary control 2', [3, [['A1', 1, 1], ['B2', 1, 2], ['C3', 1, 3]], 'pro-rata'], [['A1', 1], ['B2', 1], ['C3', 1]]], ['normal control 1', [2, [['A1', 5, 14]], 'pro-rata'], [['A1', 2]]], ['normal control 2', [3, [['E5', 3, 1]], 'pro-rata'], [['E5', 3]]]], [['regression remainder distribution 1', [9, [['B2', 2, 12], ['E5', 3, 3], ['A1', 7, 17], ['C3', 5, 5]], 'pro-rata'], [['A1', 4], ['B2', 1], ['C3', 3], ['E5', 1]]], ['regression remainder distribution 2', [14, [['C3', 2, 5], ['D4', 5, 11], ['E5', 3, 17], ['A1', 10, 13], ['B2', 10, 18]], 'pro-rata'], [['A1', 5], ['B2', 5], ['C3', 1], ['D4', 2], ['E5', 1]]], ['partial repair probe 1', [21, [['D4', 1, 15], ['E5', 5, 6], ['F6', 7, 19], ['B2', 2, 11], ['A1', 10, 4]], 'pro-rata'], [['A1', 8], ['B2', 2], ['D4', 1], ['E5', 4], ['F6', 6]]], ['partial repair probe 2', [12, [['A1', 1, 16], ['F6', 5, 18], ['D4', 2, 7], ['B2', 7, 3], ['C3', 2, 19]], 'pro-rata'], [['A1', 1], ['B2', 5], ['C3', 1], ['D4', 1], ['F6', 4]]], ['boundary control 1', [3, [['A1', 1, 1], ['B2', 1, 2], ['C3', 1, 3]], 'pro-rata'], [['A1', 1], ['B2', 1], ['C3', 1]]], ['boundary control 2', [2, [['A1', 5, 2], ['B2', 5, 1]], 'fifo'], [['B2', 2]]], ['normal control 1', [2, [['B2', 3, 13], ['F6', 1, 17], ['A1', 2, 1], ['C3', 3, 4], ['E5', 2, 3]], 'fifo'], [['A1', 2]]], ['normal control 2', [5, [['F6', 7, 2]], 'fifo'], [['F6', 5]]]], [['regression remainder distribution 1', [1, [['F6', 1, 8], ['C3', 3, 7], ['A1', 3, 14], ['B2', 2, 10]], 'pro-rata'], [['C3', 1]]], ['regression remainder distribution 2', [12, [['D4', 7, 17], ['C3', 3, 13], ['A1', 7, 8], ['B2', 1, 2], ['F6', 2, 9]], 'pro-rata'], [['A1', 4], ['B2', 1], ['C3', 2], ['D4', 4], ['F6', 1]]], ['partial repair probe 1', [2, [['E5', 1, 5], ['F6', 5, 9], ['B2', 5, 17]], 'pro-rata'], [['B2', 1], ['F6', 1]]], ['partial repair probe 2', [6, [['D4', 3, 11], ['F6', 3, 15], ['C3', 3, 18], ['B2', 5, 16], ['A1', 2, 6]], 'pro-rata'], [['A1', 1], ['B2', 2], ['C3', 1], ['D4', 1], ['F6', 1]]], ['boundary control 1', [3, [['A1', 1, 1], ['B2', 1, 2], ['C3', 1, 3]], 'pro-rata'], [['A1', 1], ['B2', 1], ['C3', 1]]], ['boundary control 2', [2, [['A1', 5, 2], ['B2', 5, 1]], 'fifo'], [['B2', 2]]], ['normal control 1', [20, [['D4', 10, 17], ['C3', 2, 3], ['F6', 3, 5], ['A1', 5, 7]], 'pro-rata'], [['A1', 5], ['C3', 2], ['D4', 10], ['F6', 3]]], ['normal control 2', [9, [['F6', 5, 5], ['E5', 10, 3], ['B2', 3, 19]], 'fifo'], [['E5', 9]]]], [['regression remainder distribution 1', [4, [['D4', 2, 5], ['A1', 5, 9], ['E5', 7, 14]], 'pro-rata'], [['A1', 1], ['D4', 1], ['E5', 2]]], ['regression remainder distribution 2', [5, [['B2', 1, 5], ['F6', 2, 19], ['D4', 2, 18], ['A1', 3, 6], ['C3', 5, 4]], 'pro-rata'], [['A1', 1], ['C3', 2], ['D4', 1], ['F6', 1]]], ['partial repair probe 1', [17, [['B2', 3, 7], ['A1', 10, 3], ['F6', 5, 14]], 'pro-rata'], [['A1', 9], ['B2', 3], ['F6', 5]]], ['partial repair probe 2', [27, [['C3', 10, 15], ['F6', 7, 1], ['D4', 5, 9], ['B2', 7, 18]], 'pro-rata'], [['B2', 6], ['C3', 9], ['D4', 5], ['F6', 7]]], ['boundary control 1', [2, [['A1', 5, 2], ['B2', 5, 1]], 'fifo'], [['B2', 2]]], ['boundary control 2', [3, [['A1', 1, 1], ['B2', 1, 2], ['C3', 1, 3]], 'pro-rata'], [['A1', 1], ['B2', 1], ['C3', 1]]], ['normal control 1', [1, [['A1', 1, 17]], 'pro-rata'], [['A1', 1]]], ['normal control 2', [12, [['D4', 3, 14], ['E5', 5, 15], ['C3', 1, 17], ['F6', 3, 8]], 'pro-rata'], [['C3', 1], ['D4', 3], ['E5', 5], ['F6', 3]]]], [['regression remainder distribution 1', [2, [['E5', 5, 12], ['D4', 10, 13], ['B2', 1, 3]], 'pro-rata'], [['D4', 1], ['E5', 1]]], ['regression remainder distribution 2', [4, [['B2', 3, 14], ['A1', 5, 1], ['C3', 1, 15]], 'pro-rata'], [['A1', 2], ['B2', 1], ['C3', 1]]], ['partial repair probe 1', [4, [['B2', 3, 13], ['F6', 5, 19], ['D4', 7, 1]], 'pro-rata'], [['B2', 1], ['D4', 2], ['F6', 1]]], ['partial repair probe 2', [7, [['B2', 10, 18], ['C3', 7, 3]], 'pro-rata'], [['B2', 4], ['C3', 3]]], ['boundary control 1', [2, [['A1', 5, 2], ['B2', 5, 1]], 'fifo'], [['B2', 2]]], ['boundary control 2', [3, [['A1', 1, 1], ['B2', 1, 2], ['C3', 1, 3]], 'pro-rata'], [['A1', 1], ['B2', 1], ['C3', 1]]], ['normal control 1', [8, [['A1', 2, 17], ['E5', 5, 8], ['C3', 2, 3], ['B2', 1, 14]], 'fifo'], [['B2', 1], ['C3', 2], ['E5', 5]]], ['normal control 2', [14, [['A1', 7, 18], ['B2', 1, 5], ['D4', 10, 12], ['E5', 1, 14]], 'fifo'], [['A1', 2], ['B2', 1], ['D4', 10], ['E5', 1]]]]]
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)

prompt:
Fewer contracts are assigned than were exercised.

Inputs exercised contracts (<= total short), shorts [account, qty, open sequence] and method. fifo assigns in ascending open sequence, each up to its quantity. pro-rata gives floor(exercised*qty/total) and distributes the remaining contracts one each by largest fractional remainder, ties by lower open sequence. Return sorted [account, assigned] for accounts with assignments.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(exercised, shorts, method):
    total = sum(q for _, q, _ in shorts)
    alloc = {}
    if method == 'fifo':
        left = exercised
        for acct, q, seq in sorted(shorts, key=lambda s: s[2]):
            take = min(q, left)
            alloc[acct] = alloc.get(acct, 0) + take
            left -= take
    else:
        rem = []
        for acct, q, seq in shorts:
            alloc[acct] = alloc.get(acct, 0) + exercised * q // total
            rem.append(((exercised * q % total), seq, acct))
        left = exercised - sum(alloc.values())
        for _, seq, acct in sorted(rem)[:left]:
            alloc[acct] += 1
    return sorted([a, n] for a, n in alloc.items() if n > 0)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression remainder ranking 1', [12, [['B2', 5, 6], ['A1', 2, 12], ['C3', 7, 10], ['E5', 1, 3]], 'pro-rata'], [['A1', 1], ['B2', 4], ['C3', 6], ['E5', 1]]], ['regression remainder ranking 2', [3, [['C3', 5, 10], ['D4', 2, 5]], 'pro-rata'], [['C3', 2], ['D4', 1]]], ['partial repair probe 1', [2, [['E5', 3, 17], ['A1', 1, 8]], 'pro-rata'], [['A1', 1], ['E5', 1]]], ['partial repair probe 2', [5, [['C3', 1, 5], ['B2', 3, 2], ['E5', 1, 8], ['A1', 5, 7]], 'pro-rata'], [['A1', 2], ['B2', 2], ['C3', 1]]], ['boundary control 1', [2, [['A1', 5, 2], ['B2', 5, 1]], 'fifo'], [['B2', 2]]], ['boundary control 2', [3, [['A1', 1, 1], ['B2', 1, 2], ['C3', 1, 3]], 'pro-rata'], [['A1', 1], ['B2', 1], ['C3', 1]]], ['normal control 1', [4, [['D4', 7, 13]], 'pro-rata'], [['D4', 4]]], ['normal control 2', [6, [['E5', 10, 11], ['F6', 7, 19]], 'fifo'], [['E5', 6]]]], [['regression remainder ranking 1', [12, [['A1', 3, 1], ['C3', 7, 18], ['B2', 7, 2], ['E5', 5, 5]], 'pro-rata'], [['A1', 1], ['B2', 4], ['C3', 4], ['E5', 3]]], ['regression remainder ranking 2', [1, [['A1', 7, 3], ['D4', 10, 11]], 'pro-rata'], [['D4', 1]]], ['partial repair probe 1', [9, [['F6', 3, 13], ['A1', 7, 16], ['C3', 3, 9], ['D4', 5, 7]], 'pro-rata'], [['A1', 3], ['C3', 2], ['D4', 3], ['F6', 1]]], ['partial repair probe 2', [8, [['C3', 7, 12], ['D4', 3, 5], ['A1', 3, 2], ['B2', 3, 11]], 'pro-rata'], [['A1', 2], ['B2', 1], ['C3', 3], ['D4', 2]]], ['boundary control 1', [2, [['A1', 5, 2], ['B2', 5, 1]], 'fifo'], [['B2', 2]]], ['boundary control 2', [3, [['A1', 1, 1], ['B2', 1, 2], ['C3', 1, 3]], 'pro-rata'], [['A1', 1], ['B2', 1], ['C3', 1]]], ['normal control 1', [3, [['D4', 3, 1]], 'pro-rata'], [['D4', 3]]], ['normal control 2', [7, [['E5', 7, 12]], 'pro-rata'], [['E5', 7]]]], [['regression remainder ranking 1', [13, [['E5', 7, 5], ['F6', 7, 1], ['D4', 10, 7], ['B2', 3, 10]], 'pro-rata'], [['B2', 2], ['D4', 5], ['E5', 3], ['F6', 3]]], ['regression remainder ranking 2', [6, [['B2', 2, 16], ['E5', 5, 6]], 'pro-rata'], [['B2', 2], ['E5', 4]]], ['partial repair probe 1', [5, [['E5', 3, 8], ['D4', 7, 18]], 'pro-rata'], [['D4', 3], ['E5', 2]]], ['partial repair probe 2', [4, [['B2', 3, 5], ['A1', 5, 6]], 'pro-rata'], [['A1', 2], ['B2', 2]]], ['boundary control 1', [3, [['A1', 1, 1], ['B2', 1, 2], ['C3', 1, 3]], 'pro-rata'], [['A1', 1], ['B2', 1], ['C3', 1]]], ['boundary control 2', [2, [['A1', 5, 2], ['B2', 5, 1]], 'fifo'], [['B2', 2]]], ['normal control 1', [2, [['B2', 3, 1]], 'fifo'], [['B2', 2]]], ['normal control 2', [2, [['F6', 5, 1]], 'pro-rata'], [['F6', 2]]]], [['regression remainder ranking 1', [11, [['A1', 3, 18], ['D4', 7, 8], ['F6', 5, 12]], 'pro-rata'], [['A1', 2], ['D4', 5], ['F6', 4]]], ['regression remainder ranking 2', [7, [['D4', 3, 19], ['B2', 5, 11], ['F6', 7, 12]], 'pro-rata'], [['B2', 2], ['D4', 2], ['F6', 3]]], ['partial repair probe 1', [5, [['D4', 7, 6], ['F6', 3, 10], ['C3', 7, 18], ['E5', 3, 1]], 'pro-rata'], [['C3', 1], ['D4', 2], ['E5', 1], ['F6', 1]]], ['partial repair probe 2', [2, [['C3', 1, 2], ['E5', 3, 17]], 'pro-rata'], [['C3', 1], ['E5', 1]]], ['boundary control 1', [3, [['A1', 1, 1], ['B2', 1, 2], ['C3', 1, 3]], 'pro-rata'], [['A1', 1], ['B2', 1], ['C3', 1]]], ['boundary control 2', [2, [['A1', 5, 2], ['B2', 5, 1]], 'fifo'], [['B2', 2]]], ['normal control 1', [6, [['A1', 5, 2], ['B2', 10, 4]], 'pro-rata'], [['A1', 2], ['B2', 4]]], ['normal control 2', [1, [['A1', 1, 1]], 'pro-rata'], [['A1', 1]]]], [['regression remainder ranking 1', [12, [['B2', 5, 16], ['A1', 2, 18], ['F6', 10, 12], ['C3', 10, 17], ['E5', 2, 3]], 'pro-rata'], [['A1', 1], ['B2', 2], ['C3', 4], ['E5', 1], ['F6', 4]]], ['regression remainder ranking 2', [1, [['A1', 10, 12], ['B2', 3, 11], ['E5', 3, 1], ['D4', 2, 5], ['F6', 7, 18]], 'pro-rata'], [['A1', 1]]], ['partial repair probe 1', [3, [['E5', 1, 1], ['A1', 5, 13]], 'pro-rata'], [['A1', 2], ['E5', 1]]], ['boundary control 1', [3, [['A1', 1, 1], ['B2', 1, 2], ['C3', 1, 3]], 'pro-rata'], [['A1', 1], ['B2', 1], ['C3', 1]]], ['boundary control 2', [2, [['A1', 5, 2], ['B2', 5, 1]], 'fifo'], [['B2', 2]]], ['normal control 1', [9, [['D4', 10, 2]], 'pro-rata'], [['D4', 9]]], ['normal control 2', [7, [['C3', 3, 7], ['F6', 2, 2], ['B2', 2, 6]], 'fifo'], [['B2', 2], ['C3', 3], ['F6', 2]]], ['normal control 3', [6, [['F6', 5, 19], ['A1', 1, 6]], 'pro-rata'], [['A1', 1], ['F6', 5]]]]]
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)

meaning: Fixture-count band, not measured model difficulty

deps: stdlib

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(exercised, shorts, method):
    total = sum(q for _, q, _ in shorts)
    alloc = {}
    if method == 'fifo':
        left = exercised
        for acct, q, seq in sorted(shorts, key=lambda s: s[2]):
            take = min(q, left)
            alloc[acct] = alloc.get(acct, 0) + take
            left -= take
    else:
        rem = []
        for acct, q, seq in shorts:
            alloc[acct] = alloc.get(acct, 0) + exercised * q // total
            rem.append((-q, seq, acct))
        left = exercised - sum(alloc.values())
        for _, seq, acct in sorted(rem)[:left]:
            alloc[acct] += 1
    return sorted([a, n] for a, n in alloc.items() if n > 0)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression remainder ranking 1', [12, [['B2', 5, 6], ['A1', 2, 12], ['C3', 7, 10], ['E5', 1, 3]], 'pro-rata'], [['A1', 1], ['B2', 4], ['C3', 6], ['E5', 1]]], ['regression remainder ranking 2', [3, [['C3', 5, 10], ['D4', 2, 5]], 'pro-rata'], [['C3', 2], ['D4', 1]]], ['partial repair probe 1', [2, [['E5', 3, 17], ['A1', 1, 8]], 'pro-rata'], [['A1', 1], ['E5', 1]]], ['partial repair probe 2', [5, [['C3', 1, 5], ['B2', 3, 2], ['E5', 1, 8], ['A1', 5, 7]], 'pro-rata'], [['A1', 2], ['B2', 2], ['C3', 1]]], ['boundary control 1', [2, [['A1', 5, 2], ['B2', 5, 1]], 'fifo'], [['B2', 2]]], ['boundary control 2', [3, [['A1', 1, 1], ['B2', 1, 2], ['C3', 1, 3]], 'pro-rata'], [['A1', 1], ['B2', 1], ['C3', 1]]], ['normal control 1', [4, [['D4', 7, 13]], 'pro-rata'], [['D4', 4]]], ['normal control 2', [6, [['E5', 10, 11], ['F6', 7, 19]], 'fifo'], [['E5', 6]]]], [['regression remainder ranking 1', [12, [['A1', 3, 1], ['C3', 7, 18], ['B2', 7, 2], ['E5', 5, 5]], 'pro-rata'], [['A1', 1], ['B2', 4], ['C3', 4], ['E5', 3]]], ['regression remainder ranking 2', [1, [['A1', 7, 3], ['D4', 10, 11]], 'pro-rata'], [['D4', 1]]], ['partial repair probe 1', [9, [['F6', 3, 13], ['A1', 7, 16], ['C3', 3, 9], ['D4', 5, 7]], 'pro-rata'], [['A1', 3], ['C3', 2], ['D4', 3], ['F6', 1]]], ['partial repair probe 2', [8, [['C3', 7, 12], ['D4', 3, 5], ['A1', 3, 2], ['B2', 3, 11]], 'pro-rata'], [['A1', 2], ['B2', 1], ['C3', 3], ['D4', 2]]], ['boundary control 1', [2, [['A1', 5, 2], ['B2', 5, 1]], 'fifo'], [['B2', 2]]], ['boundary control 2', [3, [['A1', 1, 1], ['B2', 1, 2], ['C3', 1, 3]], 'pro-rata'], [['A1', 1], ['B2', 1], ['C3', 1]]], ['normal control 1', [3, [['D4', 3, 1]], 'pro-rata'], [['D4', 3]]], ['normal control 2', [7, [['E5', 7, 12]], 'pro-rata'], [['E5', 7]]]], [['regression remainder ranking 1', [13, [['E5', 7, 5], ['F6', 7, 1], ['D4', 10, 7], ['B2', 3, 10]], 'pro-rata'], [['B2', 2], ['D4', 5], ['E5', 3], ['F6', 3]]], ['regression remainder ranking 2', [6, [['B2', 2, 16], ['E5', 5, 6]], 'pro-rata'], [['B2', 2], ['E5', 4]]], ['partial repair probe 1', [5, [['E5', 3, 8], ['D4', 7, 18]], 'pro-rata'], [['D4', 3], ['E5', 2]]], ['partial repair probe 2', [4, [['B2', 3, 5], ['A1', 5, 6]], 'pro-rata'], [['A1', 2], ['B2', 2]]], ['boundary control 1', [3, [['A1', 1, 1], ['B2', 1, 2], ['C3', 1, 3]], 'pro-rata'], [['A1', 1], ['B2', 1], ['C3', 1]]], ['boundary control 2', [2, [['A1', 5, 2], ['B2', 5, 1]], 'fifo'], [['B2', 2]]], ['normal control 1', [2, [['B2', 3, 1]], 'fifo'], [['B2', 2]]], ['normal control 2', [2, [['F6', 5, 1]], 'pro-rata'], [['F6', 2]]]], [['regression remainder ranking 1', [11, [['A1', 3, 18], ['D4', 7, 8], ['F6', 5, 12]], 'pro-rata'], [['A1', 2], ['D4', 5], ['F6', 4]]], ['regression remainder ranking 2', [7, [['D4', 3, 19], ['B2', 5, 11], ['F6', 7, 12]], 'pro-rata'], [['B2', 2], ['D4', 2], ['F6', 3]]], ['partial repair probe 1', [5, [['D4', 7, 6], ['F6', 3, 10], ['C3', 7, 18], ['E5', 3, 1]], 'pro-rata'], [['C3', 1], ['D4', 2], ['E5', 1], ['F6', 1]]], ['partial repair probe 2', [2, [['C3', 1, 2], ['E5', 3, 17]], 'pro-rata'], [['C3', 1], ['E5', 1]]], ['boundary control 1', [3, [['A1', 1, 1], ['B2', 1, 2], ['C3', 1, 3]], 'pro-rata'], [['A1', 1], ['B2', 1], ['C3', 1]]], ['boundary control 2', [2, [['A1', 5, 2], ['B2', 5, 1]], 'fifo'], [['B2', 2]]], ['normal control 1', [6, [['A1', 5, 2], ['B2', 10, 4]], 'pro-rata'], [['A1', 2], ['B2', 4]]], ['normal control 2', [1, [['A1', 1, 1]], 'pro-rata'], [['A1', 1]]]], [['regression remainder ranking 1', [12, [['B2', 5, 16], ['A1', 2, 18], ['F6', 10, 12], ['C3', 10, 17], ['E5', 2, 3]], 'pro-rata'], [['A1', 1], ['B2', 2], ['C3', 4], ['E5', 1], ['F6', 4]]], ['regression remainder ranking 2', [1, [['A1', 10, 12], ['B2', 3, 11], ['E5', 3, 1], ['D4', 2, 5], ['F6', 7, 18]], 'pro-rata'], [['A1', 1]]], ['partial repair probe 1', [3, [['E5', 1, 1], ['A1', 5, 13]], 'pro-rata'], [['A1', 2], ['E5', 1]]], ['boundary control 1', [3, [['A1', 1, 1], ['B2', 1, 2], ['C3', 1, 3]], 'pro-rata'], [['A1', 1], ['B2', 1], ['C3', 1]]], ['boundary control 2', [2, [['A1', 5, 2], ['B2', 5, 1]], 'fifo'], [['B2', 2]]], ['normal control 1', [9, [['D4', 10, 2]], 'pro-rata'], [['D4', 9]]], ['normal control 2', [7, [['C3', 3, 7], ['F6', 2, 2], ['B2', 2, 6]], 'fifo'], [['B2', 2], ['C3', 3], ['F6', 2]]], ['normal control 3', [6, [['F6', 5, 19], ['A1', 1, 6]], 'pro-rata'], [['A1', 1], ['F6', 5]]]]]
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)

prompt:
Accounts closest to deserving another contract are skipped.

Inputs exercised contracts (<= total short), shorts [account, qty, open sequence] and method. fifo assigns in ascending open sequence, each up to its quantity. pro-rata gives floor(exercised*qty/total) and distributes the remaining contracts one each by largest fractional remainder, ties by lower open sequence. Return sorted [account, assigned] for accounts with assignments.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(exercised, shorts, method):
    total = sum(q for _, q, _ in shorts)
    alloc = {}
    if method == 'fifo':
        left = exercised
        for acct, q, seq in sorted(shorts, key=lambda s: s[2]):
            take = min(q, left)
            alloc[acct] = alloc.get(acct, 0) + take
            left -= take
    else:
        rem = []
        for acct, q, seq in shorts:
            alloc[acct] = alloc.get(acct, 0) + exercised * q // total
            rem.append((-(exercised * q % total), acct, acct))
        left = exercised - sum(alloc.values())
        for _, seq, acct in sorted(rem)[:left]:
            alloc[acct] += 1
    return sorted([a, n] for a, n in alloc.items() if n > 0)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression remainder tie break 1', [8, [['F6', 1, 1], ['C3', 2, 11], ['E5', 7, 8]], 'pro-rata'], [['C3', 1], ['E5', 6], ['F6', 1]]], ['regression remainder tie break 2', [5, [['E5', 3, 12], ['F6', 3, 10]], 'pro-rata'], [['E5', 2], ['F6', 3]]], ['partial repair probe 1', [8, [['F6', 1, 14], ['D4', 3, 11], ['C3', 3, 10], ['B2', 2, 18]], 'pro-rata'], [['B2', 2], ['C3', 3], ['D4', 2], ['F6', 1]]], ['partial repair probe 2', [16, [['F6', 10, 19], ['A1', 10, 8], ['D4', 3, 10], ['C3', 1, 12]], 'pro-rata'], [['A1', 7], ['C3', 1], ['D4', 2], ['F6', 6]]], ['boundary control 1', [2, [['A1', 5, 2], ['B2', 5, 1]], 'fifo'], [['B2', 2]]], ['boundary control 2', [3, [['A1', 1, 1], ['B2', 1, 2], ['C3', 1, 3]], 'pro-rata'], [['A1', 1], ['B2', 1], ['C3', 1]]], ['normal control 1', [1, [['F6', 2, 14]], 'fifo'], [['F6', 1]]], ['normal control 2', [4, [['F6', 1, 4], ['E5', 7, 18], ['C3', 5, 19], ['D4', 7, 8]], 'fifo'], [['D4', 3], ['F6', 1]]]], [['regression remainder tie break 1', [1, [['F6', 3, 8], ['B2', 7, 4], ['C3', 3, 19], ['D4', 7, 1]], 'pro-rata'], [['D4', 1]]], ['regression remainder tie break 2', [3, [['B2', 2, 6], ['D4', 2, 5]], 'pro-rata'], [['B2', 1], ['D4', 2]]], ['partial repair probe 1', [12, [['B2', 10, 4], ['A1', 1, 11], ['F6', 3, 10], ['E5', 2, 8]], 'pro-rata'], [['A1', 1], ['B2', 8], ['E5', 1], ['F6', 2]]], ['partial repair probe 2', [14, [['A1', 10, 9], ['F6', 7, 16], ['C3', 1, 4], ['B2', 3, 7]], 'pro-rata'], [['A1', 7], ['B2', 2], ['C3', 1], ['F6', 4]]], ['boundary control 1', [3, [['A1', 1, 1], ['B2', 1, 2], ['C3', 1, 3]], 'pro-rata'], [['A1', 1], ['B2', 1], ['C3', 1]]], ['boundary control 2', [2, [['A1', 5, 2], ['B2', 5, 1]], 'fifo'], [['B2', 2]]], ['normal control 1', [5, [['D4', 3, 2], ['C3', 7, 6], ['A1', 7, 13], ['B2', 3, 9]], 'fifo'], [['C3', 2], ['D4', 3]]], ['normal control 2', [1, [['F6', 1, 3]], 'pro-rata'], [['F6', 1]]]], [['regression remainder tie break 1', [8, [['D4', 1, 13], ['F6', 7, 9], ['B2', 2, 15]], 'pro-rata'], [['B2', 1], ['D4', 1], ['F6', 6]]], ['regression remainder tie break 2', [12, [['D4', 2, 19], ['B2', 7, 10], ['F6', 2, 13], ['E5', 3, 9], ['C3', 3, 11]], 'pro-rata'], [['B2', 5], ['C3', 2], ['D4', 1], ['E5', 2], ['F6', 2]]], ['partial repair probe 1', [24, [['D4', 3, 8], ['F6', 10, 19], ['B2', 2, 11], ['A1', 10, 9]], 'pro-rata'], [['A1', 10], ['B2', 2], ['D4', 3], ['F6', 9]]], ['partial repair probe 2', [9, [['B2', 3, 13], ['A1', 2, 2], ['E5', 2, 1], ['D4', 3, 17]], 'pro-rata'], [['A1', 2], ['B2', 3], ['D4', 2], ['E5', 2]]], ['boundary control 1', [2, [['A1', 5, 2], ['B2', 5, 1]], 'fifo'], [['B2', 2]]], ['boundary control 2', [3, [['A1', 1, 1], ['B2', 1, 2], ['C3', 1, 3]], 'pro-rata'], [['A1', 1], ['B2', 1], ['C3', 1]]], ['normal control 1', [10, [['E5', 10, 5], ['D4', 5, 10], ['F6', 1, 12], ['B2', 7, 2]], 'fifo'], [['B2', 7], ['E5', 3]]], ['normal control 2', [2, [['F6', 2, 4]], 'fifo'], [['F6', 2]]]], [['regression remainder tie break 1', [12, [['C3', 10, 6], ['E5', 3, 12], ['B2', 7, 8], ['D4', 1, 17], ['A1', 3, 18]], 'pro-rata'], [['A1', 1], ['B2', 4], ['C3', 5], ['E5', 2]]], ['regression remainder tie break 2', [14, [['D4', 3, 11], ['B2', 10, 16], ['C3', 2, 18], ['E5', 10, 9]], 'pro-rata'], [['B2', 5], ['C3', 1], ['D4', 2], ['E5', 6]]], ['partial repair probe 1', [7, [['C3', 1, 14], ['A1', 1, 11], ['F6', 2, 6], ['B2', 5, 5], ['D4', 5, 19]], 'pro-rata'], [['A1', 1], ['B2', 3], ['D4', 2], ['F6', 1]]], ['partial repair probe 2', [1, [['C3', 3, 4], ['A1', 1, 9], ['D4', 3, 6]], 'pro-rata'], [['C3', 1]]], ['boundary control 1', [2, [['A1', 5, 2], ['B2', 5, 1]], 'fifo'], [['B2', 2]]], ['boundary control 2', [3, [['A1', 1, 1], ['B2', 1, 2], ['C3', 1, 3]], 'pro-rata'], [['A1', 1], ['B2', 1], ['C3', 1]]], ['normal control 1', [6, [['C3', 10, 5], ['D4', 3, 15]], 'fifo'], [['C3', 6]]], ['normal control 2', [2, [['B2', 7, 5], ['F6', 7, 9]], 'pro-rata'], [['B2', 1], ['F6', 1]]]], [['regression remainder tie break 1', [15, [['A1', 7, 13], ['B2', 5, 14], ['C3', 5, 5]], 'pro-rata'], [['A1', 6], ['B2', 4], ['C3', 5]]], ['regression remainder tie break 2', [2, [['E5', 7, 6], ['C3', 7, 8], ['F6', 10, 11]], 'pro-rata'], [['E5', 1], ['F6', 1]]], ['partial repair probe 1', [9, [['D4', 7, 18], ['C3', 5, 1], ['F6', 3, 11], ['A1', 3, 3]], 'pro-rata'], [['A1', 2], ['C3', 3], ['D4', 3], ['F6', 1]]], ['partial repair probe 2', [7, [['D4', 1, 5], ['C3', 3, 3], ['A1', 1, 6], ['E5', 3, 8]], 'pro-rata'], [['A1', 1], ['C3', 3], ['D4', 1], ['E5', 2]]], ['boundary control 1', [3, [['A1', 1, 1], ['B2', 1, 2], ['C3', 1, 3]], 'pro-rata'], [['A1', 1], ['B2', 1], ['C3', 1]]], ['boundary control 2', [2, [['A1', 5, 2], ['B2', 5, 1]], 'fifo'], [['B2', 2]]], ['normal control 1', [1, [['C3', 3, 6]], 'pro-rata'], [['C3', 1]]], ['normal control 2', [1, [['D4', 5, 9], ['C3', 3, 2], ['F6', 3, 17], ['E5', 1, 11]], 'fifo'], [['C3', 1]]]]]
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)

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(exercised, shorts, method):
    total = sum(q for _, q, _ in shorts)
    alloc = {}
    if method == 'fifo':
        left = exercised
        for acct, q, seq in sorted(shorts, key=lambda s: s[2]):
            take = min(q, left)
            alloc[acct] = alloc.get(acct, 0) + take
            left -= take
    else:
        rem = []
        for acct, q, seq in shorts:
            alloc[acct] = alloc.get(acct, 0) + exercised * q // total
            rem.append((-(exercised * q % total), -seq, acct))
        left = exercised - sum(alloc.values())
        for _, seq, acct in sorted(rem)[:left]:
            alloc[acct] += 1
    return sorted([a, n] for a, n in alloc.items() if n > 0)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression remainder tie break 1', [8, [['F6', 1, 1], ['C3', 2, 11], ['E5', 7, 8]], 'pro-rata'], [['C3', 1], ['E5', 6], ['F6', 1]]], ['regression remainder tie break 2', [5, [['E5', 3, 12], ['F6', 3, 10]], 'pro-rata'], [['E5', 2], ['F6', 3]]], ['partial repair probe 1', [8, [['F6', 1, 14], ['D4', 3, 11], ['C3', 3, 10], ['B2', 2, 18]], 'pro-rata'], [['B2', 2], ['C3', 3], ['D4', 2], ['F6', 1]]], ['partial repair probe 2', [16, [['F6', 10, 19], ['A1', 10, 8], ['D4', 3, 10], ['C3', 1, 12]], 'pro-rata'], [['A1', 7], ['C3', 1], ['D4', 2], ['F6', 6]]], ['boundary control 1', [2, [['A1', 5, 2], ['B2', 5, 1]], 'fifo'], [['B2', 2]]], ['boundary control 2', [3, [['A1', 1, 1], ['B2', 1, 2], ['C3', 1, 3]], 'pro-rata'], [['A1', 1], ['B2', 1], ['C3', 1]]], ['normal control 1', [1, [['F6', 2, 14]], 'fifo'], [['F6', 1]]], ['normal control 2', [4, [['F6', 1, 4], ['E5', 7, 18], ['C3', 5, 19], ['D4', 7, 8]], 'fifo'], [['D4', 3], ['F6', 1]]]], [['regression remainder tie break 1', [1, [['F6', 3, 8], ['B2', 7, 4], ['C3', 3, 19], ['D4', 7, 1]], 'pro-rata'], [['D4', 1]]], ['regression remainder tie break 2', [3, [['B2', 2, 6], ['D4', 2, 5]], 'pro-rata'], [['B2', 1], ['D4', 2]]], ['partial repair probe 1', [12, [['B2', 10, 4], ['A1', 1, 11], ['F6', 3, 10], ['E5', 2, 8]], 'pro-rata'], [['A1', 1], ['B2', 8], ['E5', 1], ['F6', 2]]], ['partial repair probe 2', [14, [['A1', 10, 9], ['F6', 7, 16], ['C3', 1, 4], ['B2', 3, 7]], 'pro-rata'], [['A1', 7], ['B2', 2], ['C3', 1], ['F6', 4]]], ['boundary control 1', [3, [['A1', 1, 1], ['B2', 1, 2], ['C3', 1, 3]], 'pro-rata'], [['A1', 1], ['B2', 1], ['C3', 1]]], ['boundary control 2', [2, [['A1', 5, 2], ['B2', 5, 1]], 'fifo'], [['B2', 2]]], ['normal control 1', [5, [['D4', 3, 2], ['C3', 7, 6], ['A1', 7, 13], ['B2', 3, 9]], 'fifo'], [['C3', 2], ['D4', 3]]], ['normal control 2', [1, [['F6', 1, 3]], 'pro-rata'], [['F6', 1]]]], [['regression remainder tie break 1', [8, [['D4', 1, 13], ['F6', 7, 9], ['B2', 2, 15]], 'pro-rata'], [['B2', 1], ['D4', 1], ['F6', 6]]], ['regression remainder tie break 2', [12, [['D4', 2, 19], ['B2', 7, 10], ['F6', 2, 13], ['E5', 3, 9], ['C3', 3, 11]], 'pro-rata'], [['B2', 5], ['C3', 2], ['D4', 1], ['E5', 2], ['F6', 2]]], ['partial repair probe 1', [24, [['D4', 3, 8], ['F6', 10, 19], ['B2', 2, 11], ['A1', 10, 9]], 'pro-rata'], [['A1', 10], ['B2', 2], ['D4', 3], ['F6', 9]]], ['partial repair probe 2', [9, [['B2', 3, 13], ['A1', 2, 2], ['E5', 2, 1], ['D4', 3, 17]], 'pro-rata'], [['A1', 2], ['B2', 3], ['D4', 2], ['E5', 2]]], ['boundary control 1', [2, [['A1', 5, 2], ['B2', 5, 1]], 'fifo'], [['B2', 2]]], ['boundary control 2', [3, [['A1', 1, 1], ['B2', 1, 2], ['C3', 1, 3]], 'pro-rata'], [['A1', 1], ['B2', 1], ['C3', 1]]], ['normal control 1', [10, [['E5', 10, 5], ['D4', 5, 10], ['F6', 1, 12], ['B2', 7, 2]], 'fifo'], [['B2', 7], ['E5', 3]]], ['normal control 2', [2, [['F6', 2, 4]], 'fifo'], [['F6', 2]]]], [['regression remainder tie break 1', [12, [['C3', 10, 6], ['E5', 3, 12], ['B2', 7, 8], ['D4', 1, 17], ['A1', 3, 18]], 'pro-rata'], [['A1', 1], ['B2', 4], ['C3', 5], ['E5', 2]]], ['regression remainder tie break 2', [14, [['D4', 3, 11], ['B2', 10, 16], ['C3', 2, 18], ['E5', 10, 9]], 'pro-rata'], [['B2', 5], ['C3', 1], ['D4', 2], ['E5', 6]]], ['partial repair probe 1', [7, [['C3', 1, 14], ['A1', 1, 11], ['F6', 2, 6], ['B2', 5, 5], ['D4', 5, 19]], 'pro-rata'], [['A1', 1], ['B2', 3], ['D4', 2], ['F6', 1]]], ['partial repair probe 2', [1, [['C3', 3, 4], ['A1', 1, 9], ['D4', 3, 6]], 'pro-rata'], [['C3', 1]]], ['boundary control 1', [2, [['A1', 5, 2], ['B2', 5, 1]], 'fifo'], [['B2', 2]]], ['boundary control 2', [3, [['A1', 1, 1], ['B2', 1, 2], ['C3', 1, 3]], 'pro-rata'], [['A1', 1], ['B2', 1], ['C3', 1]]], ['normal control 1', [6, [['C3', 10, 5], ['D4', 3, 15]], 'fifo'], [['C3', 6]]], ['normal control 2', [2, [['B2', 7, 5], ['F6', 7, 9]], 'pro-rata'], [['B2', 1], ['F6', 1]]]], [['regression remainder tie break 1', [15, [['A1', 7, 13], ['B2', 5, 14], ['C3', 5, 5]], 'pro-rata'], [['A1', 6], ['B2', 4], ['C3', 5]]], ['regression remainder tie break 2', [2, [['E5', 7, 6], ['C3', 7, 8], ['F6', 10, 11]], 'pro-rata'], [['E5', 1], ['F6', 1]]], ['partial repair probe 1', [9, [['D4', 7, 18], ['C3', 5, 1], ['F6', 3, 11], ['A1', 3, 3]], 'pro-rata'], [['A1', 2], ['C3', 3], ['D4', 3], ['F6', 1]]], ['partial repair probe 2', [7, [['D4', 1, 5], ['C3', 3, 3], ['A1', 1, 6], ['E5', 3, 8]], 'pro-rata'], [['A1', 1], ['C3', 3], ['D4', 1], ['E5', 2]]], ['boundary control 1', [3, [['A1', 1, 1], ['B2', 1, 2], ['C3', 1, 3]], 'pro-rata'], [['A1', 1], ['B2', 1], ['C3', 1]]], ['boundary control 2', [2, [['A1', 5, 2], ['B2', 5, 1]], 'fifo'], [['B2', 2]]], ['normal control 1', [1, [['C3', 3, 6]], 'pro-rata'], [['C3', 1]]], ['normal control 2', [1, [['D4', 5, 9], ['C3', 3, 2], ['F6', 3, 17], ['E5', 1, 11]], 'fifo'], [['C3', 1]]]]]
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)

prompt:
Ties go to alphabetically earlier accounts instead of older positions.

Inputs exercised contracts (<= total short), shorts [account, qty, open sequence] and method. fifo assigns in ascending open sequence, each up to its quantity. pro-rata gives floor(exercised*qty/total) and distributes the remaining contracts one each by largest fractional remainder, ties by lower open sequence. Return sorted [account, assigned] for accounts with assignments.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(exercised, shorts, method):
    total = sum(q for _, q, _ in shorts)
    alloc = {}
    if method == 'fifo':
        left = exercised
        for acct, q, seq in sorted(shorts, key=lambda s: s[2]):
            take = q if left > 0 else 0
            alloc[acct] = alloc.get(acct, 0) + take
            left -= take
    else:
        rem = []
        for acct, q, seq in shorts:
            alloc[acct] = alloc.get(acct, 0) + exercised * q // total
            rem.append((-(exercised * q % total), seq, acct))
        left = exercised - sum(alloc.values())
        for _, seq, acct in sorted(rem)[:left]:
            alloc[acct] += 1
    return sorted([a, n] for a, n in alloc.items() if n > 0)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression fifo allocation cap 1', [1, [['A1', 2, 17]], 'fifo'], [['A1', 1]]], ['regression fifo allocation cap 2', [1, [['F6', 7, 15]], 'fifo'], [['F6', 1]]], ['partial repair probe 1', [3, [['A1', 7, 19], ['E5', 2, 4], ['F6', 1, 15], ['D4', 3, 3]], 'fifo'], [['D4', 3]]], ['partial repair probe 2', [3, [['E5', 3, 8], ['D4', 3, 19]], 'fifo'], [['E5', 3]]], ['boundary control 1', [3, [['A1', 1, 1], ['B2', 1, 2], ['C3', 1, 3]], 'pro-rata'], [['A1', 1], ['B2', 1], ['C3', 1]]], ['normal control 1', [7, [['D4', 10, 16], ['E5', 1, 18], ['C3', 3, 13], ['A1', 1, 8]], 'pro-rata'], [['A1', 1], ['C3', 1], ['D4', 5]]], ['normal control 2', [3, [['E5', 3, 14], ['F6', 2, 15], ['A1', 2, 1], ['B2', 5, 2], ['D4', 1, 12]], 'pro-rata'], [['A1', 1], ['B2', 1], ['E5', 1]]], ['normal control 3', [2, [['F6', 2, 4]], 'pro-rata'], [['F6', 2]]]], [['regression fifo allocation cap 1', [14, [['C3', 10, 2], ['E5', 3, 5], ['A1', 3, 9], ['F6', 3, 8]], 'fifo'], [['C3', 10], ['E5', 3], ['F6', 1]]], ['regression fifo allocation cap 2', [9, [['B2', 7, 18], ['E5', 7, 5], ['C3', 1, 6]], 'fifo'], [['B2', 1], ['C3', 1], ['E5', 7]]], ['partial repair probe 1', [6, [['C3', 1, 11], ['A1', 3, 14], ['B2', 3, 16], ['D4', 2, 4]], 'fifo'], [['A1', 3], ['C3', 1], ['D4', 2]]], ['partial repair probe 2', [2, [['C3', 1, 6], ['F6', 1, 2], ['E5', 2, 1], ['B2', 7, 15]], 'fifo'], [['E5', 2]]], ['boundary control 1', [3, [['A1', 1, 1], ['B2', 1, 2], ['C3', 1, 3]], 'pro-rata'], [['A1', 1], ['B2', 1], ['C3', 1]]], ['normal control 1', [7, [['B2', 10, 14], ['F6', 3, 1], ['C3', 1, 5], ['A1', 5, 11], ['D4', 3, 9]], 'pro-rata'], [['A1', 2], ['B2', 3], ['D4', 1], ['F6', 1]]], ['normal control 2', [7, [['E5', 10, 1], ['A1', 5, 8], ['D4', 3, 18]], 'pro-rata'], [['A1', 2], ['D4', 1], ['E5', 4]]], ['normal control 3', [1, [['D4', 2, 17]], 'pro-rata'], [['D4', 1]]]], [['regression fifo allocation cap 1', [1, [['A1', 3, 7]], 'fifo'], [['A1', 1]]], ['regression fifo allocation cap 2', [1, [['B2', 2, 12]], 'fifo'], [['B2', 1]]], ['partial repair probe 1', [5, [['B2', 7, 13], ['A1', 3, 6], ['C3', 2, 5], ['F6', 2, 12]], 'fifo'], [['A1', 3], ['C3', 2]]], ['partial repair probe 2', [12, [['C3', 3, 10], ['F6', 3, 2], ['D4', 7, 3], ['B2', 5, 18], ['A1', 2, 8]], 'fifo'], [['A1', 2], ['D4', 7], ['F6', 3]]], ['boundary control 1', [3, [['A1', 1, 1], ['B2', 1, 2], ['C3', 1, 3]], 'pro-rata'], [['A1', 1], ['B2', 1], ['C3', 1]]], ['normal control 1', [6, [['F6', 10, 18], ['C3', 2, 1], ['E5', 3, 10], ['D4', 10, 4]], 'pro-rata'], [['C3', 1], ['D4', 2], ['E5', 1], ['F6', 2]]], ['normal control 2', [4, [['B2', 2, 1], ['F6', 2, 8]], 'pro-rata'], [['B2', 2], ['F6', 2]]], ['normal control 3', [6, [['F6', 7, 17], ['D4', 3, 4], ['B2', 1, 2]], 'pro-rata'], [['D4', 2], ['F6', 4]]]], [['regression fifo allocation cap 1', [6, [['F6', 3, 4], ['C3', 10, 16], ['E5', 7, 13]], 'fifo'], [['E5', 3], ['F6', 3]]], ['regression fifo allocation cap 2', [6, [['C3', 10, 3], ['A1', 7, 2], ['B2', 2, 9], ['F6', 3, 12]], 'fifo'], [['A1', 6]]], ['partial repair probe 1', [4, [['B2', 1, 6], ['D4', 10, 18], ['A1', 3, 13]], 'fifo'], [['A1', 3], ['B2', 1]]], ['partial repair probe 2', [7, [['B2', 3, 4], ['A1', 10, 14], ['E5', 1, 10], ['D4', 3, 11], ['C3', 3, 19]], 'fifo'], [['B2', 3], ['D4', 3], ['E5', 1]]], ['boundary control 1', [3, [['A1', 1, 1], ['B2', 1, 2], ['C3', 1, 3]], 'pro-rata'], [['A1', 1], ['B2', 1], ['C3', 1]]], ['normal control 1', [3, [['F6', 3, 13], ['E5', 10, 14], ['C3', 2, 8], ['B2', 3, 4], ['A1', 3, 11]], 'pro-rata'], [['A1', 1], ['B2', 1], ['E5', 1]]], ['normal control 2', [10, [['F6', 5, 17], ['A1', 3, 3], ['C3', 7, 18]], 'pro-rata'], [['A1', 2], ['C3', 5], ['F6', 3]]], ['normal control 3', [7, [['C3', 5, 8], ['F6', 3, 5], ['D4', 10, 14]], 'pro-rata'], [['C3', 2], ['D4', 4], ['F6', 1]]]], [['regression fifo allocation cap 1', [12, [['B2', 5, 18], ['C3', 3, 13], ['E5', 2, 5], ['D4', 5, 14]], 'fifo'], [['B2', 2], ['C3', 3], ['D4', 5], ['E5', 2]]], ['regression fifo allocation cap 2', [4, [['B2', 10, 14], ['A1', 3, 4], ['D4', 3, 6], ['C3', 3, 13]], 'fifo'], [['A1', 3], ['D4', 1]]], ['partial repair probe 1', [8, [['F6', 5, 17], ['E5', 3, 14], ['C3', 2, 18]], 'fifo'], [['E5', 3], ['F6', 5]]], ['partial repair probe 2', [1, [['E5', 5, 14], ['A1', 1, 1]], 'fifo'], [['A1', 1]]], ['boundary control 1', [3, [['A1', 1, 1], ['B2', 1, 2], ['C3', 1, 3]], 'pro-rata'], [['A1', 1], ['B2', 1], ['C3', 1]]], ['normal control 1', [3, [['B2', 10, 9]], 'pro-rata'], [['B2', 3]]], ['normal control 2', [2, [['A1', 1, 12], ['F6', 3, 5], ['B2', 7, 13], ['E5', 10, 4]], 'pro-rata'], [['B2', 1], ['E5', 1]]], ['normal control 3', [2, [['C3', 5, 3]], 'pro-rata'], [['C3', 2]]]]]
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)

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(exercised, shorts, method):
    total = sum(q for _, q, _ in shorts)
    alloc = {}
    if method == 'fifo':
        left = exercised
        for acct, q, seq in sorted(shorts, key=lambda s: s[2]):
            take = min(q, exercised)
            alloc[acct] = alloc.get(acct, 0) + take
            left -= take
    else:
        rem = []
        for acct, q, seq in shorts:
            alloc[acct] = alloc.get(acct, 0) + exercised * q // total
            rem.append((-(exercised * q % total), seq, acct))
        left = exercised - sum(alloc.values())
        for _, seq, acct in sorted(rem)[:left]:
            alloc[acct] += 1
    return sorted([a, n] for a, n in alloc.items() if n > 0)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression fifo allocation cap 1', [1, [['A1', 2, 17]], 'fifo'], [['A1', 1]]], ['regression fifo allocation cap 2', [1, [['F6', 7, 15]], 'fifo'], [['F6', 1]]], ['partial repair probe 1', [3, [['A1', 7, 19], ['E5', 2, 4], ['F6', 1, 15], ['D4', 3, 3]], 'fifo'], [['D4', 3]]], ['partial repair probe 2', [3, [['E5', 3, 8], ['D4', 3, 19]], 'fifo'], [['E5', 3]]], ['boundary control 1', [3, [['A1', 1, 1], ['B2', 1, 2], ['C3', 1, 3]], 'pro-rata'], [['A1', 1], ['B2', 1], ['C3', 1]]], ['normal control 1', [7, [['D4', 10, 16], ['E5', 1, 18], ['C3', 3, 13], ['A1', 1, 8]], 'pro-rata'], [['A1', 1], ['C3', 1], ['D4', 5]]], ['normal control 2', [3, [['E5', 3, 14], ['F6', 2, 15], ['A1', 2, 1], ['B2', 5, 2], ['D4', 1, 12]], 'pro-rata'], [['A1', 1], ['B2', 1], ['E5', 1]]], ['normal control 3', [2, [['F6', 2, 4]], 'pro-rata'], [['F6', 2]]]], [['regression fifo allocation cap 1', [14, [['C3', 10, 2], ['E5', 3, 5], ['A1', 3, 9], ['F6', 3, 8]], 'fifo'], [['C3', 10], ['E5', 3], ['F6', 1]]], ['regression fifo allocation cap 2', [9, [['B2', 7, 18], ['E5', 7, 5], ['C3', 1, 6]], 'fifo'], [['B2', 1], ['C3', 1], ['E5', 7]]], ['partial repair probe 1', [6, [['C3', 1, 11], ['A1', 3, 14], ['B2', 3, 16], ['D4', 2, 4]], 'fifo'], [['A1', 3], ['C3', 1], ['D4', 2]]], ['partial repair probe 2', [2, [['C3', 1, 6], ['F6', 1, 2], ['E5', 2, 1], ['B2', 7, 15]], 'fifo'], [['E5', 2]]], ['boundary control 1', [3, [['A1', 1, 1], ['B2', 1, 2], ['C3', 1, 3]], 'pro-rata'], [['A1', 1], ['B2', 1], ['C3', 1]]], ['normal control 1', [7, [['B2', 10, 14], ['F6', 3, 1], ['C3', 1, 5], ['A1', 5, 11], ['D4', 3, 9]], 'pro-rata'], [['A1', 2], ['B2', 3], ['D4', 1], ['F6', 1]]], ['normal control 2', [7, [['E5', 10, 1], ['A1', 5, 8], ['D4', 3, 18]], 'pro-rata'], [['A1', 2], ['D4', 1], ['E5', 4]]], ['normal control 3', [1, [['D4', 2, 17]], 'pro-rata'], [['D4', 1]]]], [['regression fifo allocation cap 1', [1, [['A1', 3, 7]], 'fifo'], [['A1', 1]]], ['regression fifo allocation cap 2', [1, [['B2', 2, 12]], 'fifo'], [['B2', 1]]], ['partial repair probe 1', [5, [['B2', 7, 13], ['A1', 3, 6], ['C3', 2, 5], ['F6', 2, 12]], 'fifo'], [['A1', 3], ['C3', 2]]], ['partial repair probe 2', [12, [['C3', 3, 10], ['F6', 3, 2], ['D4', 7, 3], ['B2', 5, 18], ['A1', 2, 8]], 'fifo'], [['A1', 2], ['D4', 7], ['F6', 3]]], ['boundary control 1', [3, [['A1', 1, 1], ['B2', 1, 2], ['C3', 1, 3]], 'pro-rata'], [['A1', 1], ['B2', 1], ['C3', 1]]], ['normal control 1', [6, [['F6', 10, 18], ['C3', 2, 1], ['E5', 3, 10], ['D4', 10, 4]], 'pro-rata'], [['C3', 1], ['D4', 2], ['E5', 1], ['F6', 2]]], ['normal control 2', [4, [['B2', 2, 1], ['F6', 2, 8]], 'pro-rata'], [['B2', 2], ['F6', 2]]], ['normal control 3', [6, [['F6', 7, 17], ['D4', 3, 4], ['B2', 1, 2]], 'pro-rata'], [['D4', 2], ['F6', 4]]]], [['regression fifo allocation cap 1', [6, [['F6', 3, 4], ['C3', 10, 16], ['E5', 7, 13]], 'fifo'], [['E5', 3], ['F6', 3]]], ['regression fifo allocation cap 2', [6, [['C3', 10, 3], ['A1', 7, 2], ['B2', 2, 9], ['F6', 3, 12]], 'fifo'], [['A1', 6]]], ['partial repair probe 1', [4, [['B2', 1, 6], ['D4', 10, 18], ['A1', 3, 13]], 'fifo'], [['A1', 3], ['B2', 1]]], ['partial repair probe 2', [7, [['B2', 3, 4], ['A1', 10, 14], ['E5', 1, 10], ['D4', 3, 11], ['C3', 3, 19]], 'fifo'], [['B2', 3], ['D4', 3], ['E5', 1]]], ['boundary control 1', [3, [['A1', 1, 1], ['B2', 1, 2], ['C3', 1, 3]], 'pro-rata'], [['A1', 1], ['B2', 1], ['C3', 1]]], ['normal control 1', [3, [['F6', 3, 13], ['E5', 10, 14], ['C3', 2, 8], ['B2', 3, 4], ['A1', 3, 11]], 'pro-rata'], [['A1', 1], ['B2', 1], ['E5', 1]]], ['normal control 2', [10, [['F6', 5, 17], ['A1', 3, 3], ['C3', 7, 18]], 'pro-rata'], [['A1', 2], ['C3', 5], ['F6', 3]]], ['normal control 3', [7, [['C3', 5, 8], ['F6', 3, 5], ['D4', 10, 14]], 'pro-rata'], [['C3', 2], ['D4', 4], ['F6', 1]]]], [['regression fifo allocation cap 1', [12, [['B2', 5, 18], ['C3', 3, 13], ['E5', 2, 5], ['D4', 5, 14]], 'fifo'], [['B2', 2], ['C3', 3], ['D4', 5], ['E5', 2]]], ['regression fifo allocation cap 2', [4, [['B2', 10, 14], ['A1', 3, 4], ['D4', 3, 6], ['C3', 3, 13]], 'fifo'], [['A1', 3], ['D4', 1]]], ['partial repair probe 1', [8, [['F6', 5, 17], ['E5', 3, 14], ['C3', 2, 18]], 'fifo'], [['E5', 3], ['F6', 5]]], ['partial repair probe 2', [1, [['E5', 5, 14], ['A1', 1, 1]], 'fifo'], [['A1', 1]]], ['boundary control 1', [3, [['A1', 1, 1], ['B2', 1, 2], ['C3', 1, 3]], 'pro-rata'], [['A1', 1], ['B2', 1], ['C3', 1]]], ['normal control 1', [3, [['B2', 10, 9]], 'pro-rata'], [['B2', 3]]], ['normal control 2', [2, [['A1', 1, 12], ['F6', 3, 5], ['B2', 7, 13], ['E5', 10, 4]], 'pro-rata'], [['B2', 1], ['E5', 1]]], ['normal control 3', [2, [['C3', 5, 3]], 'pro-rata'], [['C3', 2]]]]]
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)

prompt:
More contracts are assigned than were exercised.

Inputs exercised contracts (<= total short), shorts [account, qty, open sequence] and method. fifo assigns in ascending open sequence, each up to its quantity. pro-rata gives floor(exercised*qty/total) and distributes the remaining contracts one each by largest fractional remainder, ties by lower open sequence. Return sorted [account, assigned] for accounts with assignments.

split: open-access


prompt:
Buying back a short option at a lower premium records a loss.

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].

split: open-access


prompt:
Realized P&L follows LIFO instead of FIFO.

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].

split: open-access


prompt:
Selling more than the long position closes it but never opens the short.

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].

split: open-access


prompt:
Multi-contract trades are undercharged.

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].

split: open-access


prompt:
Floating-strike calls ignore a minimum set at inception.

Inputs kind, the observed path including initial and final prices, and strike. float-call pays final - min(path); float-put pays max(path) - final; fixed-call pays max(max(path) - K, 0); fixed-put pays max(K - min(path), 0). Round to 6.

split: open-access


prompt:
Floating-strike puts produce negative payoffs.

Inputs kind, the observed path including initial and final prices, and strike. float-call pays final - min(path); float-put pays max(path) - final; fixed-call pays max(max(path) - K, 0); fixed-put pays max(K - min(path), 0). Round to 6.

split: open-access


prompt:
Paths that never exceed the strike charge the holder.

Inputs kind, the observed path including initial and final prices, and strike. float-call pays final - min(path); float-put pays max(path) - final; fixed-call pays max(max(path) - K, 0); fixed-put pays max(K - min(path), 0). Round to 6.

split: open-access


prompt:
Fixed-strike puts rarely pay.

Inputs kind, the observed path including initial and final prices, and strike. float-call pays final - min(path); float-put pays max(path) - final; fixed-call pays max(max(path) - K, 0); fixed-put pays max(K - min(path), 0). Round to 6.

split: open-access


prompt:
Later periods compound earlier moves into their returns.

Inputs reset prices (first is the initial level), local cap, local floor, global floor and notional. Each period return is S_i/S_{i-1} - 1 clipped to [local floor, local cap]. Payoff = notional * max(global floor, sum of clipped returns), in exact fractions, rounded to 6.

split: open-access


prompt:
Large negative periods are not floored.

Inputs reset prices (first is the initial level), local cap, local floor, global floor and notional. Each period return is S_i/S_{i-1} - 1 clipped to [local floor, local cap]. Payoff = notional * max(global floor, sum of clipped returns), in exact fractions, rounded to 6.

split: open-access


prompt:
Guaranteed minimum coupons above zero are not honored.

Inputs reset prices (first is the initial level), local cap, local floor, global floor and notional. Each period return is S_i/S_{i-1} - 1 clipped to [local floor, local cap]. Payoff = notional * max(global floor, sum of clipped returns), in exact fractions, rounded to 6.

split: open-access


prompt:
Pip-quoted premiums are thousands of times too large.

Inputs quote, quote type, base notional, spot and pip size. pips: term premium = quote*pip*notional, base = term/spot. pct_base: base = quote/100*notional, term = base*spot. pct_term: term = quote/100*notional*spot, base = term/spot. Exact fractions; return [term, base] rounded to 2 as floats.

split: open-access


prompt:
Term-percent premiums ignore the spot conversion of the notional.

Inputs quote, quote type, base notional, spot and pip size. pips: term premium = quote*pip*notional, base = term/spot. pct_base: base = quote/100*notional, term = base*spot. pct_term: term = quote/100*notional*spot, base = term/spot. Exact fractions; return [term, base] rounded to 2 as floats.

split: open-access


prompt:
Base-currency equivalents of pip premiums are spot-squared off.

Inputs quote, quote type, base notional, spot and pip size. pips: term premium = quote*pip*notional, base = term/spot. pct_base: base = quote/100*notional, term = base*spot. pct_term: term = quote/100*notional*spot, base = term/spot. Exact fractions; return [term, base] rounded to 2 as floats.

split: open-access


prompt:
Term equivalents of base-percent premiums are wrong for any spot other than one.

Inputs quote, quote type, base notional, spot and pip size. pips: term premium = quote*pip*notional, base = term/spot. pct_base: base = quote/100*notional, term = base*spot. pct_term: term = quote/100*notional*spot, base = term/spot. Exact fractions; return [term, base] rounded to 2 as floats.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
N = 1
observations = []
def solve(kind, price, S, K, r, T):
    def N(x):
        return 0.5 * (1 + math.erf(x / math.sqrt(2)))
    def bs(v):
        d1 = (math.log(S / K) + (r + 0.5 * v * v) * T) / (v * math.sqrt(T))
        d2 = d1 - v * math.sqrt(T)
        if kind == 'C':
            return S * N(d1) - K * math.exp(-r * T) * N(d2)
        return K * math.exp(-r * T) * N(-d2) - S * N(-d1)
    disc_k = K * math.exp(-r * T)
    lower = max(S - K, 0) if kind == 'C' else max(K - S, 0)
    upper = S if kind == 'C' else disc_k
    if price <= lower or price >= upper:
        return None
    lo, hi = 1e-6, 5.0
    for _ in range(100):
        mid = (lo + hi) / 2
        if bs(mid) > price:
            hi = mid
        else:
            lo = mid
    return round((lo + hi) / 2, 4)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression lower arbitrage bound 1', ['P', 6.9002, 100.0, 120.0, 0.08, 2.0], 0.1], ['regression lower arbitrage bound 2', ['C', 22.0232, 110.0, 95.0, 0.08, 2.0], None], ['partial repair probe 1', ['P', 0.01, 100.0, 95.0, 0.03, 2.0], 0.0321], ['partial repair probe 2', ['P', 0.0713, 110.0, 95.0, 0.08, 2.0], 0.1], ['normal control 1', ['C', 32.8627, 100.0, 100.0, 0.0, 2.0], 0.6], ['normal control 2', ['C', 0.0, 100.0, 100.0, 0.0, 0.25], None], ['normal control 3', ['C', 100.0, 100.0, 100.0, 0.03, 2.0], None], ['normal control 4', ['C', 47.0024, 100.0, 100.0, 0.03, 0.25], 2.5]], [['regression lower arbitrage bound 1', ['P', 6.1558, 90.0, 100.0, 0.08, 1.0], 0.1352], ['regression lower arbitrage bound 2', ['C', 12.2939, 100.0, 95.0, 0.08, 1.0], None], ['partial repair probe 1', ['P', 1.1273, 100.0, 95.0, 0.03, 1.0], 0.1], ['partial repair probe 2', ['P', 2.2473, 100.0, 120.0, 0.08, 2.0], None], ['normal control 1', ['C', 19.4236, 100.0, 95.0, 0.08, 2.0], 0.1], ['normal control 2', ['C', 32.8627, 100.0, 100.0, 0.0, 2.0], 0.6], ['normal control 3', ['P', 12.0217, 90.0, 100.0, 0.0, 0.25], 0.3], ['normal control 4', ['C', 43.9475, 110.0, 95.0, 0.03, 2.0], 0.6]], [['regression lower arbitrage bound 1', ['C', 22.0232, 110.0, 95.0, 0.08, 2.0], None], ['regression lower arbitrage bound 2', ['C', 10.9901, 110.0, 100.0, 0.08, 0.25], None], ['partial repair probe 1', ['P', 2.2473, 100.0, 120.0, 0.08, 2.0], None], ['partial repair probe 2', ['P', 5.01, 90.0, 95.0, 0.08, 2.0], 0.1832], ['normal control 1', ['C', 91.9882, 100.0, 100.0, 0.0, 1.0], 3.5], ['normal control 2', ['C', 68.1279, 90.0, 120.0, 0.0, 1.0], 2.5], ['normal control 3', ['P', 104.819, 100.0, 120.0, 0.03, 2.0], 2.5], ['normal control 4', ['P', 120.0, 100.0, 120.0, 0.0, 2.0], None]], [['regression lower arbitrage bound 1', ['C', 0.01, 100.0, 100.0, 0.08, 2.0], None], ['regression lower arbitrage bound 2', ['C', 9.0363, 90.0, 95.0, 0.08, 2.0], None], ['partial repair probe 1', ['P', 0.01, 110.0, 100.0, 0.08, 0.25], 0.0927], ['partial repair probe 2', ['P', 0.2861, 100.0, 95.0, 0.03, 0.25], 0.1], ['normal control 1', ['C', 89.2978, 110.0, 95.0, 0.08, 1.0], 2.5], ['normal control 2', ['C', 22.3436, 110.0, 95.0, 0.08, 1.0], 0.1], ['normal control 3', ['C', 28.1884, 100.0, 95.0, 0.08, 0.25], 1.3], ['normal control 4', ['C', 100.0, 100.0, 95.0, 0.08, 1.0], None]], [['regression lower arbitrage bound 1', ['P', 19.1037, 100.0, 120.0, 0.03, 0.25], 0.1002], ['regression lower arbitrage bound 2', ['P', 2.8891, 110.0, 120.0, 0.08, 2.0], 0.1], ['partial repair probe 1', ['P', 7.4876, 100.0, 95.0, 0.08, 2.0], 0.3], ['partial repair probe 2', ['P', 9.99, 90.0, 100.0, 0.0, 1.0], None], ['normal control 1', ['P', 92.5421, 110.0, 120.0, 0.03, 1.0], 2.5], ['normal control 2', ['P', 100.0, 90.0, 100.0, 0.0, 2.0], None], ['normal control 3', ['P', 0.0, 100.0, 95.0, 0.03, 2.0], None], ['normal control 4', ['C', 0, 90.0, 100.0, 0.03, 0.25], None]]]
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)

source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
N = 1
observations = []
def solve(kind, price, S, K, r, T):
    def N(x):
        return 0.5 * (1 + math.erf(x / math.sqrt(2)))
    def bs(v):
        d1 = (math.log(S / K) + (r + 0.5 * v * v) * T) / (v * math.sqrt(T))
        d2 = d1 - v * math.sqrt(T)
        if kind == 'C':
            return S * N(d1) - K * math.exp(-r * T) * N(d2)
        return K * math.exp(-r * T) * N(-d2) - S * N(-d1)
    disc_k = K * math.exp(-r * T)
    lower = max(S - disc_k, 0)
    upper = S if kind == 'C' else disc_k
    if price <= lower or price >= upper:
        return None
    lo, hi = 1e-6, 5.0
    for _ in range(100):
        mid = (lo + hi) / 2
        if bs(mid) > price:
            hi = mid
        else:
            lo = mid
    return round((lo + hi) / 2, 4)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression lower arbitrage bound 1', ['P', 6.9002, 100.0, 120.0, 0.08, 2.0], 0.1], ['regression lower arbitrage bound 2', ['C', 22.0232, 110.0, 95.0, 0.08, 2.0], None], ['partial repair probe 1', ['P', 0.01, 100.0, 95.0, 0.03, 2.0], 0.0321], ['partial repair probe 2', ['P', 0.0713, 110.0, 95.0, 0.08, 2.0], 0.1], ['normal control 1', ['C', 32.8627, 100.0, 100.0, 0.0, 2.0], 0.6], ['normal control 2', ['C', 0.0, 100.0, 100.0, 0.0, 0.25], None], ['normal control 3', ['C', 100.0, 100.0, 100.0, 0.03, 2.0], None], ['normal control 4', ['C', 47.0024, 100.0, 100.0, 0.03, 0.25], 2.5]], [['regression lower arbitrage bound 1', ['P', 6.1558, 90.0, 100.0, 0.08, 1.0], 0.1352], ['regression lower arbitrage bound 2', ['C', 12.2939, 100.0, 95.0, 0.08, 1.0], None], ['partial repair probe 1', ['P', 1.1273, 100.0, 95.0, 0.03, 1.0], 0.1], ['partial repair probe 2', ['P', 2.2473, 100.0, 120.0, 0.08, 2.0], None], ['normal control 1', ['C', 19.4236, 100.0, 95.0, 0.08, 2.0], 0.1], ['normal control 2', ['C', 32.8627, 100.0, 100.0, 0.0, 2.0], 0.6], ['normal control 3', ['P', 12.0217, 90.0, 100.0, 0.0, 0.25], 0.3], ['normal control 4', ['C', 43.9475, 110.0, 95.0, 0.03, 2.0], 0.6]], [['regression lower arbitrage bound 1', ['C', 22.0232, 110.0, 95.0, 0.08, 2.0], None], ['regression lower arbitrage bound 2', ['C', 10.9901, 110.0, 100.0, 0.08, 0.25], None], ['partial repair probe 1', ['P', 2.2473, 100.0, 120.0, 0.08, 2.0], None], ['partial repair probe 2', ['P', 5.01, 90.0, 95.0, 0.08, 2.0], 0.1832], ['normal control 1', ['C', 91.9882, 100.0, 100.0, 0.0, 1.0], 3.5], ['normal control 2', ['C', 68.1279, 90.0, 120.0, 0.0, 1.0], 2.5], ['normal control 3', ['P', 104.819, 100.0, 120.0, 0.03, 2.0], 2.5], ['normal control 4', ['P', 120.0, 100.0, 120.0, 0.0, 2.0], None]], [['regression lower arbitrage bound 1', ['C', 0.01, 100.0, 100.0, 0.08, 2.0], None], ['regression lower arbitrage bound 2', ['C', 9.0363, 90.0, 95.0, 0.08, 2.0], None], ['partial repair probe 1', ['P', 0.01, 110.0, 100.0, 0.08, 0.25], 0.0927], ['partial repair probe 2', ['P', 0.2861, 100.0, 95.0, 0.03, 0.25], 0.1], ['normal control 1', ['C', 89.2978, 110.0, 95.0, 0.08, 1.0], 2.5], ['normal control 2', ['C', 22.3436, 110.0, 95.0, 0.08, 1.0], 0.1], ['normal control 3', ['C', 28.1884, 100.0, 95.0, 0.08, 0.25], 1.3], ['normal control 4', ['C', 100.0, 100.0, 95.0, 0.08, 1.0], None]], [['regression lower arbitrage bound 1', ['P', 19.1037, 100.0, 120.0, 0.03, 0.25], 0.1002], ['regression lower arbitrage bound 2', ['P', 2.8891, 110.0, 120.0, 0.08, 2.0], 0.1], ['partial repair probe 1', ['P', 7.4876, 100.0, 95.0, 0.08, 2.0], 0.3], ['partial repair probe 2', ['P', 9.99, 90.0, 100.0, 0.0, 1.0], None], ['normal control 1', ['P', 92.5421, 110.0, 120.0, 0.03, 1.0], 2.5], ['normal control 2', ['P', 100.0, 90.0, 100.0, 0.0, 2.0], None], ['normal control 3', ['P', 0.0, 100.0, 95.0, 0.03, 2.0], None], ['normal control 4', ['C', 0, 90.0, 100.0, 0.03, 0.25], None]]]
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)

prompt:
Prices between discounted and undiscounted intrinsic are rejected or solved inconsistently.

Inputs kind, option price, S, K, r, T (no dividends). If price <= lower bound (call max(S - K e^{-rT},0), put max(K e^{-rT} - S,0)) or price >= upper bound (call S, put K e^{-rT}) return None. Otherwise bisect sigma in [1e-6, 5] for 100 iterations on the Black-Scholes price and return the midpoint rounded to 4.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
N = 1
observations = []
def solve(kind, price, S, K, r, T):
    def N(x):
        return 0.5 * (1 + math.erf(x / math.sqrt(2)))
    def bs(v):
        d1 = (math.log(S / K) + (r + 0.5 * v * v) * T) / (v * math.sqrt(T))
        d2 = d1 - v * math.sqrt(T)
        if kind == 'C':
            return S * N(d1) - K * math.exp(-r * T) * N(d2)
        return K * math.exp(-r * T) * N(-d2) - S * N(-d1)
    disc_k = K * math.exp(-r * T)
    lower = max(S - disc_k, 0) if kind == 'C' else max(disc_k - S, 0)
    upper = S if kind == 'C' else disc_k
    if price <= lower or price >= upper:
        return None
    lo, hi = 1e-6, 1.0
    for _ in range(100):
        mid = (lo + hi) / 2
        if bs(mid) > price:
            hi = mid
        else:
            lo = mid
    return round((lo + hi) / 2, 4)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression volatility search bracket 1', ['C', 91.2319, 100.0, 120.0, 0.0, 1.0], 3.5], ['regression volatility search bracket 2', ['P', 91.5993, 110.0, 100.0, 0.0, 1.0], 3.5], ['partial repair probe 1', ['P', 94.176453, 110.0, 100.0, 0.03, 2.0], 5.0], ['partial repair probe 2', ['P', 97.044553, 100.0, 100.0, 0.03, 1.0], 5.0], ['normal control 1', ['C', 1.2175, 110.0, 120.0, 0.0, 1.0], 0.1], ['normal control 2', ['P', 3.8044, 110.0, 95.0, 0.08, 1.0], 0.3], ['normal control 3', ['P', 5.59, 100.0, 100.0, 0.03, 0.25], 0.3], ['normal control 4', ['P', 2.5, 90.0, 95.0, 0.08, 2.0], 0.1239]], [['regression volatility search bracket 1', ['C', 92.3037, 100.0, 100.0, 0.08, 1.0], 3.5], ['regression volatility search bracket 2', ['C', 56.0677, 90.0, 100.0, 0.0, 2.0], 1.3], ['partial repair probe 1', ['C', 79.4077, 100.0, 95.0, 0.0, 1.0], 2.5], ['partial repair probe 2', ['C', 70.1631, 110.0, 100.0, 0.03, 0.25], 3.5], ['normal control 1', ['P', 9.2391, 100.0, 100.0, 0.08, 2.0], 0.3], ['normal control 2', ['P', 3.6659, 100.0, 95.0, 0.0, 0.25], 0.3], ['normal control 3', ['P', 92.311635, 100.0, 100.0, 0.08, 1.0], None], ['normal control 4', ['P', 92.192326, 100.0, 95.0, 0.03, 1.0], None]], [['regression volatility search bracket 1', ['C', 87.8484, 110.0, 100.0, 0.0, 1.0], 2.5], ['regression volatility search bracket 2', ['C', 56.8158, 110.0, 100.0, 0.03, 1.0], 1.3], ['partial repair probe 1', ['C', 101.9338, 110.0, 100.0, 0.08, 1.0], 3.5], ['partial repair probe 2', ['P', 116.453464, 110.0, 120.0, 0.03, 1.0], 5.0], ['normal control 1', ['C', 0.4365, 90.0, 95.0, 0.03, 0.25], 0.1], ['normal control 2', ['P', 0.0, 110.0, 95.0, 0.0, 2.0], None], ['normal control 3', ['P', 10.0, 90.0, 100.0, 0.0, 0.25], None], ['normal control 4', ['C', 8.8425, 100.0, 100.0, 0.08, 1.0], 0.1]], [['regression volatility search bracket 1', ['P', 77.5605, 100.0, 120.0, 0.03, 0.25], 3.5], ['regression volatility search bracket 2', ['C', 58.7023, 100.0, 120.0, 0.08, 0.25], 3.5], ['partial repair probe 1', ['C', 102.1427, 110.0, 95.0, 0.08, 1.0], 3.5], ['partial repair probe 2', ['P', 92.29, 100.0, 100.0, 0.0, 2.0], 2.5], ['normal control 1', ['C', 0.01, 100.0, 100.0, 0.08, 2.0], None], ['normal control 2', ['P', 36.4553, 90.0, 120.0, 0.0, 2.0], 0.3], ['normal control 3', ['C', 0.01, 90.0, 120.0, 0.08, 0.25], 0.1967], ['normal control 4', ['C', 0.01, 90.0, 120.0, 0.03, 1.0], 0.0951]], [['regression volatility search bracket 1', ['C', 55.7612, 110.0, 95.0, 0.0, 0.25], 2.5], ['regression volatility search bracket 2', ['C', 70.09, 110.0, 120.0, 0.03, 2.0], 1.3], ['partial repair probe 1', ['C', 54.2681, 110.0, 100.0, 0.0, 0.25], 2.5], ['partial repair probe 2', ['P', 88.7705, 110.0, 100.0, 0.03, 1.0], 3.5], ['normal control 1', ['C', 12.9118, 110.0, 100.0, 0.03, 2.0], None], ['normal control 2', ['C', 110.0, 110.0, 95.0, 0.08, 0.25], None], ['normal control 3', ['P', 87.696053, 100.0, 95.0, 0.08, 1.0], None], ['normal control 4', ['P', 19.99, 100.0, 120.0, 0.0, 2.0], None]]]
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)

source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
N = 1
observations = []
def solve(kind, price, S, K, r, T):
    def N(x):
        return 0.5 * (1 + math.erf(x / math.sqrt(2)))
    def bs(v):
        d1 = (math.log(S / K) + (r + 0.5 * v * v) * T) / (v * math.sqrt(T))
        d2 = d1 - v * math.sqrt(T)
        if kind == 'C':
            return S * N(d1) - K * math.exp(-r * T) * N(d2)
        return K * math.exp(-r * T) * N(-d2) - S * N(-d1)
    disc_k = K * math.exp(-r * T)
    lower = max(S - disc_k, 0) if kind == 'C' else max(disc_k - S, 0)
    upper = S if kind == 'C' else disc_k
    if price <= lower or price >= upper:
        return None
    lo, hi = 1e-6, 2.0
    for _ in range(100):
        mid = (lo + hi) / 2
        if bs(mid) > price:
            hi = mid
        else:
            lo = mid
    return round((lo + hi) / 2, 4)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression volatility search bracket 1', ['C', 91.2319, 100.0, 120.0, 0.0, 1.0], 3.5], ['regression volatility search bracket 2', ['P', 91.5993, 110.0, 100.0, 0.0, 1.0], 3.5], ['partial repair probe 1', ['P', 94.176453, 110.0, 100.0, 0.03, 2.0], 5.0], ['partial repair probe 2', ['P', 97.044553, 100.0, 100.0, 0.03, 1.0], 5.0], ['normal control 1', ['C', 1.2175, 110.0, 120.0, 0.0, 1.0], 0.1], ['normal control 2', ['P', 3.8044, 110.0, 95.0, 0.08, 1.0], 0.3], ['normal control 3', ['P', 5.59, 100.0, 100.0, 0.03, 0.25], 0.3], ['normal control 4', ['P', 2.5, 90.0, 95.0, 0.08, 2.0], 0.1239]], [['regression volatility search bracket 1', ['C', 92.3037, 100.0, 100.0, 0.08, 1.0], 3.5], ['regression volatility search bracket 2', ['C', 56.0677, 90.0, 100.0, 0.0, 2.0], 1.3], ['partial repair probe 1', ['C', 79.4077, 100.0, 95.0, 0.0, 1.0], 2.5], ['partial repair probe 2', ['C', 70.1631, 110.0, 100.0, 0.03, 0.25], 3.5], ['normal control 1', ['P', 9.2391, 100.0, 100.0, 0.08, 2.0], 0.3], ['normal control 2', ['P', 3.6659, 100.0, 95.0, 0.0, 0.25], 0.3], ['normal control 3', ['P', 92.311635, 100.0, 100.0, 0.08, 1.0], None], ['normal control 4', ['P', 92.192326, 100.0, 95.0, 0.03, 1.0], None]], [['regression volatility search bracket 1', ['C', 87.8484, 110.0, 100.0, 0.0, 1.0], 2.5], ['regression volatility search bracket 2', ['C', 56.8158, 110.0, 100.0, 0.03, 1.0], 1.3], ['partial repair probe 1', ['C', 101.9338, 110.0, 100.0, 0.08, 1.0], 3.5], ['partial repair probe 2', ['P', 116.453464, 110.0, 120.0, 0.03, 1.0], 5.0], ['normal control 1', ['C', 0.4365, 90.0, 95.0, 0.03, 0.25], 0.1], ['normal control 2', ['P', 0.0, 110.0, 95.0, 0.0, 2.0], None], ['normal control 3', ['P', 10.0, 90.0, 100.0, 0.0, 0.25], None], ['normal control 4', ['C', 8.8425, 100.0, 100.0, 0.08, 1.0], 0.1]], [['regression volatility search bracket 1', ['P', 77.5605, 100.0, 120.0, 0.03, 0.25], 3.5], ['regression volatility search bracket 2', ['C', 58.7023, 100.0, 120.0, 0.08, 0.25], 3.5], ['partial repair probe 1', ['C', 102.1427, 110.0, 95.0, 0.08, 1.0], 3.5], ['partial repair probe 2', ['P', 92.29, 100.0, 100.0, 0.0, 2.0], 2.5], ['normal control 1', ['C', 0.01, 100.0, 100.0, 0.08, 2.0], None], ['normal control 2', ['P', 36.4553, 90.0, 120.0, 0.0, 2.0], 0.3], ['normal control 3', ['C', 0.01, 90.0, 120.0, 0.08, 0.25], 0.1967], ['normal control 4', ['C', 0.01, 90.0, 120.0, 0.03, 1.0], 0.0951]], [['regression volatility search bracket 1', ['C', 55.7612, 110.0, 95.0, 0.0, 0.25], 2.5], ['regression volatility search bracket 2', ['C', 70.09, 110.0, 120.0, 0.03, 2.0], 1.3], ['partial repair probe 1', ['C', 54.2681, 110.0, 100.0, 0.0, 0.25], 2.5], ['partial repair probe 2', ['P', 88.7705, 110.0, 100.0, 0.03, 1.0], 3.5], ['normal control 1', ['C', 12.9118, 110.0, 100.0, 0.03, 2.0], None], ['normal control 2', ['C', 110.0, 110.0, 95.0, 0.08, 0.25], None], ['normal control 3', ['P', 87.696053, 100.0, 95.0, 0.08, 1.0], None], ['normal control 4', ['P', 19.99, 100.0, 120.0, 0.0, 2.0], None]]]
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)

prompt:
High implied volatilities are reported as 1.0.

Inputs kind, option price, S, K, r, T (no dividends). If price <= lower bound (call max(S - K e^{-rT},0), put max(K e^{-rT} - S,0)) or price >= upper bound (call S, put K e^{-rT}) return None. Otherwise bisect sigma in [1e-6, 5] for 100 iterations on the Black-Scholes price and return the midpoint rounded to 4.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
N = 1
observations = []
def solve(kind, price, S, K, r, T):
    def N(x):
        return 0.5 * (1 + math.erf(x / math.sqrt(2)))
    def bs(v):
        d1 = (math.log(S / K) + (r + 0.5 * v * v) * T) / (v * math.sqrt(T))
        d2 = d1 - v * math.sqrt(T)
        if kind == 'C':
            return S * N(d1) - K * math.exp(-r * T) * N(d2)
        return K * math.exp(-r * T) * N(-d2) - S * N(-d1)
    disc_k = K * math.exp(-r * T)
    lower = max(S - disc_k, 0) if kind == 'C' else max(disc_k - S, 0)
    upper = S if kind == 'C' else disc_k
    if price <= lower:
        return None
    lo, hi = 1e-6, 5.0
    for _ in range(100):
        mid = (lo + hi) / 2
        if bs(mid) > price:
            hi = mid
        else:
            lo = mid
    return round((lo + hi) / 2, 4)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression upper arbitrage bound 1', ['C', 110.0, 110.0, 120.0, 0.03, 1.0], None], ['regression upper arbitrage bound 2', ['C', 90.0, 90.0, 120.0, 0.03, 0.25], None], ['partial repair probe 1', ['C', 100.0, 100.0, 100.0, 0.08, 0.25], None], ['partial repair probe 2', ['C', 100.0, 100.0, 95.0, 0.03, 2.0], None], ['normal control 1', ['C', 66.3463, 110.0, 120.0, 0.03, 0.25], 3.5], ['normal control 2', ['P', 18.141, 100.0, 120.0, 0.08, 2.0], 0.3], ['normal control 3', ['C', 70.2582, 90.0, 100.0, 0.03, 1.0], 2.5], ['normal control 4', ['P', 72.0164, 100.0, 100.0, 0.08, 1.0], 2.5]], [['regression upper arbitrage bound 1', ['C', 100.0, 100.0, 120.0, 0.08, 1.0], None], ['regression upper arbitrage bound 2', ['C', 110.0, 110.0, 100.0, 0.03, 2.0], None], ['partial repair probe 1', ['C', 100.0, 100.0, 100.0, 0.03, 1.0], None], ['partial repair probe 2', ['C', 110.0, 110.0, 120.0, 0.03, 1.0], None], ['normal control 1', ['C', 2.5954, 90.0, 100.0, 0.08, 1.0], 0.1], ['normal control 2', ['P', 0, 110.0, 95.0, 0.08, 1.0], None], ['normal control 3', ['C', 4.99, 100.0, 95.0, 0.0, 1.0], None], ['normal control 4', ['C', 0.01, 100.0, 100.0, 0.03, 1.0], None]], [['regression upper arbitrage bound 1', ['C', 90.0, 90.0, 120.0, 0.0, 2.0], None], ['regression upper arbitrage bound 2', ['C', 90.0, 90.0, 95.0, 0.0, 0.25], None], ['partial repair probe 1', ['C', 100.0, 100.0, 120.0, 0.03, 1.0], None], ['partial repair probe 2', ['P', 95.0, 90.0, 95.0, 0.0, 0.25], None], ['normal control 1', ['P', 0, 100.0, 95.0, 0.0, 1.0], None], ['normal control 2', ['P', 84.8945, 90.0, 95.0, 0.03, 1.0], 3.5], ['normal control 3', ['C', 88.8328, 90.0, 100.0, 0.08, 2.0], 3.5], ['normal control 4', ['P', 10.01, 110.0, 120.0, 0.03, 1.0], 0.1388]], [['regression upper arbitrage bound 1', ['P', 119.103367, 110.0, 120.0, 0.03, 0.25], None], ['regression upper arbitrage bound 2', ['P', 119.103367, 100.0, 120.0, 0.03, 0.25], None], ['partial repair probe 1', ['C', 100.0, 100.0, 120.0, 0.0, 0.25], None], ['partial repair probe 2', ['C', 110.0, 110.0, 120.0, 0.0, 1.0], None], ['normal control 1', ['P', 29.99, 90.0, 120.0, 0.0, 1.0], None], ['normal control 2', ['C', 101.1438, 110.0, 120.0, 0.0, 2.0], 2.5], ['normal control 3', ['P', 64.0631, 90.0, 120.0, 0.03, 1.0], 1.3], ['normal control 4', ['C', 0, 90.0, 100.0, 0.03, 1.0], None]], [['regression upper arbitrage bound 1', ['C', 90.0, 90.0, 120.0, 0.0, 1.0], None], ['regression upper arbitrage bound 2', ['P', 89.467631, 100.0, 95.0, 0.03, 2.0], None], ['partial repair probe 1', ['C', 110.0, 110.0, 100.0, 0.03, 1.0], None], ['partial repair probe 2', ['C', 90.0, 90.0, 100.0, 0.03, 1.0], None], ['normal control 1', ['P', 30.0, 90.0, 120.0, 0.0, 0.25], None], ['normal control 2', ['P', 0.0, 100.0, 100.0, 0.0, 1.0], None], ['normal control 3', ['C', 3.8442, 100.0, 100.0, 0.08, 1.0], None], ['normal control 4', ['C', 10.0, 110.0, 100.0, 0.0, 1.0], None]]]
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)

source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
N = 1
observations = []
def solve(kind, price, S, K, r, T):
    def N(x):
        return 0.5 * (1 + math.erf(x / math.sqrt(2)))
    def bs(v):
        d1 = (math.log(S / K) + (r + 0.5 * v * v) * T) / (v * math.sqrt(T))
        d2 = d1 - v * math.sqrt(T)
        if kind == 'C':
            return S * N(d1) - K * math.exp(-r * T) * N(d2)
        return K * math.exp(-r * T) * N(-d2) - S * N(-d1)
    disc_k = K * math.exp(-r * T)
    lower = max(S - disc_k, 0) if kind == 'C' else max(disc_k - S, 0)
    upper = S if kind == 'C' else disc_k
    if price <= lower or price > upper:
        return None
    lo, hi = 1e-6, 5.0
    for _ in range(100):
        mid = (lo + hi) / 2
        if bs(mid) > price:
            hi = mid
        else:
            lo = mid
    return round((lo + hi) / 2, 4)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression upper arbitrage bound 1', ['C', 110.0, 110.0, 120.0, 0.03, 1.0], None], ['regression upper arbitrage bound 2', ['C', 90.0, 90.0, 120.0, 0.03, 0.25], None], ['partial repair probe 1', ['C', 100.0, 100.0, 100.0, 0.08, 0.25], None], ['partial repair probe 2', ['C', 100.0, 100.0, 95.0, 0.03, 2.0], None], ['normal control 1', ['C', 66.3463, 110.0, 120.0, 0.03, 0.25], 3.5], ['normal control 2', ['P', 18.141, 100.0, 120.0, 0.08, 2.0], 0.3], ['normal control 3', ['C', 70.2582, 90.0, 100.0, 0.03, 1.0], 2.5], ['normal control 4', ['P', 72.0164, 100.0, 100.0, 0.08, 1.0], 2.5]], [['regression upper arbitrage bound 1', ['C', 100.0, 100.0, 120.0, 0.08, 1.0], None], ['regression upper arbitrage bound 2', ['C', 110.0, 110.0, 100.0, 0.03, 2.0], None], ['partial repair probe 1', ['C', 100.0, 100.0, 100.0, 0.03, 1.0], None], ['partial repair probe 2', ['C', 110.0, 110.0, 120.0, 0.03, 1.0], None], ['normal control 1', ['C', 2.5954, 90.0, 100.0, 0.08, 1.0], 0.1], ['normal control 2', ['P', 0, 110.0, 95.0, 0.08, 1.0], None], ['normal control 3', ['C', 4.99, 100.0, 95.0, 0.0, 1.0], None], ['normal control 4', ['C', 0.01, 100.0, 100.0, 0.03, 1.0], None]], [['regression upper arbitrage bound 1', ['C', 90.0, 90.0, 120.0, 0.0, 2.0], None], ['regression upper arbitrage bound 2', ['C', 90.0, 90.0, 95.0, 0.0, 0.25], None], ['partial repair probe 1', ['C', 100.0, 100.0, 120.0, 0.03, 1.0], None], ['partial repair probe 2', ['P', 95.0, 90.0, 95.0, 0.0, 0.25], None], ['normal control 1', ['P', 0, 100.0, 95.0, 0.0, 1.0], None], ['normal control 2', ['P', 84.8945, 90.0, 95.0, 0.03, 1.0], 3.5], ['normal control 3', ['C', 88.8328, 90.0, 100.0, 0.08, 2.0], 3.5], ['normal control 4', ['P', 10.01, 110.0, 120.0, 0.03, 1.0], 0.1388]], [['regression upper arbitrage bound 1', ['P', 119.103367, 110.0, 120.0, 0.03, 0.25], None], ['regression upper arbitrage bound 2', ['P', 119.103367, 100.0, 120.0, 0.03, 0.25], None], ['partial repair probe 1', ['C', 100.0, 100.0, 120.0, 0.0, 0.25], None], ['partial repair probe 2', ['C', 110.0, 110.0, 120.0, 0.0, 1.0], None], ['normal control 1', ['P', 29.99, 90.0, 120.0, 0.0, 1.0], None], ['normal control 2', ['C', 101.1438, 110.0, 120.0, 0.0, 2.0], 2.5], ['normal control 3', ['P', 64.0631, 90.0, 120.0, 0.03, 1.0], 1.3], ['normal control 4', ['C', 0, 90.0, 100.0, 0.03, 1.0], None]], [['regression upper arbitrage bound 1', ['C', 90.0, 90.0, 120.0, 0.0, 1.0], None], ['regression upper arbitrage bound 2', ['P', 89.467631, 100.0, 95.0, 0.03, 2.0], None], ['partial repair probe 1', ['C', 110.0, 110.0, 100.0, 0.03, 1.0], None], ['partial repair probe 2', ['C', 90.0, 90.0, 100.0, 0.03, 1.0], None], ['normal control 1', ['P', 30.0, 90.0, 120.0, 0.0, 0.25], None], ['normal control 2', ['P', 0.0, 100.0, 100.0, 0.0, 1.0], None], ['normal control 3', ['C', 3.8442, 100.0, 100.0, 0.08, 1.0], None], ['normal control 4', ['C', 10.0, 110.0, 100.0, 0.0, 1.0], None]]]
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)

prompt:
Arbitrage-violating prices return the bracket edge instead of None.

Inputs kind, option price, S, K, r, T (no dividends). If price <= lower bound (call max(S - K e^{-rT},0), put max(K e^{-rT} - S,0)) or price >= upper bound (call S, put K e^{-rT}) return None. Otherwise bisect sigma in [1e-6, 5] for 100 iterations on the Black-Scholes price and return the midpoint rounded to 4.

split: open-access


prompt:
Put positions are hedged in the wrong direction.

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.

split: open-access


prompt:
Rehedging buys the full target again.

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.

split: open-access


prompt:
Hedges are systematically under-sized.

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.

split: open-access


prompt:
Hedging doubles the delta instead of neutralizing it.

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.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(call_price, S, K, dividend, last_cum_day):
    c = round(call_price * 100)
    intrinsic = max(round(S * 100) - round(K * 100), 0)
    if not last_cum_day or intrinsic == 0:
        return False
    extrinsic = c - intrinsic
    return round(dividend * 100) > c
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression extrinsic measure 1', [15.25, 105.0, 90.0, 1.0, True], True], ['regression extrinsic measure 2', [9.5, 98.0, 90.0, 1.51, True], True], ['partial repair probe 1', [8.5, 98.0, 90.0, 0.51, True], True], ['partial repair probe 2', [5.05, 105.0, 100.0, 0.25, True], True], ['boundary control 1', [10.5, 110.0, 100.0, 0.5, True], False], ['normal control 1', [9.0, 98.0, 90.0, 1.0, False], False], ['normal control 2', [1.0, 98.0, 100.0, 1.0, True], False], ['normal control 3', [0.25, 105.0, 110.0, 0.25, True], False]], [['regression extrinsic measure 1', [8.25, 98.0, 90.0, 1.0, True], True], ['regression extrinsic measure 2', [31.5, 120.0, 90.0, 1.51, True], True], ['partial repair probe 1', [30.05, 120.0, 90.0, 1.0, True], True], ['partial repair probe 2', [10.05, 100.0, 90.0, 0.25, True], True], ['boundary control 1', [10.5, 110.0, 100.0, 0.5, True], False], ['normal control 1', [0.25, 98.0, 100.0, 1.0, True], False], ['normal control 2', [1.5, 100.0, 100.0, 1.5, True], False], ['normal control 3', [8.5, 98.0, 90.0, 0.5, False], False]], [['regression extrinsic measure 1', [9.5, 98.0, 90.0, 1.51, True], True], ['regression extrinsic measure 2', [5.25, 105.0, 100.0, 0.26, True], True], ['partial repair probe 1', [10.25, 100.0, 90.0, 1.0, True], True], ['partial repair probe 2', [15.05, 105.0, 90.0, 0.060000000000000005, True], True], ['boundary control 1', [10.5, 110.0, 100.0, 0.5, True], False], ['normal control 1', [0.05, 98.0, 110.0, 0.5, True], False], ['normal control 2', [1.0, 100.0, 100.0, 1.0, True], False], ['normal control 3', [15.5, 105.0, 90.0, 0.5, True], False]], [['regression extrinsic measure 1', [15.05, 105.0, 90.0, 0.25, True], True], ['regression extrinsic measure 2', [30.05, 120.0, 90.0, 1.0, True], True], ['partial repair probe 1', [16.5, 105.0, 90.0, 1.51, True], True], ['partial repair probe 2', [15.05, 105.0, 90.0, 0.060000000000000005, True], True], ['boundary control 1', [10.5, 110.0, 100.0, 0.5, True], False], ['normal control 1', [21.0, 120.0, 100.0, 0.25, False], False], ['normal control 2', [6.0, 105.0, 100.0, 0.25, True], False], ['normal control 3', [6.5, 105.0, 100.0, 0.5, False], False]], [['regression extrinsic measure 1', [6.5, 105.0, 100.0, 1.51, True], True], ['regression extrinsic measure 2', [11.0, 100.0, 90.0, 1.01, True], True], ['partial repair probe 1', [10.05, 100.0, 90.0, 1.0, True], True], ['partial repair probe 2', [9.0, 98.0, 90.0, 1.01, True], True], ['boundary control 1', [10.5, 110.0, 100.0, 0.5, True], False], ['normal control 1', [30.25, 120.0, 90.0, 0.25, True], False], ['normal control 2', [1.5, 98.0, 100.0, 1.51, True], False], ['normal control 3', [1.0, 105.0, 110.0, 1.0, True], False]]]
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)

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(call_price, S, K, dividend, last_cum_day):
    c = round(call_price * 100)
    intrinsic = max(round(S * 100) - round(K * 100), 0)
    if not last_cum_day or intrinsic == 0:
        return False
    extrinsic = c - intrinsic
    return round(dividend * 100) > intrinsic
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression extrinsic measure 1', [15.25, 105.0, 90.0, 1.0, True], True], ['regression extrinsic measure 2', [9.5, 98.0, 90.0, 1.51, True], True], ['partial repair probe 1', [8.5, 98.0, 90.0, 0.51, True], True], ['partial repair probe 2', [5.05, 105.0, 100.0, 0.25, True], True], ['boundary control 1', [10.5, 110.0, 100.0, 0.5, True], False], ['normal control 1', [9.0, 98.0, 90.0, 1.0, False], False], ['normal control 2', [1.0, 98.0, 100.0, 1.0, True], False], ['normal control 3', [0.25, 105.0, 110.0, 0.25, True], False]], [['regression extrinsic measure 1', [8.25, 98.0, 90.0, 1.0, True], True], ['regression extrinsic measure 2', [31.5, 120.0, 90.0, 1.51, True], True], ['partial repair probe 1', [30.05, 120.0, 90.0, 1.0, True], True], ['partial repair probe 2', [10.05, 100.0, 90.0, 0.25, True], True], ['boundary control 1', [10.5, 110.0, 100.0, 0.5, True], False], ['normal control 1', [0.25, 98.0, 100.0, 1.0, True], False], ['normal control 2', [1.5, 100.0, 100.0, 1.5, True], False], ['normal control 3', [8.5, 98.0, 90.0, 0.5, False], False]], [['regression extrinsic measure 1', [9.5, 98.0, 90.0, 1.51, True], True], ['regression extrinsic measure 2', [5.25, 105.0, 100.0, 0.26, True], True], ['partial repair probe 1', [10.25, 100.0, 90.0, 1.0, True], True], ['partial repair probe 2', [15.05, 105.0, 90.0, 0.060000000000000005, True], True], ['boundary control 1', [10.5, 110.0, 100.0, 0.5, True], False], ['normal control 1', [0.05, 98.0, 110.0, 0.5, True], False], ['normal control 2', [1.0, 100.0, 100.0, 1.0, True], False], ['normal control 3', [15.5, 105.0, 90.0, 0.5, True], False]], [['regression extrinsic measure 1', [15.05, 105.0, 90.0, 0.25, True], True], ['regression extrinsic measure 2', [30.05, 120.0, 90.0, 1.0, True], True], ['partial repair probe 1', [16.5, 105.0, 90.0, 1.51, True], True], ['partial repair probe 2', [15.05, 105.0, 90.0, 0.060000000000000005, True], True], ['boundary control 1', [10.5, 110.0, 100.0, 0.5, True], False], ['normal control 1', [21.0, 120.0, 100.0, 0.25, False], False], ['normal control 2', [6.0, 105.0, 100.0, 0.25, True], False], ['normal control 3', [6.5, 105.0, 100.0, 0.5, False], False]], [['regression extrinsic measure 1', [6.5, 105.0, 100.0, 1.51, True], True], ['regression extrinsic measure 2', [11.0, 100.0, 90.0, 1.01, True], True], ['partial repair probe 1', [10.05, 100.0, 90.0, 1.0, True], True], ['partial repair probe 2', [9.0, 98.0, 90.0, 1.01, True], True], ['boundary control 1', [10.5, 110.0, 100.0, 0.5, True], False], ['normal control 1', [30.25, 120.0, 90.0, 0.25, True], False], ['normal control 2', [1.5, 98.0, 100.0, 1.51, True], False], ['normal control 3', [1.0, 105.0, 110.0, 1.0, True], False]]]
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)

prompt:
Deep in-the-money calls are never exercised early.

Inputs call price, spot, strike, dividend and whether today is the last cum-dividend day. Exercise only on the last cum-dividend day, only if the call is in the money, and only if the dividend is strictly greater than the call's extrinsic value (price - intrinsic). Amounts compared exactly in cents. Return true/false.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(call_price, S, K, dividend, last_cum_day):
    c = round(call_price * 100)
    intrinsic = max(round(S * 100) - round(K * 100), 0)
    if intrinsic == 0:
        return False
    extrinsic = c - intrinsic
    return round(dividend * 100) > extrinsic
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression timing gate 1', [10.25, 120.0, 110.0, 0.5, False], False], ['regression timing gate 2', [10.05, 100.0, 90.0, 0.060000000000000005, False], False], ['partial repair probe 1', [15.05, 105.0, 90.0, 0.5, True], True], ['partial repair probe 2', [5.5, 105.0, 100.0, 0.51, True], True], ['boundary control 1', [10.5, 110.0, 100.0, 0.5, True], False], ['normal control 1', [11.0, 100.0, 90.0, 1.0, True], False], ['normal control 2', [0.25, 105.0, 110.0, 0.5, True], False], ['normal control 3', [1.5, 98.0, 110.0, 1.0, False], False]], [['regression timing gate 1', [5.25, 105.0, 100.0, 1.0, False], False], ['regression timing gate 2', [16.0, 105.0, 90.0, 1.01, False], False], ['partial repair probe 1', [10.25, 120.0, 110.0, 0.26, True], True], ['partial repair probe 2', [15.25, 105.0, 90.0, 0.26, True], True], ['boundary control 1', [10.5, 110.0, 100.0, 0.5, True], False], ['normal control 1', [0.05, 100.0, 110.0, 0.5, True], False], ['normal control 2', [1.0, 100.0, 110.0, 0.25, False], False], ['normal control 3', [10.5, 100.0, 90.0, 0.5, True], False]], [['regression timing gate 1', [15.25, 105.0, 90.0, 1.0, False], False], ['regression timing gate 2', [5.05, 105.0, 100.0, 0.060000000000000005, False], False], ['partial repair probe 1', [15.25, 105.0, 90.0, 0.26, True], True], ['partial repair probe 2', [20.5, 120.0, 100.0, 1.0, True], True], ['boundary control 1', [10.5, 110.0, 100.0, 0.5, True], False], ['normal control 1', [15.25, 105.0, 90.0, 0.25, True], False], ['normal control 2', [1.5, 105.0, 110.0, 1.51, True], False], ['normal control 3', [0.5, 100.0, 110.0, 0.5, False], False]], [['regression timing gate 1', [8.05, 98.0, 90.0, 0.060000000000000005, False], False], ['regression timing gate 2', [5.25, 105.0, 100.0, 1.0, False], False], ['partial repair probe 1', [5.5, 105.0, 100.0, 1.0, True], True], ['partial repair probe 2', [20.05, 120.0, 100.0, 0.5, True], True], ['boundary control 1', [10.5, 110.0, 100.0, 0.5, True], False], ['normal control 1', [21.0, 120.0, 100.0, 0.5, True], False], ['normal control 2', [31.5, 120.0, 90.0, 0.25, False], False], ['normal control 3', [6.0, 105.0, 100.0, 1.0, False], False]], [['regression timing gate 1', [8.05, 98.0, 90.0, 1.0, False], False], ['regression timing gate 2', [10.25, 120.0, 110.0, 1.0, False], False], ['partial repair probe 1', [10.25, 100.0, 90.0, 0.5, True], True], ['partial repair probe 2', [21.0, 120.0, 100.0, 1.01, True], True], ['boundary control 1', [10.5, 110.0, 100.0, 0.5, True], False], ['normal control 1', [0.05, 98.0, 110.0, 0.05, False], False], ['normal control 2', [1.5, 100.0, 110.0, 1.51, True], False], ['normal control 3', [10.5, 120.0, 110.0, 0.5, True], False]]]
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)

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(call_price, S, K, dividend, last_cum_day):
    c = round(call_price * 100)
    intrinsic = max(round(S * 100) - round(K * 100), 0)
    if last_cum_day or intrinsic == 0:
        return False
    extrinsic = c - intrinsic
    return round(dividend * 100) > extrinsic
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression timing gate 1', [10.25, 120.0, 110.0, 0.5, False], False], ['regression timing gate 2', [10.05, 100.0, 90.0, 0.060000000000000005, False], False], ['partial repair probe 1', [15.05, 105.0, 90.0, 0.5, True], True], ['partial repair probe 2', [5.5, 105.0, 100.0, 0.51, True], True], ['boundary control 1', [10.5, 110.0, 100.0, 0.5, True], False], ['normal control 1', [11.0, 100.0, 90.0, 1.0, True], False], ['normal control 2', [0.25, 105.0, 110.0, 0.5, True], False], ['normal control 3', [1.5, 98.0, 110.0, 1.0, False], False]], [['regression timing gate 1', [5.25, 105.0, 100.0, 1.0, False], False], ['regression timing gate 2', [16.0, 105.0, 90.0, 1.01, False], False], ['partial repair probe 1', [10.25, 120.0, 110.0, 0.26, True], True], ['partial repair probe 2', [15.25, 105.0, 90.0, 0.26, True], True], ['boundary control 1', [10.5, 110.0, 100.0, 0.5, True], False], ['normal control 1', [0.05, 100.0, 110.0, 0.5, True], False], ['normal control 2', [1.0, 100.0, 110.0, 0.25, False], False], ['normal control 3', [10.5, 100.0, 90.0, 0.5, True], False]], [['regression timing gate 1', [15.25, 105.0, 90.0, 1.0, False], False], ['regression timing gate 2', [5.05, 105.0, 100.0, 0.060000000000000005, False], False], ['partial repair probe 1', [15.25, 105.0, 90.0, 0.26, True], True], ['partial repair probe 2', [20.5, 120.0, 100.0, 1.0, True], True], ['boundary control 1', [10.5, 110.0, 100.0, 0.5, True], False], ['normal control 1', [15.25, 105.0, 90.0, 0.25, True], False], ['normal control 2', [1.5, 105.0, 110.0, 1.51, True], False], ['normal control 3', [0.5, 100.0, 110.0, 0.5, False], False]], [['regression timing gate 1', [8.05, 98.0, 90.0, 0.060000000000000005, False], False], ['regression timing gate 2', [5.25, 105.0, 100.0, 1.0, False], False], ['partial repair probe 1', [5.5, 105.0, 100.0, 1.0, True], True], ['partial repair probe 2', [20.05, 120.0, 100.0, 0.5, True], True], ['boundary control 1', [10.5, 110.0, 100.0, 0.5, True], False], ['normal control 1', [21.0, 120.0, 100.0, 0.5, True], False], ['normal control 2', [31.5, 120.0, 90.0, 0.25, False], False], ['normal control 3', [6.0, 105.0, 100.0, 1.0, False], False]], [['regression timing gate 1', [8.05, 98.0, 90.0, 1.0, False], False], ['regression timing gate 2', [10.25, 120.0, 110.0, 1.0, False], False], ['partial repair probe 1', [10.25, 100.0, 90.0, 0.5, True], True], ['partial repair probe 2', [21.0, 120.0, 100.0, 1.01, True], True], ['boundary control 1', [10.5, 110.0, 100.0, 0.5, True], False], ['normal control 1', [0.05, 98.0, 110.0, 0.05, False], False], ['normal control 2', [1.5, 100.0, 110.0, 1.51, True], False], ['normal control 3', [10.5, 120.0, 110.0, 0.5, True], False]]]
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)

prompt:
Calls are exercised days before the dividend is relevant.

Inputs call price, spot, strike, dividend and whether today is the last cum-dividend day. Exercise only on the last cum-dividend day, only if the call is in the money, and only if the dividend is strictly greater than the call's extrinsic value (price - intrinsic). Amounts compared exactly in cents. Return true/false.

split: open-access