commit
message
[NOMINAL] formula added and tested
author
Ben Vogt <[email protected]>
date
2017-06-29 00:59:27
stats
8 file(s) changed,
75 insertions(+),
6 deletions(-)
files
DOCS.md
TODO.md
dist/Formulas/AllFormulas.js
dist/Formulas/Financial.js
src/Formulas/AllFormulas.ts
src/Formulas/Financial.ts
tests/Formulas/FinancialTest.ts
tests/SheetFormulaTest.ts
1diff --git a/DOCS.md b/DOCS.md
2index 8783f4d..c58e161 100644
3--- a/DOCS.md
4+++ b/DOCS.md
5@@ -482,6 +482,16 @@
6 @returns {number}
7 @constructor
8 ```
9+
10+### NOMINAL
11+
12+```
13+ Calculates the yearly nominal interest rate, given the effective rate and the number of compounding periods per year.
14+@param rate - The effective interest rate.
15+@param periods - The number of periodic interest payments per year.
16+@returns {number}
17+@constructor
18+```
19 ## Info
20
21
22diff --git a/TODO.md b/TODO.md
23index bdd2605..73f0ca7 100644
24--- a/TODO.md
25+++ b/TODO.md
26@@ -143,7 +143,6 @@ For example 64 tbs to a qt.
27 * IPMT
28 * IRR
29 * MIRR
30-* NOMINAL
31 * PPMT - Similar to PMT, which is already written.
32 * PRICE
33 * PRICEDISC
34diff --git a/dist/Formulas/AllFormulas.js b/dist/Formulas/AllFormulas.js
35index dac8243..7932146 100644
36--- a/dist/Formulas/AllFormulas.js
37+++ b/dist/Formulas/AllFormulas.js
38@@ -114,6 +114,7 @@ exports.SYD = Financial_1.SYD;
39 exports.SLN = Financial_1.SLN;
40 exports.NPV = Financial_1.NPV;
41 exports.NPER = Financial_1.NPER;
42+exports.NOMINAL = Financial_1.NOMINAL;
43 var Statistical_1 = require("./Statistical");
44 exports.AVERAGE = Statistical_1.AVERAGE;
45 exports.AVERAGEA = Statistical_1.AVERAGEA;
46diff --git a/dist/Formulas/Financial.js b/dist/Formulas/Financial.js
47index 8ed7be2..8d3fffd 100644
48--- a/dist/Formulas/Financial.js
49+++ b/dist/Formulas/Financial.js
50@@ -526,3 +526,21 @@ var NPER = function (rate, payment, present, future, type) {
51 return logNumDen / div;
52 };
53 exports.NPER = NPER;
54+/**
55+ * Calculates the yearly nominal interest rate, given the effective rate and the number of compounding periods per year.
56+ * @param rate - The effective interest rate.
57+ * @param periods - The number of periodic interest payments per year.
58+ * @returns {number}
59+ * @constructor
60+ */
61+var NOMINAL = function (rate, periods) {
62+ ArgsChecker_1.ArgsChecker.checkLength(arguments, 2, "NOMINAL");
63+ rate = TypeConverter_1.TypeConverter.firstValueAsNumber(rate);
64+ periods = Math.round(TypeConverter_1.TypeConverter.firstValueAsNumber(periods));
65+ if (periods < 1) {
66+ throw new Errors_1.NumError("Function NOMINAL parameter 2 value is " + periods
67+ + ". It should be greater than or equal to 1.");
68+ }
69+ return (Math.pow(rate + 1, 1 / periods) - 1) * periods;
70+};
71+exports.NOMINAL = NOMINAL;
72diff --git a/src/Formulas/AllFormulas.ts b/src/Formulas/AllFormulas.ts
73index e8fac3f..c443a59 100644
74--- a/src/Formulas/AllFormulas.ts
75+++ b/src/Formulas/AllFormulas.ts
76@@ -117,7 +117,8 @@ import {
77 SYD,
78 SLN,
79 NPV,
80- NPER
81+ NPER,
82+ NOMINAL
83 } from "./Financial";
84 import {
85 AVERAGE,
86@@ -373,5 +374,6 @@ export {
87 SYD,
88 SLN,
89 NPV,
90- NPER
91+ NPER,
92+ NOMINAL
93 }
94\ No newline at end of file
95diff --git a/src/Formulas/Financial.ts b/src/Formulas/Financial.ts
96index 7f00899..5d343d7 100644
97--- a/src/Formulas/Financial.ts
98+++ b/src/Formulas/Financial.ts
99@@ -535,6 +535,23 @@ var NPER = function (rate, payment, present, future?, type?) {
100 return logNumDen / div;
101 };
102
103+/**
104+ * Calculates the yearly nominal interest rate, given the effective rate and the number of compounding periods per year.
105+ * @param rate - The effective interest rate.
106+ * @param periods - The number of periodic interest payments per year.
107+ * @returns {number}
108+ * @constructor
109+ */
110+var NOMINAL = function (rate, periods) {
111+ ArgsChecker.checkLength(arguments, 2, "NOMINAL");
112+ rate = TypeConverter.firstValueAsNumber(rate);
113+ periods = Math.round(TypeConverter.firstValueAsNumber(periods));
114+ if (periods < 1) {
115+ throw new NumError("Function NOMINAL parameter 2 value is " + periods
116+ + ". It should be greater than or equal to 1.");
117+ }
118+ return (Math.pow(rate + 1, 1 / periods) - 1) * periods;
119+};
120
121 export {
122 ACCRINT,
123@@ -550,5 +567,6 @@ export {
124 SYD,
125 SLN,
126 NPV,
127- NPER
128+ NPER,
129+ NOMINAL
130 }
131\ No newline at end of file
132diff --git a/tests/Formulas/FinancialTest.ts b/tests/Formulas/FinancialTest.ts
133index 0ea0987..862bfa6 100644
134--- a/tests/Formulas/FinancialTest.ts
135+++ b/tests/Formulas/FinancialTest.ts
136@@ -12,7 +12,8 @@ import {
137 SYD,
138 SLN,
139 NPV,
140- NPER
141+ NPER,
142+ NOMINAL
143 } from "../../src/Formulas/Financial";
144 import {
145 DATE
146@@ -343,3 +344,18 @@ test("NPER", function() {
147 NPER.apply(this, [0.04, -50, 1000, 2000, 0, 22]);
148 }, ERRORS.NA_ERROR);
149 });
150+
151+
152+test("NOMINAL", function() {
153+ assertEquals(NOMINAL(0.8, 12), 0.6024201620105654);
154+ assertEquals(NOMINAL(0.9, 2), 0.7568097504180442);
155+ catchAndAssertEquals(function() {
156+ NOMINAL(0.04, -2);
157+ }, ERRORS.NUM_ERROR);
158+ catchAndAssertEquals(function() {
159+ NOMINAL.apply(this, [0.04, -50, 44]);
160+ }, ERRORS.NA_ERROR);
161+ catchAndAssertEquals(function() {
162+ NOMINAL.apply(this, [0.04]);
163+ }, ERRORS.NA_ERROR);
164+});
165\ No newline at end of file
166diff --git a/tests/SheetFormulaTest.ts b/tests/SheetFormulaTest.ts
167index 3810e5a..5880ead 100644
168--- a/tests/SheetFormulaTest.ts
169+++ b/tests/SheetFormulaTest.ts
170@@ -735,6 +735,10 @@ test("Sheet NPER", function(){
171 assertFormulaEquals('=NPER(0.04, 100, 4000, 0, 0)', -24.362418941571317);
172 });
173
174+test("Sheet NOMINAL", function(){
175+ assertFormulaEquals('=NOMINAL(0.8, 12)', 0.6024201620105654);
176+});
177+
178 test("Sheet *", function(){
179 assertFormulaEquals('= 10 * 10', 100);
180 assertFormulaEquals('= 10 * 0', 0);