commit
message
[Financial.FVSCHEDULE] formula added and tested
author
Ben Vogt <[email protected]>
date
2017-10-04 01:19:15
stats
8 file(s) changed,
81 insertions(+),
5 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 253cf2a..71d4089 100644
3--- a/DOCS.md
4+++ b/DOCS.md
5@@ -592,6 +592,16 @@
6 @returns {number}
7 @constructor
8 ```
9+
10+### FVSCHEDULE
11+
12+```
13+ Calculates the accumulated value of the starting capital for a series of periodically varying interest rates.
14+@param principal - The starting capital.
15+@param rateSchedule - Range or Array that is a series of interest rates.
16+@returns {number}
17+@constructor
18+```
19 ## Info
20
21
22diff --git a/TODO.md b/TODO.md
23index f02b1e7..90fa502 100644
24--- a/TODO.md
25+++ b/TODO.md
26@@ -84,7 +84,6 @@ Many of these formulas can be written by allowing the Sheet and Parser to return
27 * COUPPCD
28 * DISC
29 * DURATION
30-* FVSCHEDULE
31 * INTRATE
32 * PRICE
33 * PRICEDISC
34diff --git a/dist/Formulas/AllFormulas.js b/dist/Formulas/AllFormulas.js
35index 174b51e..7d9fc23 100644
36--- a/dist/Formulas/AllFormulas.js
37+++ b/dist/Formulas/AllFormulas.js
38@@ -146,6 +146,7 @@ exports.IRR = Financial_1.IRR;
39 exports.IPMT = Financial_1.IPMT;
40 exports.FV = Financial_1.FV;
41 exports.PPMT = Financial_1.PPMT;
42+exports.FVSCHEDULE = Financial_1.FVSCHEDULE;
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 7857908..f859d6c 100644
48--- a/dist/Formulas/Financial.js
49+++ b/dist/Formulas/Financial.js
50@@ -705,3 +705,21 @@ var PPMT = function (rate, period, periods, present, future, type) {
51 return PMT(rate, periods, present, future, type) - IPMT(rate, period, periods, present, future, type);
52 };
53 exports.PPMT = PPMT;
54+/**
55+ * Calculates the accumulated value of the starting capital for a series of periodically varying interest rates.
56+ * @param principal - The starting capital.
57+ * @param rateSchedule - Range or Array that is a series of interest rates.
58+ * @returns {number}
59+ * @constructor
60+ */
61+var FVSCHEDULE = function (principal, rateSchedule) {
62+ ArgsChecker_1.ArgsChecker.checkLength(arguments, 2, "FVSCHEDULE");
63+ var future = TypeConverter_1.TypeConverter.firstValueAsNumber(principal);
64+ rateSchedule = Filter_1.Filter.flattenAndThrow(rateSchedule);
65+ for (var i = 0; i < rateSchedule.length; i++) {
66+ // Apply scheduled interest
67+ future *= 1 + rateSchedule[i];
68+ }
69+ return future;
70+};
71+exports.FVSCHEDULE = FVSCHEDULE;
72diff --git a/src/Formulas/AllFormulas.ts b/src/Formulas/AllFormulas.ts
73index aa374de..b1f1e4f 100644
74--- a/src/Formulas/AllFormulas.ts
75+++ b/src/Formulas/AllFormulas.ts
76@@ -150,7 +150,8 @@ import {
77 IRR,
78 IPMT,
79 FV,
80- PPMT
81+ PPMT,
82+ FVSCHEDULE
83 } from "./Financial";
84 import {
85 AVERAGE,
86@@ -517,5 +518,6 @@ export {
87 ROWS,
88 SERIESSUM,
89 ROMAN,
90- TEXT
91+ TEXT,
92+ FVSCHEDULE
93 }
94\ No newline at end of file
95diff --git a/src/Formulas/Financial.ts b/src/Formulas/Financial.ts
96index 04f613c..5a48078 100644
97--- a/src/Formulas/Financial.ts
98+++ b/src/Formulas/Financial.ts
99@@ -716,6 +716,27 @@ let PPMT = function (rate, period, periods, present, future?, type?) {
100 return PMT(rate, periods, present, future, type) - IPMT(rate, period, periods, present, future, type);
101 };
102
103+
104+/**
105+ * Calculates the accumulated value of the starting capital for a series of periodically varying interest rates.
106+ * @param principal - The starting capital.
107+ * @param rateSchedule - Range or Array that is a series of interest rates.
108+ * @returns {number}
109+ * @constructor
110+ */
111+let FVSCHEDULE = function (principal, rateSchedule) {
112+ ArgsChecker.checkLength(arguments, 2, "FVSCHEDULE");
113+ let future = TypeConverter.firstValueAsNumber(principal);
114+ rateSchedule = Filter.flattenAndThrow(rateSchedule);
115+
116+ for (let i = 0; i < rateSchedule.length; i++) {
117+ // Apply scheduled interest
118+ future *= 1 + rateSchedule[i];
119+ }
120+ return future;
121+};
122+
123+
124 export {
125 ACCRINT,
126 CUMPRINC,
127@@ -736,5 +757,6 @@ export {
128 IRR,
129 IPMT,
130 FV,
131- PPMT
132+ PPMT,
133+ FVSCHEDULE
134 }
135\ No newline at end of file
136diff --git a/tests/Formulas/FinancialTest.ts b/tests/Formulas/FinancialTest.ts
137index f15617c..a41a1af 100644
138--- a/tests/Formulas/FinancialTest.ts
139+++ b/tests/Formulas/FinancialTest.ts
140@@ -18,7 +18,8 @@ import {
141 IRR,
142 IPMT,
143 FV,
144- PPMT
145+ PPMT,
146+ FVSCHEDULE
147 } from "../../src/Formulas/Financial";
148 import {
149 DATE
150@@ -459,4 +460,22 @@ test("PPMT", function() {
151 catchAndAssertEquals(function() {
152 PPMT.apply(this, [0, 4, 0, 4000, 1, 1, 1]);
153 }, ERRORS.NA_ERROR);
154+});
155+
156+
157+test("FVSCHEDULE", function() {
158+ assertEquals(FVSCHEDULE(0.025, [1, 2, 3, 4]), 3.0000000000000004);
159+ assertEquals(FVSCHEDULE(0.025, [1, 2, 3, 4]), 3.0000000000000004);
160+ assertEquals(FVSCHEDULE(20000, [0.01, 0.04, 0.1, 0.01]), 23339.888000000003);
161+ assertEquals(FVSCHEDULE(0, [1, 2]), 0);
162+ assertEquals(FVSCHEDULE(-1, [1, 2]), -6);
163+ catchAndAssertEquals(function() {
164+ FVSCHEDULE.apply(this, [0.025, []]);
165+ }, ERRORS.REF_ERROR);
166+ catchAndAssertEquals(function() {
167+ FVSCHEDULE.apply(this, [0.025, [1, 2, 3, 4], 3]);
168+ }, ERRORS.NA_ERROR);
169+ catchAndAssertEquals(function() {
170+ FVSCHEDULE.apply(this, [0.025]);
171+ }, ERRORS.NA_ERROR);
172 });
173\ No newline at end of file
174diff --git a/tests/SheetFormulaTest.ts b/tests/SheetFormulaTest.ts
175index 1b7a760..d40a6ae 100644
176--- a/tests/SheetFormulaTest.ts
177+++ b/tests/SheetFormulaTest.ts
178@@ -1021,6 +1021,10 @@ test("Sheet TEXT", function(){
179 assertFormulaEquals('=TEXT(12.3, "###.##")', "12.3");
180 });
181
182+test("Sheet TEXT", function(){
183+ assertFormulaEquals('=FVSCHEDULE([0.025], [1, 2, 3, 4])', 3.0000000000000004);
184+});
185+
186 test("Sheet parsing error", function(){
187 assertFormulaEqualsError('= 10e', PARSE_ERROR);
188 assertFormulaEqualsError('= SUM(', PARSE_ERROR);