{"item":"rival-model","batch":"e01-restarts","family":"explicit rival-pool latent-state model: exact-ish Bayesian grid filter over the joint (z = ln p, w = ln s2 of the 30 bps rival), with a router-split likelihood on every own retail fill, a 30 bps rival arb-clamp transition, an unobserved-rival-retail jump kernel, own no-arb band truncation on silent steps, and an arb-vs-retail mixture on the first own trade of each timestamp; fees from oracle_table.json driven by the posterior mean of z.","hypothesis":"Because both pools have x*y = K = 1e6 (constant in the replica), the router's split ratio r = sqrt((1-fee)/0.997) is independent of pool state, so an interior split pins the rival's post-trade marginal price exactly and the order size is a deterministic function of the rival's pre-trade spot. Tracking w jointly with z and coupling them through the rival's 30 bps arb clamp should recover price information from retail fills and close part of the gap between the observable filter and the true-p oracle table.","verdict":"Structural screen, replica only. The rival dimension + router likelihood DOES carry price information but little: +0.39 paired (95% CI 0.21..0.57) and -0.60 bps RMS vs the same filter without it (10000..10063). The full observable model scores 528.65 vs 535.22 for the true-p oracle table on 10000..10255: deficit -6.57 (SE 0.08), missing the brief's 'within 2' target. Most of the observable gain comes from the own-band truncation + arb mixture, not the rival model. Not a qualification candidate; no real-engine claim is made.","engine_vs_replica":"All scores are from replica.py (pure Python, brief's file) with 10000 steps per seed. The real engine (amm_sim_rs) needs a Solidity strategy; this Python model was NOT run on the real engine, and nothing here is a board or engine claim. The pinned simulator was cloned at 6b6921f8d463314aa7c96234e1be25a25245f704 and setup.sh succeeded (StarterStrategy validated), but no engine scoring was done in this item.","sources":[{"url":"https://raw.githubusercontent.com/gtmcknight/amm-sim/main/research/filter-brief.md","sha256":"0ef2200226b68aa58de6aad268442ba09ada710c54b3fb0ec35c77b491f78a4b"},{"url":"https://raw.githubusercontent.com/gtmcknight/amm-sim/main/research/oracle_table.json","sha256":"3e9d1fc8874c6d796d4c26948d486b587f2a6b5610b20fba99923a60954cf4b5"},{"url":"https://raw.githubusercontent.com/gtmcknight/amm-sim/main/research/replica.py","sha256":"d079712fa1f4850ad8337e656e7ee8dbdde806cd4762d597fae50f547ef9c7c4"},{"url":"https://raw.githubusercontent.com/gtmcknight/amm-sim/main/research/setup.sh","sha256":"dc7fa6a1e59f5b043d3954cf68d538318b7affaf5c0db3ca69a1822680f300d4"},{"url":"https://github.com/benedictbrady/amm-challenge","commit":"6b6921f8d463314aa7c96234e1be25a25245f704"}],"not_used":"RS2 code, its numba port, other incumbents, other workers' results, RS2 overlays: none fetched or read. Seeds 5148000..5151999 never used.","model":{"state":"P[i,j] on an 80x80 grid, z_i = c + (i-40)*h, w_j = c + (j-40)*h, h = 3e-4 (3 bps), shared moving center c (integer recenter when z-mean drifts >= 6 cells); plus own (x,y), last timestamp, current fees.","init":"c = ln(10000/100) from initial reserves; P = delta at (ln100, ln100). Hidden init args (sigma, lambda, size) are discarded.","per_elapsed_step":"1) P <- P @ Tw (rival jump kernel: with prob exp(-jump_rate) no jump, else one jump of sign +/-1 (p=.5) and size 2*ln(1+0.997*S/1e4), S ~ lognormal(ln20-0.72, 1.2)*share; kernel built from 200000 draws, rng seed 12345). 2) P <- Tz @ P (Gaussian, sd sigma/h, sigma fixed 0.000945 = mid of the replica's sigma range). 3) rival arb clamp: mass with w > z+k cells moved to w = z+k, w < z-k to w = z-k, k = round(30.045bps/h) = 10. 4) silent steps (no own trade at that timestamp): zero z outside own no-arb band [ln s + ln(1-fb), ln s - ln(1-fa)].","retail_likelihood":"Trader buys X paying u1 Y (sells X: same in X units, size S = tx*p uses z): r = sqrt((1-fee)/0.997); interior split => S(w) = ((u1*(g + r*0.997) + y1)/r - y2(w))/0.997 with y2 = sqrt(K e^w); L = lognormal_pdf(S)*(g + r*0.997)/(r*0.997); if the whole order came to us ((r*y2 - y1)/g >= u1) L = lognormal_pdf(u1); else 0. After the update, w is remapped (linear interpolation) to the rival's post-trade state y2 + 0.997*(S-u1) (collapses onto the equal-marginal-price point for interior splits).","first_trade_mixture":"First own trade at a new timestamp: H_arb pins z_a = ln(s_after/(1-fa)) (pool sold X) or ln(s_after*(1-fb)) (pool bought X), weight 2*f_z(z_a) (density in ln y' or ln x'); H_retail restricts z to the own band, weight rho_ret * sum(P*L*band) * y'/(1-fee) (x'/(1-fee) for sells). Posterior = mixture; arb probability pa feeds the table's arb_flag as pa*0.1463. Later trades at the same timestamp are retail with certainty. Repeated timestamps are handled by this rule.","policy":"d = ln(spot) - E[z]; ask = interp(d/0.003 on knots -8..8, oracle ask) + 0.1463*pa; bid likewise; askFee = 1 - exp(d - ask*0.003); bidFee = 1 - exp(-bid*0.003 - d); clamp [0, 0.1]. Table values copied unchanged from oracle_table.json.","constants":{"N":80,"h":0.0003,"sigma":0.000945,"jump_rate":0.8,"share":1.0,"size_mean":20.0,"size_sd":1.2,"rho_ret":0.4,"rival_fee":0.003,"K":1000000.0,"arb_flag":0.1463,"recenter_threshold_cells":6},"fitted":"Only jump_rate was searched on 20600..20727 (0.4 vs 0.8; paired difference +0.01, SE 0.025, i.e. flat); frozen at 0.8. All other constants are priors from the replica's published ranges, not fitted.","safety":"If an update would leave zero/NaN mass the prior is kept (counted as n_fallback; mean 3.36 per 10000-step seed on eval)."},"seeds_configs":{"fit":"replica.run(seed, policy, n_steps=10000) for seed in 20600..20727 (128 seeds); per-seed sigma/lambda/size drawn by the replica from random.Random(10000000+seed).","eval":"10000..10255 (256 seeds), 10000 steps, frozen constants; arms: rival_model, oracle_table with TRUE p and true arb label, fixed 35 bps.","ablation":"10000..10063 (64 seeds), 10000 steps, router=False, no retuning.","commands":["python -I exp/harness.py rival 20600 20727 10000 res/tr_j04.json jump_rate=0.4","python -I exp/harness.py rival 20600 20727 10000 res/tr_j08.json jump_rate=0.8","python -I exp/harness.py oracle 20600 20727 10000 res/tr_oracle.json","python -I exp/harness.py rival 10000 10255 10000 res/ev_rival.json jump_rate=0.8","python -I exp/harness.py oracle 10000 10255 10000 res/ev_oracle.json","python -I exp/harness.py fixed35 10000 10255 10000 res/ev_fixed35.json","python -I exp/harness.py norouter 10000 10063 10000 res/ab_norouter.json jump_rate=0.8","python -I exp/leak.py"],"layout":"exp/ holds replica.py and oracle_table.json (from the URLs above, unmodified), rival_filter.py, harness.py, leak.py; run from the parent with the setup venv (. amm-challenge/scratch/env.sh); numpy required."},"leakage_test":{"design":"Strip wrapper calls the policy with (side, amount_in_X, amount_Y, t, x_after, y_after) only; hidden args are used outside the policy for RMS/arb-recall scoring. leak.py reruns seeds 10000 and 10001 (3000 steps) with init args set to NaN, arb label flipped, p*1.01 and s2*0.97 passed to the wrapper.","result":"10000: edge 120.92399911412292 both runs IDENTICAL; 10001: edge 197.2304164273603 both runs IDENTICAL (edge and average fees bit-equal)."},"rms_note":"rms_bps = per-seed sqrt(mean over own-trade callbacks of (E[z] - ln p)^2) in bps, averaged over seeds; measured after each update.","runtime":"Fit: 2 configs x 128 seeds ~ 2m53s each on 8 processes (10.6 s/seed/process). Eval rival arm 256 seeds 5m43s; oracle and fixed arms < 15 s; ablation 64 seeds 58 s. Total compute ~ 13 min wall.","port_estimate":"Not portable as built: per elapsed step it does two 80x80x80 matrix products plus 6400-cell masks (~1.1M multiply-adds), i.e. tens of millions of gas per step vs the 245,000 budget. A port would need z on <= 32 cells with a 5-7 tap separable diffusion and w reduced to ~3 states (at upper band edge / interior / lower edge) relative to z: ~32*3*7 ~ 700 MACs per step ~ 30-60k gas, and catch-up of many silent steps would need a closed-form (precomputed k-step kernel + single band truncation). Given the rival dimension is worth only +0.39 here, the cheaper port is the 1D z filter (the ablation arm), state ~32 words.","limitations":["Replica only; replica levels read 3-5 above the board per the brief, and this Python strategy was not ported or run on the Rust engine.","Deficit to the true-p oracle table is -6.57, far from the brief's target of within 2; the policy table was not retrained for filter noise (that is episode 2 and outside this item).","Rival jump kernel ignores routing share (share=1) and multiple orders per step; rival K assumed constant (true in replica.py: nrx = K/nry).","Diffusion sigma fixed at 0.000945, not estimated from arb-to-arb moves.","Arb/retail mixture is approximate: rho_ret = 0.4 is a prior, not fitted; arb recall 0.836, false-positive rate 0.059 on eval.","3 bps grid quantisation of z and w; recenter fallbacks 3.36 per seed."],"dead_ends":["Unnormalized lognormal density in the router likelihood (missing 1/(sd*sqrt(2pi))) over-weighted the retail hypothesis: on seed 20600, 2000 steps, arb recall fell to 0.48 and RMS to 21.3 bps; fixed version: recall 0.78, RMS 14.6 bps.","Recentering both axes by the z shift dropped all rival-axis mass (NaN fees) once on seed 20600; added a reset of w|z to the rival band (counted fallback).","jump_rate 0.4 vs 0.8 on fit seeds: 516.395 vs 516.405 (paired +0.01, SE 0.025) - the rival jump rate is not identifiable from score, a sign the w channel carries little.","Router + rival latent state vs no router (ablation): +0.39 edge, -0.60 bps RMS; worth less than the +0.9 the brief quotes for knowing the rival's position exactly."],"remaining_work":"Retrain the 35-knot table (CMA-ES) on this filter's mean and sd; estimate sigma online; fit rho_ret; test the 1D-z port. Nothing here is near the +4.6-over-RS2 entry bar, which can only be decided on the real engine on 4000 fresh seeds.","metrics":{"replica_eval_10000_10255":{"rival_model":{"edge":528.65,"retail":564.185,"arb":-35.535,"rv":75211.856,"av":24890.376,"fb":37.174,"fa":36.152,"rms_bps":14.899,"arb_recall":0.836,"arb_false_pos":0.059,"fallbacks_per_seed":3.359,"sec_per_seed_8proc":10.557},"oracle_table_true_p":{"edge":535.216,"retail":566.713,"arb":-31.497,"rv":76274.804,"av":23965.683,"fb":36.819,"fa":35.844},"fixed_35bps":{"edge":349.246,"retail":564.73,"arb":-215.484,"rv":70558.564,"av":35413.882,"fb":35.0,"fa":35.0},"paired_rival_minus_oracle":{"n":256,"mean":-6.567,"sd":1.33,"se":0.083,"ci95":[-6.729,-6.404]},"paired_rival_minus_fixed35":{"n":256,"mean":179.403,"sd":48.62,"se":3.039,"ci95":[173.447,185.359]},"paired_retail_rival_minus_oracle":{"n":256,"mean":-2.528,"sd":1.381,"se":0.086,"ci95":[-2.697,-2.359]},"paired_arb_rival_minus_oracle":{"n":256,"mean":-4.038,"sd":0.551,"se":0.034,"ci95":[-4.106,-3.971]}},"replica_fit_20600_20727":{"jump_rate_0p4":{"edge":516.395,"rms_bps":14.919},"jump_rate_0p8":{"edge":516.405,"rms_bps":14.934},"oracle_table":{"edge":522.911},"paired_j08_minus_j04":{"n":128,"mean":0.01,"sd":0.279,"se":0.025,"ci95":[-0.038,0.058]},"paired_j08_minus_oracle":{"n":128,"mean":-6.505,"sd":1.021,"se":0.09,"ci95":[-6.682,-6.328]}}},"ablation":{"name":"router likelihood + rival latent dimension removed (router=False): retail fill likelihood replaced by a w-flat lognormal size density; rival jump/clamp still run but carry no information to z since nothing observes w. No retuning (jump_rate=0.8 frozen).","seeds":"10000..10063, 10000 steps","full_model":{"edge":519.846,"rms_bps":14.902},"ablated":{"edge":519.458,"retail":565.401,"arb":-45.943,"rv":74684.957,"av":24551.342,"fb":36.789,"fa":36.237,"rms_bps":15.497,"arb_recall":0.852},"oracle":{"edge":526.39},"paired_full_minus_ablated":{"n":64,"mean":0.387,"sd":0.737,"se":0.092,"ci95":[0.207,0.568]},"paired_rms_full_minus_ablated_bps":{"n":64,"mean":-0.595,"sd":0.225,"se":0.028,"ci95":[-0.65,-0.54]}},"per_seed":{"columns":["seed","edge","edge_oracle","edge_fixed35","retail","arb","retail_vol_y","arb_vol_y","rms_bps","oracle_retail","oracle_arb","arb_recall"],"arm":"rival_model jump_rate=0.8 frozen; oracle=oracle_table with true p and true arb flag; fixed35","rows":[[10000,438.15,445.68,280.51,461.22,-23.08,61356,21490,15.42,465.43,-19.74,0.802],[10001,567.76,572.58,404.84,598.05,-30.29,87722,27055,13.73,598.35,-25.76,0.878],[10002,522.26,527.96,322.56,553.67,-31.41,68198,25023,15.71,555.45,-27.49,0.812],[10003,565.9,573.65,379.63,595.65,-29.74,81723,26785,14.64,599.42,-25.77,0.856],[10004,518.77,524.58,342.43,545.14,-26.38,72668,24470,14.01,547.56,-22.98,0.86],[10005,523.79,527.72,341.93,551.4,-27.62,72713,24372,14.48,550.97,-23.25,0.848],[10006,481.06,487.63,342.6,507.5,-26.44,74267,23858,14.0,510.14,-22.51,0.863],[10007,519.94,527.21,352.39,547.63,-27.68,76314,24410,14.55,551.18,-23.97,0.849],[10008,655.48,664.11,436.88,688.22,-32.74,95089,28576,14.87,692.07,-27.96,0.861],[10009,647.23,653.72,431.46,679.44,-32.2,91794,28273,14.39,681.56,-27.83,0.881],[10010,473.23,479.55,342.9,499.29,-26.06,75170,23688,14.79,501.59,-22.04,0.835],[10011,365.22,371.52,266.16,385.81,-20.6,57967,19173,14.98,388.94,-17.41,0.801],[10012,452.08,459.01,332.58,478.79,-26.71,73757,23707,15.26,481.25,-22.24,0.813],[10013,396.89,402.84,265.28,417.91,-21.02,56863,19462,15.01,420.48,-17.64,0.818],[10014,697.21,702.85,406.89,734.17,-36.96,86895,27496,13.31,735.24,-32.39,0.872],[10015,622.69,632.35,416.45,656.2,-33.5,91863,28638,15.43,660.94,-28.59,0.835],[10016,559.35,569.33,331.35,629.75,-70.41,70564,24338,15.58,635.45,-66.12,0.81],[10017,489.62,494.5,333.97,517.29,-27.67,72034,24608,14.53,518.83,-24.33,0.842],[10018,475.43,482.17,325.72,502.34,-26.91,69335,24278,14.6,504.76,-22.59,0.83],[10019,450.69,455.47,282.25,473.92,-23.24,60848,21286,15.09,474.96,-19.49,0.799],[10020,491.92,498.15,315.78,518.0,-26.09,67602,23899,14.1,521.04,-22.89,0.85],[10021,406.62,413.41,256.69,428.01,-21.39,56341,20289,15.7,431.32,-17.9,0.792],[10022,434.12,442.05,281.47,457.84,-23.73,60784,21212,16.04,461.87,-19.82,0.797],[10023,629.49,635.3,403.9,662.81,-33.32,86644,27318,14.0,664.3,-29.0,0.874],[10024,475.67,483.68,330.05,503.06,-27.39,72653,24654,15.2,506.96,-23.29,0.834],[10025,441.25,447.67,280.51,465.62,-24.37,61572,21499,15.89,468.13,-20.47,0.804],[10026,341.8,347.39,242.71,361.65,-19.84,53450,18982,15.03,364.63,-17.24,0.798],[10027,543.31,549.7,347.13,571.89,-28.59,72973,25087,15.36,574.39,-24.69,0.819],[10028,521.88,527.77,323.69,552.77,-30.89,67861,23751,15.61,554.83,-27.06,0.826],[10029,437.97,444.58,322.21,461.92,-23.94,71809,22219,14.82,464.82,-20.23,0.845],[10030,589.97,597.82,405.85,622.45,-32.48,88999,28158,14.76,625.56,-27.74,0.857],[10031,335.63,343.56,250.06,357.76,-22.13,56670,20639,16.63,361.74,-18.18,0.754],[10032,632.32,637.94,403.94,663.8,-31.47,86004,27211,14.31,664.71,-26.77,0.862],[10033,529.79,536.47,380.37,559.44,-29.65,81097,26075,14.64,561.38,-24.91,0.854],[10034,560.47,566.53,383.95,589.18,-28.71,83740,25650,14.97,590.85,-24.32,0.848],[10035,627.78,636.15,431.25,661.81,-34.04,93819,28778,14.89,664.6,-28.45,0.848],[10036,541.29,546.61,372.94,570.33,-29.04,81412,25655,15.12,571.12,-24.51,0.835],[10037,439.6,445.19,306.33,464.55,-24.95,66267,22522,15.03,466.13,-20.94,0.824],[10038,614.75,620.6,426.32,645.97,-31.22,91402,27914,14.65,647.59,-26.99,0.868],[10039,583.24,590.59,363.13,616.69,-33.45,78253,25163,15.7,619.96,-29.38,0.812],[10040,603.35,609.97,425.34,634.09,-30.73,90749,27867,13.57,636.92,-26.95,0.894],[10041,626.12,632.27,409.81,656.18,-30.07,86020,26963,13.7,657.78,-25.51,0.881],[10042,707.44,711.21,442.78,741.84,-34.4,93252,29794,13.4,740.97,-29.76,0.889],[10043,633.02,639.26,410.58,664.55,-31.53,88520,27528,14.92,666.8,-27.54,0.854],[10044,415.16,421.89,284.62,438.42,-23.26,60666,21275,14.63,441.49,-19.6,0.824],[10045,381.36,388.1,277.05,404.95,-23.59,60355,21595,15.82,408.24,-20.14,0.79],[10046,426.68,434.19,311.21,454.36,-27.68,68848,24398,15.61,457.45,-23.26,0.815],[10047,590.91,599.63,426.18,623.17,-32.26,90977,28574,14.42,627.58,-27.95,0.862],[10048,490.67,497.21,326.01,516.72,-26.05,70749,23529,16.35,519.67,-22.46,0.788],[10049,380.36,385.91,263.1,400.83,-20.47,56746,19474,14.86,403.3,-17.38,0.817],[10050,371.78,378.55,260.04,393.36,-21.58,57374,20553,15.14,397.26,-18.71,0.811],[10051,418.94,424.72,281.3,441.91,-22.97,59943,21440,14.92,444.66,-19.93,0.822],[10052,424.23,431.54,303.26,449.27,-25.04,68360,22880,14.99,452.52,-20.98,0.837],[10053,529.92,538.02,336.55,557.82,-27.9,72879,24269,15.4,561.56,-23.54,0.831],[10054,439.83,444.32,290.07,467.9,-28.07,63152,22093,15.88,468.33,-24.01,0.8],[10055,706.16,710.74,452.58,741.89,-35.73,95372,30514,14.6,741.36,-30.62,0.865],[10056,578.51,583.46,397.63,607.79,-29.28,83772,26167,13.87,608.56,-25.1,0.877],[10057,504.59,510.83,321.72,530.24,-25.65,68621,23187,14.78,532.81,-21.98,0.853],[10058,433.91,440.07,269.06,456.7,-22.78,58352,20950,15.61,459.6,-19.53,0.793],[10059,502.47,509.43,332.83,531.54,-29.07,71746,25291,15.65,534.18,-24.74,0.802],[10060,922.0,928.78,419.36,2094.15,-1172.16,91090,31255,15.43,2097.79,-1169.01,0.836],[10061,556.49,562.9,378.94,584.3,-27.81,82846,25436,13.97,587.03,-24.13,0.87],[10062,600.96,610.97,416.12,630.8,-29.85,89693,27006,14.71,636.67,-25.7,0.849],[10063,423.67,429.33,291.25,446.33,-22.67,63690,20959,14.67,448.66,-19.32,0.836],[10064,654.18,662.11,442.59,688.24,-34.06,94414,28708,13.9,691.76,-29.65,0.882],[10065,578.72,586.35,382.18,607.92,-29.2,81900,25777,14.8,611.99,-25.65,0.845],[10066,479.36,486.2,335.31,505.55,-26.19,72924,23590,15.11,508.71,-22.51,0.82],[10067,630.62,635.01,385.49,662.26,-31.64,80042,26510,14.19,662.2,-27.19,0.86],[10068,498.6,504.96,285.61,523.91,-25.31,60467,23022,14.31,527.02,-22.06,0.827],[10069,616.86,623.17,379.14,647.12,-30.26,80754,26081,14.32,649.62,-26.46,0.867],[10070,407.43,413.64,269.3,431.77,-24.34,57926,22023,15.95,434.48,-20.84,0.785],[10071,429.43,437.32,283.81,452.29,-22.85,62078,20869,15.66,457.17,-19.86,0.78],[10072,599.24,605.89,356.99,648.12,-48.87,77206,24574,13.96,651.23,-45.34,0.866],[10073,561.88,567.73,378.82,590.69,-28.81,80968,26235,13.75,592.59,-24.86,0.878],[10074,525.34,533.09,341.32,552.71,-27.37,73955,24352,14.58,556.81,-23.72,0.836],[10075,556.72,562.43,367.38,585.86,-29.14,79555,25748,14.65,587.22,-24.8,0.848],[10076,524.75,530.86,362.94,553.63,-28.88,78542,25488,14.23,555.45,-24.59,0.864],[10077,423.42,430.35,301.43,446.6,-23.18,66396,21689,15.42,450.09,-19.75,0.823],[10078,614.97,622.08,416.92,646.97,-32.0,89402,26868,14.92,649.53,-27.45,0.85],[10079,646.48,650.6,417.98,680.29,-33.81,88898,28722,15.18,679.75,-29.15,0.85],[10080,481.63,488.07,319.46,509.76,-28.14,69388,24746,16.48,511.78,-23.71,0.791],[10081,562.78,567.41,359.68,592.75,-29.97,75799,25448,14.01,593.5,-26.08,0.871],[10082,560.51,566.75,358.91,589.24,-28.73,75940,25007,14.12,591.77,-25.02,0.854],[10083,461.86,467.21,337.63,488.15,-26.28,72805,24107,14.2,489.64,-22.43,0.85],[10084,470.29,476.21,318.18,495.37,-25.08,68508,22852,14.96,497.38,-21.18,0.834],[10085,450.53,455.72,291.72,474.78,-24.25,63012,22450,14.4,476.5,-20.78,0.817],[10086,567.06,573.84,389.19,597.47,-30.42,84127,26571,14.9,599.91,-26.07,0.851],[10087,564.18,571.97,394.78,592.78,-28.59,86431,25791,14.52,596.53,-24.57,0.863],[10088,435.15,442.48,305.43,460.65,-25.5,65998,23028,15.52,464.67,-22.19,0.809],[10089,409.04,414.9,277.26,432.66,-23.62,60026,21625,16.12,435.16,-20.26,0.77],[10090,581.35,587.68,399.75,614.55,-33.2,87433,28176,14.82,615.69,-28.01,0.861],[10091,479.74,486.86,308.92,507.15,-27.41,67177,23792,15.4,510.75,-23.89,0.803],[10092,553.49,557.74,350.53,581.28,-27.79,74844,24865,14.15,581.48,-23.74,0.849],[10093,653.93,663.39,429.75,693.67,-39.74,92453,28529,14.71,699.15,-35.76,0.86],[10094,474.87,480.63,321.15,502.78,-27.92,68759,24846,14.38,504.36,-23.73,0.837],[10095,590.64,597.95,395.46,622.2,-31.56,85087,27257,14.94,624.98,-27.04,0.84],[10096,484.97,492.09,318.52,509.53,-24.56,66488,22738,14.88,513.59,-21.5,0.841],[10097,505.82,512.78,336.07,531.51,-25.69,72437,22817,15.17,534.44,-21.66,0.831],[10098,497.91,503.26,350.3,524.71,-26.8,76192,24422,14.66,525.88,-22.62,0.847],[10099,464.51,470.46,334.4,489.0,-24.48,71443,22731,14.12,491.43,-20.97,0.856],[10100,437.28,444.11,283.82,466.31,-29.03,60960,22222,16.88,469.17,-25.06,0.774],[10101,530.19,536.95,352.3,558.08,-27.89,75773,24728,14.48,560.53,-23.58,0.857],[10102,732.25,737.22,466.62,771.46,-39.21,98026,30599,13.31,771.58,-34.36,0.899],[10103,734.37,741.54,443.33,768.43,-34.06,92838,28723,14.63,770.88,-29.34,0.864],[10104,699.54,703.15,460.21,734.94,-35.4,97020,30428,14.15,733.45,-30.29,0.871],[10105,465.58,472.25,293.63,490.59,-25.01,62808,23004,15.23,493.69,-21.44,0.819],[10106,424.47,429.55,272.25,448.85,-24.38,58596,20627,15.1,450.28,-20.73,0.811],[10107,484.84,491.97,334.7,511.97,-27.13,71592,24538,14.76,515.42,-23.45,0.849],[10108,528.25,535.48,341.74,558.46,-30.21,74782,25271,14.54,561.94,-26.46,0.847],[10109,732.38,738.83,446.3,783.84,-51.46,96177,29615,14.34,785.2,-46.37,0.862],[10110,568.64,572.96,405.29,599.16,-30.52,89263,26891,14.08,598.9,-25.94,0.877],[10111,399.11,406.3,284.49,423.99,-24.88,60448,22749,15.84,427.79,-21.49,0.795],[10112,460.16,464.07,304.06,486.66,-26.5,64960,23279,15.69,486.23,-22.17,0.795],[10113,430.51,436.53,285.06,454.03,-23.52,61759,21509,15.81,456.17,-19.64,0.793],[10114,529.46,535.08,375.42,557.37,-27.9,81096,25581,14.03,558.95,-23.87,0.868],[10115,656.06,663.15,440.65,689.68,-33.62,93084,29519,13.98,692.4,-29.24,0.881],[10116,519.0,526.86,347.5,545.66,-26.66,74366,24205,14.4,549.63,-22.77,0.851],[10117,406.53,413.05,284.39,429.89,-23.36,61176,21983,15.58,433.02,-19.97,0.793],[10118,417.27,424.53,283.64,442.31,-25.04,61035,22772,15.01,445.83,-21.31,0.802],[10119,409.81,416.95,286.16,434.84,-25.04,62406,22452,14.98,437.95,-21.0,0.808],[10120,543.99,553.43,386.2,573.76,-29.76,83456,26819,15.13,579.0,-25.57,0.846],[10121,530.03,536.69,371.57,559.67,-29.64,80213,26054,14.72,561.8,-25.11,0.86],[10122,581.63,587.94,402.31,613.53,-31.9,86526,27232,15.87,614.97,-27.03,0.828],[10123,501.35,506.72,330.44,529.44,-28.09,71495,25256,14.78,530.57,-23.86,0.828],[10124,523.64,533.84,341.33,552.42,-28.78,74018,25577,15.59,558.5,-24.66,0.822],[10125,450.75,455.31,319.91,477.32,-26.57,71086,24031,15.87,477.64,-22.33,0.779],[10126,451.94,460.7,295.82,475.71,-23.77,64754,21024,16.05,481.21,-20.51,0.806],[10127,490.69,495.76,332.72,517.91,-27.22,72474,24536,14.5,518.8,-23.04,0.841],[10128,727.4,732.52,462.73,769.49,-42.09,97516,30788,14.09,769.39,-36.86,0.873],[10129,530.8,535.3,361.22,559.65,-28.85,77944,25549,14.64,559.9,-24.6,0.837],[10130,455.55,461.72,314.63,480.81,-25.26,68034,23043,15.38,483.33,-21.62,0.82],[10131,493.19,499.68,314.04,519.73,-26.54,67126,23308,15.41,522.59,-22.91,0.812],[10132,498.47,503.6,310.3,523.32,-24.85,65134,22629,14.45,525.56,-21.96,0.834],[10133,624.96,631.5,399.51,654.33,-29.37,85478,26915,13.93,657.09,-25.59,0.873],[10134,529.74,536.23,356.98,560.12,-30.38,76958,26641,14.91,562.46,-26.23,0.84],[10135,454.87,459.54,322.33,481.71,-26.84,69462,23984,14.69,482.07,-22.53,0.842],[10136,610.89,620.34,414.05,641.8,-30.91,90116,26886,14.56,646.98,-26.64,0.861],[10137,615.78,622.68,404.08,646.08,-30.3,86821,27157,14.38,648.65,-25.98,0.856],[10138,494.09,501.37,311.14,521.32,-27.23,67627,24130,14.37,524.74,-23.37,0.832],[10139,461.71,467.56,314.53,486.84,-25.13,67947,22588,15.59,489.01,-21.45,0.802],[10140,548.49,552.86,371.13,576.17,-27.68,79352,25394,13.58,576.4,-23.55,0.879],[10141,576.35,580.65,369.1,612.75,-36.4,78886,25270,14.74,613.56,-32.9,0.851],[10142,620.7,628.25,431.29,654.34,-33.64,92632,29175,14.1,657.0,-28.75,0.879],[10143,465.8,471.45,304.65,490.01,-24.21,64911,22047,14.75,492.0,-20.55,0.823],[10144,434.64,440.81,307.88,459.88,-25.24,66275,22609,15.12,462.01,-21.2,0.821],[10145,476.55,481.6,312.93,501.67,-25.12,66702,22902,14.21,503.59,-22.0,0.847],[10146,755.92,765.78,410.8,1026.35,-270.44,86385,29332,15.34,1030.38,-264.6,0.836],[10147,464.19,469.59,321.44,490.2,-26.01,68554,23627,14.68,491.65,-22.06,0.844],[10148,686.58,692.34,427.07,719.97,-33.39,89313,27970,14.24,720.96,-28.61,0.869],[10149,514.9,523.63,349.13,548.1,-33.2,76628,26696,15.87,552.5,-28.87,0.817],[10150,579.47,589.25,385.23,609.7,-30.23,83020,26546,15.46,615.02,-25.77,0.835],[10151,470.2,474.55,314.99,494.86,-24.66,68773,22980,14.95,495.79,-21.24,0.822],[10152,411.69,418.11,279.75,435.24,-23.56,60416,22170,14.79,438.22,-20.11,0.809],[10153,551.36,555.93,370.15,579.08,-27.73,80978,25429,13.91,579.66,-23.73,0.867],[10154,484.89,490.94,326.69,509.68,-24.79,71439,22963,13.99,511.99,-21.05,0.859],[10155,471.32,478.58,315.06,495.53,-24.2,68490,22009,14.77,499.15,-20.57,0.845],[10156,528.11,534.11,317.77,563.61,-35.5,68795,23666,14.9,565.42,-31.31,0.836],[10157,529.82,537.99,350.09,555.15,-25.33,75217,23561,14.38,559.43,-21.44,0.847],[10158,432.01,437.86,287.04,457.3,-25.29,61588,23068,15.2,459.49,-21.63,0.791],[10159,432.05,439.39,296.38,457.35,-25.3,63470,23170,15.74,461.22,-21.82,0.799],[10160,417.94,422.61,284.78,442.84,-24.89,61517,22967,15.5,443.91,-21.3,0.799],[10161,453.47,458.62,306.33,479.63,-26.17,65965,23637,14.84,481.19,-22.57,0.82],[10162,715.23,721.72,463.97,748.81,-33.58,99033,29302,13.13,750.71,-28.99,0.897],[10163,661.9,669.13,442.72,695.75,-33.84,95780,29735,14.16,698.12,-28.98,0.879],[10164,679.43,684.24,389.42,799.41,-119.98,83811,28130,14.95,797.9,-113.65,0.845],[10165,434.39,441.79,313.96,459.26,-24.87,68152,22660,15.35,463.38,-21.59,0.822],[10166,413.76,419.54,276.0,437.47,-23.71,58926,21409,16.43,439.55,-20.02,0.775],[10167,487.68,494.24,313.8,515.76,-28.08,67568,23281,14.47,518.32,-24.08,0.848],[10168,618.49,627.24,329.71,738.51,-120.02,70919,25931,15.84,743.47,-116.23,0.799],[10169,565.72,572.88,393.41,593.5,-27.77,84701,25796,14.4,596.62,-23.74,0.863],[10170,383.71,389.7,283.24,407.26,-23.55,62409,21439,15.31,409.69,-19.99,0.822],[10171,563.56,568.42,346.71,592.09,-28.53,72996,25245,14.08,592.95,-24.53,0.862],[10172,679.34,686.94,445.53,715.24,-35.9,94837,29078,14.84,718.27,-31.33,0.849],[10173,392.29,398.48,258.68,413.92,-21.63,55996,19950,15.54,416.84,-18.36,0.778],[10174,536.38,544.04,382.09,565.63,-29.25,83021,26326,14.42,569.15,-25.1,0.859],[10175,500.04,505.19,337.29,526.34,-26.3,72427,23751,14.38,527.59,-22.41,0.851],[10176,440.81,449.16,308.95,465.96,-25.15,66867,23015,14.54,470.67,-21.52,0.829],[10177,647.71,656.15,390.4,719.36,-71.65,83138,26710,14.64,723.55,-67.4,0.858],[10178,656.49,664.21,420.52,690.97,-34.47,91334,28102,15.05,693.64,-29.43,0.841],[10179,375.15,382.43,262.31,398.93,-23.78,57144,21289,16.46,402.56,-20.13,0.772],[10180,577.91,585.75,381.13,610.15,-32.24,82174,27884,15.14,613.76,-28.01,0.841],[10181,456.71,463.97,318.61,482.99,-26.28,69783,23842,15.83,486.57,-22.59,0.801],[10182,569.83,575.17,396.08,600.49,-30.66,84207,27425,14.34,601.24,-26.07,0.859],[10183,624.06,633.1,401.34,659.9,-35.84,85601,27941,15.36,664.19,-31.09,0.847],[10184,515.73,522.57,305.76,551.75,-36.02,65569,23838,15.22,554.68,-32.11,0.818],[10185,536.93,545.63,350.27,571.44,-34.52,77046,25698,15.98,575.64,-30.01,0.816],[10186,568.9,575.46,337.67,598.78,-29.88,72073,25549,15.47,601.64,-26.18,0.824],[10187,544.74,551.66,351.78,583.95,-39.21,75430,24394,14.17,587.27,-35.61,0.855],[10188,526.77,533.4,365.29,555.77,-29.0,78789,25514,14.54,557.76,-24.35,0.846],[10189,711.71,717.58,440.31,748.06,-36.35,94206,29473,14.64,749.15,-31.58,0.866],[10190,655.4,661.69,402.58,688.93,-33.53,85840,27325,14.16,691.01,-29.32,0.867],[10191,658.37,662.48,415.81,694.86,-36.49,88436,26985,14.12,694.8,-32.33,0.879],[10192,659.31,665.87,427.72,692.09,-32.79,92205,27789,15.05,693.75,-27.88,0.854],[10193,576.44,583.35,394.68,606.47,-30.03,85134,27216,13.66,608.68,-25.34,0.879],[10194,505.27,512.13,361.2,535.17,-29.9,80141,26445,15.16,537.52,-25.39,0.837],[10195,549.3,554.53,372.79,578.69,-29.39,80249,26090,14.19,580.04,-25.52,0.863],[10196,579.0,587.12,393.13,611.62,-32.62,85731,27594,15.14,614.76,-27.63,0.851],[10197,436.15,443.35,296.3,461.11,-24.95,63765,22935,16.03,464.41,-21.05,0.785],[10198,551.22,558.4,346.45,583.17,-31.95,74105,25649,14.37,585.83,-27.43,0.855],[10199,478.35,483.7,295.64,510.3,-31.95,63181,22480,15.6,511.4,-27.71,0.794],[10200,556.46,563.07,380.2,585.6,-29.14,81821,25852,14.36,588.22,-25.14,0.86],[10201,475.9,482.41,342.3,500.8,-24.91,73854,23149,14.59,503.45,-21.04,0.832],[10202,561.68,570.12,370.99,592.07,-30.39,80153,25273,15.24,596.3,-26.18,0.822],[10203,612.79,618.45,401.52,644.73,-31.94,86398,27797,14.39,646.18,-27.72,0.861],[10204,451.48,456.7,313.18,478.6,-27.12,66873,24187,14.67,479.65,-22.95,0.85],[10205,414.39,420.64,287.77,437.56,-23.17,63827,21858,14.9,440.52,-19.88,0.831],[10206,515.69,523.64,364.6,542.76,-27.07,77566,24354,15.23,546.25,-22.62,0.829],[10207,631.84,637.32,415.21,666.0,-34.16,88130,29105,14.6,666.89,-29.56,0.857],[10208,623.68,629.59,322.86,700.21,-76.52,69218,24612,14.92,702.63,-73.04,0.829],[10209,546.39,554.05,347.88,576.21,-29.82,73146,24397,15.41,580.35,-26.3,0.826],[10210,421.54,427.14,292.62,444.75,-23.21,62863,21412,14.84,446.54,-19.39,0.822],[10211,434.29,441.69,284.8,457.27,-22.98,61805,21262,15.66,461.13,-19.44,0.811],[10212,619.72,630.22,419.03,652.06,-32.34,89089,28001,14.83,657.74,-27.52,0.847],[10213,575.71,583.88,384.68,605.2,-29.5,83564,26336,15.36,609.32,-25.44,0.837],[10214,571.18,578.58,412.27,602.27,-31.09,90572,27530,14.83,605.25,-26.67,0.846],[10215,453.63,457.41,302.46,479.52,-25.89,64641,23090,15.06,479.55,-22.14,0.831],[10216,448.17,454.86,281.94,473.66,-25.49,59645,22469,15.43,476.59,-21.72,0.798],[10217,662.76,668.59,432.68,698.73,-35.97,92714,30202,15.4,699.64,-31.05,0.838],[10218,628.03,633.67,420.91,659.71,-31.68,89261,28365,13.27,661.31,-27.64,0.886],[10219,518.11,524.93,377.15,547.93,-29.81,82650,25959,15.12,549.81,-24.87,0.849],[10220,512.26,518.48,293.69,548.78,-36.52,62377,23034,16.02,551.04,-32.56,0.776],[10221,530.92,536.96,313.36,565.21,-34.29,65801,24973,15.52,567.1,-30.13,0.825],[10222,614.41,621.72,381.58,645.93,-31.52,82173,27334,15.14,648.79,-27.07,0.829],[10223,657.22,664.05,397.91,693.08,-35.85,85385,27593,14.62,695.75,-31.71,0.859],[10224,429.29,436.88,290.03,455.33,-26.04,64188,21250,15.51,459.02,-22.13,0.804],[10225,477.35,484.09,330.83,503.42,-26.07,71871,23785,14.54,506.79,-22.69,0.855],[10226,703.1,707.78,432.17,736.82,-33.72,91931,28494,13.67,737.49,-29.71,0.875],[10227,439.27,446.78,291.46,462.52,-23.25,63482,21450,15.47,466.57,-19.8,0.796],[10228,535.86,542.25,378.12,564.59,-28.73,82430,25319,15.44,566.2,-23.95,0.837],[10229,426.0,433.68,306.98,449.69,-23.69,69086,22180,14.64,454.29,-20.61,0.829],[10230,625.34,633.96,432.89,659.1,-33.76,92562,28804,15.08,662.57,-28.61,0.839],[10231,689.45,696.75,427.63,723.84,-34.39,89722,29135,14.69,726.7,-29.95,0.861],[10232,497.52,502.62,328.35,524.37,-26.85,71240,23775,15.55,525.77,-23.15,0.822],[10233,442.89,448.73,315.31,468.22,-25.33,66779,23154,14.29,470.4,-21.67,0.84],[10234,533.83,539.9,351.3,564.0,-30.18,73418,25077,15.0,566.2,-26.3,0.832],[10235,658.86,663.13,394.86,693.08,-34.22,84286,26995,14.59,693.17,-30.04,0.844],[10236,438.63,445.65,318.37,463.37,-24.74,68815,22259,15.9,466.33,-20.69,0.807],[10237,637.93,645.69,412.52,670.82,-32.9,86352,28517,14.66,673.89,-28.19,0.857],[10238,448.66,454.82,271.98,479.22,-30.56,57712,22763,16.42,481.58,-26.76,0.756],[10239,595.76,603.9,383.64,627.39,-31.63,82162,27195,15.57,631.29,-27.4,0.841],[10240,593.96,603.95,372.03,634.05,-40.09,82453,26396,15.9,639.54,-35.59,0.832],[10241,400.6,406.79,268.23,424.72,-24.12,59088,20738,15.52,427.62,-20.83,0.8],[10242,419.72,425.51,273.88,442.9,-23.17,58970,20465,14.64,444.79,-19.27,0.835],[10243,614.65,621.37,339.53,685.11,-70.47,72602,25739,14.38,687.69,-66.33,0.847],[10244,434.34,440.85,295.39,459.15,-24.81,63554,22610,14.48,462.19,-21.34,0.829],[10245,592.86,600.11,388.45,623.61,-30.76,82875,26646,15.64,626.35,-26.24,0.841],[10246,556.26,563.33,371.74,586.51,-30.26,82157,26552,14.36,588.89,-25.56,0.844],[10247,495.41,504.92,350.06,523.67,-28.27,76139,24964,15.82,528.63,-23.71,0.813],[10248,491.75,499.5,356.71,519.69,-27.94,78277,24711,16.13,522.88,-23.38,0.81],[10249,530.29,536.97,358.64,558.5,-28.22,76573,25417,13.87,561.25,-24.28,0.864],[10250,399.48,407.05,272.05,421.83,-22.35,60113,20519,15.3,426.17,-19.12,0.812],[10251,381.21,386.22,266.69,404.58,-23.37,58787,21715,15.27,406.07,-19.84,0.801],[10252,393.58,399.77,266.44,416.9,-23.32,58884,20963,16.57,419.62,-19.85,0.774],[10253,574.59,581.53,400.74,603.77,-29.18,88110,26599,14.28,606.78,-25.25,0.869],[10254,495.08,502.48,305.94,522.8,-27.72,65424,24583,15.57,527.21,-24.74,0.799],[10255,596.36,601.82,403.51,626.37,-30.01,86253,27072,14.09,627.8,-25.99,0.864]]},"ablation_per_seed":{"columns":["seed","edge","retail","arb","rms_bps"],"rows":[[10000,437.74,460.8,-23.06,15.64],[10001,568.69,598.81,-30.12,14.45],[10002,522.09,553.34,-31.24,16.4],[10003,566.39,596.16,-29.76,15.21],[10004,518.65,544.77,-26.12,14.58],[10005,523.92,551.13,-27.2,14.9],[10006,481.75,507.75,-26.0,14.34],[10007,518.5,545.67,-27.17,15.42],[10008,654.38,686.95,-32.56,15.46],[10009,646.53,678.01,-31.48,15.18],[10010,472.19,497.64,-25.45,14.99],[10011,365.1,385.3,-20.2,15.02],[10012,450.75,477.41,-26.66,16.33],[10013,396.42,417.33,-20.91,15.62],[10014,697.15,733.72,-36.56,14.02],[10015,621.92,655.17,-33.25,16.07],[10016,560.07,630.45,-70.39,15.89],[10017,489.39,516.78,-27.38,14.75],[10018,474.9,501.42,-26.52,15.34],[10019,450.44,473.48,-23.04,15.68],[10020,491.78,517.57,-25.79,14.57],[10021,406.27,427.12,-20.85,16.46],[10022,433.94,457.16,-23.22,16.35],[10023,630.74,663.9,-33.16,14.54],[10024,475.34,502.37,-27.03,15.74],[10025,441.36,465.22,-23.85,16.35],[10026,341.93,361.47,-19.53,15.62],[10027,544.14,572.38,-28.25,15.9],[10028,522.08,552.39,-30.31,15.97],[10029,437.78,461.43,-23.65,15.57],[10030,589.37,621.93,-32.56,15.68],[10031,335.45,357.58,-22.13,17.5],[10032,631.32,662.42,-31.11,14.52],[10033,528.29,557.48,-29.19,15.46],[10034,559.66,588.24,-28.58,16.0],[10035,627.3,660.94,-33.64,15.5],[10036,540.03,568.75,-28.73,15.9],[10037,439.6,464.14,-24.54,15.41],[10038,614.07,645.06,-30.99,15.39],[10039,583.01,616.62,-33.61,16.61],[10040,602.78,633.11,-30.33,14.44],[10041,625.05,654.59,-29.54,14.21],[10042,705.21,739.52,-34.31,13.85],[10043,632.59,663.84,-31.25,15.28],[10044,413.75,436.66,-22.9,15.49],[10045,381.15,404.78,-23.63,16.6],[10046,426.42,453.64,-27.22,16.22],[10047,592.0,624.32,-32.33,15.32],[10048,490.6,516.65,-26.04,16.73],[10049,379.98,400.21,-20.23,15.22],[10050,371.51,392.94,-21.42,15.94],[10051,419.29,442.06,-22.77,15.32],[10052,423.0,447.71,-24.71,15.82],[10053,530.69,558.71,-28.01,16.18],[10054,439.07,466.63,-27.56,16.45],[10055,705.23,740.66,-35.43,15.16],[10056,577.22,606.13,-28.91,14.38],[10057,503.25,528.54,-25.29,15.36],[10058,432.97,455.27,-22.3,16.01],[10059,500.16,528.82,-28.66,16.45],[10060,922.11,2094.23,-1172.12,15.74],[10061,555.72,583.03,-27.31,14.77],[10062,601.37,631.04,-29.67,15.16],[10063,423.74,446.31,-22.57,15.34]]},"source_code":{"rival_filter.py":"\"\"\"Clean-room observable-only strategy: joint grid posterior over (z=ln p, w=ln s2_rival).\nInputs used: initial reserves (100 X, 10000 Y => K=1e6), and per own trade: side, amounts,\ntimestamp, post-reserves, plus own stored history/fees. No true p, rival reserves, arb label,\nsigma/lambda/size are read. Fees from oracle_table.json driven by the posterior mean of z.\"\"\"\nimport math, json, os\nimport numpy as np\n\nK = 1e6\nG2 = 0.997                     # rival's 30 bps fee (public rule of the normalizer)\nLG2 = -math.log(G2)            # 30.045 bps\n_T = json.load(open(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'oracle_table.json')))\nASK = np.array(_T['ask']); BID = np.array(_T['bid']); ARBF = _T['arb_flag']\nKN = np.arange(-8, 9) * 0.003\n\n\ndef table_fees(lns, lnp, arbw):\n    d = lns - lnp\n    a = float(np.interp(d, KN, ASK)) + ARBF * arbw\n    b = float(np.interp(d, KN, BID)) + ARBF * arbw\n    fa = 1.0 - math.exp(d - a * 0.003)\n    fb = 1.0 - math.exp(-b * 0.003 - d)\n    return min(max(fb, 0.0), 0.1), min(max(fa, 0.0), 0.1)\n\n\nclass RivalFilter:\n    def __init__(self, N=80, h=3e-4, sigma=0.000945, jump_rate=0.4, share=1.0,\n                 size_mean=20.0, size_sd=1.2, rho_ret=0.4, router=True, rival=True):\n        self.N, self.h = N, h\n        self.router, self.rival = router, rival\n        self.rho_ret = rho_ret\n        self.mu = math.log(size_mean) - 0.5 * size_sd ** 2\n        self.ssd = size_sd\n        idx = np.arange(N)\n        # diffusion matrix along z (rows): P <- Tz @ P\n        s = sigma / h\n        D = idx[:, None] - idx[None, :]\n        Tz = np.exp(-0.5 * (D / s) ** 2); Tz /= Tz.sum(0, keepdims=True)\n        self.Tz = Tz\n        # rival 30bps band in cells\n        k = int(round(LG2 / h)); self.k = k\n        J = idx[None, :] - idx[:, None]           # j - i\n        self.Bm = (np.abs(J) <= k).astype(float)\n        self.Um = (J > k).astype(float); self.Lm = (J < -k).astype(float)\n        self.rhi = idx[idx + k < N]; self.rlo = idx[idx - k >= 0]\n        # rival unobserved-retail jump kernel on w (columns): P <- P @ Tw\n        rng = np.random.default_rng(12345)\n        S = rng.lognormal(self.mu, size_sd, 200000) * share\n        dl = 2.0 * np.log1p(G2 * S / 1e4)          # ln-impact on a 10000-Y pool\n        sgn = np.where(rng.random(S.size) < 0.5, 1.0, -1.0)\n        cells = np.clip(np.round(sgn * dl / h).astype(int), -N + 1, N - 1)\n        ker = np.bincount(cells + N - 1, minlength=2 * N - 1).astype(float); ker /= ker.sum()\n        p0 = math.exp(-jump_rate)\n        ker *= (1 - p0); ker[N - 1] += p0\n        Tw = np.zeros((N, N))\n        for j in range(N):\n            Tw[j] = ker[(idx - j) + N - 1]\n        Tw /= Tw.sum(1, keepdims=True)\n        self.Tw = Tw\n        self.zoff = (idx - N // 2) * h             # offsets from center (both axes)\n\n    # ---------------- state helpers\n    def init(self, *hidden):                       # hidden args (sigma, lam, size) ignored\n        N = self.N\n        self.c = math.log(100.0)                   # from initial reserves 10000/100\n        self.P = np.zeros((N, N)); self.P[N // 2, N // 2] = 1.0\n        self.x, self.y = 100.0, 10000.0\n        self.last_t = -1\n        self.fb, self.fa = table_fees(math.log(100.0), math.log(100.0), 0.0)\n        self.arbw = 0.0; self.n_arb = 0.0; self.n_fallback = 0\n        return self.fb, self.fa\n\n    def zgrid(self):\n        return self.c + self.zoff\n\n    def mean_lnp(self):\n        m = self.P.sum(1); return float(self.c + (m * self.zoff).sum() / m.sum())\n\n    def recenter(self):\n        m = self.P.sum(1); mi = (m * np.arange(self.N)).sum() / m.sum()\n        sh = int(round(mi - self.N // 2))\n        if abs(sh) >= 6:\n            P = np.roll(self.P, -sh, 0)\n            if self.rival: P = np.roll(P, -sh, 1)\n            if sh > 0:\n                P[-sh:, :] = 0\n                if self.rival: P[:, -sh:] = 0\n            else:\n                P[:-sh, :] = 0\n                if self.rival: P[:, :-sh] = 0\n            s = P.sum()\n            if not (s > 1e-9 and np.isfinite(s)):   # w mass fell off grid: reset w | z to rival band\n                self.n_fallback += 1\n                mz = np.roll(m, -sh); mz = np.clip(mz, 0, None)\n                if sh > 0: mz[-sh:] = 0\n                else: mz[:-sh] = 0\n                if mz.sum() <= 0: mz = np.zeros(self.N); mz[self.N // 2] = 1.0\n                P = mz[:, None] * self.Bm / self.Bm.sum(1, keepdims=True); s = P.sum()\n            self.P = P / s; self.c += sh * self.h\n\n    def own_band_mask(self):\n        z = self.zgrid(); ls = math.log(self.y / self.x)\n        lo = ls + math.log(1 - self.fb); hi = ls - math.log(1 - self.fa)\n        return ((z >= lo - 0.5 * self.h) & (z <= hi + 0.5 * self.h)).astype(float)\n\n    def step(self, silent):\n        P = self.P\n        if self.rival:\n            P = P @ self.Tw                       # previous step's unobserved rival retail\n        P = self.Tz @ P                           # GBM diffusion of p\n        if self.rival:                            # rival arb clamps s2 into [p*g2, p/g2]\n            up = (P * self.Um).sum(1); lo = (P * self.Lm).sum(1)\n            P = P * self.Bm\n            P[self.rhi, self.rhi + self.k] += up[self.rhi]\n            P[self.rlo, self.rlo - self.k] += lo[self.rlo]\n        if silent:\n            P2 = P * self.own_band_mask()[:, None]\n            s = P2.sum()\n            P = P2 if s > 1e-300 else P\n        s = P.sum()\n        if not (s > 1e-300 and np.isfinite(s)):\n            self.n_fallback += 1; P = self.P; s = P.sum()\n        self.P = P / s\n\n    # ---------------- router likelihood over grid, density in own fill amount\n    def router_lik(self, recv_x, amt, x1, y1, fee):\n        \"\"\"recv_x False: trader buys X paying amt Y; True: trader sells amt X.\n        Returns L (N_z x N_w) and post-trade rival w cell coordinate per w (or None).\"\"\"\n        g = 1.0 - fee; r = math.sqrt(g / G2)       # x1*y1 = x2*y2 = K  =>  r constant\n        w = self.c + self.zoff\n        s2 = np.exp(w); x2 = np.sqrt(K / s2); y2 = np.sqrt(K * s2)\n        Jc = (g + r * G2) / (r * G2)\n        if not recv_x:\n            S = ((amt * (g + r * G2) + y1) / r - y2) / G2          # Y size if interior\n            inter = S > amt + 1e-4\n            allus = (r * y2 - y1) / g >= amt                        # whole order to us\n            lnS = np.log(np.where(inter, S, amt))\n            f = np.exp(-0.5 * ((lnS - self.mu) / self.ssd) ** 2) / (np.where(inter, S, amt) * self.ssd * 2.5066282746)\n            L = np.where(inter, f * Jc, np.where(allus, f, 0.0))\n            y2n = np.where(inter, y2 + G2 * (S - amt), y2)\n            wn = np.log(y2n * y2n / K)\n            return np.broadcast_to(L[None, :], (self.N, self.N)), wn\n        tx = ((amt * (g + r * G2) + x1) / r - x2) / G2              # X size if interior\n        inter = tx > amt + 1e-4\n        allus = (r * x2 - x1) / g >= amt\n        tt = np.where(inter, tx, amt)\n        pz = np.exp(self.zgrid())[:, None]\n        Sy = tt[None, :] * pz\n        f = np.exp(-0.5 * ((np.log(Sy) - self.mu) / self.ssd) ** 2) / (Sy * self.ssd * 2.5066282746) * pz\n        L = np.where(inter[None, :], f * Jc, np.where(allus[None, :], f, 0.0))\n        x2n = np.where(inter, x2 + G2 * (tx - amt), x2)\n        wn = np.log(K / (x2n * x2n))\n        return L, wn\n\n    def remap_w(self, P, wn):\n        pos = (wn - self.c) / self.h + self.N // 2\n        pos = np.clip(pos, 0, self.N - 1 - 1e-9)\n        lo = np.floor(pos).astype(int); fr = pos - lo\n        M = np.zeros((self.N, self.N))\n        ar = np.arange(self.N)\n        M[ar, lo] += 1 - fr\n        hi = np.minimum(lo + 1, self.N - 1)\n        M[ar, hi] += fr\n        return P @ M\n\n    def flat_lik(self, recv_x, amt):\n        # ablation: router information removed; density of own fill as if lognormal size\n        a = amt if not recv_x else amt * math.exp(self.mean_lnp())\n        f = math.exp(-0.5 * ((math.log(a) - self.mu) / self.ssd) ** 2) / (a * self.ssd * 2.5066282746)\n        if recv_x: f *= math.exp(self.mean_lnp())\n        return np.full((self.N, self.N), f), None\n\n    # ---------------- main callback (observables only)\n    def on_trade(self, recv_x, ax, ay, t, x, y, *hidden):\n        x1, y1 = self.x, self.y\n        first = t > self.last_t\n        if first:\n            for _ in range(self.last_t + 1, t):\n                self.step(True)\n            self.step(False)\n            self.last_t = t\n        amt = ay if not recv_x else ax                       # amount paid in by trader\n        fee = self.fa if not recv_x else self.fb\n        g = 1.0 - fee\n        if self.router:\n            L, wn = self.router_lik(recv_x, amt, x1, y1, fee)\n        else:\n            L, wn = self.flat_lik(recv_x, amt)\n        lnpost = math.log(y / x)\n        P = self.P\n        Pr = P * L\n        if first:\n            band = self.own_band_mask()[:, None]\n            Pr = Pr * band\n            wret = Pr.sum() * self.rho_ret * ((y if not recv_x else x) / g)\n            za = lnpost - math.log(g) if not recv_x else lnpost + math.log(g)\n            pos = (za - self.c) / self.h + self.N // 2\n            if 0 <= pos < self.N - 1:\n                i0 = int(pos); fr = pos - i0\n                row = P[i0] * (1 - fr) + P[i0 + 1] * fr\n                warb = 2.0 * row.sum() / self.h\n                Pa = np.zeros_like(P); Pa[i0] = row * (1 - fr); Pa[i0 + 1] = row * fr\n            else:\n                warb = 0.0; Pa = None\n        else:\n            wret = 1.0; warb = 0.0; Pa = None\n        sr = Pr.sum()\n        if sr > 0 and wn is not None:\n            Pr = self.remap_w(Pr, wn)\n        tot = warb + (wret if sr > 0 else 0.0)\n        if tot <= 0 or not np.isfinite(tot):          # numerical fallback: keep prior, no update\n            pa = 0.0; Pn = P\n        else:\n            pa = warb / tot\n            Pn = (Pr / sr) * (1 - pa) if sr > 0 else 0.0\n            if pa > 0:\n                Pn = Pn + Pa / Pa.sum() * pa\n        s = float(np.sum(Pn)) if not np.isscalar(Pn) else 0.0\n        if not (s > 1e-300 and np.isfinite(s)):\n            self.n_fallback += 1; Pn = P; s = P.sum()\n        self.P = Pn / s\n        self.recenter()\n        self.x, self.y = x, y\n        self.arbw = pa; self.n_arb += pa\n        self.fb, self.fa = table_fees(lnpost, self.mean_lnp(), pa)\n        return self.fb, self.fa\n\n\nclass OracleTable:\n    \"\"\"Same table, TRUE p and true arb label (offline ceiling arm).\"\"\"\n    def init(self, *a): return table_fees(math.log(100.0), math.log(100.0), 0.0)\n    def on_trade(self, recv_x, ax, ay, t, x, y, arb, p, s2):\n        return table_fees(math.log(y / x), math.log(p), 1.0 if arb else 0.0)\n","harness.py":"\"\"\"Harness: python -I harness.py ARM SEED0 SEED1 NSTEPS OUT.json [key=val ...]\nARM in {rival, norouter, norival, oracle, fixed35}. Policies see only observables: the Strip\nwrapper drops hidden args (init params, arb label, true p, rival spot) before calling the policy\nand uses them only to score RMS error and arb-label agreement.\"\"\"\nimport sys, os, json, math, time\nfrom multiprocessing import Pool\nsys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))\nimport replica\nfrom rival_filter import RivalFilter, OracleTable\n\n\nclass Strip:\n    def __init__(self, pol, poison=False):\n        self.pol = pol; self.poison = poison\n        self.se = 0.0; self.n = 0; self.arb_hit = 0; self.arb_n = 0; self.arb_fp = 0; self.n_ret = 0\n    def init(self, *a):\n        return self.pol.init(*([float('nan')] * len(a) if self.poison else []))\n    def on_trade(self, rx, ax, ay, t, x, y, arb, p, s2):\n        fb, fa = self.pol.on_trade(rx, ax, ay, t, x, y)\n        e = (self.pol.mean_lnp() - math.log(p)) * 1e4\n        self.se += e * e; self.n += 1\n        pa = self.pol.arbw\n        if arb:\n            self.arb_n += 1; self.arb_hit += pa > 0.5\n        else:\n            self.n_ret += 1; self.arb_fp += pa > 0.5\n        return fb, fa\n\n\ndef make(arm, kw):\n    if arm == 'oracle': return OracleTable()\n    if arm == 'fixed35': return replica.Fixed(0.0035)\n    if arm == 'norouter': kw = dict(kw, router=False)\n    if arm == 'norival': kw = dict(kw, router=False, rival=False)\n    kw = dict(kw); poison = bool(kw.pop('_poison', False))\n    return Strip(RivalFilter(**kw), poison=poison)\n\n\ndef one(args):\n    arm, seed, n, kw = args\n    pol = make(arm, dict(kw))\n    t0 = time.time()\n    r = replica.run(seed, pol, n_steps=n)\n    out = dict(seed=seed, edge=r['edge'], retail=r['retail'], arb=r['arb'], rv=r['rv'], av=r['av'],\n               fb=r['fb'], fa=r['fa'], sec=time.time() - t0)\n    if isinstance(pol, Strip):\n        out.update(rms=math.sqrt(pol.se / max(pol.n, 1)), arb_recall=pol.arb_hit / max(pol.arb_n, 1),\n                   arb_fp=float(pol.arb_fp / max(pol.n_ret, 1)), n_arb=pol.arb_n,\n                   n_fallback=pol.pol.n_fallback)\n        out['arb_recall'] = float(out['arb_recall'])\n    return out\n\n\nif __name__ == '__main__':\n    arm, s0, s1, n, outp = sys.argv[1], int(sys.argv[2]), int(sys.argv[3]), int(sys.argv[4]), sys.argv[5]\n    kw = {}\n    for a in sys.argv[6:]:\n        k, v = a.split('='); kw[k] = float(v) if k != '_poison' else bool(int(v))\n    done = {}\n    if os.path.exists(outp):\n        done = {d['seed']: d for d in json.load(open(outp))}\n    todo = [(arm, s, n, kw) for s in range(s0, s1 + 1) if s not in done]\n    with Pool(8) as pool:\n        for d in pool.imap_unordered(one, todo):\n            done[d['seed']] = d\n            json.dump(sorted(done.values(), key=lambda d: d['seed']), open(outp, 'w'))\n    rows = list(done.values())\n    print(arm, len(rows), 'edge', sum(r['edge'] for r in rows) / len(rows),\n          'rms', sum(r.get('rms', 0) for r in rows) / len(rows), 'sec', sum(r['sec'] for r in rows) / len(rows))\n","leak.py":"\"\"\"Leakage test: hidden args poisoned (init params NaN; arb label flipped, p and s2 scaled)\nmust leave the fee path and edge bit-identical.\"\"\"\nimport sys, os\nsys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))\nimport replica\nfrom harness import Strip\nfrom rival_filter import RivalFilter\n\n\nclass Poison(Strip):\n    def on_trade(self, rx, ax, ay, t, x, y, arb, p, s2):\n        return Strip.on_trade(self, rx, ax, ay, t, x, y, not arb, p * 1.01, s2 * 0.97)\n\n\nfor seed in (10000, 10001):\n    a = replica.run(seed, Strip(RivalFilter(jump_rate=0.8)), n_steps=3000)\n    b = replica.run(seed, Poison(RivalFilter(jump_rate=0.8), poison=True), n_steps=3000)\n    print(seed, a['edge'], b['edge'], 'IDENTICAL' if (a['edge'], a['fb'], a['fa']) == (b['edge'], b['fb'], b['fa']) else 'DIFFER')\n","build.py":"import json, math, os, sys\nD = os.path.dirname(os.path.abspath(__file__)); R = os.path.join(D, '..', 'res')\nout_path = sys.argv[1]\nL = lambda f: {d['seed']: d for d in json.load(open(os.path.join(R, f)))}\nrv, orc, f35, ab = L('ev_rival.json'), L('ev_oracle.json'), L('ev_fixed35.json'), L('ab_norouter.json')\ntrs = {k: L(f) for k, f in [('j04', 'tr_j04.json'), ('j08', 'tr_j08.json'), ('oracle', 'tr_oracle.json')]}\n\n\ndef st(xs):\n    n = len(xs); m = sum(xs) / n; sd = math.sqrt(sum((x - m) ** 2 for x in xs) / (n - 1)); se = sd / math.sqrt(n)\n    return dict(n=n, mean=round(m, 3), sd=round(sd, 3), se=round(se, 3), ci95=[round(m - 1.96 * se, 3), round(m + 1.96 * se, 3)])\n\n\ndef mean(d, k): return round(sum(r[k] for r in d.values()) / len(d), 3)\n\n\nS = sorted(rv)\nassert S == list(range(10000, 10256)) and sorted(orc) == S and sorted(f35) == S\narm = lambda d: {k: mean(d, k) for k in ('edge', 'retail', 'arb', 'rv', 'av', 'fb', 'fa')}\nmetrics = dict(\n    replica_eval_10000_10255=dict(\n        rival_model=dict(arm(rv), rms_bps=mean(rv, 'rms'), arb_recall=mean(rv, 'arb_recall'), arb_false_pos=mean(rv, 'arb_fp'),\n                         fallbacks_per_seed=mean(rv, 'n_fallback'), sec_per_seed_8proc=mean(rv, 'sec')),\n        oracle_table_true_p=arm(orc), fixed_35bps=arm(f35),\n        paired_rival_minus_oracle=st([rv[s]['edge'] - orc[s]['edge'] for s in S]),\n        paired_rival_minus_fixed35=st([rv[s]['edge'] - f35[s]['edge'] for s in S]),\n        paired_retail_rival_minus_oracle=st([rv[s]['retail'] - orc[s]['retail'] for s in S]),\n        paired_arb_rival_minus_oracle=st([rv[s]['arb'] - orc[s]['arb'] for s in S])),\n    replica_fit_20600_20727=dict(\n        jump_rate_0p4=dict(edge=mean(trs['j04'], 'edge'), rms_bps=mean(trs['j04'], 'rms')),\n        jump_rate_0p8=dict(edge=mean(trs['j08'], 'edge'), rms_bps=mean(trs['j08'], 'rms')),\n        oracle_table=dict(edge=mean(trs['oracle'], 'edge')),\n        paired_j08_minus_j04=st([trs['j08'][s]['edge'] - trs['j04'][s]['edge'] for s in trs['j04']]),\n        paired_j08_minus_oracle=st([trs['j08'][s]['edge'] - trs['oracle'][s]['edge'] for s in trs['j04']])))\nA = sorted(ab); assert A == list(range(10000, 10064))\nablation = dict(\n    name='router likelihood + rival latent dimension removed (router=False): retail fill likelihood replaced by a w-flat lognormal size density; rival jump/clamp still run but carry no information to z since nothing observes w. No retuning (jump_rate=0.8 frozen).',\n    seeds='10000..10063, 10000 steps',\n    full_model=dict(edge=round(sum(rv[s]['edge'] for s in A) / 64, 3), rms_bps=round(sum(rv[s]['rms'] for s in A) / 64, 3)),\n    ablated=dict(arm(ab), rms_bps=mean(ab, 'rms'), arb_recall=mean(ab, 'arb_recall')),\n    oracle=dict(edge=round(sum(orc[s]['edge'] for s in A) / 64, 3)),\n    paired_full_minus_ablated=st([rv[s]['edge'] - ab[s]['edge'] for s in A]),\n    paired_rms_full_minus_ablated_bps=st([rv[s]['rms'] - ab[s]['rms'] for s in A]))\ncols = ['seed', 'edge', 'edge_oracle', 'edge_fixed35', 'retail', 'arb', 'retail_vol_y', 'arb_vol_y', 'rms_bps', 'oracle_retail', 'oracle_arb', 'arb_recall']\nrows = [[s, round(rv[s]['edge'], 2), round(orc[s]['edge'], 2), round(f35[s]['edge'], 2), round(rv[s]['retail'], 2), round(rv[s]['arb'], 2),\n         round(rv[s]['rv']), round(rv[s]['av']), round(rv[s]['rms'], 2), round(orc[s]['retail'], 2), round(orc[s]['arb'], 2), round(rv[s]['arb_recall'], 3)] for s in S]\nabrows = [[s, round(ab[s]['edge'], 2), round(ab[s]['retail'], 2), round(ab[s]['arb'], 2), round(ab[s]['rms'], 2)] for s in A]\nsrc = {f: open(os.path.join(D, f)).read() for f in ('rival_filter.py', 'harness.py', 'leak.py', 'build.py')}\nextra = json.load(open(os.path.join(D, 'extra.json')))\nres = dict(extra)\nres.update(metrics=metrics, ablation=ablation,\n           per_seed=dict(columns=cols, arm='rival_model jump_rate=0.8 frozen; oracle=oracle_table with true p and true arb flag; fixed35', rows=rows),\n           ablation_per_seed=dict(columns=['seed', 'edge', 'retail', 'arb', 'rms_bps'], rows=abrows),\n           source_code=src)\ns = json.dumps(res, separators=(',', ':'))\nprint(len(s.encode()))\nassert len(s.encode()) <= 64000\nopen(out_path, 'w').write(s)\nprint(json.dumps(metrics, indent=1)); print(json.dumps(ablation, indent=1))\n"}}