SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Addict
    Join Date
    Jul 2008
    Posts
    255
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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

  2. #2
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Here you go, this should work.

    PHP Code:
    <?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 
    calculateMonthlyPayments1008.912 );

    ?>
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  3. #3
    SitePoint Enthusiast reflash's Avatar
    Join Date
    Jul 2008
    Location
    Pocono Mtns.
    Posts
    70
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The formula you gave doesn't seem to work too well. On a loan of $60,000.00 at 9&#37; 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.
    Whatever is worth doing is worth over-doing...

  4. #4
    SitePoint Enthusiast reflash's Avatar
    Join Date
    Jul 2008
    Location
    Pocono Mtns.
    Posts
    70
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Took a while, but I got one that works:

    PHP Code:
    function calcPmt$amt $i$term ) {

    $int $i/1200;
    $int1 1+$int;
    $r1 pow($int1$term);
     
    $pmt $amt*($int*$r1)/($r1-1);

        return 
    $pmt;

    }

    echo 
    calcPmt600009360 ); 
    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.
    Whatever is worth doing is worth over-doing...

  5. #5
    SitePoint Enthusiast
    Join Date
    Dec 2008
    Posts
    39
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.

  6. #6
    SitePoint Member
    Join Date
    Jan 2010
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by reflash View Post
    Took a while, but I got one that works:

    PHP Code:
    function calcPmt$amt $i$term ) {

    $int $i/1200;
    $int1 1+$int;
    $r1 pow($int1$term);
     
    $pmt $amt*($int*$r1)/($r1-1);

        return 
    $pmt;

    }

    echo 
    calcPmt600009360 ); 
    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.

    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


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •