@syncfusion/ej2-calculate 35.1.37

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (173) hide show
  1. package/.eslintrc.json +263 -0
  2. package/README.md +132 -0
  3. package/base.d.ts +4 -0
  4. package/base.js +4 -0
  5. package/common.d.ts +4 -0
  6. package/common.js +4 -0
  7. package/dist/ej2-calculate.umd.min.js +11 -0
  8. package/dist/ej2-calculate.umd.min.js.map +1 -0
  9. package/dist/es6/ej2-calculate.es2015.js +24801 -0
  10. package/dist/es6/ej2-calculate.es2015.js.map +1 -0
  11. package/dist/es6/ej2-calculate.es5.js +27229 -0
  12. package/dist/es6/ej2-calculate.es5.js.map +1 -0
  13. package/dist/global/ej2-calculate.min.js +11 -0
  14. package/dist/global/ej2-calculate.min.js.map +1 -0
  15. package/dist/global/index.d.ts +14 -0
  16. package/formulas.d.ts +4 -0
  17. package/formulas.js +4 -0
  18. package/index.d.ts +4 -0
  19. package/index.js +4 -0
  20. package/license +10 -0
  21. package/package.json +30 -0
  22. package/src/base/calculate-model.d.ts +4 -0
  23. package/src/base/calculate-model.js +0 -0
  24. package/src/base/calculate.d.ts +1105 -0
  25. package/src/base/calculate.js +4720 -0
  26. package/src/base/index.d.ts +8 -0
  27. package/src/base/index.js +7 -0
  28. package/src/base/parser.d.ts +208 -0
  29. package/src/base/parser.js +1512 -0
  30. package/src/common/address.d.ts +59 -0
  31. package/src/common/address.js +96 -0
  32. package/src/common/cell-ref.d.ts +32 -0
  33. package/src/common/cell-ref.js +112 -0
  34. package/src/common/common.d.ts +44 -0
  35. package/src/common/common.js +134 -0
  36. package/src/common/enum.d.ts +94 -0
  37. package/src/common/enum.js +97 -0
  38. package/src/common/index.d.ts +9 -0
  39. package/src/common/index.js +8 -0
  40. package/src/common/interface.d.ts +122 -0
  41. package/src/common/interface.js +0 -0
  42. package/src/common/l10n.d.ts +24 -0
  43. package/src/common/l10n.js +54 -0
  44. package/src/common/number-date.d.ts +26 -0
  45. package/src/common/number-date.js +38 -0
  46. package/src/common/sheet-info.d.ts +10 -0
  47. package/src/common/sheet-info.js +17 -0
  48. package/src/common/sort.d.ts +17 -0
  49. package/src/common/sort.js +44 -0
  50. package/src/formulas/array.d.ts +47 -0
  51. package/src/formulas/array.js +718 -0
  52. package/src/formulas/basic.d.ts +47 -0
  53. package/src/formulas/basic.js +181 -0
  54. package/src/formulas/complex-numbers.d.ts +207 -0
  55. package/src/formulas/complex-numbers.js +549 -0
  56. package/src/formulas/database.d.ts +152 -0
  57. package/src/formulas/database.js +579 -0
  58. package/src/formulas/date-time-extra.d.ts +97 -0
  59. package/src/formulas/date-time-extra.js +415 -0
  60. package/src/formulas/date-time-intl.d.ts +57 -0
  61. package/src/formulas/date-time-intl.js +309 -0
  62. package/src/formulas/date-time.d.ts +164 -0
  63. package/src/formulas/date-time.js +1021 -0
  64. package/src/formulas/engineering-base.d.ts +150 -0
  65. package/src/formulas/engineering-base.js +404 -0
  66. package/src/formulas/engineering-bessel.d.ts +65 -0
  67. package/src/formulas/engineering-bessel.js +167 -0
  68. package/src/formulas/engineering-convert.d.ts +35 -0
  69. package/src/formulas/engineering-convert.js +120 -0
  70. package/src/formulas/engineering-misc.d.ts +64 -0
  71. package/src/formulas/engineering-misc.js +168 -0
  72. package/src/formulas/financial-amortization-ecma.d.ts +87 -0
  73. package/src/formulas/financial-amortization-ecma.js +288 -0
  74. package/src/formulas/financial-annuity.d.ts +104 -0
  75. package/src/formulas/financial-annuity.js +419 -0
  76. package/src/formulas/financial-bond-helpers.d.ts +106 -0
  77. package/src/formulas/financial-bond-helpers.js +190 -0
  78. package/src/formulas/financial-cashflow.d.ts +47 -0
  79. package/src/formulas/financial-cashflow.js +203 -0
  80. package/src/formulas/financial-coupons.d.ts +227 -0
  81. package/src/formulas/financial-coupons.js +810 -0
  82. package/src/formulas/financial-depreciation.d.ts +64 -0
  83. package/src/formulas/financial-depreciation.js +247 -0
  84. package/src/formulas/financial-rates.d.ts +54 -0
  85. package/src/formulas/financial-rates.js +140 -0
  86. package/src/formulas/financial-securities.d.ts +126 -0
  87. package/src/formulas/financial-securities.js +488 -0
  88. package/src/formulas/formula-math-helpers.d.ts +212 -0
  89. package/src/formulas/formula-math-helpers.js +599 -0
  90. package/src/formulas/formula-module-base.d.ts +54 -0
  91. package/src/formulas/formula-module-base.js +125 -0
  92. package/src/formulas/formula-owner.d.ts +17 -0
  93. package/src/formulas/formula-owner.js +0 -0
  94. package/src/formulas/index.d.ts +68 -0
  95. package/src/formulas/index.js +67 -0
  96. package/src/formulas/information-advanced.d.ts +44 -0
  97. package/src/formulas/information-advanced.js +157 -0
  98. package/src/formulas/information-ecma.d.ts +33 -0
  99. package/src/formulas/information-ecma.js +88 -0
  100. package/src/formulas/information-extra.d.ts +146 -0
  101. package/src/formulas/information-extra.js +351 -0
  102. package/src/formulas/information.d.ts +34 -0
  103. package/src/formulas/information.js +78 -0
  104. package/src/formulas/logical-extra.d.ts +75 -0
  105. package/src/formulas/logical-extra.js +217 -0
  106. package/src/formulas/logical.d.ts +83 -0
  107. package/src/formulas/logical.js +296 -0
  108. package/src/formulas/lookup-array.d.ts +98 -0
  109. package/src/formulas/lookup-array.js +364 -0
  110. package/src/formulas/lookup-ref-extra.d.ts +64 -0
  111. package/src/formulas/lookup-ref-extra.js +180 -0
  112. package/src/formulas/lookup-ref.d.ts +84 -0
  113. package/src/formulas/lookup-ref.js +263 -0
  114. package/src/formulas/lookup.d.ts +114 -0
  115. package/src/formulas/lookup.js +881 -0
  116. package/src/formulas/math-aggregate.d.ts +74 -0
  117. package/src/formulas/math-aggregate.js +376 -0
  118. package/src/formulas/math-ceiling-ecma.d.ts +42 -0
  119. package/src/formulas/math-ceiling-ecma.js +123 -0
  120. package/src/formulas/math-combinatorics.d.ts +75 -0
  121. package/src/formulas/math-combinatorics.js +290 -0
  122. package/src/formulas/math-misc.d.ts +164 -0
  123. package/src/formulas/math-misc.js +889 -0
  124. package/src/formulas/math-number.d.ts +76 -0
  125. package/src/formulas/math-number.js +261 -0
  126. package/src/formulas/math-rounding.d.ts +115 -0
  127. package/src/formulas/math-rounding.js +728 -0
  128. package/src/formulas/math-trig-hyperbolic.d.ts +55 -0
  129. package/src/formulas/math-trig-hyperbolic.js +113 -0
  130. package/src/formulas/math-trig.d.ts +165 -0
  131. package/src/formulas/math-trig.js +334 -0
  132. package/src/formulas/matrix-base.d.ts +13 -0
  133. package/src/formulas/matrix-base.js +169 -0
  134. package/src/formulas/matrix.d.ts +64 -0
  135. package/src/formulas/matrix.js +161 -0
  136. package/src/formulas/regression-ecma.d.ts +66 -0
  137. package/src/formulas/regression-ecma.js +234 -0
  138. package/src/formulas/statistical-advanced.d.ts +125 -0
  139. package/src/formulas/statistical-advanced.js +756 -0
  140. package/src/formulas/statistical-correlation.d.ts +75 -0
  141. package/src/formulas/statistical-correlation.js +198 -0
  142. package/src/formulas/statistical-dispersion.d.ts +108 -0
  143. package/src/formulas/statistical-dispersion.js +337 -0
  144. package/src/formulas/statistical-distribution-extended.d.ts +176 -0
  145. package/src/formulas/statistical-distribution-extended.js +668 -0
  146. package/src/formulas/statistical-distribution.d.ts +104 -0
  147. package/src/formulas/statistical-distribution.js +368 -0
  148. package/src/formulas/statistical-ecma.d.ts +95 -0
  149. package/src/formulas/statistical-ecma.js +392 -0
  150. package/src/formulas/statistical-extended.d.ts +136 -0
  151. package/src/formulas/statistical-extended.js +340 -0
  152. package/src/formulas/statistical-ifs.d.ts +46 -0
  153. package/src/formulas/statistical-ifs.js +180 -0
  154. package/src/formulas/statistical-moments.d.ts +84 -0
  155. package/src/formulas/statistical-moments.js +269 -0
  156. package/src/formulas/statistical-percentile.d.ts +56 -0
  157. package/src/formulas/statistical-percentile.js +195 -0
  158. package/src/formulas/statistical-sample-base.d.ts +14 -0
  159. package/src/formulas/statistical-sample-base.js +124 -0
  160. package/src/formulas/statistical.d.ts +135 -0
  161. package/src/formulas/statistical.js +542 -0
  162. package/src/formulas/text-advanced.d.ts +64 -0
  163. package/src/formulas/text-advanced.js +222 -0
  164. package/src/formulas/text-ecma.d.ts +54 -0
  165. package/src/formulas/text-ecma.js +106 -0
  166. package/src/formulas/text-extra.d.ts +216 -0
  167. package/src/formulas/text-extra.js +657 -0
  168. package/src/formulas/text.d.ts +125 -0
  169. package/src/formulas/text.js +628 -0
  170. package/src/global.js +1 -0
  171. package/src/index.d.ts +14 -0
  172. package/src/index.js +14 -0
  173. package/tslint.json +111 -0
@@ -0,0 +1,419 @@
1
+ var __extends = (this && this.__extends) || (function () {
2
+ var extendStatics = function (d, b) {
3
+ extendStatics = Object.setPrototypeOf ||
4
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
5
+ function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
6
+ return extendStatics(d, b);
7
+ };
8
+ return function (d, b) {
9
+ extendStatics(d, b);
10
+ function __() { this.constructor = d; }
11
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
12
+ };
13
+ })();
14
+ import { FormulasErrorsStrings, CommonErrors } from '../common/index';
15
+ import { isNullOrUndefined } from '@syncfusion/ej2-base';
16
+ import { FormulaModuleBase } from './formula-module-base';
17
+ /**
18
+ * Annuity and payment functions: present/future value, payment amount, periods, and interest rate.
19
+ *
20
+ * Registered functions: FV, PV, PMT, NPER, IPMT, PPMT, NPV, RATE.
21
+ *
22
+ * @hidden
23
+ */
24
+ var FinancialAnnuityFormulas = /** @class */ (function (_super) {
25
+ __extends(FinancialAnnuityFormulas, _super);
26
+ /**
27
+ * @hidden
28
+ * @param {FormulaOwner} owner - Formula registration owner ({@link BasicFormulas}).
29
+ */
30
+ function FinancialAnnuityFormulas(owner) {
31
+ var _this = _super.call(this, owner) || this;
32
+ /** Formula definitions registered with {@link BasicFormulas}. */
33
+ _this.formulas = [
34
+ { formulaName: 'FV', category: 'Financial', description: 'Returns the future value of an investment.' },
35
+ { formulaName: 'PV', category: 'Financial', description: 'Returns the present value of an investment.' },
36
+ { formulaName: 'PMT', category: 'Financial', description: 'Returns the periodic payment for an annuity.' },
37
+ { formulaName: 'NPER', category: 'Financial', description: 'Returns the number of periods for an investment.' },
38
+ { formulaName: 'IPMT', category: 'Financial', description: 'Returns the interest payment for an investment for a given period.' },
39
+ { formulaName: 'PPMT', category: 'Financial', description: 'Returns the payment on the principal for an investment for a given period.' },
40
+ { formulaName: 'NPV', category: 'Financial', description: 'Returns the net present value of an investment based on periodic cash flows.' },
41
+ { formulaName: 'RATE', category: 'Financial', description: 'Returns the interest rate per period of an annuity.' }
42
+ ];
43
+ return _this;
44
+ }
45
+ FinancialAnnuityFormulas.prototype.resolveOptional = function (args, index, defaultValue) {
46
+ if (args.length <= index || args[index] === '') {
47
+ return defaultValue;
48
+ }
49
+ return this.resolveNumberArg(args[index]);
50
+ };
51
+ /**
52
+ * Returns the future value of an investment.
53
+ *
54
+ * Excel: `FV(...)`.
55
+ *
56
+ * @param {string[]} args - Formula argument tokens from the Calculate engine.
57
+ * @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
58
+ *
59
+ * @example
60
+ * ```ts
61
+ * engine.computeFormula('=FV(1)');
62
+ * ```
63
+ */
64
+ FinancialAnnuityFormulas.prototype.ComputeFV = function () {
65
+ var args = [];
66
+ for (var _i = 0; _i < arguments.length; _i++) {
67
+ args[_i] = arguments[_i];
68
+ }
69
+ if (isNullOrUndefined(args) || args.length < 3 || args.length > 5) {
70
+ return this.parent.formulaErrorStrings[FormulasErrorsStrings.WrongNumberArguments];
71
+ }
72
+ var rate = this.resolveNumberArg(args[0]);
73
+ var nper = this.resolveNumberArg(args[1]);
74
+ var pmt = this.resolveNumberArg(args[2]);
75
+ if (typeof rate === 'string') {
76
+ return rate;
77
+ }
78
+ if (typeof nper === 'string') {
79
+ return nper;
80
+ }
81
+ if (typeof pmt === 'string') {
82
+ return pmt;
83
+ }
84
+ var pv = this.resolveOptional(args, 3, 0);
85
+ var type = this.resolveOptional(args, 4, 0);
86
+ if (typeof pv === 'string') {
87
+ return pv;
88
+ }
89
+ if (typeof type === 'string') {
90
+ return type;
91
+ }
92
+ if (rate === 0) {
93
+ return (-pv - pmt * nper).toString();
94
+ }
95
+ var pow = Math.pow(1 + rate, nper);
96
+ var when = type ? 1 : 0;
97
+ var fv = -pv * pow - pmt * (1 + rate * when) * (pow - 1) / rate;
98
+ return fv.toString();
99
+ };
100
+ /**
101
+ * Returns the present value of an investment.
102
+ *
103
+ * Excel: `PV(...)`.
104
+ *
105
+ * @hidden
106
+ * @param {string[]} args - Formula argument tokens from the Calculate engine.
107
+ * @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
108
+ */
109
+ FinancialAnnuityFormulas.prototype.ComputePV = function () {
110
+ var args = [];
111
+ for (var _i = 0; _i < arguments.length; _i++) {
112
+ args[_i] = arguments[_i];
113
+ }
114
+ if (isNullOrUndefined(args) || args.length < 3 || args.length > 5) {
115
+ return this.parent.formulaErrorStrings[FormulasErrorsStrings.WrongNumberArguments];
116
+ }
117
+ var rate = this.resolveNumberArg(args[0]);
118
+ var nper = this.resolveNumberArg(args[1]);
119
+ var pmt = this.resolveNumberArg(args[2]);
120
+ if (typeof rate === 'string') {
121
+ return rate;
122
+ }
123
+ if (typeof nper === 'string') {
124
+ return nper;
125
+ }
126
+ if (typeof pmt === 'string') {
127
+ return pmt;
128
+ }
129
+ var fv = this.resolveOptional(args, 3, 0);
130
+ var type = this.resolveOptional(args, 4, 0);
131
+ if (typeof fv === 'string') {
132
+ return fv;
133
+ }
134
+ if (typeof type === 'string') {
135
+ return type;
136
+ }
137
+ if (rate === 0) {
138
+ return (-fv - pmt * nper).toString();
139
+ }
140
+ var pow = Math.pow(1 + rate, nper);
141
+ var when = type ? 1 : 0;
142
+ var pv = (-fv - pmt * (1 + rate * when) * (pow - 1) / rate) / pow;
143
+ return pv.toString();
144
+ };
145
+ /**
146
+ * Returns the periodic payment for an annuity.
147
+ *
148
+ * Excel: `PMT(...)`.
149
+ *
150
+ * @hidden
151
+ * @param {string[]} args - Formula argument tokens from the Calculate engine.
152
+ * @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
153
+ */
154
+ FinancialAnnuityFormulas.prototype.ComputePMT = function () {
155
+ var args = [];
156
+ for (var _i = 0; _i < arguments.length; _i++) {
157
+ args[_i] = arguments[_i];
158
+ }
159
+ if (isNullOrUndefined(args) || args.length < 3 || args.length > 5) {
160
+ return this.parent.formulaErrorStrings[FormulasErrorsStrings.WrongNumberArguments];
161
+ }
162
+ var rate = this.resolveNumberArg(args[0]);
163
+ var nper = this.resolveNumberArg(args[1]);
164
+ var pv = this.resolveNumberArg(args[2]);
165
+ if (typeof rate === 'string') {
166
+ return rate;
167
+ }
168
+ if (typeof nper === 'string') {
169
+ return nper;
170
+ }
171
+ if (typeof pv === 'string') {
172
+ return pv;
173
+ }
174
+ var fv = this.resolveOptional(args, 3, 0);
175
+ var type = this.resolveOptional(args, 4, 0);
176
+ if (typeof fv === 'string') {
177
+ return fv;
178
+ }
179
+ if (typeof type === 'string') {
180
+ return type;
181
+ }
182
+ if (rate === 0) {
183
+ return (-pv - fv) / nper;
184
+ }
185
+ var pow = Math.pow(1 + rate, nper);
186
+ var when = type ? 1 : 0;
187
+ var pmt = (rate * (fv + pv * pow)) / ((1 + rate * when) * (1 - pow));
188
+ return pmt.toString();
189
+ };
190
+ /**
191
+ * Returns the number of periods for an investment.
192
+ *
193
+ * Excel: `NPER(...)`.
194
+ *
195
+ * @hidden
196
+ * @param {string[]} args - Formula argument tokens from the Calculate engine.
197
+ * @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
198
+ */
199
+ FinancialAnnuityFormulas.prototype.ComputeNPER = function () {
200
+ var args = [];
201
+ for (var _i = 0; _i < arguments.length; _i++) {
202
+ args[_i] = arguments[_i];
203
+ }
204
+ var errCollection = this.parent.getErrorStrings();
205
+ if (isNullOrUndefined(args) || args.length < 3 || args.length > 5) {
206
+ return this.parent.formulaErrorStrings[FormulasErrorsStrings.WrongNumberArguments];
207
+ }
208
+ var rate = this.resolveNumberArg(args[0]);
209
+ var pmt = this.resolveNumberArg(args[1]);
210
+ var pv = this.resolveNumberArg(args[2]);
211
+ if (typeof rate === 'string') {
212
+ return rate;
213
+ }
214
+ if (typeof pmt === 'string') {
215
+ return pmt;
216
+ }
217
+ if (typeof pv === 'string') {
218
+ return pv;
219
+ }
220
+ var fv = this.resolveOptional(args, 3, 0);
221
+ var type = this.resolveOptional(args, 4, 0);
222
+ if (typeof fv === 'string') {
223
+ return fv;
224
+ }
225
+ if (typeof type === 'string') {
226
+ return type;
227
+ }
228
+ if (rate === 0) {
229
+ if (pmt === 0) {
230
+ return errCollection[CommonErrors.Num];
231
+ }
232
+ return (-(pv + fv) / pmt).toString();
233
+ }
234
+ var when = type ? 1 : 0;
235
+ var num = pmt * (1 + rate * when) / rate - fv;
236
+ var den = pv + pmt * (1 + rate * when) / rate;
237
+ if (den === 0 || num / den <= 0) {
238
+ return errCollection[CommonErrors.Num];
239
+ }
240
+ return (Math.log(num / den) / Math.log(1 + rate)).toString();
241
+ };
242
+ /**
243
+ * Returns the interest payment for an investment for a given period.
244
+ *
245
+ * Excel: `IPMT(...)`.
246
+ *
247
+ * @hidden
248
+ * @param {string[]} args - Formula argument tokens from the Calculate engine.
249
+ * @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
250
+ */
251
+ FinancialAnnuityFormulas.prototype.ComputeIPMT = function () {
252
+ var args = [];
253
+ for (var _i = 0; _i < arguments.length; _i++) {
254
+ args[_i] = arguments[_i];
255
+ }
256
+ if (isNullOrUndefined(args) || args.length < 4 || args.length > 6) {
257
+ return this.parent.formulaErrorStrings[FormulasErrorsStrings.WrongNumberArguments];
258
+ }
259
+ var rate = this.resolveNumberArg(args[0]);
260
+ var per = this.resolveNumberArg(args[1]);
261
+ var nper = this.resolveNumberArg(args[2]);
262
+ var pv = this.resolveNumberArg(args[3]);
263
+ if (typeof rate === 'string') {
264
+ return rate;
265
+ }
266
+ if (typeof per === 'string') {
267
+ return per;
268
+ }
269
+ if (typeof nper === 'string') {
270
+ return nper;
271
+ }
272
+ if (typeof pv === 'string') {
273
+ return pv;
274
+ }
275
+ var fv = this.resolveOptional(args, 4, 0);
276
+ var type = this.resolveOptional(args, 5, 0);
277
+ if (typeof fv === 'string') {
278
+ return fv;
279
+ }
280
+ if (typeof type === 'string') {
281
+ return type;
282
+ }
283
+ var pmtResult = this.ComputePMT(rate.toString(), nper.toString(), pv.toString(), fv.toString(), type.toString());
284
+ if (typeof pmtResult === 'string' && this.parent.getErrorStrings().indexOf(pmtResult) > -1) {
285
+ return pmtResult;
286
+ }
287
+ var pmt = parseFloat(pmtResult.toString());
288
+ var balance = pv;
289
+ for (var i = 1; i < per; i++) {
290
+ balance = balance * (1 + rate) + pmt;
291
+ }
292
+ var ipmt = balance * rate;
293
+ return ipmt.toString();
294
+ };
295
+ /**
296
+ * Returns the payment on the principal for an investment for a given period.
297
+ *
298
+ * Excel: `PPMT(...)`.
299
+ *
300
+ * @hidden
301
+ * @param {string[]} args - Formula argument tokens from the Calculate engine.
302
+ * @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
303
+ */
304
+ FinancialAnnuityFormulas.prototype.ComputePPMT = function () {
305
+ var args = [];
306
+ for (var _i = 0; _i < arguments.length; _i++) {
307
+ args[_i] = arguments[_i];
308
+ }
309
+ if (isNullOrUndefined(args) || args.length < 4 || args.length > 6) {
310
+ return this.parent.formulaErrorStrings[FormulasErrorsStrings.WrongNumberArguments];
311
+ }
312
+ var ipmt = this.ComputeIPMT.apply(this, args);
313
+ if (typeof ipmt === 'string' && this.parent.getErrorStrings().indexOf(ipmt) > -1) {
314
+ return ipmt;
315
+ }
316
+ var rate = this.resolveNumberArg(args[0]);
317
+ var nper = this.resolveNumberArg(args[2]);
318
+ var pv = this.resolveNumberArg(args[3]);
319
+ var fv = this.resolveOptional(args, 4, 0);
320
+ var type = this.resolveOptional(args, 5, 0);
321
+ var pmtResult = this.ComputePMT(rate.toString(), nper.toString(), pv.toString(), (typeof fv === 'number' ? fv : 0).toString(), (typeof type === 'number' ? type : 0).toString());
322
+ var pmt = parseFloat(pmtResult.toString());
323
+ return (pmt - parseFloat(ipmt.toString())).toString();
324
+ };
325
+ /**
326
+ * Returns the net present value of an investment based on periodic cash flows.
327
+ *
328
+ * Excel: `NPV(...)`.
329
+ *
330
+ * @hidden
331
+ * @param {string[]} args - Formula argument tokens from the Calculate engine.
332
+ * @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
333
+ */
334
+ FinancialAnnuityFormulas.prototype.ComputeNPV = function () {
335
+ var args = [];
336
+ for (var _i = 0; _i < arguments.length; _i++) {
337
+ args[_i] = arguments[_i];
338
+ }
339
+ if (isNullOrUndefined(args) || args.length < 2) {
340
+ return this.parent.formulaErrorStrings[FormulasErrorsStrings.WrongNumberArguments];
341
+ }
342
+ var rate = this.resolveNumberArg(args[0]);
343
+ if (typeof rate === 'string') {
344
+ return rate;
345
+ }
346
+ var npv = 0;
347
+ for (var i = 1; i < args.length; i++) {
348
+ var cf = this.resolveNumberArg(args[i]);
349
+ if (typeof cf === 'string') {
350
+ return cf;
351
+ }
352
+ npv += cf / Math.pow(1 + rate, i);
353
+ }
354
+ return npv.toString();
355
+ };
356
+ /**
357
+ * Returns the interest rate per period of an annuity.
358
+ *
359
+ * Excel: `RATE(...)`.
360
+ *
361
+ * @hidden
362
+ * @param {string[]} args - Formula argument tokens from the Calculate engine.
363
+ * @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
364
+ */
365
+ FinancialAnnuityFormulas.prototype.ComputeRATE = function () {
366
+ var args = [];
367
+ for (var _i = 0; _i < arguments.length; _i++) {
368
+ args[_i] = arguments[_i];
369
+ }
370
+ var errCollection = this.parent.getErrorStrings();
371
+ if (isNullOrUndefined(args) || args.length < 3 || args.length > 6) {
372
+ return this.parent.formulaErrorStrings[FormulasErrorsStrings.WrongNumberArguments];
373
+ }
374
+ var nper = this.resolveNumberArg(args[0]);
375
+ var pmt = this.resolveNumberArg(args[1]);
376
+ var pv = this.resolveNumberArg(args[2]);
377
+ if (typeof nper === 'string') {
378
+ return nper;
379
+ }
380
+ if (typeof pmt === 'string') {
381
+ return pmt;
382
+ }
383
+ if (typeof pv === 'string') {
384
+ return pv;
385
+ }
386
+ var fv = this.resolveOptional(args, 3, 0);
387
+ var type = this.resolveOptional(args, 4, 0);
388
+ var guess = this.resolveOptional(args, 5, 0.1);
389
+ if (typeof fv === 'string') {
390
+ return fv;
391
+ }
392
+ if (typeof type === 'string') {
393
+ return type;
394
+ }
395
+ if (typeof guess === 'string') {
396
+ return guess;
397
+ }
398
+ var rate = guess;
399
+ for (var i = 0; i < 100; i++) {
400
+ var when = type ? 1 : 0;
401
+ var pow = Math.pow(1 + rate, nper);
402
+ var f = pv * pow + pmt * (1 + rate * when) * (pow - 1) / rate + fv;
403
+ var df = nper * pv * Math.pow(1 + rate, nper - 1)
404
+ + pmt * (1 + rate * when) * (nper * Math.pow(1 + rate, nper - 1) * rate - (pow - 1)) / (rate * rate)
405
+ + pmt * when * (pow - 1) / rate;
406
+ if (Math.abs(df) < 1e-12) {
407
+ break;
408
+ }
409
+ var next = rate - f / df;
410
+ if (Math.abs(next - rate) < 1e-10) {
411
+ return next.toString();
412
+ }
413
+ rate = next;
414
+ }
415
+ return errCollection[CommonErrors.Num];
416
+ };
417
+ return FinancialAnnuityFormulas;
418
+ }(FormulaModuleBase));
419
+ export { FinancialAnnuityFormulas };
@@ -0,0 +1,106 @@
1
+ import { Calculate } from '../base/index';
2
+ /**
3
+ * Shared bond/coupon date helpers for financial ECMA formulas.
4
+ *
5
+ * @hidden
6
+ */
7
+ export declare class FinancialBondHelpers {
8
+ private parent;
9
+ constructor(parent: Calculate);
10
+ /**
11
+ * yearDays helper.
12
+ *
13
+ * @param {number} basis - basis argument.
14
+ * @returns {number} - yearDays result.
15
+ */
16
+ yearDays(basis: number): number;
17
+ /**
18
+ * toDate helper.
19
+ *
20
+ * @param {number} serial - serial argument.
21
+ * @returns {Date} - toDate result.
22
+ */
23
+ toDate(serial: number): Date;
24
+ /**
25
+ * toSerial helper.
26
+ *
27
+ * @param {Date} date - date argument.
28
+ * @returns {number} - toSerial result.
29
+ */
30
+ toSerial(date: Date): number;
31
+ /**
32
+ * coupPCD helper.
33
+ *
34
+ * @param {number} settlement - settlement argument.
35
+ * @param {number} maturity - maturity argument.
36
+ * @param {number} frequency - frequency argument.
37
+ * @returns {number} - coupPCD result.
38
+ */
39
+ coupPCD(settlement: number, maturity: number, frequency: number): number;
40
+ /**
41
+ * coupNCD helper.
42
+ *
43
+ * @param {number} settlement - settlement argument.
44
+ * @param {number} maturity - maturity argument.
45
+ * @param {number} frequency - frequency argument.
46
+ * @returns {number} - coupNCD result.
47
+ */
48
+ coupNCD(settlement: number, maturity: number, frequency: number): number;
49
+ /**
50
+ * coupDays helper.
51
+ *
52
+ * @param {number} settlement - settlement argument.
53
+ * @param {number} maturity - maturity argument.
54
+ * @param {number} frequency - frequency argument.
55
+ * @param {number} basis - basis argument.
56
+ * @returns {number} - coupDays result.
57
+ */
58
+ coupDays(settlement: number, maturity: number, frequency: number, basis?: number): number;
59
+ /**
60
+ * coupDayBS helper.
61
+ *
62
+ * @param {number} settlement - settlement argument.
63
+ * @param {number} maturity - maturity argument.
64
+ * @param {number} frequency - frequency argument.
65
+ * @param {number} basis - basis argument.
66
+ * @returns {number} - coupDayBS result.
67
+ */
68
+ coupDayBS(settlement: number, maturity: number, frequency: number, basis?: number): number;
69
+ /**
70
+ * coupDaysNC helper.
71
+ *
72
+ * @param {number} settlement - settlement argument.
73
+ * @param {number} maturity - maturity argument.
74
+ * @param {number} frequency - frequency argument.
75
+ * @param {number} basis - basis argument.
76
+ * @returns {number} - coupDaysNC result.
77
+ */
78
+ coupDaysNC(settlement: number, maturity: number, frequency: number, basis?: number): number;
79
+ /**
80
+ * coupNum helper.
81
+ *
82
+ * @param {number} settlement - settlement argument.
83
+ * @param {number} maturity - maturity argument.
84
+ * @param {number} frequency - frequency argument.
85
+ * @param {number} _basis - basis argument.
86
+ * @returns {number} - coupNum result.
87
+ */
88
+ coupNum(settlement: number, maturity: number, frequency: number, _basis?: number): number;
89
+ /**
90
+ * daysBetween helper.
91
+ *
92
+ * @param {number} start - start argument.
93
+ * @param {number} end - end argument.
94
+ * @param {number} basis - basis argument.
95
+ * @returns {number} - daysBetween result.
96
+ */
97
+ daysBetween(start: number, end: number, basis: number): number;
98
+ /**
99
+ * addMonths helper.
100
+ *
101
+ * @param {Date} date - date argument.
102
+ * @param {number} months - months argument.
103
+ * @returns {Date} - addMonths result.
104
+ */
105
+ private addMonths;
106
+ }