{
 "approach": "Blind build from simulator source only. S0: probability estimate from the competitor ladder's arb sweeps (asks swept => p just under new best ask; bids swept => p just over new best bid), quotes 1 tick inside the competitor only where they clear margin = 0.5 tick + 3 one-step sds of p (sd from Phi-density * sigma / sqrt(H*(sigma^2+lambda*sigmaJ^2)) at mid-range jump params), 8 shares a side, flat for the last 20 steps. S1 adds an Avellaneda-Stoikov reservation price r = p - gamma*q*Var_rem, q = YES-NO shares, Var_rem = H*sd_step(p,H)^2, gamma=0.06; bid/ask are set around r with the same clipping. Score is edge, not PnL, so the skew works by moving quotes after adverse fills, which tilts against the side the arb just took (inventory acts as a signal that p has moved).",
 "tried": [
  {
   "variant": "S0 design diagnostics (not tuning variants): competitor-mid estimate -37.17 (20 seeds 115000-115019); sweep-based estimate -13.49; kvol 1/2/3 -> 1.87/5.05/5.05; size30 -8.26; margin0 3.41; stop150 4.14 (all 80 seeds 115000-115079)",
   "score": null
  },
  {
   "variant": "S0-A kvol=2 size=8",
   "seeds": "115000-115499",
   "mean": 4.774
  },
  {
   "variant": "S0-B kvol=3 size=8 (FROZEN S0)",
   "seeds": "115000-115499",
   "mean": 5.161
  },
  {
   "variant": "S0-C kvol=2 size=5",
   "seeds": "115000-115499",
   "mean": 4.392
  },
  {
   "variant": "S0-D kvol=2.5 size=6",
   "seeds": "115000-115499",
   "mean": 4.904
  },
  {
   "variant": "S1 gamma=0.006 horizon_pow=0",
   "seeds": "115000-115499",
   "mean": 5.232,
   "paired_vs_S0": 0.0705,
   "se": 0.0686
  },
  {
   "variant": "S1 gamma=0.02 horizon_pow=0",
   "seeds": "115000-115499",
   "mean": 5.277,
   "paired_vs_S0": 0.1156,
   "se": 0.098
  },
  {
   "variant": "S1 gamma=0.06 horizon_pow=0 (FROZEN S1)",
   "seeds": "115000-115499",
   "mean": 5.8444,
   "paired_vs_S0": 0.6829,
   "se": 0.1105
  },
  {
   "variant": "S1 gamma=0.06 horizon_pow=1",
   "seeds": "115000-115499",
   "mean": 5.6688,
   "paired_vs_S0": 0.5073,
   "se": 0.1028
  }
 ],
 "next": "The mechanism is real but small: +0.50 +- 0.09 on holdout, almost all of it lower arbitrage loss (+0.86) bought with some retail edge (-0.36). Try it on B with gamma swept around 0.03-0.1 in B's own units, and an asymmetric version (skew only the side that would add to inventory). The baseline here is far below B (6.3 vs 99.7), so the gain may shrink or grow on a strong base.",
 "code": "import math\nfrom orderbook_pm_challenge.strategy import BaseStrategy\nfrom orderbook_pm_challenge.types import CancelAll, PlaceOrder, Side, StepState\n\n\nclass Strategy(BaseStrategy):\n    \"\"\"S1 = S0 + Avellaneda-Stoikov reservation price: quotes centre on\n    r = p - gamma * q * Var_rem, q = net YES inventory in shares,\n    Var_rem = H * (one-step sd of p)^2 * (H/T)^horizon_pow.\"\"\"\n\n    size = 8.0          # shares per side (about one retail clip)\n    margin = 0.5        # fixed ticks of edge vs estimate\n    kvol = 3.0          # plus this many one-step sds of p (adverse selection)\n    stop_steps = 20     # stop quoting this close to expiry\n    gamma = 0.06        # risk aversion of the reservation skew\n    horizon_pow = 0.0   # extra taper of the skew by remaining horizon\n\n    def __init__(self):\n        self.p = None\n        self.pbb = None\n        self.pba = None\n\n    def estimate(self, state):\n        # Arb sweeps reveal p: asks swept => p just under new best ask,\n        # bids swept => p just above new best bid.\n        bb, ba = state.competitor_best_bid_ticks, state.competitor_best_ask_ticks\n        if bb is None and ba is None:\n            return None, bb, ba\n        if bb is None:\n            bb = 0\n        if ba is None:\n            ba = 100\n        if self.p is None:\n            self.p = 0.5 * (bb + ba)\n        else:\n            if ba > self.pba:\n                self.p = ba - 0.5\n            if bb < self.pbb:\n                self.p = bb + 0.5\n            self.p = min(max(self.p, bb), ba)\n        self.pbb, self.pba = bb, ba\n        return self.p, bb, ba\n\n    def step_sd(self, p_ticks, h):\n        # one-step sd of p in ticks, assuming mid-range jump parameters\n        x = min(max(p_ticks / 100.0, 0.005), 0.995)\n        lo, hi = -9.0, 9.0\n        for _ in range(40):\n            mid = 0.5 * (lo + hi)\n            if 0.5 * (1 + math.erf(mid / math.sqrt(2))) < x:\n                lo = mid\n            else:\n                hi = mid\n        z = 0.5 * (lo + hi)\n        dens = math.exp(-0.5 * z * z) / math.sqrt(2 * math.pi)\n        return 100.0 * dens * 0.02 / math.sqrt(max(h, 1) * 0.000704)\n\n    def reservation(self, p_ticks, state):\n        h = state.steps_remaining\n        q = state.yes_inventory - state.no_inventory\n        sd = self.step_sd(p_ticks, h) / 100.0\n        var_rem = h * sd * sd * (h / 2000.0) ** self.horizon_pow\n        return p_ticks - 100.0 * self.gamma * q * var_rem\n\n    def on_step(self, state: StepState):\n        actions = [CancelAll()]\n        if state.steps_remaining <= self.stop_steps:\n            return actions\n        p, bb, ba = self.estimate(state)\n        if p is None:\n            return actions\n        r = self.reservation(p, state)\n        m = self.margin + self.kvol * self.step_sd(p, state.steps_remaining)\n        bid = min(bb + 1, math.floor(r - m + 1e-9))\n        ask = max(ba - 1, math.ceil(r + m - 1e-9))\n        cash = state.cash\n        yes = state.yes_inventory\n        q = self.size\n        if 1 <= bid <= 99 and bid < ba:\n            need = bid / 100.0 * q\n            if need <= cash - 1e-6:\n                actions.append(PlaceOrder(side=Side.BUY, price_ticks=bid, quantity=q))\n                cash -= need\n        if 1 <= ask <= 99 and ask > bb and ask > bid:\n            cover = min(q, yes)\n            need = (1.0 - ask / 100.0) * (q - cover)\n            if need <= cash - 1e-6:\n                actions.append(PlaceOrder(side=Side.SELL, price_ticks=ask, quantity=q))\n        return actions\n",
 "code_sha256": "2a3dfecdaa853ce8978ea92a5773c59ff81f3c2135473d59ea3b0577d9bba01f",
 "code_s0": "import math\nfrom orderbook_pm_challenge.strategy import BaseStrategy\nfrom orderbook_pm_challenge.types import CancelAll, PlaceOrder, Side, StepState\n\n\nclass Strategy(BaseStrategy):\n    \"\"\"S0: probability estimate from competitor-ladder sweeps; quote one tick\n    inside the competitor where that clears a volatility-scaled margin.\"\"\"\n\n    size = 8.0          # shares per side (about one retail clip)\n    margin = 0.5        # fixed ticks of edge vs estimate\n    kvol = 3.0          # plus this many one-step sds of p (adverse selection)\n    stop_steps = 20     # stop quoting this close to expiry\n\n    def __init__(self):\n        self.p = None\n        self.pbb = None\n        self.pba = None\n\n    def estimate(self, state):\n        # Arb sweeps reveal p: asks swept => p just under new best ask,\n        # bids swept => p just above new best bid.\n        bb, ba = state.competitor_best_bid_ticks, state.competitor_best_ask_ticks\n        if bb is None and ba is None:\n            return None, bb, ba\n        if bb is None:\n            bb = 0\n        if ba is None:\n            ba = 100\n        if self.p is None:\n            self.p = 0.5 * (bb + ba)\n        else:\n            if ba > self.pba:\n                self.p = ba - 0.5\n            if bb < self.pbb:\n                self.p = bb + 0.5\n            self.p = min(max(self.p, bb), ba)\n        self.pbb, self.pba = bb, ba\n        return self.p, bb, ba\n\n    def step_sd(self, p_ticks, h):\n        # one-step sd of p in ticks, assuming mid-range jump parameters\n        x = min(max(p_ticks / 100.0, 0.005), 0.995)\n        lo, hi = -9.0, 9.0\n        for _ in range(40):\n            mid = 0.5 * (lo + hi)\n            if 0.5 * (1 + math.erf(mid / math.sqrt(2))) < x:\n                lo = mid\n            else:\n                hi = mid\n        z = 0.5 * (lo + hi)\n        dens = math.exp(-0.5 * z * z) / math.sqrt(2 * math.pi)\n        return 100.0 * dens * 0.02 / math.sqrt(max(h, 1) * 0.000704)\n\n    def reservation(self, p_ticks, state):\n        return p_ticks\n\n    def on_step(self, state: StepState):\n        actions = [CancelAll()]\n        if state.steps_remaining <= self.stop_steps:\n            return actions\n        p, bb, ba = self.estimate(state)\n        if p is None:\n            return actions\n        r = self.reservation(p, state)\n        m = self.margin + self.kvol * self.step_sd(p, state.steps_remaining)\n        bid = min(bb + 1, math.floor(r - m + 1e-9))\n        ask = max(ba - 1, math.ceil(r + m - 1e-9))\n        cash = state.cash\n        yes = state.yes_inventory\n        q = self.size\n        if 1 <= bid <= 99 and bid < ba:\n            need = bid / 100.0 * q\n            if need <= cash - 1e-6:\n                actions.append(PlaceOrder(side=Side.BUY, price_ticks=bid, quantity=q))\n                cash -= need\n        if 1 <= ask <= 99 and ask > bb and ask > bid:\n            cover = min(q, yes)\n            need = (1.0 - ask / 100.0) * (q - cover)\n            if need <= cash - 1e-6:\n                actions.append(PlaceOrder(side=Side.SELL, price_ticks=ask, quantity=q))\n        return actions\n",
 "tuning_score": {
  "seeds": "115000-115499",
  "n": 500,
  "s1_mean": 5.8444,
  "s0_mean": 5.1615
 },
 "paired": {
  "seeds": "200000-200999",
  "n": 1000,
  "complete": true,
  "mechanism_diff": 0.5006,
  "mechanism_se": 0.0886,
  "mechanism_retail_diff": -0.3582,
  "mechanism_retail_se": 0.1037,
  "mechanism_arb_diff": 0.8588,
  "mechanism_arb_se": 0.0716,
  "reference_diff": -93.3495,
  "reference_se": 5.48,
  "s1_mean": 6.3464,
  "s0_mean": 5.8458,
  "b_mean": 99.6959,
  "failures": []
 },
 "graft": "After your fair-value estimate p (ticks) each step: q = yes_inventory - no_inventory; v = H*sd_step(p,H)^2 (sd_step = one-step sd of p in price units); r = p - 100*gamma*q*v; quote bid/ask around r instead of p, keeping your own margins and clips. gamma=0.06 here (about 0.5 tick of skew per 10 shares at p=0.5, H=2000); retune gamma on your base.",
 "seconds_per_simulation": {
  "single_process": 0.28,
  "under_8_concurrent_processes": 0.884
 }
}