본문 바로가기
업무자동화 with Python

[업무자동화 with Python] SCHD의 투자 적기는? 월별/분기별/요일별 평균 수익률 계산 결과

by CodeCrafter 2025. 3. 9.
반응형

 이번에는 SCHD ETF의 주가 데이터에 대한 간단한 통계분석을 진행해보겠습니다.

 

 분석을 위해서 파이썬의 yfinance 라이브러리르 통해서 손쉽게 데이터를 가져오고 이를 통해서 간단한 통계 분석 결과를 시각화 해서 투자에 도움이 되는 정보를 도출해보겠습니다.

 

1. SCHD의 투자 적기는? 월별/분기별/요일별 평균 수익률 계산 결과

- SCHD는 장기적인 투자에 적합한 안정적인 배당성장 ETF입니다.

 

- 언제 투자해도 좋겠으나, 그래도 어떤 월, 분기, 요일에 투자하면 좋을지 파이썬을 활용해서 분석해보겠습니다.

 

- 간단한 통계분석이고, 이는 코랩에서 실행해보았습니다.

 

- 먼저 사용할 라이브러리와 데이터를 가져옵니다.

import yfinance as yf
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns

# 📌 데이터 다운로드
ticker = "SCHD"
schd = yf.download(ticker, start="2011-01-01", end="2025-01-01")

# 📌 로그 수익률 계산
schd['Log_Return'] = np.log(schd['Close'] / schd['Close'].shift(1))

 

- 분석할 기간은 최근 1,3,5,7,9,11,13년 이라는 기간으로 다양한 텀으로 설정하였습니다.

- 분석할 데이터는 월별/분기별/요일별 SCHD의 평균 수익률은 어땠는지 통계적으로 확인해보는 것입니다.

# 📌 분석할 기간 리스트 (최근 1, 3, 5, 7, 9, 11, 13년)
time_frames = [1, 3, 5, 7, 9, 11, 13]
reference_date = schd.index.max()  # 가장 최근 날짜

# 📌 데이터 저장을 위한 리스트
monthly_data = []
quarterly_data = []
weekday_data = []

for years in time_frames:
    start_date = reference_date - pd.DateOffset(years=years)
    df_filtered = schd.loc[start_date:]

    # 📌 월별 평균 수익률
    df_filtered['Month'] = df_filtered.index.month
    monthly_returns = df_filtered.groupby('Month')['Log_Return'].mean().reset_index()
    monthly_returns['Years'] = f'Last {years} Years'
    monthly_data.append(monthly_returns)

    # 📌 분기별 평균 수익률
    df_filtered['Quarter'] = df_filtered.index.quarter
    quarterly_returns = df_filtered.groupby('Quarter')['Log_Return'].mean().reset_index()
    quarterly_returns['Years'] = f'Last {years} Years'
    quarterly_data.append(quarterly_returns)

    # 📌 요일별 평균 수익률
    df_filtered['Weekday'] = df_filtered.index.weekday  # 0=월요일, ..., 4=금요일
    weekday_returns = df_filtered.groupby('Weekday')['Log_Return'].mean().reset_index()
    weekday_returns['Years'] = f'Last {years} Years'
    weekday_data.append(weekday_returns)

 

 

- 이제 계산된 리스트 결과를 데이터프레임으로 변환하고 시각화해보겠습니다.

 

* 먼저 월별 평균 수익률입니다.

# 📌 리스트를 데이터프레임으로 변환
monthly_df = pd.concat(monthly_data)
quarterly_df = pd.concat(quarterly_data)
weekday_df = pd.concat(weekday_data)

# 📊 📌 월별 평균 수익률 비교 시각화
plt.figure(figsize=(12, 6))
sns.barplot(data=monthly_df, x='Month', y='Log_Return', hue='Years', palette='coolwarm')
plt.title("SCHD Monthly Average Returns Across Different Time Frames")
plt.xlabel("Month")
plt.ylabel("Average Log Return")
plt.xticks(range(12), ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"])
plt.legend(title="Time Period")
plt.show()

 

* 결과는 아래와 같습니다. SCHD의 성과는 3 / 5 / 7 / 8 / 10 / 11 월에 통상적으로 좋았으며, 그 중에서도 7월과 11월에 좋았습니다. 반대로 6월과 9월 12월에는 통상적으로 좋지 않은 결과가 나왔습니다.

 

* 매수의 관점에서 봤을때는 3 / 7 / 10 / 11월 정도가 괜찮은 기간인 것 같습니다.

 

* 다음은 분기별 결과입니다.

# 📊 📌 분기별 평균 수익률 비교 시각화
plt.figure(figsize=(10, 5))
sns.barplot(data=quarterly_df, x='Quarter', y='Log_Return', hue='Years', palette='Blues')
plt.title("SCHD Quarterly Average Returns Across Different Time Frames")
plt.xlabel("Quarter")
plt.ylabel("Average Log Return")
plt.xticks([0, 1, 2, 3], ["Q1", "Q2", "Q3", "Q4"])
plt.legend(title="Time Period")
plt.show()

 

* 앞선 월별 결과들이 요약된 것이며, 최근과 과거를 모두 고려했을때 3분기가  매수하기에 적당해보입니다.

 

*마지막으로 요일입니다.

# 📊 📌 요일별 평균 수익률 비교 시각화
plt.figure(figsize=(10, 5))
sns.barplot(data=weekday_df, x='Weekday', y='Log_Return', hue='Years', palette='viridis')
plt.title("SCHD Weekday Average Returns Across Different Time Frames")
plt.xlabel("Weekday")
plt.ylabel("Average Log Return")
plt.xticks(range(5), ["Mon", "Tue", "Wed", "Thu", "Fri"])
plt.legend(title="Time Period")
plt.show()

 

* 요일별 평균 수익률은 수요일이 가장 좋지 않으며, 월요일과 금요일에 수익률이 좋은 것을 알 수 있습니다. 

 

 

- 전반적인 결과를 바탕으로 봤을때, 

 

한번 에 목돈을 투자해야한다면  

 

* 7월 또는 11월 중

 

* 월요일 또는 금요일에 

 

투자하면 좋을 결과를 얻을 것으로 보이네요

반응형

댓글