如何在JavaScript中计算抵押贷款

8

我有一个公式可以计算四个字段的月付款:

  1. 贷款金额
  2. 利率
  3. 贷款期限
  4. 月付款

公式:月付款 = 贷款金额 * ((1 + 年利率/100) ^ 贷款期限) / 贷款期限 / 12

现在,如果三个字段中有任何一个填写了,我想找到:

  1. 贷款金额
  2. 利率
  3. 贷款期限

我还有一个公式可以根据利率、贷款期限和月付款来计算贷款金额。

Formula: Loan amount = Monthly Payment/ ((1 + Interest rate per annum/100) ^ Term of loan) * Term of loan * 12

但它并不能计算完美的数字。

有人能为我提供这三个公式来计算贷款金额/利率/贷款期限(如果用JavaScript编写就更好了)。


1
但是那个公式的JavaScript代码在哪里?有什么问题吗? - elclanrs
你已经有了公式。将其转换为代码并不难,你是否需要解决更具体的问题? - icedwater
我想根据从四个字段填充的三个字段中的任何一个字段来查找。所以我想要四个公式。1)对于我已经有并且正在工作的月度付款 2)贷款金额公式 3)利率公式和4)贷款期限公式 - steve
3个回答

19

这是我的,

公式:

M = P [ i(1 + i)^n ] / [ (1 + i)^n – 1]

NerdWallet

希望这在某种程度上有所帮助。

var M; //monthly mortgage payment
var P = 400000; //principle / initial amount borrowed
var I = 3.5 / 100 / 12; //monthly interest rate
var N = 30 * 12; //number of payments months

//monthly mortgage payment
M = monthlyPayment(P, N, I);

console.log(M);

function monthlyPayment(p, n, i) {
  return p * i * (Math.pow(1 + i, n)) / (Math.pow(1 + i, n) - 1);
}


1
如果利息为0,则此方法无效。我知道这是一个罕见的情况,但完美的函数应该覆盖它。 - Andrei

1
var deno = (100 + Interest_rate_per_annum)/100;
var pdeno = Math.pow(deno, Term_of_Loan);
var loan_amount = (Monthly_payment * Term_of_Loan * 12) / pdeno;

1
这与@shay给出的答案完全相同,只是变量名称拼写出来,以便我更容易理解:
// totalPayments should be the total number of payments expected to be made for the life of the loan: years * 12
// interestRate: eg. 6.2% should be passed as 0.062
function getMortgagePayment(startingLoanAmount, totalPayments, interestRate)
{
    let interestRatePerMonth = interestRate / 12;
    return startingLoanAmount * interestRatePerMonth * (Math.pow(1 + interestRatePerMonth, totalPayments)) / (Math.pow(1 + interestRatePerMonth, totalPayments) - 1);
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接