{
 "approach": "The wave-1 base strategy with its 36 constants re-tuned by a plain-Python optimiser; the trading logic is unchanged. The strategy rests 0.01-share probe orders around its estimate of p (the arbitrageur removes every order on the wrong side of p, so surviving and eaten probes bound p to about a tick), narrows that with a sub-tick grid filter, quotes one tick inside the competitor, sizes each quote by the marginal rule (one more share while expected retail edge exceeds expected arbitrage loss), keeps resting orders for queue priority, and below 5 cents buys YES to cover low asks. What I changed: every constant in the P dict became a search dimension (31 tuned, 5 on/off flags held at the author's values), with log-normal mutations for positive constants, additive for dmin, rounding for rmin and bins, and box bounds. The optimiser is a racing (1+lambda) evolution strategy with successive halving: each generation samples 8 mutants of the incumbent (each parameter mutated with probability 0.35), scores all 8 on a random 80 of seeds 0-599, promotes the best 3 to 220 fresh seeds, promotes the best of those to the remaining 300, and replaces the incumbent only if the paired per-seed difference against it is positive on the 300 never-used-for-selection seeds and exceeds 0.5 standard errors on all 520 fresh seeds. Every comparison is paired on identical seeds, which cuts the standard error of a difference to about 0.4-0.9 against about 5 for an unpaired 600-seed mean. Step sizes shrink by 7% per failed generation and grow by 20% on the parameters of an accepted mutant. It ran 30 generations, 240 variants, about 67 minutes on 4 cores, 4 accepted improvements; no variant failed a simulation. Scores on seeds 0-599: base 87.4165, after 60 variants 88.137, after 120 variants 89.785, after 180 variants 89.785, after 240 variants 90.410. Largest constant changes: sig_j 0.35 to 0.289, lam_r 0.25 to 0.291, pL 0.05 to 0.070, kLf 0.08 to 0.038, keep_lo 0.7 to 0.859, min_ahead 2 to 2.83, bins 8 to 15, uni 0.01 to 0.0029, W 200 to 177, fy 0.6 to 0.694, dmin 0 to 0.016. Honest caveat: the 3.0-point gain on the tuning seeds did not transfer. On the holdout seeds 20000-20599 this file scores 85.537 against 85.468 for the unchanged base, a paired difference of 0.07 with standard error 0.95, so the base's constants were already at a plateau and the measured in-sample gain is mostly selection noise. The sandbox check passed 20/20 here (Python 3.14.4); the --workers flag was refused (multiprocessing needs a socket), so scoring ran as 4 serial processes on seed sub-ranges whose per-seed results are identical to a single run.",
 "blocked": null,
 "python_version": "3.14.4",
 "base_mean_edge": 78.85441957511699,
 "score": {
  "mean_edge": 90.41000104487082,
  "retail_edge": 122.53225390694934,
  "arb_edge": -32.12225286211683,
  "simulations": 600,
  "seed_start": 0,
  "failures": 0
 },
 "holdout": {
  "mean_edge": 85.53715620079267,
  "simulations": 600,
  "seed_start": 20000,
  "failures": 0
 },
 "code": "\"\"\"Stale-quote defence (constants re-tuned by a racing evolution strategy) 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.2907347136064522, m=5.0, sig_n=1.2, lam_j=0.0019, sig_j=0.2894046811636501, sig=0.02, qmax=3088.8931066347836, rmin=2, kA=0.7, kL=0.13725749526362813, pL=0.07047568489893936, ammo=1.0, ydem=0.4015922324333809, W=176.70764126759292, fy=0.6938507829010012, ammo_q=55.02599224600719, ammo_pmax=0.0508122005364876, ammo_maxpay=0.023321867541372613, fb=0.9, fu=0.5614576969198919, xu=0.10646581087615566, sticky=1.0, min_ahead=2.8296708868938696, keep_hi=1.5, keep_lo=0.8594237951635815, Hu=280.608511929507, bins=15.0, filt=1.0, uni=0.002918453085269526, jumpinfo=1.0, dmin=0.01618374265384913, kLb=0.08, kLf=0.03756506011679626, pinf=1.0, pre=1482.854614138653, H1=100.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            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 = 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                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": "401ad34f466c9e43e3591043b0306d565aa87e0c95ce981c39260dd02e4ed2c8",
 "tried": [
  "Reproduced the base on seeds 0-199: 78.85441957511699 (wave 1 reported the same figure), retail 105.18, arb -26.33, 0 failures",
  "Base on all tuning seeds 0-599: 87.41650726068066, retail 116.13, arb -28.71, 0 failures",
  "Base on holdout seeds 20000-20599: 85.4678, 0 failures, measured once for comparison only",
  "Optimiser design: racing (1+8)-ES with successive halving 80 -> 300 -> 600 seeds, paired per-seed comparison against the incumbent, acceptance only on seeds not used for selection; stage-A paired standard errors were 1-3, stage-B 0.4-2.4, stage-C about 0.5-0.9",
  "Variants 1-60 (generations 1-8): one acceptance at variant 24 (sig_j 0.245, pL 0.070, ydem, ammo_maxpay, keep_lo, bins, kLf): 88.137 on seeds 0-599",
  "Variants 61-120: acceptance at variant 72 (lam_r 0.291, kL, fy, ammo_q, ammo_pmax, xu, min_ahead, uni, kLf): 88.690; acceptance at variant 104 (sig_j 0.289, kL 0.137, W 177, fy 0.694, min_ahead 2.83, keep_lo 0.859, bins 15, uni): 89.785",
  "Variants 121-180: no acceptance; four finalists reached stage C with paired differences between -1.1 and +0.2 (within 1-2 standard errors), step scale shrank to about 0.4 of its start",
  "Variants 181-240: acceptance at variant 208 (qmax 3089, fu 0.561, keep_lo, Hu 281, uni 0.0029, dmin 0.016, kLf 0.038, pre 1483): 90.410 on seeds 0-599; two later finalists lost by -0.6 and -1.1",
  "Final frozen file re-scored with the CLI: seeds 0-599 mean 90.41000104487082 (retail 122.53, arb -32.12, 0 failures), settle-0 runs 167.2 and settle-1 runs 20.9; holdout seeds 20000-20599 mean 85.53715620079267 (retail 121.81, arb -36.27, 0 failures)",
  "Holdout paired against the base on the same 600 seeds: +0.069 with standard error 0.95, i.e. no measurable improvement out of sample; --sandbox passed 20/20 for this file and for examples/starter_strategy.py on Python 3.14.4"
 ],
 "next": "Constant tuning of the base is exhausted: 240 variants with paired racing moved the tuning-seed score by +3.0 and the holdout by +0.07 +/- 0.95, so stop searching these constants and change structure instead. Two concrete directions the numbers point at: (1) the arbitrage loss grew from -28.7 to -32.1 on the tuning seeds (base to final) while retail edge rose from 116.1 to 122.5, and the holdout shows the same pattern (retail 121.8, arb -36.3), so the marginal sizing rule's loss model is miscalibrated at low prices where most arb loss sits; fit the loss term per price band on logged fills rather than tuning kL/kLb/kLf. (2) Settle-1 runs earn only 21 against 167 in settle-0 runs; the YES-ammunition machinery has no mirror for p near 1 (buying NO / selling YES ahead of a competitor bid), which is the largest untouched symmetric opportunity. If a future seat does run an optimiser again, reuse this one (worker.py + opt.py pattern: persistent in-process workers, paired seeds, successive halving) but validate every acceptance on a disjoint seed block, because in-sample acceptance at 0.5 standard errors still accumulated about 3 points of selection bias here."
}