# Merge 01 of batch r3-fresh-overlay Sources: the six item results under .imd/reads/artifacts/item-f-*. Numbers are copied from the items; nothing recomputed. `paired_n` is the item's `paired.n`. `top` takes the three unflagged rows with the largest signed mean_diff/se in one spread of at least 60 runs (jump-scale spread 3, post-jump spread 1, cp-filter spread 1); the fourth unflagged row, interval-vol, has only a negative ratio (spread 2). Flags: f-run-class has incumbent_mean 104.39217582931512 versus 104.4137531881468 in the other rows; f-jump-hazard has 19 failed runs in spread 1 (`failures`: incumbent 0, s1 19). The `tuning` figures are each item's own tuning-seed result. ```json { "rows": [ { "key": "f-cp-filter", "spreads_acted": [ 1 ], "off_equals_n": true, "code_sha256": "0d8b3bfc15f4ebb6d87b6f0319fa0b5d7d8656faf01b39822de07a18ae40e73b", "assembled_sha256": "cfb2b64ae8853f5ce7fdb1e0735c7e3c62d38bdbc70de23140aefb5e96276053", "tuning": { "mean_diff": -1.646333043531, "se": 0.9979799039501333 }, "paired_n": 500, "complete": true, "incumbent_mean": 104.4137531881468, "mean_diff": -1.1100869039471999, "se": 0.5379546442126854, "sum_d": -555.0434519736, "sum_d2": 72820.24867504176, "retail_diff": -0.28749331825019975, "arb_diff": -0.8225935857025999, "failures": [], "by_spread": { "1": { "runs": 115, "mean_diff": -4.826464799770434, "se": 2.3130537103475493, "sum_d": -555.0434519736, "sum_d2": 72820.24867504176 }, "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-run-class", "spreads_acted": [ 4 ], "off_equals_n": { "passed": true, "n": 10, "seeds": [ 310000, 310001, 310002, 310003, 310004, 310005, 310006, 310007, 310008, 310009 ], "comparison": "Exact action equality on every callback, 2000 per seed, with mechanism disabled." }, "code_sha256": "cf2315a5df6fb7e3208bf08c2dcf7d7b864c6589f358def9f068ae346cd7de04", "assembled_sha256": "bae4bedcf45030eb77959002916ad3354742e4c33ba4dc947ec55ca025f65e43", "tuning": { "mean_diff": -1.5148449827575008, "se": 0.40933699632644943 }, "paired_n": 500, "complete": true, "incumbent_mean": 104.39217582931512, "mean_diff": -1.2657039363906002, "se": 0.6279690666845577, "sum_d": -632.8519681953001, "sum_d2": 99190.11783110962, "retail_diff": 0.46734012163320054, "arb_diff": -1.7330440580183992, "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.830931054925955, "se": 2.3759023826355956, "sum_d": -632.8519681953001, "sum_d2": 99190.11783110962 } }, "flag": "incumbent_mean_unlike_others" }, { "key": "f-interval-vol", "spreads_acted": [ 2 ], "off_equals_n": true, "code_sha256": "0e6a608053af237468264663541681653cab68845fa760cb5238e0b483f5c8f9", "assembled_sha256": "e6818e2b3111bc57b20dfd22c549203ec9f50bc98ee78c691101439719167d89", "tuning": { "mean_diff": -0.30954789622000006, "se": 0.06611246670459199 }, "paired_n": 500, "complete": true, "incumbent_mean": 104.4137531881468, "mean_diff": -0.6748852093749997, "se": 0.15443782784214174, "sum_d": -337.4426046874999, "sum_d2": 6178.570168732022, "retail_diff": -0.2102066658670004, "arb_diff": -0.4646785435138001, "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": -2.9089879714439646, "se": 0.6241608273746742, "sum_d": -337.4426046874999, "sum_d2": 6178.570168732022 }, "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-jump-hazard", "spreads_acted": [ 1 ], "off_equals_n": true, "code_sha256": "e6b3070d01defa2d6e9436d6b133a0a3c834d63506429bcb8b1430a868b1b897", "assembled_sha256": "dba226eb471ed4dae1690331cdf574ca994c857e311bb858aa53a8790c297351", "tuning": { "mean_diff": -8.1233062950425, "se": 2.8521431429265665 }, "paired_n": 500, "complete": true, "incumbent_mean": 104.4137531881468, "mean_diff": -8.6466422506826, "se": 2.0732668703150328, "sum_d": -4323.3211253413, "sum_d2": 1109841.8722343447, "retail_diff": -4.0670200732704, "arb_diff": -4.5796221774224, "failures": { "incumbent": 0, "s1": 19 }, "by_spread": { "1": { "runs": 115, "mean_diff": -37.59409674209826, "se": 8.500507094853203, "sum_d": -4323.3211253413, "sum_d2": 1109841.8722343447 }, "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": "failures" }, { "key": "f-jump-scale", "spreads_acted": [ 2, 3 ], "off_equals_n": true, "code_sha256": "19aa0a454387c70ec599aacc8376ad9f6f128da3e15f380eea67b85798c0ebf6", "assembled_sha256": "499530021c3f72e8da491724f289913282998f1a183036e4ca65bfa1d3ccd86f", "tuning": { "mean_diff": 0.03221736027700006, "se": 0.10853236226713701 }, "paired_n": 500, "complete": true, "incumbent_mean": 104.4137531881468, "mean_diff": 0.2119980034939997, "se": 0.10582488390319784, "sum_d": 105.99900174699985, "sum_d2": 2816.5986369974835, "retail_diff": 0.07904918007179998, "arb_diff": 0.13294882341940004, "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.2407281207568967, "se": 0.218532827025179, "sum_d": 27.924462007800017, "sum_d2": 643.7952004070933 }, "3": { "runs": 138, "mean_diff": 0.5657575343420278, "se": 0.3355447782120479, "sum_d": 78.07453973919984, "sum_d2": 2172.80343659039 }, "4": { "runs": 131, "mean_diff": 0.0, "se": 0.0, "sum_d": 0.0, "sum_d2": 0.0 } }, "flag": "" }, { "key": "f-post-jump", "spreads_acted": [ 1, 2 ], "off_equals_n": true, "code_sha256": "5bf56012353053f27ae99edb3b452fd97486d198e68c7ee9b78edb7764109d75", "assembled_sha256": "93ab390d012d875f1e8246e3a07901090d99025032fc5d9febca65b9d09e6323", "tuning": { "mean_diff": 0.029057504757000006, "se": 0.030859230992502606 }, "paired_n": 500, "complete": true, "incumbent_mean": 104.4137531881468, "mean_diff": 0.041534091033599674, "se": 0.033972866517976, "sum_d": 20.767045516799836, "sum_d2": 288.82437739132325, "retail_diff": -0.03846756154559986, "arb_diff": 0.08000165258179992, "failures": 0, "by_spread": { "1": { "runs": 115, "mean_diff": 0.06300988988782574, "se": 0.04849860936089579, "sum_d": 7.2461373370999596, "sum_d2": 31.292807407046208 }, "2": { "runs": 116, "mean_diff": 0.1165595532732748, "se": 0.13851741726253283, "sum_d": 13.520908179699877, "sum_d2": 257.53156998427704 }, "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": "" } ], "top": [ { "key": "f-jump-scale", "spread": "3", "code": "from dataclasses import replace\nimport math\n\nfrom orderbook_pm_challenge.strategy import BaseStrategy\nfrom orderbook_pm_challenge.types import CancelAll, CancelOrder, PlaceOrder, Side\n\n\nclass Strategy(BaseStrategy):\n \"\"\"Conservatively remove newly stale incumbent quotes after inferred jumps.\"\"\"\n\n ACTIVE = True\n ACTIVE_SPREADS = (2, 3)\n CUT_SCALE = 0.1\n PRIOR_WEIGHT = 3.0\n PRIOR_SIGMA2 = (0.20 * 0.20 + 0.20 * 0.60 + 0.60 * 0.60) / 3.0\n JUMP_INTENSITY = (0.0008 + 0.0030) / 2.0\n DIFFUSION_SIGMA = 0.02\n\n def __init__(self):\n self._n = _N()\n self._spread = None\n self._previous_mid = None\n self._sigma2 = self.PRIOR_SIGMA2\n self._jump_count = 0\n self._jump_squares = 0.0\n self._cut_steps = 0\n self._cut_mid = None\n self._cut_distance = 0\n\n @staticmethod\n def _inv_norm(p):\n # Peter J. Acklam's rational approximation, adequate for tick prices.\n p = min(0.999, max(0.001, p))\n a = (-39.6968302866538, 220.946098424521, -275.928510446969,\n 138.357751867269, -30.6647980661472, 2.50662827745924)\n b = (-54.4760987982241, 161.585836858041, -155.698979859887,\n 66.8013118877197, -13.2806815528857)\n c = (-0.00778489400243029, -0.322396458041136, -2.40075827716184,\n -2.54973253934373, 4.37466414146497, 2.93816398269878)\n d = (0.00778469570904146, 0.32246712907004, 2.445134137143,\n 3.75440866190742)\n if p < 0.02425:\n q = math.sqrt(-2.0 * math.log(p))\n return (((((c[0]*q+c[1])*q+c[2])*q+c[3])*q+c[4])*q+c[5]) / ((((d[0]*q+d[1])*q+d[2])*q+d[3])*q+1.0)\n if p > 0.97575:\n q = math.sqrt(-2.0 * math.log(1.0-p))\n return -(((((c[0]*q+c[1])*q+c[2])*q+c[3])*q+c[4])*q+c[5]) / ((((d[0]*q+d[1])*q+d[2])*q+d[3])*q+1.0)\n q = p - 0.5\n r = q*q\n return (((((a[0]*r+a[1])*r+a[2])*r+a[3])*r+a[4])*r+a[5])*q / (((((b[0]*r+b[1])*r+b[2])*r+b[3])*r+b[4])*r+1.0)\n\n def _observe(self, state):\n bid = state.competitor_best_bid_ticks\n ask = state.competitor_best_ask_ticks\n if bid is None or ask is None:\n return\n mid = (bid + ask) / 200.0\n horizon = max(1, state.steps_remaining)\n scale = math.sqrt(horizon * (self.DIFFUSION_SIGMA ** 2 + self.JUMP_INTENSITY * self._sigma2))\n score = self._inv_norm(mid) * scale\n if self._previous_mid is not None:\n move = score - self._previous_mid\n # A score move six diffusion standard deviations is treated as a jump.\n if abs(move) >= 0.12:\n self._jump_count += 1\n self._jump_squares += move * move\n self._sigma2 = (self.PRIOR_WEIGHT * self.PRIOR_SIGMA2 + self._jump_squares) / (self.PRIOR_WEIGHT + self._jump_count)\n z = self._inv_norm(mid)\n density = math.exp(-0.5 * z * z) / math.sqrt(2.0 * math.pi)\n expected_ticks = math.sqrt(self._sigma2) * density * 100.0 * math.sqrt(2.0 / math.pi) / max(scale, 0.05)\n self._cut_distance = min(8, max(1, int(math.ceil(self.CUT_SCALE * expected_ticks))))\n self._cut_steps = 1\n self._cut_mid = (bid + ask) // 2\n self._previous_mid = score\n\n def _cut(self, action):\n if self._cut_steps <= 0 or self._cut_mid is None:\n return False\n if action.side is Side.BUY:\n return action.price_ticks >= self._cut_mid - self._cut_distance\n return action.price_ticks <= self._cut_mid + self._cut_distance\n\n def on_step(self, state):\n bid = state.competitor_best_bid_ticks\n ask = state.competitor_best_ask_ticks\n if self._spread is None:\n self._spread = 0 if bid is None or ask is None else max(1, (ask - bid + 1) // 2)\n enabled = self.ACTIVE and self._spread in self.ACTIVE_SPREADS\n if enabled:\n self._observe(state)\n incumbent_state = replace(state, own_orders=tuple(state.own_orders))\n actions = list(self._n.on_step(incumbent_state))\n if not enabled or self._cut_steps <= 0:\n return actions\n existing = [o for o in state.own_orders if self._cut(o)]\n cancelled = {a.order_id for a in actions if isinstance(a, CancelOrder)}\n has_cancel_all = any(isinstance(a, CancelAll) for a in actions)\n prefix = [] if has_cancel_all else [CancelOrder(o.order_id) for o in existing if o.order_id not in cancelled]\n kept = [a for a in actions if not isinstance(a, PlaceOrder) or not self._cut(a)]\n self._cut_steps -= 1\n return prefix + kept\n" }, { "key": "f-post-jump", "spread": "1", "code": "import dataclasses as _dc\nfrom orderbook_pm_challenge.types import PlaceOrder as _PO, Side as _Sd\n\n\nclass Strategy(BaseStrategy):\n ACT = (1, 2)\n M = 4\n JUMP = 2.0\n ON = True\n\n def __init__(self, *a, **k):\n super().__init__(*a, **k)\n self._n = _N(*a, **k)\n self._s = None\n self._pm = None\n self._dis = 0\n self._lo = 0\n self._hi = 0\n self._dir = 0\n self._pd = 0.05\n\n def on_step(self, state):\n acts = self._n.on_step(state)\n b, a = state.competitor_best_bid_ticks, state.competitor_best_ask_ticks\n if self._s is None and b is not None and a is not None:\n self._s = max(1, (a - b + 1) // 2)\n if not self.ON or self._s not in self.ACT or b is None or a is None:\n return acts\n mid = (a + b) / 2.0\n pm = self._pm\n self._pm = mid\n if pm is None:\n return acts\n mv = mid - pm\n fb, fs = state.buy_filled_quantity, state.sell_filled_quantity\n # two-state filter: likelihood-ratio update on quote move and own fills\n ev = abs(mv) / self.JUMP + (0.5 if (fs > 0 and mv > 0) or (fb > 0 and mv < 0) else 0.0)\n p = self._pd\n lr = 2.718281828 ** (3.0 * (ev - 1.0))\n p = p * lr / (p * lr + (1 - p))\n self._pd = min(0.95, max(0.01, 0.9 * p + 0.01))\n if p > 0.5 and abs(mv) >= 1:\n self._dis = self.M\n self._dir = 1 if mv > 0 else -1\n self._lo = min(pm, mid)\n self._hi = max(pm, mid)\n elif self._dis > 0:\n if abs(mv) >= 1 and (mv > 0) == (self._dir > 0):\n self._lo = min(self._lo, mid)\n self._hi = max(self._hi, mid)\n self._dis = self.M\n else:\n self._dis -= 1\n if self._dis <= 0:\n return acts\n out = []\n for x in acts:\n if isinstance(x, _PO):\n pr = x.price_ticks\n if self._dir > 0 and x.side == _Sd.SELL and pr <= self._hi + self._s:\n continue\n if self._dir < 0 and x.side == _Sd.BUY and pr >= self._lo - self._s:\n continue\n out.append(x)\n return out\n" }, { "key": "f-cp-filter", "spread": "1", "code": "import math as _cp_math\nimport bisect as _cp_bisect\nfrom orderbook_pm_challenge.types import PlaceOrder as _CPPlace, CancelOrder as _CPCancel, CancelAll as _CPAll, Side as _CPSide\n\n# Fixed latent grid, with exact Poisson-Gaussian mixture probabilities at\n# bin boundaries. Unknown jump parameters use ParameterVariance midpoints.\n_CP_DX = 0.025\n_CP_ZERO = 320\n_CP_SIZE = 641\n_CP_MAP = {}\n_CP_KERNEL = None\n\ndef _cp_weights(lam):\n w = _cp_math.exp(-lam)\n out = [w]\n total = w\n n = 0\n while 1.0 - total > 1e-12:\n n += 1\n w *= lam / n\n out.append(w)\n total += w\n return [v / total for v in out]\n\ndef _cp_cdf(x):\n return 0.5 * (1.0 + _cp_math.erf(x / _cp_math.sqrt(2.0)))\n\ndef _cp_mapping(h):\n if h not in _CP_MAP:\n weights = _cp_weights(0.0019 * h)\n scales = [1.0 / _cp_math.sqrt(h * 0.0004 + n * 0.16) for n in range(len(weights))]\n values = []\n for i in range(_CP_SIZE):\n z = (i - _CP_ZERO) * _CP_DX\n values.append(sum(w * _cp_cdf(z * a) for w, a in zip(weights, scales)))\n _CP_MAP[h] = values\n return _CP_MAP[h]\n\ndef _cp_kernel():\n global _CP_KERNEL\n if _CP_KERNEL is None:\n weights = _cp_weights(0.0019)\n scales = [1.0 / _cp_math.sqrt(0.0004 + n * 0.16) for n in range(len(weights))]\n _CP_KERNEL = [sum(w * (_cp_cdf((d + 0.5) * _CP_DX * a) - _cp_cdf((d - 0.5) * _CP_DX * a)) for w, a in zip(weights, scales)) for d in range(_CP_SIZE)]\n return _CP_KERNEL\n\nclass Strategy(_N):\n # Set selected using tuning seeds only. Empty tuple disables the overlay.\n SPREADS = (1,)\n MARGIN_TICKS = 0.5\n\n def __init__(self):\n self._n = _N()\n self._spread = None\n self._post = None\n self._lo = 0\n\n def _estimate(self, state):\n pmap = _cp_mapping(state.steps_remaining)\n bid = state.competitor_best_bid_ticks\n ask = state.competitor_best_ask_ticks\n lower = 0.0 if bid is None else bid / 100.0\n upper = 1.0 if ask is None else ask / 100.0\n # Include grid cells intersecting the quote interval, to avoid\n # empty support when the latent interval is narrower than a bin.\n lo = max(0, _cp_bisect.bisect_left(pmap, lower) - 1)\n hi = min(_CP_SIZE - 1, _cp_bisect.bisect_right(pmap, upper))\n if hi < lo:\n lo, hi = hi, lo\n kernel = _cp_kernel()\n if self._post is None:\n prior = [1.0 if abs((j - _CP_ZERO) * _CP_DX) <= 0.75 else 0.0 for j in range(lo, hi + 1)]\n else:\n old = self._post\n oldlo = self._lo\n prior = [sum(v * kernel[abs(j - oldlo - k)] for k, v in enumerate(old)) for j in range(lo, hi + 1)]\n # Uniform within-bin observation likelihood, with fractional cells.\n for k, j in enumerate(range(lo, hi + 1)):\n left = 0.0 if j == 0 else (pmap[j - 1] + pmap[j]) * 0.5\n right = 1.0 if j == _CP_SIZE - 1 else (pmap[j] + pmap[j + 1]) * 0.5\n prior[k] *= max(0.0, min(upper, right) - max(lower, left)) / max(1e-15, right - left)\n total = sum(prior)\n if total <= 1e-200:\n prior = [1.0] * (hi - lo + 1)\n total = len(prior)\n self._post = [v / total for v in prior]\n self._lo = lo\n return 100.0 * sum(v * pmap[lo + k] for k, v in enumerate(self._post))\n\n def on_step(self, state):\n actions = self._n.on_step(state)\n if self._spread is None:\n bid = state.competitor_best_bid_ticks\n ask = state.competitor_best_ask_ticks\n self._spread = max(1, (ask - bid + 1) // 2) if bid is not None and ask is not None else 0\n if self._spread not in self.SPREADS:\n return actions\n mean = self._estimate(state)\n margin = self.MARGIN_TICKS\n def wrong(side, price):\n return price > mean + margin if side == _CPSide.BUY else price < mean - margin\n kept = [a for a in actions if not isinstance(a, _CPPlace) or not wrong(a.side, a.price_ticks)]\n if not any(isinstance(a, _CPAll) for a in kept):\n canceled = {a.order_id for a in kept if isinstance(a, _CPCancel)}\n extra = [_CPCancel(o.order_id) for o in state.own_orders if o.order_id not in canceled and wrong(o.side, o.price_ticks)]\n kept = extra + kept\n return kept\n" } ] } ```