# regime-detection-volatility

> Detect market regimes and forecast volatility without lookahead: HMM, Markov switching, GARCH, change points, vol targeting.

regime-detection-volatility is a paid AI agent skill on Agensi by BanditXBT. It loads into your AI agent through the Agensi MCP server, always in its latest approved version.

- Price: $29 (one-time purchase)
- Creator: [BanditXBT](https://www.agensi.io/creators/banditxbt)
- Version: 1.0
- Last updated: 2026-11-21
- Security: scan passed (2026-11-21); every new listing is also reviewed by a person
- Listing: https://www.agensi.io/skills/regime-detection-volatility
- Tags: trading-investing, research-analysis, web3-crypto

## About this skill

Regimes are latent; every label used in a backtest must be a filtered, real-time estimate from parameters fit only on past data, never a smoothed or full-sample one. Educational analysis, not investment advice; state assumptions and data sources.

1. **Pick the question.** Continuous volatility forecast for sizing vs discrete state for strategy switching. Prefer 2-3 states; more mostly fit noise.
2. **Volatility estimators.**
   - EWMA: `s2_t = lam*s2_{t-1} + (1-lam)*r_{t-1}^2`. RiskMetrics defaults are lam = 0.94 (daily) and 0.97 (monthly). Half-life = ln(0.5)/ln(lam), about 11 days at 0.94.
   - GARCH(1,1): `s2_t = w + a*r_{t-1}^2 + b*s2_{t-1}`; unconditional variance `w/(1-a-b)`; daily a+b is often fitted near 0.97-0.99 (empirical tendency, varies). GJR-GARCH/EGARCH capture leverage effect; Student-t innovations suit fat tails. Python: `arch.arch_model(r*100, vol="GARCH", p=1, o=1, q=1, dist="t")` (o=1 gives GJR); `vol="EGARCH"` for EGARCH. Refit on rolling windows; use `forecast()` out of sample.
   - Realized vol from intraday returns (e.g., 5-minute; check microstructure noise); HAR-RV (Corsi 2009) is a simple strong baseline.
   - Evaluate forecasts out of sample with QLIKE or MSE (both robust to noisy proxies, Patton 2011) and Mincer-Zarnowitz regressions; compare models with Diebold-Mariano or `arch.bootstrap.MCS` (Model Confidence Set).
3. **Markov switching (Hamilton 1989).** `statsmodels.tsa.regime_switching.markov_regression.MarkovRegression(endog, k_regimes=2, switching_variance=True)` (also `MarkovAutoregression`). Results expose smoothed vs filtered marginal probabilities (`smoothed_marginal_probabilities`, `filtered_marginal_probabilities`; verify names in your version). Only filtered ones are causal, and only if parameters were also estimated on past data: refit expanding/rolling. Expected duration `1/(1-p_ii)`.
4. **Gaussian HMM.** `hmmlearn.hmm.GaussianHMM(n_components=k, covariance_type="full", n_iter=500)`; multiple random inits (EM finds local optima), compare BIC, sort states by variance after each refit (label switching). In hmmlearn, `predict` is Viterbi and `predict_proba` returns posteriors using the whole sequence, so neither is causal on a full-sample call. For a filtered probability at t, fit on data up to t (or fit earlier, then call `predict_proba` on data truncated at t and take the last row); this is O(T^2) but correct.
5. **Change points.** Offline: PELT (Killick, Fearnhead, Eckley 2012, *JASA*) via `ruptures`: `rpt.Pelt(model="rbf", min_size=..., jump=...).fit(x).predict(pen=...)`. Online: Bayesian online changepoint detection (Adams and MacKay 2007, arXiv:0710.3742); CUSUM. The penalty drives results; calibrate on simulated null data to a target false-alarm rate. Offline detectors see the whole series and are not trading signals.
6. **Volatility targeting.** `w_t = min(L_max, sigma_target / sigma_hat_t)` with sigma_hat known at t-1, executed at t. Moreira and Muir (*J. Finance* 2017) report volatility-managed portfolios earn large alphas for equity factors and the currency carry trade. Harvey et al. (*J. Portfolio Mgmt* 2018) find Sharpe gains for risk assets with a leverage effect (equities, credit) and negligible effects for bonds, currencies, commodities; vol targeting consistently reduced extreme negative returns. Add leverage caps, rebalance thresholds (e.g., trade only if weight change > 10-20%, heuristic), and cost and financing accounting.
7. **Regime-conditioned evaluation.** Tag each bar with the filtered regime known at t-1. Report per-regime return, vol, Sharpe, drawdown, turnover and independent episode count (not bars). Test alpha differences with `r_t = a + b*f_t + c*I + d*(f_t*I) + e`, HAC errors.

## Requires

- Python 3
- statsmodels
- arch
- Optional: hmmlearn
- Optional: ruptures

## Known limitations

Educational analysis, not investment advice. Verify statsmodels attribute names against your installed version.

## How to use this skill

1. Connect your AI agent to Agensi once: add the MCP server https://mcp.agensi.io/mcp/auth and sign in with your Agensi account (OAuth, no API key). Steps for Claude, ChatGPT, Claude Code, Codex, Cursor, VS Code and other agents: https://www.agensi.io/docs/mcp-setup
2. Ask your agent: "Use the regime-detection-volatility skill from Agensi" and describe your task.
3. Buy it on the listing or let your agent ask you first; your agent then loads it from Agensi when it needs it. Every paid skill has a money-back guarantee: https://www.agensi.io/docs/money-back-guarantee

## Frequently asked questions

### What does regime-detection-volatility do?

Detect market regimes and forecast volatility without lookahead: HMM, Markov switching, GARCH, change points, vol targeting.

### Which AI agents support regime-detection-volatility?

This skill uses the open SKILL.md standard. Use it through an MCP-compatible agent connected to Agensi, and check the compatibility information on this page for confirmed agents and required capabilities.

### How do I use regime-detection-volatility?

Connect your AI agent to Agensi through MCP, then ask it to use regime-detection-volatility on your task. Your agent loads the latest approved version each time. Paid skills require a purchase or active subscription. Skill files are not available for download; your licence does not allow you to save, copy or export any part of a skill.

---

Source: [Agensi](https://www.agensi.io), the marketplace of skills for AI agents. Any MCP-compatible agent (Claude, ChatGPT, Claude Code, Codex, Cursor, VS Code and more) connects at https://mcp.agensi.io/mcp/auth and signs in with an Agensi account; setup for every agent: https://www.agensi.io/docs/mcp-setup. Append .md to any skill, guide or docs address on agensi.io for its markdown version.
