Exemplo n.º 1
0
 public function testMagicProperty()
 {
     $annuityValueType = new AnnuityValueTypes(AnnuityValueTypes::FUTURE_VALUE);
     // the enum's value should now be able to be channged by so much as assigning a magic property
     // lets change it from the future value to present value and see if it comes through
     $annuityValueType->magicProperty = AnnuityValueTypes::PRESENT_VALUE;
     $this->assertEquals(AnnuityValueTypes::PRESENT_VALUE, $annuityValueType->getValue());
     $this->assertEquals(AnnuityValueTypes::PRESENT_VALUE, $annuityValueType->magicProperty);
 }
Exemplo n.º 2
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;
 }