{"key":"f-jump-scale","approach":"Blind wrapper over N: infer large score moves from consecutive competitor-quote midpoints, update a jump-sigma-squared posterior with a uniform ParameterVariance-range prior, then for one callback cancel/suppress incumbent orders within a posterior-scaled tick distance of the observed midpoint. Frozen after tuning to competitor spreads 2 and 3.","tried":"Two tuning variants on seeds 310000-310199 only: all spreads with cut scales 0.20 and 0.10. The 0.10 variant was frozen; its spread-2/3 evidence selected active spreads [2,3].","next":"The 500-seed holdout gain is 0.211998003494 with SE 0.105824883903, narrowly above twice its SE; replicate it before any promotion decision.","spreads_acted":[2,3],"off_equals_n":true,"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","code_sha256":"19aa0a454387c70ec599aacc8376ad9f6f128da3e15f380eea67b85798c0ebf6","assembled_sha256":"499530021c3f72e8da491724f289913282998f1a183036e4ca65bfa1d3ccd86f","tuning":{"n":200,"mean_diff":0.03221736027700006,"se":0.10853236226713701},"paired":{"first_seed":410000,"last_seed":410499,"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,"incumbent_mean":28.495154459731307,"mean_diff":0.0,"se":0.0,"sum_d":0.0,"sum_d2":0.0,"retail_diff":0.0,"arb_diff":0.0},"2":{"runs":116,"incumbent_mean":97.76626247947758,"mean_diff":0.2407281207568967,"se":0.218532827025179,"sum_d":27.924462007800017,"sum_d2":643.7952004070933,"retail_diff":-0.20481360496551757,"arb_diff":0.4455417257232758},"3":{"runs":138,"incumbent_mean":128.4054514027384,"mean_diff":0.5657575343420278,"se":0.3355447782120479,"sum_d":78.07453973919984,"sum_d2":2172.80343659039,"retail_diff":0.45857223341956543,"arb_diff":0.10718530091159438},"4":{"runs":131,"incumbent_mean":151.67248160310686,"mean_diff":0.0,"se":0.0,"sum_d":0.0,"sum_d2":0.0,"retail_diff":0.0,"arb_diff":0.0}},"seconds_per_simulation":0.5946321126990951}
