最近大家都在讨论存量房贷下调利率的事情,今天我们来算一下房贷利率下调之后能省下多少钱
一、贷款计算器-等额本金VS等额本息
class LoanCalculator:
def average_capital(self,loan_amount,loan_years,rate_year):
"""
每月还款金额 = (借款金额/期数)+(借款本金-累计已还款金额)*月利率
:param loan_amount: 贷款金额
:param loan_years: 贷款年限
:param rate_year: 贷款年利率
:return:
"""
interest = 0
month_rate = rate_year/100 / 12
principal = loan_amount / loan_years / 12
for i in range(0,loan_years*12):
if i == 0:
month_amount = principal + (loan_amount * month_rate)
print(f'第{i+1}期还款金额:',month_amount)
else:
month_amount = principal +(loan_amount * month_rate)
print(f'第{i+1}期还款金额:',month_amount)
interest += loan_amount * month_rate
loan_amount -= principal
print("总利息",interest)
def equality_corp(self,loan_amount,loan_years,rate_year):
"""
月利息 = 贷款金额 * 月利率
每月应还金额 = 贷款金额 * (月利率 * (1 + 月利率) ** 贷款月数) / ((1 + 月利率) ** 贷款月数 - 1)
:param loan_amount: 贷款本金
:param loan_years: 贷款月数
:param rate_year: 贷款年利率
:return:
"""
total_interest = 0
month_rate = rate_year/100/12
loan_month = loan_years * 12
amount = loan_amount * (month_rate * (1 + month_rate) ** loan_month) / ((1 + month_rate) ** loan_month - 1)
print('等额本息每月还款金额:',amount)
for i in range(0,loan_month):
interest = loan_amount * month_rate
print(f'第{i+1}期还款利息:', interest)
total_interest += interest
principal = amount - interest
print(f'第{i+1}期还款本金:',principal)
loan_amount -= principal
print("等额本息还款总利息:",total_interest)
if __name__ == '__main__':
cl = LoanCalculator()
cl.average_capital(loan_amount=500000,loan_years=20,rate_year=5.9)
cl.equality_corp(loan_amount=500000,loan_years=20,rate_year=5.9)