Works with the AI Agents you already use
Regime Detection Volatility
by BanditXBT
Detect market regimes and forecast volatility without lookahead: HMM, Markov switching, GARCH, change points, vol targeting.
$29
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.
- Pick the question. Continuous volatility forecast for sizing vs discrete state for strategy switching. Prefer 2-3 states; more mostly fit noise.
- 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 variancew/(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; useforecast()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).
- EWMA:
- Markov switching (Hamilton 1989).
statsmodels.tsa.regime_switching.markov_regression.MarkovRegression(endog, k_regimes=2, switching_variance=True)(alsoMarkovAutoregression). 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 duration1/(1-p_ii). - 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,predictis Viterbi andpredict_probareturns 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 callpredict_probaon data truncated at t and take the last row); this is O(T^2) but correct. - 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. - 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. - 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.
Educational analysis, not investment advice. Verify statsmodels attribute names against your installed version.
How to use
- 1
Connect your agent to the Agensi MCP
Copy the prompt and paste it into Claude, ChatGPT, Cursor or any agent that supports MCP. It sets up the connection for you. Manual setup
- 2
Sign in to Agensi
Your agent shows a sign-in link. Sign in and click Allow.
- 3
Ask for what you need
Your agent loads this skill and uses it on your task. It always asks before buying a skill.
Reviews
No reviews yet
Be one of the first to try it. Every listed skill goes through the trust checks below.
Security scanned
Checked by our 8-point scan before listing
Fresh listing
Recently published to Agensi
Money-back guarantee
Doesn't do what its page promises? You get your money back.
Trust & safety
Security scan
Security scan passed 13 days ago
- Software
Python 3statsmodelsarch
- Optional
- hmmlearnruptures
Permissions
No special permissions declared or detected
What's inside
Frequently Asked Questions
Find more skills like this on the Claude Skills Marketplace, the Codex Skills Marketplace and the Gemini Skills Marketplace, or browse All Claude Skills.