Stock Correlation Analysis Skill
Finds and analyzes correlated stocks using historical price data from Yahoo Finance via yfinance. Routes to specialized sub-skills based on user intent.
Important: This is for research and educational purposes only. Not financial advice. yfinance is not affiliated with Yahoo, Inc.
Step 1: Ensure Dependencies Are Available
Current environment status:
If DEPS_MISSING, install required packages before running any code:
If all dependencies are already installed, skip the install step and proceed directly.
Step 2: Route to the Correct Sub-Skill
Classify the user's request and jump to the matching sub-skill section below.
If ambiguous, default to Sub-Skill A (Co-movement Discovery) for single tickers, or Sub-Skill B (Return Correlation) for two tickers.
Defaults for all sub-skills
Sub-Skill A: Co-movement Discovery
Goal: Given a single ticker, find stocks that move with it.
A1: Build the peer universe
You need 15-30 candidates. Do not use hardcoded ticker lists — build the universe dynamically at runtime. See references/sector_universes.md for the full implementation. The approach:
- Screen same-industry stocks using
yf.screen()+yf.EquityQueryto find stocks in the same industry as the target - Broaden to sector if the industry screen returns fewer than 10 peers
- Add thematic/adjacent industries — read the target's
longBusinessSummaryand screen 1-2 related industries (e.g., a semiconductor company → also screen semiconductor equipment) - Combine, deduplicate, remove target ticker
A2: Compute correlations
A3: Present results
Show a ranked table with company names and sectors (fetch via yf.Ticker(t).info.get("shortName")). Values below are illustrative:
Include:
- Top 10 positively correlated stocks
- Any notable negatively correlated stocks (potential hedges)
- Brief explanation of why each might be linked (sector, supply chain, customer overlap)
Sub-Skill B: Return Correlation
Goal: Deep-dive into the relationship between two (or a few) specific tickers.
B1: Download and compute
B2: Present results
Show a summary card (illustrative values):
Interpretation guide:
- Correlation > 0.80: Strong co-movement — these stocks are tightly linked
- Correlation 0.50–0.80: Moderate — shared sector drivers but independent factors too
- Correlation < 0.50: Weak — limited co-movement despite possible sector overlap
- High rolling std: Unstable relationship — correlation varies significantly over time
- Spread Z > |2|: Unusual divergence from historical relationship
Sub-Skill C: Sector Clustering
Goal: Given a group of tickers, show the full correlation structure and identify clusters.
C1: Build the correlation matrix
Note: if scipy is not available, fall back to sorting by average correlation instead of hierarchical clustering.
C2: Present results
-
Full correlation matrix — formatted as a table. For more than 8 tickers, show as a heatmap description or highlight only the strongest/weakest pairs.
-
Identified clusters — group tickers that have high intra-group correlation:
- Cluster 1: [NVDA, AMD, AVGO] — avg intra-correlation 0.82
- Cluster 2: [AAPL, MSFT] — avg intra-correlation 0.75
-
Outliers — tickers with low average correlation to the group (potential diversifiers).
-
Strongest pairs — top 5 highest-correlation pairs in the matrix.
-
Weakest pairs — top 5 lowest/negative-correlation pairs (hedging candidates).
Sub-Skill D: Realized Correlation
Goal: Show how correlation changes over time and under different market conditions.
D1: Rolling correlation
D2: Regime-conditional correlation
D3: Present results
- Rolling correlation summary table (illustrative values here and in the regime table):
- Regime correlation table:
-
Key insight: Highlight whether correlation increases during sell-offs (very common — "correlations go to 1 in a crisis"). This is critical for risk management.
-
Trend: Is correlation trending higher or lower recently vs. its historical average?
Step 3: Respond to the User
After running the appropriate sub-skill, present results clearly:
Always include
- The lookback period and data interval used
- The number of observations (trading days)
- Any tickers dropped due to insufficient data
Always caveat
- Correlation is not causation — co-movement does not imply a causal link
- Past correlation does not guarantee future correlation — regimes shift
- Short lookback windows produce noisy estimates; longer windows smooth but may miss regime changes
Practical applications (mention when relevant)
- Sympathy plays: Stocks likely to follow a peer's earnings/news move
- Pair trading: High-correlation pairs where the spread has diverged from its mean
- Portfolio diversification: Finding low-correlation assets to reduce risk
- Hedging: Identifying inversely correlated instruments
- Sector rotation: Understanding which sectors move together
- Risk management: Correlation spikes during stress — diversification may fail when needed most
Present the data and let the user draw conclusions; don't recommend specific trades.
Reference Files
references/sector_universes.md— Dynamic peer universe construction using yfinance Screener API
Read the reference file when you need to build a peer universe for a given ticker.

