简体   繁体   中英

Mortgage calculator: Formula to calculate total number of payments from monthly payment

If we manage to get the monthly payment with the fixed variables of interest rate and loan amount with the formula given, how to get total monthly payment in years if monthly payment is given?

//   r is the percentage rate per period divided by 100
//   n is numbers of years * 12 / number of payments
//   Principal amount = House value * ( 90 / 100 )
//   payment = ((Principal amount *  (1 + r/12) ^ n) * r) / (12 * ((1 + r/12)^n - 1)));

double loanAmount = (double)txtLoanAmount.CurrentValue * ((double)txtFinancing.CurrentValue / 100); // house value * % Financing
double interestRate = (double)udInterest.Value / 100;  // calculate interest from 100%
double termOfLoan = (double)(udTerm.Value * 12); // monthly term
double payment;

payment = (loanAmount) * (Math.Pow((1 + interestRate / 12), termOfLoan) * interestRate) / (12 * (Math.Pow((1 + interestRate / 12), termOfLoan) - 1));
                txtPayment.Text = payment.ToString("N2");

You want the equivalent of the nper function in Excel. The equation you are looking for is:

N = (-log(1- i * a / p)) / log (1 + i)

a = amount    
i = interest rate (divide by 12 if yearly rate)
p = payment amount

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM