You are here

public static function PHPExcel_Calculation_Financial::PRICE 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::PRICE()

File

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

Class

PHPExcel_Calculation_Financial
PHPExcel_Calculation_Financial

Code

public static function PRICE($settlement, $maturity, $rate, $yield, $redemption, $frequency, $basis = 0) {
  $settlement = PHPExcel_Calculation_Functions::flattenSingleValue($settlement);
  $maturity = PHPExcel_Calculation_Functions::flattenSingleValue($maturity);
  $rate = (double) PHPExcel_Calculation_Functions::flattenSingleValue($rate);
  $yield = (double) PHPExcel_Calculation_Functions::flattenSingleValue($yield);
  $redemption = (double) PHPExcel_Calculation_Functions::flattenSingleValue($redemption);
  $frequency = (int) PHPExcel_Calculation_Functions::flattenSingleValue($frequency);
  $basis = is_null($basis) ? 0 : (int) PHPExcel_Calculation_Functions::flattenSingleValue($basis);
  if (is_string($settlement = PHPExcel_Calculation_DateTime::_getDateValue($settlement))) {
    return PHPExcel_Calculation_Functions::VALUE();
  }
  if (is_string($maturity = PHPExcel_Calculation_DateTime::_getDateValue($maturity))) {
    return PHPExcel_Calculation_Functions::VALUE();
  }
  if ($settlement > $maturity || !self::_validFrequency($frequency) || ($basis < 0 || $basis > 4)) {
    return PHPExcel_Calculation_Functions::NaN();
  }
  $dsc = self::COUPDAYSNC($settlement, $maturity, $frequency, $basis);
  $e = self::COUPDAYS($settlement, $maturity, $frequency, $basis);
  $n = self::COUPNUM($settlement, $maturity, $frequency, $basis);
  $a = self::COUPDAYBS($settlement, $maturity, $frequency, $basis);
  $baseYF = 1.0 + $yield / $frequency;
  $rfp = 100 * ($rate / $frequency);
  $de = $dsc / $e;
  $result = $redemption / pow($baseYF, --$n + $de);
  for ($k = 0; $k <= $n; ++$k) {
    $result += $rfp / pow($baseYF, $k + $de);
  }
  $result -= $rfp * ($a / $e);
  return $result;
}