ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
Single.php
Go to the documentation of this file.
1<?php
2
4
7
8class Single
9{
24 public static function futureValue($principal, $schedule)
25 {
26 $principal = Functions::flattenSingleValue($principal);
27 $schedule = Functions::flattenArray($schedule);
28
29 try {
30 $principal = CashFlowValidations::validateFloat($principal);
31
32 foreach ($schedule as $rate) {
34 $principal *= 1 + $rate;
35 }
36 } catch (Exception $e) {
37 return $e->getMessage();
38 }
39
40 return $principal;
41 }
42
54 public static function periods($rate, $presentValue, $futureValue)
55 {
56 $rate = Functions::flattenSingleValue($rate);
57 $presentValue = Functions::flattenSingleValue($presentValue);
58 $futureValue = Functions::flattenSingleValue($futureValue);
59
60 try {
62 $presentValue = CashFlowValidations::validatePresentValue($presentValue);
63 $futureValue = CashFlowValidations::validateFutureValue($futureValue);
64 } catch (Exception $e) {
65 return $e->getMessage();
66 }
67
68 // Validate parameters
69 if ($rate <= 0.0 || $presentValue <= 0.0 || $futureValue <= 0.0) {
70 return Functions::NAN();
71 }
72
73 return (log($futureValue) - log($presentValue)) / log(1 + $rate);
74 }
75
87 public static function interestRate($periods = 0.0, $presentValue = 0.0, $futureValue = 0.0)
88 {
89 $periods = Functions::flattenSingleValue($periods);
90 $presentValue = Functions::flattenSingleValue($presentValue);
91 $futureValue = Functions::flattenSingleValue($futureValue);
92
93 try {
94 $periods = CashFlowValidations::validateFloat($periods);
95 $presentValue = CashFlowValidations::validatePresentValue($presentValue);
96 $futureValue = CashFlowValidations::validateFutureValue($futureValue);
97 } catch (Exception $e) {
98 return $e->getMessage();
99 }
100
101 // Validate parameters
102 if ($periods <= 0.0 || $presentValue <= 0.0 || $futureValue < 0.0) {
103 return Functions::NAN();
104 }
105
106 return ($futureValue / $presentValue) ** (1 / $periods) - 1;
107 }
108}
An exception for terminatinating execution or to throw for unit testing.
static futureValue($principal, $schedule)
FVSCHEDULE.
Definition: Single.php:24
static interestRate($periods=0.0, $presentValue=0.0, $futureValue=0.0)
RRI.
Definition: Single.php:87
static periods($rate, $presentValue, $futureValue)
PDURATION.
Definition: Single.php:54
static flattenArray($array)
Convert a multi-dimensional array to a simple 1-dimensional array.
Definition: Functions.php:583
static flattenSingleValue($value='')
Convert an array to a single scalar value by extracting the first element.
Definition: Functions.php:649