Explainable Regime-Aware Portfolio Optimization: The case for Robust Rolling Regime Detection
Abstract
We propose an explainable framework for cross-asset portfolio optimization under time-varying market regimes. Our approach leverages a robust rolling regime detection model (R2-RD) to identify latent market states with interpretable mean and covariance structures, and a K-Nearest Neighbors (KNN) model as a nonparametric benchmark. Both methods are embedded within a regime-aware mean–variance optimization (MVO) framework and evaluated via a strictly causal expanding-window backtest on monthly data. Using a diversified cross-asset universe, we find that R2-RD delivers superior risk-adjusted returns and drawdown control relative to KNN, highlighting the benefits of parametric structure, temporal consistency, and regime-aware allocation for medium-frequency portfolio construction. The results demonstrate that R2-RD not only improves performance but also provides a transparent mapping between observed market states and portfolio decisions.
Introduction
Financial markets exhibit persistent structural changes driven by macroeconomic cycles, monetary policy regimes, and shifts in risk appetite. Ignoring such regime dynamics can lead to unstable portfolio allocations and poor risk-adjusted performance. Regime-aware portfolio construction seeks to address this issue by conditioning expected returns and risks on latent market states. This paper compares two distinct approaches to regime detection:
- Rolling parametric regime detection using Hidden Markov Models with dynamically optimized regime count and robust regime label tracking (R2-RD);
- Nonparametric local regime approximation using K-Nearest Neighbors (KNN).
Data and Market Universe
The empirical analysis is conducted on a diversified cross-asset universe designed to capture major global risk factors. Monthly log-returns are constructed from adjusted close prices obtained via Yahoo Finance. The asset universe consists of:
- Equities: S&P 500 Index (SPX), representing U.S. equity market risk;
- Fixed Income: iShares 7–10 Year Treasury ETF (IEF), proxying interest rate and duration risk;
- Commodities: SPDR Gold Shares (GLD) and United States Oil Fund (USO), capturing inflation sensitivity and real asset exposure;
- Foreign Exchange: U.S. Dollar Index proxy (UUP), representing global risk-off dynamics and dollar strength.
Feature Representation
Both regime detection approaches operate on a shared feature space constructed from asset returns and risk measures. At each month t, the feature vector is defined as:
rt ∈ RN denotes the vector of monthly asset returns and σt is a six-month rolling volatility estimate. This representation captures both directional information and prevailing market uncertainty, which are key drivers of regime differentiation.
Robust Rolling Regime Detection (R2-RD)
Model Specification
Let zt ∈ \1,,K\ denote a latent market regime evolving according to a first-order Markov chain:
Rolling BIC-Based Regime Selection with Regime Emergence Constraint
At each rebalancing date t, Hidden Markov Models are estimated on an expanding window using all information available up to t-1. Candidate models are fit for a range of regime counts K ∈ ,t, , K\, and the optimal number of regimes is selected via the Bayesian Information Criterion (BIC):
LK denotes the maximized likelihood and pK the number of free parameters.Crucially, the lower bound on the candidate regime count is set dynamically according to:
Regime Label Matching for Robust Rolling Regime Detection (R2-RD)
One limitation of standard rolling HMM estimation is the label switching problem: regime labels at successive expanding windows may permute arbitrarily, leading to inconsistent regime identification over time. To address this, we introduce a regime label matching mechanism, inspired by Hirsa et Al (2024), which ensures temporal consistency of regime assignments across windows.
Let zpastt denote the regime labels from the previous expanding window and znewt the labels from the current window over an overlapping period. We construct a similarity matrix M ∈ RK × K with elements
We then solve the following linear assignment problem:
xij=1 if past regime i is matched to new regime j. The solution provides a permutation mapping that aligns the new regime labels with the past ones.Applying this mapping to
znewt produces aligned regime labels zalignedt that are consistent with historical regimes. These aligned labels are then used to compute regime probabilities πt(k) and the corresponding conditional moments μt and Σt for portfolio optimization.
This approach ensures:
- Temporal consistency of regime assignments,
- Smooth evolution of portfolio weights,
- Robustness to short-term label permutation artifacts.
Regime-Conditional Moments
Regime detection enters portfolio construction through probability-weighted return and covariance estimates:
πt(k) = P(zt = k | Ft-1). This mixture structure smooths estimation noise and stabilizes portfolio weights across regime transitions.
K-Nearest Neighbors Regime Approximation
Local Similarity Estimation
The KNN approach does not model latent regimes explicitly. Instead, it approximates regimes locally by identifying historical months whose feature vectors are closest to the current state:
Local Moment Estimation
Expected returns and covariances are estimated directly from the identified neighbors:
Portfolio Optimization
At each rebalancing date, portfolio weights are determined by solving the following constrained mean–variance optimization problem:
l1 penalty controls turnover, ensuring realistic trading behavior.
Backtesting Framework
The evaluation framework adheres to strict causality:
- Expanding-window estimation;
- Monthly rebalancing;
- Out-of-sample period from 2016 to present;
- No look-ahead bias.
Performance is assessed using annualized Sharpe ratio and maximum drawdown.
Pseudocodes
R2-RD: Robust Rolling Regime Detection + MVO
InitializeK0^* = 1,zpast =fort = T0toT: Construct feature matrix_τ\τ t-1Step 1: Rolling HMM estimation SetK,t arrow Kt-1^*# Regime emergence policy: no merging forK = K,ttoK: Fit HMM withKregimes using data up tot-1Compute BICKSelectKt^* arrow K BICKInfer raw regime labelsznewand probabilitiesπt(k)ifzpastis not empty: Step 2: Label matching via linear assignment Construct similarity matrixMij = _τ 1[zpast,τ = i \ &\ znew,τ = j]Solve linear assignment problem: Apply optimal mapping toznew zalignedelse:zaligned arrow znewUpdatezpast arrow zalignedStep 3: Compute regime-conditional momentsμt = Sum[k=1 to Kt^*] πt(k) μkΣt = Sum[k=1 to Kt^*] πt(k) ΣkStep 4: Solve MVO Solve: Observe returnrt+1and record PnL
KNN + MVO
fort = T0toT: Construct feature vectorxtIdentifyKnearest historical neighbors Estimateμt, Σtfrom neighbors Solve MVO to obtainwtObservert+1and record PnL
Empirical Results
This section presents the out-of-sample performance of the two regime-aware portfolio construction methods evaluated from January 2016 through the most recent available data. Performance is assessed using annualized Sharpe ratio and maximum drawdown, computed from monthly portfolio returns.
Performance Summary
Table summarizes the risk-adjusted performance downside risk of the two strategies. The robust rolling regime detection approach (R2-RD) delivers superior performance across both metrics, achieving a higher Sharpe ratio and substantially lower maximum drawdown relative to the KNN-based approach.
Out-of-Sample Performance Comparison (2016–Present)
| Strategy | Sharpe Ratio (Ann.) | Max Drawdown |
|---|---|---|
| R2-RD + MVO | 0.93 | -15.79\ |
| KNN + MVO | 0.73 | -30.44\ |
Cumulative Performance
Figures and display the cumulative out-of-sample profit-and-loss (PnL) trajectories for the R2-RD and KNN strategies, respectively. The HMM-based strategy exhibits smoother growth and shallower drawdowns, while the KNN-based approach experiences larger volatility and deeper drawdown episodes.
[Figure]
[Figure]
Model Performance Discussion
The superior performance of R2-RD reflects the benefits of global parametric structure. By smoothing regime transitions and dynamically adapting regime complexity, rolling HMMs produce more stable estimates of return and risk, which translate into controlled portfolio turnover and drawdowns. KNN, while adaptive, relies on local similarity and is more sensitive to noise and covariance instability, particularly at monthly horizons.
R2-RD Regimes Discussion
We now examine the dynamics of the R2-RD regime labels over time and the corresponding asset performance across regimes. Figure presents the monthly regime assignments from the HMM, where each regime is labeled according to its economic interpretation: Regime 0 (Financial Crisis), Regime 1 (Normal), Regime 2 (Early Pandemic), and Regime 3 (Late Pandemic). The timeline clearly captures major structural shifts in global markets, including the 2008–2009 financial crisis and the COVID-19 pandemic period.
[Figure]
Figure shows the average monthly returns of each asset conditional on the detected regimes. Several key observations emerge:- Financial Crisis (Regime 0): Equity (SPX) and commodity (OIL, GOLD) returns are muted or slightly negative, while BOND and USD perform positively, reflecting a typical flight-to-safety pattern. Volatility is elevated, consistent with crisis periods.
- Normal (Regime 1): SPX and BOND deliver steady positive returns, while GOLD and USD exhibit small negative average returns, indicating normal market conditions with moderate risk-on behavior.
- Early Pandemic (Regime 2): SPX and BOND show strong positive returns, but GOLD suffers a large negative shock, reflecting dislocations in commodity markets during March–April 2020. OIL returns are mildly positive, and USD is roughly neutral.
- Late Pandemic (Regime 3): SPX and USD exhibit strong positive returns, GOLD rebounds, and OIL turns slightly negative, consistent with a gradual recovery and central bank liquidity support.
[Figure]
These results highlight the economic interpretability of the R2-RD regimes. By linking asset performance to identified regimes, we observe patterns that align with well-known market behavior during crises, normal periods, and pandemic-related disruptions. This explainable mapping between regimes and asset returns provides a robust foundation for regime-aware portfolio construction, as it allows investors to anticipate which assets are likely to perform well or poorly under each detected market state.Explainability of R2-RD and Regime-Aware Allocation
A key advantage of the R2-RD framework is its inherent explainability when applied to market data. Unlike black-box models, R2-RD provides interpretable regime definitions and transparent evolution over time:
- Parametric structure: Each latent regime is explicitly characterized by a multivariate Gaussian distribution with interpretable mean vectors
μkand covariance matricesΣk. This allows practitioners to understand the expected return and risk profile of each regime, and relate it to macroeconomic or market conditions. - Monotonic regime emergence: The policy preventing regime merging ensures that new regimes are only added when new market dynamics appear, preserving the identity of previously learned regimes. This makes the sequence of regimes over time easily interpretable, and avoids abrupt, arbitrary label changes.
- Regime label alignment: The label matching mechanism provides temporal consistency, guaranteeing that the same regime label corresponds to the same market state across rolling windows. This further enhances interpretability of regime transitions and their impact on portfolio behavior.
- The conditional moments
μtandΣtused in the optimization are explicitly weighted by regime probabilitiesπt(k), linking portfolio weights directly to interpretable market states. - The resulting allocations can be analyzed in the context of the underlying regime characteristics. For instance, higher allocations to defensive assets can be traced to regimes with elevated covariance among equities or increased market volatility, providing a transparent rationale for each allocation decision.
- This framework allows practitioners and risk managers to understand not only what the portfolio holds at each point in time, but also why those allocations arise, bridging statistical modeling and practical portfolio decision-making.