CAGR, 배당 수익률로 미래 배당수익률 예측해 보는 파이썬 코드입니다.
조건
1. CAGR: 9%
2. 배당 수익률 3.5%
import matplotlib.pyplot as plt
import pandas as pd
# 초기 설정
initial_investment = 300000000 # 원금 3억원
cagr = 0.09 # CAGR 9%
dividend_rate = 0.035 # 배당률 3.5%
years = 15 # 투자 기간 15년
start_year = 2020 # 시작 연도
# 자산 평가액 및 배당금 계산
asset_values = [initial_investment]
dividends = [0] # 첫 해 배당금 0으로 초기화
for i in range(years):
asset_value = asset_values[-1] * (1 + cagr)
asset_values.append(asset_value)
dividend = asset_value * dividend_rate
dividends.append(dividend)
# 데이터프레임 생성
data = {'연도': range(start_year, start_year + years + 1),
'자산 평가액 (만원)': [round(value / 10000) for value in asset_values],
'배당금 (만원)': [round(dividend / 10000) for dividend in dividends]} # 배당금 계산식 수정
df = pd.DataFrame(data)
# 데이터프레임 출력
display(df)
# 시각화
years_range = range(start_year, start_year + years + 1)
fig, axes = plt.subplots(1, 2, figsize=(15, 5))
# 자산 평가액 바 그래프
bars1 = axes[0].bar(years_range, df['자산 평가액 (만원)'], color = 'skyblue')
axes[0].set_title('자산 평가액 변화')
axes[0].set_xlabel('연도')
axes[0].set_ylabel('자산 평가액 (만원)')
axes[0].ticklabel_format(style='plain', axis='y') # y축 지수 표기 비활성화
# 배당금 바 그래프
bars2 = axes[1].bar(years_range[1:], df['배당금 (만원)'].iloc[1:], color = 'lightcoral')
axes[1].set_title('배당금 변화')
axes[1].set_xlabel('연도')
axes[1].set_ylabel('배당금 (만원)')
axes[1].ticklabel_format(style='plain', axis='y') # y축 지수 표기 비활성화
# 바 위에 값 표시
def autolabel(bars):
for bar in bars:
height = bar.get_height()
axes[0 if bars is bars1 else 1].annotate('{}'.format(height),
xy=(bar.get_x() + bar.get_width() / 2, height),
xytext=(0, 3), # 3 points vertical offset
textcoords="offset points",
ha='center', va='bottom')
autolabel(bars1)
autolabel(bars2)
# 그래프 표시
plt.tight_layout()
plt.show()
실행 결과
'투자 연구소 > 주식 투자 이론' 카테고리의 다른 글
예제를 통해 보는 미국 배당주로 월세 받기 (0) | 2021.05.07 |
---|---|
쌩초보 주린이의 주식 투자법 #4 - 올웨더 포트폴리오 (0) | 2021.05.07 |
쌩초보 주린이의 주식 투자법 #3 - 영구 포트폴리오 (0) | 2021.05.06 |
배당 성장 포트폴리오 전략으로 돈나무 키우기 (2) | 2021.05.05 |
황금알을 낳는 주식 투자 #5 - 나에게 맞는 투자 방법은 무엇인가? (0) | 2021.05.03 |