{
  "approach": "Preserves the base's tick probes, sub-tick probability filter, marginal sizing and FIFO queue retention, while planning collateral through cheap YES inventory. Low-price main bids use stronger, inventory-dependent sizing and a 3000-share cap; asks may reach 6000 shares. The cover bank spans 300 remaining steps, dedicated cover purchases stop above 3.5 cents, and one-cent asks become eligible in the last 250 steps rather than the last 100. New uncovered asks must leave a $100 cash reserve, released linearly over the final 50 steps so remaining cash can serve terminal retail demand. A small scarcity charge on ask edge when YES inventory is low discourages tying up cash in uncovered asks. The frozen candidate was selected entirely on seeds 0-599.",
  "blocked": null,
  "python_version": "3.14.4",
  "base_mean_edge": 78.85441957511699,
  "score": {
    "mean_edge": 90.936731974051,
    "retail_edge": 119.34506311800217,
    "arb_edge": -28.40833114395033,
    "simulations": 600,
    "seed_start": 0,
    "failures": 0
  },
  "holdout": {
    "mean_edge": 87.87707760418967,
    "simulations": 600,
    "seed_start": 20000,
    "failures": 0
  },
  "code": "\"\"\"Stale-quote defence with tick probes, a sub-tick belief and YES ammunition.\n\nEvery step the arbitrageur removes any order on the wrong side of p, so tiny\ntwo-sided probes around the estimate locate p to a tick; a grid filter narrows\nthat further.  Quotes sit one tick inside the competitor and are sized by the\nmarginal rule: one more share is worth quoting while the chance a retail order\nreaches it, times its edge, exceeds the expected arbitrage loss.  That rule pulls\nquotes by itself when a move would hurt most.  Near p=0 a retail buy pays almost\nits whole notional as edge, so YES is held to cover low asks.\n\"\"\"\nimport math\nfrom orderbook_pm_challenge.strategy import BaseStrategy\nfrom orderbook_pm_challenge.types import CancelOrder, PlaceOrder, Side\n\nP = dict(lam_r=0.25, m=5.0, sig_n=1.2, lam_j=0.0019, sig_j=0.35, sig=0.02,\n         qmax=3000.0, rmin=2, kA=0.7, kL=0.15, pL=0.05,\n         ammo=1.0, ydem=0.4, W=200.0, fy=0.6, ammo_q=60.0, ammo_pmax=0.05, ammo_maxpay=0.02,\n         fb=0.9, fu=0.5, xu=0.1, sticky=1.0, min_ahead=2.0, keep_hi=1.5, keep_lo=0.7, Hu=300.0, bins=8.0, filt=1.0, uni=0.01, jumpinfo=1.0, dmin=0.0, kLb=0.08, kLf=0.08, pinf=1.0, pre=1500.0, H1=100.0)\nP.update({'ammo_q': 60.0, 'ydem': 0.4, 'W': 300.0, 'ammo_pmax': 0.035, 'fy': 0.7, 'pre': 1500.0, 'H1': 250.0, 'kLb': 0.005, 'kLf': 0.02, 'fb': 0.9, 'fu': 0.25, 'xu': 0.1, 'Hu': 500.0, 'qmax': 6000.0})\nSQ2 = math.sqrt(2.0)\nSQ2PI = math.sqrt(2.0 * math.pi)\ndef cdf(x): return 0.5 * (1.0 + math.erf(x / SQ2))\ndef pdf(x): return math.exp(-0.5 * x * x) / SQ2PI\ndef inv(p):\n    p = min(max(p, 1e-9), 1 - 1e-9)\n    t = math.sqrt(-2.0 * math.log(min(p, 1 - p)))\n    x = t - (2.515517 + 0.802853 * t + 0.010328 * t * t) / (1 + 1.432788 * t + 0.189269 * t * t + 0.001308 * t ** 3)\n    x = -x if p < 0.5 else x\n    for _ in range(2):\n        d = pdf(x)\n        if d < 1e-12:\n            break\n        x -= (cdf(x) - p) / d\n    return x\ndef lpm(k):\n    return pdf(k) + k * cdf(k)\ndef fl(q):\n    return math.floor(q * 100 + 1e-9) / 100\n\nNODES = [(-2.2, .06), (-1.3, .17), (-0.6, .27), (0.6, .27), (1.3, .17), (2.2, .06)]\nPROBE = 0.01\n\n\nclass Strategy(BaseStrategy):\n    def __init__(self):\n        self.n = 0\n        self.ahead = set()     # main orders placed strictly ahead of any competitor order at their tick\n        self.res = {}          # order id -> uncovered quantity at placement\n        self.bc = None         # belief: sub-tick grid centres (ticks)\n        self.bw = None         # belief: weights\n        self.st = 0.5          # last one-step sd in ticks\n        self.pcb = self.pca = None\n        self.pb = set()\n        self.pa = set()\n\n    def _oid(self, tag):\n        self.n += 1\n        return tag + str(self.n)\n\n    def on_step(self, state):\n        H = max(1, state.steps_remaining)\n        cb = state.competitor_best_bid_ticks or 0\n        ca = state.competitor_best_ask_ticks or 100\n        lo, hi = cb, ca\n        for o in state.own_orders:\n            if o.side is Side.BUY:\n                lo = max(lo, o.price_ticks)\n            else:\n                hi = min(hi, o.price_ticks)\n        if P['pinf'] > 0:\n            sb = {o.price_ticks for o in state.own_orders if o.side is Side.BUY and o.remaining_quantity <= PROBE + 1e-9}\n            sa = {o.price_ticks for o in state.own_orders if o.side is Side.SELL and o.remaining_quantity <= PROBE + 1e-9}\n            ea = self.pa - sa\n            eb = self.pb - sb\n            if sa and ea:\n                lo = max(lo, min(max(ea), hi))\n            if sb and eb:\n                hi = min(hi, max(min(eb), lo))\n        if P['jumpinfo'] > 0 and self.pcb is not None:\n            if ca > self.pca + 1:\n                lo = max(lo, ca - 1)\n            if cb < self.pcb - 1:\n                hi = min(hi, cb + 1)\n        self.pcb, self.pca = cb, ca\n        if lo > hi:\n            lo, hi = hi, lo\n        # sub-tick belief over p_(t-1): predict with one-step noise, truncate to [lo, hi]\n        wid = max(hi - lo, 1e-6)\n        nb = max(2, min(48, int(round(wid * P['bins']))))\n        cs = [lo + (i + 0.5) * wid / nb for i in range(nb)]\n        if self.bc is None or P['filt'] <= 0:\n            ws = [1.0 / nb] * nb\n        else:\n            sg = max(self.st, 0.6 * wid / nb)\n            k = -0.5 / (sg * sg)\n            ws = []\n            uni = P['uni'] * sg\n            for c in cs:\n                t = uni\n                for ci, wi in zip(self.bc, self.bw):\n                    d = c - ci\n                    d2 = d * d * k\n                    if d2 > -12.5:\n                        t += wi * math.exp(d2)\n                ws.append(t)\n            tot = sum(ws)\n            ws = [w / tot for w in ws]\n        self.bc, self.bw = cs, ws\n        mean_t = sum(c * w for c, w in zip(cs, ws))\n        var_t = max(sum(c * c * w for c, w in zip(cs, ws)) - mean_t * mean_t, 0.0)\n        phat = min(max(mean_t / 100.0, 0.002), 0.998)\n        var = P['sig'] ** 2 + P['lam_j'] * P['sig_j'] ** 2\n        sd = math.sqrt(H * var)\n        z = inv(phat)\n        Z = z * sd\n        sp = pdf(z) / sd * P['sig']\n        self.st = sp * 100.0\n        s = math.sqrt(sp * sp + var_t / 1e4 + 1e-8)\n        sd1 = math.sqrt(max(1.0, H - 1.0) * var)\n        jp = [(cdf((Z + n * P['sig_j']) / sd1), w) for n, w in NODES]\n        lj = P['lam_j']\n\n        def AB(x):\n            k = (x - phat) / s\n            a = s * lpm(k)\n            b = a - (x - phat)\n            ja = sum(w * max(0.0, x - p) for p, w in jp)\n            jb = sum(w * max(0.0, p - x) for p, w in jp)\n            return (1 - lj) * a + lj * ja, (1 - lj) * b + lj * jb\n\n        if H == 1:\n            def AB(x):\n                return (1 - phat) * x, phat * (1 - x)\n        rho = P['lam_r'] * 0.5\n        mu = math.log(P['m']) - 0.5 * P['sig_n'] ** 2\n        kA = P['kL'] if phat < P['pL'] else P['kA']\n\n        def qsize(loss, gain, px):\n            loss *= kA\n            if gain <= 0:\n                return 0.0\n            tail = loss / (rho * gain)\n            if tail >= 1.0:\n                return 0.0\n            return min(P['qmax'], math.exp(mu + P['sig_n'] * inv(1 - max(tail, 1e-6))) / px)\n\n        ptk = phat * 100\n        def qbid(t):\n            if not 1 <= t <= 99:\n                return 0.0\n            a, b = AB(t / 100.0)\n            if phat * 100 - t < P['dmin']:\n                return 0.0\n            if phat < P['pL']:\n                ytg = P['ydem'] * min(H, P['W']) / max(ca - 1, ptk + 1) * 100.0\n                a *= (P['kLb'] if state.yes_inventory < ytg else P['kLf']) / P['kL']\n            return qsize(a, b, max(phat, 0.05))\n\n        def qask(t):\n            if not 1 <= t <= 99:\n                return 0.0\n            a, b = AB(t / 100.0)\n            if t - phat * 100 < P['dmin']:\n                return 0.0\n            if phat < .1:\n                a = max(0.0,a - 0.0025 * (1 - min(1.0, state.yes_inventory / 3000.0)))\n            return qsize(b, a, t / 100.0)\n\n        bids = [o for o in state.own_orders if o.side is Side.BUY and o.remaining_quantity > PROBE + 1e-9]\n        asks = [o for o in state.own_orders if o.side is Side.SELL and o.remaining_quantity > PROBE + 1e-9]\n        sticky = P['sticky'] > 0\n        def top(orders, comp, step):\n            if sticky and sum(o.remaining_quantity for o in orders if o.price_ticks == comp and o.order_id in self.ahead) >= P['min_ahead']:\n                return comp\n            return comp + step\n        bid_t = top(bids, cb, 1)\n        ask_t = top(asks, ca, -1)\n        qb = min(3000.0,qbid(bid_t))\n        qa = qask(ask_t)\n\n        Y = state.yes_inventory\n        if ask_t == 1 and H > P['H1'] and P['pre'] > 0:\n            qa = 0.0          # let the competitor's 2-tick ask erode instead of fronting it for nothing\n        # ammunition: hold YES so that low asks are covered\n        ptick = phat * 100\n        amt = 0\n        qam = 0.0\n        if P['ammo'] > 0 and ask_t >= 2 and phat < P['ammo_pmax']:\n            wealth = state.cash + Y * phat\n            x = max(ask_t, ptick + 1) / 100.0\n            target = min(P['ydem'] * min(H, P['W']) / x, P['fy'] * wealth / max(phat, 0.005))\n            if Y < target:\n                t = max(1, min(99, int(math.ceil(ptick + 1e-9))))\n                if bid_t <= t < ask_t and t / 100.0 - phat < P['ammo_maxpay']:\n                    amt = t\n                    qam = min(P['ammo_q'], target - Y)\n\n        if P['pre'] > 0 and ca == 2 and phat < 0.01 and H > P['H1'] and Y < P['pre'] and not qam:\n            amt, qam = 1, min(P['ammo_q'], P['pre'] - Y)\n        # order management\n        actions = []\n        free = state.free_cash - 2.0\n        keep_ask = 0.0\n        new_b = []\n        new_a = []\n        def cancel(o):\n            nonlocal free\n            actions.append(CancelOrder(o.order_id))\n            x = o.price_ticks / 100.0\n            if o.side is Side.BUY:\n                free += x * o.remaining_quantity\n            else:\n                free += (1 - x) * min(self.res.get(o.order_id, 0.0), o.remaining_quantity)\n            self.ahead.discard(o.order_id)\n            self.res.pop(o.order_id, None)\n        for o in state.own_orders:\n            if o.remaining_quantity <= PROBE + 1e-9:\n                cancel(o)\n        kept_ids = set()\n        def manage(orders, t, q, comp):\n            kept = 0.0\n            for o in orders:\n                if o.price_ticks == t and q > 0 and kept + o.remaining_quantity <= max(q * P['keep_hi'], 1.0):\n                    kept += o.remaining_quantity\n                    kept_ids.add(o.order_id)\n                else:\n                    cancel(o)\n            return kept\n        kb = manage(bids, bid_t, qb, cb)\n        ka = manage(asks, ask_t, qa, ca)\n        add_b = (qb - kb) if (kb < qb * P['keep_lo'] and bid_t != cb) else 0.0\n        add_a = (qa - ka) if (ka < qa * P['keep_lo'] and ask_t != ca) else 0.0\n\n        budget = P['fb'] * max(free, 0.0)\n        cost = add_b * bid_t / 100.0 + qam * amt / 100.0\n        if cost > budget:\n            f = budget / cost\n            add_b *= f\n            qam *= f\n            cost = budget\n        out = []\n        if amt and qam >= 0.01:\n            q = fl(qam)\n            out.append(PlaceOrder(side=Side.BUY, price_ticks=amt, quantity=q))\n            free -= q * amt / 100.0 + 1e-6\n        if bid_t >= 1 and add_b >= 0.01:\n            q = fl(add_b)\n            oid = self._oid('b')\n            out.append(PlaceOrder(side=Side.BUY, price_ticks=bid_t, quantity=q, client_order_id=oid))\n            free -= q * bid_t / 100.0 + 1e-6\n            if bid_t > cb:\n                self.ahead.add(oid)\n        if ask_t <= 99 and add_a >= 0.01:\n            x = ask_t / 100.0\n            covk = sum(o.remaining_quantity - min(self.res.get(o.order_id, 0.0), o.remaining_quantity)\n                       for o in asks if o.order_id in kept_ids)\n            cov = max(0.0, Y - covk - 0.1)\n            unc = max(0.0, add_a - cov)\n            if unc > 0:\n                ub = max(0.0, free - (1 - P['fu']) * max(state.cash, 0.0)) if x >= P['xu'] else 0.0\n                if H < P['Hu'] and phat < 0.05:\n                    ub = max(0.0, free * (1 - H / P['Hu']))\n                ub = min(ub, max(0.0, free - 100.0 * min(1.0,H/50.0)))\n                unc = min(unc, ub / (1 - x))\n            q = fl(min(add_a, cov + unc))\n            if q >= 0.01:\n                oid = self._oid('a')\n                out.append(PlaceOrder(side=Side.SELL, price_ticks=ask_t, quantity=q, client_order_id=oid))\n                r = max(0.0, q - cov)\n                self.res[oid] = r\n                free -= r * (1 - x) + 1e-6\n                if ask_t < ca:\n                    self.ahead.add(oid)\n\n        # probes: tiny orders that the arbitrageur removes when p crosses them\n        f = int(math.floor(ptick + 1e-9))\n        r = max(int(P['rmin']), int(math.ceil(2.0 * s * 100)))\n        self.pb = set()\n        self.pa = set()\n        if free > 1.0:\n            for t in range(f, f + r + 1):\n                if cb < t < ca and 1 <= t <= 99:\n                    out.append(PlaceOrder(side=Side.BUY, price_ticks=t, quantity=PROBE))\n                    self.pb.add(t)\n            for t in range(f + 1 - r, f + 2):\n                if cb < t < ca and 1 <= t <= 99:\n                    out.append(PlaceOrder(side=Side.SELL, price_ticks=t, quantity=PROBE))\n                    self.pa.add(t)\n        return actions + out\n",
  "code_sha256": "b237f1c9190f3196224e3b2a910ff9c57a20cebcb4abd11899296df6dd4ea0a4",
  "tried": [
    "Reproduced base with the unmodified public simulator at commit b244530ee2a6247b5f930830eeca9dd950da0e7e: seeds 0-199 mean 78.85441957511699, retail 105.184836572219, arb -26.330416997007, zero failures; base seeds 0-599 mean 87.41650726068066.",
    "Base seeds 0-199 were logged on every callback. Clipping means desired new quantity exceeded actual new quantity by >0.02 shares, after queue management; aggregate unquoted shares are NOT missed fills. Rows [steps, side, ticks, clipped callbacks/run, aggregate unquoted shares/run (approx), cash at clipping (approx)]: [[\"0-499\", \"ask\", \"2-5\", 0.035, 14.35, 952.711], [\"0-499\", \"ask\", \"6-10\", 0.165, 42.788, 673.559], [\"500-999\", \"ask\", \"11-50\", 0.21, 23.591, 240.213], [\"500-999\", \"ask\", \"2-5\", 1.185, 674.926, 929.51], [\"500-999\", \"ask\", \"6-10\", 2.485, 474.375, 791.411], [\"500-999\", \"bid\", \"2-5\", 0.07, 24.002, 30.645], [\"500-999\", \"cover_bid\", \"2-5\", 0.005, 0.131, 57.92], [\"1000-1499\", \"ask\", \"11-50\", 0.04, 2.838, 190.493], [\"1000-1499\", \"ask\", \"2-5\", 6.615, 6597.514, 707.567], [\"1000-1499\", \"ask\", \"6-10\", 3.955, 829.67, 775.199], [\"1000-1499\", \"bid\", \"2-5\", 0.005, 0.237, 46.538], [\"1500-1999\", \"ask\", \"1\", 1.975, 1273.703, 286.367], [\"1500-1999\", \"ask\", \"2-5\", 5.495, 5665.123, 572.038], [\"1500-1999\", \"ask\", \"6-10\", 0.98, 138.06, 797.57], [\"1500-1999\", \"bid\", \"1\", 1.85, 188.696, 71.276], [\"1500-1999\", \"bid\", \"2-5\", 0.005, 0.065, 4.415], [\"1500-1999\", \"bid\", \"51-99\", 1.605, 18.363, 5.303], [\"1500-1999\", \"cover_bid\", \"1\", 0.765, 40.294, 60.592], [\"1500-1999\", \"cover_bid\", \"2-5\", 0.165, 7.67, 225.639]]",
    "The public Action union exposes PlaceOrder, CancelOrder and CancelAll only. No explicit mint/redeem action is available; an uncovered ask fill debits (1-price)*quantity cash and adds NO. The candidate therefore uses YES acquisition, coverage, quote sizing and cash budgets rather than an unsupported mint action.",
    "Baseline fill instrumentation reproduced the same 78.85441957511699 score: dedicated one-cent ammunition buys lost about 8.858 edge/run to arbitrage; this motivated acquiring cover closer to fair value before later low-price demand.",
    "--workers 4 failed with PermissionError: [Errno 1] Operation not permitted in multiprocessing forkserver socket creation. All actual measurements used serial simulator batches, with separate Python commands for independent candidates/ranges.",
    "Searched 752 successfully scored strategy files, including the base and equivalent controls. All tuning used only seeds 0-599; lower-count screens were followed by 600-seed evaluation for finalists. Holdout seeds 20000-20599 were not evaluated before freezing one file.",
    "Marginal cash charge on bid/ask fills: best evaluated capital_shadow0.001_reserve600.0_time1.0, seeds 0-199, mean 78.9965328000085, zero failures/200.",
    "Amortize forced-cover premium against expected ask margin: best evaluated amortize_power2.0_scale1.5_kl0.04, seeds 0-199, mean 79.693028811018, zero failures/200.",
    "Release old uncovered reservations after YES arrives: best evaluated recover1.0, seeds 0-119, mean 94.08729438165666, zero failures/120.",
    "Liquidate surplus YES only when cash is low: best evaluated liquidate100.0, seeds 0-119, mean 94.10535668979084, zero failures/120.",
    "Delayed terminal cash spending on uncovered asks: best evaluated late_H150.0_aq1000.0, seeds 0-119, mean 94.21385572409167, zero failures/120.",
    "Demand tied to intended ask size: best evaluated target_q1.0_pm0.05, seeds 0-119, mean 94.24043402206166, zero failures/120.",
    "Faster dedicated YES cover replenishment: best evaluated ammo300, seeds 0-599, mean 87.56629634039267, zero failures/600.",
    "Cash floors for naked asks: best evaluated naked_floor30.0_decay0.5, seeds 0-599, mean 87.68122529944117, zero failures/600.",
    "Inventory-dependent main-bid aggression: best evaluated stock_low0.01_full0.16, seeds 0-599, mean 87.7226281509285, zero failures/600.",
    "Cover inventory demand/horizon sweeps: best evaluated cover_y0.2_w400.0, seeds 0-599, mean 87.94510962118433, zero failures/600.",
    "Earlier forced cover purchases: best evaluated early_pm0.03_y0.4, seeds 0-599, mean 87.97449816832383, zero failures/600.",
    "Forced-cover target that tapers ahead of the final step: best evaluated horizon_lag10.0_d0.2_cap100.0, seeds 0-599, mean 88.0185813369955, zero failures/600.",
    "Cheaper passive cover bids, including behind the main bid: best evaluated passive_offset1_p0.1_y0.4, seeds 0-599, mean 88.53641004270767, zero failures/600.",
    "Larger inventory when acquisition premium is low: best evaluated cheap_stock1500.0_premium0.001_pm0.05, seeds 0-599, mean 88.77285144447617, zero failures/600.",
    "Marginal opportunity cost of uncovered ask collateral: best evaluated marginal_cash0.001_p0.05_off1, seeds 0-599, mean 89.0716742394815, zero failures/600.",
    "Focused main-bid and ask-cap grid: best evaluated refine_bid3000.0_ask9000.0_pm0.025, seeds 0-599, mean 90.09081120279266, zero failures/600.",
    "Ablations of the conservative bid-cap candidate: best evaluated ablate013_passive, seeds 0-599, mean 90.40577303977183, zero failures/600.",
    "Focused low-price bid/inventory/cash refinements: best evaluated refine062_pm035, seeds 0-599, mean 90.8528817699045, zero failures/600.",
    "Joint collateral/cover/cash parameter search: best evaluated random_132, seeds 0-599, mean 90.87900597019849, zero failures/600.",
    "Cash-reserve and cover-purchase ablations of the cash-floor candidate: best evaluated refine132_taper50.0, seeds 0-599, mean 90.93576945877484, zero failures/600.",
    "Final coarse single-feature ablations of the leading cash plan: best evaluated last_ablate_pre, seeds 0-599, mean 90.936731974051, zero failures/600.",
    "Frozen candidate training robustness (not independent validation): [competitor spread ticks, simulations, candidate-minus-base mean edge] [[1, 141, 7.324199512716313], [2, 166, 6.361053889257829], [3, 158, 0.4118591890424057], [4, 135, -0.3080444500466657]]; deleting its single most favorable paired run still leaves mean improvement 3.2812930820654422.",
    "After the strategy was frozen, a base control scored 85.46780344973116 on seeds 20000-20599; candidate-minus-base holdout mean 2.4092741544584997, paired standard error 0.8379147187815611. Neither holdout result was used to change or select code.",
    "Final unmodified-simulator --sandbox check: 20 simulations on seeds 0-19, zero failures. Starter sandbox also passed 20/20 on this Python runtime.",
    "Frozen final candidate last_ablate_pre: training seeds 0-599 mean 90.936731974051, retail 119.34506311800217, arb -28.40833114395033, failures 0/600; untouched holdout seeds 20000-20599 mean 87.87707760418967, failures 0/600. Code was frozen before any holdout evaluation, and not changed afterward."
  ],
  "next": "Estimate the future retail value of one more covered YES share by price, horizon and competitor queue position, then use that value to set passive cover-bid size and terminal cash spending. Compare changes against the base on paired runs and reserve a new untouched holdout; do not tune further on seeds 20000-20599."
}