correlation-analysis
यह क्या करती है
यह स्किल एजेंट को संपत्तियों के बीच सहसंबंध और कोइंटीग्रेशन मापना सिखाती है। यह उन ट्रेडरों और पोर्टफ़ोलियो बनाने वालों के लिए है जो जानना चाहते हैं कि कौन-सी संपत्तियाँ एक साथ चलती हैं और क्या यह जुड़ाव टिकता है।
कब इस्तेमाल करें
- ✓जब आप चुनी गई संपत्ति के साथ करीब से चलने वाली संपत्तियाँ खोजना चाहें।
- ✓जब आप पेयर ट्रेडिंग के लिए जाँचना चाहें कि दो संपत्तियाँ लंबे समय तक जुड़ी रहती हैं या नहीं।
- ✓जब आप संपत्तियों को उनकी चाल के आधार पर समूहों में बाँटना चाहें।
Skill का लिंक
https://github.com/HKUDS/Vibe-Trading/blob/main/agent/src/skills/correlation-analysis/SKILL.mdइसे कॉपी करके अपने AI (Claude, ChatGPT या Cursor) में पेस्ट करें और निर्देशों का पालन करने को कहें।
कैसे इस्तेमाल करें
सबसे आसान तरीका: मैसेज कॉपी करके अपने AI में पेस्ट करें। वह skill पढ़कर निर्देशों का पालन करेगा।
पेस्ट करने के लिए तैयार मैसेज
Claude Code, Codex या Cursor के लिए: प्रोजेक्ट फ़ोल्डर में चलाएँ और skill इंस्टॉल हो जाएगी।
SKILL.md डाउनलोड करें और अपने एजेंट के skills फ़ोल्डर में रखें।
AI से क्या माँगें: उदाहरण
“ऐसे शेयर खोजिए जो इस शेयर के साथ करीब से चलते हैं, और टेस्ट कीजिए कि उनमें से कौन-सी जोड़ियाँ समय के साथ जुड़ी रहती हैं।”
हर हफ़्ते 5 नई skills, 1 मिनट में पढ़ें।
यह कैसे काम करती है
एजेंट लक्ष्य और संपत्तियों के समूह के बीच सहसंबंध निकालता है, सबसे मज़बूत मेल रखता है, और लंबी अवधि के जुड़ाव की पुष्टि के लिए कोइंटीग्रेशन टेस्ट चलाता है। फिर वह बताता है कि किसी अंतर को बंद होने में आमतौर पर कितना समय लगता है, और पेयर-ट्रेडिंग संकेत बनाता है।
तकनीकी सामग्री (मूल SKILL.md)
लेखक का मूल टेक्स्ट, अंग्रेज़ी में, सीधे GitHub से।
Correlation and Cointegration Analysis
Overview
Correlation analysis is a foundational tool for pairs trading, portfolio construction, and risk management. This skill covers four analysis modes (co-movement discovery / return-correlation deep dive / sector clustering / realized correlation), a full cointegration-testing framework, cross-market linkage analysis, and the complete workflow from analytics to pair-trading signals.
Mode 1: Co-Movement Discovery
Use case: Given a target asset, scan a universe for highly correlated assets and build a candidate pool with similar industry or factor exposure, for use in pairs trading or substitute identification.
Workflow
1. Pull daily return series for the target asset and N candidates
2. Compute Pearson / Spearman correlations between the target and each candidate
3. Rank by correlation in descending order and keep Top-K (usually K=10-20)
4. Run cointegration tests on the Top-K set to retain pairs with real long-run equilibrium
5. Output the candidate pool and a correlation summary
import pandas as pd
import numpy as np
from scipy.stats import pearsonr, spearmanr
def scan_correlated_assets(
target_returns: pd.Series,
universe_returns: pd.DataFrame,
top_k: int = 20,
min_corr: float = 0.5,
method: str = "pearson",
) -> pd.DataFrame:
"""Scan for assets that are highly correlated with the target asset.
Args:
target_returns: Daily return series for the target asset
universe_returns: Candidate-universe return matrix, columns are symbols
top_k: Number of top candidates to return
min_corr: Minimum absolute-correlation threshold
method: "pearson" or "spearman"
Returns:
A DataFrame containing symbol / corr / p_value / rank
"""
aligned = universe_returns.dropna(axis=1, how="any")
aligned, target_aligned = aligned.align(target_returns, join="inner", axis=0)
results = []
for col in aligned.columns:
if method == "spearman":
corr, p = spearmanr(target_aligned, aligned[col])
else:
corr, p = pearsonr(target_aligned, aligned[col])
results.append({"symbol": col, "corr": corr, "p_value": p})
df = pd.DataFrame(results)
df = df[df["corr"].abs() >= min_corr].sort_values("corr", ascending=False)
df["rank"] = range(1, len(df) + 1)
return df.head(top_k).reset_index(drop=True)
Screening guidance:
| Correlation | Conclusion | Follow-up Action |
|---|---|---|
| > 0.8 | Strong same-direction co-movement | Send to the cointegration test queue |
| 0.6 - 0.8 | Moderate co-movement | Check industry / factor alignment before cointegration |
| < 0.6 | Weak correlation | Usually unsuitable for pairs trading |
| Negative and < -0.6 | Strong inverse co-movement | Can be used in hedged portfolios, but be careful with spread direction |
Mode 2: Deep Return-Correlation Analysis
Use case: Run a full bivariate correlation study on two assets, including multiple correlation coefficients, Beta / R², rolling correlation, and spread Z-Score.
Core Metrics
import statsmodels.api as sm
from scipy.stats import pearsonr, spearmanr, kendalltau
def bivariate_correlation_analysis(
y: pd.Series,
x: pd.Series,
rolling_window: int = 60,
) -> dict:
"""Run deep correlation analysis for two assets.
Args:
y: Daily return series of asset A
x: Daily return series of asset B
rolling_window: Rolling-window length in trading days
Returns:
Dict of correlation statistics
"""
# Align the two series.
df = pd.concat([y.rename("y"), x.rename("x")], axis=1).dropna()
y_clean, x_clean = df["y"], df["x"]
# Static correlations.
pearson_r, pearson_p = pearsonr(y_clean, x_clean)
spearman_r, spearman_p = spearmanr(y_clean, x_clean)
kendall_r, kendall_p = kendalltau(y_clean, x_clean)
# OLS: y = α + β·x
x_const = sm.add_constant(x_clean)
ols = sm.OLS(y_clean, x_const).fit()
beta = ols.params["x"]
alpha = ols.params["const"]
r_squared = ols.rsquared
# Rolling Pearson correlation.
rolling_corr = y_clean.rolling(rolling_window).corr(x_clean)
# Spread and Z-Score using the hedge ratio.
spread = y_clean - beta * x_clean
spread_mean = spread.rolling(rolling_window).mean()
spread_std = spread.rolling(rolling_window).std()
z_score = (spread - spread_mean) /
अक्सर पूछे जाने वाले सवाल
क्या सहसंबंध और कोइंटीग्रेशन एक ही हैं?
नहीं। सहसंबंध दिखाता है कि संपत्तियाँ एक साथ कैसे चलती हैं, जबकि कोइंटीग्रेशन जाँचता है कि वे लंबी अवधि के संतुलन से बँधी हैं या नहीं।
यहाँ हाफ़-लाइफ़ क्या है?
यह अनुमान है कि जोड़ी की संपत्तियों के बीच का अंतर आधा होकर वापस आने में आमतौर पर कितना समय लेता है।
क्या यह गारंटी देती है कि पेयर ट्रेड काम करेगा?
नहीं। जोड़ी का रिश्ता टूट सकता है, इसलिए संकेतों की जाँच और निगरानी ज़रूरी है।
जानकारी
लेखक का मूल विवरण
Correlation and cointegration analysis — co-movement discovery, deep return-correlation analysis, sector clustering, realized correlation, Engle-Granger / Johansen cointegration, half-life, Kalman dynamic hedge ratio, cross-market linkage analysis, and pair-trading signal generation
repo: HKUDS/Vibe-Trading
लोकप्रियता
- GitHub स्टार
- 37k
- रैंकिंग में स्थान
- #7505
- लाइसेंस
- MIT
- अपडेट की गई
- 1/11/2026
कमेंट
- …
इस repository की और skills
vibe-trading
37kयह आपके एजेंट को वित्त शोध का पूरा टूलकिट देती है, जिसमें बैकटेस्ट, फ़ैक्टर एनालिसिस, ऑप्शन प्राइसिंग और कई बाज़ारों का डेटा शामिल है।
adr-hshare
37kयह आपके एजेंट को दिखाती है कि कई बाज़ारों में लिस्टेड एक चीनी कंपनी के भाव की तुलना कैसे करें, जैसे अमेरिकी ADR और हॉन्गकॉन्ग शेयर।
akshare
37kयह आपके एजेंट को चीनी और वैश्विक शेयरों, फ़्यूचर्स, फ़ॉरेक्स और आर्थिक संकेतकों का मुफ़्त बाज़ार डेटा लेने देती है, बिना API key के।
alpha-zoo
37kयह आपके एजेंट को बने-बनाए स्टॉक फ़ैक्टरों की लाइब्रेरी देखने और चुने हुए बाज़ार पर उनके पूरे समूह के रिटर्न की भविष्यवाणी की क्षमता जाँचने देती है।
मिलती-जुलती skills
gitcrawl
394kयह आपके एजेंट को GitHub issues और pull requests के सेव आर्काइव में खोजने, मिलते-जुलते मामलों को समूह में रखने और लाइव स्थिति जांचने देती है।
slacrawl
394kयह आपके एजेंट को स्थानीय Slack आर्काइव में संदेश खोजने और गिनने, उसकी ताज़गी जांचने और ज़रूरत पड़ने पर उसे ताज़ा करने देती है।
goplaces
394kयह आपके एजेंट को Google Places से जगहें खोजने, उनका विवरण और समीक्षाएं पाने, और जगह के नाम हल करने में मदद करती है, स्क्रिप्ट के लिए JSON आउटपुट के साथ।