/**
* PMT
* Calculates the payment for a loan based on constant payments
* and a constant interest rate.
*
* For a more complete description of the arguments in PMT, see the PV function.
*
* Rate: is the interest rate for the loan.
* Nper: is the total number of payments for the loan.
* Pv: is the present value, or the total amount that a series of future payments
* is worth now; also known as the principal.
* 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 (zero), that is,
* the future value of a loan is 0.
* Type: is the number 0 (zero) or 1 and indicates when payments are due.
* 0 or omitted, At the end of the period
* 1, At the beginning of the period
*
* If rate = 0:
* -(FV + PV)
* PMT = ------------
* nper
*
* Else
*
* nper
* FV + PV * (1 + rate)
* PMT = --------------------------------------------
* / nper \
* | 1 - (1 + rate) |
* (1 + rate * type) * | ------------------ |
* \ rate /
*
**/
function PMT($rate, $nper, $pv, $fv = 0.0, $type = 0)
{
$pmt = $this->_calculate_pmt ($rate, $nper, $pv, $fv, $type);
return (is_finite($pmt) ? $pmt: null);
}
/**
* IPMT
* Returns the interest payment for a given period for an investment based
* on periodic, constant payments and a constant interest rate.
*
* For a more complete description of the arguments in IPMT, see the PV function.
*
*/
function IPMT($rate, $per, $nper, $pv, $fv = 0.0, $type = 0)
{
if (($per < 1) || ($per >= ($nper + 1)))
return null;
else {
$pmt = $this->_calculate_pmt ($rate, $nper, $pv, $fv, $type);
$ipmt = $this->_calculate_interest_part ($pv, $pmt, $rate, $per - 1);
return (is_finite($ipmt) ? $ipmt: null);
}
}
/**
* PPMT
* Returns the payment on the principal for a given period for an
* investment based on periodic, constant payments and a constant
* interest rate.
*
**/
function PPMT($rate, $per, $nper, $pv, $fv = 0.0, $type = 0)
{
if (($per < 1) || ($per >= ($nper + 1)))
return null;
else {
$pmt = $this->_calculate_pmt ($rate, $nper, $pv, $fv, $type);
$ipmt = $this->_calculate_interest_part ($pv, $pmt, $rate, $per - 1);
return ((is_finite($pmt) && is_finite($ipmt)) ? $pmt - $ipmt: null);
}
}
/**
* NPER
* Returns the number of periods for an investment based on periodic,
* constant payments and a constant interest rate.
*
* 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.
* 0 or omitted, At the end of the period
* 1, At the beginning of the period
*
* If rate = 0:
* -(FV + PV)
* nper = -----------
* PMT
*
* Else
* / PMT * (1 + rate * type) - FV * rate \
* log | ------------------------------------- |
* \ PMT * (1 + rate * type) + PV * rate /
* nper = -----------------------------------------------
* log (1 + rate)
*
**/
function NPER($rate, $pmt, $pv, $fv = 0.0, $type = 0)
{
if (($rate == 0) && ($pmt != 0))
$nper = (-($fv + $pv) / $pmt);
elseif ($rate <= 0.0)
return null;
else {
$tmp = ($pmt * (1.0 + $rate * $type) - $fv * $rate) /
($pv * $rate + $pmt * (1.0 + $rate * $type));
if ($tmp <= 0.0)
return null;
$nper = (log10($tmp) / log10(1.0 + $rate));
}
return (is_finite($nper) ? $nper: null);
}
|