research/regime.py: Step 0 probe (labelable-session/SPY-coverage STOP gate),
Step 1 build-features (regime_features: pre-open breadth/tape + prior-close
SPY momentum/vol + trailing bot expR, label = mean _sim_baseline_r over the
session's setup fires) + walk-forward threshold_v1 rule, Step 2 walk-forward
meta_v1 (shallow sklearn GBM), Step 4 OOS/leakage-audit helpers
(oos_split/sequential_folds/session_expr_delta/full_sample_fit_threshold).
Step 3 (HMM) deferred per scope — statsmodels stays absent.
replay.py: new iv_regime_gate intervention (keep-or-zero a fire on a
pre-computed session regime score, fail-open on no score row) wired into
_compute_fire + run(), mirroring rank_one_bullet's shape.
experiments/regime_threshold_v1.json + regime_meta_v1.json register the two
model variants against the shared population/bars/fidelity contract.
All new code is unit-tested against isolated EventStore(":memory:") schemas
only — no production DB read or written. Live-trading paths untouched.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
35 lines
2.0 KiB
SQL
35 lines
2.0 KiB
SQL
-- Regime gate schema (plan 011) — a FREE-data daily signal (session-level
|
|
-- metalabel) that decides whether the ORB trades AT ALL today, separate from
|
|
-- which NAME to trade (strategy/population.py). Applied by
|
|
-- research.regime.apply_schema on first run (same idiom as
|
|
-- storage/experiments_schema.sql). Idempotent: safe to run repeatedly.
|
|
|
|
-- One row per labelable session_date: PRE-OPEN/prior-close-lagged features +
|
|
-- the session's OWN outcome label. label_* are OUTCOME columns computed from
|
|
-- the session's setup fires — NEVER read back as model features (see
|
|
-- research.regime.FEATURE_COLS / test_regime_features_no_label_leak).
|
|
CREATE TABLE IF NOT EXISTS regime_features (
|
|
session_date DATE PRIMARY KEY,
|
|
breadth_gap DOUBLE PRECISION, -- fraction of session's setups with gap_pct>0
|
|
breadth_rvol DOUBLE PRECISION, -- median relative_volume across session's setups
|
|
tape_regime DOUBLE PRECISION, -- ordinal: trend_down=-1, chop=0, trend_up=1
|
|
spy_mom5 DOUBLE PRECISION, -- SPY 5-session momentum as of PRIOR close
|
|
spy_mom20 DOUBLE PRECISION, -- SPY 20-session momentum as of PRIOR close
|
|
spy_vol20 DOUBLE PRECISION, -- SPY 20-session realized vol as of PRIOR close
|
|
bot_trailing_expr_10d DOUBLE PRECISION, -- mean label_expR over the PRIOR 10 labelable sessions
|
|
label_expr DOUBLE PRECISION, -- OUTCOME: mean _sim_baseline_r over the session's setup fires
|
|
label_pos BOOLEAN, -- OUTCOME: label_expr > 0
|
|
computed_at TIMESTAMP
|
|
);
|
|
|
|
-- One row per (model, session): the walk-forward gate decision consumed by
|
|
-- research.experiments.replay's iv_regime_gate.
|
|
CREATE TABLE IF NOT EXISTS regime_scores (
|
|
model_version TEXT NOT NULL,
|
|
session_date DATE NOT NULL,
|
|
p_profit DOUBLE PRECISION,
|
|
favorable BOOLEAN NOT NULL,
|
|
computed_at TIMESTAMP NOT NULL,
|
|
PRIMARY KEY (model_version, session_date)
|
|
);
|