{"approach": "Retains the base tick probes, sub-tick probability filter, FIFO order preservation and low-price YES cover stock. A per-run retail posterior uses zero and partial fills of surviving front-of-queue orders with a right-truncated approximate compound-Poisson likelihood, correcting the selection bias from simply averaging surviving fills. Estimated arrival rate and mean size drive marginal quote sizing, with size calibrated relative to the base prior; inferred retail demand scales the inventory target and acquisition cap. A shrunk process posterior learns jump intensity and variance from nonoverlapping eight-step belief increments using the compound-Poisson probability model. Its run-specific parameters drive a model-based probability gradient and jump-loss mixture; a bracketed inverse handles late horizons. The initial competitor spread is decoded exactly to narrow the initial probability bound.", "blocked": null, "python_version": "3.12.3", "base_mean_edge": 78.85441957511699, "score": {"mean_edge": 89.50960810972317, "retail_edge": 119.02587107676601, "arb_edge": -29.516262967079832, "simulations": 600, "seed_start": 0, "failures": 0}, "holdout": {"mean_edge": 85.86390504412384, "simulations": 600, "seed_start": 20000, "failures": 0}, "code": "# Run-specific retail and jump inference layered onto the probe strategy.\n# Retail uses survival conditioning; process inference uses eight-step increments.\n\"\"\"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)\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\n        self.params = dict(P)\n        self.retail = RetailEstimator()\n        self.process = ExactProcessEstimator()\n        self.exposure=[]\n        self.spread=None\n\n    def _oid(self, tag):\n        self.n += 1\n        return tag + str(self.n)\n\n    def on_step(self, state):\n        P = self.params\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        if state.step==0 and cb>0 and ca<100:\n            self.competitor_spread=(ca-cb+1)//2\n            lo=cb+self.competitor_spread-1\n            hi=ca-self.competitor_spread+1\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\n        # Only resting survivors are used. Full fills could be arbitrage, so\n        # selection is explicitly conditioned on volume being below capacity.\n        if R_ENABLE and state.step % R_STRIDE == 0:\n            current={o.order_id:o.remaining_quantity for o in state.own_orders}\n            for side,t,cap,orders in self.exposure:\n                remain=sum(current.get(oid,0.) for oid,q in orders)\n                if remain > .000001:\n                    filled=cap-remain\n                    scale=t/100 if side is Side.SELL else max(phat,.05)\n                    if side is Side.SELL or R_BIDS:\n                        self.retail.observe(cap*scale,filled*scale,R_POWER)\n        if R_ENABLE:\n            P['lam_r']=(1-R_BLEND)*.25+R_BLEND*self.retail.lam\n            r=self.retail\n            rate=sum(w*r.rates[i//7] for i,w in enumerate(r.w))\n            lm=sum(w*r.rates[i//7]*math.log(r.means[i%7]) for i,w in enumerate(r.w))/rate\n            vl=sum(w*r.rates[i//7]*(math.log(r.means[i%7])-lm)**2 for i,w in enumerate(r.w))/rate\n            av=sum(w*r.rates[i//7]*r.means[i%7] for i,w in enumerate(r.w))/rate\n            P['m']=av*R_SCALE\n            P['sig_n']=math.sqrt(1.44+vl)\n        flow=self.retail.lam*self.retail.mean/(.253*4.488)\n        P['ydem']=.4*(1+1.0*(flow-1))\n        P['ammo_q']=60.*(1+1.0*(flow-1))\n        if J_ENABLE:\n            self.process.observe(state.step,H,phat,var_t,J_POWER)\n            P['lam_j']=(1-J_BLEND)*.0019+J_BLEND*self.process.lam\n            P['sig_j']=(1-J_BLEND)*.35+J_BLEND*self.process.sigma\n\n        var = P['sig'] ** 2 + P['lam_j'] * P['sig_j'] ** 2\n        sd = math.sqrt(H * var)\n        z = inv(phat)\n        Z,g = exact_inverse(phat,H,P['lam_j'],P['sig_j'])\n        sp = g * 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 = [(exact_probability(Z+n*P['sig_j'], max(1,H-1), P['lam_j'],P['sig_j']),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\n        # Reconstruct only our submitted book, using public actions and state.\n        book={o.order_id:(o.side,o.price_ticks,o.remaining_quantity) for o in state.own_orders}\n        result=[]\n        for action in actions+out:\n            if isinstance(action,CancelOrder):\n                book.pop(action.order_id,None)\n            else:\n                if action.client_order_id is None:\n                    action=PlaceOrder(side=action.side,price_ticks=action.price_ticks,quantity=action.quantity,client_order_id=self._oid('r'))\n                book[action.client_order_id]=(action.side,action.price_ticks,action.quantity)\n            result.append(action)\n        self.exposure=[]\n        for side,comp in ((Side.BUY,cb),(Side.SELL,ca)):\n            levels=[t for s,t,q in book.values() if s is side and q>PROBE+1e-9]\n            if not levels: continue\n            t=max(levels) if side is Side.BUY else min(levels)\n            front=t>comp if side is Side.BUY else t<comp\n            if not front and not (R_QUEUE and t==comp): continue\n            orders=[(oid,q) for oid,(s,px,q) in book.items() if s is side and px==t and (front or oid in self.ahead)]\n            if not orders:continue\n            cap=sum(q for oid,q in orders)\n            self.exposure.append((side,t,cap,orders))\n        return result\n\n\nR_ENABLE = True\nR_BIDS = True\nR_POWER = 1.0\nR_BLEND = 1.0\nR_STRIDE = 1\nJ_ENABLE = True\nJ_POWER = 0.3\nJ_BLEND = 1.0\nR_SCALE = 1.1140819964349375\nR_QUEUE = False\n\nclass RetailEstimator:\n    \"\"\"Posterior from surviving, front-of-queue quotes.\n\n    Survival conditions away arbitrage and right-truncates retail volume.\n    Zero fills are observations too. Compound-Poisson sums use a three-term\n    lognormal moment approximation (the single-arrival term is exact).\n    \"\"\"\n    def __init__(self):\n        self.rates = [.154 + (.352-.154)*(i+.5)/5 for i in range(5)]\n        self.means = [2.64 + (6.336-2.64)*(i+.5)/7 for i in range(7)]\n        self.w = [1.0/35]*35\n        self.kn = []\n        for k in (1,2,3):\n            v=math.log(1+(math.exp(1.44)-1)/k)\n            self.kn.append((k, math.sqrt(v), .5*v))\n        self.lam = .253\n        self.mean = 4.488\n        self.samples=0\n    def observe(self, cap, amount, power):\n        if cap < .2 or amount >= cap-1e-7 or amount < -1e-7:\n            return\n        lc=math.log(cap)\n        lx=math.log(max(amount,1e-12))\n        fs=[]; ds=[]\n        for m in self.means:\n            f=[]; d=[]\n            for k,sg,v2 in self.kn:\n                mu=math.log(k*m)-v2\n                f.append(cdf((lc-mu)/sg))\n                d.append(pdf((lx-mu)/sg)/max(amount*sg,1e-12))\n            fs.append(f); ds.append(d)\n        nw=[]\n        for i,r in enumerate(self.rates):\n            rho=r/2\n            co=(rho,rho*rho/2,rho**3/6)\n            for j,m in enumerate(self.means):\n                den=1+sum(a*b for a,b in zip(co,fs[j]))\n                num=1.0 if amount < .00001 else sum(a*b for a,b in zip(co,ds[j]))\n                nw.append(self.w[i*7+j]*max(num/den,1e-30)**power)\n        norm=sum(nw)\n        self.w=[w/norm for w in nw]\n        self.lam=sum(w*self.rates[i//7] for i,w in enumerate(self.w))\n        self.mean=sum(w*self.means[i%7] for i,w in enumerate(self.w))\n        self.samples+=1\n\nclass ProcessEstimator:\n    \"\"\"Shrunk jump/diffusion likelihood from nonoverlapping belief increments.\"\"\"\n    def __init__(self):\n        self.grid=[(.0008+(.003-.0008)*(i+.5)/5, .2+.4*(j+.5)/7) for i in range(5) for j in range(7)]\n        self.w=[1.0/35]*35\n        self.last=None\n        self.lam=.0019; self.sigma=.4\n    def observe(self, step,H,p,v,power):\n        if H < 400 or not .07 < p < .93:\n            self.last=None\n            return\n        if self.last is None:\n            self.last=(step,H,p,v)\n            return\n        t0,h0,p0,v0=self.last\n        dt=step-t0\n        if dt < 8: return\n        self.last=(step,H,p,v)\n        if dt>12: return\n        pm=(p+p0)/2\n        z=inv(pm)\n        d=p-p0\n        nw=[]\n        for (lam,sig),w in zip(self.grid,self.w):\n            var=.0004+lam*sig*sig\n            slope=pdf(z)/math.sqrt((H+dt/2)*var)\n            dv=slope*slope*.0004*dt+(v+v0)/1e4+1e-7\n            jv=dv+slope*slope*sig*sig\n            lj=lam*dt\n            likelihood=(1-lj)*math.exp(-.5*d*d/dv)/math.sqrt(dv)+lj*math.exp(-.5*d*d/jv)/math.sqrt(jv)\n            nw.append(w*max(likelihood,1e-30)**power)\n        norm=sum(nw)\n        self.w=[w/norm for w in nw]\n        self.lam=sum(w*g[0] for w,g in zip(self.w,self.grid))\n        self.sigma=math.sqrt(sum(w*g[0]*g[1]**2 for w,g in zip(self.w,self.grid))/self.lam)\n\nclass ExactProcessEstimator(ProcessEstimator):\n    def __init__(self):\n        super().__init__()\n        self.grid=[(.0008+(.003-.0008)*(i+.5)/3,.2+.4*(j+.5)/5) for i in range(3) for j in range(5)]\n        self.w=[1./len(self.grid)]*len(self.grid)\n    def invert(self,p,H,lam,sig):\n        rate=lam*H\n        weights=[];w=math.exp(-rate)\n        for n in range(24):\n            if n: w*=rate/n\n            weights.append((w,math.sqrt(H*.0004+n*sig*sig)))\n            if n>rate+5 and w<1e-9: break\n        z=inv(p)*math.sqrt(H*(.0004+lam*sig*sig))\n        for _ in range(4):\n            value=sum(w*cdf(z/sd) for w,sd in weights)\n            slope=sum(w*pdf(z/sd)/sd for w,sd in weights)\n            z-=max(-1.,min(1.,(value-p)/max(slope,1e-10)))\n        slope=sum(w*pdf(z/sd)/sd for w,sd in weights)\n        return z,slope\n    def observe(self,step,H,p,v,power):\n        if H<400 or not .07<p<.93:\n            self.last=None\n            return\n        if self.last is None:\n            self.last=(step,H,p,v)\n            return\n        t0,h0,p0,v0=self.last\n        dt=step-t0\n        if dt<8:return\n        self.last=(step,H,p,v)\n        if dt>12:return\n        nw=[]\n        for (lam,sig),w in zip(self.grid,self.w):\n            z0,g0=self.invert(p0,h0,lam,sig)\n            z,g=self.invert(p,H,lam,sig)\n            d=z-z0\n            dv=.0004*dt+v/1e4/g**2+v0/1e4/g0**2+1e-7\n            jv=dv+sig*sig\n            lj=lam*dt\n            likelihood=((1-lj)*math.exp(-.5*d*d/dv)/math.sqrt(dv)+lj*math.exp(-.5*d*d/jv)/math.sqrt(jv))/g\n            nw.append(w*max(likelihood,1e-30)**power)\n        norm=sum(nw)\n        self.w=[w/norm for w in nw]\n        self.lam=sum(w*g[0] for w,g in zip(self.w,self.grid))\n        self.sigma=math.sqrt(sum(w*g[0]*g[1]**2 for w,g in zip(self.w,self.grid))/self.lam)\n\ndef exact_probability(Z,H,lam,sig):\n    rate=lam*H\n    w=math.exp(-rate)\n    result=0.\n    for n in range(25):\n        if n:w*=rate/n\n        result+=w*cdf(Z/math.sqrt(H*.0004+n*sig*sig))\n        if n>rate+5 and w<1e-9: break\n    return result\ndef exact_inverse(p,H,lam,sig):\n    rate=lam*H\n    terms=[];w=math.exp(-rate)\n    for n in range(28):\n        if n:w*=rate/n\n        terms.append((w,math.sqrt(H*.0004+n*sig*sig)))\n        if n>rate+5 and w<1e-11:break\n    extent=8.*math.sqrt(H*.0004+28.*sig*sig)\n    lower=-extent;upper=extent\n    Z=inv(p)*math.sqrt(H*(.0004+lam*sig*sig))\n    for _ in range(28):\n        val=sum(w*cdf(Z/sd) for w,sd in terms)\n        g=sum(w*pdf(Z/sd)/sd for w,sd in terms)\n        if abs(val-p)<1e-11:break\n        if val<p:lower=Z\n        else:upper=Z\n        candidate=Z-(val-p)/max(g,1e-15)\n        Z=candidate if lower<candidate<upper else (lower+upper)/2\n    g=sum(w*pdf(Z/sd)/sd for w,sd in terms)\n    return Z,g\n", "code_sha256": "65cfc3c859a624226d5203be4c989c8fd7ad81386b3048ef99c07b5d985f667f", "tried": ["Double demand-scaled inventory target; seeds 0-199: mean_edge=76.834464539288, failures=0.", "Full-weight exact process likelihood, original pricing; seeds 0-199: mean_edge=77.91791853095201, failures=0.", "Direct retail and approximate process adaptation; seeds 0-199: mean_edge=78.4045036507285, failures=0.", "Approximate process posterior, direct substitution; seeds 0-199: mean_edge=78.444103864964, failures=0.", "Normalized 12-node quadrature, learned process; seeds 0-199: mean_edge=78.457098273741, failures=0.", "Full-weight approximate process likelihood using raw midpoints; seeds 0-199: mean_edge=78.5192265889605, failures=0.", "Ask-side inference only; seeds 0-199: mean_edge=78.542091259671, failures=0.", "Survival-conditioned retail estimator; direct physical parameters; seeds 0-199: mean_edge=78.567417485094, failures=0.", "Discarded full-weight raw-bound prototype; inverse later repaired; seeds 0-199: mean_edge=78.6403805261025, failures=0.", "Exact process likelihood with raw bounds, original pricing; seeds 0-199: mean_edge=78.65362357349599, failures=0.", "Half demand-scaled inventory target; seeds 0-199: mean_edge=78.6628530251365, failures=0.", "Compound-Poisson positive-volume moment sizing; seeds 0-199: mean_edge=78.7344234879895, failures=0.", "Normalized 12-node quadrature, fixed parameters; seeds 0-199: mean_edge=78.748065379536, failures=0.", "Approximate process likelihood using raw tick midpoints; seeds 0-199: mean_edge=78.770209723644, failures=0.", "Repaired exact pricing and normalized nodes with fixed parameters; seeds 0-199: mean_edge=78.81384170912901, failures=0.", "Unmodified base reproduction; seeds 0-199: mean_edge=78.85441957511699, failures=0.", "Compound-Poisson posterior predictive sizing; seeds 0-199: mean_edge=78.926712447839, failures=0.", "Approximate process posterior relative to base calibration; seeds 0-199: mean_edge=78.927830477122, failures=0.", "Half demand-scaled acquisition cap; seeds 0-199: mean_edge=78.9496122876995, failures=0.", "Exact process posterior relative to base calibration; seeds 0-199: mean_edge=78.961626635695, failures=0.", "Normalized 6-node quadrature, learned process; seeds 0-199: mean_edge=78.9733763960415, failures=0.", "Repaired exact pricing with fixed prior parameters; seeds 0-199: mean_edge=79.010585265694, failures=0.", "Fixed-prior predictive control, no run learning; seeds 0-199: mean_edge=79.018174869496, failures=0.", "Discarded exact-pricing 12-node prototype; inverse later repaired; seeds 0-199: mean_edge=79.0790539057995, failures=0.", "Discarded fixed exact-pricing 12-node prototype; inverse later repaired; seeds 0-199: mean_edge=79.0868253955785, failures=0.", "Also infer from known priority at competitor ticks; seeds 0-199: mean_edge=79.1056507998205, failures=0.", "Discarded exact-pricing prototype; late inverse later repaired; seeds 0-199: mean_edge=79.191925229452, failures=0.", "Discarded raw-bound exact-pricing prototype; inverse later repaired; seeds 0-199: mean_edge=79.23477852824949, failures=0.", "Repaired exact pricing and learned process parameters; seeds 0-199: mean_edge=79.245877078544, failures=0.", "Repaired exact pricing, normalized Gaussian nodes, learned parameters; seeds 0-199: mean_edge=79.2471300883125, failures=0.", "Half-strength relative retail adaptation; seeds 0-199: mean_edge=79.2769445872745, failures=0.", "Discarded fixed-parameter exact-pricing prototype; inverse later repaired; seeds 0-199: mean_edge=79.29620857998749, failures=0.", "Retail parameters relative to base calibration; seeds 0-199: mean_edge=79.298045854184, failures=0.", "Fixed quote parameters, adaptive inventory; seeds 0-199: mean_edge=79.319112602216, failures=0.", "Event-weighted posterior size moments; seeds 0-199: mean_edge=79.345197625034, failures=0.", "Solve posterior marginal retail tail directly; seeds 0-199: mean_edge=79.370079040061, failures=0.", "Half-strength quote and inventory adaptation; seeds 0-199: mean_edge=79.385465955658, failures=0.", "Adapt inventory but keep original quote-size parameters; seeds 0-199: mean_edge=79.3887466557785, failures=0.", "Freeze retail learning after step 500; seeds 0-199: mean_edge=79.425251820053, failures=0.", "Adaptive quotes, fixed inventory parameters; seeds 0-199: mean_edge=79.4294784708485, failures=0.", "Full-weight retail likelihood; seeds 0-199: mean_edge=79.4573422455725, failures=0.", "Priority-aware inference, half inventory adaptation; seeds 0-199: mean_edge=79.5418961048005, failures=0.", "Adapt quote order size only, plus inventory; seeds 0-199: mean_edge=79.587463872276, failures=0.", "Double demand-scaled acquisition cap; seeds 0-199: mean_edge=79.592474197719, failures=0.", "Priority-aware inference plus inventory target only; seeds 0-199: mean_edge=79.595107433854, failures=0.", "Run-demand inventory target only; seeds 0-199: mean_edge=79.6036529977855, failures=0.", "Point compound-Poisson sizing plus inventory adaptation; seeds 0-199: mean_edge=79.616813039638, failures=0.", "Combined model with normalized Gaussian nodes; seeds 0-199: mean_edge=79.630448971337, failures=0.", "Double-strength quote and inventory adaptation; seeds 0-199: mean_edge=79.669124416866, failures=0.", "Adapt quote arrival rate only, plus inventory; seeds 0-199: mean_edge=79.673498660799, failures=0.", "Scale preliminary near-zero inventory by inferred demand; seeds 0-199: mean_edge=79.6990195328265, failures=0.", "Half preliminary inventory with demand scaling; seeds 0-199: mean_edge=79.7237360893515, failures=0.", "Scale inventory by order size only; seeds 0-199: mean_edge=79.73027659606001, failures=0.", "Scale inventory by arrival rate only; seeds 0-199: mean_edge=79.731845509831, failures=0.", "Compound predictive sizing with 1.05 size calibration and inventory; seeds 0-199: mean_edge=79.750050830953, failures=0.", "Priority-aware inference plus demand-scaled inventory; seeds 0-199: mean_edge=79.800328130901, failures=0.", "Compound-Poisson predictive sizing plus inventory adaptation; seeds 0-199: mean_edge=79.8666416442535, failures=0.", "Acquisition cap = 2 times estimated per-step retail shares; seeds 0-199: mean_edge=79.868413571726, failures=0.", "Double preliminary inventory with demand scaling; seeds 0-199: mean_edge=79.8780054045825, failures=0.", "Retail adaptation plus run-demand inventory target and acquisition cap; seeds 0-199: mean_edge=79.92925252101, failures=0.", "Decode initial competitor spread and use a one-tick initial belief; seeds 0-199: mean_edge=79.97750898172251, failures=0.", "Posterior moments plus demand-scaled inventory; seeds 0-199: mean_edge=80.130178228774, failures=0.", "Exact posterior marginal-tail solve plus inventory adaptation; seeds 0-199: mean_edge=80.1448384876475, failures=0.", "Acquisition cap = 4 times estimated per-step retail shares; seeds 0-199: mean_edge=80.145369690504, failures=0.", "Acquisition cap = 8 times estimated per-step retail shares; seeds 0-199: mean_edge=80.1717559942505, failures=0.", "Relative exact process posterior plus predictive retail and inventory; seeds 0-199: mean_edge=80.18289891405101, failures=0.", "Exact initial spread plus posterior moments and inventory; seeds 0-199: mean_edge=80.18390396986649, failures=0.", "Combined model with one-step martingale mean adjustment; seeds 0-199: mean_edge=80.5593859903845, failures=0.", "Retail posterior, inventory adaptation, exact process likelihood and repaired exact pricing; seeds 0-199: mean_edge=80.6863249702435, failures=0.", "Unmodified base reproduction; seeds 0-599: mean_edge=87.41650726068066, failures=0.", "Also infer from known priority at competitor ticks; seeds 0-599: mean_edge=88.15852181614333, failures=0.", "Event-weighted posterior size moments; seeds 0-599: mean_edge=88.39989979725067, failures=0.", "Retail parameters relative to base calibration; seeds 0-599: mean_edge=88.51038368665617, failures=0.", "Scale preliminary near-zero inventory by inferred demand; seeds 0-599: mean_edge=88.69174497733016, failures=0.", "Initial spread plus retail/inventory and full calibrated exact process adaptation; seeds 0-599: mean_edge=88.78236014988317, failures=0.", "Posterior moments plus demand-scaled inventory; seeds 0-599: mean_edge=88.87031634309466, failures=0.", "Retail adaptation plus run-demand inventory target and acquisition cap; seeds 0-599: mean_edge=88.89810070227034, failures=0.", "Decode initial competitor spread and use a one-tick initial belief; seeds 0-599: mean_edge=88.90354818588966, failures=0.", "Initial spread plus retail/inventory and half-strength calibrated exact process adaptation; seeds 0-599: mean_edge=89.0232228208455, failures=0.", "Combined model with half-weight process likelihood; seeds 0-599: mean_edge=89.03028450445984, failures=0.", "Initial spread plus full-weight retail learning and inventory adaptation; seeds 0-599: mean_edge=89.04375809854633, failures=0.", "Combined model with double-weight process likelihood; seeds 0-599: mean_edge=89.26842824076518, failures=0.", "Combined model with one-step martingale mean adjustment; seeds 0-599: mean_edge=89.27995123327733, failures=0.", "Combined model with exact initial spread bound; seeds 0-599: mean_edge=89.320709858373, failures=0.", "Retail posterior, inventory adaptation, exact process likelihood and repaired exact pricing; seeds 0-599: mean_edge=89.32666422493216, failures=0.", "Combined model with twice-standard retail likelihood weight; seeds 0-599: mean_edge=89.40256596068184, failures=0.", "Diagnostic only, not a candidate: actual retail parameters supplied to the point inventory model on training seeds 0-199, mean_edge=80.1701569302415.", "Inference limitation: competitor notional depth is not directly exposed by StepState; no reliable early depth estimator was established. Front-of-queue quoting retains the base rule, which does not require a depth estimate.", "Training means within 0.02 were treated as ties, preferring the mathematically exact initial-spread bound. All tuning and model selection used seeds 0-599. The strategy was frozen before the single 600-run holdout on seeds 20000-20599.", "Numerical checks: bracketed inverse maximum probability residual below 6e-9 on the tested horizon/parameter grid; process inverse residual below 2e-8 on the sampled learning-domain grid. Per-run posterior isolation passed.", "Frozen final file: serial seed 0 exactly reproduced the parallel training result, including edge components, traded quantity and fill count.", "Sandbox check: final file and examples/starter_strategy.py both failed 20/20 before strategy loading on Python 3.12.3: ImportError: Import of 'ntpath' is not allowed in sandbox mode. Normal-mode training and holdout each completed 600/600 without failures; no simulator patch was used.", "Post-freeze diagnostic control only: unmodified base on holdout seeds 20000-20599 mean_edge=85.46780344973116; candidate paired mean gain=0.3961015943926672, paired standard error=0.7810289117235663. The holdout gain is within sampling noise. No strategy choice or parameter change used this control or the holdout.", "Selected frozen combined_r1: training seeds 0-599 mean_edge=89.50960810972317, retail_edge=119.02587107676601, arb_edge=-29.516262967079832; holdout seeds 20000-20599 mean_edge=85.86390504412384; zero normal-mode failures."], "next": "The paired holdout gain is small relative to its standard error, so test the simpler retail estimator and the full model on more fresh paired runs before merging the extra complexity. Preserve the survival-conditioning correction and calibration ratios when combining with other seats. Competitor depth still needs explicit inference from censored queue depletion rather than a naive elapsed-time estimate."}