PluginProbe
TablePress – Tables in WordPress made easy / 3.4
TablePress – Tables in WordPress made easy v3.4
3.4 3.3.4 3.3.3 3.3.2 3.3.1 trunk 1.12 1.14 1.9.2 2.0.4 2.1.7 2.1.8 2.2 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.3 2.3.1 2.3.2 2.4 2.4.1 2.4.2 2.4.3 All 45 releases
tablepress / libraries / vendor / PhpSpreadsheet / Calculation / Financial / InterestRate.php

InterestRate.php in TablePress – Tables in WordPress made easy 3.4, at libraries/vendor/PhpSpreadsheet/Calculation/Financial/InterestRate.php

73 lines 2.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace TablePress\PhpOffice\PhpSpreadsheet\Calculation\Financial;
4
5 use TablePress\PhpOffice\PhpSpreadsheet\Calculation\Exception;
6 use TablePress\PhpOffice\PhpSpreadsheet\Calculation\Functions;
7 use TablePress\PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError;
8
9 class InterestRate
10 {
11 /**
12 * EFFECT.
13 *
14 * Returns the effective interest rate given the nominal rate and the number of
15 * compounding payments per year.
16 *
17 * Excel Function:
18 * EFFECT(nominal_rate,npery)
19 *
20 * @param mixed $nominalRate Nominal interest rate as a float
21 * @param mixed $periodsPerYear Integer number of compounding payments per year
22 * @return string|float
23 */
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 ExcelError::NAN();
38 }
39
40 return ((1 + $nominalRate / $periodsPerYear) ** $periodsPerYear) - 1;
41 }
42
43 /**
44 * NOMINAL.
45 *
46 * Returns the nominal interest rate given the effective rate and the number of compounding payments per year.
47 *
48 * @param mixed $effectiveRate Effective interest rate as a float
49 * @param mixed $periodsPerYear Integer number of compounding payments per year
50 *
51 * @return float|string Result, or a string containing an error
52 */
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 ExcelError::NAN();
67 }
68
69 // Calculate
70 return $periodsPerYear * (($effectiveRate + 1) ** (1 / $periodsPerYear) - 1);
71 }
72 }
73