抵押计算器数学错误 [英] Mortgage calculator math error

查看:52
本文介绍了抵押计算器数学错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此程序运行很好,但是它返回的每月付款完全没有用.如果本金为$ 400,000,利率为11%,付款期限为10年,则它将返回每月$ 44000.16的付款.我用谷歌搜索等式(算法?)中的抵押付款,然后放进去,不确定我要去哪里错了.

This program runs fine, but the monthly payment it returns is totally off. For a principal amount of $400,000, interest rate of 11%, and a 10-year payment period, it returns the monthly payment of $44000.16. I googled the equation (algorithm?) for mortgage payments and put it in, not sure where I'm going wrong.

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))

推荐答案

问题出在您使用的利率上.您要求的是年利率,而永远不要转换为月利率.

The problem is in your interest rate used. You request the annual interest rate and never convert to a monthly interest rate.

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

r-每月利率,用小数表示,而不是百分比.由于所引用的年度百分比不是复利,每月百分比就是每年百分比除以12;将每月百分比除以100给出r,以十进制表示的月费率.

r - the monthly interest rate, expressed as a decimal, not a percentage. Since the quoted yearly percentage rate is not a compounded rate, the monthly percentage rate is simply the yearly percentage rate divided by 12; dividing the monthly percentage rate by 100 gives r, the monthly rate expressed as a decimal.

我刚在计算机上尝试过,然后将利率除以12计算得出的每月$ 5510,这与其他抵押贷款计算器相符.

I just tried this on my computer and dividing the interest rate by 12 calculated $5510/month which agrees with other mortgage calculators.

这篇关于抵押计算器数学错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆