{
 "key": "f-fill-rate-size",
 "mech": "fill-rate adaptive size",
 "approach": "Overlay on N. Each step, own-fill notional (fill quantity times own best quote) enters a rolling 200-step sum; ratio = sum / (cumulative notional per step * 200) after a 400-step warmup. New quotes of at least 0.05 shares scale by clip(ratio, 0.6, 1.0); N's 0.01-share orders are never touched. Acts on s=2,3,4 only. A guard replays the book's collateral check from StepState and shrinks or drops orders that would raise, because resized resting orders made N's later orders fail without it. Screen result: null.",
 "tried": [
  "Two variants first, down-only A (0.6,1.0) and up-only B (1.0,1.6), all spreads, on the tuning seeds. Those first runs failed 7 of 200 (A) and 1 of 200 (B) simulations with 'Insufficient free cash for order collateral'; N failed none.",
  "Added the collateral guard and reran A and B on the same tuning seeds; failures went to 0. Reported variant numbers are the guarded reruns. Unguarded runs: A -0.65 (se 0.81), B -0.91 (se 0.30).",
  "Tuning read: up-sizing in high-fill windows buys arbitrage loss (B retail +0.62, arb -1.42); down-sizing in low-fill windows cuts arbitrage loss but costs retail, worst at s=1 (A retail -1.92, arb +0.40 there).",
  "Third variant C is A restricted to s=2,3,4, frozen on tuning (+0.66, se 0.53). Holdout gave +0.01, se 0.32: the tuning gain did not hold, and the s=4 tuning gain of +2.28 (se 1.98) came back -0.72 (se 0.61).",
  "Diagnostics only, on seeds 310000..310007: action counts by quantity, which showed the 0.01-share orders, and constant-scale churn runs. One smoke run of N and A on tuning seed 320025 outside the sweep files."
 ],
 "next": "Do not promote; drop this signal as a size scaler. On the holdout it trades retail for arbitrage about one for one (retail -0.42, arb +0.43). Retail arrival rate is fixed within a game, so my untested guess is that high-fill windows mostly reflect price moves and ladder position rather than better flow. The collateral guard is reusable by any overlay that resizes N's orders. Untested: lo below 0.6, and a per-side ratio.",
 "spreads_acted": [
  2,
  3,
  4
 ],
 "off_equals_n": true,
 "off_equals_n_detail": "ON=False: action lists equal to N's at all 2000 steps on each of seeds 310000..310009 (20000 steps), by repr of every action, with equal total edge.",
 "code": "from collections import deque as _deque\n\n\nclass Strategy(_N):\n    \"\"\"Fill-rate adaptive size: new quotes scale by clip(rolling/avg, LO, HI).\"\"\"\n    ON = True\n    LO = 0.6\n    HI = 1.0\n    SPREADS = (2, 3, 4)\n    WINDOW = 200\n    WARMUP = 400\n    MIN_Q = 0.05\n\n    def __init__(self):\n        super().__init__()\n        self._fr_win = _deque()\n        self._fr_sum = 0.0\n        self._fr_tot = 0.0\n        self._fr_bid = None\n        self._fr_ask = None\n        self._fr_touched = False\n\n    def _fr_scale(self, state):\n        n = 0.0\n        if self._fr_bid is not None:\n            n += state.buy_filled_quantity * self._fr_bid / 100.0\n        if self._fr_ask is not None:\n            n += state.sell_filled_quantity * self._fr_ask / 100.0\n        self._fr_tot += n\n        self._fr_sum += n\n        self._fr_win.append(n)\n        if len(self._fr_win) > self.WINDOW:\n            self._fr_sum -= self._fr_win.popleft()\n        t = state.step\n        if t < self.WARMUP or self._fr_tot <= 0.0:\n            return 1.0\n        ratio = max(self._fr_sum, 0.0) / (self._fr_tot / t * self.WINDOW)\n        return max(self.LO, min(self.HI, ratio))\n\n    def on_step(self, state):\n        actions = super().on_step(state)\n        if not self.ON:\n            return actions\n        k = self._fr_scale(state)\n        out = actions\n        if getattr(self, \"s\", None) in self.SPREADS:\n            if k != 1.0:\n                self._fr_touched = True\n                out = self._fr_resize(state, actions, k)\n            if self._fr_touched:\n                out = self._fr_guard(state, out)\n        self._fr_track(state, out)\n        return out\n\n    def _fr_guard(self, state, actions):\n        \"\"\"Replay the book's collateral check; shrink or drop what would raise.\"\"\"\n        live = {o.order_id: o for o in state.own_orders}\n        bids = sum(o.price_ticks / 100.0 * o.remaining_quantity\n                   for o in live.values() if o.side.value == \"BUY\")\n        sell_cash = max(0.0, state.reserved_cash - bids)\n        free = state.free_cash\n        held = 0.0\n        out = []\n        for a in actions:\n            name = type(a).__name__\n            if name == \"CancelOrder\":\n                o = live.pop(a.order_id, None)\n                if o is None:\n                    continue\n                if o.side.value == \"BUY\":\n                    free += o.price_ticks / 100.0 * o.remaining_quantity\n                else:\n                    kept = sum((1.0 - x.price_ticks / 100.0) * x.remaining_quantity\n                               for x in live.values() if x.side.value == \"SELL\")\n                    back = max(0.0, sell_cash - kept)\n                    free += back\n                    sell_cash -= back\n                out.append(a)\n            elif name == \"PlaceOrder\":\n                p = a.price_ticks / 100.0\n                room = max(0.0, free - 1e-6)\n                if a.side.value == \"BUY\":\n                    top = room / p\n                    avail = 0.0\n                else:\n                    resting = sum(x.remaining_quantity for x in live.values()\n                                  if x.side.value == \"SELL\")\n                    avail = max(0.0, state.yes_inventory - resting - held)\n                    top = avail + room / (1.0 - p)\n                q = a.quantity\n                if q > top:\n                    q = int(top * 100) / 100.0\n                    if q < 0.01:\n                        continue\n                    a = type(a)(side=a.side, price_ticks=a.price_ticks, quantity=q,\n                                client_order_id=a.client_order_id)\n                if a.side.value == \"BUY\":\n                    free -= p * q\n                else:\n                    cover = min(q, avail)\n                    held += cover\n                    free -= (1.0 - p) * (q - cover)\n                out.append(a)\n            else:\n                out.append(a)\n        return out\n\n    def _fr_resize(self, state, actions, k):\n        need = 0.0\n        for a in actions:\n            if type(a).__name__ == \"PlaceOrder\":\n                need += a.quantity * self._fr_unit(a)\n        room = max(0.0, state.free_cash - need)\n        out = []\n        for a in actions:\n            if type(a).__name__ != \"PlaceOrder\" or a.quantity < self.MIN_Q:\n                out.append(a)\n                continue\n            q = a.quantity * k\n            if q > a.quantity:\n                u = self._fr_unit(a)\n                extra = min(q - a.quantity, room / u) if u > 0 else 0.0\n                room -= extra * u\n                q = a.quantity + extra\n            q = int(q * 100 + 1e-9) / 100.0\n            if q < 0.01:\n                continue\n            out.append(type(a)(side=a.side, price_ticks=a.price_ticks, quantity=q,\n                               client_order_id=a.client_order_id))\n        return out\n\n    @staticmethod\n    def _fr_unit(a):\n        p = a.price_ticks / 100.0\n        return p if a.side.value == \"BUY\" else 1.0 - p\n\n    def _fr_track(self, state, actions):\n        gone = {a.order_id for a in actions if type(a).__name__ == \"CancelOrder\"}\n        bid = ask = None\n        for o in state.own_orders:\n            if o.order_id in gone:\n                continue\n            if o.side.value == \"BUY\":\n                bid = o.price_ticks if bid is None else max(bid, o.price_ticks)\n            else:\n                ask = o.price_ticks if ask is None else min(ask, o.price_ticks)\n        for a in actions:\n            if type(a).__name__ == \"PlaceOrder\":\n                if a.side.value == \"BUY\":\n                    bid = a.price_ticks if bid is None else max(bid, a.price_ticks)\n                else:\n                    ask = a.price_ticks if ask is None else min(ask, a.price_ticks)\n        self._fr_bid = bid\n        self._fr_ask = ask\n",
 "code_sha256": "2eed99754103e32ef765bb44910bc40c3635f990186de8cd700378ff3e03ac46",
 "assembled_sha256": "1a301bbc492851942816bde716632d97c882316b94f48b380e8eb1215a5406fd",
 "tuning": {
  "seeds": "320000..320199",
  "selected": "C",
  "selected_params": {
   "lo": 0.6,
   "hi": 1.0,
   "window": 200,
   "warmup": 400,
   "spreads": [
    2,
    3,
    4
   ]
  },
  "tuning_score": {
   "mean_diff": 0.6606159068884991,
   "se": 0.5298262415524924
  },
  "variants": [
   {
    "name": "A",
    "lo": 0.6,
    "hi": 1.0,
    "spreads": [
     1,
     2,
     3,
     4
    ],
    "n": 200,
    "mean_diff": 0.27964863764899894,
    "se": 0.6009169915760337,
    "retail_diff": -0.41746170045600045,
    "arb_diff": 0.6971103381249999,
    "by_spread_mean_diff": {
     "1": -1.5238690769580012,
     "2": 0.1564470886679986,
     "3": 0.12173801114791466,
     "4": 2.2780269694076924
    },
    "failures": 0
   },
   {
    "name": "B",
    "lo": 1.0,
    "hi": 1.6,
    "spreads": [
     1,
     2,
     3,
     4
    ],
    "n": 200,
    "mean_diff": -0.7957588123885002,
    "se": 0.2996461512739173,
    "retail_diff": 0.6197203922480011,
    "arb_diff": -1.4154792046,
    "by_spread_mean_diff": {
     "1": -1.5184115720799998,
     "2": -0.4960142948660001,
     "3": -1.060583632112501,
     "4": -0.14466259209615362
    },
    "failures": 0
   },
   {
    "name": "C",
    "lo": 0.6,
    "hi": 1.0,
    "spreads": [
     2,
     3,
     4
    ],
    "n": 200,
    "mean_diff": 0.6606159068884991,
    "se": 0.5298262415524924,
    "retail_diff": 0.06300114063149975,
    "arb_diff": 0.59761476627,
    "by_spread_mean_diff": {
     "1": 0.0,
     "2": 0.1564470886679986,
     "3": 0.12173801114791466,
     "4": 2.2780269694076924
    },
    "failures": 0
   }
  ]
 },
 "paired": {
  "seeds": "430000..430499",
  "n": 500,
  "complete": true,
  "missing_seeds": [],
  "overall": {
   "n": 500,
   "sum_d": 3.6039548935996937,
   "sum_d2": 25204.767812641334,
   "mean_diff": 0.0072079097871993875,
   "se": 0.31783802378154985,
   "incumbent_mean": 95.54201511346659,
   "candidate_mean": 95.5492230232538,
   "retail_diff": -0.4216279529919995,
   "arb_diff": 0.4288358627695998
  },
  "by_spread": {
   "1": {
    "n": 131,
    "sum_d": 0.0,
    "sum_d2": 0.0,
    "mean_diff": 0.0,
    "se": 0.0,
    "incumbent_mean": 38.277936657049615,
    "candidate_mean": 38.277936657049615,
    "retail_diff": 0.0,
    "arb_diff": 0.0
   },
   "2": {
    "n": 120,
    "sum_d": -9.219568894700073,
    "sum_d2": 593.1455418617153,
    "mean_diff": -0.07682974078916728,
    "se": 0.20368406715749726,
    "incumbent_mean": 77.8558643979175,
    "candidate_mean": 77.77903465712832,
    "retail_diff": -0.9636309508383315,
    "arb_diff": 0.8868012099974998
   },
   "3": {
    "n": 133,
    "sum_d": 95.91874633739992,
    "sum_d2": 19602.246329387068,
    "mean_diff": 0.72119358148421,
    "se": 1.0548057072466617,
    "incumbent_mean": 146.55140363646615,
    "candidate_mean": 147.27259721795036,
    "retail_diff": -0.6784684162353379,
    "arb_diff": 1.3996619977195484
   },
   "4": {
    "n": 116,
    "sum_d": -83.09522254910016,
    "sum_d2": 5009.375941392552,
    "mean_diff": -0.7163381254232772,
    "se": 0.6091414845780005,
    "incumbent_mean": 120.02204692465259,
    "candidate_mean": 119.30570879922931,
    "retail_diff": -0.04260312962155187,
    "arb_diff": -0.6737349957896556
   }
  }
 },
 "failures": {
  "holdout": 0,
  "holdout_detail": [],
  "tuning_frozen_variant": 0,
  "n_failures_tuning": 0,
  "note": "8 failures in the unguarded first tuning runs of A and B, fixed by the guard before freezing; see tried."
 },
 "check_values": {
  "310000": "17.116002",
  "310001": "20.017111",
  "310002": "2.390311",
  "310003": "241.484752"
 },
 "check_values_match": true,
 "python_version": "3.12.3",
 "seconds_per_simulation": 0.777,
 "n_sha256_verified": "bf0d179f3e47d28819f6fa7e0d25548c2ced43374c216d36460b00a26a26ffae",
 "screen_only": true
}