@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,190 @@
1
+ /**
2
+ * Shared bond/coupon date helpers for financial ECMA formulas.
3
+ *
4
+ * @hidden
5
+ */
6
+ var FinancialBondHelpers = /** @class */ (function () {
7
+ function FinancialBondHelpers(parent) {
8
+ this.parent = parent;
9
+ }
10
+ /**
11
+ * yearDays helper.
12
+ *
13
+ * @param {number} basis - basis argument.
14
+ * @returns {number} - yearDays result.
15
+ */
16
+ FinancialBondHelpers.prototype.yearDays = function (basis) {
17
+ switch (basis) {
18
+ case 1:
19
+ return 365;
20
+ case 3:
21
+ return 365;
22
+ default:
23
+ return 360;
24
+ }
25
+ };
26
+ /**
27
+ * toDate helper.
28
+ *
29
+ * @param {number} serial - serial argument.
30
+ * @returns {Date} - toDate result.
31
+ */
32
+ FinancialBondHelpers.prototype.toDate = function (serial) {
33
+ return this.parent.fromOADate(serial);
34
+ };
35
+ /**
36
+ * toSerial helper.
37
+ *
38
+ * @param {Date} date - date argument.
39
+ * @returns {number} - toSerial result.
40
+ */
41
+ FinancialBondHelpers.prototype.toSerial = function (date) {
42
+ return this.parent.toOADate(date);
43
+ };
44
+ /**
45
+ * coupPCD helper.
46
+ *
47
+ * @param {number} settlement - settlement argument.
48
+ * @param {number} maturity - maturity argument.
49
+ * @param {number} frequency - frequency argument.
50
+ * @returns {number} - coupPCD result.
51
+ */
52
+ FinancialBondHelpers.prototype.coupPCD = function (settlement, maturity, frequency) {
53
+ var mat = this.toDate(maturity);
54
+ var coupon = new Date(mat.getFullYear(), mat.getMonth(), mat.getDate());
55
+ var monthsPer = 12 / frequency;
56
+ while (this.toSerial(coupon) > settlement) {
57
+ coupon = this.addMonths(coupon, -monthsPer);
58
+ }
59
+ if (this.toSerial(coupon) > settlement) {
60
+ return settlement;
61
+ }
62
+ return this.toSerial(coupon);
63
+ };
64
+ /**
65
+ * coupNCD helper.
66
+ *
67
+ * @param {number} settlement - settlement argument.
68
+ * @param {number} maturity - maturity argument.
69
+ * @param {number} frequency - frequency argument.
70
+ * @returns {number} - coupNCD result.
71
+ */
72
+ FinancialBondHelpers.prototype.coupNCD = function (settlement, maturity, frequency) {
73
+ var pcd = this.coupPCD(settlement, maturity, frequency);
74
+ if (pcd <= settlement) {
75
+ var monthsPer = 12 / frequency;
76
+ pcd = this.toSerial(this.addMonths(this.toDate(pcd), monthsPer));
77
+ }
78
+ return pcd;
79
+ };
80
+ /**
81
+ * coupDays helper.
82
+ *
83
+ * @param {number} settlement - settlement argument.
84
+ * @param {number} maturity - maturity argument.
85
+ * @param {number} frequency - frequency argument.
86
+ * @param {number} basis - basis argument.
87
+ * @returns {number} - coupDays result.
88
+ */
89
+ FinancialBondHelpers.prototype.coupDays = function (settlement, maturity, frequency, basis) {
90
+ if (basis === void 0) { basis = 0; }
91
+ var pcd = this.coupPCD(settlement, maturity, frequency);
92
+ var ncd = this.coupNCD(settlement, maturity, frequency);
93
+ return this.daysBetween(pcd, ncd, basis);
94
+ };
95
+ /**
96
+ * coupDayBS helper.
97
+ *
98
+ * @param {number} settlement - settlement argument.
99
+ * @param {number} maturity - maturity argument.
100
+ * @param {number} frequency - frequency argument.
101
+ * @param {number} basis - basis argument.
102
+ * @returns {number} - coupDayBS result.
103
+ */
104
+ FinancialBondHelpers.prototype.coupDayBS = function (settlement, maturity, frequency, basis) {
105
+ if (basis === void 0) { basis = 0; }
106
+ var pcd = this.coupPCD(settlement, maturity, frequency);
107
+ return this.daysBetween(pcd, settlement, basis);
108
+ };
109
+ /**
110
+ * coupDaysNC helper.
111
+ *
112
+ * @param {number} settlement - settlement argument.
113
+ * @param {number} maturity - maturity argument.
114
+ * @param {number} frequency - frequency argument.
115
+ * @param {number} basis - basis argument.
116
+ * @returns {number} - coupDaysNC result.
117
+ */
118
+ FinancialBondHelpers.prototype.coupDaysNC = function (settlement, maturity, frequency, basis) {
119
+ if (basis === void 0) { basis = 0; }
120
+ var ncd = this.coupNCD(settlement, maturity, frequency);
121
+ return this.daysBetween(settlement, ncd, basis);
122
+ };
123
+ /**
124
+ * coupNum helper.
125
+ *
126
+ * @param {number} settlement - settlement argument.
127
+ * @param {number} maturity - maturity argument.
128
+ * @param {number} frequency - frequency argument.
129
+ * @param {number} _basis - basis argument.
130
+ * @returns {number} - coupNum result.
131
+ */
132
+ FinancialBondHelpers.prototype.coupNum = function (settlement, maturity, frequency, _basis) {
133
+ if (_basis === void 0) { _basis = 0; }
134
+ void _basis;
135
+ var monthsPer = 12 / frequency;
136
+ var mat = this.toDate(maturity);
137
+ var coupon = new Date(mat.getFullYear(), mat.getMonth(), mat.getDate());
138
+ var count = 0;
139
+ while (this.toSerial(coupon) > settlement) {
140
+ count++;
141
+ coupon = this.addMonths(coupon, -monthsPer);
142
+ }
143
+ return count;
144
+ };
145
+ /**
146
+ * daysBetween helper.
147
+ *
148
+ * @param {number} start - start argument.
149
+ * @param {number} end - end argument.
150
+ * @param {number} basis - basis argument.
151
+ * @returns {number} - daysBetween result.
152
+ */
153
+ FinancialBondHelpers.prototype.daysBetween = function (start, end, basis) {
154
+ if (basis === 1) {
155
+ return Math.round((end - start));
156
+ }
157
+ var d1 = this.toDate(start);
158
+ var d2 = this.toDate(end);
159
+ if (basis === 3) {
160
+ return Math.abs(Math.round((d2.getTime() - d1.getTime()) / 86400000));
161
+ }
162
+ var y1 = d1.getFullYear();
163
+ var m1 = d1.getMonth() + 1;
164
+ var day1 = d1.getDate();
165
+ var y2 = d2.getFullYear();
166
+ var m2 = d2.getMonth() + 1;
167
+ var day2 = d2.getDate();
168
+ if (day1 === 31) {
169
+ day1 = 30;
170
+ }
171
+ if (day2 === 31) {
172
+ day2 = 30;
173
+ }
174
+ return (y2 - y1) * 360 + (m2 - m1) * 30 + (day2 - day1);
175
+ };
176
+ /**
177
+ * addMonths helper.
178
+ *
179
+ * @param {Date} date - date argument.
180
+ * @param {number} months - months argument.
181
+ * @returns {Date} - addMonths result.
182
+ */
183
+ FinancialBondHelpers.prototype.addMonths = function (date, months) {
184
+ var d = new Date(date.getTime());
185
+ d.setMonth(d.getMonth() + months);
186
+ return d;
187
+ };
188
+ return FinancialBondHelpers;
189
+ }());
190
+ export { FinancialBondHelpers };
@@ -0,0 +1,47 @@
1
+ import { IBasicFormula } from '../common/index';
2
+ import { FormulaOwner } from './formula-owner';
3
+ import { FormulaModuleBase } from './formula-module-base';
4
+ /**
5
+ * Net present value and internal rate of return for uneven cash-flow series.
6
+ *
7
+ * Registered functions: IRR, MIRR.
8
+ *
9
+ * @hidden
10
+ */
11
+ export declare class FinancialCashflowFormulas extends FormulaModuleBase {
12
+ /** Formula definitions registered with {@link BasicFormulas}. */
13
+ formulas: IBasicFormula[];
14
+ /**
15
+ * @hidden
16
+ * @param {FormulaOwner} owner - Formula registration owner ({@link BasicFormulas}).
17
+ */
18
+ constructor(owner: FormulaOwner);
19
+ private collectCashflows;
20
+ private npvAtRate;
21
+ private npvDerivative;
22
+ /**
23
+ * Returns the internal rate of return for a series of cash flows.
24
+ *
25
+ * Excel: `IRR(...)`.
26
+ *
27
+ * @hidden
28
+ * @param {string[]} args - Formula argument tokens from the Calculate engine.
29
+ * @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
30
+ *
31
+ * @example
32
+ * ```ts
33
+ * engine.computeFormula('=IRR(1)');
34
+ * ```
35
+ */
36
+ ComputeIRR(...args: string[]): string | number;
37
+ /**
38
+ * Returns the modified internal rate of return for cash flows.
39
+ *
40
+ * Excel: `MIRR(...)`.
41
+ *
42
+ * @hidden
43
+ * @param {string[]} args - Formula argument tokens from the Calculate engine.
44
+ * @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
45
+ */
46
+ ComputeMIRR(...args: string[]): string | number;
47
+ }
@@ -0,0 +1,203 @@
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
+ * Net present value and internal rate of return for uneven cash-flow series.
19
+ *
20
+ * Registered functions: IRR, MIRR.
21
+ *
22
+ * @hidden
23
+ */
24
+ var FinancialCashflowFormulas = /** @class */ (function (_super) {
25
+ __extends(FinancialCashflowFormulas, _super);
26
+ /**
27
+ * @hidden
28
+ * @param {FormulaOwner} owner - Formula registration owner ({@link BasicFormulas}).
29
+ */
30
+ function FinancialCashflowFormulas(owner) {
31
+ var _this = _super.call(this, owner) || this;
32
+ /** Formula definitions registered with {@link BasicFormulas}. */
33
+ _this.formulas = [
34
+ { formulaName: 'IRR', category: 'Financial', description: 'Returns the internal rate of return for a series of cash flows.' },
35
+ { formulaName: 'MIRR', category: 'Financial', description: 'Returns the modified internal rate of return for cash flows.' }
36
+ ];
37
+ return _this;
38
+ }
39
+ FinancialCashflowFormulas.prototype.collectCashflows = function (args) {
40
+ var errCollection = this.parent.getErrorStrings();
41
+ var flows = [];
42
+ for (var i = 0; i < args.length; i++) {
43
+ var arg = args[i];
44
+ if (arg === '') {
45
+ continue;
46
+ }
47
+ if (this.parent.isCellReference(arg) && arg.indexOf(':') > -1) {
48
+ var cells = this.parent.getCellCollection(arg);
49
+ var list = Array.isArray(cells) ? cells : [cells];
50
+ for (var c = 0; c < list.length; c++) {
51
+ var val = this.parent.getValueFromArg(list[c]);
52
+ if (errCollection.indexOf(val) > -1) {
53
+ return val;
54
+ }
55
+ if (val !== '' && this.parent.isNumber(val)) {
56
+ flows.push(this.parent.parseFloat(val));
57
+ }
58
+ }
59
+ }
60
+ else {
61
+ var num = this.resolveNumberArg(arg);
62
+ if (typeof num === 'string') {
63
+ return num;
64
+ }
65
+ flows.push(num);
66
+ }
67
+ }
68
+ return flows;
69
+ };
70
+ FinancialCashflowFormulas.prototype.npvAtRate = function (flows, rate) {
71
+ var npv = 0;
72
+ for (var i = 0; i < flows.length; i++) {
73
+ npv += flows[i] / Math.pow(1 + rate, i);
74
+ }
75
+ return npv;
76
+ };
77
+ FinancialCashflowFormulas.prototype.npvDerivative = function (flows, rate) {
78
+ var d = 0;
79
+ for (var i = 1; i < flows.length; i++) {
80
+ d -= i * flows[i] / Math.pow(1 + rate, i + 1);
81
+ }
82
+ return d;
83
+ };
84
+ /**
85
+ * Returns the internal rate of return for a series of cash flows.
86
+ *
87
+ * Excel: `IRR(...)`.
88
+ *
89
+ * @hidden
90
+ * @param {string[]} args - Formula argument tokens from the Calculate engine.
91
+ * @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
92
+ *
93
+ * @example
94
+ * ```ts
95
+ * engine.computeFormula('=IRR(1)');
96
+ * ```
97
+ */
98
+ FinancialCashflowFormulas.prototype.ComputeIRR = function () {
99
+ var args = [];
100
+ for (var _i = 0; _i < arguments.length; _i++) {
101
+ args[_i] = arguments[_i];
102
+ }
103
+ var errCollection = this.parent.getErrorStrings();
104
+ if (isNullOrUndefined(args) || args.length < 1) {
105
+ return this.parent.formulaErrorStrings[FormulasErrorsStrings.WrongNumberArguments];
106
+ }
107
+ var guess = 0.1;
108
+ var flowArgs = args;
109
+ if (args.length === 2 && this.parent.isCellReference(args[0])) {
110
+ var guessArg = this.resolveNumberArg(args[1]);
111
+ if (typeof guessArg === 'number') {
112
+ guess = guessArg;
113
+ flowArgs = [args[0]];
114
+ }
115
+ }
116
+ var flows = this.collectCashflows(flowArgs);
117
+ if (typeof flows === 'string') {
118
+ return flows;
119
+ }
120
+ if (flows.length < 2) {
121
+ return errCollection[CommonErrors.Num];
122
+ }
123
+ var hasPos = false;
124
+ var hasNeg = false;
125
+ for (var i = 0; i < flows.length; i++) {
126
+ if (flows[i] > 0) {
127
+ hasPos = true;
128
+ }
129
+ if (flows[i] < 0) {
130
+ hasNeg = true;
131
+ }
132
+ }
133
+ if (!hasPos || !hasNeg) {
134
+ return errCollection[CommonErrors.Num];
135
+ }
136
+ var rate = guess;
137
+ for (var iter = 0; iter < 100; iter++) {
138
+ var npv = this.npvAtRate(flows, rate);
139
+ var dnpv = this.npvDerivative(flows, rate);
140
+ if (Math.abs(dnpv) < 1e-12) {
141
+ break;
142
+ }
143
+ var next = rate - npv / dnpv;
144
+ if (Math.abs(next - rate) < 1e-10) {
145
+ return next.toString();
146
+ }
147
+ rate = next;
148
+ }
149
+ return errCollection[CommonErrors.Num];
150
+ };
151
+ /**
152
+ * Returns the modified internal rate of return for cash flows.
153
+ *
154
+ * Excel: `MIRR(...)`.
155
+ *
156
+ * @hidden
157
+ * @param {string[]} args - Formula argument tokens from the Calculate engine.
158
+ * @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
159
+ */
160
+ FinancialCashflowFormulas.prototype.ComputeMIRR = function () {
161
+ var args = [];
162
+ for (var _i = 0; _i < arguments.length; _i++) {
163
+ args[_i] = arguments[_i];
164
+ }
165
+ var errCollection = this.parent.getErrorStrings();
166
+ if (isNullOrUndefined(args) || args.length !== 3) {
167
+ return this.parent.formulaErrorStrings[FormulasErrorsStrings.WrongNumberArguments];
168
+ }
169
+ var financeRate = this.resolveNumberArg(args[1]);
170
+ var reinvestRate = this.resolveNumberArg(args[2]);
171
+ if (typeof financeRate === 'string') {
172
+ return financeRate;
173
+ }
174
+ if (typeof reinvestRate === 'string') {
175
+ return reinvestRate;
176
+ }
177
+ var flows = this.collectCashflows([args[0]]);
178
+ if (typeof flows === 'string') {
179
+ return flows;
180
+ }
181
+ if (flows.length < 2) {
182
+ return errCollection[CommonErrors.Num];
183
+ }
184
+ var n = flows.length - 1;
185
+ var posPv = 0;
186
+ var negFv = 0;
187
+ for (var i = 0; i < flows.length; i++) {
188
+ var cf = flows[i];
189
+ if (cf >= 0) {
190
+ negFv += cf * Math.pow(1 + reinvestRate, n - i);
191
+ }
192
+ else {
193
+ posPv += cf / Math.pow(1 + financeRate, i);
194
+ }
195
+ }
196
+ if (posPv === 0 || negFv === 0) {
197
+ return errCollection[CommonErrors.DivZero];
198
+ }
199
+ return (Math.pow(-negFv / posPv, 1 / n) - 1).toString();
200
+ };
201
+ return FinancialCashflowFormulas;
202
+ }(FormulaModuleBase));
203
+ export { FinancialCashflowFormulas };
@@ -0,0 +1,227 @@
1
+ import { IBasicFormula } from '../common/index';
2
+ import { FormulaOwner } from './formula-owner';
3
+ import { FormulaModuleBase } from './formula-module-base';
4
+ /**
5
+ * Bond coupon payment schedules, accrued interest, and coupon-period date boundaries.
6
+ *
7
+ * Registers 20 functions including COUPDAYBS, COUPDAYS, COUPDAYSNC, COUPNCD, COUPNUM, and others.
8
+ *
9
+ * @hidden
10
+ */
11
+ export declare class FinancialCouponsFormulas extends FormulaModuleBase {
12
+ private bond;
13
+ /** Formula definitions registered with {@link BasicFormulas}. */
14
+ formulas: IBasicFormula[];
15
+ /**
16
+ * @hidden
17
+ * @param {FormulaOwner} owner - Formula registration owner ({@link BasicFormulas}).
18
+ */
19
+ constructor(owner: FormulaOwner);
20
+ private parseBondArgs;
21
+ private coupArgs;
22
+ /**
23
+ * Returns the number of days from the beginning of the coupon period to the settlement date.
24
+ *
25
+ * Excel: `COUPDAYBS(...)`.
26
+ *
27
+ * @hidden
28
+ * @param {string[]} args - Formula argument tokens from the Calculate engine.
29
+ * @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
30
+ *
31
+ * @example
32
+ * ```ts
33
+ * engine.computeFormula('=COUPDAYBS(1)');
34
+ * ```
35
+ */
36
+ ComputeCOUPDAYBS(...args: string[]): string | number;
37
+ /**
38
+ * Returns the number of days in the coupon period that contains the settlement date.
39
+ *
40
+ * Excel: `COUPDAYS(...)`.
41
+ *
42
+ * @hidden
43
+ * @param {string[]} args - Formula argument tokens from the Calculate engine.
44
+ * @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
45
+ */
46
+ ComputeCOUPDAYS(...args: string[]): string | number;
47
+ /**
48
+ * Returns the number of days from the settlement date to the next coupon date.
49
+ *
50
+ * Excel: `COUPDAYSNC(...)`.
51
+ *
52
+ * @hidden
53
+ * @param {string[]} args - Formula argument tokens from the Calculate engine.
54
+ * @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
55
+ */
56
+ ComputeCOUPDAYSNC(...args: string[]): string | number;
57
+ /**
58
+ * Returns the next coupon date after the settlement date.
59
+ *
60
+ * Excel: `COUPNCD(...)`.
61
+ *
62
+ * @hidden
63
+ * @param {string[]} args - Formula argument tokens from the Calculate engine.
64
+ * @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
65
+ */
66
+ ComputeCOUPNCD(...args: string[]): string | number;
67
+ /**
68
+ * Returns the number of coupons payable between settlement and maturity.
69
+ *
70
+ * Excel: `COUPNUM(...)`.
71
+ *
72
+ * @hidden
73
+ * @param {string[]} args - Formula argument tokens from the Calculate engine.
74
+ * @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
75
+ */
76
+ ComputeCOUPNUM(...args: string[]): string | number;
77
+ /**
78
+ * Returns the previous coupon date before the settlement date.
79
+ *
80
+ * Excel: `COUPPCD(...)`.
81
+ *
82
+ * @hidden
83
+ * @param {string[]} args - Formula argument tokens from the Calculate engine.
84
+ * @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
85
+ */
86
+ ComputeCOUPPCD(...args: string[]): string | number;
87
+ /**
88
+ * Returns the accrued interest for a security that pays periodic interest.
89
+ *
90
+ * Excel: `ACCRINT(...)`.
91
+ *
92
+ * @hidden
93
+ * @param {string[]} args - Formula argument tokens from the Calculate engine.
94
+ * @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
95
+ */
96
+ ComputeACCRINT(...args: string[]): string | number;
97
+ /**
98
+ * Returns the accrued interest for a security that pays interest at maturity.
99
+ *
100
+ * Excel: `ACCRINTM(...)`.
101
+ *
102
+ * @hidden
103
+ * @param {string[]} args - Formula argument tokens from the Calculate engine.
104
+ * @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
105
+ */
106
+ ComputeACCRINTM(...args: string[]): string | number;
107
+ /**
108
+ * Returns the interest paid during a specific period of an investment.
109
+ *
110
+ * Excel: `ISPMT(...)`.
111
+ *
112
+ * @hidden
113
+ * @param {string[]} args - Formula argument tokens from the Calculate engine.
114
+ * @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
115
+ */
116
+ ComputeISPMT(...args: string[]): string | number;
117
+ /**
118
+ * Returns the modified Macauley duration for a security with an assumed par value of $100.
119
+ *
120
+ * Excel: `MDURATION(...)`.
121
+ *
122
+ * @hidden
123
+ * @param {string[]} args - Formula argument tokens from the Calculate engine.
124
+ * @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
125
+ */
126
+ ComputeMDURATION(...args: string[]): string | number;
127
+ /**
128
+ * Returns the price per $100 face value of a security that pays periodic interest.
129
+ *
130
+ * Excel: `PRICE(...)`.
131
+ *
132
+ * @hidden
133
+ * @param {string[]} args - Formula argument tokens from the Calculate engine.
134
+ * @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
135
+ */
136
+ ComputePRICE(...args: string[]): string | number;
137
+ /**
138
+ * Returns the price per $100 face value of a discounted security.
139
+ *
140
+ * Excel: `PRICEDISC(...)`.
141
+ *
142
+ * @hidden
143
+ * @param {string[]} args - Formula argument tokens from the Calculate engine.
144
+ * @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
145
+ */
146
+ ComputePRICEDISC(...args: string[]): string | number;
147
+ /**
148
+ * Returns the price per $100 face value of a security that pays interest at maturity.
149
+ *
150
+ * Excel: `PRICEMAT(...)`.
151
+ *
152
+ * @hidden
153
+ * @param {string[]} args - Formula argument tokens from the Calculate engine.
154
+ * @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
155
+ */
156
+ ComputePRICEMAT(...args: string[]): string | number;
157
+ /**
158
+ * Returns the price per $100 face value for a Treasury bill.
159
+ *
160
+ * Excel: `TBILLPRICE(...)`.
161
+ *
162
+ * @hidden
163
+ * @param {string[]} args - Formula argument tokens from the Calculate engine.
164
+ * @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
165
+ */
166
+ ComputeTBILLPRICE(...args: string[]): string | number;
167
+ /**
168
+ * Returns the yield for a Treasury bill.
169
+ *
170
+ * Excel: `TBILLYIELD(...)`.
171
+ *
172
+ * @hidden
173
+ * @param {string[]} args - Formula argument tokens from the Calculate engine.
174
+ * @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
175
+ */
176
+ ComputeTBILLYIELD(...args: string[]): string | number;
177
+ /**
178
+ * Returns the bond-equivalent yield for a Treasury bill.
179
+ *
180
+ * Excel: `TBILLEQ(...)`.
181
+ *
182
+ * @hidden
183
+ * @param {string[]} args - Formula argument tokens from the Calculate engine.
184
+ * @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
185
+ */
186
+ ComputeTBILLEQ(...args: string[]): string | number;
187
+ /**
188
+ * Returns the net present value for a schedule of cash flows that is not necessarily periodic.
189
+ *
190
+ * Excel: `XNPV(...)`.
191
+ *
192
+ * @hidden
193
+ * @param {string[]} args - Formula argument tokens from the Calculate engine.
194
+ * @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
195
+ */
196
+ ComputeXNPV(...args: string[]): string | number;
197
+ /**
198
+ * Returns the yield on a security that pays periodic interest.
199
+ *
200
+ * Excel: `YIELD(...)`.
201
+ *
202
+ * @hidden
203
+ * @param {string[]} args - Formula argument tokens from the Calculate engine.
204
+ * @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
205
+ */
206
+ ComputeYIELD(...args: string[]): string | number;
207
+ /**
208
+ * Returns the annual yield for a discounted security.
209
+ *
210
+ * Excel: `YIELDDISC(...)`.
211
+ *
212
+ * @hidden
213
+ * @param {string[]} args - Formula argument tokens from the Calculate engine.
214
+ * @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
215
+ */
216
+ ComputeYIELDDISC(...args: string[]): string | number;
217
+ /**
218
+ * Returns the annual yield of a security that pays interest at maturity.
219
+ *
220
+ * Excel: `YIELDMAT(...)`.
221
+ *
222
+ * @hidden
223
+ * @param {string[]} args - Formula argument tokens from the Calculate engine.
224
+ * @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
225
+ */
226
+ ComputeYIELDMAT(...args: string[]): string | number;
227
+ }