대감집
[시장 지표] 상관관계 분석 본문
Overview
- 시장 지표들의 상관관계를 통해 헷징 가능성에 대해서 탐구하는 시간
- 다양한 시장 지표들을 받아와 상관관계 분석 진행
- 본 분석에서는 헷징 가능성이 없음을 확인(주식 내부적으로 헷징이 필요)
- 하지만 환율간 높은 상관관계가 있음을 확인(환율 투자 가능성 확인)
- Strong Positive Correlation
- S&P 500 and Dow Jones: Strong positive correlation (0.99)
NASDAQ and S&P 500: Strong positive correlation (0.98)
Dow Jones and NASDAQ: Strong positive correlation (0.95)
Bitcoin and Ethereum: Strong positive correlation (0.93)
NASDAQ and Bitcoin: Strong positive correlation (0.92)
Ethereum and Copper: Strong positive correlation (0.91)
S&P 500 and Bitcoin: Strong positive correlation (0.90)
Silver and Gold: Strong positive correlation (0.89)
NASDAQ and Gold: Strong positive correlation (0.89)
Gold and S&P 500: Strong positive correlation (0.89)
Bitcoin and Dow Jones: Strong positive correlation (0.89)
NASDAQ and Silver: Strong positive correlation (0.89)
GBP/USD and EUR/USD: Strong positive correlation (0.89)
S&P 500 and Ethereum: Strong positive correlation (0.88)
Ethereum and NASDAQ: Strong positive correlation (0.88)
Russell 2000 and Copper: Strong positive correlation (0.87)
Dow Jones and Ethereum: Strong positive correlation (0.87)
Copper and Dow Jones: Strong positive correlation (0.86)
USD/JPY and 10-Year Treasury Yield: Strong positive correlation (0.86)
USD/JPY and Interest Rate: Strong positive correlation (0.86)
Bitcoin and Russell 2000: Strong positive correlation (0.85)
Copper and Bitcoin: Strong positive correlation (0.85)
S&P 500 and Copper: Strong positive correlation (0.85)
Dow Jones and Gold: Strong positive correlation (0.85)
Ethereum and Russell 2000: Strong positive correlation (0.85)
Silver and S&P 500: Strong positive correlation (0.85)
Russell 2000 and NASDAQ: Strong positive correlation (0.84)
Copper and NASDAQ: Strong positive correlation (0.84)
Dow Jones and Russell 2000: Strong positive correlation (0.84)
Dow Jones and Silver: Strong positive correlation (0.83)
Ethereum and Dogecoin: Strong positive correlation (0.83)
Russell 2000 and S&P 500: Strong positive correlation (0.81)
Silver and Copper: Strong positive correlation (0.81)
Silver and Bitcoin: Strong positive correlation (0.81)
Dogecoin and Copper: Strong positive correlation (0.79)
Russell 2000 and Dogecoin: Strong positive correlation (0.78)
Gold and Bitcoin: Strong positive correlation (0.77)
Silver and Russell 2000: Strong positive correlation (0.76)
Bitcoin and Dogecoin: Strong positive correlation (0.73)
Ethereum and Silver: Strong positive correlation (0.73)
USD/JPY and S&P 500: Strong positive correlation (0.72)
Dow Jones and USD/JPY: Strong positive correlation (0.71)
Gold and Copper: Strong positive correlation (0.69)
Gold and Ethereum: Strong positive correlation (0.69)
NASDAQ and Dogecoin: Strong positive correlation (0.68)
Oil and Copper: Strong positive correlation (0.68)
Dow Jones and Dogecoin: Strong positive correlation (0.68)
S&P 500 and Dogecoin: Strong positive correlation (0.66)
Gold and USD/JPY: Strong positive correlation (0.65)
Litecoin and GBP/USD: Strong positive correlation (0.64)
Natural Gas and Oil: Strong positive correlation (0.62)
Interest Rate and Oil: Strong positive correlation (0.62)
Oil and 10-Year Treasury Yield: Strong positive correlation (0.62)
USD/JPY and Oil: Strong positive correlation (0.61)
Dogecoin and Silver: Strong positive correlation (0.61)
Oil and Dow Jones: Strong positive correlation (0.60)
NASDAQ and USD/JPY: Strong positive correlation (0.60)
Ethereum and Oil: Strong positive correlation (0.59)
Russell 2000 and Gold: Strong positive correlation (0.58)
S&P 500 and Oil: Strong positive correlation (0.57)
Litecoin and Dogecoin: Strong positive correlation (0.54)
Russell 2000 and Oil: Strong positive correlation (0.54)
EUR/USD and Litecoin: Strong positive correlation (0.54)
USD/JPY and Bitcoin: Strong positive correlation (0.53)
Ethereum and USD/JPY: Strong positive correlation (0.52)
Russell 2000 and Litecoin: Strong positive correlation (0.51)
Copper and USD/JPY: Strong positive correlation (0.50)
- S&P 500 and Dow Jones: Strong positive correlation (0.99)
- Strong Negative Correlation
- Interest Rate and EUR/USD: Strong negative correlation (-0.53)
10-Year Treasury Yield and EUR/USD: Strong negative correlation (-0.53)
GBP/USD and USD/JPY: Strong negative correlation (-0.54)
USD/JPY and EUR/USD: Strong negative correlation (-0.71)
- Interest Rate and EUR/USD: Strong negative correlation (-0.53)
import yfinance as yf
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
from datetime import datetime
# 출력 설정
pd.set_option('display.max_rows', None) # 모든 행 표시
pd.set_option('display.max_columns', None) # 모든 열 표시
# 데이터 다운로드 함수
def get_data(ticker, start_date, end_date):
data = yf.download(ticker, start=start_date, end=end_date)
return data['Close']
# 금리 데이터 다운로드 (10년물 국채 수익률)
def get_interest_rate_data(start_date, end_date):
rate_data = yf.download('^TNX', start=start_date, end=end_date) # 10-Year Treasury Yield
return rate_data['Close']
# 상관관계 검증 함수
def analyze_correlation(data_dict):
combined_data = pd.concat(data_dict, axis=1)
combined_data.columns = list(data_dict.keys())
combined_data = combined_data.dropna()
# 상관계수 계산
correlation_matrix = combined_data.corr()
# 상관관계 시각화
plt.figure(figsize=(14, 12))
sns.heatmap(correlation_matrix, annot=True, cmap='coolwarm', center=0)
plt.title('Correlation between Different Market Data')
plt.show()
# 상관관계가 높은 순으로 정렬
sorted_correlations = correlation_matrix.unstack().sort_values(ascending=False)
# 중복 제거: 자기 상관관계 및 중복 데이터 제거
sorted_correlations = sorted_correlations[sorted_correlations < 1] # 자기 상관관계 제외
sorted_correlations = sorted_correlations[~sorted_correlations.index.duplicated(keep='first')] # 중복 인덱스 제거
return sorted_correlations
# 상관관계 해석 함수
def interpret_correlations(correlations):
interpretation = {}
seen_pairs = set()
for (asset1, asset2), value in correlations.items():
# 자기 상관관계는 건너뜁니다.
if asset1 != asset2 and (asset2, asset1) not in seen_pairs:
if value > 0.5:
interpretation[(asset1, asset2)] = f"Strong positive correlation ({value:.2f})"
elif value < -0.5:
interpretation[(asset1, asset2)] = f"Strong negative correlation ({value:.2f})"
seen_pairs.add((asset1, asset2)) # 쌍 추가
return interpretation
# 매개변수 설정
start_date = '2010-01-01'
end_date = datetime.now().strftime('%Y-%m-%d') # 오늘 날짜
# 데이터 다운로드
tickers = {
'S&P 500': '^GSPC',
'Gold': 'GC=F', # 금 선물
'Silver': 'SI=F', # 은 선물
'Oil': 'CL=F', # 원유 선물
'Copper': 'HG=F', # 구리 선물
'Natural Gas': 'NG=F', # 천연가스 선물
'NASDAQ': '^IXIC', # 나스닥 지수
'Dow Jones': '^DJI', # 다우 존스 지수
'Russell 2000': '^RUT', # 러셀 2000 지수
'EUR/USD': 'EURUSD=X', # 유로/달러 환율
'GBP/USD': 'GBPUSD=X', # 파운드/달러 환율
'USD/JPY': 'JPY=X', # 달러/엔 환율
'Bitcoin': 'BTC-USD', # 비트코인
'Ethereum': 'ETH-USD', # 이더리움
'Litecoin': 'LTC-USD', # 라이트코인
'Dogecoin': 'DOGE-USD', # 도지코인
'10-Year Treasury Yield': '^TNX', # 10년물 국채 수익률
'VIX': '^VIX', # 변동성 지수
}
data_dict = {}
for name, ticker in tickers.items():
data_dict[name] = get_data(ticker, start_date, end_date)
# 금리 데이터 추가
data_dict['Interest Rate'] = get_interest_rate_data(start_date, end_date)
# 상관관계 분석
sorted_correlations = analyze_correlation(data_dict)
# 상관관계 해석
correlation_interpretation = interpret_correlations(sorted_correlations)
# 결과 출력
print("Sorted Correlations:\n", sorted_correlations)
print("\nStrong Correlation Interpretations:")
for (asset1, asset2), interpretation in correlation_interpretation.items():
print(f"{asset1} and {asset2}: {interpretation}")
'투자 분석' 카테고리의 다른 글
[재무제표] 손익계산서 분석 (5) | 2024.10.05 |
---|---|
[Risk Hedging] 시장 별 관계성 분석 (2) | 2024.09.20 |
[돌파매매] 투자 전략 검증 (0) | 2024.09.20 |
[모멘텀] 투자 전략 검증 (0) | 2024.09.20 |
9/2 트레이딩 머신 적용 (6) | 2024.09.03 |