Beispiel #1
0
 /**
  * @param integer $years
  * @param integer $months
  * @param integer $days
  * @return TimeSpan
  */
 public static function asDuration($years, $months = 0, $days = 0)
 {
     foreach (func_get_args() as $arg) {
         Helpers::checkIfNotNegativeNumberOrThrowAnException($arg);
     }
     $newThis = new TimeSpan();
     $newThis->newDateIntervalAbsolute($years, $months, $days);
     return $newThis;
 }
 /**
  * @param $stockAnnualDividendsGrowth
  */
 public function setStockAnnualDividendsGrowth($stockAnnualDividendsGrowth)
 {
     $dividendDiscountModelType = $this->dividendDiscountModelType->getValue();
     if ($dividendDiscountModelType == StockDDMTypes::ZERO_GROWTH && $stockAnnualDividendsGrowth !== null) {
         throw new InvalidArgumentException(Strings::getString('message_cannot_set_growth_value_on_zero_growth_type'));
     }
     if ($dividendDiscountModelType == StockDDMTypes::MULTIPLE_GROWTH) {
         if (Helpers::checkIfPositiveNumberOrThrowAnException($stockAnnualDividendsGrowth)) {
             Helpers::checkIfLeftOperandGreaterOrThrowAnException($this->stockVIR, $stockAnnualDividendsGrowth, Strings::getString('message_vir_must_be_higher_than_growth_value'));
         }
     }
     $this->setProperty("stockAnnualDividendsGrowth", $stockAnnualDividendsGrowth);
 }
Beispiel #3
0
 public function testRoundMoneyFOrDisplayNegative()
 {
     $unroundedNumber = 666.6666;
     $this->assertNotEquals(Helpers::roundMoneyForDisplay($unroundedNumber), "666.6666");
     $unroundedNumber = 444.4444;
     $this->assertNotEquals(Helpers::roundMoneyForDisplay($unroundedNumber), "444.4444");
 }
Beispiel #4
0
 /**
  * @param $checkedVariable
  * @return bool|null
  */
 public static function checkIfNegativeNumber($checkedVariable)
 {
     return Helpers::checkNumberRelativityToZero($checkedVariable, -1);
 }
 /**
  * @param $bondPaymentFrequency
  */
 public function setBondPaymentFrequency($bondPaymentFrequency)
 {
     if (Helpers::checkIfPositiveNumberOrThrowAnException($bondPaymentFrequency)) {
         $this->setProperty("bondPaymentFrequency", $bondPaymentFrequency);
     }
 }
Beispiel #6
0
 /**
  * @param AnnuityPaymentTypes $annuityPaymentType
  * @param AnnuityValueTypes $annuityValueType
  * @return null|string
  * @throws Exception
  */
 public function getAnnuityValue(AnnuityPaymentTypes $annuityPaymentType = null, AnnuityValueTypes $annuityValueType)
 {
     // if the number of the annuity's compounding periods
     // is set to zero, we're dealing with a perpetuity
     if (Helpers::checkIfZero($this->annuityNoOfCompoundingPeriods)) {
         // we cannot calculate FV of a perpetuity, we therefore return null
         // in case such a value is demanded
         if ($annuityValueType->getValue() == AnnuityValueTypes::FUTURE_VALUE) {
             return null;
         }
         // PV of a perpetuity = K/i
         return Helpers::roundMoneyForDisplay(MathFuncs::div($this->annuitySinglePaymentAmount, $this->annuityInterest));
     }
     // when the annuity is not a perpetuity, we first need to check that
     // the $annuityPaymentType is not null
     if (Helpers::checkIfNotNull($annuityPaymentType)) {
         // discount factor 'v = 1/(1+i)'
         $discountFactor = MathFuncs::div(1, MathFuncs::add(1, $this->annuityInterest));
         if ($annuityValueType->getValue() == AnnuityValueTypes::PRESENT_VALUE) {
             // PV numerator = 1-v^n
             $numerator = MathFuncs::sub(1, MathFuncs::pow($discountFactor, $this->annuityNoOfCompoundingPeriods));
         } elseif ($annuityValueType->getValue() == AnnuityValueTypes::FUTURE_VALUE) {
             // FV numerator = (1+i)^n-1
             $numerator = MathFuncs::sub(MathFuncs::pow(MathFuncs::add(1, $this->annuityInterest), $this->annuityNoOfCompoundingPeriods), 1);
         }
         if ($annuityPaymentType->getValue() == AnnuityPaymentTypes::IN_ADVANCE) {
             // in advance denom. = 1-v
             $denominator = MathFuncs::sub(1, $discountFactor);
         } elseif ($annuityPaymentType->getValue() == AnnuityPaymentTypes::IN_ARREARS) {
             // in arrears denom. = i
             $denominator = $this->annuityInterest;
         }
         if (isset($numerator) && isset($denominator)) {
             return MathFuncs::mul(MathFuncs::div($numerator, $denominator), $this->annuitySinglePaymentAmount);
         }
     }
     return null;
 }