200字范文,内容丰富有趣,生活中的好帮手!
200字范文 > [Python]等额本息房贷计算器

[Python]等额本息房贷计算器

时间:2022-06-16 09:02:49

相关推荐

[Python]等额本息房贷计算器

等额本息还款法:

每月月供额=〔贷款本金×月利率×(1+月利率)^还款月数〕÷〔(1+月利率)^还款月数-1〕

每月应还利息=贷款本金×月利率×〔(1+月利率)^还款月数-(1+月利率)^(还款月序号-1)〕÷〔(1+月利率)^还款月数-1〕

每月应还本金=贷款本金×月利率×(1+月利率)^(还款月序号-1)÷〔(1+月利率)^还款月数-1〕

总利息=还款月数×每月月供额-贷款本金

比如贷款200万,年贷款利率4.9%,贷款期限30年

根据等额本息,算出每个月还贷10614.53,贷款200万,还了182.12万的利息

第一个月还的10614.53中,8166.67还的是利息,2447.87还的是本金

第二月还了8156.67的利息,2457.86的本金

以此类推

运行结果

代码如下

def monthlyPayment(principal, year_rate, year_duration):monthly_rate = year_rate / (12 * 100) # convert 4.9 to 0.049 and monthly interest ratemonth_amounts = year_duration * 12# 每月月供monthly_payment = (principal * monthly_rate * (1 + monthly_rate) ** month_amounts) / ((1 + monthly_rate) ** month_amounts - 1)#总利息total_interest_payable = monthly_payment * month_amounts - principalprint('-----------------------------------')print ('Total interest payable is %.2f ' % total_interest_payable)for i in range (1, month_amounts + 1):#每月应还利息monthly_interest_payable = principal * monthly_rate * ((1 + monthly_rate) ** month_amounts - (1 + monthly_rate) ** (i - 1 ))/ ((1 + monthly_rate) ** month_amounts -1)#每月应还本金monthly_principal_payable = principal * monthly_rate * (1 + monthly_rate) ** (i - 1)/ ((1 + monthly_rate) ** month_amounts -1)#每月利息占比monthly_interest_percentage = monthly_interest_payable * 100 / monthly_paymentprint('-----------------------------------')print ('%dth monthly payment is : %.2f (Interest: %.2f and Principal: %.2f)' % (i, monthly_payment,monthly_interest_payable,monthly_principal_payable))print('%dth month interest percentage is %.2f %%' % (i,monthly_interest_percentage))returnif __name__ == '__main__':principal = int(input('Please input your loan amounts:'))year_rate = float(input('Please input Year Debt Interest Rate:(such as 4.9,it means 4.9%)'))year_duration = int(input('Please input Debt Year Duration:'))monthlyPayment(principal, year_rate, year_duration)

根据等额本息法公式可以计算出每月还款,具体每月还款里面,多少是利息,多少是本金,除了用之前的公式,还可以用下面的方法考虑

还是用上面的例子 ,贷款200万,年贷款利率4.9%,贷款期限30年,等额本息每个月需还贷10614.53

第一个月房贷里还的利息是2,000,000×(4.9%/12)= 8166.67

得出第一个房贷还的本金是 10614.53 - 8166.67 = 2447.87

剩余总本金为2,000,000-2447.87 = 1,997,552.13

---------------------------------------------------------------------

第二个月房贷需要还的利息为:剩余总本金×月利息:1,997,552.13 ×(4.9%/12) = 8156.67

第二个月房贷还的本金是10614.53 - 8156.67 = 2457.86

剩余总本金为1,997,552.131-2457.87 = 1,995,094.26

----------------------------------------------------------------------

第三个月房贷需要还的利息为:为剩余总本金×月利息:1,995,094.26×(4.9%/12) = 8146.63

第三个月房贷还的本金是10614.53 - 8146.63 = 2467.89

剩余总本金为1,995,094.26-2467.89= 1,992,626.37

以此类推

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。