# 定义利率调整后的月供计算函数
def calculate_monthly_payment(principal, years, rate):
# 将年利率转换为月利率
monthly_rate = rate / 12
# 计算等额本息还款的月供
monthly_payment = (principal * monthly_rate * (1 + monthly_rate) ** years) / ((1 + monthly_rate) ** years - 1)
return monthly_payment
# 定义总利息计算函数
def calculate_total_interest(monthly_payment, principal, years):
# 总还款额 = 月供 × 还款月数
total_payment = monthly_payment * years * 12
# 总利息 = 总还款额 - 本金
total_interest = total_payment - principal
return total_interest
# 利率调整前后的利率
rate_before = 2.85 / 100 # 2.85%
rate_after = 2.6 / 100 # 2.6%
# **金额、年限
principal = 1000000 # 100万元
years = 30 # 30年
# 计算调整前后的月供和总利息
monthly_payment_before = calculate_monthly_payment(principal, years, rate_before)
monthly_payment_after = calculate_monthly_payment(principal, years, rate_after)
total_interest_before = calculate_total_interest(monthly_payment_before, principal, years)
total_interest_after = calculate_total_interest(monthly_payment_after, principal, years)
monthly_payment_before, monthly_payment_after, total_interest_before, total_interest_after