You are here

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

* TBILLYIELD * * 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 price The Treasury bill's price per $100 face value. * @return float

File

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

Class

PHPExcel_Calculation_Financial
PHPExcel_Calculation_Financial

Code

public static function TBILLYIELD($settlement, $maturity, $price) {
  $settlement = PHPExcel_Calculation_Functions::flattenSingleValue($settlement);
  $maturity = PHPExcel_Calculation_Functions::flattenSingleValue($maturity);
  $price = PHPExcel_Calculation_Functions::flattenSingleValue($price);

  //	Validate
  if (is_numeric($price)) {
    if ($price <= 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();
    }
    return (100 - $price) / $price * (360 / $daysBetweenSettlementAndMaturity);
  }
  return PHPExcel_Calculation_Functions::VALUE();
}