{
  "key": "f-step-inside",
  "approach": "Antithetic posterior loss integration over a public-quote-history Gaussian approximation to p. A softened competitor-quote interval updates posterior moments; large midpoint changes update a shrunk jump-rate estimate. Three symmetric posterior nodes, three antithetic diffusion nodes, and three antithetic one-jump nodes approximate the next probability distribution. Compare quantity times expected adverse-selection loss with estimated retail priority edge after better-priced own liquidity, using prior-mean retail parameters and six symmetric lognormal nodes. Move up to 25% (maximum 6 shares) of each side's best N order to one tick inside the competitor when estimated retail edge exceeds 1.25 times loss. Orders added by the overlay expire after one step and are hidden from N with dataclasses.replace. The conservative all-asks-uncovered cash bound can veto moves. This is an approximate posterior/integration model, not access to latent p or sampled parameters.",
  "tried": {
    "incumbent_artifact_url": "https://api.imdnotdead.fun/artifacts/db22aff7167a4798251ed3d20432509f30e511e4958799aba5b17b41bb39b4b6",
    "incumbent_source_quote_note": "Only the code field name is quoted in sources.json to preserve the blind-source rule; its UTF-8 payload was verified by SHA-256 without inspection.",
    "incumbent_code_sha256": "bf0d179f3e47d28819f6fa7e0d25548c2ced43374c216d36460b00a26a26ffae",
    "incumbent_seed_310000_edge": 17.1160017503,
    "incumbent_check_matches_17_116002": true,
    "scoreboard": [
      {
        "candidate": "v1 strictly more aggressive than N",
        "code_sha256": "75ab8c294286b9e46e5e04057e95ae25947fa0cf7fdcfdbe36f289022f029e1b",
        "tuning_first_seed": 310000,
        "tuning_last_seed": 310017,
        "complete_tuning_range": false,
        "n": 18,
        "mean_diff": 0.0,
        "se": 0.0,
        "sum_d": 0.0,
        "sum_d2": 0.0,
        "incumbent_mean": 66.96483026137778,
        "retail_diff": 0.0,
        "arb_diff": 0.0,
        "reason_stopped": "No changes. Black-box action audit showed N usually already quoted more aggressively than the target."
      },
      {
        "candidate": "v2 target relocation in either direction, account for better-priced own queue",
        "code_sha256": "8c0812c85fac9b2df9002f10c6dfcb8d1cc72b8df2f3ace2aceb1ea636d419be",
        "tuning_first_seed": 310000,
        "tuning_last_seed": 310199,
        "all": {
          "n": 200,
          "mean_diff": 0.0006398837305000171,
          "se": 0.0006011241195053529,
          "sum_d": 0.12797674610000342,
          "sum_d2": 0.014463628478344938,
          "incumbent_mean": 85.162653165042,
          "retail_diff": 0.0,
          "arb_diff": 0.0006398837305000171
        },
        "by_spread": {
          "1": {
            "n": 47,
            "mean_diff": 0.0,
            "se": 0.0,
            "sum_d": 0.0,
            "sum_d2": 0.0,
            "incumbent_mean": 30.59600304578298,
            "retail_diff": 0.0,
            "arb_diff": 0.0
          },
          "2": {
            "n": 57,
            "mean_diff": 0.002245206071929885,
            "se": 0.002107414282851434,
            "sum_d": 0.12797674610000342,
            "sum_d2": 0.014463628478344938,
            "incumbent_mean": 81.35713208259824,
            "retail_diff": 0.0,
            "arb_diff": 0.002245206071929885
          },
          "3": {
            "n": 53,
            "mean_diff": 0.0,
            "se": 0.0,
            "sum_d": 0.0,
            "sum_d2": 0.0,
            "incumbent_mean": 115.06691980369057,
            "retail_diff": 0.0,
            "arb_diff": 0.0
          },
          "4": {
            "n": 43,
            "mean_diff": 0.0,
            "se": 0.0,
            "sum_d": 0.0,
            "sum_d2": 0.0,
            "incumbent_mean": 112.9910514314628,
            "retail_diff": 0.0,
            "arb_diff": 0.0
          }
        }
      }
    ],
    "spread_selection": "Freeze the spreads with positive tuning mean difference; if none, retain all four. No holdout-based changes.",
    "frozen_spreads": [
      2
    ],
    "off_verification": {
      "n": 10,
      "seeds": [
        310000,
        310001,
        310002,
        310003,
        310004,
        310005,
        310006,
        310007,
        310008,
        310009
      ],
      "equal": "Full SimulationResult and SHA-256 of every public state/action trace."
    },
    "assembly_verification": {
      "n": 5,
      "seeds": [
        310041,
        310093,
        310000,
        310001,
        310002
      ],
      "equal": "Full SimulationResult and SHA-256 of every public state/action trace."
    },
    "controlled_checks": "Synthetic profitable state splits both sides to the target; next step expires/hides overlay orders; disabled and excluded-spread branches return N actions unchanged.",
    "holdout_overlay_orders": 12,
    "holdout_seeds_with_overlay_orders": 9,
    "measurement": "Pinned unmodified simulator; default ChallengeConfig and ParameterVariance, 2000 steps; serial in-process engine calls; no workers or sandbox. Tuning and holdout disjoint. Finalist seeds 900000..903999 never run. N loaded, hashed and mechanically assembled without source inspection.",
    "limitations": "Gaussian terminal-probability approximation, moment closure, one-jump truncation, sparse quadrature, prior retail parameters and conservative collateral accounting may miss rare profitable orders. Equal-price own queue and retail-flow feedback are not fully modeled. No finalist promotion is asserted."
  },
  "next": "Keep N as incumbent unless separate authorized finalist measurement establishes a gain above twice its standard error. This overlay must not be promoted from this holdout alone. Investigate rare activation and queue/collateral estimation in a separate item; do not retune on these holdout seeds.",
  "spreads_acted": [
    2
  ],
  "off_equals_n": true,
  "code": "# Antithetic posterior integration; only public StepState history is used.\nimport math as _fsi_math\nfrom statistics import NormalDist as _FsiNormal\nfrom dataclasses import replace as _fsi_replace\nfrom orderbook_pm_challenge.types import PlaceOrder as _FsiPlace, CancelOrder as _FsiCancel, CancelAll as _FsiAll, Side as _FsiSide\n\nclass Strategy(BaseStrategy):\n    SPREADS = (2,)\n    ENABLED = True\n    FRACTION = 0.25\n    CAP = 6.0\n    HURDLE = 1.25\n    _prefix = 'fsi-antithetic-'\n\n    def __init__(self):\n        self._n = _N()\n        self._spread = None\n        self._mean = 0.5\n        self._var = 0.0001\n        self._prev_mid = None\n        self._jump_rate = 0.0019\n        self._ticks = 0\n        self._jumps = 0\n        self._normal = _FsiNormal()\n        self._nodes = ((0.0, 2.0/3.0), (-1.7320508075688772, 1.0/6.0), (1.7320508075688772, 1.0/6.0))\n\n    def _posterior(self, state):\n        b, a = state.competitor_best_bid_ticks, state.competitor_best_ask_ticks\n        lo = (b or 0) / 100.0\n        hi = (a if a is not None else 100) / 100.0\n        mid = (lo + hi) * 0.5\n        horizon = max(1, state.steps_remaining)\n        tau = _fsi_math.sqrt(horizon * (0.0004 + self._jump_rate * 0.17333333333333334))\n        p = min(0.99999, max(0.00001, self._mean))\n        z = self._normal.inv_cdf(p)\n        dp = 0.02 * _fsi_math.exp(-0.5*z*z) / (_fsi_math.sqrt(2*_fsi_math.pi)*tau)\n        if self._prev_mid is None:\n            # The initial ladder brackets p within one tick after removing s-1.\n            lo = min(hi, lo + (self._spread-1)/100.0)\n            hi = max(lo, hi - (self._spread-1)/100.0)\n            self._mean = (lo+hi)/2.0\n            self._var = max(1e-7, (hi-lo)**2/12.0)\n        else:\n            self._ticks += 1\n            change = abs(mid-self._prev_mid)\n            if change > max(0.035, 6.0*dp):\n                self._jumps += 1\n            self._jump_rate = min(0.003, max(0.0008, (1.9+self._jumps)/(1000.0+self._ticks)))\n            v = self._var + dp*dp\n            sd = _fsi_math.sqrt(max(v, 1e-9))\n            # Retail can also remove competitor quotes: soften the interval.\n            lower, upper = max(0.0,lo-0.0025), min(1.0,hi+0.0025)\n            al, be = (lower-self._mean)/sd, (upper-self._mean)/sd\n            mass = self._normal.cdf(be)-self._normal.cdf(al)\n            if mass < 1e-6:\n                self._mean = min(upper,max(lower,self._mean))\n                self._var = max(dp*dp, min(0.0001,(upper-lower)**2/12.0))\n            else:\n                pa = _fsi_math.exp(-0.5*al*al)/_fsi_math.sqrt(2*_fsi_math.pi)\n                pb = _fsi_math.exp(-0.5*be*be)/_fsi_math.sqrt(2*_fsi_math.pi)\n                delta = (pa-pb)/mass\n                self._mean += sd*delta\n                self._var = max(1e-8, v*(1.0+(al*pa-be*pb)/mass-delta*delta))\n        self._prev_mid = mid\n        self._mean = min(0.99999,max(0.00001,self._mean))\n        return tau\n\n    def _predict(self, state, tau):\n        # Posterior, diffusion and jump nodes each come in antithetic pairs.\n        horizon = max(1,state.steps_remaining)\n        next_tau = tau*_fsi_math.sqrt(max(0.5,horizon-1)/horizon)\n        sd = _fsi_math.sqrt(self._var)\n        lam = self._jump_rate\n        points = []\n        for u, wu in self._nodes:\n            p = min(0.99999,max(0.00001,self._mean+u*sd))\n            score = self._normal.inv_cdf(p)*tau\n            for d, wd in self._nodes:\n                x = score+0.02*d\n                points.append((self._normal.cdf(x/next_tau),wu*wd*(1-lam)))\n                for j, wj in self._nodes:\n                    points.append((self._normal.cdf((x+_fsi_math.sqrt(0.17333333333333334)*j)/next_tau),wu*wd*lam*wj))\n        return points\n\n    def _worth(self, side, tick, quantity, points, ahead):\n        price = tick/100.0\n        loss = retail = 0.0\n        # Mean retail parameters under the stated randomization prior.\n        # Six antithetic lognormal nodes integrate priority fill quantity.\n        flow = ((-1.382994,1/6),(-0.674490,1/6),(-0.210428,1/6),\n                (0.210428,1/6),(0.674490,1/6),(1.382994,1/6))\n        notionals = [(_fsi_math.exp(_fsi_math.log(4.488)-0.72+1.2*z),w) for z,w in flow]\n        for p,w in points:\n            margin = p-price if side == _FsiSide.BUY else price-p\n            if margin < 0:\n                loss -= w*quantity*margin\n            else:\n                denom = max(p,0.05) if side == _FsiSide.BUY else price\n                filled = sum(v*min(quantity,max(0.0,n/denom-ahead)) for n,v in notionals)\n                retail += w*0.1265*filled*margin\n        return retail > self.HURDLE*loss and retail > 1e-7\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 a is not None and b 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        hidden = tuple(o for o in state.own_orders if o.order_id.startswith(self._prefix))\n        visible = tuple(o for o in state.own_orders if not o.order_id.startswith(self._prefix))\n        clean = _fsi_replace(state,own_orders=visible)\n        actions = list(self._n.on_step(clean))\n        expiry = [_FsiCancel(o.order_id) for o in hidden]\n        tau = self._posterior(state)\n        # Project N's surviving book, keeping original action locations.\n        book = {o.order_id:(o.side,o.price_ticks,o.remaining_quantity,None,o.order_id) for o in visible}\n        for i,act in enumerate(actions):\n            if isinstance(act,_FsiAll):\n                book.clear()\n            elif isinstance(act,_FsiCancel):\n                book.pop(act.order_id,None)\n            elif isinstance(act,_FsiPlace):\n                book[act.client_order_id or ('new',i)] = (act.side,act.price_ticks,act.quantity,i,act.client_order_id)\n        points = None\n        extras = []\n        original_actions = list(actions)\n        for side in (_FsiSide.BUY,_FsiSide.SELL):\n            candidates = [(k,v) for k,v in book.items() if v[0] == side]\n            if not candidates:\n                continue\n            key,entry = (max(candidates,key=lambda kv:kv[1][1]) if side == _FsiSide.BUY else min(candidates,key=lambda kv:kv[1][1]))\n            _,old,q,index,oid = entry\n            bid,ask = state.competitor_best_bid_ticks,state.competitor_best_ask_ticks\n            target = (bid+1 if bid is not None else 0) if side == _FsiSide.BUY else (ask-1 if ask is not None else 100)\n            if not 1 <= target <= 99:\n                continue\n            if side == _FsiSide.BUY:\n                if target == old or (ask is not None and target >= ask):\n                    continue\n            elif target == old or (bid is not None and target <= bid):\n                continue\n            part = _fsi_math.floor(min(self.CAP,q*self.FRACTION)*100)/100.0\n            if part < 0.01 or q-part < 0.01:\n                continue\n            if points is None:\n                points = self._predict(state,tau)\n            ahead = sum(v[2] for v in book.values() if v[0] == side and ((v[1] > target) if side == _FsiSide.BUY else (v[1] < target)))\n            if (old > target if side == _FsiSide.BUY else old < target):\n                ahead = max(0.0,ahead-part)\n            if not self._worth(side,target,part,points,ahead):\n                continue\n            rest = _fsi_math.floor((q-part+1e-9)*100)/100.0\n            if index is None:\n                extras.extend((_FsiCancel(oid),_FsiPlace(side,old,rest,oid)))\n            else:\n                actions[index] = _fsi_replace(actions[index],quantity=rest)\n            new_id = self._prefix+str(state.step)+'-'+side.value\n            extras.append(_FsiPlace(side,target,part,new_id))\n            book[key] = (side,old,rest,index,oid)\n            book[new_id] = (side,target,part,None,new_id)\n        if not extras:\n            return expiry+actions\n        # All-sells-uncovered is a conservative collateral bound. Initial N\n        # actions only shrink; the added orders are placed after those actions.\n        worst = sum((p/100 if side == _FsiSide.BUY else 1-p/100)*q for side,p,q,_,_ in book.values())\n        if worst > state.cash-0.02:\n            return expiry+original_actions\n        return expiry+actions+extras\n",
  "code_sha256": "706c66ded92f9ed83a8e68a67b95a07f32f2553c77337f29b760bb3189798b4c",
  "assembled_sha256": "2fabfee2a8a44bdc34ad4e1c65379df7c4b9fdaf93c431f27710ead9d79624c8",
  "tuning": {
    "n": 200,
    "mean_diff": 0.0006398837305000171,
    "se": 0.0006011241195053529
  },
  "paired": {
    "first_seed": 410000,
    "last_seed": 410499,
    "n": 500,
    "complete": true,
    "incumbent_mean": 104.4137531881468,
    "mean_diff": 0.0008917695677999547,
    "se": 0.00035265207303674886,
    "sum_d": 0.4458847838999773,
    "sum_d2": 0.031426315892997624,
    "retail_diff": 0.0,
    "arb_diff": 0.0008917695678000009,
    "failures": []
  },
  "by_spread": {
    "1": {
      "runs": 115,
      "mean_diff": 0.0,
      "se": 0.0,
      "sum_d": 0.0,
      "sum_d2": 0.0,
      "incumbent_mean": 28.495154459731303,
      "retail_diff": 0.0,
      "arb_diff": 0.0
    },
    "2": {
      "runs": 116,
      "mean_diff": 0.003843834343965322,
      "se": 0.001492419843758561,
      "sum_d": 0.4458847838999773,
      "sum_d2": 0.031426315892997624,
      "incumbent_mean": 97.76626247947759,
      "retail_diff": 0.0,
      "arb_diff": 0.003843834343965521
    },
    "3": {
      "runs": 138,
      "mean_diff": 0.0,
      "se": 0.0,
      "sum_d": 0.0,
      "sum_d2": 0.0,
      "incumbent_mean": 128.4054514027384,
      "retail_diff": 0.0,
      "arb_diff": 0.0
    },
    "4": {
      "runs": 131,
      "mean_diff": 0.0,
      "se": 0.0,
      "sum_d": 0.0,
      "sum_d2": 0.0,
      "incumbent_mean": 151.67248160310686,
      "retail_diff": 0.0,
      "arb_diff": 0.0
    }
  },
  "seconds_per_simulation": 1.413915802154108
}
