Plummer
Plummer

Reputation: 6688

understanding phpexcel RATE function

The Formula call for variables. I've look all over and can't find what these variables are and what values they're supposed to represent.

RATE($nper, $pmt, $pv, $fv = 0.0, $type = 0, $guess = 0.1)

Is anyone familiar with this function? Do you know what values the variables are meant to represent?

Upvotes: 0

Views: 1673

Answers (2)

chuckedw
chuckedw

Reputation: 751

I dont know if you need to implement this function, but in any case, I looked at how this algorithm was built and even though I was not able to access the excel source code (or the google worksheet) I found that this is not a simple calculation. About this math, more can be read here:

https://brownmath.com/bsci/loan.htm#Eq8

The function, in PHP, may be something like this:

function rate($nprest, $vlrparc, $vp, $guess = 0.25) {
    $maxit = 100;
    $precision = 14;
    $guess = round($guess,$precision);
    for ($i=0 ; $i<$maxit ; $i++) {
        $divdnd = $vlrparc - ( $vlrparc * (pow(1 + $guess , -$nprest)) ) - ($vp * $guess);
        $divisor = $nprest * $vlrparc * pow(1 + $guess , (-$nprest - 1)) - $vp;
        $newguess = $guess - ( $divdnd / $divisor );
        $newguess = round($newguess, $precision);
        if ($newguess == $guess) {
            return $newguess;
        } else {
            $guess = $newguess;
        }
    }
    return null;
}

Upvotes: 1

dnagirl
dnagirl

Reputation: 20446

From the Excel help file:

RATE(nper,pmt,pv,fv,type,guess)

For a complete description of the arguments nper, pmt, pv, fv, and type, see PV.

  • Nper - is the total number of payment periods in an annuity.
  • Pmt - is the payment made each period and cannot change over the life of the annuity. Typically, pmt includes principal and interest but no other fees or taxes. If pmt is omitted, you must include the fv argument.
  • Pv - is the present value — the total amount that a series of future payments is worth now.
  • Fv - is the future value, or a cash balance you want to attain after the last payment is made. If fv is omitted, it is assumed to be 0 (the future value of a loan, for example, is 0).
  • Type - is the number 0 or 1 and indicates when payments are due.

    Set type equal to the following if payments are due:

    • 0 or omitted - At the end of the period
    • 1 - At the beginning of the period
  • Guess - is your guess for what the rate will be.

    If you omit guess, it is assumed to be 10 percent.
    If RATE does not converge, try different values for guess. RATE usually converges if guess is between 0 and 1.

Remark

Make sure that you are consistent about the units you use for specifying guess and nper. If you make monthly payments on a four-year loan at 12 percent annual interest, use 12%/12 for guess and 4*12 for nper. If you make annual payments on the same loan, use 12% for guess and 4 for nper

Upvotes: 3

Related Questions