
Stock Correlation
Run correlation, beta, clustering, and regime analysis on tickers to find peers, hedge pairs, and sympathy plays from natural-language finance questions.
Overview
Stock Correlation is an agent skill most often used in Grow (also Validate scope, Build backend) that analyzes historical stock price relationships via four routed correlation workflows.
Install
npx skills add https://github.com/himself65/finance-skills --skill stock-correlationWhat is this skill?
- Four routed modes: co-movement discovery, pairwise return correlation, sector clustering, realized/regime correlation
- Pairwise depth: Pearson, beta, R-squared, spread Z-score, rolling stability
- NxN correlation matrix with hierarchical clustering for peer groups
- Rolling 20/60/120-day and up/down/high-vol/drawdown regime splits
- Auto-installs yfinance, pandas, and numpy via pip when missing
- Four specialized sub-skill routes: co-movement, return correlation, sector clustering, realized correlation
- Rolling windows explicitly include 20-, 60-, and 120-day variants in realized correlation mode
Adoption & trust: 1k installs on skills.sh; 2.7k GitHub stars; 2/3 security scanners passed (skills.sh audits).
What problem does it solve?
You have tickers in mind but no fast way to find peers, pair-trade stats, or regime-dependent co-movement without writing new pandas code every session.
Who is it for?
Indie quant-curious builders, trading-journal workflows, and fintech prototypes that need reproducible correlation stats from Yahoo-backed price data.
Skip if: Real-time execution, fundamental valuation, or regulated advisory without your own compliance layer and data licensing review.
When should I use this skill?
User asks what correlates with a ticker, pairwise correlation, sector matrix, pair trading, sympathy plays, or regime/rolling co-movement (triggers include NVDA/AMD-style examples and FAANG matrix requests).
What do I get? / Deliverables
You receive correlation matrices, pairwise metrics, clustered peer groups, or rolling regime breakdowns grounded in downloaded historical prices.
- Peer or cluster lists from co-movement or matrix analysis
- Pairwise correlation report with beta, R-squared, and spread Z-score where applicable
- Regime-conditional or rolling correlation summaries
Recommended Skills
Journey fit
Spans multiple journey phases - primary shelf plus alternate fits below.
Grow analytics is the primary shelf because the skill answers how markets and positions co-move after you have symbols to track—not initial product scoping. Analytics subphase matches price-data statistical outputs (Pearson, beta, matrices, rolling windows) rather than checkout or infra work.
Where it fits
Check whether a proposed fintech wedge (e.g. AI supply-chain tickers) shows tight clustering before committing to build.
Find sympathy plays and hedge pairs when a core holding gaps on earnings.
Prototype an internal CLI or API endpoint that answers correlation questions using the skill's four routed modes.
How it compares
Agent-orchestrated Python analytics skill, not a hosted Bloomberg terminal or paid API integration.
Common Questions / FAQ
Who is stock-correlation for?
Solo builders and small teams doing market analytics, pair-trade research, or fintech features who want agent-driven correlation without maintaining separate notebooks.
When should I use stock-correlation?
In Grow analytics when tracking sympathy plays or hedges; in Validate scope when correlation evidence supports a finance niche; in Build backend when prototyping quant APIs from natural-language queries.
Is stock-correlation safe to install?
It runs local Python and fetches market data via yfinance; review Security Audits on this page and treat outputs as research, not guaranteed investment guidance.
SKILL.md
READMESKILL.md - Stock Correlation
# stock-correlation Analyze stock correlations to find related companies, sector peers, and pair-trading candidates using historical price data. ## What it does Routes to four specialized sub-skills based on user intent: - **Co-movement Discovery** — given a single ticker, find the most correlated stocks from curated sector and thematic peer universes (e.g., "what correlates with NVDA?") - **Return Correlation** — deep-dive pairwise analysis between two tickers: Pearson correlation, beta, R-squared, spread Z-score, and rolling stability (e.g., "correlation between AMD and NVDA") - **Sector Clustering** — full NxN correlation matrix with hierarchical clustering to identify groups and outliers (e.g., "correlation matrix for FAANG") - **Realized Correlation** — time-varying and regime-conditional correlation: rolling windows (20/60/120-day), up vs down days, high-vol vs low-vol, drawdown regimes (e.g., "when NVDA drops what else drops?") ## Triggers - "what correlates with NVDA", "find stocks related to AMD" - "correlation between AAPL and MSFT", "how do LITE and COHR move together" - "what moves with", "stocks that move together", "sympathy plays" - "sector peers", "pair trading", "hedging pair" - "when NVDA drops what else drops", "rolling correlation" - "correlation matrix for FAANG", "cluster these stocks" - Well-known pairs: AMD/NVDA, GOOGL/AVGO, LITE/COHR ## Prerequisites - Python 3.8+ - The skill auto-installs `yfinance`, `pandas`, and `numpy` via pip if not already present - `scipy` is optional (used for hierarchical clustering in Sector Clustering sub-skill; falls back to sorting if unavailable) ## Platform Works on **all platforms** (Claude Code, Claude.ai with code execution, etc.). ## Setup ```bash # As a plugin (recommended — installs all skills) npx plugins add himself65/finance-skills --plugin finance-market-analysis # Or install just this skill npx skills add himself65/finance-skills --skill stock-correlation ``` See the [main README](../../../../README.md) for more installation options. ## Reference files - `references/sector_universes.md` — Dynamic peer universe construction using yfinance Screener API, with fallback strategies # Dynamic Peer Universe Construction How to build a peer universe at runtime for correlation analysis. **Do not hardcode ticker lists** — fetch them dynamically so results stay current. --- ## Method 1: Same-Sector Screen (Primary) Use yfinance's `yf.screen()` + `EquityQuery` to find stocks in the same sector as the target. Note: the screener supports filtering by `sector` but not directly by `industry` — use sector-level screening and let the correlation math surface the closest peers. ```python import yfinance as yf from yfinance import EquityQuery def get_sector_peers(ticker_symbol, min_market_cap=1_000_000_000, max_results=30): """Find peers in the same sector above a market cap threshold.""" target = yf.Ticker(ticker_symbol) info = target.info sector = info.get("sector", "") if not sector: return [] # Screen for same-sector stocks on major US exchanges query = EquityQuery("and", [ EquityQuery("eq", ["sector", sector]), EquityQuery("gt", ["intradaymarketcap", min_market_cap]), EquityQuery("is-in", ["exchange", "NMS", "NYQ"]), ]) result = yf.screen(query, size=max_results, sortField="intradaymarketcap", sortAsc=False) peers = [] for quote in result.get("quotes", []): symbol = quote.get("symbol", "") if symbol and symbol != ticker_symbol: peers.append(symbol) return peers ``` ## Method 2: Thematic Expansion For cross-sector correlations (e.g., AI supply chain spans semis + cloud + software), read the target's business description and screen adjacent sectors: ```python def get_thematic_context(ticker_symbol): """Get company context to inform adjacent-sector screening.""" target = yf.Ticker(ticker_symbol) info = target.info return {