/** * @return string */ public function getBondFairValue() { // we need to get the coupon rate per payment period = c/payment frequency $couponRateForPeriod = MathFuncs::div($this->bondAnnualCouponRate, $this->bondPaymentFrequency); // similarly, we need to calculate the VIR per payment period = i/payment frequency $VIRForPeriod = MathFuncs::div($this->bondVIR, $this->bondPaymentFrequency); // we also save the bond's number of payments to an auxillary variable $bondNoOfPayments = $this->getBondNoOfPayments(); // next, we also need the present value of the unit annuity pertaining to the bond, in arrears $PVofUnitBondAnnuity = MathFuncs::div(MathFuncs::sub(1, Mathfuncs::pow(MathFuncs::div(1, MathFuncs::add(1, $VIRForPeriod)), $bondNoOfPayments)), $VIRForPeriod); // now we can use the formula to calculate the real value of the bond (i.e., the present value of its payments) // PV = F*[c*PVofUnitBondAnnuity+1/((1+i)^n)] $fairValue = MathFuncs::mul($this->bondFaceValue, MathFuncs::add(MathFuncs::mul($couponRateForPeriod, $PVofUnitBondAnnuity), MathFuncs::div(1, MathFuncs::pow(MathFuncs::add(1, $VIRForPeriod), $bondNoOfPayments)))); return $fairValue; }
public function testPow() { $this->assertEquals("53.157376", MathFuncs::pow(3.76, 3)); }
/** * @return string [Value of a single debt repayment instance as a string] */ public function getDebtSingleRepayment() { // single repayment 'K = PV/((1-v^n)/i)' return MathFuncs::div($this->debtPrincipal, MathFuncs::div(MathFuncs::sub(1, MathFuncs::pow($this->getDebtDiscountFactor(), $this->debtNoOfCompoundingPeriods)), $this->debtInterest)); }
/** * @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; }
/** * @return array */ public function getBondDiscountedCashFlows() { // discounted cash flows = nominal cash flows discounted by the means of yield $discountFactor = MathFuncs::div(1, MathFuncs::add(1, $this->getBondYieldPerPaymentPeriod())); $nominalCashFlows = $this->getBondNominalCashFlows(); $discountedCashFlows = array(); $i = 1; foreach ($nominalCashFlows as $nominalCashFlowEntry) { $discountedCashFlows[] = MathFuncs::mul($nominalCashFlowEntry, MathFuncs::pow($discountFactor, $i++)); } return $discountedCashFlows; }