You are here

public static function PHPExcel_Calculation_Financial::PMT in Loft Data Grids 6.2

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

* PMT * * Returns the constant payment (annuity) for a cash flow with a constant interest rate. * *

Parameters

float $rate Interest rate per period: * @param int $nper Number of periods * @param float $pv Present Value * @param float $fv Future Value * @param int $type Payment type: 0 = at the end of each period, 1 = at the beginning of each period * @return float

1 call to PHPExcel_Calculation_Financial::PMT()
PHPExcel_Calculation_Financial::_interestAndPrincipal in vendor/phpoffice/phpexcel/Classes/PHPExcel/Calculation/Financial.php

File

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

Class

PHPExcel_Calculation_Financial
PHPExcel_Calculation_Financial

Code

public static function PMT($rate = 0, $nper = 0, $pv = 0, $fv = 0, $type = 0) {
  $rate = PHPExcel_Calculation_Functions::flattenSingleValue($rate);
  $nper = PHPExcel_Calculation_Functions::flattenSingleValue($nper);
  $pv = PHPExcel_Calculation_Functions::flattenSingleValue($pv);
  $fv = PHPExcel_Calculation_Functions::flattenSingleValue($fv);
  $type = PHPExcel_Calculation_Functions::flattenSingleValue($type);

  // Validate parameters
  if ($type != 0 && $type != 1) {
    return PHPExcel_Calculation_Functions::NaN();
  }

  // Calculate
  if (!is_null($rate) && $rate != 0) {
    return (-$fv - $pv * pow(1 + $rate, $nper)) / (1 + $rate * $type) / ((pow(1 + $rate, $nper) - 1) / $rate);
  }
  else {
    return (-$pv - $fv) / $nper;
  }
}