regime-detection

Market regime identification using volatility clustering, trend detection, and statistical methods for adaptive trading

By agiprolabs · 443 installs

npx skills add agiprolabs/claude-trading-skills --skill regime-detection

Source repository · Upstream listing

Regime Detection Identify the current market regime so you can pick the right strategy, size positions correctly, and avoid deploying trend following logic in a ranging market (or vice versa). Why Regime Detection Matters Every strategy has a "home regime." A momentum strategy prints money in a clean uptrend but bleeds in a choppy range. A mean reversion grid thrives in low volatility consolidation but gets steamrolled by a trending breakout. Regime detection tells you which playbook to use right now . Key benefits: Strategy selection : Route signals to the right strategy for the current environment Position sizing : Reduce exposure in hostile regimes, increase in favorable ones Stop adaptation : Wider stops in high vol regimes, tighter in low vol trends Drawdown control : Sit out "danger zone" regimes (high vol + no trend) Core Regime Dimensions Two orthogonal axes define the four quadrant regime model: Low Volatility High Volatility Trending Q1: Clean trend — best for trend following Q2: Volatile trend — momentum with caution Ranging Q3: Quiet range — mean reversion paradise Q4: Choppy chaos — reduce or sit out A third dimension — mean reversion tendency (Hurst exponent) — refines Q3 by telling you how reliably price reverts. Simple Approaches (No ML Required) 1. ATR Volatility Percentile Rank the current ATR against its own recent history to get a 0–100 percentile score. < 25th percentile → Low volatility regime 25th–75th → Normal volatility 75th percentile → High volatility regime 2. ADX Trend Strength ADX above 25 signals a trending market; below 20 signals a range. 3. EMA Slope + Price Position 4. Bollinger Band Width Percentile BB width (upper lower) / middle as a volatility proxy. A "squeeze" (low percentile) often precedes a breakout. Statistical Approaches Rolling Hurst Exponent The Hurst exponent H classifies time series behavior: H < 0.4 → Mean reverting (anti persistent) 0.4 ≤ H ≤ 0.6 → Random walk (no exploitable structure) H 0.6 → Trending (persistent) Computed via the Rescaled Range (R/S) method. See references/methodology.md for the full derivation. Change Point Detection (CUSUM) Detects abrupt shifts in mean or variance of a return series. Hidden Markov Models For 2–3 state regime models using hmmlearn . This is optional — all core functionality works with numpy/pandas only. See references/methodology.md for details on feature selection and state interpretation. Crypto Specific Considerations Regime Speed Crypto regimes change much faster than equities: Parameter Equities Crypto (large cap) Crypto (micro cap / PumpFun) ATR lookback 100–200 bars 50–100 bars 20–50 bars ADX period 14–28 10–14 7–10 Regime persistence Weeks–months Days–weeks Hours–days Hurst window 200+ bars 100 bars 50 bars Volume as a Regime Signal In crypto, volume confirms regime quality: High volume + trend → Strong conviction, ride it Low volume + trend → Drift, unreliable, reduce size High volume + range → Distribution or accumulation, watch for breakout Low volume + range → Dead market, skip PumpFun Micro Regimes New token launches follow a stereotyped sequence: 1. Launch pump (minutes): Vertical move, extreme vol, no mean reversion 2. First dump (minutes–hours): Profit taking, high vol, trending down 3. Consolidation (hours–days): Low vol range, potential mean reversion 4. Second wave or death : Either breaks out again (new trend) or fades to zero Each micro regime lasts minutes to hours. Use 1 minute bars with 20–50 bar windows. Combined Regime Classification Strategy Adaptation See references/strategy adaptation.md for the full regime strategy matrix. Quick reference: Current Regime Action Low vol + trending up Full size trend following, tight stops High vol + trending Half size momentum, wide stops Low vol + ranging Mean reversion / grid strategies High vol + ranging Reduce to 25% size or sit out Regime transition Flatten or reduce to minimum size Integration with Other Skills pandas ta : Compute ATR, ADX, Bollinger Bands, EMAs volatility modeling : Advanced vol forecasting (GARCH, realized vol) strategy framework : Route signals through regime filter before execution position sizing : Scale position size by regime volatility risk management : Adjust portfolio risk limits per regime Files References references/methodology.md — Detailed math for Hurst exponent, HMM, change point detection, and volatility estimation methods references/strategy adaptation.md — Full regime strategy matrix with position sizing, stop adaptation, and PumpFun micro regime playbook Scripts scripts/detect regime.py — Compute regime indicators on live or demo data, classify into 4 quadrant model scripts/regime backtest.py — Compare regime adaptive vs static strategy on synthetic data with clear regime transitions