Analyze Chinese A-share market regimes by combining index data, macro indicators, futures term structure, and volatility clustering. Use when an agent needs to: (1) classify market states (bull/bear/sideways/high-vol/low-vol), (2) detect regime shifts using Hidden Markov Models or threshold rules, (3) evaluate factor performance conditional on regimes, (4) generate regime-aware risk forecasts, or (5) build regime-switching trading strategies using Pandadata APIs (get_index_daily, get_macro_*, get_future_term_structure, get_future_basis) and panda_backtest.
Ships in market-regime-analysis. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
{
"version": 1,
"task": {
"placeholder": "补充分析区间、宏观变量、因子条件分析或风险预测目标(可选)"
},
"fields": [
{
"key": "index",
"label": "分析指数",
"type": "select",
"default": "000300.SH",
"options": [
{ "value": "000300.SH", "label": "沪深300" },
{ "value": "000905.SH", "label": "中证500" },
{ "value": "000016.SH", "label": "上证50" },
{ "value": "000688.SH", "label": "科创50" },
{ "value": "399006.SZ", "label": "创业板指" },
{ "value": "000001.SH", "label": "上证指数" }
]
},
{
"key": "method",
"label": "状态识别方法",
"type": "select",
"default": "threshold",
"options": [
{ "value": "threshold", "label": "阈值规则" },
{ "value": "hmm", "label": "隐马尔可夫模型" },
{ "value": "rolling", "label": "滚动状态分类" }
]
},
{
"key": "focus",
"label": "关注点",
"type": "text",
"placeholder": "例如:因子条件表现、VaR/CVaR、状态切换策略"
}
],
"prompt_template": "{{#task}}任务与材料:\n{{task}}\n\n{{/task}}{{#attachments}}用户上传的材料(已放入工作区):\n{{attachments}}\n\n{{/attachments}}以 {{index}} 为核心,使用 {{method}} 方法结合指数趋势与波动、宏观指标、股指期货期限结构和市场横截面特征识别 A 股牛熊、震荡及高低波状态,严格避免前视,{{#focus}}重点分析:{{focus}};{{/focus}}给出状态证据、切换判断、条件因子表现与状态感知风险结论,输出中文报告。"
}
Analyze and classify Chinese A-share market regimes using multi-source data, then use regime information to improve factor timing, risk forecasting, and strategy design.
This skill uses the following Pandadata APIs for regime detection:
| Data | API | Purpose |
|---|---|---|
| Index prices | get_index_daily(symbol, start_date, end_date) | Price trends, momentum, volatility (沪深300/中证500/创业板指 等) |
| Index valuations | get_index_indicator(symbol, start_date, end_date, fields) | PE/PB/股息率分位值 → 估值状态 |
| Macro (NA/CI/PI/FI/MB/IR/PM) | get_macro_*(symbol, start_date, end_date) | GDP/CPI/PPI/社融/M2/利率/PMI → 宏观状态 |
| Futures term structure | get_future_term_structure(symbol, start_date, end_date) | 基差/期限结构 → 市场情绪与预期 |
| Futures basis | get_future_basis(underlying_symbol, start_date, end_date, fields) | 期现价差 → 套保/投机情绪 |
| Stock daily | get_stock_daily(start_date, end_date, symbol, indicator, st) | 全市场量价数据 → 截面波动、相关性 |
| Trade calendar | get_trade_cal(start_date, end_date) | 交易日对齐 |
| Symbol | Index |
|---|---|
000300.SH | 沪深300 (CSI 300) |
000905.SH | 中证500 (CSI 500) |
000016.SH | 上证50 (SSE 50) |
000688.SH | 科创50 (STAR 50) |
399006.SZ | 创业板指 (ChiNext) |
000001.SH | 上证综合 (SSE Composite) |
| API | Data |
|---|---|
get_macro_na | 国民经济核算 — GDP |
get_macro_ci | 景气指数 — 中国经济景气 |
get_macro_pi | 价格指数 — CPI/PPI |
get_macro_fi | 财政 — 财政收入/支出 |
get_macro_mb | 货币与银行 — M2/社融/信贷 |
get_macro_ir | 利率 — 贷款/存款基准利率 |
get_macro_pm | 采购经理人指数 — PMI |
get_macro_fe | 对外经济 — 进出口 |
get_macro_na | GDP — 季度GDP/累计GDP |
get_macro_dt | 国内贸易 — 社会消费品零售 |
get_macro_fa | 固定资产投资 |
get_macro_in | 工业 — 工业增加值 |
get_macro_cal | 宏观日历 — 经济数据发布时间 |
Define regimes by cutting historical data at fixed thresholds. Best for explaining to non-technical stakeholders.
Price trend regime:
Volatility regime:
Macro regime:
Use Gaussian HMM on multi-dimensional features to discover latent states. Supports 2-5 states.
Standard feature set (4-dim):
Workflow:
returns + vol + term_structure + turnover_change
│
┌─────┴─────┐
│ StandardScaler │
└─────┬─────┘
│
┌─────┴─────┐
│ GaussianHMM │ (fit 500 iter, 10 random init)
│ n_components │ (2-5 states, pick by BIC or AIC)
└─────┬─────┘
│
┌───────────┼───────────┐
▼ ▼ ▼
State 0 State 1 State 2 ...
(Bull) (Bear) (Sideways)
Update regime daily with a rolling window. The regime at date T is inferred from data up to T (no look-ahead).
After regimes are classified, test how factors perform differently across regimes:
# Per-regime factor evaluation pattern
regime_stats = {}
for state in states:
regime_stats[state] = {
'avg_ic': factors[dates_in_state].corr(returns[dates_in_state]),
'avg_ret': factors[dates_in_state].mean(),
'hit_rate': (factors[dates_in_state] * returns[dates_in_state] > 0).mean(),
'sharpe': ...,
'n_days': len(dates_in_state)
}
Key question: does a factor's IC vary significantly across regimes? If yes, regime-aware factor weighting can improve performance.
Each regime has distinct risk characteristics:
| Regime | Typical Vol | Correlation | Drawdown Risk |
|---|---|---|---|
| Bull | Low-Med | Low | Low (short-lived) |
| Bear | High | High (all stocks fall together) | High (prolonged) |
| Sideways | Low | Medium | Medium (range-bound) |
| High-Vol | Very High | Very High | Extreme |
| Low-Vol | Low | Low | Low |
For each regime, estimate conditional covariance matrix and VaR/CVaR. See references/risk_forecast.md for detailed method.
Use regime to adjust portfolio parameters:
| Parameter | Bull | Bear | Sideways | High Vol |
|---|---|---|---|---|
| Target volatility | 12% | 8% | 10% | 6% |
| Max drawdown limit | 15% | 10% | 12% | 8% |
| Factor tilt | Momentum+Growth | Value+LowVol | Quality+Reversal | Cash+Defensive |
| Leverage | 1.0x | 0.5x | 0.8x | 0.3x |
| Position sizing | Full | Half | Normal | Quarter |
import pandas as pd
import numpy as np
# Collect index data
index_data = get_index_daily(symbol='000300.SH', start_date='20200101', end_date='20250702')
# Collect macro indicators
gdp = get_macro_na(symbol='GDP_QUARTERLY', start_date='20200101', end_date='20250702')
cpi = get_macro_pi(symbol='CPI_YOY', start_date='20200101', end_date='20250702')
pmi = get_macro_pm(symbol='PMI', start_date='20200101', end_date='20250702')
m2 = get_macro_mb(symbol='M2_YOY', start_date='20200101', end_date='20250702')
# Collect term structure
term_structure = get_future_term_structure(symbol='IF', start_date='20200101', end_date='20250702')
Compute regime features from raw data. See references/feature_engineering.md.
Choose a method. See references/hmm_detection.md and references/threshold_rules.md.
Evaluate factors and risk metrics per regime. See references/conditional_analysis.md.
Build a strategy that adapts to detected regimes. See examples/regime_switching_strategy.py.
| File | When to read |
|---|---|
references/threshold_rules.md | When using simple threshold-based regime definitions (bull/bear/sideways, high/low vol) |
references/hmm_detection.md | When applying Hidden Markov Models for latent state discovery |
references/feature_engineering.md | When computing regime features from raw data (rolling stats, normalization, date alignment) |
references/conditional_analysis.md | When evaluating factor performance or risk metrics per regime |
references/risk_forecast.md | When generating regime-aware covariance, VaR, or drawdown forecasts |
examples/regime_switching_strategy.py | When building a complete regime-dependent trading strategy with panda_backtest |
What SKILL.md sets; muted values are Claude Code's defaults
Other plugins' skills for the same job
/market-regime-analysis:market-regime-analysisfrom market-regime-analysis
market-regime-analysis@quantskills is listed by quantskills/registry — review the source before installing
npx claudepluginhub quantskills/registry --plugin market-regime-analysis