```json { "rows": [ { "key": "f-nofill-bounds", "spreads_acted": [ 4 ], "off_equals_n": true, "code_sha256": "bc5f1d1aeb505ca20ab5f4f6b58037c2a2a2599f9d14fdeb129e3389b439446e", "assembled_sha256": "d05a77cc3c3f1d8cba78a6f596fa354d220a760b5f40540a345f984572427f52", "tuning": { "mean_diff": 0.326439, "se": 1.284461 }, "paired": { "n": 500, "complete": true, "incumbent_mean": 104.413753, "mean_diff": -0.099236, "se": 0.105246, "sum_d": -49.61814, "sum_d2": 2768.567977, "retail_diff": 0.056202, "arb_diff": -0.155439, "failures": 0 }, "by_spread": { "1": { "runs": 115, "mean_diff": 0.0, "se": 0.0, "sum_d": 0.0, "sum_d2": 0.0 }, "2": { "runs": 116, "mean_diff": 0.0, "se": 0.0, "sum_d": 0.0, "sum_d2": 0.0 }, "3": { "runs": 138, "mean_diff": 0.0, "se": 0.0, "sum_d": 0.0, "sum_d2": 0.0 }, "4": { "runs": 131, "mean_diff": -0.378764, "se": 0.401829, "sum_d": -49.61814, "sum_d2": 2768.567977 } }, "flag": [] }, { "key": "f-side-staleness", "spreads_acted": [ 1, 2, 3, 4 ], "off_equals_n": true, "code_sha256": "755b966620276ddda466bba202c98989f200499e927c3d4197229d459f2e8946", "assembled_sha256": "7d6ba8329c9e8703ec8767416a06a2682a5193506b39688112219964cfffed26", "tuning": { "mean_diff": 0.0, "se": 0.0 }, "paired": { "n": 500, "complete": true, "incumbent_mean": 104.4137531881468, "mean_diff": 0.0, "se": 0.0, "sum_d": 0.0, "sum_d2": 0.0, "retail_diff": 0.0, "arb_diff": 0.0, "failures": 0 }, "by_spread": { "1": { "runs": 115, "mean_diff": 0.0, "se": 0.0, "sum_d": 0.0, "sum_d2": 0.0 }, "2": { "runs": 116, "mean_diff": 0.0, "se": 0.0, "sum_d": 0.0, "sum_d2": 0.0 }, "3": { "runs": 138, "mean_diff": 0.0, "se": 0.0, "sum_d": 0.0, "sum_d2": 0.0 }, "4": { "runs": 131, "mean_diff": 0.0, "se": 0.0, "sum_d": 0.0, "sum_d2": 0.0 } }, "flag": [] }, { "key": "f-entropy-probes", "spreads_acted": [ 1 ], "off_equals_n": true, "code_sha256": "fc562ab21035eb7ae20ce368d4d241af15056d3e5d49e643ac658f3f6fbd4750", "assembled_sha256": "6d6b3416ff55a109227d23406a621507cba53b41ef1f6c66c3fa2100ea02f188", "tuning": { "mean_diff": -0.11955382296750017, "se": 0.10967181633384236 }, "paired": { "n": 500, "complete": true, "incumbent_mean": 104.4137531881468, "mean_diff": 0.04308369514640007, "se": 0.1294094053714322, "sum_d": 21.541847573200034, "sum_d2": 4179.253254941355, "retail_diff": 0.08762716991220028, "arb_diff": -0.04454347478040007, "failures": 0 }, "by_spread": { "1": { "runs": 115, "mean_diff": 0.1873204136800003, "se": 0.5643366212245237, "sum_d": 21.541847573200034, "sum_d2": 4179.253254941355 }, "2": { "runs": 116, "mean_diff": 0.0, "se": 0.0, "sum_d": 0.0, "sum_d2": 0.0 }, "3": { "runs": 138, "mean_diff": 0.0, "se": 0.0, "sum_d": 0.0, "sum_d2": 0.0 }, "4": { "runs": 131, "mean_diff": 0.0, "se": 0.0, "sum_d": 0.0, "sum_d2": 0.0 } }, "flag": [] }, { "key": "f-probe-stopping", "spreads_acted": [ 2, 3 ], "off_equals_n": true, "code_sha256": "7fa10543f5349a27a9f5e739cf38e7fb62bfe02144cbad8a44a6202030a7745a", "assembled_sha256": "46434cb8ca37b6f4fd6b7e7e7d5a4ebf60dde34edfb20076eca024ee4ba77c8c", "tuning": { "mean_diff": 0.017228190573999123, "se": 0.036002742279609735 }, "paired": { "n": 500, "complete": true, "incumbent_mean": 104.4137531881468, "mean_diff": 0.016767629280000168, "se": 0.030340765993081643, "sum_d": 8.383814640000084, "sum_d2": 229.82081591704718, "retail_diff": -0.053693320717199906, "arb_diff": 0.07046094999859989, "failures": [] }, "by_spread": { "1": { "runs": 115, "mean_diff": 0.0, "se": 0.0, "sum_d": 0.0, "sum_d2": 0.0 }, "2": { "runs": 116, "mean_diff": 0.04460301534482666, "se": 0.12894293783950417, "sum_d": 5.173949779999893, "sum_d2": 222.0253652186517 }, "3": { "runs": 138, "mean_diff": 0.02325989028985646, "se": 0.020208358226073298, "sum_d": 3.2098648600001916, "sum_d2": 7.7954506983954825 }, "4": { "runs": 131, "mean_diff": 0.0, "se": 0.0, "sum_d": 0.0, "sum_d2": 0.0 } }, "flag": [] }, { "key": "f-endgame-stop", "spreads_acted": [ 4 ], "off_equals_n": true, "code_sha256": "fad593aa209f973286ed505d9524f5be1c2ede6acc7b28ea2ee8b42e691a59e5", "assembled_sha256": "54547bcab6845a2b286a48d52433e36e194057598e6b7f8a02e89921f0ee9972", "tuning": { "mean_diff": 0.7489174217975002, "se": 1.1938712483943008 }, "paired": { "n": 500, "complete": true, "incumbent_mean": 104.4137531881468, "mean_diff": -1.2806409814948008, "se": 0.453000171696227, "sum_d": -640.3204907474004, "sum_d2": 52019.70497316637, "retail_diff": -1.4237439286181994, "arb_diff": 0.14310294712500007, "failures": [] }, "by_spread": { "1": { "runs": 115, "mean_diff": 0.0, "se": 0.0, "sum_d": 0.0, "sum_d2": 0.0 }, "2": { "runs": 116, "mean_diff": 0.0, "se": 0.0, "sum_d": 0.0, "sum_d2": 0.0 }, "3": { "runs": 138, "mean_diff": 0.0, "se": 0.0, "sum_d": 0.0, "sum_d2": 0.0 }, "4": { "runs": 131, "mean_diff": -4.887942677461072, "se": 1.6943458027529323, "sum_d": -640.3204907474004, "sum_d2": 52019.70497316637 } }, "flag": [] }, { "key": "f-join-timing", "spreads_acted": [ 4 ], "off_equals_n": true, "code_sha256": "56c54021a1e04a1ba1a46cd74fd82a20acf24e314d3beedd2090ce697eb7aa02", "assembled_sha256": "4baf6f540c53e4cca01a8aebec16db2b3ef3b84aa7f3e171ff5cbca7edf057ee", "tuning": { "mean_diff": -0.50848106736, "se": 0.23003515929090654 }, "paired": { "n": 500, "complete": true, "incumbent_mean": 104.4137531881468, "mean_diff": -0.48611712687180036, "se": 0.08468698293516504, "sum_d": -243.05856343590017, "sum_d2": 1907.5402576449499, "retail_diff": 0.06351087063600043, "arb_diff": -0.5496279975049998, "failures": 0 }, "by_spread": { "1": { "runs": 115, "mean_diff": 0.0, "se": 0.0, "sum_d": 0.0, "sum_d2": 0.0 }, "2": { "runs": 116, "mean_diff": 0.0, "se": 0.0, "sum_d": 0.0, "sum_d2": 0.0 }, "3": { "runs": 138, "mean_diff": 0.0, "se": 0.0, "sum_d": 0.0, "sum_d2": 0.0 }, "4": { "runs": 131, "mean_diff": -1.8554088811900775, "se": 0.29245425541254577, "sum_d": -243.05856343590017, "sum_d2": 1907.5402576449499 } }, "flag": [] } ], "top": [ { "key": "f-probe-stopping", "spread": 3, "code": "from dataclasses import replace as _probe_replace\nfrom math import sqrt as _probe_sqrt\nfrom orderbook_pm_challenge.types import PlaceOrder as _PP, CancelOrder as _PC, CancelAll as _PA, Side as _PS\n\nclass Strategy(BaseStrategy):\n # The incumbent is opaque; only callback inputs and returned actions are used.\n SPREADS = (2, 3)\n ENABLED = True\n SHRINK = 0.35\n\n def __init__(self):\n self.n = _N()\n self.spread = None\n self.probes = {}\n self.weights = None\n self.last_quotes = None\n self.anchor = None\n self.stopped = set()\n self.serial = 0\n\n def on_step(self, state):\n if self.spread is None:\n b, a = state.competitor_best_bid_ticks, state.competitor_best_ask_ticks\n self.spread = max(1, (a-b+1)//2) if b is not None and a is not None else 1\n if not self.ENABLED or self.spread not in self.SPREADS:\n return self.n.on_step(state)\n own = {o.order_id:o for o in state.own_orders}\n visible = tuple(o for o in state.own_orders if o.order_id not in self.probes)\n clean = _probe_replace(state, own_orders=visible)\n actions = list(self.n.on_step(clean))\n b = state.competitor_best_bid_ticks\n a = state.competitor_best_ask_ticks\n lo, hi = (b if b is not None else 0), (a if a is not None else 100)\n if self.weights is None:\n self.weights = [1.0 if lo <= i*.5 <= hi else 0.000001 for i in range(201)]\n w = self.weights\n # Diffusion plus a small jump hazard, followed by the last-step bracket.\n mass = sum(w)\n w = [(.84*w[i]+.08*w[max(0,i-1)]+.08*w[min(200,i+1)])*.998 + mass*.002/201 for i in range(201)]\n w = [v*(1 if lo <= i*.5 <= hi else .001) for i,v in enumerate(w)]\n swept = {}\n for oid,(side, tick, quantity) in self.probes.items():\n filled = oid not in own or own[oid].remaining_quantity < quantity-.005\n # A retail arrival can also sweep a tiny probe: use a noisy likelihood.\n for i in range(201):\n toxic = i*.5 < tick if side == _PS.BUY else i*.5 > tick\n pf = .995 if toxic else .12\n w[i] *= pf if filled else 1-pf\n if filled:\n swept[side] = tick\n self.stopped.discard(side)\n z = sum(w)\n w = [v/z for v in w]\n self.weights = w\n mean = sum(i*.5*v for i,v in enumerate(w))\n variance = sum((i*.5-mean)**2*v for i,v in enumerate(w))\n quotes = (b,a)\n if self.last_quotes != quotes or (self.anchor is not None and abs(mean-self.anchor)>1):\n self.stopped.clear()\n self.anchor = mean\n if self.anchor is None:\n self.anchor = mean\n self.last_quotes = quotes\n # Release surviving probes before the incumbent's action list.\n out = [_PC(oid) for oid in self.probes if oid in own]\n self.probes = {}\n # Track the book resulting from N's actions, without inspecting N itself.\n live = dict((o.order_id,o) for o in visible)\n revised = []\n for action in actions:\n if isinstance(action,_PA):\n live.clear()\n elif isinstance(action,_PC):\n live.pop(action.order_id,None)\n elif isinstance(action,_PP):\n tick = swept.get(action.side)\n behind = tick is not None and (action.price_tickstick)\n if behind:\n q = max(.01, int(action.quantity*self.SHRINK*100)/100)\n action = _probe_replace(action,quantity=q)\n revised.append(action)\n # Existing resting orders also shrink if N chose to retain them.\n for oid,o in list(live.items()):\n tick = swept.get(o.side)\n behind = tick is not None and (o.price_tickstick)\n if behind:\n revised.extend([_PC(oid),_PP(o.side,o.price_ticks,max(.01,int(o.remaining_quantity*self.SHRINK*100)/100),oid)])\n out.extend(revised)\n # Build a reservation-conservative view of final orders for probe budgeting.\n book = {oid:(o.side,o.price_ticks,o.remaining_quantity) for oid,o in visible_dict(visible).items()}\n for act in revised:\n if isinstance(act,_PA): book.clear()\n elif isinstance(act,_PC): book.pop(act.order_id,None)\n elif isinstance(act,_PP): book[act.client_order_id or ('new',len(book))]=(act.side,act.price_ticks,act.quantity)\n reserve = sum(q*(p/100 if side==_PS.BUY else 1-p/100) for side,p,q in book.values())\n budget = state.cash-reserve\n for side in (_PS.BUY,_PS.SELL):\n candidates = [(p,q) for s,p,q in book.values() if s==side]\n if not candidates or side in self.stopped: continue\n best = max(p for p,q in candidates) if side==_PS.BUY else min(p for p,q in candidates)\n tick = best+(1 if side==_PS.BUY else -1)\n other = [p for s,p,q in book.values() if s!=side]\n if not 1<=tick<=99: continue\n exposure = sum(q for p,q in candidates if abs(p-best)<=1)\n pf = [(.995 if (i*.5tick) else .12) for i in range(201)]\n prob = sum(v*f for v,f in zip(w,pf))\n mfill = sum(i*.5*v*f for i,(v,f) in enumerate(zip(w,pf)))/max(prob,1e-12)\n msurvive = (mean-prob*mfill)/max(1-prob,1e-12)\n reduction = prob*(mfill-mean)**2+(1-prob)*(msurvive-mean)**2\n loss = .01*.01*sum(v*max(0,tick-i*.5 if side==_PS.BUY else i*.5-tick) for i,v in enumerate(w))\n value = .15*.01*min(exposure,20)*reduction/max(1,_probe_sqrt(variance))\n if value <= loss+.00001 or reduction < .002:\n self.stopped.add(side)\n continue\n if budget < .02: continue\n self.serial += 1\n oid = '__sequential_probe_%d'%self.serial\n out.append(_PP(side,tick,.01,oid))\n self.probes[oid]=(side,tick,.01)\n budget -= .01\n return out\n\ndef visible_dict(orders):\n return {o.order_id:o for o in orders}\n" }, { "key": "f-entropy-probes", "spread": 1, "code": "from dataclasses import replace as _probe_replace\nfrom orderbook_pm_challenge.types import PlaceOrder as _PPlace, CancelOrder as _PCancel, CancelAll as _PAll, Side as _PSide\n\nclass Strategy(BaseStrategy):\n # Joint ternary entropy probes: thresholds at posterior terciles.\n SPREADS = (1,)\n CONFIDENCE = 0.95\n ENABLED = True\n\n def __init__(self):\n self.n = _N()\n self.spread = None\n self.probes = {}\n self.weights = None\n\n def on_step(self, state):\n if self.spread is None:\n b, a = state.competitor_best_bid_ticks, state.competitor_best_ask_ticks\n self.spread = max(1, (a-b+1)//2) if b is not None and a is not None else 0\n if not self.ENABLED or self.spread not in self.SPREADS:\n return self.n.on_step(state)\n visible = {o.order_id: o for o in state.own_orders}\n hidden = tuple(o for o in state.own_orders if o.order_id not in self.probes)\n actions = list(self.n.on_step(_probe_replace(state, own_orders=hidden)))\n w = self.weights\n evidence = []\n if w is not None:\n for oid, (side, tick) in self.probes.items():\n filled = oid not in visible\n adverse = sum(v for i,v in enumerate(w) if (i+0.5 < tick if side == _PSide.BUY else i+0.5 > tick))\n confidence = adverse / max(1e-15, adverse + 0.15*(1-adverse))\n if filled and confidence >= self.CONFIDENCE:\n evidence.append((side, tick))\n # Surviving a full arbitrage pass is a hard inequality;\n # fills may instead be caused by a retail order.\n for i in range(100):\n bad = i+0.5 < tick if side == _PSide.BUY else i+0.5 > tick\n w[i] *= (1.0 if bad else 0.15) if filled else (0.0 if bad else 0.85)\n norm = sum(w)\n if norm > 1e-15:\n w = [v/norm for v in w]\n b, a = state.competitor_best_bid_ticks, state.competitor_best_ask_ticks\n lo, hi = b if b is not None else 0, a if a is not None else 100\n if w is None:\n w = [float(lo <= i+0.5 <= hi) for i in range(100)]\n else:\n w = [v if lo <= i+0.5 <= hi else 0.0 for i,v in enumerate(w)]\n total = sum(w)\n if total <= 1e-15:\n w = [float(lo <= i+0.5 <= hi) for i in range(100)]\n total = sum(w)\n if total <= 0:\n w = [1.0]*100\n total = 100.0\n w = [v/total for v in w]\n # Predict the next probability, allowing diffusion and occasional jumps.\n radius = 1 if state.steps_remaining > 200 else 2\n predicted = [0.0]*100\n for i,v in enumerate(w):\n for j in range(max(0,i-radius), min(100,i+radius+1)):\n predicted[j] += 0.98*v/(min(99,i+radius)-max(0,i-radius)+1)\n for i in range(100):\n predicted[i] += 0.02/100\n self.weights = predicted\n # Remove old probes before applying N's requested actions.\n out = [_PCancel(oid) for oid in self.probes if oid in visible]\n live = {o.order_id: (o.side,o.price_ticks,o.remaining_quantity) for o in hidden}\n # Track only explicit client ids; anonymous new orders can be dropped\n # immediately when stale, without needing their simulator-generated ids.\n def stale(side,tick):\n return any(side == s and (tick >= p if s == _PSide.BUY else tick <= p) for s,p in evidence)\n anon = 0\n for act in actions:\n if isinstance(act,_PAll):\n live.clear()\n out.append(act)\n elif isinstance(act,_PCancel):\n live.pop(act.order_id,None)\n out.append(act)\n elif isinstance(act,_PPlace):\n if stale(act.side,act.price_ticks):\n continue\n out.append(act)\n oid = act.client_order_id\n if oid is None:\n anon += 1\n oid = ('anonymous',anon)\n live[oid] = (act.side,act.price_ticks,act.quantity)\n else:\n out.append(act)\n for oid,(side,tick,q) in list(live.items()):\n if isinstance(oid,str) and stale(side,tick):\n out.append(_PCancel(oid))\n del live[oid]\n # Conservative collateral bound: charge every sell as uncovered.\n available = state.cash - sum((tick/100 if side == _PSide.BUY else 1-tick/100)*q for side,tick,q in live.values())\n self.probes = {}\n if b is None or a is None or a-b < 2:\n return out\n thresholds = []\n for target in (1/3,2/3):\n cdf = 0.0\n tick = b+1\n for i,v in enumerate(predicted):\n cdf += v\n if cdf >= target:\n tick = round(i+0.5)\n break\n thresholds.append(max(b+1,min(a-1,tick)))\n for side,tick in zip((_PSide.BUY,_PSide.SELL),thresholds):\n cost = 0.01*(tick/100 if side == _PSide.BUY else 1-tick/100)\n if 1 <= tick <= 99 and available >= cost+1e-8:\n oid = '__entropy_probe_%s_%d' % (side.value,state.step)\n out.append(_PPlace(side,tick,0.01,oid))\n self.probes[oid] = (side,tick)\n available -= cost\n return out\n" }, { "key": "f-nofill-bounds", "spread": 4, "code": "class Strategy(BaseStrategy):\n \"\"\"Overlay f-nofill-bounds: censored no-fill bounds on p.\n\n An own bid at x that sat a whole step untouched means p >= x (else the\n arbitrageur would have sold into it); an untouched ask at y means p <= y.\n Together with the competitor quotes this keeps an interval [lo, hi] (ticks).\n N's new asks priced below lo and new bids priced above hi are dropped.\"\"\"\n\n ACT = (4,)\n STRICT = True\n OFF = False\n\n def __init__(self):\n self._n = _N()\n self._s = None\n self._prev = {}\n self._placed = []\n self.steps = 0\n self.narrow = 0\n self.dropped = 0\n\n def on_step(self, state):\n acts = self._n.on_step(state)\n cb, ca = state.competitor_best_bid_ticks, state.competitor_best_ask_ticks\n if self._s is None:\n if cb is not None and ca is not None:\n self._s = max(1, (ca - cb + 1) // 2)\n else:\n self._s = 0\n lo, hi = None, None\n cur = {}\n placed = self._placed\n for o in state.own_orders:\n cur[o.order_id] = o.remaining_quantity\n q = self._prev.get(o.order_id)\n full = False\n if q is not None:\n full = abs(q - o.remaining_quantity) < 1e-9\n elif o.submitted_step == state.step - 1:\n for (sd, px, qq) in placed:\n if sd == o.side and px == o.price_ticks and abs(qq - o.remaining_quantity) < 1e-9:\n full = True\n break\n if not full:\n continue\n if o.side.value == \"BUY\":\n lo = o.price_ticks if lo is None else max(lo, o.price_ticks)\n else:\n hi = o.price_ticks if hi is None else min(hi, o.price_ticks)\n self._prev = cur\n L = cb if lo is None else (lo if cb is None else max(lo, cb))\n H = ca if hi is None else (hi if ca is None else min(hi, ca))\n self.steps += 1\n if L is not None and H is not None and cb is not None and ca is not None:\n if H - L < ca - cb:\n self.narrow += 1\n out = list(acts)\n if not self.OFF and self._s in self.ACT and (lo is not None or hi is not None):\n keep = []\n for a in out:\n if isinstance(a, PlaceOrder):\n sv = a.side.value\n if sv == \"SELL\" and lo is not None and (a.price_ticks < lo if self.STRICT else a.price_ticks <= lo):\n self.dropped += 1\n continue\n if sv == \"BUY\" and hi is not None and (a.price_ticks > hi if self.STRICT else a.price_ticks >= hi):\n self.dropped += 1\n continue\n keep.append(a)\n out = keep\n self._placed = [(a.side, a.price_ticks, a.quantity) for a in out if isinstance(a, PlaceOrder)]\n return out\n" } ] } ``` Sources (each row and code field comes from its matching item): [f-nofill-bounds](../../items/f-nofill-bounds/result.json), [f-side-staleness](../../items/f-side-staleness/result.json), [f-entropy-probes](../../items/f-entropy-probes/result.json), [f-probe-stopping](../../items/f-probe-stopping/result.json), [f-endgame-stop](../../items/f-endgame-stop/result.json), [f-join-timing](../../items/f-join-timing/result.json). Source caveat supplied with the items: two cited sources for f-probe-stopping and one for f-endgame-stop failed revalidation. Their external-source claims are unverified; this merge copies their reported measurements and does not rely on those claims.