ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
InterestRate.php
Go to the documentation of this file.
1 <?php
2 
4 
7 
9 {
24  public static function effective($nominalRate = 0, $periodsPerYear = 0)
25  {
26  $nominalRate = Functions::flattenSingleValue($nominalRate);
27  $periodsPerYear = Functions::flattenSingleValue($periodsPerYear);
28 
29  try {
30  $nominalRate = FinancialValidations::validateFloat($nominalRate);
31  $periodsPerYear = FinancialValidations::validateInt($periodsPerYear);
32  } catch (Exception $e) {
33  return $e->getMessage();
34  }
35 
36  if ($nominalRate <= 0 || $periodsPerYear < 1) {
37  return Functions::NAN();
38  }
39 
40  return ((1 + $nominalRate / $periodsPerYear) ** $periodsPerYear) - 1;
41  }
42 
53  public static function nominal($effectiveRate = 0, $periodsPerYear = 0)
54  {
55  $effectiveRate = Functions::flattenSingleValue($effectiveRate);
56  $periodsPerYear = Functions::flattenSingleValue($periodsPerYear);
57 
58  try {
59  $effectiveRate = FinancialValidations::validateFloat($effectiveRate);
60  $periodsPerYear = FinancialValidations::validateInt($periodsPerYear);
61  } catch (Exception $e) {
62  return $e->getMessage();
63  }
64 
65  if ($effectiveRate <= 0 || $periodsPerYear < 1) {
66  return Functions::NAN();
67  }
68 
69  // Calculate
70  return $periodsPerYear * (($effectiveRate + 1) ** (1 / $periodsPerYear) - 1);
71  }
72 }
static nominal($effectiveRate=0, $periodsPerYear=0)
NOMINAL.
static effective($nominalRate=0, $periodsPerYear=0)
EFFECT.
static flattenSingleValue($value='')
Convert an array to a single scalar value by extracting the first element.
Definition: Functions.php:649