ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
InterestAndPrincipal.php
Go to the documentation of this file.
1<?php
2
4
6
8{
9 protected $interest;
10
11 protected $principal;
12
13 public function __construct(
14 float $rate = 0.0,
15 int $period = 0,
16 int $numberOfPeriods = 0,
17 float $presentValue = 0,
18 float $futureValue = 0,
19 int $type = FinancialConstants::PAYMENT_END_OF_PERIOD
20 ) {
21 $payment = Payments::annuity($rate, $numberOfPeriods, $presentValue, $futureValue, $type);
22 $capital = $presentValue;
23 $interest = 0.0;
24 $principal = 0.0;
25 for ($i = 1; $i <= $period; ++$i) {
26 $interest = ($type === FinancialConstants::PAYMENT_BEGINNING_OF_PERIOD && $i == 1) ? 0 : -$capital * $rate;
27 $principal = $payment - $interest;
28 $capital += $principal;
29 }
30
31 $this->interest = $interest;
32 $this->principal = $principal;
33 }
34
35 public function interest(): float
36 {
37 return $this->interest;
38 }
39
40 public function principal(): float
41 {
42 return $this->principal;
43 }
44}
An exception for terminatinating execution or to throw for unit testing.
__construct(float $rate=0.0, int $period=0, int $numberOfPeriods=0, float $presentValue=0, float $futureValue=0, int $type=FinancialConstants::PAYMENT_END_OF_PERIOD)
static annuity( $interestRate, $numberOfPeriods, $presentValue, $futureValue=0, $type=FinancialConstants::PAYMENT_END_OF_PERIOD)
PMT.
Definition: Payments.php:25
$i
Definition: disco.tpl.php:19
$type