図:5%成長するファンドが2%配当金を払う場合と払わない場合の基準価額
from NISAにVTは向いてない?
https://gyazo.com/6b959f6d60450fb9ee7260bc87eeb273
外国税額控除ありのシミュレーション
code:main.py
import matplotlib.pyplot as plt
# 定義された条件
annual_growth_rate = 0.05
dividend_rate = 0.02
initial_investment = 10**7
investment_period = 20
us_tax_rate = 0.1
jp_tax_rate = 0.2
# 資産推移を保持するリスト
nisa_account_final = initial_investment
non_nisa_account_final = 0
regular_growth = initial_investment
# シミュレーション
for year in range(1, investment_period + 1):
dividend_nisa = nisa_account_final-1 * dividend_rate * (1 - us_tax_rate)
nisa_growth = nisa_account_final-1 * (1 + annual_growth_rate - dividend_rate)
nisa_account_final.append(nisa_growth)
dividend_non_nisa = non_nisa_account_final-1 * dividend_rate
# 米国税を差し引く
dividend_non_nisa_after_tax = dividend_non_nisa * (1 - us_tax_rate) * (1 - jp_tax_rate)
# 税額控除のために米国税を計算しておく
us_tax = dividend_non_nisa * us_tax_rate
# 年度ごとにdevidend_non_nisa_after_us_taxを出力
print(f"Year {year}: {us_tax}")
# 米国税を差し引いた後の配当を加算
non_nisa_growth = non_nisa_account_final-1 * (1 + annual_growth_rate - dividend_rate) + dividend_non_nisa_after_tax + dividend_nisa + us_tax
non_nisa_account_final.append(non_nisa_growth)
regular_growth.append(regular_growth-1 * (1 + annual_growth_rate))
# 相対誤差の計算
relative_error = (n + nn - rg) / rg * 100 for n, nn, rg in zip(nisa_account_final, non_nisa_account_final, regular_growth)
# グラフの描画
fig, (ax1, ax2) = plt.subplots(2, 1, figsize=(10, 10))
ax1.plot(nisa_account_final, label="NISA Account (Final)")
ax1.plot(n + nn for n, nn in zip(nisa_account_final, non_nisa_account_final), label="NISA + Non-NISA Account (Final)")
ax1.plot(regular_growth, label="Regular Growth (5%)")
ax1.set_ylabel("Amount (JPY)")
ax1.set_title("Investment Simulation Over 20 Years (Final Corrected)")
ax1.legend()
ax1.grid(True)
ax2.plot(relative_error, label="Relative Error (NISA + Non-NISA vs Regular Growth)", color="red")
ax2.set_xlabel("Year")
ax2.set_ylabel("Relative Error (%)")
ax2.set_title("Relative Error Between NISA + Non-NISA and Regular Growth")
ax2.legend()
ax2.grid(True)
plt.tight_layout()
plt.show()
https://gyazo.com/523d815b5afcaea19a28a6988b916dfb
code:実行方法
rye init
rye add matplotlib
rye sync
rye run python main.py
code:main.py
import matplotlib.pyplot as plt
# 定義された条件
annual_growth_rate = 0.05
dividend_rate = 0.02
initial_investment = 10**7
investment_period = 20
us_tax_rate = 0.1
jp_tax_rate = 0.2
# 資産推移を保持するリスト
nisa_account_final = initial_investment
non_nisa_account_final = 0
regular_growth = initial_investment
# シミュレーション
for year in range(1, investment_period + 1):
dividend_nisa = nisa_account_final-1 * dividend_rate * (1 - us_tax_rate)
nisa_growth = nisa_account_final-1 * (1 + annual_growth_rate - dividend_rate)
nisa_account_final.append(nisa_growth)
dividend_non_nisa = non_nisa_account_final-1 * dividend_rate
dividend_non_nisa_after_tax = dividend_non_nisa * (1 - us_tax_rate) * (1 - jp_tax_rate)
non_nisa_growth = non_nisa_account_final-1 * (1 + annual_growth_rate - dividend_rate) + dividend_non_nisa_after_tax + dividend_nisa
non_nisa_account_final.append(non_nisa_growth)
regular_growth.append(regular_growth-1 * (1 + annual_growth_rate))
# 相対誤差の計算
relative_error = (n + nn - rg) / rg * 100 for n, nn, rg in zip(nisa_account_final, non_nisa_account_final, regular_growth)
# グラフの描画
fig, (ax1, ax2) = plt.subplots(2, 1, figsize=(10, 10))
ax1.plot(nisa_account_final, label="NISA Account (Final)")
ax1.plot(n + nn for n, nn in zip(nisa_account_final, non_nisa_account_final), label="NISA + Non-NISA Account (Final)")
ax1.plot(regular_growth, label="Regular Growth (5%)")
ax1.set_ylabel("Amount (JPY)")
ax1.set_title("Investment Simulation Over 20 Years (Final Corrected)")
ax1.legend()
ax1.grid(True)
ax2.plot(relative_error, label="Relative Error (NISA + Non-NISA vs Regular Growth)", color="red")
ax2.set_xlabel("Year")
ax2.set_ylabel("Relative Error (%)")
ax2.set_title("Relative Error Between NISA + Non-NISA and Regular Growth")
ax2.legend()
ax2.grid(True)
plt.tight_layout()
plt.show()
--
https://gyazo.com/b6741692d29670b3c6844958a70f4c91
2%の配当を払い、配当の20%の税金が取られ、再投資なし
2%の配当を払い、配当の20%の税金が取られ、配当は手動で全額再投資する
配当が出ず、税金も取られない
前提がおかしいな
実際にはこうだ
配当2%に対して10%の税金がかかる。これが税額控除できない
残りの再投資した配当はNISA枠ではないから、そこからでた配当には外国税が10%、日本の税金が20%かかる
これが考慮されていない
code:py
import matplotlib.pyplot as plt
# Constants
initial_investment = 10000000
annual_addition = 1000000
annual_growth_rate = 1.05
dividend_rate = 0.02
tax_rate = 0.20
years = 20
def calculate_corrected_cases():
case1 = initial_investment
case2 = initial_investment
case3 = initial_investment # No dividend, no tax
for year in range(1, years + 1):
# Case 1: Dividend paid, taxed, not reinvested
dividend1 = case1-1 * dividend_rate
taxed_dividend1 = dividend1 * (1 - tax_rate)
# 元手から税引き後の配当金を引いているので、間違っていそう
growth1 = (case1-1 - taxed_dividend1) * annual_growth_rate
case1.append(growth1 + annual_addition)
# Case 2: Dividend paid, taxed, reinvested
dividend2 = case2-1 * dividend_rate
reinvested_dividend2 = dividend2 * (1 - tax_rate)
# (元金-配当金)*成長率
growth2 = (case2-1 - reinvested_dividend2) * annual_growth_rate
# 配当金を再投資
case2.append(growth2 + reinvested_dividend2 + annual_addition)
# Case 3: No dividend, no tax
growth3 = case3-1 * annual_growth_rate
case3.append(growth3 + annual_addition)
return case1, case2, case3
# Calculating the corrected cases
case1_corrected, case2_corrected, case3_corrected = calculate_corrected_cases()
# Calculating the relative errors for comparison
relative_error_case1_vs_case3 = (case1 - case3) / case3 * 100 for case1, case3 in zip(case1_corrected, case3_corrected)
relative_error_case2_vs_case3 = (case2 - case3) / case3 * 100 for case2, case3 in zip(case2_corrected, case3_corrected)
# Plotting the main graph and relative errors as subplots
fig, (ax1, ax2) = plt.subplots(2, 1, figsize=12, 10)
# Main graph
ax1.plot(range(years + 1), amount for amount in case1_corrected, marker='o', label="No Reinvestment of Dividend")
ax1.plot(range(years + 1), amount for amount in case2_corrected, marker='o', label="Reinvestment of Dividend")
ax1.plot(range(years + 1), amount for amount in case3_corrected, marker='o', label="No Dividend, No Tax")
ax1.set_title('Comparison of Investment Strategies Over 20 Years')
ax1.set_xlabel('Year')
ax1.set_ylabel('Amount (yen)')
ax1.legend()
ax1.grid(True)
# Relative errors
ax2.plot(range(years + 1), relative_error_case1_vs_case3, marker='o', label="Relative Error: No Reinvestment vs No Dividend")
ax2.plot(range(years + 1), relative_error_case2_vs_case3, marker='o', label="Relative Error: Reinvestment vs No Dividend")
ax2.set_title('Relative Errors Compared to No Dividend Case Over 20 Years')
ax2.set_xlabel('Year')
ax2.set_ylabel('Relative Error (%)')
ax2.legend()
ax2.grid(True)
plt.tight_layout()
plt.show()
https://gyazo.com/d8a6700665f17df7614895bd7987c545
code:py
import matplotlib.pyplot as plt
# Initial investment amount
initial_investment = 10_000_000 # 1000万円
# Annual growth rate
growth_rate = 0.05 # 5%
# Dividend rate
dividend_rate = 0.02 # 2%
# Number of years
years = 10
# Lists to store yearly investment amounts
investment_with_dividend_list = initial_investment
investment_without_dividend_list = initial_investment
# Calculating the yearly amounts for both scenarios
investment_with_dividend_temp = initial_investment
for year in range(years):
profit = investment_with_dividend_temp * growth_rate
dividend = profit * dividend_rate
investment_with_dividend_temp += profit - dividend
investment_with_dividend_list.append(investment_with_dividend_temp)
investment_without_dividend_list.append(initial_investment * (1 + growth_rate) ** (year + 1))
# Calculating the yearly differences between the two scenarios
yearly_differences = [investment_without_dividend_listi - investment_with_dividend_listi for i in range(years + 1)]
# Plotting the main graph for investment amount comparison
fig, axes = plt.subplots(2, 1, figsize=10,10, sharex=True)
axes0.plot(investment_with_dividend_list, label='With Dividends', marker='o')
axes0.plot(investment_without_dividend_list, label='Without Dividends', marker='x')
axes0.set_title('Comparison of Investment with and without Dividends over 10 Years')
axes0.set_ylabel('Investment Amount (in Yen)')
axes0.legend()
axes0.grid(True)
# Plotting the subplot for yearly differences
axes1.plot(yearly_differences, label='Difference Without - With Dividends', marker='s')
axes1.set_title('Yearly Differences between Without and With Dividends')
axes1.set_xlabel('Year')
axes1.set_ylabel('Difference Amount (in Yen)')
axes1.legend()
axes1.grid(True)
plt.show()
同じ条件で毎年100万円積んだ場合
https://gyazo.com/02f65174eaff1a22ea426b7998e2eba6
code:py
import matplotlib.pyplot as plt
# Initial investment amount
initial_investment = 10_000_000 # 1000万円
# Annual growth rate
growth_rate = 0.05 # 5%
# Dividend rate
dividend_rate = 0.02 # 2%
# Number of years
years = 10
# Annual addition
annual_addition = 1_000_000 # 100万円
# Lists to store yearly investment amounts
investment_with_dividend_list = initial_investment
investment_without_dividend_list = initial_investment
investment_with_dividend_and_addition_list = initial_investment
investment_without_dividend_and_addition_list = initial_investment
# Calculating the yearly amounts for all scenarios
investment_with_dividend_temp = initial_investment
investment_without_dividend_temp = initial_investment
investment_with_dividend_and_addition_temp = initial_investment
investment_without_dividend_and_addition_temp = initial_investment
for year in range(years):
# With Dividends
profit_with_dividend = investment_with_dividend_temp * growth_rate
dividend_with_dividend = profit_with_dividend * dividend_rate
investment_with_dividend_temp += profit_with_dividend - dividend_with_dividend
investment_with_dividend_list.append(investment_with_dividend_temp)
# Without Dividends
investment_without_dividend_temp = investment_without_dividend_temp * (1 + growth_rate)
investment_without_dividend_list.append(investment_without_dividend_temp)
# With Dividends and Addition
profit_with_dividend_and_addition = investment_with_dividend_and_addition_temp * growth_rate
dividend_with_dividend_and_addition = profit_with_dividend_and_addition * dividend_rate
investment_with_dividend_and_addition_temp += profit_with_dividend_and_addition - dividend_with_dividend_and_addition + annual_addition
investment_with_dividend_and_addition_list.append(investment_with_dividend_and_addition_temp)
# Without Dividends and Addition
investment_without_dividend_and_addition_temp = (investment_without_dividend_and_addition_temp + annual_addition) * (1 + growth_rate)
investment_without_dividend_and_addition_list.append(investment_without_dividend_and_addition_temp)
# Calculating the yearly differences between the two scenarios
yearly_differences = [investment_without_dividend_listi - investment_with_dividend_listi for i in range(years + 1)]
yearly_differences_with_addition = [investment_without_dividend_and_addition_listi - investment_with_dividend_and_addition_listi for i in range(years + 1)]
# Plotting the main graph for investment amount comparison
fig, axes = plt.subplots(2, 1, figsize=10,10, sharex=True)
axes0.plot(investment_with_dividend_list, label='With Dividends, No Addition', marker='o')
axes0.plot(investment_without_dividend_list, label='Without Dividends, No Addition', marker='x')
axes0.plot(investment_with_dividend_and_addition_list, label='With Dividends, Annual Addition', marker='s')
axes0.plot(investment_without_dividend_and_addition_list, label='Without Dividends, Annual Addition', marker='d')
axes0.set_title('Comparison of Investment over 10 Years')
axes0.set_ylabel('Investment Amount (in Yen)')
axes0.legend()
axes0.grid(True)
# Plotting the subplot for yearly differences
axes1.plot(yearly_differences, label='Difference Without - With Dividends (No Addition)', marker='s')
axes1.plot(yearly_differences_with_addition, label='Difference Without - With Dividends (Annual Addition)', marker='d')
axes1.set_title('Yearly Differences')
axes1.set_xlabel('Year')
axes1.set_ylabel('Difference Amount (in Yen)')
axes1.legend()
axes1.grid(True)
plt.show()