Example #1
0
 /**
  * TBILLYIELD
  *
  * Returns the yield for a Treasury bill.
  *
  * @param    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
  */
 public static function TBILLYIELD($settlement, $maturity, $price)
 {
     $settlement = Functions::flattenSingleValue($settlement);
     $maturity = Functions::flattenSingleValue($maturity);
     $price = Functions::flattenSingleValue($price);
     //    Validate
     if (is_numeric($price)) {
         if ($price <= 0) {
             return Functions::NAN();
         }
         if (Functions::getCompatibilityMode() == Functions::COMPATIBILITY_OPENOFFICE) {
             ++$maturity;
             $daysBetweenSettlementAndMaturity = DateTime::YEARFRAC($settlement, $maturity) * 360;
             if (!is_numeric($daysBetweenSettlementAndMaturity)) {
                 //    return date error
                 return $daysBetweenSettlementAndMaturity;
             }
         } else {
             $daysBetweenSettlementAndMaturity = DateTime::getDateValue($maturity) - DateTime::getDateValue($settlement);
         }
         if ($daysBetweenSettlementAndMaturity > 360) {
             return Functions::NAN();
         }
         return (100 - $price) / $price * (360 / $daysBetweenSettlementAndMaturity);
     }
     return Functions::VALUE();
 }