{
  "key": "f-retail-clock",
  "mech": "retail clock",
  "approach": "Blind overlay counts filled sides over the previous 100 steps (buy>0 plus sell>0), divides this rate by 0.253, the midpoint of the simulator randomization band [0.154,0.352], and clips to tuned size bounds. Warm up for 100 observations. Resize only N placements; retain prices and cancellation actions. Cap resized orders using a conservative collateral ledger through cancellations and placements. Own fill counts are a censored proxy and include arbitrage; actual retail arrivals are not observable.",
  "tried": [
    "Three bound settings: [0.9,1.1], [0.75,1.25], [0.5,1.5], on all four spreads.",
    "The initial pilot failed on wide bounds at seed 320001. A cancel-all-only guard later failed on mild bounds at seed 320196. The final repair caps every placement with a conservative action-by-action collateral ledger. Earlier revision observations are excluded from the final tuning table; cached N observations are reused.",
    "Selected the highest overall paired tuning mean; no spread gating or parameter changes after selection.",
    "Checked low/high-rate scaling and collateral clipping with synthetic StepStates and the simulator market."
  ],
  "next": "Keep N: this screen does not establish an improvement. Own fills mix retail and arbitrage and depend on quoting exposure; investigate an estimator that accounts for those limitations in a separately assigned item.",
  "spreads_acted": [
    1,
    2,
    3,
    4
  ],
  "off_equals_n": {
    "passed": true,
    "seeds": {
      "start": 310000,
      "end": 310009,
      "inclusive": true
    },
    "callbacks": 20000,
    "method": "One engine run per seed, forwarding each actual N state to separate N and disabled-overlay instances and asserting action equality every step. Disabled early-return path unchanged by both collateral repairs."
  },
  "code": "from collections import deque as _ClockDeque\nfrom dataclasses import replace as _clock_replace\nfrom orderbook_pm_challenge.types import PlaceOrder as _ClockPlace, CancelAll as _ClockCancelAll, CancelOrder as _ClockCancel, Side as _ClockSide\nfrom orderbook_pm_challenge.utils import quantize_down as _clock_floor\n\nclass Strategy(_N):\n    # Midpoint of the documented randomized retail arrival-rate band.\n    clock_prior = (0.154 + 0.352) / 2.0\n    clock_lo = 0.9\n    clock_hi = 1.1\n    clock_enabled = True\n    clock_spreads = (1, 2, 3, 4)\n\n    def on_step(self, state):\n        actions = super().on_step(state)\n        if not self.clock_enabled or self.s not in self.clock_spreads:\n            return actions\n        if not hasattr(self, '_retail_clock_fills'):\n            self._retail_clock_fills = _ClockDeque(maxlen=100)\n        if state.step > 0:\n            # Only aggregate side quantities are observable: count filled sides.\n            self._retail_clock_fills.append(\n                int(state.buy_filled_quantity > 0) +\n                int(state.sell_filled_quantity > 0))\n        if len(self._retail_clock_fills) < 100:\n            return actions\n        rate = sum(self._retail_clock_fills) / 100.0\n        scale = min(self.clock_hi, max(self.clock_lo, rate / self.clock_prior))\n        # Track a conservative collateral budget through the action sequence.\n        # Existing sell-order cash reservations are not exposed in StepState;\n        # individual cancellations therefore need not release their collateral.\n        # CancelAll restores the exact starting cash and inventory budget.\n        free = max(0.0, state.free_cash)\n        yes = max(0.0, state.yes_inventory - sum(\n            o.remaining_quantity for o in state.own_orders\n            if o.side == _ClockSide.SELL))\n        reservations = {\n            o.order_id: (round(o.price_ticks / 100.0 * o.remaining_quantity, 10), 0.0)\n            if o.side == _ClockSide.BUY else (0.0, 0.0)\n            for o in state.own_orders}\n        result = []\n        for a in actions:\n            if isinstance(a, _ClockCancelAll):\n                free = max(0.0, state.cash)\n                yes = max(0.0, state.yes_inventory)\n                reservations.clear()\n                result.append(a)\n            elif isinstance(a, _ClockCancel):\n                cash_refund, yes_refund = reservations.pop(a.order_id, (0.0, 0.0))\n                free += cash_refund\n                yes += yes_refund\n                result.append(a)\n            elif isinstance(a, _ClockPlace):\n                q = _clock_floor(a.quantity * scale, 0.01)\n                price = a.price_ticks / 100.0\n                capacity = (free / price if a.side == _ClockSide.BUY\n                            else yes + free / (1.0 - price))\n                q = min(q, _clock_floor(max(0.0, capacity - 1e-8), 0.01))\n                if q < 0.01:\n                    continue\n                if a.side == _ClockSide.BUY:\n                    cash_used = round(price * q, 10)\n                    covered = 0.0\n                else:\n                    covered = min(yes, q)\n                    cash_used = round((1.0 - price) * (q - covered), 10)\n                free = max(0.0, free - cash_used)\n                yes -= covered\n                if a.client_order_id is not None:\n                    reservations[a.client_order_id] = (cash_used, covered)\n                result.append(_clock_replace(a, quantity=q))\n            else:\n                result.append(a)\n        return result\n",
  "code_sha256": "8bc98c28c0086a79616b2611c92c395c41ba3900931c216332eefd12b087da07",
  "assembled_sha256": "bd3791eaad2b71e7e03fa777c309b77307d7c9cf6565cefd44afcaac7ef283ec",
  "tuning": {
    "seeds": {
      "start": 320000,
      "end": 320199,
      "inclusive": true
    },
    "incumbent_code_sha256": "bf0d179f3e47d28819f6fa7e0d25548c2ced43374c216d36460b00a26a26ffae",
    "selected": "mild_safe2",
    "selection_rule": "Maximum paired overall mean difference over all 200 tuning seeds; frozen before any holdout run.",
    "variants": [
      {
        "name": "mild_safe2",
        "lo": 0.9,
        "hi": 1.1,
        "code_sha256": "8bc98c28c0086a79616b2611c92c395c41ba3900931c216332eefd12b087da07",
        "paired": {
          "n": 200,
          "sum_d": -90.29857212240023,
          "sum_d2": 4188.587739156367,
          "mean_diff": -0.45149286061200117,
          "se": 0.3228258775237606,
          "incumbent_mean": 98.47071831456549,
          "candidate_mean": 98.0192254539535,
          "retail_diff": 0.44666970058000016,
          "arb_diff": -0.8981625611965002
        },
        "by_spread": {
          "1": {
            "n": 50,
            "sum_d": -13.995089903400062,
            "sum_d2": 579.2078202930278,
            "mean_diff": -0.27990179806800125,
            "se": 0.4845745322781932,
            "incumbent_mean": 25.711261479664,
            "candidate_mean": 25.431359681596,
            "retail_diff": 0.7010581343319986,
            "arb_diff": -0.9809599323880005
          },
          "2": {
            "n": 50,
            "sum_d": -17.887509487300026,
            "sum_d2": 540.6996399134017,
            "mean_diff": -0.35775018974600054,
            "se": 0.46699227804664895,
            "incumbent_mean": 61.219908510538,
            "candidate_mean": 60.862158320792,
            "retail_diff": 0.39710946525000124,
            "arb_diff": -0.7548596550519998
          },
          "3": {
            "n": 48,
            "sum_d": -11.175551633200058,
            "sum_d2": 510.45967869497554,
            "mean_diff": -0.23282399235833454,
            "se": 0.4744620610813396,
            "incumbent_mean": 130.8342429047854,
            "candidate_mean": 130.60141891242708,
            "retail_diff": 0.13947414117291723,
            "arb_diff": -0.37229813355625035
          },
          "4": {
            "n": 52,
            "sum_d": -47.240421098500086,
            "sum_d2": 2558.2206002549624,
            "mean_diff": -0.908469636509617,
            "se": 0.9738868248097938,
            "incumbent_mean": 174.37579815333268,
            "candidate_mean": 173.46732851682307,
            "retail_diff": 0.5332846415500002,
            "arb_diff": -1.4417542780115384
          }
        }
      },
      {
        "name": "medium_safe2",
        "lo": 0.75,
        "hi": 1.25,
        "code_sha256": "7b2a778d31e9ca7af92bbdd61a606f84bcaa88b5e4226d5c348bc4ebbec8e0fd",
        "paired": {
          "n": 200,
          "sum_d": -182.65343786710028,
          "sum_d2": 10959.940415848332,
          "mean_diff": -0.9132671893355014,
          "se": 0.5207534410181903,
          "incumbent_mean": 98.47071831456549,
          "candidate_mean": 97.55745112523,
          "retail_diff": 1.1748860473175,
          "arb_diff": -2.08815323668
        },
        "by_spread": {
          "1": {
            "n": 50,
            "sum_d": 6.673378658799955,
            "sum_d2": 896.322366579946,
            "mean_diff": 0.13346757317599908,
            "se": 0.6045513387579834,
            "incumbent_mean": 25.711261479664,
            "candidate_mean": 25.844729052839998,
            "retail_diff": 1.500054194753999,
            "arb_diff": -1.3665866215680007
          },
          "2": {
            "n": 50,
            "sum_d": -35.545736672600015,
            "sum_d2": 871.1349006289439,
            "mean_diff": -0.7109147334520003,
            "se": 0.5875806198152249,
            "incumbent_mean": 61.219908510538,
            "candidate_mean": 60.508993777086,
            "retail_diff": 1.0829590840840002,
            "arb_diff": -1.7938738175679998
          },
          "3": {
            "n": 48,
            "sum_d": -74.48671563600003,
            "sum_d2": 1182.8007681685592,
            "mean_diff": -1.5518065757500006,
            "se": 0.6877898463926282,
            "incumbent_mean": 130.8342429047854,
            "candidate_mean": 129.28243632903542,
            "retail_diff": 0.7142655011958335,
            "arb_diff": -2.266072077022917
          },
          "4": {
            "n": 52,
            "sum_d": -79.29436421730017,
            "sum_d2": 8009.682380470884,
            "mean_diff": -1.5248916195634648,
            "se": 1.7247168509823094,
            "incumbent_mean": 174.37579815333268,
            "candidate_mean": 172.85090653376923,
            "retail_diff": 1.3758038743115388,
            "arb_diff": -2.9006954938865395
          }
        }
      },
      {
        "name": "wide_safe2",
        "lo": 0.5,
        "hi": 1.5,
        "code_sha256": "6ec77bb251aa4939f1aebba5c24b6e931ae916d607c70cc0006b6eb0312a7291",
        "paired": {
          "n": 200,
          "sum_d": -433.74922764020005,
          "sum_d2": 28975.322483843513,
          "mean_diff": -2.168746138201,
          "se": 0.8392780835599122,
          "incumbent_mean": 98.47071831456549,
          "candidate_mean": 96.3019721763645,
          "retail_diff": 2.1789323024015,
          "arb_diff": -4.3476784406140006
        },
        "by_spread": {
          "1": {
            "n": 50,
            "sum_d": 10.730767574599996,
            "sum_d2": 2924.0775341524086,
            "mean_diff": 0.21461535149199992,
            "se": 1.092044431087129,
            "incumbent_mean": 25.711261479664,
            "candidate_mean": 25.925876831156003,
            "retail_diff": 2.539559469992,
            "arb_diff": -2.324944118490001
          },
          "2": {
            "n": 50,
            "sum_d": -76.6121045649,
            "sum_d2": 2750.405801025886,
            "mean_diff": -1.532242091298,
            "se": 1.0366778787891957,
            "incumbent_mean": 61.219908510538,
            "candidate_mean": 59.68766641924,
            "retail_diff": 2.4461271763859997,
            "arb_diff": -3.978369267727999
          },
          "3": {
            "n": 48,
            "sum_d": -193.22867020700002,
            "sum_d2": 4509.367260412874,
            "mean_diff": -4.025597295979167,
            "se": 1.2860935215424014,
            "incumbent_mean": 130.8342429047854,
            "candidate_mean": 126.80864560880626,
            "retail_diff": 0.9629795800875008,
            "arb_diff": -4.988576876110417
          },
          "4": {
            "n": 52,
            "sum_d": -174.63922044290004,
            "sum_d2": 18791.471888252345,
            "mean_diff": -3.358446546978847,
            "se": 2.6200407726978407,
            "incumbent_mean": 174.37579815333268,
            "candidate_mean": 171.01735160635386,
            "retail_diff": 2.697675159946153,
            "arb_diff": -6.056121706896154
          }
        }
      }
    ],
    "superseded_revision_rows": 595
  },
  "paired": {
    "seeds": {
      "start": 430000,
      "end": 430499,
      "inclusive": true
    },
    "n": 500,
    "complete": true,
    "missing_seeds": [],
    "overall": {
      "n": 500,
      "sum_d": 11.583124723699964,
      "sum_d2": 94798.94306796261,
      "mean_diff": 0.023166249447399926,
      "se": 0.6164045815354549,
      "incumbent_mean": 95.54201511346659,
      "candidate_mean": 95.56518136291399,
      "retail_diff": 1.175439528368601,
      "arb_diff": -1.1522732789392003
    },
    "by_spread": {
      "1": {
        "n": 131,
        "sum_d": -2.1959440067000293,
        "sum_d2": 40399.23624530289,
        "mean_diff": -0.016762931348855186,
        "se": 1.5402068676754244,
        "incumbent_mean": 38.277936657049615,
        "candidate_mean": 38.26117372570076,
        "retail_diff": 2.308708432766413,
        "arb_diff": -2.3254713641366407
      },
      "2": {
        "n": 120,
        "sum_d": -107.75560350150003,
        "sum_d2": 7841.424356210039,
        "mean_diff": -0.8979633625125003,
        "se": 0.736439679411548,
        "incumbent_mean": 77.8558643979175,
        "candidate_mean": 76.957901035405,
        "retail_diff": 1.0727727075750018,
        "arb_diff": -1.970736070090001
      },
      "3": {
        "n": 133,
        "sum_d": 104.56779314780002,
        "sum_d2": 33874.662598209026,
        "mean_diff": 0.7862240086300754,
        "se": 1.3873851660724037,
        "incumbent_mean": 146.55140363646615,
        "candidate_mean": 147.33762764509626,
        "retail_diff": 0.6335602255729328,
        "arb_diff": 0.15266378299097716
      },
      "4": {
        "n": 116,
        "sum_d": 16.966879084099997,
        "sum_d2": 12683.619868240661,
        "mean_diff": 0.14626619900086205,
        "se": 0.9749923379289188,
        "incumbent_mean": 120.02204692465259,
        "candidate_mean": 120.16831312365345,
        "retail_diff": 0.6231269360491392,
        "arb_diff": -0.4768607370232764
      }
    }
  },
  "failures": [
    {
      "phase": "superseded_revision_on_tuning_seeds",
      "seed": 320001,
      "variant": "wide",
      "error": "orderbook_pm_challenge.market.OrderBookError: Insufficient free cash for order collateral",
      "resolution": "Replaced incomplete collateral guards with an action-by-action ledger; the same three bound settings were then screened under safe2 revision IDs. Preflight outcomes excluded from tuning statistics; every (seed, revision ID) ran once; cached N observations reused."
    },
    {
      "phase": "superseded_revision_on_tuning_seeds",
      "seed": 320196,
      "variant": "mild_safe",
      "error": "orderbook_pm_challenge.market.OrderBookError: Insufficient free cash for order collateral",
      "resolution": "Replaced incomplete collateral guards with an action-by-action ledger; the same three bound settings were then screened under safe2 revision IDs. Preflight outcomes excluded from tuning statistics; every (seed, revision ID) ran once; cached N observations reused."
    }
  ],
  "check_values": [
    17.116002,
    20.017111,
    2.390311,
    241.484752
  ],
  "python_version": "3.12.3",
  "seconds_per_simulation": 1.4677585896634553
}
