formula del interes compuesto del mortgege calculator in javascript

Here is the formula for calculating the monthly payment of a mortgage with compound interest:

index.tsx
// P = (Pv * r) / (1 - (1 + r) ^ -n)
// P = monthly payment
// Pv = principal or the amount of the loan
// r = monthly interest rate
// n = number of monthly payments

function calculateMortgagePayment(Pv, i, n) {
  const r = i / 12; // the monthly interest rate
  const numerator = Pv * r;
  const denominator = 1 - Math.pow(1 + r, -n);
  return numerator / denominator;
}
374 chars
13 lines

In the calculateMortgagePayment function, we first calculate the monthly interest rate by dividing the annual interest rate (i) by 12. Then we use that rate along with the principal (Pv) and the number of monthly payments (n) to calculate the monthly payment of the mortgage using the compound interest formula. Finally, we return the monthly payment.

You can call this function with your desired values for principal, annual interest rate, and duration of the loan to calculate the monthly mortgage payment.

gistlibby LogSnag