図:積立額を変えたときのDCとNISAの最終的な利益の差
https://gyazo.com/32539185d9d16353a94570bd5dfe49e6
図:積立額を変えたときのDCとNISAの最終的な利益の差
code:py
import matplotlib.pyplot as plt
import numpy as np
annual_income = 5000000
annual_social_fee = 750000 # 社会保険料
annual_basic_deduction = 480000 # 基礎控除
years_of_service = 30 # 勤続年数
years_of_investment = 30 # 今から定年までの期間
annual_growth_rate = 5 # %
annual_taxable_income = annual_income - annual_social_fee - annual_basic_deduction
# Tax calculation functions
def calculate_progressive_tax(income):
tax = 0
lower_limit = 0
tax_brackets = [
(1950000, 0.15),
(3300000, 0.20),
(6950000, 0.30),
(9000000, 0.33),
(18000000, 0.43),
(40000000, 0.5),
(99999999999, 0.55)
]
for upper_limit, rate in tax_brackets:
if income > upper_limit:
tax += (upper_limit - lower_limit) * rate
else:
tax += (income - lower_limit) * rate
break
lower_limit = upper_limit
return tax
def get_japan_tax_rate(income):
if income <= 1949000:
return 0.15
elif 1950000 <= income <= 3299000:
return 0.2
elif 3300000 <= income <= 6949000:
return 0.3
elif 6950000 <= income <= 8999000:
return 0.33
elif 9000000 <= income <= 17999000:
return 0.43
elif 18000000 <= income <= 39999000:
return 0.5
else: # income >= 40000000
return 0.55
# 退職所得控除
def calculate_retirement_deduction(years):
if years <= 20:
return 400000 * years
else:
return 8000000 + 700000 * (years - 20)
# 退職金にかかる税金
def calculate_retirement_tax(retirement_pay, years):
return calculate_progressive_tax((retirement_pay - calculate_retirement_deduction(years)) / 2)
# Function to calculate the total value of investments
def calculate_total_value(monthly_fee, annual_growth_rate, years_of_service):
asset_from_now_growth = (monthly_fee * ((1 + (annual_growth_rate / 12 / 100)) ** (years_of_investment * 12) - 1)) / (annual_growth_rate / 12 / 100);
return asset_from_now_growth
# Function to calculate tax benefit from iDeCo
def calculate_ideco_benefit(monthly_ideco_fee, annual_growth_rate, years_of_service):
annual_ideco_fee = monthly_ideco_fee * 12
post_investment_value = calculate_total_value(monthly_ideco_fee, annual_growth_rate, years_of_service)
ideco_total_tax = calculate_retirement_tax(post_investment_value, years_of_service)
ideco_investment_value = post_investment_value - ideco_total_tax
# 先に税金を引いて運用する
nisa_investment_value = calculate_total_value(monthly_ideco_fee * (1 - get_japan_tax_rate(annual_taxable_income)), annual_growth_rate, years_of_service)
# print(nisa_total_tax)
return ideco_investment_value - nisa_investment_value
# Generate graph
monthly_ideco_fees = np.linspace(5000, 55000, 100) # Range of monthly iDeCo fees to explore
plt.figure(figsize=(10, 6))
plt.plot(monthly_ideco_fees, benefits)
plt.xlabel('Monthly iDeCo Fee (Yen)')
plt.ylabel('DC invest - NISA invest (Yen)')
plt.title('DC invest - NISA invest on Monthly Fee')
plt.grid(True)
plt.show()