correlation-regime
What it does
This skill tracks shifts in how strongly assets move together over time, and looks for the first asset to move in a sudden sell-off. It is for risk managers and traders who want to know when diversification is failing.
When to use it
- βWhen you want to know when a market has moved into a highly correlated state.
- βWhen you want to know which asset moved first during a crisis or sudden drop.
- βWhen you want to catch assets whose relationship to the market has changed quietly.
Skill link
https://github.com/HKUDS/Vibe-Trading/blob/main/agent/src/skills/correlation-regime/SKILL.mdCopy it and paste it into your AI (Claude, ChatGPT or Cursor), asking it to follow the instructions.
How to use
The easiest way: copy the message and paste it into your AI. It reads the skill and follows the instructions.
Ready-to-paste message
For Claude Code, Codex or Cursor: run it in your project folder and the skill gets installed.
Download the SKILL.md and drop it into your agentβs skills folder.
Example of what to ask your AI
βHas the crypto market moved into a highly correlated state recently, and did any asset lead the recent sell-off?β
5 new skills a week. 1 minute to read.
How it works
The agent tracks how connected the assets are over time, marking regimes with a hysteresis method that avoids rapid switching. It then looks at the first movers in a crisis and labels each attribution with its confidence, including saying when the cause is unclear.
Technical content (original SKILL.md)
Original text by the author, straight from GitHub.
Correlation-Regime Detection and Crisis Attribution
Overview
The correlation-analysis skill answers "how correlated are these assets?" β a snapshot.
This skill answers the temporal questions a snapshot cannot:
- When did the market fuse into one highly-correlated bloc, and when did it release? (Mode 1 β regime detection)
- What does a fused regime mean for position sizing? (Mode 2 β risk context)
- Who moved first when a crisis broke β is there a nameable trigger asset? (Mode 3 β first-mover attribution)
- Who quietly rewired their relationship to the rest of the market, even without a violent move? (Mode 4 β rewiring leaderboard)
The methodology comes from an open-source streaming pipeline (see References) whose public repository pins the regime machinery's math and an eight-event historical replay regression (COVID, May-2021, China ban, Nov-2021 top, LUNA, FTX, SVB, yen-carry β 17 crypto symbols, 1-minute bars) that its CI reproduces bit-for-bit. The finer-grained numbers quoted in this skill β 13 fused/defused regime cycles on the continuous 2020β2024 tape at a ~0.008/day calm false-alarm rate, and zero wrong culprit names across 10 labeled crises (2 held out-of-sample), including naming FTT roughly two days before the November 2022 collapse β are the author's unpublished internal replays on that same pipeline and are not independently verifiable. All of it is historical replay, never live results, and the method is market-agnostic even though the validation tape is crypto.
What this skill is NOT: a trade-timing signal. The same validation program tested regime-based exits head-to-head against a plain price stop and lost β correlation regimes cannot time tops, and the give-up cost of selling into a crash is a property of the tape, not of any signal. Use these modes for risk context, monitoring, and post-hoc attribution; never present them as buy/sell triggers.
Mode 1: Correlation-Regime Detection (Edge Density + Hysteresis)
Use case: Maintain a live, causal answer to "is the market currently one bloc?" Diversification quietly disappears when pairwise correlations fuse; a regime state machine turns that into an explicit, monitorable state with few false alarms.
Workflow
1. Compute rolling-window pairwise correlations of returns
2. Reduce each correlation matrix to one number: edge density
= fraction of asset pairs with |Ο| β₯ edge_threshold
3. Smooth the density series with a TRAILING window (causal β see warning below)
4. Run a hysteresis (Schmitt-trigger) state machine over the smoothed series:
enter FUSED when density β₯ enter_threshold, exit only when β€ exit_threshold
5. Emit regime state + transition timestamps for monitoring / reporting
Two thresholds with a dead band between them are the entire trick: a single threshold chatters (fires dozens of times as density oscillates around it), while hysteresis yields a handful of clean regime cycles per market cycle.
import numpy as np
import pandas as pd
def compute_edge_density(
returns: pd.DataFrame,
corr_window: int = 60,
edge_threshold: float = 0.5,
) -> pd.Series:
"""Reduce rolling correlation matrices to an edge-density series.
Edge density is the fraction of distinct asset pairs whose rolling
|correlation| clears ``edge_threshold`` β a scalar "how fused is the
market" gauge in [0, 1].
Args:
returns: Multi-asset return matrix, columns are symbols
corr_window: Rolling window length (bars) for pairwise correlation
edge_threshold: |Ο| level at which a pair counts as an "edge"
Returns:
Edge-density series aligned to ``returns.index`` (NaN during warmup)
"""
n_assets = returns.shape[1]
n_pairs = n_assets * (n_assets - 1) // 2
upper_mask = np.triu(np.ones((n_assets, n_assets), dtype=bool), k=1)
density = pd.Series(np.nan, index=returns.index)
for i in range(corr_window, len(returns) + 1):
corr = returns.iloc[i - corr_window:i].corr().abs().to_numpy()
density.iloc[i - 1] = float((corr[upper_mask] >= edge_threshold).sum()) / n_pairs
return density
def detect_regimes(
density: pd.Series,
smooth_window: int = 5,
enter_threshold: float = 0.65,
exit_threshold: float = 0.45,
) -> pd.DataFrame:
"""Hysteresis (Schmitt-trigger) regime state machine on smoothed density.
The market is FUSED once smoothed density reaches ``enter_threshold`` an
FAQ
What does highly correlated mean for risk?
When assets move together, diversification weakens, so the skill can be used to adjust exposure.
Can it say the cause was unclear?
Yes. Verdicts can be named, macro-driven, ambiguous or an abstention when the evidence is not strong enough.
Does it look ahead in time?
No. The smoothing is causal, so it only uses information that was available at each point.
Details
Original description by the author
Correlation-regime detection and crisis attribution β edge-density regime states with hysteresis, causal (no look-ahead) smoothing, regime-aware exposure context, first-mover crisis attribution with honest NAME / MACRO / AMBIGUOUS / ABSTAIN verdicts, and a correlation-rewiring leaderboard that catches slow bleed-outs
repo: HKUDS/Vibe-Trading
Popularity
- GitHub stars
- 37k
- Ranking position
- #7506
- License
- MIT
- Updated
- 11/1/2026
Comments
- β¦
More skills from this repository
vibe-trading
37kGives your agent a full finance research toolkit, covering backtests, factor analysis, options pricing and market data across many markets.
adr-hshare
37kShows your agent how to compare the price of a Chinese company listed in several markets, such as a US ADR and a Hong Kong share.
akshare
37kLets your agent pull free market data for Chinese and global stocks, futures, forex and economic indicators, with no API key needed.
alpha-zoo
37kLets your agent browse a library of ready-made stock factors and test how well a whole set of them predicts returns on a chosen market.
Similar skills
gitcrawl
394kLets your agent search a saved archive of GitHub issues and pull requests, group duplicates, and check their current status on GitHub.
slacrawl
394kLets your agent search and count messages in a local Slack archive, check how fresh that archive is, and refresh it when needed.
goplaces
394kHelps your agent search for places, get their details and reviews, and resolve place names using Google Places, with JSON output for scripts.