我正在尝试在 python 中进行摊销计算。我使用 PyCharm IDE,它一直得到错误的答案。 MIR 和 MT 是抵押贷款利率和抵押贷款期限(年),在脚本中的输入要高得多。
我不确定问题出在哪里,有什么帮助吗?
monthly_rate = MIR / 100
loan_term_months = MT * 12
balance = Mortgage_Balance
# Top of the equation
math1 = monthly_rate * ((1 + monthly_rate) ** MT) # r(1+r)^n
# Bottom of the equation
math2 = ((1 + monthly_rate) ** MT) - 1 # (1+r)^n -1
# Total Equation
annual_payment = (Mortgage_Balance * math1) / math2 # P (r(1+r)^n /(1+r)^n -1)
final_monthly_payment = round((annual_payment / 12), 2)
final_annual_payment = round(annual_payment, 2)
预期结果(当 MIR=4.375 和 MT=30 时):617.87
给出的结果(当MIR=4.375,MT=30时):623.82
最佳答案
使用 scipy financial functions 获取每月付款时可以看出差异.
给定的结果623.82是年付除以12得到月付。这是一个错误。你真的想计算月供而不是年供除以 12。
这是 scipy 的支付函数的结果。
>>> pmt(.04375, 30, 123750)
-7485.858293501044
>>> -7485.8582935010447/12
-623.8215244584204
>>> pmt(.04375/12, 360, 123750)
-617.8655064472862
您可以看到每月付款使用利率除以 12(得到每月利率)和期间 = 360,(30 年乘以 12 个月)。
所以,在你的计算中,
monthly_rate = MIR / 100
“应该”
monthly_rate = MIR / 100/12
loan_term_months = MT * 12
此处您正确计算了周期,但没有在公式中使用它们。
math1 = monthly_rate * ((1 + monthly_rate) ** loan_term_months)
math2 = ((1 + monthly_rate) ** loan_term_months) - 1
关于python - 如何进行摊销计算,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56782711/