앞에서 생성한 데이터를 이용하여 ETF간 상관관계를 분석합니다.
date_cnt = 0
amount_cnt = 0
total_cnt = 0
tic = []
for idx,row in ticdf.iterrows():
ticker = row['ticker']
first_day = row['first_day']
last_amt = int((row['last_close'] * row['last_volume']) / 1000000)
if first_day > '2002-01-01':
pass
else:
date_cnt = date_cnt + 1
if last_amt < 10:
pass
else:
amount_cnt = amount_cnt + 1
if first_day > '2002-01-01' or last_amt < 10:
pass
else:
total_cnt = total_cnt + 1
tic.append(ticker)
print("%4d %4s %s %6s" %(total_cnt, ticker, first_day, format(last_amt, ',')))
print("일자기준건수: ", date_cnt, " 금액기준건수:", amount_cnt, " 조건만족건수:", total_cnt)
ETF를 이용하여 퀀트전략을 수행 시 거래대금도 중요하지만 장기 시계열데이터의 확보도 무엇보다 중요합니다.
여기에선 10년이상 데이터가 존재하면서 일거래대금이 1000만달러 이상되는 ETF 데이터만 추출하려고 합니다.
수행결과 일자기준건수: 101건, 금액기준건수: 601건, 둘다 만족하는건수: 85건이 나왔습니다.
targetdf = Closedf[tic].copy()
ok = targetdf.index >= '2002-01-01'
targetdf = targetdf[ok]
corrdf = targetdf.corr()
위 85건 데이터에 대해 상장일이 서로 다르므로 2002-01-01이후 데이터만 가지고 상관관계를 분석한다.
corrresultdf = corrdf.copy()
for i in range (0, len(corrdf)):
for j in range (0, len(corrdf)):
if (corrdf.iloc[i][j] > 0.2 or corrdf.iloc[i][j] < -0.2):
corrresultdf.iat[i, j] = 0
corrresultdf = corrresultdf.round(2)
corrresultdf = corrresultdf.astype(str)
corrresultdf = corrresultdf.replace('0.0', '')
데이터 중 상관계수가 -0.2 ~ 0.2 사이의 약한 상관관계에 있는 데이터만 추출해본다.
corrresultdf.to_csv('drive/My Drive/ETF/ETFCorr02_211221.csv')
SPY의 경우 상관관계가 낮은 ETF는 EWI와 EWZ으로 나타났다.
특이하게 EWI와 EWZ은 대부분의 ETF와 약한 상관관계를 보인다. 매우 흥미로운 결과이다!! -> 혹시 내가 분석한 자료에 뭔가 문제가 있나 ?? -> 혹시 문제점이 보이게 되면 지적해주시면 감사~~
EWI : 이탈리아에 투자하는 ETF
EWZ : 브라질에 투자하는 ETF
import matplotlib.pyplot as plt
import seaborn as sns
plt.figure(figsize=(50,50))
sns.heatmap(data = targetdf.corr(), annot=True, fmt = '.2f', linewidths=.5, cmap='Blues')
앞의 ETF간 상관계수를 히트맵 그래프를 이용하여 그려본다.
'퀀트(Quant)' 카테고리의 다른 글
6. ETF 기본데이터 추출(거래대금 상위 데이터) (0) | 2021.12.25 |
---|---|
5. ETF 기본데이터 추출(주가 및 거래량 합치기) (0) | 2021.12.25 |
4. ETF 기본데이터 추출(종가 데이터 합치기) (0) | 2021.12.25 |
3. ETF 기본데이터 추출(거래량 데이터 합치기) (0) | 2021.12.25 |
2. ETF 기본데이터 추출(주가) (0) | 2021.12.25 |