Skip to content

Add market regime detection for conditional model selection - #190

Merged
ch55secake merged 5 commits into
mainfrom
copilot/add-market-regime-detection
Apr 20, 2026
Merged

Add market regime detection for conditional model selection#190
ch55secake merged 5 commits into
mainfrom
copilot/add-market-regime-detection

Conversation

Copilot AI commented Apr 19, 2026

Copy link
Copy Markdown
Contributor

Description

Adds three regime signals as first-class ML features and a regime-routing trading strategy. The pipeline previously applied identical logic regardless of market conditions; now each bar is labelled with volatility, trend, and GMM-based regime state so models and strategies can condition on market context.

Changes in this pull request

  • src/feature/regime.py (new) — three detectors exposed via classify_regime:

    • detect_volatility_regime — rolling vol bucketed into low/medium/high via quantile thresholds
    • detect_trend_regime — bull/bear/sideways from price vs 50d/200d MAs
    • detect_gmm_regime — Gaussian Mixture Model on (rolling mean return, rolling vol); components sorted so state 0 is always the most bearish; includes assert gmm.means_ is not None guard to satisfy static type checking
  • src/feature/feature_engineering.py_add_regime_features() appends Regime_Volatility, Regime_Trend, Regime_GMM to every feature matrix (shifted with all other indicators)

  • src/feature/__init__.py — exports classify_regime and regime constants

  • src/simulation/strategy/regime_aware.py (new) — RegimeAwareStrategy registered as "regime_aware", routes each bar to one of three sub-logics:

    • Bull → momentum (enter on positive pred, exit when pred turns negative)
    • Bear → conservative (close longs only, no new entries)
    • Sideways → mean-reversion (higher entry/exit threshold to suppress noise)
  • src/simulation/strategy/__init__.py — imports the new strategy

  • src/pipeline/base_pipeline.py_log_regime_coverage logs train/test regime distributions per symbol; warns when the test split is single-regime

  • tests/feature/test_regime.py — 28 unit tests covering all detectors, edge cases (tiny series fallback, state-count clamping), and FeatureEngineering integration

  • tests/simulation/test_regime_strategy.py — 21 unit tests covering all strategy branches and a full simulation loop

Copilot AI and others added 2 commits April 20, 2026 07:43
…REGIME_HMM→COL_REGIME_GMM, fix docstrings

Agent-Logs-Url: https://github.com/ch55secake/hyperion/sessions/dae6ab1d-d0b0-4dac-8f2c-35f7ecc9636d

Co-authored-by: ch55secake <87881861+ch55secake@users.noreply.github.com>
@ch55secake
ch55secake marked this pull request as ready for review April 20, 2026 20:10
@ch55secake ch55secake changed the title [WIP] Add market regime detection for conditional model selection Add market regime detection for conditional model selection Apr 20, 2026
@ch55secake

Copy link
Copy Markdown
Owner

@copilot fix the typecheck

Copilot AI commented Apr 20, 2026

Copy link
Copy Markdown
Contributor Author

@copilot fix the typecheck

Fixed in 3a3a0b8. Added assert gmm.means_ is not None after fit_predict in detect_gmm_regime — the attribute is always populated post-fit but ty rightly flags it as potentially None without an explicit guard.

@ch55secake
ch55secake merged commit 77bdbac into main Apr 20, 2026
8 checks passed
@ch55secake
ch55secake deleted the copilot/add-market-regime-detection branch April 20, 2026 20:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature: Add market regime detection for conditional model selection

2 participants