prompt:
Values are wrong for every maturity other than one year.

Inputs kind, spot S, strike K, rate r, dividend yield q, volatility sigma and calendar days to expiry. T = days/365. At days == 0 return intrinsic value. Otherwise d1 = (ln(S/K) + (r - q + sigma^2/2)T)/(sigma sqrt T), d2 = d1 - sigma sqrt T, call = S e^{-qT} N(d1) - K e^{-rT} N(d2), put = K e^{-rT} N(-d2) - S e^{-qT} N(-d1). Round to 6.

split: open-access


meaning: Fixture-count band, not measured model difficulty

deps: stdlib

prompt:
Calls on dividend payers are overpriced.

Inputs kind, spot S, strike K, rate r, dividend yield q, volatility sigma and calendar days to expiry. T = days/365. At days == 0 return intrinsic value. Otherwise d1 = (ln(S/K) + (r - q + sigma^2/2)T)/(sigma sqrt T), d2 = d1 - sigma sqrt T, call = S e^{-qT} N(d1) - K e^{-rT} N(d2), put = K e^{-rT} N(-d2) - S e^{-qT} N(-d1). Round to 6.

split: open-access


prompt:
Puts violate put-call parity.

Inputs kind, spot S, strike K, rate r, dividend yield q, volatility sigma and calendar days to expiry. T = days/365. At days == 0 return intrinsic value. Otherwise d1 = (ln(S/K) + (r - q + sigma^2/2)T)/(sigma sqrt T), d2 = d1 - sigma sqrt T, call = S e^{-qT} N(d1) - K e^{-rT} N(d2), put = K e^{-rT} N(-d2) - S e^{-qT} N(-d1). Round to 6.

split: open-access


prompt:
Time value is overstated for every maturity.

Inputs kind, spot S, strike K, rate r, dividend yield q, volatility sigma and calendar days to expiry. T = days/365. At days == 0 return intrinsic value. Otherwise d1 = (ln(S/K) + (r - q + sigma^2/2)T)/(sigma sqrt T), d2 = d1 - sigma sqrt T, call = S e^{-qT} N(d1) - K e^{-rT} N(d2), put = K e^{-rT} N(-d2) - S e^{-qT} N(-d1). Round to 6.

split: open-access


prompt:
Expiring in-the-money options are valued at zero.

Inputs kind, spot S, strike K, rate r, dividend yield q, volatility sigma and calendar days to expiry. T = days/365. At days == 0 return intrinsic value. Otherwise d1 = (ln(S/K) + (r - q + sigma^2/2)T)/(sigma sqrt T), d2 = d1 - sigma sqrt T, call = S e^{-qT} N(d1) - K e^{-rT} N(d2), put = K e^{-rT} N(-d2) - S e^{-qT} N(-d1). Round to 6.

split: open-access


prompt:
Settlement values drop sharply when any component is halted at the open.

Inputs components [weight, opening price or None, last close] and a divisor. Each component uses its opening price, or its last close if it did not open. Settlement = sum(weight*price)/divisor computed in Decimal and rounded half-up to cents. Return as a string.

split: open-access


prompt:
Exact half-cent values settle a cent lower half of the time.

Inputs components [weight, opening price or None, last close] and a divisor. Each component uses its opening price, or its last close if it did not open. Settlement = sum(weight*price)/divisor computed in Decimal and rounded half-up to cents. Return as a string.

split: open-access


prompt:
Per-component rounding accumulates into a settlement value off by cents.

Inputs components [weight, opening price or None, last close] and a divisor. Each component uses its opening price, or its last close if it did not open. Settlement = sum(weight*price)/divisor computed in Decimal and rounded half-up to cents. Return as a string.

split: open-access


prompt:
Settlement is a plain price average scaled by the divisor.

Inputs components [weight, opening price or None, last close] and a divisor. Each component uses its opening price, or its last close if it did not open. Settlement = sum(weight*price)/divisor computed in Decimal and rounded half-up to cents. Return as a string.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import datetime
N = 1
observations = []
def solve(y, m, kind, holidays):
    H = {datetime.date(*h) for h in holidays}
    def biz(x):
        return x.weekday() < 5 and x not in H
    def mlen(yy, mm):
        if mm == 2:
            return 29 if (yy % 4 == 0 and yy % 100 != 0) or yy % 400 == 0 else 28
        return 30 if mm in (4, 6, 9, 11) else 31
    if kind == 'quarterly':
        qm = ((m - 1) // 3 + 1) * 3
        x = datetime.date(y, qm, mlen(y, qm))
    else:
        first = datetime.date(y, m, 1)
        offset = 4 - first.weekday()
        x = first + datetime.timedelta(days=offset + 14)
    while not biz(x):
        x -= datetime.timedelta(days=1)
    return [x.year, x.month, x.day]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression first friday offset 1', [2032, 2, 'monthly', []], [2032, 2, 20]], ['regression first friday offset 2', [2030, 9, 'monthly', [[2030, 9, 20]]], [2030, 9, 19]], ['partial repair probe 1', [2023, 12, 'monthly', []], [2023, 12, 15]], ['partial repair probe 2', [2029, 6, 'monthly', []], [2029, 6, 15]], ['boundary control 1', [2024, 3, 'quarterly', []], [2024, 3, 29]], ['boundary control 2', [2024, 12, 'quarterly', []], [2024, 12, 31]], ['normal control 1', [2028, 8, 'monthly', []], [2028, 8, 18]], ['normal control 2', [2022, 3, 'quarterly', [[2022, 3, 28]]], [2022, 3, 31]]], [['regression first friday offset 1', [2023, 7, 'monthly', []], [2023, 7, 21]], ['regression first friday offset 2', [2031, 6, 'monthly', [[2031, 6, 20], [2031, 6, 19]]], [2031, 6, 18]], ['partial repair probe 1', [2025, 8, 'monthly', []], [2025, 8, 15]], ['partial repair probe 2', [2019, 2, 'monthly', [[2019, 2, 15], [2019, 2, 14]]], [2019, 2, 13]], ['boundary control 1', [2024, 12, 'quarterly', []], [2024, 12, 31]], ['boundary control 2', [2024, 3, 'quarterly', []], [2024, 3, 29]], ['normal control 1', [2021, 3, 'quarterly', []], [2021, 3, 31]], ['normal control 2', [2030, 11, 'quarterly', [[2030, 11, 15]]], [2030, 12, 31]]], [['regression first friday offset 1', [2023, 7, 'monthly', []], [2023, 7, 21]], ['regression first friday offset 2', [2020, 2, 'monthly', [[2020, 2, 21], [2020, 2, 20]]], [2020, 2, 19]], ['partial repair probe 1', [2029, 6, 'monthly', []], [2029, 6, 15]], ['partial repair probe 2', [2031, 8, 'monthly', []], [2031, 8, 15]], ['boundary control 1', [2024, 12, 'quarterly', []], [2024, 12, 31]], ['boundary control 2', [2024, 3, 'quarterly', []], [2024, 3, 29]], ['normal control 1', [2027, 3, 'monthly', [[2027, 3, 19], [2027, 3, 18]]], [2027, 3, 17]], ['normal control 2', [2022, 5, 'quarterly', [[2022, 6, 29]]], [2022, 6, 30]]], [['regression first friday offset 1', [2020, 2, 'monthly', []], [2020, 2, 21]], ['regression first friday offset 2', [2026, 3, 'monthly', [[2026, 3, 20]]], [2026, 3, 19]], ['partial repair probe 1', [2026, 5, 'monthly', []], [2026, 5, 15]], ['partial repair probe 2', [2019, 11, 'monthly', [[2019, 11, 15], [2019, 11, 14]]], [2019, 11, 13]], ['boundary control 1', [2024, 12, 'quarterly', []], [2024, 12, 31]], ['boundary control 2', [2024, 3, 'quarterly', []], [2024, 3, 29]], ['normal control 1', [2031, 1, 'quarterly', [[2031, 1, 17], [2031, 3, 28]]], [2031, 3, 31]], ['normal control 2', [2021, 4, 'quarterly', [[2021, 4, 16], [2021, 4, 15]]], [2021, 6, 30]]], [['regression first friday offset 1', [2025, 3, 'monthly', [[2025, 3, 21]]], [2025, 3, 20]], ['regression first friday offset 2', [2021, 8, 'monthly', []], [2021, 8, 20]], ['partial repair probe 1', [2022, 7, 'monthly', [[2022, 7, 15]]], [2022, 7, 14]], ['partial repair probe 2', [2025, 8, 'monthly', []], [2025, 8, 15]], ['boundary control 1', [2024, 12, 'quarterly', []], [2024, 12, 31]], ['boundary control 2', [2024, 3, 'quarterly', []], [2024, 3, 29]], ['normal control 1', [2029, 2, 'monthly', []], [2029, 2, 16]], ['normal control 2', [2032, 7, 'quarterly', []], [2032, 9, 30]]]]
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 datetime
N = 1
observations = []
def solve(y, m, kind, holidays):
    H = {datetime.date(*h) for h in holidays}
    def biz(x):
        return x.weekday() < 5 and x not in H
    def mlen(yy, mm):
        if mm == 2:
            return 29 if (yy % 4 == 0 and yy % 100 != 0) or yy % 400 == 0 else 28
        return 30 if mm in (4, 6, 9, 11) else 31
    if kind == 'quarterly':
        qm = ((m - 1) // 3 + 1) * 3
        x = datetime.date(y, qm, mlen(y, qm))
    else:
        first = datetime.date(y, m, 1)
        offset = (4 - first.weekday()) % 7 or 7
        x = first + datetime.timedelta(days=offset + 14)
    while not biz(x):
        x -= datetime.timedelta(days=1)
    return [x.year, x.month, x.day]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression first friday offset 1', [2032, 2, 'monthly', []], [2032, 2, 20]], ['regression first friday offset 2', [2030, 9, 'monthly', [[2030, 9, 20]]], [2030, 9, 19]], ['partial repair probe 1', [2023, 12, 'monthly', []], [2023, 12, 15]], ['partial repair probe 2', [2029, 6, 'monthly', []], [2029, 6, 15]], ['boundary control 1', [2024, 3, 'quarterly', []], [2024, 3, 29]], ['boundary control 2', [2024, 12, 'quarterly', []], [2024, 12, 31]], ['normal control 1', [2028, 8, 'monthly', []], [2028, 8, 18]], ['normal control 2', [2022, 3, 'quarterly', [[2022, 3, 28]]], [2022, 3, 31]]], [['regression first friday offset 1', [2023, 7, 'monthly', []], [2023, 7, 21]], ['regression first friday offset 2', [2031, 6, 'monthly', [[2031, 6, 20], [2031, 6, 19]]], [2031, 6, 18]], ['partial repair probe 1', [2025, 8, 'monthly', []], [2025, 8, 15]], ['partial repair probe 2', [2019, 2, 'monthly', [[2019, 2, 15], [2019, 2, 14]]], [2019, 2, 13]], ['boundary control 1', [2024, 12, 'quarterly', []], [2024, 12, 31]], ['boundary control 2', [2024, 3, 'quarterly', []], [2024, 3, 29]], ['normal control 1', [2021, 3, 'quarterly', []], [2021, 3, 31]], ['normal control 2', [2030, 11, 'quarterly', [[2030, 11, 15]]], [2030, 12, 31]]], [['regression first friday offset 1', [2023, 7, 'monthly', []], [2023, 7, 21]], ['regression first friday offset 2', [2020, 2, 'monthly', [[2020, 2, 21], [2020, 2, 20]]], [2020, 2, 19]], ['partial repair probe 1', [2029, 6, 'monthly', []], [2029, 6, 15]], ['partial repair probe 2', [2031, 8, 'monthly', []], [2031, 8, 15]], ['boundary control 1', [2024, 12, 'quarterly', []], [2024, 12, 31]], ['boundary control 2', [2024, 3, 'quarterly', []], [2024, 3, 29]], ['normal control 1', [2027, 3, 'monthly', [[2027, 3, 19], [2027, 3, 18]]], [2027, 3, 17]], ['normal control 2', [2022, 5, 'quarterly', [[2022, 6, 29]]], [2022, 6, 30]]], [['regression first friday offset 1', [2020, 2, 'monthly', []], [2020, 2, 21]], ['regression first friday offset 2', [2026, 3, 'monthly', [[2026, 3, 20]]], [2026, 3, 19]], ['partial repair probe 1', [2026, 5, 'monthly', []], [2026, 5, 15]], ['partial repair probe 2', [2019, 11, 'monthly', [[2019, 11, 15], [2019, 11, 14]]], [2019, 11, 13]], ['boundary control 1', [2024, 12, 'quarterly', []], [2024, 12, 31]], ['boundary control 2', [2024, 3, 'quarterly', []], [2024, 3, 29]], ['normal control 1', [2031, 1, 'quarterly', [[2031, 1, 17], [2031, 3, 28]]], [2031, 3, 31]], ['normal control 2', [2021, 4, 'quarterly', [[2021, 4, 16], [2021, 4, 15]]], [2021, 6, 30]]], [['regression first friday offset 1', [2025, 3, 'monthly', [[2025, 3, 21]]], [2025, 3, 20]], ['regression first friday offset 2', [2021, 8, 'monthly', []], [2021, 8, 20]], ['partial repair probe 1', [2022, 7, 'monthly', [[2022, 7, 15]]], [2022, 7, 14]], ['partial repair probe 2', [2025, 8, 'monthly', []], [2025, 8, 15]], ['boundary control 1', [2024, 12, 'quarterly', []], [2024, 12, 31]], ['boundary control 2', [2024, 3, 'quarterly', []], [2024, 3, 29]], ['normal control 1', [2029, 2, 'monthly', []], [2029, 2, 16]], ['normal control 2', [2032, 7, 'quarterly', []], [2032, 9, 30]]]]
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:
In months starting on a Saturday or Sunday the expiry lands a week early.

Inputs year, month, kind and holidays. Monthly expiry is the third Friday of the month; quarterly expiry is the last calendar day of the quarter-end month (Mar/Jun/Sep/Dec) containing the month. Either date rolls back to the preceding business day (weekday not in holidays) when it is not a business day. Return [y,m,d].

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import datetime
N = 1
observations = []
def solve(y, m, kind, holidays):
    H = {datetime.date(*h) for h in holidays}
    def biz(x):
        return x.weekday() < 5 and x not in H
    def mlen(yy, mm):
        if mm == 2:
            return 29 if (yy % 4 == 0 and yy % 100 != 0) or yy % 400 == 0 else 28
        return 30 if mm in (4, 6, 9, 11) else 31
    if kind == 'quarterly':
        qm = ((m - 1) // 3 + 1) * 3
        x = datetime.date(y, qm, mlen(y, qm))
    else:
        first = datetime.date(y, m, 1)
        offset = (4 - first.weekday()) % 7
        x = first + datetime.timedelta(days=offset + 14)
    while not biz(x):
        x += datetime.timedelta(days=1)
    return [x.year, x.month, x.day]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression holiday roll direction 1', [2030, 5, 'quarterly', [[2030, 6, 30]]], [2030, 6, 28]], ['regression holiday roll direction 2', [2032, 12, 'monthly', [[2032, 12, 17], [2032, 12, 16]]], [2032, 12, 15]], ['partial repair probe 1', [2032, 5, 'monthly', [[2032, 5, 21], [2032, 5, 20]]], [2032, 5, 19]], ['partial repair probe 2', [2021, 2, 'monthly', [[2021, 2, 19], [2021, 2, 18]]], [2021, 2, 17]], ['boundary control 1', [2024, 12, 'quarterly', []], [2024, 12, 31]], ['boundary control 2', [2024, 6, 'monthly', []], [2024, 6, 21]], ['normal control 1', [2022, 2, 'quarterly', []], [2022, 3, 31]], ['normal control 2', [2031, 4, 'quarterly', [[2031, 4, 18], [2031, 4, 17], [2031, 6, 27]]], [2031, 6, 30]]], [['regression holiday roll direction 1', [2028, 9, 'quarterly', [[2028, 9, 15], [2028, 9, 14], [2028, 9, 27]]], [2028, 9, 29]], ['regression holiday roll direction 2', [2028, 10, 'quarterly', []], [2028, 12, 29]], ['partial repair probe 1', [2024, 6, 'quarterly', [[2024, 6, 21], [2024, 6, 20]]], [2024, 6, 28]], ['partial repair probe 2', [2021, 9, 'monthly', [[2021, 9, 17], [2021, 9, 16]]], [2021, 9, 15]], ['boundary control 1', [2024, 6, 'monthly', []], [2024, 6, 21]], ['boundary control 2', [2024, 12, 'quarterly', []], [2024, 12, 31]], ['normal control 1', [2029, 2, 'monthly', []], [2029, 2, 16]], ['normal control 2', [2023, 11, 'monthly', []], [2023, 11, 17]]], [['regression holiday roll direction 1', [2029, 6, 'quarterly', [[2029, 6, 15]]], [2029, 6, 29]], ['regression holiday roll direction 2', [2025, 12, 'monthly', [[2025, 12, 19], [2025, 12, 18]]], [2025, 12, 17]], ['partial repair probe 1', [2029, 9, 'monthly', [[2029, 9, 21], [2029, 9, 20]]], [2029, 9, 19]], ['partial repair probe 2', [2022, 3, 'monthly', [[2022, 3, 18], [2022, 3, 17]]], [2022, 3, 16]], ['boundary control 1', [2024, 3, 'monthly', []], [2024, 3, 15]], ['boundary control 2', [2024, 6, 'monthly', []], [2024, 6, 21]], ['normal control 1', [2026, 2, 'quarterly', [[2026, 3, 30]]], [2026, 3, 31]], ['normal control 2', [2020, 8, 'quarterly', [[2020, 8, 21]]], [2020, 9, 30]]], [['regression holiday roll direction 1', [2029, 8, 'quarterly', []], [2029, 9, 28]], ['regression holiday roll direction 2', [2023, 5, 'monthly', [[2023, 5, 19], [2023, 5, 18]]], [2023, 5, 17]], ['partial repair probe 1', [2028, 12, 'quarterly', [[2028, 12, 29]]], [2028, 12, 28]], ['partial repair probe 2', [2030, 3, 'monthly', [[2030, 3, 15], [2030, 3, 14]]], [2030, 3, 13]], ['boundary control 1', [2024, 3, 'monthly', []], [2024, 3, 15]], ['boundary control 2', [2024, 6, 'monthly', []], [2024, 6, 21]], ['normal control 1', [2030, 10, 'monthly', []], [2030, 10, 18]], ['normal control 2', [2025, 7, 'monthly', []], [2025, 7, 18]]], [['regression holiday roll direction 1', [2024, 4, 'quarterly', [[2024, 6, 28]]], [2024, 6, 27]], ['regression holiday roll direction 2', [2024, 6, 'quarterly', [[2024, 6, 30]]], [2024, 6, 28]], ['partial repair probe 1', [2032, 2, 'monthly', [[2032, 2, 20], [2032, 2, 19]]], [2032, 2, 18]], ['partial repair probe 2', [2032, 4, 'monthly', [[2032, 4, 16], [2032, 4, 15]]], [2032, 4, 14]], ['boundary control 1', [2024, 3, 'monthly', []], [2024, 3, 15]], ['boundary control 2', [2024, 12, 'quarterly', []], [2024, 12, 31]], ['normal control 1', [2031, 12, 'monthly', []], [2031, 12, 19]], ['normal control 2', [2029, 4, 'monthly', []], [2029, 4, 20]]]]
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 datetime
N = 1
observations = []
def solve(y, m, kind, holidays):
    H = {datetime.date(*h) for h in holidays}
    def biz(x):
        return x.weekday() < 5 and x not in H
    def mlen(yy, mm):
        if mm == 2:
            return 29 if (yy % 4 == 0 and yy % 100 != 0) or yy % 400 == 0 else 28
        return 30 if mm in (4, 6, 9, 11) else 31
    if kind == 'quarterly':
        qm = ((m - 1) // 3 + 1) * 3
        x = datetime.date(y, qm, mlen(y, qm))
    else:
        first = datetime.date(y, m, 1)
        offset = (4 - first.weekday()) % 7
        x = first + datetime.timedelta(days=offset + 14)
    if not biz(x):
        x -= datetime.timedelta(days=1)
    return [x.year, x.month, x.day]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression holiday roll direction 1', [2030, 5, 'quarterly', [[2030, 6, 30]]], [2030, 6, 28]], ['regression holiday roll direction 2', [2032, 12, 'monthly', [[2032, 12, 17], [2032, 12, 16]]], [2032, 12, 15]], ['partial repair probe 1', [2032, 5, 'monthly', [[2032, 5, 21], [2032, 5, 20]]], [2032, 5, 19]], ['partial repair probe 2', [2021, 2, 'monthly', [[2021, 2, 19], [2021, 2, 18]]], [2021, 2, 17]], ['boundary control 1', [2024, 12, 'quarterly', []], [2024, 12, 31]], ['boundary control 2', [2024, 6, 'monthly', []], [2024, 6, 21]], ['normal control 1', [2022, 2, 'quarterly', []], [2022, 3, 31]], ['normal control 2', [2031, 4, 'quarterly', [[2031, 4, 18], [2031, 4, 17], [2031, 6, 27]]], [2031, 6, 30]]], [['regression holiday roll direction 1', [2028, 9, 'quarterly', [[2028, 9, 15], [2028, 9, 14], [2028, 9, 27]]], [2028, 9, 29]], ['regression holiday roll direction 2', [2028, 10, 'quarterly', []], [2028, 12, 29]], ['partial repair probe 1', [2024, 6, 'quarterly', [[2024, 6, 21], [2024, 6, 20]]], [2024, 6, 28]], ['partial repair probe 2', [2021, 9, 'monthly', [[2021, 9, 17], [2021, 9, 16]]], [2021, 9, 15]], ['boundary control 1', [2024, 6, 'monthly', []], [2024, 6, 21]], ['boundary control 2', [2024, 12, 'quarterly', []], [2024, 12, 31]], ['normal control 1', [2029, 2, 'monthly', []], [2029, 2, 16]], ['normal control 2', [2023, 11, 'monthly', []], [2023, 11, 17]]], [['regression holiday roll direction 1', [2029, 6, 'quarterly', [[2029, 6, 15]]], [2029, 6, 29]], ['regression holiday roll direction 2', [2025, 12, 'monthly', [[2025, 12, 19], [2025, 12, 18]]], [2025, 12, 17]], ['partial repair probe 1', [2029, 9, 'monthly', [[2029, 9, 21], [2029, 9, 20]]], [2029, 9, 19]], ['partial repair probe 2', [2022, 3, 'monthly', [[2022, 3, 18], [2022, 3, 17]]], [2022, 3, 16]], ['boundary control 1', [2024, 3, 'monthly', []], [2024, 3, 15]], ['boundary control 2', [2024, 6, 'monthly', []], [2024, 6, 21]], ['normal control 1', [2026, 2, 'quarterly', [[2026, 3, 30]]], [2026, 3, 31]], ['normal control 2', [2020, 8, 'quarterly', [[2020, 8, 21]]], [2020, 9, 30]]], [['regression holiday roll direction 1', [2029, 8, 'quarterly', []], [2029, 9, 28]], ['regression holiday roll direction 2', [2023, 5, 'monthly', [[2023, 5, 19], [2023, 5, 18]]], [2023, 5, 17]], ['partial repair probe 1', [2028, 12, 'quarterly', [[2028, 12, 29]]], [2028, 12, 28]], ['partial repair probe 2', [2030, 3, 'monthly', [[2030, 3, 15], [2030, 3, 14]]], [2030, 3, 13]], ['boundary control 1', [2024, 3, 'monthly', []], [2024, 3, 15]], ['boundary control 2', [2024, 6, 'monthly', []], [2024, 6, 21]], ['normal control 1', [2030, 10, 'monthly', []], [2030, 10, 18]], ['normal control 2', [2025, 7, 'monthly', []], [2025, 7, 18]]], [['regression holiday roll direction 1', [2024, 4, 'quarterly', [[2024, 6, 28]]], [2024, 6, 27]], ['regression holiday roll direction 2', [2024, 6, 'quarterly', [[2024, 6, 30]]], [2024, 6, 28]], ['partial repair probe 1', [2032, 2, 'monthly', [[2032, 2, 20], [2032, 2, 19]]], [2032, 2, 18]], ['partial repair probe 2', [2032, 4, 'monthly', [[2032, 4, 16], [2032, 4, 15]]], [2032, 4, 14]], ['boundary control 1', [2024, 3, 'monthly', []], [2024, 3, 15]], ['boundary control 2', [2024, 12, 'quarterly', []], [2024, 12, 31]], ['normal control 1', [2031, 12, 'monthly', []], [2031, 12, 19]], ['normal control 2', [2029, 4, 'monthly', []], [2029, 4, 20]]]]
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:
An expiry Friday that is a holiday moves to the following Monday.

Inputs year, month, kind and holidays. Monthly expiry is the third Friday of the month; quarterly expiry is the last calendar day of the quarter-end month (Mar/Jun/Sep/Dec) containing the month. Either date rolls back to the preceding business day (weekday not in holidays) when it is not a business day. Return [y,m,d].

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import datetime
N = 1
observations = []
def solve(y, m, kind, holidays):
    H = {datetime.date(*h) for h in holidays}
    def biz(x):
        return x.weekday() < 5 and x not in H
    def mlen(yy, mm):
        if mm == 2:
            return 29 if (yy % 4 == 0 and yy % 100 != 0) or yy % 400 == 0 else 28
        return 30 if mm in (4, 6, 9, 11) else 31
    if kind == 'quarterly':
        qm = (m // 3 + 1) * 3
        x = datetime.date(y, qm, mlen(y, qm))
    else:
        first = datetime.date(y, m, 1)
        offset = (4 - first.weekday()) % 7
        x = first + datetime.timedelta(days=offset + 14)
    while not biz(x):
        x -= datetime.timedelta(days=1)
    return [x.year, x.month, x.day]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression quarter month mapping 1', [2021, 3, 'quarterly', [[2021, 3, 29]]], [2021, 3, 31]], ['regression quarter month mapping 2', [2026, 6, 'quarterly', [[2026, 6, 19], [2026, 6, 18]]], [2026, 6, 30]], ['partial repair probe 1', [2030, 9, 'quarterly', []], [2030, 9, 30]], ['partial repair probe 2', [2025, 9, 'quarterly', []], [2025, 9, 30]], ['boundary control 1', [2024, 3, 'monthly', []], [2024, 3, 15]], ['boundary control 2', [2024, 6, 'monthly', []], [2024, 6, 21]], ['normal control 1', [2031, 3, 'monthly', []], [2031, 3, 21]], ['normal control 2', [2024, 3, 'monthly', [[2024, 3, 15], [2024, 3, 14]]], [2024, 3, 13]]], [['regression quarter month mapping 1', [2030, 3, 'quarterly', []], [2030, 3, 29]], ['regression quarter month mapping 2', [2027, 6, 'quarterly', [[2027, 6, 27]]], [2027, 6, 30]], ['partial repair probe 1', [2020, 6, 'quarterly', [[2020, 6, 19], [2020, 6, 18]]], [2020, 6, 30]], ['partial repair probe 2', [2029, 3, 'quarterly', [[2029, 3, 28]]], [2029, 3, 30]], ['boundary control 1', [2024, 6, 'monthly', []], [2024, 6, 21]], ['boundary control 2', [2024, 3, 'monthly', []], [2024, 3, 15]], ['normal control 1', [2028, 11, 'monthly', [[2028, 11, 17], [2028, 11, 16]]], [2028, 11, 15]], ['normal control 2', [2030, 11, 'quarterly', []], [2030, 12, 31]]], [['regression quarter month mapping 1', [2026, 9, 'quarterly', []], [2026, 9, 30]], ['regression quarter month mapping 2', [2027, 6, 'quarterly', [[2027, 6, 18], [2027, 6, 28]]], [2027, 6, 30]], ['partial repair probe 1', [2030, 9, 'quarterly', []], [2030, 9, 30]], ['partial repair probe 2', [2029, 9, 'quarterly', [[2029, 9, 21], [2029, 9, 28]]], [2029, 9, 27]], ['boundary control 1', [2024, 6, 'monthly', []], [2024, 6, 21]], ['boundary control 2', [2024, 3, 'monthly', []], [2024, 3, 15]], ['normal control 1', [2029, 8, 'monthly', []], [2029, 8, 17]], ['normal control 2', [2022, 4, 'monthly', [[2022, 4, 15]]], [2022, 4, 14]]], [['regression quarter month mapping 1', [2031, 9, 'quarterly', [[2031, 9, 27]]], [2031, 9, 30]], ['regression quarter month mapping 2', [2032, 3, 'quarterly', [[2032, 3, 28]]], [2032, 3, 31]], ['partial repair probe 1', [2029, 6, 'quarterly', []], [2029, 6, 29]], ['partial repair probe 2', [2027, 9, 'quarterly', [[2027, 9, 17], [2027, 9, 27]]], [2027, 9, 30]], ['boundary control 1', [2024, 6, 'monthly', []], [2024, 6, 21]], ['boundary control 2', [2024, 3, 'monthly', []], [2024, 3, 15]], ['normal control 1', [2023, 3, 'monthly', []], [2023, 3, 17]], ['normal control 2', [2032, 5, 'quarterly', [[2032, 6, 28]]], [2032, 6, 30]]], [['regression quarter month mapping 1', [2029, 3, 'quarterly', [[2029, 3, 16], [2029, 3, 30]]], [2029, 3, 29]], ['regression quarter month mapping 2', [2029, 3, 'quarterly', []], [2029, 3, 30]], ['partial repair probe 1', [2029, 3, 'quarterly', [[2029, 3, 16], [2029, 3, 15], [2029, 3, 30]]], [2029, 3, 29]], ['partial repair probe 2', [2019, 9, 'quarterly', [[2019, 9, 20], [2019, 9, 30]]], [2019, 9, 27]], ['boundary control 1', [2024, 3, 'monthly', []], [2024, 3, 15]], ['boundary control 2', [2024, 6, 'monthly', []], [2024, 6, 21]], ['normal control 1', [2020, 7, 'quarterly', [[2020, 9, 30]]], [2020, 9, 29]], ['normal control 2', [2026, 9, 'monthly', [[2026, 9, 18]]], [2026, 9, 17]]]]
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 datetime
N = 1
observations = []
def solve(y, m, kind, holidays):
    H = {datetime.date(*h) for h in holidays}
    def biz(x):
        return x.weekday() < 5 and x not in H
    def mlen(yy, mm):
        if mm == 2:
            return 29 if (yy % 4 == 0 and yy % 100 != 0) or yy % 400 == 0 else 28
        return 30 if mm in (4, 6, 9, 11) else 31
    if kind == 'quarterly':
        qm = min(12, (m // 3 + 1) * 3)
        x = datetime.date(y, qm, mlen(y, qm))
    else:
        first = datetime.date(y, m, 1)
        offset = (4 - first.weekday()) % 7
        x = first + datetime.timedelta(days=offset + 14)
    while not biz(x):
        x -= datetime.timedelta(days=1)
    return [x.year, x.month, x.day]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression quarter month mapping 1', [2021, 3, 'quarterly', [[2021, 3, 29]]], [2021, 3, 31]], ['regression quarter month mapping 2', [2026, 6, 'quarterly', [[2026, 6, 19], [2026, 6, 18]]], [2026, 6, 30]], ['partial repair probe 1', [2030, 9, 'quarterly', []], [2030, 9, 30]], ['partial repair probe 2', [2025, 9, 'quarterly', []], [2025, 9, 30]], ['boundary control 1', [2024, 3, 'monthly', []], [2024, 3, 15]], ['boundary control 2', [2024, 6, 'monthly', []], [2024, 6, 21]], ['normal control 1', [2031, 3, 'monthly', []], [2031, 3, 21]], ['normal control 2', [2024, 3, 'monthly', [[2024, 3, 15], [2024, 3, 14]]], [2024, 3, 13]]], [['regression quarter month mapping 1', [2030, 3, 'quarterly', []], [2030, 3, 29]], ['regression quarter month mapping 2', [2027, 6, 'quarterly', [[2027, 6, 27]]], [2027, 6, 30]], ['partial repair probe 1', [2020, 6, 'quarterly', [[2020, 6, 19], [2020, 6, 18]]], [2020, 6, 30]], ['partial repair probe 2', [2029, 3, 'quarterly', [[2029, 3, 28]]], [2029, 3, 30]], ['boundary control 1', [2024, 6, 'monthly', []], [2024, 6, 21]], ['boundary control 2', [2024, 3, 'monthly', []], [2024, 3, 15]], ['normal control 1', [2028, 11, 'monthly', [[2028, 11, 17], [2028, 11, 16]]], [2028, 11, 15]], ['normal control 2', [2030, 11, 'quarterly', []], [2030, 12, 31]]], [['regression quarter month mapping 1', [2026, 9, 'quarterly', []], [2026, 9, 30]], ['regression quarter month mapping 2', [2027, 6, 'quarterly', [[2027, 6, 18], [2027, 6, 28]]], [2027, 6, 30]], ['partial repair probe 1', [2030, 9, 'quarterly', []], [2030, 9, 30]], ['partial repair probe 2', [2029, 9, 'quarterly', [[2029, 9, 21], [2029, 9, 28]]], [2029, 9, 27]], ['boundary control 1', [2024, 6, 'monthly', []], [2024, 6, 21]], ['boundary control 2', [2024, 3, 'monthly', []], [2024, 3, 15]], ['normal control 1', [2029, 8, 'monthly', []], [2029, 8, 17]], ['normal control 2', [2022, 4, 'monthly', [[2022, 4, 15]]], [2022, 4, 14]]], [['regression quarter month mapping 1', [2031, 9, 'quarterly', [[2031, 9, 27]]], [2031, 9, 30]], ['regression quarter month mapping 2', [2032, 3, 'quarterly', [[2032, 3, 28]]], [2032, 3, 31]], ['partial repair probe 1', [2029, 6, 'quarterly', []], [2029, 6, 29]], ['partial repair probe 2', [2027, 9, 'quarterly', [[2027, 9, 17], [2027, 9, 27]]], [2027, 9, 30]], ['boundary control 1', [2024, 6, 'monthly', []], [2024, 6, 21]], ['boundary control 2', [2024, 3, 'monthly', []], [2024, 3, 15]], ['normal control 1', [2023, 3, 'monthly', []], [2023, 3, 17]], ['normal control 2', [2032, 5, 'quarterly', [[2032, 6, 28]]], [2032, 6, 30]]], [['regression quarter month mapping 1', [2029, 3, 'quarterly', [[2029, 3, 16], [2029, 3, 30]]], [2029, 3, 29]], ['regression quarter month mapping 2', [2029, 3, 'quarterly', []], [2029, 3, 30]], ['partial repair probe 1', [2029, 3, 'quarterly', [[2029, 3, 16], [2029, 3, 15], [2029, 3, 30]]], [2029, 3, 29]], ['partial repair probe 2', [2019, 9, 'quarterly', [[2019, 9, 20], [2019, 9, 30]]], [2019, 9, 27]], ['boundary control 1', [2024, 3, 'monthly', []], [2024, 3, 15]], ['boundary control 2', [2024, 6, 'monthly', []], [2024, 6, 21]], ['normal control 1', [2020, 7, 'quarterly', [[2020, 9, 30]]], [2020, 9, 29]], ['normal control 2', [2026, 9, 'monthly', [[2026, 9, 18]]], [2026, 9, 17]]]]
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:
March, June and September quarterly contracts expire three months late.

Inputs year, month, kind and holidays. Monthly expiry is the third Friday of the month; quarterly expiry is the last calendar day of the quarter-end month (Mar/Jun/Sep/Dec) containing the month. Either date rolls back to the preceding business day (weekday not in holidays) when it is not a business day. Return [y,m,d].

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import datetime
N = 1
observations = []
def solve(y, m, kind, holidays):
    H = {datetime.date(*h) for h in holidays}
    def biz(x):
        return x.weekday() < 5 and x not in H
    def mlen(yy, mm):
        if mm == 2:
            return 29 if (yy % 4 == 0 and yy % 100 != 0) or yy % 400 == 0 else 28
        return 30 if mm in (4, 6, 9, 11) else 31
    if kind == 'quarterly':
        qm = ((m - 1) // 3 + 1) * 3
        x = datetime.date(y, qm, mlen(y, qm))
        return [x.year, x.month, x.day]
    else:
        first = datetime.date(y, m, 1)
        offset = (4 - first.weekday()) % 7
        x = first + datetime.timedelta(days=offset + 14)
    while not biz(x):
        x -= datetime.timedelta(days=1)
    return [x.year, x.month, x.day]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression quarterly business day 1', [2021, 7, 'quarterly', [[2021, 9, 30]]], [2021, 9, 29]], ['regression quarterly business day 2', [2028, 10, 'quarterly', [[2028, 10, 20], [2028, 10, 19]]], [2028, 12, 29]], ['partial repair probe 1', [2030, 4, 'quarterly', [[2030, 6, 28]]], [2030, 6, 27]], ['partial repair probe 2', [2024, 1, 'quarterly', [[2024, 3, 29]]], [2024, 3, 28]], ['boundary control 1', [2024, 3, 'monthly', []], [2024, 3, 15]], ['boundary control 2', [2024, 6, 'monthly', []], [2024, 6, 21]], ['normal control 1', [2022, 12, 'monthly', []], [2022, 12, 16]], ['normal control 2', [2021, 4, 'monthly', []], [2021, 4, 16]]], [['regression quarterly business day 1', [2031, 4, 'quarterly', [[2031, 6, 30]]], [2031, 6, 27]], ['regression quarterly business day 2', [2027, 8, 'quarterly', [[2027, 9, 30]]], [2027, 9, 29]], ['partial repair probe 1', [2031, 6, 'quarterly', [[2031, 6, 30]]], [2031, 6, 27]], ['partial repair probe 2', [2027, 10, 'quarterly', [[2027, 10, 15], [2027, 10, 14], [2027, 12, 31]]], [2027, 12, 30]], ['boundary control 1', [2024, 6, 'monthly', []], [2024, 6, 21]], ['boundary control 2', [2024, 12, 'quarterly', []], [2024, 12, 31]], ['normal control 1', [2022, 1, 'monthly', [[2022, 1, 21]]], [2022, 1, 20]], ['normal control 2', [2023, 4, 'quarterly', [[2023, 4, 21]]], [2023, 6, 30]]], [['regression quarterly business day 1', [2028, 11, 'quarterly', [[2028, 12, 29]]], [2028, 12, 28]], ['regression quarterly business day 2', [2019, 5, 'quarterly', [[2019, 6, 27]]], [2019, 6, 28]], ['partial repair probe 1', [2021, 3, 'quarterly', [[2021, 3, 31]]], [2021, 3, 30]], ['partial repair probe 2', [2021, 9, 'quarterly', [[2021, 9, 17], [2021, 9, 16], [2021, 9, 30]]], [2021, 9, 29]], ['boundary control 1', [2024, 12, 'quarterly', []], [2024, 12, 31]], ['boundary control 2', [2024, 3, 'monthly', []], [2024, 3, 15]], ['normal control 1', [2024, 12, 'monthly', [[2024, 12, 20], [2024, 12, 19]]], [2024, 12, 18]], ['normal control 2', [2025, 11, 'monthly', []], [2025, 11, 21]]], [['regression quarterly business day 1', [2023, 7, 'quarterly', []], [2023, 9, 29]], ['regression quarterly business day 2', [2030, 6, 'quarterly', [[2030, 6, 21], [2030, 6, 20]]], [2030, 6, 28]], ['partial repair probe 1', [2019, 12, 'quarterly', [[2019, 12, 31]]], [2019, 12, 30]], ['partial repair probe 2', [2024, 6, 'quarterly', [[2024, 6, 28]]], [2024, 6, 27]], ['boundary control 1', [2024, 6, 'monthly', []], [2024, 6, 21]], ['boundary control 2', [2024, 12, 'quarterly', []], [2024, 12, 31]], ['normal control 1', [2020, 5, 'monthly', []], [2020, 5, 15]], ['normal control 2', [2023, 6, 'quarterly', [[2023, 6, 16]]], [2023, 6, 30]]], [['regression quarterly business day 1', [2029, 7, 'quarterly', [[2029, 7, 20], [2029, 7, 19]]], [2029, 9, 28]], ['regression quarterly business day 2', [2029, 4, 'quarterly', [[2029, 6, 29]]], [2029, 6, 28]], ['partial repair probe 1', [2031, 7, 'quarterly', [[2031, 9, 30]]], [2031, 9, 29]], ['partial repair probe 2', [2027, 5, 'quarterly', [[2027, 6, 30]]], [2027, 6, 29]], ['boundary control 1', [2024, 6, 'monthly', []], [2024, 6, 21]], ['boundary control 2', [2024, 3, 'monthly', []], [2024, 3, 15]], ['normal control 1', [2026, 10, 'monthly', [[2026, 10, 16], [2026, 10, 15]]], [2026, 10, 14]], ['normal control 2', [2028, 10, 'monthly', []], [2028, 10, 20]]]]
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 datetime
N = 1
observations = []
def solve(y, m, kind, holidays):
    H = {datetime.date(*h) for h in holidays}
    def biz(x):
        return x.weekday() < 5 and x not in H
    def mlen(yy, mm):
        if mm == 2:
            return 29 if (yy % 4 == 0 and yy % 100 != 0) or yy % 400 == 0 else 28
        return 30 if mm in (4, 6, 9, 11) else 31
    if kind == 'quarterly':
        qm = ((m - 1) // 3 + 1) * 3
        x = datetime.date(y, qm, mlen(y, qm))
        while x.weekday() >= 5:
            x -= datetime.timedelta(days=1)
        return [x.year, x.month, x.day]
    else:
        first = datetime.date(y, m, 1)
        offset = (4 - first.weekday()) % 7
        x = first + datetime.timedelta(days=offset + 14)
    while not biz(x):
        x -= datetime.timedelta(days=1)
    return [x.year, x.month, x.day]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression quarterly business day 1', [2021, 7, 'quarterly', [[2021, 9, 30]]], [2021, 9, 29]], ['regression quarterly business day 2', [2028, 10, 'quarterly', [[2028, 10, 20], [2028, 10, 19]]], [2028, 12, 29]], ['partial repair probe 1', [2030, 4, 'quarterly', [[2030, 6, 28]]], [2030, 6, 27]], ['partial repair probe 2', [2024, 1, 'quarterly', [[2024, 3, 29]]], [2024, 3, 28]], ['boundary control 1', [2024, 3, 'monthly', []], [2024, 3, 15]], ['boundary control 2', [2024, 6, 'monthly', []], [2024, 6, 21]], ['normal control 1', [2022, 12, 'monthly', []], [2022, 12, 16]], ['normal control 2', [2021, 4, 'monthly', []], [2021, 4, 16]]], [['regression quarterly business day 1', [2031, 4, 'quarterly', [[2031, 6, 30]]], [2031, 6, 27]], ['regression quarterly business day 2', [2027, 8, 'quarterly', [[2027, 9, 30]]], [2027, 9, 29]], ['partial repair probe 1', [2031, 6, 'quarterly', [[2031, 6, 30]]], [2031, 6, 27]], ['partial repair probe 2', [2027, 10, 'quarterly', [[2027, 10, 15], [2027, 10, 14], [2027, 12, 31]]], [2027, 12, 30]], ['boundary control 1', [2024, 6, 'monthly', []], [2024, 6, 21]], ['boundary control 2', [2024, 12, 'quarterly', []], [2024, 12, 31]], ['normal control 1', [2022, 1, 'monthly', [[2022, 1, 21]]], [2022, 1, 20]], ['normal control 2', [2023, 4, 'quarterly', [[2023, 4, 21]]], [2023, 6, 30]]], [['regression quarterly business day 1', [2028, 11, 'quarterly', [[2028, 12, 29]]], [2028, 12, 28]], ['regression quarterly business day 2', [2019, 5, 'quarterly', [[2019, 6, 27]]], [2019, 6, 28]], ['partial repair probe 1', [2021, 3, 'quarterly', [[2021, 3, 31]]], [2021, 3, 30]], ['partial repair probe 2', [2021, 9, 'quarterly', [[2021, 9, 17], [2021, 9, 16], [2021, 9, 30]]], [2021, 9, 29]], ['boundary control 1', [2024, 12, 'quarterly', []], [2024, 12, 31]], ['boundary control 2', [2024, 3, 'monthly', []], [2024, 3, 15]], ['normal control 1', [2024, 12, 'monthly', [[2024, 12, 20], [2024, 12, 19]]], [2024, 12, 18]], ['normal control 2', [2025, 11, 'monthly', []], [2025, 11, 21]]], [['regression quarterly business day 1', [2023, 7, 'quarterly', []], [2023, 9, 29]], ['regression quarterly business day 2', [2030, 6, 'quarterly', [[2030, 6, 21], [2030, 6, 20]]], [2030, 6, 28]], ['partial repair probe 1', [2019, 12, 'quarterly', [[2019, 12, 31]]], [2019, 12, 30]], ['partial repair probe 2', [2024, 6, 'quarterly', [[2024, 6, 28]]], [2024, 6, 27]], ['boundary control 1', [2024, 6, 'monthly', []], [2024, 6, 21]], ['boundary control 2', [2024, 12, 'quarterly', []], [2024, 12, 31]], ['normal control 1', [2020, 5, 'monthly', []], [2020, 5, 15]], ['normal control 2', [2023, 6, 'quarterly', [[2023, 6, 16]]], [2023, 6, 30]]], [['regression quarterly business day 1', [2029, 7, 'quarterly', [[2029, 7, 20], [2029, 7, 19]]], [2029, 9, 28]], ['regression quarterly business day 2', [2029, 4, 'quarterly', [[2029, 6, 29]]], [2029, 6, 28]], ['partial repair probe 1', [2031, 7, 'quarterly', [[2031, 9, 30]]], [2031, 9, 29]], ['partial repair probe 2', [2027, 5, 'quarterly', [[2027, 6, 30]]], [2027, 6, 29]], ['boundary control 1', [2024, 6, 'monthly', []], [2024, 6, 21]], ['boundary control 2', [2024, 3, 'monthly', []], [2024, 3, 15]], ['normal control 1', [2026, 10, 'monthly', [[2026, 10, 16], [2026, 10, 15]]], [2026, 10, 14]], ['normal control 2', [2028, 10, 'monthly', []], [2028, 10, 20]]]]
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:
Quarter-end expiries on Saturdays or Sundays are not moved.

Inputs year, month, kind and holidays. Monthly expiry is the third Friday of the month; quarterly expiry is the last calendar day of the quarter-end month (Mar/Jun/Sep/Dec) containing the month. Either date rolls back to the preceding business day (weekday not in holidays) when it is not a business day. Return [y,m,d].

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import datetime
N = 1
observations = []
def solve(y, m, kind, holidays):
    H = {datetime.date(*h) for h in holidays}
    def biz(x):
        return x.weekday() < 5 and x not in H
    def mlen(yy, mm):
        if mm == 2:
            return 29 if (yy % 4 == 0 and yy % 100 != 0) or yy % 400 == 0 else 28
        return 30 if mm in (4, 6, 9, 11) else 31
    if kind == 'quarterly':
        qm = ((m - 1) // 3 + 1) * 3
        x = datetime.date(y, qm, mlen(y, qm))
    else:
        first = datetime.date(y, m, 1)
        offset = (5 - first.weekday()) % 7
        x = first + datetime.timedelta(days=offset + 14)
    while not biz(x):
        x -= datetime.timedelta(days=1)
    return [x.year, x.month, x.day]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression weekday numbering 1', [2022, 10, 'monthly', []], [2022, 10, 21]], ['regression weekday numbering 2', [2028, 4, 'monthly', [[2028, 4, 21]]], [2028, 4, 20]], ['partial repair probe 1', [2023, 6, 'monthly', []], [2023, 6, 16]], ['partial repair probe 2', [2022, 4, 'monthly', []], [2022, 4, 15]], ['boundary control 1', [2024, 3, 'quarterly', []], [2024, 3, 29]], ['boundary control 2', [2024, 12, 'quarterly', []], [2024, 12, 31]], ['normal control 1', [2024, 2, 'quarterly', [[2024, 2, 16], [2024, 2, 15], [2024, 3, 31]]], [2024, 3, 29]], ['normal control 2', [2030, 6, 'quarterly', [[2030, 6, 28]]], [2030, 6, 27]]], [['regression weekday numbering 1', [2031, 11, 'monthly', [[2031, 11, 21], [2031, 11, 20]]], [2031, 11, 19]], ['regression weekday numbering 2', [2032, 5, 'monthly', []], [2032, 5, 21]], ['partial repair probe 1', [2019, 7, 'monthly', []], [2019, 7, 19]], ['partial repair probe 2', [2029, 6, 'monthly', [[2029, 6, 15], [2029, 6, 14]]], [2029, 6, 13]], ['boundary control 1', [2024, 3, 'quarterly', []], [2024, 3, 29]], ['boundary control 2', [2024, 12, 'quarterly', []], [2024, 12, 31]], ['normal control 1', [2022, 2, 'quarterly', []], [2022, 3, 31]], ['normal control 2', [2032, 12, 'monthly', [[2032, 12, 17], [2032, 12, 16]]], [2032, 12, 15]]], [['regression weekday numbering 1', [2028, 4, 'monthly', []], [2028, 4, 21]], ['regression weekday numbering 2', [2025, 11, 'monthly', [[2025, 11, 21], [2025, 11, 20]]], [2025, 11, 19]], ['partial repair probe 1', [2028, 2, 'monthly', []], [2028, 2, 18]], ['partial repair probe 2', [2022, 11, 'monthly', []], [2022, 11, 18]], ['boundary control 1', [2024, 3, 'quarterly', []], [2024, 3, 29]], ['boundary control 2', [2024, 12, 'quarterly', []], [2024, 12, 31]], ['normal control 1', [2026, 7, 'quarterly', []], [2026, 9, 30]], ['normal control 2', [2031, 5, 'monthly', [[2031, 5, 16], [2031, 5, 15]]], [2031, 5, 14]]], [['regression weekday numbering 1', [2020, 8, 'monthly', []], [2020, 8, 21]], ['regression weekday numbering 2', [2031, 11, 'monthly', []], [2031, 11, 21]], ['partial repair probe 1', [2024, 8, 'monthly', []], [2024, 8, 16]], ['partial repair probe 2', [2029, 5, 'monthly', []], [2029, 5, 18]], ['boundary control 1', [2024, 12, 'quarterly', []], [2024, 12, 31]], ['boundary control 2', [2024, 3, 'quarterly', []], [2024, 3, 29]], ['normal control 1', [2030, 12, 'monthly', [[2030, 12, 20]]], [2030, 12, 19]], ['normal control 2', [2031, 3, 'quarterly', [[2031, 3, 28]]], [2031, 3, 31]]], [['regression weekday numbering 1', [2028, 1, 'monthly', []], [2028, 1, 21]], ['regression weekday numbering 2', [2025, 3, 'monthly', []], [2025, 3, 21]], ['partial repair probe 1', [2025, 8, 'monthly', []], [2025, 8, 15]], ['partial repair probe 2', [2030, 2, 'monthly', [[2030, 2, 15]]], [2030, 2, 14]], ['boundary control 1', [2024, 12, 'quarterly', []], [2024, 12, 31]], ['boundary control 2', [2024, 3, 'quarterly', []], [2024, 3, 29]], ['normal control 1', [2019, 5, 'quarterly', []], [2019, 6, 28]], ['normal control 2', [2024, 5, 'quarterly', [[2024, 5, 17], [2024, 6, 27]]], [2024, 6, 28]]]]
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 datetime
N = 1
observations = []
def solve(y, m, kind, holidays):
    H = {datetime.date(*h) for h in holidays}
    def biz(x):
        return x.weekday() < 5 and x not in H
    def mlen(yy, mm):
        if mm == 2:
            return 29 if (yy % 4 == 0 and yy % 100 != 0) or yy % 400 == 0 else 28
        return 30 if mm in (4, 6, 9, 11) else 31
    if kind == 'quarterly':
        qm = ((m - 1) // 3 + 1) * 3
        x = datetime.date(y, qm, mlen(y, qm))
    else:
        first = datetime.date(y, m, 1)
        offset = (4 - first.isoweekday()) % 7
        x = first + datetime.timedelta(days=offset + 14)
    while not biz(x):
        x -= datetime.timedelta(days=1)
    return [x.year, x.month, x.day]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression weekday numbering 1', [2022, 10, 'monthly', []], [2022, 10, 21]], ['regression weekday numbering 2', [2028, 4, 'monthly', [[2028, 4, 21]]], [2028, 4, 20]], ['partial repair probe 1', [2023, 6, 'monthly', []], [2023, 6, 16]], ['partial repair probe 2', [2022, 4, 'monthly', []], [2022, 4, 15]], ['boundary control 1', [2024, 3, 'quarterly', []], [2024, 3, 29]], ['boundary control 2', [2024, 12, 'quarterly', []], [2024, 12, 31]], ['normal control 1', [2024, 2, 'quarterly', [[2024, 2, 16], [2024, 2, 15], [2024, 3, 31]]], [2024, 3, 29]], ['normal control 2', [2030, 6, 'quarterly', [[2030, 6, 28]]], [2030, 6, 27]]], [['regression weekday numbering 1', [2031, 11, 'monthly', [[2031, 11, 21], [2031, 11, 20]]], [2031, 11, 19]], ['regression weekday numbering 2', [2032, 5, 'monthly', []], [2032, 5, 21]], ['partial repair probe 1', [2019, 7, 'monthly', []], [2019, 7, 19]], ['partial repair probe 2', [2029, 6, 'monthly', [[2029, 6, 15], [2029, 6, 14]]], [2029, 6, 13]], ['boundary control 1', [2024, 3, 'quarterly', []], [2024, 3, 29]], ['boundary control 2', [2024, 12, 'quarterly', []], [2024, 12, 31]], ['normal control 1', [2022, 2, 'quarterly', []], [2022, 3, 31]], ['normal control 2', [2032, 12, 'monthly', [[2032, 12, 17], [2032, 12, 16]]], [2032, 12, 15]]], [['regression weekday numbering 1', [2028, 4, 'monthly', []], [2028, 4, 21]], ['regression weekday numbering 2', [2025, 11, 'monthly', [[2025, 11, 21], [2025, 11, 20]]], [2025, 11, 19]], ['partial repair probe 1', [2028, 2, 'monthly', []], [2028, 2, 18]], ['partial repair probe 2', [2022, 11, 'monthly', []], [2022, 11, 18]], ['boundary control 1', [2024, 3, 'quarterly', []], [2024, 3, 29]], ['boundary control 2', [2024, 12, 'quarterly', []], [2024, 12, 31]], ['normal control 1', [2026, 7, 'quarterly', []], [2026, 9, 30]], ['normal control 2', [2031, 5, 'monthly', [[2031, 5, 16], [2031, 5, 15]]], [2031, 5, 14]]], [['regression weekday numbering 1', [2020, 8, 'monthly', []], [2020, 8, 21]], ['regression weekday numbering 2', [2031, 11, 'monthly', []], [2031, 11, 21]], ['partial repair probe 1', [2024, 8, 'monthly', []], [2024, 8, 16]], ['partial repair probe 2', [2029, 5, 'monthly', []], [2029, 5, 18]], ['boundary control 1', [2024, 12, 'quarterly', []], [2024, 12, 31]], ['boundary control 2', [2024, 3, 'quarterly', []], [2024, 3, 29]], ['normal control 1', [2030, 12, 'monthly', [[2030, 12, 20]]], [2030, 12, 19]], ['normal control 2', [2031, 3, 'quarterly', [[2031, 3, 28]]], [2031, 3, 31]]], [['regression weekday numbering 1', [2028, 1, 'monthly', []], [2028, 1, 21]], ['regression weekday numbering 2', [2025, 3, 'monthly', []], [2025, 3, 21]], ['partial repair probe 1', [2025, 8, 'monthly', []], [2025, 8, 15]], ['partial repair probe 2', [2030, 2, 'monthly', [[2030, 2, 15]]], [2030, 2, 14]], ['boundary control 1', [2024, 12, 'quarterly', []], [2024, 12, 31]], ['boundary control 2', [2024, 3, 'quarterly', []], [2024, 3, 29]], ['normal control 1', [2019, 5, 'quarterly', []], [2019, 6, 28]], ['normal control 2', [2024, 5, 'quarterly', [[2024, 5, 17], [2024, 6, 27]]], [2024, 6, 28]]]]
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:
Monthly expiries land on the third Saturday.

Inputs year, month, kind and holidays. Monthly expiry is the third Friday of the month; quarterly expiry is the last calendar day of the quarter-end month (Mar/Jun/Sep/Dec) containing the month. Either date rolls back to the preceding business day (weekday not in holidays) when it is not a business day. Return [y,m,d].

split: open-access


prompt:
Deep out-of-the-money puts get no margin relief while in-the-money puts get relief.

Inputs kind, underlying price, strike, premium, contracts and multiplier. Out-of-the-money amount is max(K-S,0) for calls and max(S-K,0) for puts. Per-unit requirement = premium + max(20% of underlying - OTM amount, 10% of floor base) where the floor base is the underlying for calls and the strike for puts. Return requirement*multiplier*contracts rounded to cents.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
N = 1
observations = []
def solve(kind, underlying, strike, premium, contracts, multiplier):
    S = Fraction(str(underlying))
    K = Fraction(str(strike))
    P = Fraction(str(premium))
    otm = max(K - S, 0) if kind == 'C' else max(S - K, 0)
    floor_base = S
    req = P + max(S * Fraction(20, 100) - otm, floor_base * Fraction(10, 100))
    return float(round(req * multiplier * contracts, 2))
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression minimum floor base 1', ['P', 120.0, 95, 0.5, 10, 10], 1000.0], ['regression minimum floor base 2', ['P', 120.0, 95, 0.5, 10, 100], 10000.0], ['partial repair probe 1', ['C', 92.5, 110, 8.0, 1, 100], 1725.0], ['partial repair probe 2', ['C', 92.5, 105, 3.4, 2, 100], 2530.0], ['boundary control 1', ['P', 80.0, 100, 20.5, 1, 100], 3650.0], ['boundary control 2', ['C', 100.0, 100, 2.0, 1, 100], 2200.0], ['normal control 1', ['P', 100.0, 110, 3.4, 2, 10], 468.0], ['normal control 2', ['C', 92.5, 100, 1.25, 2, 10], 245.0]], [['regression minimum floor base 1', ['P', 120.0, 95, 3.4, 2, 100], 2580.0], ['regression minimum floor base 2', ['P', 104.25, 90, 3.4, 10, 100], 12400.0], ['partial repair probe 1', ['C', 100.0, 110, 15.1, 1, 100], 2510.0], ['partial repair probe 2', ['C', 80.0, 90, 1.25, 10, 10], 925.0], ['boundary control 1', ['P', 80.0, 100, 20.5, 1, 100], 3650.0], ['boundary control 2', ['C', 100.0, 100, 2.0, 1, 100], 2200.0], ['normal control 1', ['C', 100.0, 100, 1.25, 2, 100], 4250.0], ['normal control 2', ['P', 92.5, 95, 3.4, 1, 100], 2190.0]], [['regression minimum floor base 1', ['P', 120.0, 95, 3.4, 2, 10], 258.0], ['regression minimum floor base 2', ['P', 120.0, 95, 3.4, 1, 100], 1290.0], ['partial repair probe 1', ['C', 80.0, 95, 8.0, 1, 10], 160.0], ['partial repair probe 2', ['C', 80.0, 110, 8.0, 1, 100], 1600.0], ['boundary control 1', ['P', 80.0, 100, 20.5, 1, 100], 3650.0], ['boundary control 2', ['C', 100.0, 100, 2.0, 1, 100], 2200.0], ['normal control 1', ['P', 104.25, 105, 0.5, 2, 100], 4270.0], ['normal control 2', ['P', 100.0, 110, 1.25, 10, 10], 2125.0]], [['regression minimum floor base 1', ['P', 120.0, 95, 3.4, 1, 10], 129.0], ['regression minimum floor base 2', ['P', 120.0, 105, 3.4, 10, 10], 1390.0], ['partial repair probe 1', ['C', 80.0, 100, 3.4, 1, 100], 1140.0], ['partial repair probe 2', ['C', 100.0, 110, 3.4, 2, 100], 2680.0], ['boundary control 1', ['P', 80.0, 100, 20.5, 1, 100], 3650.0], ['boundary control 2', ['C', 100.0, 100, 2.0, 1, 100], 2200.0], ['normal control 1', ['P', 120.0, 110, 8.0, 10, 100], 22000.0], ['normal control 2', ['P', 92.5, 100, 15.1, 1, 10], 336.0]], [['regression minimum floor base 1', ['P', 120.0, 95, 0.5, 10, 100], 10000.0], ['regression minimum floor base 2', ['P', 120.0, 100, 8.0, 1, 100], 1800.0], ['partial repair probe 1', ['C', 92.5, 105, 0.5, 2, 100], 1950.0], ['partial repair probe 2', ['C', 80.0, 105, 3.4, 1, 10], 114.0], ['boundary control 1', ['C', 100.0, 100, 2.0, 1, 100], 2200.0], ['boundary control 2', ['P', 80.0, 100, 20.5, 1, 100], 3650.0], ['normal control 1', ['P', 104.25, 95, 15.1, 10, 100], 26700.0], ['normal control 2', ['C', 104.25, 110, 1.25, 10, 10], 1635.0]]]
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
from fractions import Fraction
N = 1
observations = []
def solve(kind, underlying, strike, premium, contracts, multiplier):
    S = Fraction(str(underlying))
    K = Fraction(str(strike))
    P = Fraction(str(premium))
    otm = max(K - S, 0) if kind == 'C' else max(S - K, 0)
    floor_base = K
    req = P + max(S * Fraction(20, 100) - otm, floor_base * Fraction(10, 100))
    return float(round(req * multiplier * contracts, 2))
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression minimum floor base 1', ['P', 120.0, 95, 0.5, 10, 10], 1000.0], ['regression minimum floor base 2', ['P', 120.0, 95, 0.5, 10, 100], 10000.0], ['partial repair probe 1', ['C', 92.5, 110, 8.0, 1, 100], 1725.0], ['partial repair probe 2', ['C', 92.5, 105, 3.4, 2, 100], 2530.0], ['boundary control 1', ['P', 80.0, 100, 20.5, 1, 100], 3650.0], ['boundary control 2', ['C', 100.0, 100, 2.0, 1, 100], 2200.0], ['normal control 1', ['P', 100.0, 110, 3.4, 2, 10], 468.0], ['normal control 2', ['C', 92.5, 100, 1.25, 2, 10], 245.0]], [['regression minimum floor base 1', ['P', 120.0, 95, 3.4, 2, 100], 2580.0], ['regression minimum floor base 2', ['P', 104.25, 90, 3.4, 10, 100], 12400.0], ['partial repair probe 1', ['C', 100.0, 110, 15.1, 1, 100], 2510.0], ['partial repair probe 2', ['C', 80.0, 90, 1.25, 10, 10], 925.0], ['boundary control 1', ['P', 80.0, 100, 20.5, 1, 100], 3650.0], ['boundary control 2', ['C', 100.0, 100, 2.0, 1, 100], 2200.0], ['normal control 1', ['C', 100.0, 100, 1.25, 2, 100], 4250.0], ['normal control 2', ['P', 92.5, 95, 3.4, 1, 100], 2190.0]], [['regression minimum floor base 1', ['P', 120.0, 95, 3.4, 2, 10], 258.0], ['regression minimum floor base 2', ['P', 120.0, 95, 3.4, 1, 100], 1290.0], ['partial repair probe 1', ['C', 80.0, 95, 8.0, 1, 10], 160.0], ['partial repair probe 2', ['C', 80.0, 110, 8.0, 1, 100], 1600.0], ['boundary control 1', ['P', 80.0, 100, 20.5, 1, 100], 3650.0], ['boundary control 2', ['C', 100.0, 100, 2.0, 1, 100], 2200.0], ['normal control 1', ['P', 104.25, 105, 0.5, 2, 100], 4270.0], ['normal control 2', ['P', 100.0, 110, 1.25, 10, 10], 2125.0]], [['regression minimum floor base 1', ['P', 120.0, 95, 3.4, 1, 10], 129.0], ['regression minimum floor base 2', ['P', 120.0, 105, 3.4, 10, 10], 1390.0], ['partial repair probe 1', ['C', 80.0, 100, 3.4, 1, 100], 1140.0], ['partial repair probe 2', ['C', 100.0, 110, 3.4, 2, 100], 2680.0], ['boundary control 1', ['P', 80.0, 100, 20.5, 1, 100], 3650.0], ['boundary control 2', ['C', 100.0, 100, 2.0, 1, 100], 2200.0], ['normal control 1', ['P', 120.0, 110, 8.0, 10, 100], 22000.0], ['normal control 2', ['P', 92.5, 100, 15.1, 1, 10], 336.0]], [['regression minimum floor base 1', ['P', 120.0, 95, 0.5, 10, 100], 10000.0], ['regression minimum floor base 2', ['P', 120.0, 100, 8.0, 1, 100], 1800.0], ['partial repair probe 1', ['C', 92.5, 105, 0.5, 2, 100], 1950.0], ['partial repair probe 2', ['C', 80.0, 105, 3.4, 1, 10], 114.0], ['boundary control 1', ['C', 100.0, 100, 2.0, 1, 100], 2200.0], ['boundary control 2', ['P', 80.0, 100, 20.5, 1, 100], 3650.0], ['normal control 1', ['P', 104.25, 95, 15.1, 10, 100], 26700.0], ['normal control 2', ['C', 104.25, 110, 1.25, 10, 10], 1635.0]]]
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:
Put minimums are wrong whenever the underlying differs from the strike.

Inputs kind, underlying price, strike, premium, contracts and multiplier. Out-of-the-money amount is max(K-S,0) for calls and max(S-K,0) for puts. Per-unit requirement = premium + max(20% of underlying - OTM amount, 10% of floor base) where the floor base is the underlying for calls and the strike for puts. Return requirement*multiplier*contracts rounded to cents.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
N = 1
observations = []
def solve(kind, underlying, strike, premium, contracts, multiplier):
    S = Fraction(str(underlying))
    K = Fraction(str(strike))
    P = Fraction(str(premium))
    otm = max(K - S, 0) if kind == 'C' else max(S - K, 0)
    floor_base = S if kind == 'C' else K
    req = P + max(S * Fraction(20, 100), floor_base * Fraction(10, 100)) - otm
    return float(round(req * multiplier * contracts, 2))
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression otm reduction placement 1', ['C', 80.0, 110, 8.0, 10, 100], 16000.0], ['regression otm reduction placement 2', ['P', 120.0, 100, 0.5, 2, 100], 2100.0], ['partial repair probe 1', ['P', 100.0, 90, 15.1, 1, 10], 251.0], ['partial repair probe 2', ['P', 104.25, 100, 15.1, 2, 100], 6340.0], ['boundary control 1', ['C', 100.0, 100, 2.0, 1, 100], 2200.0], ['boundary control 2', ['P', 80.0, 100, 20.5, 1, 100], 3650.0], ['normal control 1', ['C', 100.0, 95, 0.5, 10, 10], 2050.0], ['normal control 2', ['C', 104.25, 90, 3.4, 10, 10], 2425.0]], [['regression otm reduction placement 1', ['P', 104.25, 90, 0.5, 2, 10], 190.0], ['regression otm reduction placement 2', ['P', 120.0, 90, 0.5, 2, 100], 1900.0], ['partial repair probe 1', ['C', 100.0, 110, 1.25, 2, 100], 2250.0], ['partial repair probe 2', ['P', 92.5, 90, 8.0, 2, 100], 4800.0], ['boundary control 1', ['C', 100.0, 100, 2.0, 1, 100], 2200.0], ['boundary control 2', ['P', 80.0, 100, 20.5, 1, 100], 3650.0], ['normal control 1', ['C', 92.5, 90, 1.25, 10, 100], 19750.0], ['normal control 2', ['P', 100.0, 105, 8.0, 10, 10], 2800.0]], [['regression otm reduction placement 1', ['C', 92.5, 110, 1.25, 10, 100], 10500.0], ['regression otm reduction placement 2', ['P', 104.25, 90, 0.5, 1, 10], 95.0], ['partial repair probe 1', ['P', 104.25, 100, 8.0, 10, 100], 24600.0], ['partial repair probe 2', ['C', 104.25, 105, 1.25, 10, 10], 2135.0], ['boundary control 1', ['P', 80.0, 100, 20.5, 1, 100], 3650.0], ['boundary control 2', ['C', 100.0, 100, 2.0, 1, 100], 2200.0], ['normal control 1', ['C', 92.5, 90, 15.1, 10, 100], 33600.0], ['normal control 2', ['P', 80.0, 95, 0.5, 10, 10], 1650.0]], [['regression otm reduction placement 1', ['P', 104.25, 90, 3.4, 1, 100], 1240.0], ['regression otm reduction placement 2', ['C', 80.0, 105, 3.4, 2, 100], 2280.0], ['partial repair probe 1', ['P', 104.25, 95, 3.4, 10, 100], 15000.0], ['partial repair probe 2', ['P', 92.5, 90, 1.25, 2, 100], 3450.0], ['boundary control 1', ['C', 100.0, 100, 2.0, 1, 100], 2200.0], ['boundary control 2', ['P', 80.0, 100, 20.5, 1, 100], 3650.0], ['normal control 1', ['P', 80.0, 100, 8.0, 2, 100], 4800.0], ['normal control 2', ['P', 92.5, 100, 1.25, 1, 100], 1975.0]], [['regression otm reduction placement 1', ['C', 80.0, 95, 1.25, 10, 100], 9250.0], ['regression otm reduction placement 2', ['C', 80.0, 95, 0.5, 1, 10], 85.0], ['partial repair probe 1', ['P', 100.0, 95, 0.5, 10, 100], 15500.0], ['partial repair probe 2', ['P', 104.25, 95, 8.0, 2, 100], 3920.0], ['boundary control 1', ['C', 100.0, 100, 2.0, 1, 100], 2200.0], ['boundary control 2', ['P', 80.0, 100, 20.5, 1, 100], 3650.0], ['normal control 1', ['C', 120.0, 110, 0.5, 10, 100], 24500.0], ['normal control 2', ['P', 92.5, 110, 1.25, 2, 100], 3950.0]]]
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
from fractions import Fraction
N = 1
observations = []
def solve(kind, underlying, strike, premium, contracts, multiplier):
    S = Fraction(str(underlying))
    K = Fraction(str(strike))
    P = Fraction(str(premium))
    otm = max(K - S, 0) if kind == 'C' else max(S - K, 0)
    floor_base = S if kind == 'C' else K
    req = P + max(S * Fraction(20, 100) - otm / 2, floor_base * Fraction(10, 100))
    return float(round(req * multiplier * contracts, 2))
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression otm reduction placement 1', ['C', 80.0, 110, 8.0, 10, 100], 16000.0], ['regression otm reduction placement 2', ['P', 120.0, 100, 0.5, 2, 100], 2100.0], ['partial repair probe 1', ['P', 100.0, 90, 15.1, 1, 10], 251.0], ['partial repair probe 2', ['P', 104.25, 100, 15.1, 2, 100], 6340.0], ['boundary control 1', ['C', 100.0, 100, 2.0, 1, 100], 2200.0], ['boundary control 2', ['P', 80.0, 100, 20.5, 1, 100], 3650.0], ['normal control 1', ['C', 100.0, 95, 0.5, 10, 10], 2050.0], ['normal control 2', ['C', 104.25, 90, 3.4, 10, 10], 2425.0]], [['regression otm reduction placement 1', ['P', 104.25, 90, 0.5, 2, 10], 190.0], ['regression otm reduction placement 2', ['P', 120.0, 90, 0.5, 2, 100], 1900.0], ['partial repair probe 1', ['C', 100.0, 110, 1.25, 2, 100], 2250.0], ['partial repair probe 2', ['P', 92.5, 90, 8.0, 2, 100], 4800.0], ['boundary control 1', ['C', 100.0, 100, 2.0, 1, 100], 2200.0], ['boundary control 2', ['P', 80.0, 100, 20.5, 1, 100], 3650.0], ['normal control 1', ['C', 92.5, 90, 1.25, 10, 100], 19750.0], ['normal control 2', ['P', 100.0, 105, 8.0, 10, 10], 2800.0]], [['regression otm reduction placement 1', ['C', 92.5, 110, 1.25, 10, 100], 10500.0], ['regression otm reduction placement 2', ['P', 104.25, 90, 0.5, 1, 10], 95.0], ['partial repair probe 1', ['P', 104.25, 100, 8.0, 10, 100], 24600.0], ['partial repair probe 2', ['C', 104.25, 105, 1.25, 10, 10], 2135.0], ['boundary control 1', ['P', 80.0, 100, 20.5, 1, 100], 3650.0], ['boundary control 2', ['C', 100.0, 100, 2.0, 1, 100], 2200.0], ['normal control 1', ['C', 92.5, 90, 15.1, 10, 100], 33600.0], ['normal control 2', ['P', 80.0, 95, 0.5, 10, 10], 1650.0]], [['regression otm reduction placement 1', ['P', 104.25, 90, 3.4, 1, 100], 1240.0], ['regression otm reduction placement 2', ['C', 80.0, 105, 3.4, 2, 100], 2280.0], ['partial repair probe 1', ['P', 104.25, 95, 3.4, 10, 100], 15000.0], ['partial repair probe 2', ['P', 92.5, 90, 1.25, 2, 100], 3450.0], ['boundary control 1', ['C', 100.0, 100, 2.0, 1, 100], 2200.0], ['boundary control 2', ['P', 80.0, 100, 20.5, 1, 100], 3650.0], ['normal control 1', ['P', 80.0, 100, 8.0, 2, 100], 4800.0], ['normal control 2', ['P', 92.5, 100, 1.25, 1, 100], 1975.0]], [['regression otm reduction placement 1', ['C', 80.0, 95, 1.25, 10, 100], 9250.0], ['regression otm reduction placement 2', ['C', 80.0, 95, 0.5, 1, 10], 85.0], ['partial repair probe 1', ['P', 100.0, 95, 0.5, 10, 100], 15500.0], ['partial repair probe 2', ['P', 104.25, 95, 8.0, 2, 100], 3920.0], ['boundary control 1', ['C', 100.0, 100, 2.0, 1, 100], 2200.0], ['boundary control 2', ['P', 80.0, 100, 20.5, 1, 100], 3650.0], ['normal control 1', ['C', 120.0, 110, 0.5, 10, 100], 24500.0], ['normal control 2', ['P', 92.5, 110, 1.25, 2, 100], 3950.0]]]
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:
Far out-of-the-money options fall below the minimum requirement.

Inputs kind, underlying price, strike, premium, contracts and multiplier. Out-of-the-money amount is max(K-S,0) for calls and max(S-K,0) for puts. Per-unit requirement = premium + max(20% of underlying - OTM amount, 10% of floor base) where the floor base is the underlying for calls and the strike for puts. Return requirement*multiplier*contracts rounded to cents.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
N = 1
observations = []
def solve(kind, underlying, strike, premium, contracts, multiplier):
    S = Fraction(str(underlying))
    K = Fraction(str(strike))
    P = Fraction(str(premium))
    otm = max(K - S, 0) if kind == 'C' else max(S - K, 0)
    floor_base = S if kind == 'C' else K
    req = max(P + S * Fraction(20, 100) - otm, floor_base * Fraction(10, 100))
    return float(round(req * multiplier * contracts, 2))
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression premium inclusion 1', ['P', 120.0, 95, 3.4, 1, 100], 1290.0], ['regression premium inclusion 2', ['C', 80.0, 90, 0.5, 2, 10], 170.0], ['partial repair probe 1', ['P', 104.25, 110, 3.4, 1, 100], 2425.0], ['partial repair probe 2', ['P', 100.0, 95, 3.4, 1, 10], 184.0], ['normal control 1', ['P', 80.0, 90, 8.0, 1, 10], 240.0], ['normal control 2', ['P', 80.0, 105, 15.1, 2, 10], 622.0], ['normal control 3', ['P', 100.0, 100, 15.1, 1, 100], 3510.0], ['normal control 4', ['C', 100.0, 110, 1.25, 1, 100], 1125.0]], [['regression premium inclusion 1', ['P', 120.0, 95, 1.25, 1, 100], 1075.0], ['regression premium inclusion 2', ['C', 92.5, 110, 0.5, 10, 100], 9750.0], ['partial repair probe 1', ['P', 80.0, 95, 1.25, 1, 100], 1725.0], ['partial repair probe 2', ['P', 92.5, 105, 8.0, 1, 10], 265.0], ['normal control 1', ['C', 100.0, 95, 0.5, 10, 10], 2050.0], ['normal control 2', ['C', 100.0, 110, 1.25, 2, 100], 2250.0], ['normal control 3', ['C', 100.0, 110, 15.1, 1, 10], 251.0], ['normal control 4', ['P', 120.0, 95, 0.5, 2, 100], 2000.0]], [['regression premium inclusion 1', ['P', 120.0, 95, 3.4, 1, 100], 1290.0], ['regression premium inclusion 2', ['P', 120.0, 95, 1.25, 10, 10], 1075.0], ['partial repair probe 1', ['C', 92.5, 90, 3.4, 10, 100], 21900.0], ['partial repair probe 2', ['P', 80.0, 95, 8.0, 10, 10], 2400.0], ['normal control 1', ['C', 92.5, 95, 8.0, 2, 10], 480.0], ['normal control 2', ['C', 104.25, 105, 1.25, 1, 10], 213.5], ['normal control 3', ['P', 92.5, 95, 1.25, 10, 100], 19750.0], ['normal control 4', ['C', 80.0, 95, 3.4, 1, 100], 1140.0]], [['regression premium inclusion 1', ['C', 80.0, 90, 15.1, 2, 10], 462.0], ['regression premium inclusion 2', ['P', 120.0, 105, 1.25, 10, 10], 1175.0], ['partial repair probe 1', ['P', 100.0, 95, 3.4, 1, 10], 184.0], ['partial repair probe 2', ['P', 100.0, 100, 1.25, 2, 10], 425.0], ['normal control 1', ['C', 80.0, 100, 1.25, 1, 10], 92.5], ['normal control 2', ['P', 120.0, 95, 0.5, 2, 10], 200.0], ['normal control 3', ['P', 80.0, 100, 15.1, 2, 10], 622.0], ['normal control 4', ['C', 80.0, 105, 0.5, 2, 100], 1700.0]], [['regression premium inclusion 1', ['C', 80.0, 100, 15.1, 2, 100], 4620.0], ['regression premium inclusion 2', ['P', 104.25, 90, 8.0, 1, 100], 1700.0], ['partial repair probe 1', ['P', 80.0, 95, 3.4, 10, 100], 19400.0], ['partial repair probe 2', ['P', 80.0, 105, 0.5, 1, 10], 165.0], ['normal control 1', ['C', 120.0, 105, 3.4, 2, 100], 5480.0], ['normal control 2', ['C', 80.0, 95, 8.0, 10, 10], 1600.0], ['normal control 3', ['C', 100.0, 90, 0.5, 10, 100], 20500.0], ['normal control 4', ['P', 120.0, 100, 15.1, 10, 10], 2510.0]]]
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
from fractions import Fraction
N = 1
observations = []
def solve(kind, underlying, strike, premium, contracts, multiplier):
    S = Fraction(str(underlying))
    K = Fraction(str(strike))
    P = Fraction(str(premium))
    otm = max(K - S, 0) if kind == 'C' else max(S - K, 0)
    floor_base = S if kind == 'C' else K
    req = max(S * Fraction(20, 100) - otm, floor_base * Fraction(10, 100))
    return float(round(req * multiplier * contracts, 2))
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression premium inclusion 1', ['P', 120.0, 95, 3.4, 1, 100], 1290.0], ['regression premium inclusion 2', ['C', 80.0, 90, 0.5, 2, 10], 170.0], ['partial repair probe 1', ['P', 104.25, 110, 3.4, 1, 100], 2425.0], ['partial repair probe 2', ['P', 100.0, 95, 3.4, 1, 10], 184.0], ['normal control 1', ['P', 80.0, 90, 8.0, 1, 10], 240.0], ['normal control 2', ['P', 80.0, 105, 15.1, 2, 10], 622.0], ['normal control 3', ['P', 100.0, 100, 15.1, 1, 100], 3510.0], ['normal control 4', ['C', 100.0, 110, 1.25, 1, 100], 1125.0]], [['regression premium inclusion 1', ['P', 120.0, 95, 1.25, 1, 100], 1075.0], ['regression premium inclusion 2', ['C', 92.5, 110, 0.5, 10, 100], 9750.0], ['partial repair probe 1', ['P', 80.0, 95, 1.25, 1, 100], 1725.0], ['partial repair probe 2', ['P', 92.5, 105, 8.0, 1, 10], 265.0], ['normal control 1', ['C', 100.0, 95, 0.5, 10, 10], 2050.0], ['normal control 2', ['C', 100.0, 110, 1.25, 2, 100], 2250.0], ['normal control 3', ['C', 100.0, 110, 15.1, 1, 10], 251.0], ['normal control 4', ['P', 120.0, 95, 0.5, 2, 100], 2000.0]], [['regression premium inclusion 1', ['P', 120.0, 95, 3.4, 1, 100], 1290.0], ['regression premium inclusion 2', ['P', 120.0, 95, 1.25, 10, 10], 1075.0], ['partial repair probe 1', ['C', 92.5, 90, 3.4, 10, 100], 21900.0], ['partial repair probe 2', ['P', 80.0, 95, 8.0, 10, 10], 2400.0], ['normal control 1', ['C', 92.5, 95, 8.0, 2, 10], 480.0], ['normal control 2', ['C', 104.25, 105, 1.25, 1, 10], 213.5], ['normal control 3', ['P', 92.5, 95, 1.25, 10, 100], 19750.0], ['normal control 4', ['C', 80.0, 95, 3.4, 1, 100], 1140.0]], [['regression premium inclusion 1', ['C', 80.0, 90, 15.1, 2, 10], 462.0], ['regression premium inclusion 2', ['P', 120.0, 105, 1.25, 10, 10], 1175.0], ['partial repair probe 1', ['P', 100.0, 95, 3.4, 1, 10], 184.0], ['partial repair probe 2', ['P', 100.0, 100, 1.25, 2, 10], 425.0], ['normal control 1', ['C', 80.0, 100, 1.25, 1, 10], 92.5], ['normal control 2', ['P', 120.0, 95, 0.5, 2, 10], 200.0], ['normal control 3', ['P', 80.0, 100, 15.1, 2, 10], 622.0], ['normal control 4', ['C', 80.0, 105, 0.5, 2, 100], 1700.0]], [['regression premium inclusion 1', ['C', 80.0, 100, 15.1, 2, 100], 4620.0], ['regression premium inclusion 2', ['P', 104.25, 90, 8.0, 1, 100], 1700.0], ['partial repair probe 1', ['P', 80.0, 95, 3.4, 10, 100], 19400.0], ['partial repair probe 2', ['P', 80.0, 105, 0.5, 1, 10], 165.0], ['normal control 1', ['C', 120.0, 105, 3.4, 2, 100], 5480.0], ['normal control 2', ['C', 80.0, 95, 8.0, 10, 10], 1600.0], ['normal control 3', ['C', 100.0, 90, 0.5, 10, 100], 20500.0], ['normal control 4', ['P', 120.0, 100, 15.1, 10, 10], 2510.0]]]
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:
Options at the minimum requirement exclude their own premium.

Inputs kind, underlying price, strike, premium, contracts and multiplier. Out-of-the-money amount is max(K-S,0) for calls and max(S-K,0) for puts. Per-unit requirement = premium + max(20% of underlying - OTM amount, 10% of floor base) where the floor base is the underlying for calls and the strike for puts. Return requirement*multiplier*contracts rounded to cents.

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], reverse=True):
            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 fifo ordering 1', [6, [['F6', 1, 10], ['E5', 2, 14], ['B2', 3, 15], ['C3', 3, 16], ['A1', 7, 2]], 'fifo'], [['A1', 6]]], ['regression fifo ordering 2', [5, [['F6', 3, 8], ['D4', 7, 11], ['E5', 10, 5], ['C3', 7, 19], ['B2', 1, 9]], 'fifo'], [['E5', 5]]], ['partial repair probe 1', [4, [['C3', 3, 19], ['E5', 3, 13], ['F6', 10, 10], ['B2', 2, 2]], 'fifo'], [['B2', 2], ['F6', 2]]], ['partial repair probe 2', [16, [['B2', 5, 12], ['E5', 10, 9], ['C3', 7, 11], ['D4', 10, 18]], 'fifo'], [['C3', 6], ['E5', 10]]], ['boundary control 1', [3, [['A1', 1, 1], ['B2', 1, 2], ['C3', 1, 3]], 'pro-rata'], [['A1', 1], ['B2', 1], ['C3', 1]]], ['normal control 1', [10, [['F6', 1, 1], ['C3', 1, 5], ['D4', 3, 12], ['A1', 7, 6], ['B2', 2, 4]], 'pro-rata'], [['A1', 5], ['B2', 1], ['C3', 1], ['D4', 2], ['F6', 1]]], ['normal control 2', [8, [['E5', 2, 16], ['A1', 10, 1]], 'pro-rata'], [['A1', 7], ['E5', 1]]], ['normal control 3', [1, [['D4', 1, 16]], 'pro-rata'], [['D4', 1]]]], [['regression fifo ordering 1', [2, [['C3', 3, 11], ['E5', 10, 6], ['F6', 7, 17], ['A1', 10, 4]], 'fifo'], [['A1', 2]]], ['regression fifo ordering 2', [15, [['D4', 5, 11], ['E5', 10, 3], ['B2', 5, 14], ['C3', 2, 15]], 'fifo'], [['D4', 5], ['E5', 10]]], ['partial repair probe 1', [10, [['F6', 3, 1], ['A1', 10, 6], ['C3', 1, 5]], 'fifo'], [['A1', 6], ['C3', 1], ['F6', 3]]], ['partial repair probe 2', [7, [['A1', 7, 16], ['B2', 3, 14]], 'fifo'], [['A1', 4], ['B2', 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', [9, [['D4', 10, 17], ['E5', 3, 11]], 'pro-rata'], [['D4', 7], ['E5', 2]]], ['normal control 2', [1, [['F6', 10, 15]], 'fifo'], [['F6', 1]]], ['normal control 3', [12, [['B2', 5, 8], ['D4', 3, 1], ['E5', 1, 2], ['C3', 3, 4], ['A1', 7, 13]], 'pro-rata'], [['A1', 4], ['B2', 3], ['C3', 2], ['D4', 2], ['E5', 1]]]], [['regression fifo ordering 1', [4, [['C3', 10, 15], ['E5', 5, 16], ['F6', 7, 3], ['B2', 1, 9]], 'fifo'], [['F6', 4]]], ['regression fifo ordering 2', [1, [['F6', 3, 17], ['D4', 1, 18]], 'fifo'], [['F6', 1]]], ['partial repair probe 1', [7, [['C3', 1, 4], ['F6', 10, 2], ['D4', 7, 18], ['A1', 5, 8], ['E5', 1, 15]], 'fifo'], [['F6', 7]]], ['partial repair probe 2', [13, [['E5', 7, 7], ['A1', 5, 9], ['D4', 2, 6]], 'fifo'], [['A1', 4], ['D4', 2], ['E5', 7]]], ['boundary control 1', [3, [['A1', 1, 1], ['B2', 1, 2], ['C3', 1, 3]], 'pro-rata'], [['A1', 1], ['B2', 1], ['C3', 1]]], ['normal control 1', [5, [['F6', 3, 7], ['B2', 2, 19]], 'pro-rata'], [['B2', 2], ['F6', 3]]], ['normal control 2', [4, [['F6', 1, 8], ['B2', 2, 4], ['D4', 3, 15], ['C3', 7, 16]], 'pro-rata'], [['B2', 1], ['C3', 2], ['D4', 1]]], ['normal control 3', [2, [['D4', 2, 1]], 'pro-rata'], [['D4', 2]]]], [['regression fifo ordering 1', [22, [['F6', 7, 10], ['B2', 5, 7], ['C3', 2, 19], ['A1', 10, 14], ['E5', 5, 8]], 'fifo'], [['A1', 5], ['B2', 5], ['E5', 5], ['F6', 7]]], ['regression fifo ordering 2', [2, [['F6', 2, 5], ['C3', 1, 6]], 'fifo'], [['F6', 2]]], ['partial repair probe 1', [8, [['D4', 5, 5], ['C3', 7, 9]], 'fifo'], [['C3', 3], ['D4', 5]]], ['partial repair probe 2', [7, [['F6', 5, 16], ['D4', 3, 18], ['B2', 3, 17]], 'fifo'], [['B2', 2], ['F6', 5]]], ['boundary control 1', [3, [['A1', 1, 1], ['B2', 1, 2], ['C3', 1, 3]], 'pro-rata'], [['A1', 1], ['B2', 1], ['C3', 1]]], ['normal control 1', [16, [['F6', 10, 18], ['B2', 1, 12], ['D4', 10, 3]], 'pro-rata'], [['B2', 1], ['D4', 8], ['F6', 7]]], ['normal control 2', [1, [['E5', 1, 17]], 'pro-rata'], [['E5', 1]]], ['normal control 3', [7, [['C3', 7, 13], ['B2', 3, 8]], 'pro-rata'], [['B2', 2], ['C3', 5]]]], [['regression fifo ordering 1', [9, [['D4', 1, 12], ['B2', 7, 9], ['F6', 7, 19], ['C3', 10, 18]], 'fifo'], [['B2', 7], ['C3', 1], ['D4', 1]]], ['regression fifo ordering 2', [12, [['E5', 1, 5], ['F6', 3, 1], ['B2', 10, 3], ['C3', 3, 8]], 'fifo'], [['B2', 9], ['F6', 3]]], ['partial repair probe 1', [8, [['F6', 1, 14], ['B2', 2, 2], ['C3', 1, 18], ['A1', 7, 15]], 'fifo'], [['A1', 5], ['B2', 2], ['F6', 1]]], ['partial repair probe 2', [3, [['F6', 2, 8], ['D4', 2, 17], ['E5', 10, 15]], 'fifo'], [['E5', 1], ['F6', 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', [17, [['A1', 10, 11], ['D4', 10, 16], ['F6', 1, 5]], 'pro-rata'], [['A1', 8], ['D4', 8], ['F6', 1]]], ['normal control 2', [4, [['A1', 2, 4], ['B2', 2, 2], ['E5', 2, 1], ['D4', 2, 10]], 'pro-rata'], [['A1', 1], ['B2', 1], ['D4', 1], ['E5', 1]]], ['normal control 3', [7, [['B2', 2, 11], ['F6', 2, 6], ['D4', 3, 14]], 'pro-rata'], [['B2', 2], ['D4', 3], ['F6', 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[0]):
            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 fifo ordering 1', [6, [['F6', 1, 10], ['E5', 2, 14], ['B2', 3, 15], ['C3', 3, 16], ['A1', 7, 2]], 'fifo'], [['A1', 6]]], ['regression fifo ordering 2', [5, [['F6', 3, 8], ['D4', 7, 11], ['E5', 10, 5], ['C3', 7, 19], ['B2', 1, 9]], 'fifo'], [['E5', 5]]], ['partial repair probe 1', [4, [['C3', 3, 19], ['E5', 3, 13], ['F6', 10, 10], ['B2', 2, 2]], 'fifo'], [['B2', 2], ['F6', 2]]], ['partial repair probe 2', [16, [['B2', 5, 12], ['E5', 10, 9], ['C3', 7, 11], ['D4', 10, 18]], 'fifo'], [['C3', 6], ['E5', 10]]], ['boundary control 1', [3, [['A1', 1, 1], ['B2', 1, 2], ['C3', 1, 3]], 'pro-rata'], [['A1', 1], ['B2', 1], ['C3', 1]]], ['normal control 1', [10, [['F6', 1, 1], ['C3', 1, 5], ['D4', 3, 12], ['A1', 7, 6], ['B2', 2, 4]], 'pro-rata'], [['A1', 5], ['B2', 1], ['C3', 1], ['D4', 2], ['F6', 1]]], ['normal control 2', [8, [['E5', 2, 16], ['A1', 10, 1]], 'pro-rata'], [['A1', 7], ['E5', 1]]], ['normal control 3', [1, [['D4', 1, 16]], 'pro-rata'], [['D4', 1]]]], [['regression fifo ordering 1', [2, [['C3', 3, 11], ['E5', 10, 6], ['F6', 7, 17], ['A1', 10, 4]], 'fifo'], [['A1', 2]]], ['regression fifo ordering 2', [15, [['D4', 5, 11], ['E5', 10, 3], ['B2', 5, 14], ['C3', 2, 15]], 'fifo'], [['D4', 5], ['E5', 10]]], ['partial repair probe 1', [10, [['F6', 3, 1], ['A1', 10, 6], ['C3', 1, 5]], 'fifo'], [['A1', 6], ['C3', 1], ['F6', 3]]], ['partial repair probe 2', [7, [['A1', 7, 16], ['B2', 3, 14]], 'fifo'], [['A1', 4], ['B2', 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', [9, [['D4', 10, 17], ['E5', 3, 11]], 'pro-rata'], [['D4', 7], ['E5', 2]]], ['normal control 2', [1, [['F6', 10, 15]], 'fifo'], [['F6', 1]]], ['normal control 3', [12, [['B2', 5, 8], ['D4', 3, 1], ['E5', 1, 2], ['C3', 3, 4], ['A1', 7, 13]], 'pro-rata'], [['A1', 4], ['B2', 3], ['C3', 2], ['D4', 2], ['E5', 1]]]], [['regression fifo ordering 1', [4, [['C3', 10, 15], ['E5', 5, 16], ['F6', 7, 3], ['B2', 1, 9]], 'fifo'], [['F6', 4]]], ['regression fifo ordering 2', [1, [['F6', 3, 17], ['D4', 1, 18]], 'fifo'], [['F6', 1]]], ['partial repair probe 1', [7, [['C3', 1, 4], ['F6', 10, 2], ['D4', 7, 18], ['A1', 5, 8], ['E5', 1, 15]], 'fifo'], [['F6', 7]]], ['partial repair probe 2', [13, [['E5', 7, 7], ['A1', 5, 9], ['D4', 2, 6]], 'fifo'], [['A1', 4], ['D4', 2], ['E5', 7]]], ['boundary control 1', [3, [['A1', 1, 1], ['B2', 1, 2], ['C3', 1, 3]], 'pro-rata'], [['A1', 1], ['B2', 1], ['C3', 1]]], ['normal control 1', [5, [['F6', 3, 7], ['B2', 2, 19]], 'pro-rata'], [['B2', 2], ['F6', 3]]], ['normal control 2', [4, [['F6', 1, 8], ['B2', 2, 4], ['D4', 3, 15], ['C3', 7, 16]], 'pro-rata'], [['B2', 1], ['C3', 2], ['D4', 1]]], ['normal control 3', [2, [['D4', 2, 1]], 'pro-rata'], [['D4', 2]]]], [['regression fifo ordering 1', [22, [['F6', 7, 10], ['B2', 5, 7], ['C3', 2, 19], ['A1', 10, 14], ['E5', 5, 8]], 'fifo'], [['A1', 5], ['B2', 5], ['E5', 5], ['F6', 7]]], ['regression fifo ordering 2', [2, [['F6', 2, 5], ['C3', 1, 6]], 'fifo'], [['F6', 2]]], ['partial repair probe 1', [8, [['D4', 5, 5], ['C3', 7, 9]], 'fifo'], [['C3', 3], ['D4', 5]]], ['partial repair probe 2', [7, [['F6', 5, 16], ['D4', 3, 18], ['B2', 3, 17]], 'fifo'], [['B2', 2], ['F6', 5]]], ['boundary control 1', [3, [['A1', 1, 1], ['B2', 1, 2], ['C3', 1, 3]], 'pro-rata'], [['A1', 1], ['B2', 1], ['C3', 1]]], ['normal control 1', [16, [['F6', 10, 18], ['B2', 1, 12], ['D4', 10, 3]], 'pro-rata'], [['B2', 1], ['D4', 8], ['F6', 7]]], ['normal control 2', [1, [['E5', 1, 17]], 'pro-rata'], [['E5', 1]]], ['normal control 3', [7, [['C3', 7, 13], ['B2', 3, 8]], 'pro-rata'], [['B2', 2], ['C3', 5]]]], [['regression fifo ordering 1', [9, [['D4', 1, 12], ['B2', 7, 9], ['F6', 7, 19], ['C3', 10, 18]], 'fifo'], [['B2', 7], ['C3', 1], ['D4', 1]]], ['regression fifo ordering 2', [12, [['E5', 1, 5], ['F6', 3, 1], ['B2', 10, 3], ['C3', 3, 8]], 'fifo'], [['B2', 9], ['F6', 3]]], ['partial repair probe 1', [8, [['F6', 1, 14], ['B2', 2, 2], ['C3', 1, 18], ['A1', 7, 15]], 'fifo'], [['A1', 5], ['B2', 2], ['F6', 1]]], ['partial repair probe 2', [3, [['F6', 2, 8], ['D4', 2, 17], ['E5', 10, 15]], 'fifo'], [['E5', 1], ['F6', 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', [17, [['A1', 10, 11], ['D4', 10, 16], ['F6', 1, 5]], 'pro-rata'], [['A1', 8], ['D4', 8], ['F6', 1]]], ['normal control 2', [4, [['A1', 2, 4], ['B2', 2, 2], ['E5', 2, 1], ['D4', 2, 10]], 'pro-rata'], [['A1', 1], ['B2', 1], ['D4', 1], ['E5', 1]]], ['normal control 3', [7, [['B2', 2, 11], ['F6', 2, 6], ['D4', 3, 14]], 'pro-rata'], [['B2', 2], ['D4', 3], ['F6', 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:
Recently opened shorts are assigned ahead of older ones.

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