/** * @param DebtAmortizator $result */ private function processResult(DebtAmortizator $result) { $this->assertEquals("40000", $result->getDebtPrincipal()); $this->assertEquals("6", $result->getDebtNoOfCompoundingPeriods()); $this->assertEquals(TimeSpan::asDuration(intval(floor($result->getDebtPeriodLengthInYears())), intval(floor($result->getDebtPeriodLengthInYears()) == 0 ? $result->getDebtPeriodLengthInMonths() : $result->getDebtPeriodLengthInMonths() % $result->getDebtPeriodLengthInYears()), intval(floor($result->getDebtPeriodLengthInMonths()) == 0 ? $result->getDebtPeriodLengthInDays() : $result->getDebtPeriodLengthInDays() % $result->getDebtPeriodLengthInMonths())), $result->getDebtPeriodLength()); $this->assertEquals(MathFuncs::div($result->getDebtPeriodLengthInDays(), TimeUtils::getDaysFromYears(1)), $result->getDebtPeriodLengthInYears()); $this->assertEquals(MathFuncs::div($result->getDebtPeriodLengthInDays(), TimeUtils::getDaysFromMonths(1)), $result->getDebtPeriodLengthInMonths()); $this->assertEquals(MathFuncs::div($result->getDebtLengthInDays(), TimeUtils::getDaysFromYears(1)), $result->getDebtLengthInYears()); $this->assertEquals(MathFuncs::div($result->getDebtLengthInDays(), TimeUtils::getDaysFromMonths(1)), $result->getDebtLengthInMonths()); $dateStart = new DateTime(); $dateEnd = clone $dateStart; $dateEnd->add(new DateInterval("P" . (int) $result->getDebtLengthInDays() . "D")); $this->assertEquals($dateEnd, $result->getDebtEndDate($dateStart)); $this->assertEquals("0.12", $result->getDebtInterest()); $repayments = $result->getDebtRepayments(); $INDIVIDUAL_REPAYMENT = "9729.03"; $this->assertEquals("4929.03", round($repayments[1]->getPrincipalAmount(), 2)); $this->assertEquals("4800.00", round($repayments[1]->getInterestAmount(), 2)); $this->assertEquals($INDIVIDUAL_REPAYMENT, round($repayments[1]->getTotalAmount(), 2)); $this->assertEquals("5520.51", round($repayments[2]->getPrincipalAmount(), 2)); $this->assertEquals("4208.52", round($repayments[2]->getInterestAmount(), 2)); $this->assertEquals($INDIVIDUAL_REPAYMENT, round($repayments[2]->getTotalAmount(), 2)); $this->assertEquals("6182.97", round($repayments[3]->getPrincipalAmount(), 2)); $this->assertEquals("3546.06", round($repayments[3]->getInterestAmount(), 2)); $this->assertEquals($INDIVIDUAL_REPAYMENT, round($repayments[3]->getTotalAmount(), 2)); $this->assertEquals("6924.93", round($repayments[4]->getPrincipalAmount(), 2)); $this->assertEquals("2804.10", round($repayments[4]->getInterestAmount(), 2)); $this->assertEquals($INDIVIDUAL_REPAYMENT, round($repayments[4]->getTotalAmount(), 2)); $this->assertEquals("7755.92", round($repayments[5]->getPrincipalAmount(), 2)); $this->assertEquals("1973.11", round($repayments[5]->getInterestAmount(), 2)); $this->assertEquals($INDIVIDUAL_REPAYMENT, round($repayments[5]->getTotalAmount(), 2)); $this->assertEquals("8686.63", round($repayments[6]->getPrincipalAmount(), 2)); $this->assertEquals("1042.4", round($repayments[6]->getInterestAmount(), 2)); $this->assertEquals($INDIVIDUAL_REPAYMENT, round($repayments[6]->getTotalAmount(), 2)); }
/** * @param $annuityPeriodLength */ public function setAnnuityPeriodLength(TimeSpan $annuityPeriodLength) { if (Helpers::checkIfNotNegativeNumberOrThrowAnException((string) $annuityPeriodLength)) { if (Helpers::checkIfZero($this->annuityNoOfCompoundingPeriods)) { $annuityPeriodLength = TimeSpan::asDuration(0); } $this->setProperty("annuityPeriodLength", $annuityPeriodLength); } }
public function testTimeSpanAsDuration() { $timeSpan = TimeSpan::asDuration(0, 6); $this->assertNull($timeSpan->getStartDate()); $this->assertNull($timeSpan->getEndDate()); $this->assertEquals(0, $timeSpan->getYearsComponent()); $this->assertEquals(6, $timeSpan->getMonthsComponent()); $this->assertEquals(0, $timeSpan->getDaysComponent()); $timeSpan->setStartDate(new DateTime("2012-01-01")); $this->assertTimeSpan($timeSpan); }
/** * @param $annuitySinglePaymentAmount * @param $annuityInterest * @return AnnuityCalculator */ public function newPerpetuity($annuitySinglePaymentAmount, $annuityInterest) { return $this->manufactureInstance([$annuitySinglePaymentAmount, 0, TimeSpan::asDuration(0), $annuityInterest]); }
/** * @return \FinanCalc\Calculators\AnnuityCalculator */ private function newAnnuityCalculatorDirectYearly() { return new AnnuityCalculator(100000, 5, TimeSpan::asDuration(1), 0.15); }
public function testCheckInstanceException() { $this->setExpectedException('InvalidArgumentException', ErrorMessages::getIncompatibleTypesMessage("Non\\Existing\\Class", "FinanCalc\\Calculators\\AnnuityCalculator")); Helpers::checkIfInstanceOfAClassOrThrowAnException(new AnnuityCalculator(100000, 5, TimeSpan::asDuration(1), 0.15), "Non\\Existing\\Class"); }
/** * @return SimpleInterestCalculator * @throws Exception */ private function newSimpleInterestCalculatorFactory() { return \FinanCalc\FinanCalc::getInstance()->getFactory('SimpleInterestCalculatorFactory')->newSimpleInterest(100, 0.0375, TimeSpan::asDuration(1)); }
/** * @return mixed * @throws Exception */ private function newSimpleDiscountCalculatorFactory() { return \FinanCalc\FinanCalc::getInstance()->getFactory('SimpleDiscountCalculatorFactory')->newSimpleDiscount(100000, 0.13, TimeSpan::asDuration(0, 6)); }
/** * @param $debtPrincipal * @param $debtNoOfPeriods * @param $debtInterest * @return DebtAmortizator */ public function newDailyDebtAmortization($debtPrincipal, $debtNoOfPeriods, $debtInterest) { return $this->manufactureInstance([$debtPrincipal, $debtNoOfPeriods, TimeSpan::asDuration(0, 0, 1), $debtInterest]); }
protected function setUp() { $this->timeSpan = TimeSpan::asDuration(1, 6, 90); parent::setUp(); }
/** * @param DateTime $startDate * @param $years * @param $months * @param int $days * @return TimeSpan */ public static function asDurationWithStartDate(DateTime $startDate, $years, $months = 0, $days = 0) { $newThis = TimeSpan::asDuration($years, $months, $days); $newThis->setStartDate($startDate); return $newThis; }