{
 "approach": "Same strategy as the base (0.01-share probes that the arbitrageur clears on the wrong side of p, a sub-tick grid filter, quotes one tick inside the competitor sized by the marginal retail-edge vs arbitrage-loss rule, resting orders kept for queue priority, YES ammunition below 5c), with its Gaussian score map replaced by the exact compound-Poisson mixture from the rules: p = sum_n Poi(n; lam*H) Phi((Z+n*mu)/sqrt(H*sigma^2+n*sj^2)). Each step the belief mean is inverted through the mixture (safeguarded Newton) to a latent score Z; the one-step p volatility used by both the filter's predict step and the local loss term is the mixture density times sigma, and the jump branch of the sizing rule evaluates the mixture at H-1 for Z shifted by quadrature jump nodes. Each run's jump rate and jump size are estimated online: whenever p is between 3c and 97c and the probe bracket is tight, the step's change in Z is scored against a two-component Gaussian likelihood (diffusion plus measurement noise, or that plus a jump) on a 5x5 grid of rates 0.0008-0.003 and sizes 0.2-0.6, and the posterior means feed the map. On test seeds 0-7 the estimates landed near the true values (e.g. 0.0025 vs 0.0027, 0.37 vs 0.39 for seed 0). Gain is small: +0.06 on seeds 0-199 and +0.82 on seeds 200-599 over the base, about +0.57 on 0-599, within noise; by price level on seeds 0-199 the mixture adds about +1.0 retail edge below 5c but costs about 0.6 more arbitrage there. Jump mean is not estimated (set to 0). Scores were run as 4 parallel chunks of the public simulator (--workers is refused here: socket creation is denied) and averaged over the per-simulation JSON.",
 "blocked": null,
 "python_version": "3.14.4",
 "base_mean_edge": 78.85441957511699,
 "score": {
  "mean_edge": 87.98508148206817,
  "retail_edge": 117.13053940397917,
  "arb_edge": -29.14545792188467,
  "simulations": 600,
  "seed_start": 0,
  "failures": 0
 },
 "holdout": {
  "mean_edge": 84.89089630473633,
  "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, mix=1.0, est=1.0, mu_j=0.0, zthr=0.0, lam0=0.0019, sj0=0.35)\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\n\ndef poiw(m):\n    if m <= 0:\n        return [1.0]\n    w = math.exp(-m); out = [w]; c = w; n = 0\n    while 1 - c > 1e-9 and n < 60:\n        n += 1; w *= m / n; out.append(w); c += w\n    return out\ndef mixF(Z, H, lam, sj, mu):\n    s2 = H * P['sig'] ** 2\n    F = 0.0; f = 0.0\n    for n, w in enumerate(poiw(lam * H)):\n        v = math.sqrt(s2 + n * sj * sj)\n        x = (Z + n * mu) / v\n        F += w * cdf(x); f += w * pdf(x) / v\n    return F, f\ndef mixinv(p, H, lam, sj, mu, z0):\n    lo, hi = -30.0, 30.0\n    Z = z0\n    for _ in range(60):\n        F, f = mixF(Z, H, lam, sj, mu)\n        if F > p:\n            hi = Z\n        else:\n            lo = Z\n        if abs(F - p) < 1e-10 * max(p, 1e-3) or hi - lo < 1e-9:\n            break\n        Zn = Z - (F - p) / f if f > 1e-14 else 0.5 * (lo + hi)\n        Z = Zn if lo < Zn < hi else 0.5 * (lo + hi)\n    return Z\nLG = [0.0008, 0.0012, 0.0017, 0.0023, 0.003]\nSG = [0.2, 0.3, 0.4, 0.5, 0.6]\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        self.zprev = None\n        self.ll = [[0.0] * len(SG) for _ in LG]\n        self.lamh, self.sjh = P['lam0'], P['sj0']\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        if P['mix'] > 0:\n            lj, sj, muj = self.lamh, self.sjh, P['mu_j']\n            sdg = math.sqrt(H * (P['sig'] ** 2 + lj * sj * sj))\n            Z = mixinv(phat, H, lj, sj, muj, inv(phat) * sdg)\n            _, fz = mixF(Z, H, lj, sj, muj)\n            sp = fz * P['sig']\n            self.st = sp * 100.0\n            s = math.sqrt(sp * sp + var_t / 1e4 + 1e-8)\n            H1_ = max(1.0, H - 1.0)\n            jp = [(mixF(Z + muj + n * sj, H1_, lj, sj, muj)[0], w) for n, w in NODES]\n            if P['est'] > 0:\n                ok = 0.03 < phat < 0.97 and var_t < 0.25\n                if ok and self.zprev is not None:\n                    d = Z - self.zprev\n                    e2 = 2.0 * var_t / 1e4 / max(fz, 1e-6) ** 2 + P['zthr']\n                    b = P['sig'] ** 2 + e2\n                    l0 = math.exp(-0.5 * d * d / b) / math.sqrt(b)\n                    for i, la in enumerate(LG):\n                        row = self.ll[i]\n                        for j, sg_ in enumerate(SG):\n                            b2 = b + sg_ * sg_\n                            l1 = math.exp(-0.5 * d * d / b2) / math.sqrt(b2)\n                            row[j] += math.log((1 - la) * l0 + la * l1 + 1e-300)\n                    mx = max(max(r) for r in self.ll)\n                    tw = tl = ts = 0.0\n                    for i, la in enumerate(LG):\n                        for j, sg_ in enumerate(SG):\n                            w = math.exp(self.ll[i][j] - mx)\n                            tw += w; tl += w * la; ts += w * sg_\n                    self.lamh, self.sjh = tl / tw, ts / tw\n                self.zprev = Z if ok else None\n        else:\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": "b580832594eb555ad53a525fd6370644c34ec0d1cadc598876993918e529c30d",
 "tried": [
  "Base reproduced on seeds 0-199: 78.85441957511699 (retail 105.185, arb -26.330), exactly wave 1's figure",
  "Base on seeds 200-599: 91.698 (retail 121.604, arb -29.907); base over 0-599 is about 87.42",
  "Edge by true-price level, base, seeds 0-199 (retail/arb): <5c 70.70/-17.17, 5-20c 11.74/-3.12, 20-80c 17.94/-5.30, 80-95c 2.37/-0.53, >95c 2.43/-0.20",
  "Edge by price level, mixture+estimation, seeds 0-199: <5c 71.68/-17.79, 5-20c 11.91/-3.63, 20-80c 17.85/-5.19, 80-95c 2.38/-0.56, >95c 2.50/-0.23: the gain is in retail edge below 5c, mostly given back to the arbitrageur",
  "Mixture with fixed jump prior (lam 0.0019, sj 0.35), no online estimation: 79.297 on 0-199",
  "Mixture, fixed prior lam 0.0019 sj 0.4: 79.011 on 0-199",
  "Mixture+estimation, kL 0.25: 78.257; kA 0.5: 78.407; kA 0.9: 78.606; kL 0.1 with pL 0.08: 77.950; ammo_pmax 0.08: 78.048; ammo_maxpay 0.03: 78.912 (unchanged) on 0-199. The sizing constants sit on a plateau with the mixture too",
  "Mixture+estimation, kL 0.1: 79.163 on 0-199",
  "Mixture with fixed prior and kL 0.1: 79.335 on 0-199, 92.176 on 200-599 (about 87.90 over 0-599)",
  "Sandbox: --sandbox on Python 3.14.4 ran 20/20 without failure (Python-level sandbox, nsjail absent); the starter also runs under --sandbox here",
  "Final: mixture map + online jump rate/size estimation, base constants: 78.912 on 0-199, 92.522 on 200-599, 87.985 on 0-599 (600 sims), holdout seeds 20000-20599 84.891"
 ],
 "next": "The exact map is not where the score is: it moved the mean by less than one standard error. The edge is below 5c (about 71 retail of 105 on seeds 0-199), and there the limit is how much the strategy quotes and how much ammunition it holds, not the precision of p. Next seats should estimate retail rate and size per run without bias to set ammunition demand, and estimate jump mean online (it shifts p near 0 by up to 0.24 in Z over a run). Compare variants on 600+ paired seeds: 200-seed differences under 1 are noise here. Keep the mixture map as the base's map, since it is exact and costs nothing."
}