You are here

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

* PRICEMAT * * Returns the price per $100 face value of a security that pays interest at maturity. * *

Parameters

mixed settlement The security's settlement date.: * The security's settlement date is the date after the issue date when the security is traded to the buyer. * @param mixed maturity The security's maturity date. * The maturity date is the date when the security expires. * @param mixed issue The security's issue date. * @param int rate The security's interest rate at date of issue. * @param int yield The security's annual yield. * @param int basis The type of day count to use. * 0 or omitted US (NASD) 30/360 * 1 Actual/actual * 2 Actual/360 * 3 Actual/365 * 4 European 30/360 * @return float

File

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

Class

PHPExcel_Calculation_Financial
PHPExcel_Calculation_Financial

Code

public static function PRICEMAT($settlement, $maturity, $issue, $rate, $yield, $basis = 0) {
  $settlement = PHPExcel_Calculation_Functions::flattenSingleValue($settlement);
  $maturity = PHPExcel_Calculation_Functions::flattenSingleValue($maturity);
  $issue = PHPExcel_Calculation_Functions::flattenSingleValue($issue);
  $rate = PHPExcel_Calculation_Functions::flattenSingleValue($rate);
  $yield = PHPExcel_Calculation_Functions::flattenSingleValue($yield);
  $basis = (int) PHPExcel_Calculation_Functions::flattenSingleValue($basis);

  //	Validate
  if (is_numeric($rate) && is_numeric($yield)) {
    if ($rate <= 0 || $yield <= 0) {
      return PHPExcel_Calculation_Functions::NaN();
    }
    $daysPerYear = self::_daysPerYear(PHPExcel_Calculation_DateTime::YEAR($settlement), $basis);
    if (!is_numeric($daysPerYear)) {
      return $daysPerYear;
    }
    $daysBetweenIssueAndSettlement = PHPExcel_Calculation_DateTime::YEARFRAC($issue, $settlement, $basis);
    if (!is_numeric($daysBetweenIssueAndSettlement)) {

      //	return date error
      return $daysBetweenIssueAndSettlement;
    }
    $daysBetweenIssueAndSettlement *= $daysPerYear;
    $daysBetweenIssueAndMaturity = PHPExcel_Calculation_DateTime::YEARFRAC($issue, $maturity, $basis);
    if (!is_numeric($daysBetweenIssueAndMaturity)) {

      //	return date error
      return $daysBetweenIssueAndMaturity;
    }
    $daysBetweenIssueAndMaturity *= $daysPerYear;
    $daysBetweenSettlementAndMaturity = PHPExcel_Calculation_DateTime::YEARFRAC($settlement, $maturity, $basis);
    if (!is_numeric($daysBetweenSettlementAndMaturity)) {

      //	return date error
      return $daysBetweenSettlementAndMaturity;
    }
    $daysBetweenSettlementAndMaturity *= $daysPerYear;
    return (100 + $daysBetweenIssueAndMaturity / $daysPerYear * $rate * 100) / (1 + $daysBetweenSettlementAndMaturity / $daysPerYear * $yield) - $daysBetweenIssueAndSettlement / $daysPerYear * $rate * 100;
  }
  return PHPExcel_Calculation_Functions::VALUE();
}