{
 "key": "f-boundary",
 "approach": "Absorbing-boundary overlay on N (owns one _N instance; hidden orders and their fills are removed from N's StepState via dataclasses.replace). In the boundary zone (ticks 1-5 / 95-99): in the last 100 steps, where p is absorbed fastest, drop N's bids at 2-5c (mirror: asks at 95-98c), the side that can then only be swept. Add hidden size equal to N's size behind N's asks at 1-5c (mirror: bids at 95-99c), the side that mostly meets retail buys of notional/price shares. No added size in the last 20 steps. Added size may lock at most 50% of the spare free cash, computed with worst-case YES coverage, and all added orders are cancelled first whenever N's own placements might not fit. Acts only when the first-step competitor spread s is in {2}.",
 "tried": [
  "Diagnostic of N on tuning seeds 310000-310199 (fills wrapped in the simulator, N's source not read): fills at <=5c are about 55 of N's 85.16 mean edge. 1-5c asks earn +62.9/run from retail; 1c bids lose -3.1/run to the arb against +0.9 from retail; N's low asks are used up by the retail buy in 59-83% of hits (by tick, seeds 310000-310099).",
  "Variant A (tuning 310000-310199): always drop 1c bids (and 99c asks), drop 2-5c bids in the last 100 steps, add 1x hidden ask size at 1-5c using all spare cash. Paired vs N: -32.21 +/- 6.30 (n=200; retail -32.84, arb +0.63). Cause: N's 1c bids, swept by the arb at under 1c loss, are its cheap YES supply. That YES covers its big retail asks at 2-3c without cash (seed 310098: N 623.5, A 110.1). A first build also failed one run (310007) when a hidden ask took YES coverage N relied on; fixed by the cancel-first guard.",
  "Variant B (tuning 310000-310199): keep 1c bids, late drop of 2-5c bids only, hidden size capped at 50% of spare cash. All spreads: -3.36 +/- 2.16. By spread: s1 -3.05 +/- 2.00 (47), s2 +1.12 +/- 1.25 (57), s3 -9.60 +/- 7.69 (53), s4 -1.92 +/- 1.83 (43). Spread set frozen to {2}.",
  "Holdout 410000-410499, once, B with spreads {2}: -1.77 +/- 1.11 overall, -7.61 +/- 4.77 on the 116 spread-2 runs. The tuning gain did not replicate; the overlay does not beat N."
 ],
 "next": "Do not promote. The low-boundary edge in N comes from a loop: buy YES from the arb at 1c, then sell it to retail at 2-5c as covered asks. The limit is YES inventory and cash, not order size, so extra uncovered size mostly ties up collateral and gets swept on up-jumps (arb diff -1.93/run on holdout). A better boundary overlay would add to the inventory loop: bid more at 1c when p is clearly below 2c, so more YES covers retail asks. Keep added size out of N's FIFO slot and test it per spread on more seeds. Dropping 1c bids is clearly harmful (-32/run).",
 "spreads_acted": [
  2
 ],
 "off_equals_n": true,
 "code": "# f-boundary overlay: absorbing-boundary filter over the incumbent _N.\n# Near 0 (ticks 1..5) p is clipped: a bid there is mostly swept by the arb as p\n# is absorbed toward 0, an ask there mostly meets retail buys (notional/price,\n# so large share counts). Mirror at 95..99. Overlay: drop the swept side,\n# add hidden size behind N's retail-only side.\nimport dataclasses as _dc\nfrom orderbook_pm_challenge.types import CancelAll, CancelOrder, PlaceOrder, Side\n\nFB_SPREADS = {2}\nFB_MULT = 2.0     # total size multiple on the retail-only side\nFB_EDGE = 5       # boundary zone: ticks 1..FB_EDGE and 100-FB_EDGE..99\nFB_LATE = 100     # in the last FB_LATE steps every boundary order on the swept side is dropped\nFB_NOENL = 20     # no added size in the last FB_NOENL steps\nFB_CASH = 0.5     # share of spare free cash the added size may lock\n\n\nclass Strategy:\n    def __init__(self):\n        self._n = _N()\n        self._on = None\n        self._x = {}      # hidden id -> [side, tick, last remaining]\n        self._k = 0\n\n    def _drop(self, side, k, H):\n        # 1c bids / 99c asks are kept: swept there at <1c loss, they load the\n        # inventory that covers the retail-only side without cash.\n        if H > FB_LATE:\n            return False\n        if side is Side.BUY:\n            return 1 < k <= FB_EDGE\n        return 100 - FB_EDGE <= k < 99\n\n    def on_step(self, state):\n        if self._on is None:\n            b, a = state.competitor_best_bid_ticks, state.competitor_best_ask_ticks\n            s = None if (b is None or a is None) else max(1, (a - b + 1) // 2)\n            self._on = s in FB_SPREADS\n        if not self._on:\n            return self._n.on_step(state)\n        H = state.steps_remaining\n        live = {o.order_id: o for o in state.own_orders}\n        bf, sf = state.buy_filled_quantity, state.sell_filled_quantity\n        for oid, v in list(self._x.items()):\n            o = live.get(oid)\n            rem = o.remaining_quantity if o is not None else 0.0\n            if v[0] is Side.BUY:\n                bf -= v[2] - rem\n            else:\n                sf -= v[2] - rem\n            if o is None:\n                del self._x[oid]\n            else:\n                v[2] = rem\n        vis = tuple(o for o in state.own_orders if o.order_id not in self._x)\n        st = _dc.replace(state, own_orders=vis,\n                         buy_filled_quantity=max(0.0, round(bf, 10)),\n                         sell_filled_quantity=max(0.0, round(sf, 10)))\n        acts = list(self._n.on_step(st))\n        vid = {o.order_id for o in vis}\n        out, post, pre = [], [], []\n        cancelled, placed = set(), set()\n        call = False\n        book = {o.order_id: (o.side, o.price_ticks, o.remaining_quantity) for o in vis}\n        cost, j = 0.0, 0\n        # worst-case collateral of N's placements: YES coverage only beyond every live ask\n        av = state.yes_inventory - sum(o.remaining_quantity for o in state.own_orders if o.side is Side.SELL)\n        for a in acts:\n            if isinstance(a, PlaceOrder) and not self._drop(a.side, a.price_ticks, H):\n                p = a.price_ticks / 100.0\n                if a.side is Side.BUY:\n                    cost += p * a.quantity\n                else:\n                    cv = min(a.quantity, max(0.0, av))\n                    av -= cv\n                    cost += (1.0 - p) * (a.quantity - cv)\n        if self._x and cost > state.free_cash - 0.05:\n            pre = [CancelOrder(i) for i in self._x]\n            self._x = {}\n        for a in acts:\n            if isinstance(a, CancelAll):\n                call = True\n                book = {}\n                self._x = {}\n                out.append(a)\n            elif isinstance(a, CancelOrder):\n                i = a.order_id\n                if i in placed or (i in vid and i not in cancelled):\n                    cancelled.add(i)\n                    placed.discard(i)\n                    book.pop(i, None)\n                    out.append(a)\n            elif isinstance(a, PlaceOrder):\n                i = a.client_order_id\n                if self._drop(a.side, a.price_ticks, H):\n                    continue\n                j += 1\n                book[i or (\"\\0%d\" % j)] = (a.side, a.price_ticks, a.quantity)\n                if i:\n                    placed.add(i)\n                out.append(a)\n            else:\n                out.append(a)\n        if not call:\n            for o in vis:\n                if o.order_id not in cancelled and self._drop(o.side, o.price_ticks, H):\n                    post.append(CancelOrder(o.order_id))\n                    book.pop(o.order_id, None)\n        want = {}\n        if H > FB_NOENL and FB_MULT > 1.0:\n            for side, k, q in book.values():\n                if (side is Side.SELL and k <= FB_EDGE) or (side is Side.BUY and k >= 100 - FB_EDGE):\n                    want[(side, k)] = want.get((side, k), 0.0) + (FB_MULT - 1.0) * q\n        have = {}\n        for oid, v in list(self._x.items()):\n            key = (v[0], v[1])\n            if key not in want or have.get(key, 0.0) + v[2] > 1.5 * want[key]:\n                post.append(CancelOrder(oid))\n                del self._x[oid]\n            else:\n                have[key] = have.get(key, 0.0) + v[2]\n        budget = FB_CASH * (state.free_cash - cost - 0.05)\n        for (side, k), q in sorted(want.items(), key=lambda t: t[0][1]):\n            unit = k / 100.0 if side is Side.BUY else 1.0 - k / 100.0\n            extra = min(q - have.get((side, k), 0.0), max(0.0, budget) / unit)\n            extra = int(extra * 100) / 100.0\n            if extra < 0.5:\n                continue\n            budget -= extra * unit\n            self._k += 1\n            oid = \"_fb_%d\" % self._k\n            self._x[oid] = [side, k, extra]\n            post.append(PlaceOrder(side, k, extra, oid))\n        return pre + out + post\n",
 "code_sha256": "4e5eeb89bf80374db02f4c99e8675bfb0a6b523284fb48816179e565175aa114",
 "assembled_sha256": "e79e0fce84fea5d735cd353bf8ac1b55d7c0ce392789cfdfbf635cca2109b743",
 "tuning": {
  "n": 200,
  "mean_diff": 0.318514,
  "se": 0.355087
 },
 "paired": {
  "first_seed": 410000,
  "last_seed": 410499,
  "n": 500,
  "complete": true,
  "incumbent_mean": 104.413753,
  "mean_diff": -1.765506,
  "se": 1.112315,
  "sum_d": -882.752798,
  "sum_d2": 310251.037534,
  "retail_diff": 0.165674,
  "arb_diff": -1.93118,
  "failures": 0
 },
 "by_spread": {
  "1": {
   "runs": 115,
   "incumbent_mean": 28.495154,
   "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.766262,
   "mean_diff": -7.609938,
   "se": 4.770076,
   "sum_d": -882.752798,
   "sum_d2": 310251.037534,
   "retail_diff": 0.714113,
   "arb_diff": -8.324051
  },
  "3": {
   "runs": 138,
   "incumbent_mean": 128.405451,
   "mean_diff": 0.0,
   "se": 0.0,
   "sum_d": 0.0,
   "sum_d2": 0.0,
   "retail_diff": 0.0,
   "arb_diff": 0.0
  },
  "4": {
   "runs": 131,
   "incumbent_mean": 151.672482,
   "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.3879
}