Python笔记-房贷计算(本息和本⾦,每⽉还利息和每⽉还本
⾦)及作图对⽐
如下例⼦:
贷款100万元,如果20年还清,年贷款利率为6%,如果按照等额还款,每⽉需要还款多少,如果按照等额本⾦还款,绘制每⽉还款额度
通过做图画⽐较,两种还款⽅式,每⽉还款的本⾦,利息以及总还款额和剩余本⾦(绘制图形,展⽰两种⽅式下,每⽉的还款额,本⾦以及利息和剩余本⾦)
以及两种还款⽅式下,两种还款⽅式下总还款额的差值。
⽤贝壳来计算看看。
⾸先是本息:
然后是本⾦:
下⾯⽤Python计算下,代码如下:
# -*- coding: utf-8 -*-
import matplotlib.pyplot as plt
import numpy as np
import seaborn as sns
import matplotlib as mpl
# 等额本息-每⽉还款额
def DEBXMonthlyPaymentCal(principal, yearRate, month):
monthRate = yearRate / 12
ret = (principal * (monthRate * (1 + monthRate) ** month)) / ((1 + monthRate) ** month - 1) return ret
pass
# 等额本息-总⽀付利息
发票未盖章打一成语def DEBXTotalInterestCal(principal, monthPay, month):
ret = month * monthPay - principal
return ret
pass
# 等额本息-每⽉应还利息
def DEBXMonthlyPaymentInterestCal(principal, yearRate, month, monthPay):
monthRate = yearRate / 12
IR = [0] * month #每⽉利息
YE = [0] * month #每⽉贷款余额
BJ = [0] * month # 每⽉偿还本⾦
YE[0] = principal
for i in range(0, month):
IR[i] = YE[i] * monthRate
BJ[i] = monthPay - IR[i]
if i < month - 1:
YE[i + 1] = YE[i] - BJ[i]什么牌子的音箱好
pass
return IR永州美食
pass
# 等额本息-每⽉应还本⾦
# 等额本息-每⽉应还本⾦
def DEBXMonthlyPrincipalCal(principal, yearRate, month, monthPay): monthRate = yearRate / 12
黑白照片变彩IR = [0] * month #每⽉利息
YE = [0] * month #每⽉贷款余额
BJ = [0] * month # 每⽉偿还本⾦
YE[0] = principal
for i in range(0, month):
IR[i] = YE[i] * monthRate
BJ[i] = monthPay - IR[i]
if i < month - 1:
YE[i + 1] = YE[i] - BJ[i]
pass
return BJ
pass
# 等额本⾦-每⽉应还款额
浅绿def DEBJMonthlyPaymentCal(principal, yearRate, month):
收回孤单monthRate = yearRate / 12
MB = principal / month # 每⽉本⾦
# 初始化相关变量
IR = [0] * month # 每⽉利息
YE = [0] * month # 每⽉贷款余额
MP = [0] * month # 每⽉还款额
YE[0] = principal
for i in range(0, month):
IR[i] = YE[i] * monthRate
MP[i] = MB + IR[i]
if i < month - 1:
YE[i + 1] = YE[i] - MB
return MP
pass
# 等额本⾦-总⽀付利息
def DEBJTotalInterestCal(principal, monthPayArray):
totalPay = 0
for pay in monthPayArray:
totalPay += pay
pass
ret = totalPay - principal
return ret
pass
# 等⾦本息-每⽉应还利息
def DEBJMonthlyPaymentInterestCal(principal, yearRate, month):
monthRate = yearRate / 12
MB = principal / month # 每⽉本⾦
# 初始化相关变量
IR = [0] * month # 每⽉利息
YE = [0] * month # 每⽉贷款余额
MP = [0] * month # 每⽉还款额
YE[0] = principal
for i in range(0, month):
IR[i] = YE[i] * monthRate
MP[i] = MB + IR[i]
if i < month - 1:
YE[i + 1] = YE[i] - MB
return IR
pass
# 等额本⾦-每⽉应还本⾦
def DEBJMonthlyPrincipalCal(principal, month):
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论