You are here

public static function PHPExcel_Calculation_Financial::ISPMT in Loft Data Grids 7.2

Same name and namespace in other branches
  1. 6.2 vendor/phpoffice/phpexcel/Classes/PHPExcel/Calculation/Financial.php \PHPExcel_Calculation_Financial::ISPMT()

* ISPMT * * Returns the interest payment for an investment based on an interest rate and a constant payment schedule. * * Excel Function: * =ISPMT(interest_rate, period, number_payments, PV) * * interest_rate is the interest rate for the investment * * period is the period to calculate the interest rate. It must be betweeen 1 and number_payments. * * number_payments is the number of payments for the annuity * * PV is the loan amount or present value of the payments

File

vendor/phpoffice/phpexcel/Classes/PHPExcel/Calculation/Financial.php, line 1394

Class

PHPExcel_Calculation_Financial
PHPExcel_Calculation_Financial

Code

public static function ISPMT() {

  // Return value
  $returnValue = 0;

  // Get the parameters
  $aArgs = PHPExcel_Calculation_Functions::flattenArray(func_get_args());
  $interestRate = array_shift($aArgs);
  $period = array_shift($aArgs);
  $numberPeriods = array_shift($aArgs);
  $principleRemaining = array_shift($aArgs);

  // Calculate
  $principlePayment = $principleRemaining * 1.0 / ($numberPeriods * 1.0);
  for ($i = 0; $i <= $period; ++$i) {
    $returnValue = $interestRate * $principleRemaining * -1;
    $principleRemaining -= $principlePayment;

    // principle needs to be 0 after the last payment, don't let floating point screw it up
    if ($i == $numberPeriods) {
      $returnValue = 0;
    }
  }
  return $returnValue;
}