40 $type = FinancialConstants::PAYMENT_END_OF_PERIOD
57 return $e->getMessage();
61 if ($period <= 0 || $period > $numberOfPeriods) {
75 return $interestAndPrincipal->interest();
91 public static function schedulePayment($interestRate, $period, $numberOfPeriods, $principleRemaining)
104 return $e->getMessage();
108 if ($period <= 0 || $period > $numberOfPeriods) {
116 $principlePayment = ($principleRemaining * 1.0) / ($numberOfPeriods * 1.0);
117 for (
$i = 0;
$i <= $period; ++
$i) {
118 $returnValue = $interestRate * $principleRemaining * -1;
119 $principleRemaining -= $principlePayment;
121 if (
$i == $numberOfPeriods) {
160 $type = FinancialConstants::PAYMENT_END_OF_PERIOD,
178 return $e->getMessage();
185 while (!$close && $iter < self::FINANCIAL_MAX_ITERATIONS) {
186 $nextdiff = self::rateNextGuess($rate, $numberOfPeriods, $payment, $presentValue, $futureValue,
$type);
187 if (!is_numeric($nextdiff)) {
190 $rate1 = $rate - $nextdiff;
191 $close = abs($rate1 - $rate) < self::FINANCIAL_PRECISION;
199 private static function rateNextGuess($rate, $numberOfPeriods, $payment, $presentValue, $futureValue,
$type)
204 $tt1 = ($rate + 1) ** $numberOfPeriods;
205 $tt2 = ($rate + 1) ** ($numberOfPeriods - 1);
206 $numerator = $futureValue + $tt1 * $presentValue + $payment * ($tt1 - 1) * ($rate *
$type + 1) / $rate;
207 $denominator = $numberOfPeriods * $tt2 * $presentValue - $payment * ($tt1 - 1)
208 * ($rate *
$type + 1) / ($rate * $rate) + $numberOfPeriods
209 * $payment * $tt2 * ($rate *
$type + 1) / $rate + $payment * ($tt1 - 1) *
$type / $rate;
210 if ($denominator == 0) {
214 return $numerator / $denominator;
static schedulePayment($interestRate, $period, $numberOfPeriods, $principleRemaining)
ISPMT.
const FINANCIAL_MAX_ITERATIONS
static validatePresentValue($presentValue)
const FINANCIAL_PRECISION
static validateRate($rate)
static validatePeriodType($type)
static validateFutureValue($futureValue)
static rate( $numberOfPeriods, $payment, $presentValue, $futureValue=0.0, $type=FinancialConstants::PAYMENT_END_OF_PERIOD, $guess=0.1)
RATE.
static payment( $interestRate, $period, $numberOfPeriods, $presentValue, $futureValue=0, $type=FinancialConstants::PAYMENT_END_OF_PERIOD)
IPMT.
static rateNextGuess($rate, $numberOfPeriods, $payment, $presentValue, $futureValue, $type)
static validateFloat($value)
static validateInt($value)
static flattenSingleValue($value='')
Convert an array to a single scalar value by extracting the first element.