{
  "key": "f-run-class",
  "approach": "Blind composition over opaque N (SHA256 bf0d179f3e47d28819f6fa7e0d25548c2ced43374c216d36460b00a26a26ffae). 25 deterministic quadrature particles span the uniform jump-intensity [0.0008,0.0030] and jump-sigma [0.20,0.60] priors. An approximate Rao-Blackwellised filter integrates Gaussian latent score and jump/no-jump branches, moment-matches each posterior, and weights parameter particles from competitor midpoint moves every eight steps. The observation model uses a Gaussian moment approximation to the terminal compound-Poisson distribution, ignores the small unknown jump mean, and models quote gaps as observation noise; this is not an exact posterior. After 600 steps, freeze high-loss classification if posterior E[intensity*sigma^2] exceeds its quadrature prior mean; otherwise low. In high runs, apply the frozen size factor to N new PlaceOrders within two ticks (absolute distance) of the same-side competitor best; low runs use factor 1. A conservative collateral cap can further reduce only these resized placements, reserving cash for unchanged orders later in the batch. Existing resting orders are left to N. No orders are added, so N receives the original state with all own orders. Single OS process; pinned unmodified simulator b244530ee2a6247b5f930830eeca9dd950da0e7e; default ChallengeConfig and ParameterVariance, 2000 steps; no workers or sandbox.",
  "tried": {
    "variants": [
      {
        "factor": 0.65,
        "spreads": [
          4
        ],
        "summary": {
          "n": 200,
          "incumbent_mean": 85.162644703073,
          "mean_diff": -1.5148449827575008,
          "se": 0.40933699632644943,
          "sum_d": -302.96899655150014,
          "sum_d2": 7127.71077150719,
          "retail_diff": -0.16215079196099924,
          "arb_diff": -1.352694190805,
          "failures": []
        },
        "all_spreads": {
          "n": 200,
          "incumbent_mean": 85.162644703073,
          "mean_diff": -16.384508021425,
          "se": 2.2966310781410804,
          "sum_d": -3276.901604285,
          "sum_d2": 263616.0901223498,
          "retail_diff": -6.114056865541,
          "arb_diff": -10.270451155916,
          "failures": []
        },
        "by_spread": {
          "1": {
            "n": 47,
            "incumbent_mean": 30.59600304578298,
            "mean_diff": -9.381002249593616,
            "se": 3.1152695952097713,
            "sum_d": -440.9071057308999,
            "sum_d2": 25118.154405836114,
            "retail_diff": -4.979069203793618,
            "arb_diff": -4.401933045944681,
            "failures": []
          },
          "2": {
            "n": 57,
            "incumbent_mean": 81.35713208259824,
            "mean_diff": -27.054996174566668,
            "se": 6.814527910253212,
            "sum_d": -1542.1347819503,
            "sum_d2": 189951.87834799866,
            "retail_diff": -9.659518394224559,
            "arb_diff": -17.395477780349122,
            "failures": []
          },
          "3": {
            "n": 53,
            "incumbent_mean": 115.0669198036906,
            "mean_diff": -18.696051321741518,
            "se": 2.882092931608372,
            "sum_d": -990.8907200523005,
            "sum_d2": 41418.34659700787,
            "retail_diff": -7.656083276733962,
            "arb_diff": -11.039968044960375,
            "failures": []
          },
          "4": {
            "n": 43,
            "incumbent_mean": 112.9910120734674,
            "mean_diff": -7.045790617476747,
            "se": 1.6627397799953896,
            "sum_d": -302.96899655150014,
            "sum_d2": 7127.71077150719,
            "retail_diff": -0.7541897300511593,
            "arb_diff": -6.291600887465116,
            "failures": []
          }
        },
        "code_sha256": "cf2315a5df6fb7e3208bf08c2dcf7d7b864c6589f358def9f068ae346cd7de04"
      },
      {
        "factor": 0.85,
        "spreads": [
          4
        ],
        "summary": {
          "n": 200,
          "incumbent_mean": 85.162644703073,
          "mean_diff": -1.6768224244369998,
          "se": 0.8053178956050818,
          "sum_d": -335.36448488739995,
          "sum_d2": 26374.115825294495,
          "retail_diff": -0.19496162369799952,
          "arb_diff": -1.4818608007570004,
          "failures": []
        },
        "all_spreads": {
          "n": 200,
          "incumbent_mean": 85.162644703073,
          "mean_diff": -18.4562681182885,
          "se": 2.6842763060784125,
          "sum_d": -3691.2536236577,
          "sum_d2": 354899.27020831435,
          "retail_diff": -5.748083582141001,
          "arb_diff": -12.708184536187497,
          "failures": []
        },
        "by_spread": {
          "1": {
            "n": 47,
            "incumbent_mean": 30.59600304578298,
            "mean_diff": -9.405595287978722,
            "se": 3.06312331250063,
            "sum_d": -442.06297853499996,
            "sum_d2": 24443.31568033704,
            "retail_diff": -4.949740023776596,
            "arb_diff": -4.455855264323404,
            "failures": []
          },
          "2": {
            "n": 57,
            "incumbent_mean": 81.35713208259824,
            "mean_diff": -30.359283426459655,
            "se": 7.872601115931871,
            "sum_d": -1730.4791553082002,
            "sum_d2": 250369.3990107671,
            "retail_diff": -9.209607622624558,
            "arb_diff": -21.14967580385263,
            "failures": []
          },
          "3": {
            "n": 53,
            "incumbent_mean": 115.0669198036906,
            "mean_diff": -22.327301979756612,
            "se": 3.146835543119191,
            "sum_d": -1183.3470049271004,
            "sum_d2": 53712.43969191573,
            "retail_diff": -6.661112756254719,
            "arb_diff": -15.666189223458488,
            "failures": []
          },
          "4": {
            "n": 43,
            "incumbent_mean": 112.9910120734674,
            "mean_diff": -7.7991740671488365,
            "se": 3.6270295293712898,
            "sum_d": -335.36448488739995,
            "sum_d2": 26374.115825294495,
            "retail_diff": -0.9067982497581373,
            "arb_diff": -6.89237581747442,
            "failures": []
          }
        },
        "code_sha256": "2f7d322d4517164789baeb4c3a700e0c82de76cff93d2d01d54099365518b7c2"
      }
    ],
    "selection": "For each variant, include spreads with positive tuning paired mean; if none are positive, use its single best-mean spread to retain a nonempty mechanism test. Choose variant with greater masked mean across all 200 tuning seeds. Tuning score is selection-biased.",
    "frozen_high_factor": 0.65,
    "warmup": 600,
    "k": 2,
    "correctness_repair": "An interrupted preliminary tuning pass exposed collateral failures after altered inventory paths. Added conservative collateral clipping only to eligible resized placements, verified the failing cases, and restarted the same two-factor tuning experiment from scratch. No holdout was used for repair.",
    "reference_check": {
      "seed": 310000,
      "expected_rounded": 17.116002,
      "observed": 17.1160017503,
      "matches": true
    },
    "assembled_equals_s1": {
      "passed": true,
      "seeds": [
        310009,
        310013,
        310021,
        310023,
        310024
      ],
      "comparison": "Every callback action list; 2000 callbacks per seed."
    },
    "scoreboard": {
      "incumbent_sha256": "bf0d179f3e47d28819f6fa7e0d25548c2ced43374c216d36460b00a26a26ffae",
      "candidate_sha256": "cf2315a5df6fb7e3208bf08c2dcf7d7b864c6589f358def9f068ae346cd7de04",
      "paired_mean_diff": -1.2657039363906002,
      "paired_se": 0.6279690666845577,
      "promoted": false
    },
    "high_classified_holdout": 130,
    "eligible_holdout_runs": 131,
    "run_class_diagnostics": {
      "high": {
        "n": 130,
        "true_mean_intensity_times_sigma_squared": 0.0003321767935708599,
        "mean_diff": -4.86809206304077
      },
      "low": {
        "n": 1,
        "true_mean_intensity_times_sigma_squared": 8.798374844126872e-05,
        "mean_diff": 0.0
      }
    }
  },
  "next": "Retain N; this overlay has a nonpositive holdout paired mean. If revisited, first validate the approximate quote-driven risk classifier on tuning seeds; do not retune on this holdout. Finalist seeds 900000..903999 were untouched. The approximate observation model and short warm-up limit run-parameter identification.",
  "spreads_acted": [
    4
  ],
  "off_equals_n": {
    "passed": true,
    "n": 10,
    "seeds": [
      310000,
      310001,
      310002,
      310003,
      310004,
      310005,
      310006,
      310007,
      310008,
      310009
    ],
    "comparison": "Exact action equality on every callback, 2000 per seed, with mechanism disabled."
  },
  "code": "import math as _rc_math\nfrom statistics import NormalDist as _RCNormal\nfrom dataclasses import replace as _rc_replace\nfrom orderbook_pm_challenge.types import (PlaceOrder as _RCPlace, Side as _RCSide,\n                                        CancelAll as _RCAll, CancelOrder as _RCCancel)\n\n\nclass Strategy(BaseStrategy):\n    # Static quadrature particles for uniform ParameterVariance priors.\n    # Each carries a Gaussian conditional latent-score distribution;\n    # jump occurrence and score are integrated rather than sampled.\n    ENABLED = True\n    SPREADS = (4,)\n    WARMUP = 600\n    EVERY = 8\n    K = 2\n    HIGH_FACTOR = 0.65\n\n    def __init__(self):\n        self.n = _N()\n        self.spread = None\n        self.factor = None\n        self.last = None\n        self.particles = []\n        self.prior_risk = 0.0\n        self.posterior_risk = None\n        for i in range(5):\n            intensity = 0.0008 + (i + 0.5) * 0.0022 / 5\n            for j in range(5):\n                sigma = 0.20 + (j + 0.5) * 0.40 / 5\n                self.particles.append([intensity, sigma, 1.0 / 25, 0.0, 0.1875])\n                self.prior_risk += intensity * sigma * sigma / 25\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 or bid >= ask:\n            return\n        if self.last is not None and state.step - self.last < self.EVERY:\n            return\n        dt = 0 if self.last is None else state.step - self.last\n        self.last = state.step\n        probability = max(0.015, min(0.985, (bid + ask) / 200.0))\n        z = _RCNormal().inv_cdf(probability)\n        density = max(0.035, _rc_math.exp(-0.5 * z * z) / _rc_math.sqrt(2 * _rc_math.pi))\n        # Uniform uncertainty across the visible quote interval, with a\n        # one-tick floor for stale replenishments and retail depletion.\n        obs_probability_sd = max(0.01, (ask - bid) / (100 * _rc_math.sqrt(12)))\n        total = 0.0\n        for particle in self.particles:\n            intensity, sigma, weight, mean, variance = particle\n            terminal_var = max(0.0004, state.steps_remaining * (0.0004 + intensity * sigma * sigma))\n            scale = _rc_math.sqrt(terminal_var)\n            observed = z * scale\n            noise = (obs_probability_sd * scale / density) ** 2\n            predicted_var = variance + dt * 0.0004\n            jump_probability = -_rc_math.expm1(-intensity * dt)\n            branches = []\n            likelihood = 0.0\n            # Conditional on a nonzero Poisson count, integrate its\n            # second moment too. Moment-match the updated Gaussian mixture.\n            conditional_jump_var = (intensity * dt / jump_probability * sigma * sigma\n                                    if jump_probability > 0 else sigma * sigma)\n            for mass, extra_var in ((1 - jump_probability, 0.0),\n                                    (jump_probability, conditional_jump_var)):\n                v = predicted_var + extra_var\n                innovation_var = max(1e-12, v + noise)\n                residual = observed - mean\n                evidence = (_rc_math.exp(max(-700, -0.5 * residual * residual / innovation_var))\n                            / _rc_math.sqrt(2 * _rc_math.pi * innovation_var))\n                # Change of variables keeps evidence comparable across\n                # particles' distinct score-to-probability mappings.\n                evidence *= scale / density\n                branch_weight = mass * evidence\n                gain = v / innovation_var\n                branches.append((branch_weight, mean + gain * residual, (1 - gain) * v))\n                likelihood += branch_weight\n            if likelihood > 1e-200:\n                updated_mean = sum(w * m for w, m, v in branches) / likelihood\n                updated_var = sum(w * (v + (m - updated_mean) ** 2)\n                                  for w, m, v in branches) / likelihood\n            else:\n                updated_mean, updated_var = observed, noise\n            # Small quote-contamination mixture avoids numerical collapse.\n            particle[2] = weight * (0.99 * likelihood + 0.01)\n            particle[3] = updated_mean\n            particle[4] = max(1e-10, updated_var)\n            total += particle[2]\n        for particle in self.particles:\n            particle[2] /= total\n        self.posterior_risk = sum(p[2] * p[0] * p[1] ** 2 for p in self.particles)\n\n    def on_step(self, state):\n        # No orders are added: every own order remains visible to N.\n        actions = self.n.on_step(state)\n        if not self.ENABLED:\n            return actions\n        bid = state.competitor_best_bid_ticks\n        ask = state.competitor_best_ask_ticks\n        if self.spread is None:\n            self.spread = max(1, (ask - bid + 1) // 2) if bid is not None and ask is not None else 0\n        if self.spread not in self.SPREADS:\n            return actions\n        if self.factor is None:\n            self._observe(state)\n            if state.step < self.WARMUP:\n                return actions\n            risk = self.posterior_risk if self.posterior_risk is not None else self.prior_risk\n            self.factor = self.HIGH_FACTOR if risk > self.prior_risk else 1.0\n        if self.factor == 1.0:\n            return actions\n        return self._resize(state, list(actions), bid, ask)\n\n    def _resize(self, state, actions, bid, ask):\n        def near(action):\n            if not isinstance(action, _RCPlace):\n                return False\n            quote = bid if action.side == _RCSide.BUY else ask\n            return quote is not None and abs(action.price_ticks - quote) <= self.K\n\n        # Reserve a conservative cash budget for unchanged placements later\n        # in the batch. A CancelAll starts a fresh budget. Only near-quote\n        # placements can be clipped; all other N actions stay untouched.\n        protected = [0.0] * len(actions)\n        reserve = 0.0\n        for i in range(len(actions) - 1, -1, -1):\n            action = actions[i]\n            protected[i] = reserve\n            if isinstance(action, _RCAll):\n                reserve = 0.0\n            elif isinstance(action, _RCPlace) and not near(action):\n                price = action.price_ticks / 100\n                reserve += float(action.quantity) * (price if action.side == _RCSide.BUY else 1 - price)\n        orders = {o.order_id: (o.side, o.price_ticks / 100, o.remaining_quantity)\n                  for o in state.own_orders}\n        sell_total = sum(q for side, p, q in orders.values() if side == _RCSide.SELL)\n        cash = state.free_cash\n        yes = state.yes_inventory\n        result = []\n        for i, action in enumerate(actions):\n            if isinstance(action, _RCAll):\n                cash = state.cash\n                sell_total = 0.0\n                orders.clear()\n            elif isinstance(action, _RCCancel):\n                old = orders.pop(action.order_id, None)\n                if old is not None:\n                    side, price, q = old\n                    # A sell's reserved YES cannot exceed total YES; use\n                    # only its guaranteed cash release, never guess it.\n                    cash += q * price if side == _RCSide.BUY else max(0.0, q - yes) * (1 - price)\n                    if side == _RCSide.SELL:\n                        sell_total -= q\n            elif isinstance(action, _RCPlace):\n                price = action.price_ticks / 100\n                quantity = float(action.quantity)\n                available_yes = max(0.0, yes - sell_total)\n                if near(action):\n                    budget = max(0.0, cash - protected[i] - 1e-7)\n                    capacity = (budget / price if action.side == _RCSide.BUY\n                                else available_yes + budget / (1 - price))\n                    quantity = _rc_math.floor(min(quantity * self.factor, capacity) * 100 + 1e-9) / 100\n                    if quantity < 0.01:\n                        continue\n                    action = _rc_replace(action, quantity=quantity)\n                if action.side == _RCSide.BUY:\n                    cash -= quantity * price\n                else:\n                    cash -= max(0.0, quantity - available_yes) * (1 - price)\n                    sell_total += quantity\n                orders[action.client_order_id if action.client_order_id is not None else object()] = (action.side, price, quantity)\n            result.append(action)\n        return result\n",
  "code_sha256": "cf2315a5df6fb7e3208bf08c2dcf7d7b864c6589f358def9f068ae346cd7de04",
  "assembled_sha256": "bae4bedcf45030eb77959002916ad3354742e4c33ba4dc947ec55ca025f65e43",
  "tuning": {
    "n": 200,
    "mean_diff": -1.5148449827575008,
    "se": 0.40933699632644943
  },
  "paired": {
    "n": 500,
    "incumbent_mean": 104.39217582931512,
    "mean_diff": -1.2657039363906002,
    "se": 0.6279690666845577,
    "sum_d": -632.8519681953001,
    "sum_d2": 99190.11783110962,
    "retail_diff": 0.46734012163320054,
    "arb_diff": -1.7330440580183992,
    "failures": [],
    "first_seed": 410000,
    "last_seed": 410499,
    "complete": true
  },
  "by_spread": {
    "1": {
      "incumbent_mean": 28.495164940043484,
      "mean_diff": 0.0,
      "se": 0.0,
      "sum_d": 0.0,
      "sum_d2": 0.0,
      "retail_diff": 0.0,
      "arb_diff": 0.0,
      "runs": 115
    },
    "2": {
      "incumbent_mean": 97.76628686140519,
      "mean_diff": 0.0,
      "se": 0.0,
      "sum_d": 0.0,
      "sum_d2": 0.0,
      "retail_diff": 0.0,
      "arb_diff": 0.0,
      "runs": 116
    },
    "3": {
      "incumbent_mean": 128.40565590283617,
      "mean_diff": 0.0,
      "se": 0.0,
      "sum_d": 0.0,
      "sum_d2": 0.0,
      "retail_diff": 0.0,
      "arb_diff": 0.0,
      "runs": 138
    },
    "4": {
      "incumbent_mean": 151.58987905372672,
      "mean_diff": -4.830931054925955,
      "se": 2.3759023826355956,
      "sum_d": -632.8519681953001,
      "sum_d2": 99190.11783110962,
      "retail_diff": 1.7837409222641243,
      "arb_diff": -6.614671977169463,
      "runs": 131
    }
  },
  "seconds_per_simulation": 1.1740021647564136
}
