What is Market Regime?

Market regime describes the current state of the market: bullish (uptrend), bearish (downtrend), or sideways (range-bound). Different strategies work in different regimes. Detecting the current regime allows you to adapt your trading approach dynamically.

Defining Regimes

def classify_regime(prices, lookback=20, threshold=0.02):
    """Classify market regime based on price trends."""
    returns = prices.pct_change(lookback)
    
    regimes = pd.Series(index=prices.index, dtype=str)
    regimes[returns > threshold] = 'BULL'
    regimes[returns < -threshold] = 'BEAR'
    regimes[(returns >= -threshold) & (returns <= threshold)] = 'SIDEWAYS'
    
    return regimes

Features for Regime Detection

  • Trend: Moving average slopes, ADX, price vs moving averages
  • Momentum: RSI, MACD, rate of change
  • Volatility: ATR, Bollinger Band width, VIX level
  • Volume: Volume trend, OBV slope
  • Cross-market: Sector correlations, global market trends

XGBoost Regime Classifier

import xgboost as xgb
from sklearn.metrics import classification_report

# Create features
X = create_regime_features(nifty_data)
y = classify_regime(nifty_data['Close'])

# Train classifier
model = xgb.XGBClassifier(
    n_estimators=300,
    max_depth=4,
    learning_rate=0.05,
    objective='multi:softmax',
    num_class=3,
    random_state=42
)
model.fit(X_train, y_train)

# Predict regime
predicted_regime = model.predict(X_test)

Walk-Forward Results

Regime detection accuracy on Nifty 50 (2020-2025):

  • Bull detection: 72% accuracy
  • Bear detection: 68% accuracy
  • Sideways detection: 61% accuracy
  • Overall accuracy: 67%

Regime-Adaptive Strategy

def regime_adaptive_strategy(model_regime, model_signal, X):
    """Adapt strategy based on detected regime."""
    regime = model_regime.predict(X)
    
    if regime == 'BULL':
        # Use momentum strategy
        signal = model_signal.predict(X)
        return signal
    elif regime == 'BEAR':
        # Use mean-reversion or hedging
        signal = model_signal.predict(X)
        return -signal  # Reverse signals
    else:  # SIDEWAYS
        # Use range-trading
        return 'HOLD'  # No positions

Practical Applications

  • Position sizing: Larger positions in trending markets, smaller in sideways
  • Strategy selection: Momentum in bull, mean-reversion in bear, options selling in sideways
  • Risk management: Tighter stops in bear markets

SEBI Disclaimer

This article is for educational purposes only. Trading involves substantial risk. Past performance does not guarantee future results. Regime detection is not perfect and should be used with other analysis methods.

Regime Labels From a Rolling Sharpe

Before XGBoost labels anything, define what a regime means with a durable, arbitrary metric. A rolling 20-day annualised risk-return ratio does the job:

  1. Compute the 20-day rolling return scaled by 20-day volatility annualised.
  2. Label bull when the ratio sits above +0.5 for five consecutive days, bear below -0.5, otherwise sideways.
  3. Require confirmation days so transition churn does not label noise into whipsaw regimes.

The label set should be audited against the chart a trader would draw; if your labels call a 6-week flag "bull" when VIX is spiking, the labels are lying.

Transition Probabilities as a Risk Thermometer

Once trained, the model's implied transition matrix is the most useful output a trader can consume, even more than today's classification:

  • Diagonal values show persistence: a bullish regime that self-transitions at 0.85 supports trend overlays.
  • Off-diagonals that spike (sideways to bear rising from 0.05 to 0.15) are the early warning worth hedging.
  • Report the matrix in the morning brief; regime awareness is a positioning input, not a trade signal.

A Second-Stage Signal on Top of Regime

The classifier labels regime; a second stage converts it into trade type. Never hand raw regime output to an order:

  • Bull-confirmed: trend-following overlays and long-premium momentum structures deserve the regime's blessing.
  • Bear-confirmed: insurance is strategic; build protective puts pre-crash visibility instead of reacting inside it.
  • Sideways-confirmed: option-selling and calendar structures get the green light; momentum systems get a veto.

The two-stage design means the regime model is a filter and the trade logic stays independent, keeping each auditable alone.

Calibrating to Stress Slices

A regime model trained across five peaceful years is a paper tiger until it has seen the sharp edges. Stress-calibrate deliberately:

  • Walk-forward through COVID 2020, the 2022 rate-shock taper and a Budget-move week, and measure transition forecasts through those windows.
  • If the model calls every crash day "sideways" because the rolling label lags, add a volatility-only regime leg; crash detection needs vol, not just returns.

Position Sizing by Regime Probability

The strongest compounding lever is regime-conscious sizing:

  • Scale new risk linearly with the winning regime's probability: full size only above 0.70, half size in the 0.50-0.70 band.
  • Concentrate option-selling allocation only in sideways-confirmed states; the crash years were sold by traders who ignored the bear-probability rise.
  • Cap total daily exposure at 60% of the average in ambiguous states; being wrong on regime twice in a row is normal, and surviving it is the strategy.

XGBoost regime detection converts hindsight into foresight when its labels are honest, its transitions are watched and its output gates a human trading layer instead of replacing it. The market does not know regimes; it only produces conditions. The model's job is to name them while there is time to act.