# Loan repayment formula

Hi,
Does anybody have a formula to return the monthly repayments on a loan?

I am using this, but its not correct

this is where \$term is in months + \$interest = 9.8

\$payment = (\$interest*(\$loanamount/12))/(1-pow((\$interest/12)+1,-1*\$term));
\$payment = \$payment /12;

thanks

Here you go, this should work.

``````<?php

/**
* @desc    Calculates the monthly payments of a loan
*             based on the APR and Term.
*
* @param    Float    \$fLoanAmount    The loan amount.
* @param    Float    \$fAPR            The annual interest rate.
* @param    Integer    \$iTerm            The length of the loan in months.
* @return    Float    Monthly Payment.
*/
function calculateMonthlyPayments( \$fLoanAmount , \$fAPR, \$iTerm )
{
return (\$fLoanAmount/\$iTerm)+((\$fLoanAmount/\$iTerm)/100*(\$fAPR/12*\$iTerm));
}

echo calculateMonthlyPayments( 100, 8.9, 12 );

?>
``````

The formula you gave doesn’t seem to work too well. On a loan of \$60,000.00 at 9% for 30 years (360 payments), this formula gives a monthly payment of \$616.67, but the actual monthly payment on that loan would be \$482.77.

Took a while, but I got one that works:

``````function calcPmt( \$amt , \$i, \$term ) {

\$int = \$i/1200;
\$int1 = 1+\$int;
\$r1 = pow(\$int1, \$term);

\$pmt = \$amt*(\$int*\$r1)/(\$r1-1);

return \$pmt;

}

echo calcPmt( 60000, 9, 360 );

``````

The loan amount (\$amt) is in dollars, interest rate (\$i) is in whole numbers (9 for 9% not .09) and the term of the loan (\$term) is in months. You’ll have to do the formatting of the output. I checked the formula in as written here with the values that I provided and it gives the right payment: \$482.77.

The formula is a little bit more complicated than that. It would be:

Payment = P*(I/12) / (1-(1+I/12)^(-n))
Where P is the principal loan amount, I is the APR interest rate, and n is the number of periods.

The best way to figure out payments is to use a financial calculator or you can use Excel. The formula for use in Excel would be
=PMT(I,n,P,FV)

where P=principal, I=Interest per period, n=number of periods, FV=final value.

Good luck.

I’ve look for a good payment solution and this is simple and elegant, congratulations. I haven’t tried it out yet, but it looks right. Typically the payment would be a neg number where this would appear to provide a positive number, but most expect a positive number anyway so I don’t have to do a neg ot pos fix.

Thanx