You are here

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

* TBILLPRICE * * Returns the yield for a Treasury bill. * *

Parameters

mixed settlement The Treasury bill's settlement date.: * The Treasury bill's settlement date is the date after the issue date when the Treasury bill is traded to the buyer. * @param mixed maturity The Treasury bill's maturity date. * The maturity date is the date when the Treasury bill expires. * @param int discount The Treasury bill's discount rate. * @return float

1 call to PHPExcel_Calculation_Financial::TBILLPRICE()
PHPExcel_Calculation_Financial::TBILLEQ in vendor/phpoffice/phpexcel/Classes/PHPExcel/Calculation/Financial.php
* TBILLEQ * * Returns the bond-equivalent yield for a Treasury bill. * *

File

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

Class

PHPExcel_Calculation_Financial
PHPExcel_Calculation_Financial

Code

public static function TBILLPRICE($settlement, $maturity, $discount) {
  $settlement = PHPExcel_Calculation_Functions::flattenSingleValue($settlement);
  $maturity = PHPExcel_Calculation_Functions::flattenSingleValue($maturity);
  $discount = PHPExcel_Calculation_Functions::flattenSingleValue($discount);
  if (is_string($maturity = PHPExcel_Calculation_DateTime::_getDateValue($maturity))) {
    return PHPExcel_Calculation_Functions::VALUE();
  }

  //	Validate
  if (is_numeric($discount)) {
    if ($discount <= 0) {
      return PHPExcel_Calculation_Functions::NaN();
    }
    if (PHPExcel_Calculation_Functions::getCompatibilityMode() == PHPExcel_Calculation_Functions::COMPATIBILITY_OPENOFFICE) {
      ++$maturity;
      $daysBetweenSettlementAndMaturity = PHPExcel_Calculation_DateTime::YEARFRAC($settlement, $maturity) * 360;
      if (!is_numeric($daysBetweenSettlementAndMaturity)) {

        //	return date error
        return $daysBetweenSettlementAndMaturity;
      }
    }
    else {
      $daysBetweenSettlementAndMaturity = PHPExcel_Calculation_DateTime::_getDateValue($maturity) - PHPExcel_Calculation_DateTime::_getDateValue($settlement);
    }
    if ($daysBetweenSettlementAndMaturity > 360) {
      return PHPExcel_Calculation_Functions::NaN();
    }
    $price = 100 * (1 - $discount * $daysBetweenSettlementAndMaturity / 360);
    if ($price <= 0) {
      return PHPExcel_Calculation_Functions::NaN();
    }
    return $price;
  }
  return PHPExcel_Calculation_Functions::VALUE();
}