抵押贷款计算器数学错误

con*_*nks 2 python math calculator

这个程序运行正常,但它返回的每月付款完全关闭.本金额为400,000美元,利率为11%,10年付款期间,每月支付44000.16美元.我搜索了抵押贷款支付的等式(算法?),然后把它放进去,不知道我哪里出错了.

import locale
locale.setlocale(locale.LC_ALL, '')

def mortgage(principal, interest, n):
    payment = principal*((interest*(1+interest)**n) / ((1+interest)**n-1))
    return payment

principal = float(input("What is the amount of the loan you are taking out? $"))
interest = float(input("What is the interest rate? (%) ")) / 100
n = float(input("How many years? ")) * 12
print
print "Your monthly payment would be", locale.currency(mortgage(principal, interest, n))
Run Code Online (Sandbox Code Playgroud)

Ron*_*Ron 7

问题在于您使用的利率.您要求年利率并且永远不会转换为每月利率.

来自https://en.wikipedia.org/wiki/Mortgage_calculator#Monthly_payment_formula:

r - 利率,以小数表示,而不是百分比.由于引用的年度百分比率不是复合率,因此月度百分比率仅为年度百分比率除以12; 将每月百分比率除以100给出r,以小数表示的月率.

我只是在我的电脑上尝试了这个并将利率除以12计算为每月5510美元,这与其他抵押贷款计算器一致.