@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.
- package/.eslintrc.json +263 -0
- package/README.md +132 -0
- package/base.d.ts +4 -0
- package/base.js +4 -0
- package/common.d.ts +4 -0
- package/common.js +4 -0
- package/dist/ej2-calculate.umd.min.js +11 -0
- package/dist/ej2-calculate.umd.min.js.map +1 -0
- package/dist/es6/ej2-calculate.es2015.js +24801 -0
- package/dist/es6/ej2-calculate.es2015.js.map +1 -0
- package/dist/es6/ej2-calculate.es5.js +27229 -0
- package/dist/es6/ej2-calculate.es5.js.map +1 -0
- package/dist/global/ej2-calculate.min.js +11 -0
- package/dist/global/ej2-calculate.min.js.map +1 -0
- package/dist/global/index.d.ts +14 -0
- package/formulas.d.ts +4 -0
- package/formulas.js +4 -0
- package/index.d.ts +4 -0
- package/index.js +4 -0
- package/license +10 -0
- package/package.json +30 -0
- package/src/base/calculate-model.d.ts +4 -0
- package/src/base/calculate-model.js +0 -0
- package/src/base/calculate.d.ts +1105 -0
- package/src/base/calculate.js +4720 -0
- package/src/base/index.d.ts +8 -0
- package/src/base/index.js +7 -0
- package/src/base/parser.d.ts +208 -0
- package/src/base/parser.js +1512 -0
- package/src/common/address.d.ts +59 -0
- package/src/common/address.js +96 -0
- package/src/common/cell-ref.d.ts +32 -0
- package/src/common/cell-ref.js +112 -0
- package/src/common/common.d.ts +44 -0
- package/src/common/common.js +134 -0
- package/src/common/enum.d.ts +94 -0
- package/src/common/enum.js +97 -0
- package/src/common/index.d.ts +9 -0
- package/src/common/index.js +8 -0
- package/src/common/interface.d.ts +122 -0
- package/src/common/interface.js +0 -0
- package/src/common/l10n.d.ts +24 -0
- package/src/common/l10n.js +54 -0
- package/src/common/number-date.d.ts +26 -0
- package/src/common/number-date.js +38 -0
- package/src/common/sheet-info.d.ts +10 -0
- package/src/common/sheet-info.js +17 -0
- package/src/common/sort.d.ts +17 -0
- package/src/common/sort.js +44 -0
- package/src/formulas/array.d.ts +47 -0
- package/src/formulas/array.js +718 -0
- package/src/formulas/basic.d.ts +47 -0
- package/src/formulas/basic.js +181 -0
- package/src/formulas/complex-numbers.d.ts +207 -0
- package/src/formulas/complex-numbers.js +549 -0
- package/src/formulas/database.d.ts +152 -0
- package/src/formulas/database.js +579 -0
- package/src/formulas/date-time-extra.d.ts +97 -0
- package/src/formulas/date-time-extra.js +415 -0
- package/src/formulas/date-time-intl.d.ts +57 -0
- package/src/formulas/date-time-intl.js +309 -0
- package/src/formulas/date-time.d.ts +164 -0
- package/src/formulas/date-time.js +1021 -0
- package/src/formulas/engineering-base.d.ts +150 -0
- package/src/formulas/engineering-base.js +404 -0
- package/src/formulas/engineering-bessel.d.ts +65 -0
- package/src/formulas/engineering-bessel.js +167 -0
- package/src/formulas/engineering-convert.d.ts +35 -0
- package/src/formulas/engineering-convert.js +120 -0
- package/src/formulas/engineering-misc.d.ts +64 -0
- package/src/formulas/engineering-misc.js +168 -0
- package/src/formulas/financial-amortization-ecma.d.ts +87 -0
- package/src/formulas/financial-amortization-ecma.js +288 -0
- package/src/formulas/financial-annuity.d.ts +104 -0
- package/src/formulas/financial-annuity.js +419 -0
- package/src/formulas/financial-bond-helpers.d.ts +106 -0
- package/src/formulas/financial-bond-helpers.js +190 -0
- package/src/formulas/financial-cashflow.d.ts +47 -0
- package/src/formulas/financial-cashflow.js +203 -0
- package/src/formulas/financial-coupons.d.ts +227 -0
- package/src/formulas/financial-coupons.js +810 -0
- package/src/formulas/financial-depreciation.d.ts +64 -0
- package/src/formulas/financial-depreciation.js +247 -0
- package/src/formulas/financial-rates.d.ts +54 -0
- package/src/formulas/financial-rates.js +140 -0
- package/src/formulas/financial-securities.d.ts +126 -0
- package/src/formulas/financial-securities.js +488 -0
- package/src/formulas/formula-math-helpers.d.ts +212 -0
- package/src/formulas/formula-math-helpers.js +599 -0
- package/src/formulas/formula-module-base.d.ts +54 -0
- package/src/formulas/formula-module-base.js +125 -0
- package/src/formulas/formula-owner.d.ts +17 -0
- package/src/formulas/formula-owner.js +0 -0
- package/src/formulas/index.d.ts +68 -0
- package/src/formulas/index.js +67 -0
- package/src/formulas/information-advanced.d.ts +44 -0
- package/src/formulas/information-advanced.js +157 -0
- package/src/formulas/information-ecma.d.ts +33 -0
- package/src/formulas/information-ecma.js +88 -0
- package/src/formulas/information-extra.d.ts +146 -0
- package/src/formulas/information-extra.js +351 -0
- package/src/formulas/information.d.ts +34 -0
- package/src/formulas/information.js +78 -0
- package/src/formulas/logical-extra.d.ts +75 -0
- package/src/formulas/logical-extra.js +217 -0
- package/src/formulas/logical.d.ts +83 -0
- package/src/formulas/logical.js +296 -0
- package/src/formulas/lookup-array.d.ts +98 -0
- package/src/formulas/lookup-array.js +364 -0
- package/src/formulas/lookup-ref-extra.d.ts +64 -0
- package/src/formulas/lookup-ref-extra.js +180 -0
- package/src/formulas/lookup-ref.d.ts +84 -0
- package/src/formulas/lookup-ref.js +263 -0
- package/src/formulas/lookup.d.ts +114 -0
- package/src/formulas/lookup.js +881 -0
- package/src/formulas/math-aggregate.d.ts +74 -0
- package/src/formulas/math-aggregate.js +376 -0
- package/src/formulas/math-ceiling-ecma.d.ts +42 -0
- package/src/formulas/math-ceiling-ecma.js +123 -0
- package/src/formulas/math-combinatorics.d.ts +75 -0
- package/src/formulas/math-combinatorics.js +290 -0
- package/src/formulas/math-misc.d.ts +164 -0
- package/src/formulas/math-misc.js +889 -0
- package/src/formulas/math-number.d.ts +76 -0
- package/src/formulas/math-number.js +261 -0
- package/src/formulas/math-rounding.d.ts +115 -0
- package/src/formulas/math-rounding.js +728 -0
- package/src/formulas/math-trig-hyperbolic.d.ts +55 -0
- package/src/formulas/math-trig-hyperbolic.js +113 -0
- package/src/formulas/math-trig.d.ts +165 -0
- package/src/formulas/math-trig.js +334 -0
- package/src/formulas/matrix-base.d.ts +13 -0
- package/src/formulas/matrix-base.js +169 -0
- package/src/formulas/matrix.d.ts +64 -0
- package/src/formulas/matrix.js +161 -0
- package/src/formulas/regression-ecma.d.ts +66 -0
- package/src/formulas/regression-ecma.js +234 -0
- package/src/formulas/statistical-advanced.d.ts +125 -0
- package/src/formulas/statistical-advanced.js +756 -0
- package/src/formulas/statistical-correlation.d.ts +75 -0
- package/src/formulas/statistical-correlation.js +198 -0
- package/src/formulas/statistical-dispersion.d.ts +108 -0
- package/src/formulas/statistical-dispersion.js +337 -0
- package/src/formulas/statistical-distribution-extended.d.ts +176 -0
- package/src/formulas/statistical-distribution-extended.js +668 -0
- package/src/formulas/statistical-distribution.d.ts +104 -0
- package/src/formulas/statistical-distribution.js +368 -0
- package/src/formulas/statistical-ecma.d.ts +95 -0
- package/src/formulas/statistical-ecma.js +392 -0
- package/src/formulas/statistical-extended.d.ts +136 -0
- package/src/formulas/statistical-extended.js +340 -0
- package/src/formulas/statistical-ifs.d.ts +46 -0
- package/src/formulas/statistical-ifs.js +180 -0
- package/src/formulas/statistical-moments.d.ts +84 -0
- package/src/formulas/statistical-moments.js +269 -0
- package/src/formulas/statistical-percentile.d.ts +56 -0
- package/src/formulas/statistical-percentile.js +195 -0
- package/src/formulas/statistical-sample-base.d.ts +14 -0
- package/src/formulas/statistical-sample-base.js +124 -0
- package/src/formulas/statistical.d.ts +135 -0
- package/src/formulas/statistical.js +542 -0
- package/src/formulas/text-advanced.d.ts +64 -0
- package/src/formulas/text-advanced.js +222 -0
- package/src/formulas/text-ecma.d.ts +54 -0
- package/src/formulas/text-ecma.js +106 -0
- package/src/formulas/text-extra.d.ts +216 -0
- package/src/formulas/text-extra.js +657 -0
- package/src/formulas/text.d.ts +125 -0
- package/src/formulas/text.js +628 -0
- package/src/global.js +1 -0
- package/src/index.d.ts +14 -0
- package/src/index.js +14 -0
- package/tslint.json +111 -0
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { IBasicFormula } from '../common/index';
|
|
2
|
+
import { FormulaOwner } from './formula-owner';
|
|
3
|
+
import { FormulaModuleBase } from './formula-module-base';
|
|
4
|
+
/**
|
|
5
|
+
* Asset depreciation schedules including straight-line, declining-balance, and SYD methods.
|
|
6
|
+
*
|
|
7
|
+
* Registered functions: SLN, SYD, DB, DDB.
|
|
8
|
+
*
|
|
9
|
+
* @hidden
|
|
10
|
+
*/
|
|
11
|
+
export declare class FinancialDepreciationFormulas 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
|
+
/**
|
|
20
|
+
* Returns the straight-line depreciation of an asset for one period.
|
|
21
|
+
*
|
|
22
|
+
* Excel: `SLN(...)`.
|
|
23
|
+
*
|
|
24
|
+
* @hidden
|
|
25
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
26
|
+
* @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```ts
|
|
30
|
+
* engine.computeFormula('=SLN(1)');
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
ComputeSLN(...args: string[]): string | number;
|
|
34
|
+
/**
|
|
35
|
+
* Returns the sum-of-years digits depreciation for a specified period.
|
|
36
|
+
*
|
|
37
|
+
* Excel: `SYD(...)`.
|
|
38
|
+
*
|
|
39
|
+
* @hidden
|
|
40
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
41
|
+
* @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
|
|
42
|
+
*/
|
|
43
|
+
ComputeSYD(...args: string[]): string | number;
|
|
44
|
+
/**
|
|
45
|
+
* Returns the depreciation of an asset for a period using fixed-declining balance.
|
|
46
|
+
*
|
|
47
|
+
* Excel: `DB(...)`.
|
|
48
|
+
*
|
|
49
|
+
* @hidden
|
|
50
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
51
|
+
* @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
|
|
52
|
+
*/
|
|
53
|
+
ComputeDB(...args: string[]): string | number;
|
|
54
|
+
/**
|
|
55
|
+
* Returns the depreciation of an asset for a period using double-declining balance.
|
|
56
|
+
*
|
|
57
|
+
* Excel: `DDB(...)`.
|
|
58
|
+
*
|
|
59
|
+
* @hidden
|
|
60
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
61
|
+
* @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
|
|
62
|
+
*/
|
|
63
|
+
ComputeDDB(...args: string[]): string | number;
|
|
64
|
+
}
|
|
@@ -0,0 +1,247 @@
|
|
|
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
|
+
* Asset depreciation schedules including straight-line, declining-balance, and SYD methods.
|
|
19
|
+
*
|
|
20
|
+
* Registered functions: SLN, SYD, DB, DDB.
|
|
21
|
+
*
|
|
22
|
+
* @hidden
|
|
23
|
+
*/
|
|
24
|
+
var FinancialDepreciationFormulas = /** @class */ (function (_super) {
|
|
25
|
+
__extends(FinancialDepreciationFormulas, _super);
|
|
26
|
+
/**
|
|
27
|
+
* @hidden
|
|
28
|
+
* @param {FormulaOwner} owner - Formula registration owner ({@link BasicFormulas}).
|
|
29
|
+
*/
|
|
30
|
+
function FinancialDepreciationFormulas(owner) {
|
|
31
|
+
var _this = _super.call(this, owner) || this;
|
|
32
|
+
/** Formula definitions registered with {@link BasicFormulas}. */
|
|
33
|
+
_this.formulas = [
|
|
34
|
+
{ formulaName: 'SLN', category: 'Financial', description: 'Returns the straight-line depreciation of an asset for one period.' },
|
|
35
|
+
{ formulaName: 'SYD', category: 'Financial', description: 'Returns the sum-of-years digits depreciation for a specified period.' },
|
|
36
|
+
{ formulaName: 'DB', category: 'Financial', description: 'Returns the depreciation of an asset for a period using fixed-declining balance.' },
|
|
37
|
+
{ formulaName: 'DDB', category: 'Financial', description: 'Returns the depreciation of an asset for a period using double-declining balance.' }
|
|
38
|
+
];
|
|
39
|
+
return _this;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Returns the straight-line depreciation of an asset for one period.
|
|
43
|
+
*
|
|
44
|
+
* Excel: `SLN(...)`.
|
|
45
|
+
*
|
|
46
|
+
* @hidden
|
|
47
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
48
|
+
* @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* ```ts
|
|
52
|
+
* engine.computeFormula('=SLN(1)');
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
55
|
+
FinancialDepreciationFormulas.prototype.ComputeSLN = function () {
|
|
56
|
+
var args = [];
|
|
57
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
58
|
+
args[_i] = arguments[_i];
|
|
59
|
+
}
|
|
60
|
+
var errCollection = this.parent.getErrorStrings();
|
|
61
|
+
if (isNullOrUndefined(args) || args.length !== 3) {
|
|
62
|
+
return this.parent.formulaErrorStrings[FormulasErrorsStrings.WrongNumberArguments];
|
|
63
|
+
}
|
|
64
|
+
var cost = this.resolveNumberArg(args[0]);
|
|
65
|
+
var salvage = this.resolveNumberArg(args[1]);
|
|
66
|
+
var life = this.resolveNumberArg(args[2]);
|
|
67
|
+
if (typeof cost === 'string') {
|
|
68
|
+
return cost;
|
|
69
|
+
}
|
|
70
|
+
if (typeof salvage === 'string') {
|
|
71
|
+
return salvage;
|
|
72
|
+
}
|
|
73
|
+
if (typeof life === 'string') {
|
|
74
|
+
return life;
|
|
75
|
+
}
|
|
76
|
+
if (life === 0) {
|
|
77
|
+
return errCollection[CommonErrors.DivZero];
|
|
78
|
+
}
|
|
79
|
+
return ((cost - salvage) / life).toString();
|
|
80
|
+
};
|
|
81
|
+
/**
|
|
82
|
+
* Returns the sum-of-years digits depreciation for a specified period.
|
|
83
|
+
*
|
|
84
|
+
* Excel: `SYD(...)`.
|
|
85
|
+
*
|
|
86
|
+
* @hidden
|
|
87
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
88
|
+
* @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
|
|
89
|
+
*/
|
|
90
|
+
FinancialDepreciationFormulas.prototype.ComputeSYD = function () {
|
|
91
|
+
var args = [];
|
|
92
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
93
|
+
args[_i] = arguments[_i];
|
|
94
|
+
}
|
|
95
|
+
var errCollection = this.parent.getErrorStrings();
|
|
96
|
+
if (isNullOrUndefined(args) || args.length !== 4) {
|
|
97
|
+
return this.parent.formulaErrorStrings[FormulasErrorsStrings.WrongNumberArguments];
|
|
98
|
+
}
|
|
99
|
+
var cost = this.resolveNumberArg(args[0]);
|
|
100
|
+
var salvage = this.resolveNumberArg(args[1]);
|
|
101
|
+
var life = this.resolveNumberArg(args[2]);
|
|
102
|
+
var per = this.resolveNumberArg(args[3]);
|
|
103
|
+
if (typeof cost === 'string') {
|
|
104
|
+
return cost;
|
|
105
|
+
}
|
|
106
|
+
if (typeof salvage === 'string') {
|
|
107
|
+
return salvage;
|
|
108
|
+
}
|
|
109
|
+
if (typeof life === 'string') {
|
|
110
|
+
return life;
|
|
111
|
+
}
|
|
112
|
+
if (typeof per === 'string') {
|
|
113
|
+
return per;
|
|
114
|
+
}
|
|
115
|
+
if (life <= 0 || per <= 0 || per > life) {
|
|
116
|
+
return errCollection[CommonErrors.Num];
|
|
117
|
+
}
|
|
118
|
+
var sumYears = life * (life + 1) / 2;
|
|
119
|
+
var depreciation = (cost - salvage) * (life - per + 1) / sumYears;
|
|
120
|
+
return depreciation.toString();
|
|
121
|
+
};
|
|
122
|
+
/**
|
|
123
|
+
* Returns the depreciation of an asset for a period using fixed-declining balance.
|
|
124
|
+
*
|
|
125
|
+
* Excel: `DB(...)`.
|
|
126
|
+
*
|
|
127
|
+
* @hidden
|
|
128
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
129
|
+
* @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
|
|
130
|
+
*/
|
|
131
|
+
FinancialDepreciationFormulas.prototype.ComputeDB = function () {
|
|
132
|
+
var args = [];
|
|
133
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
134
|
+
args[_i] = arguments[_i];
|
|
135
|
+
}
|
|
136
|
+
var errCollection = this.parent.getErrorStrings();
|
|
137
|
+
if (isNullOrUndefined(args) || args.length < 4 || args.length > 5) {
|
|
138
|
+
return this.parent.formulaErrorStrings[FormulasErrorsStrings.WrongNumberArguments];
|
|
139
|
+
}
|
|
140
|
+
var cost = this.resolveNumberArg(args[0]);
|
|
141
|
+
var salvage = this.resolveNumberArg(args[1]);
|
|
142
|
+
var life = this.resolveNumberArg(args[2]);
|
|
143
|
+
var period = this.resolveNumberArg(args[3]);
|
|
144
|
+
if (typeof cost === 'string') {
|
|
145
|
+
return cost;
|
|
146
|
+
}
|
|
147
|
+
if (typeof salvage === 'string') {
|
|
148
|
+
return salvage;
|
|
149
|
+
}
|
|
150
|
+
if (typeof life === 'string') {
|
|
151
|
+
return life;
|
|
152
|
+
}
|
|
153
|
+
if (typeof period === 'string') {
|
|
154
|
+
return period;
|
|
155
|
+
}
|
|
156
|
+
var month = 12;
|
|
157
|
+
if (args.length === 5) {
|
|
158
|
+
var m = this.resolveNumberArg(args[4]);
|
|
159
|
+
if (typeof m === 'string') {
|
|
160
|
+
return m;
|
|
161
|
+
}
|
|
162
|
+
month = Math.floor(m);
|
|
163
|
+
}
|
|
164
|
+
if (life <= 0 || period <= 0) {
|
|
165
|
+
return errCollection[CommonErrors.Num];
|
|
166
|
+
}
|
|
167
|
+
var rate = 1 - Math.pow(salvage / cost, 1 / life);
|
|
168
|
+
var totalDep = 0;
|
|
169
|
+
for (var p = 1; p <= Math.floor(period); p++) {
|
|
170
|
+
var dep = (cost - totalDep) * rate * (p === 1 ? month / 12 : 1);
|
|
171
|
+
totalDep += dep;
|
|
172
|
+
}
|
|
173
|
+
var frac = period - Math.floor(period);
|
|
174
|
+
if (frac > 0) {
|
|
175
|
+
totalDep += (cost - totalDep) * rate * frac;
|
|
176
|
+
}
|
|
177
|
+
if (Math.floor(period) === 1) {
|
|
178
|
+
return (totalDep).toString();
|
|
179
|
+
}
|
|
180
|
+
var prev = 0;
|
|
181
|
+
for (var p = 1; p < Math.floor(period); p++) {
|
|
182
|
+
var dep = (cost - prev) * rate * (p === 1 ? month / 12 : 1);
|
|
183
|
+
prev += dep;
|
|
184
|
+
}
|
|
185
|
+
return (totalDep - prev).toString();
|
|
186
|
+
};
|
|
187
|
+
/**
|
|
188
|
+
* Returns the depreciation of an asset for a period using double-declining balance.
|
|
189
|
+
*
|
|
190
|
+
* Excel: `DDB(...)`.
|
|
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
|
+
FinancialDepreciationFormulas.prototype.ComputeDDB = function () {
|
|
197
|
+
var args = [];
|
|
198
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
199
|
+
args[_i] = arguments[_i];
|
|
200
|
+
}
|
|
201
|
+
var errCollection = this.parent.getErrorStrings();
|
|
202
|
+
if (isNullOrUndefined(args) || args.length < 4 || args.length > 5) {
|
|
203
|
+
return this.parent.formulaErrorStrings[FormulasErrorsStrings.WrongNumberArguments];
|
|
204
|
+
}
|
|
205
|
+
var cost = this.resolveNumberArg(args[0]);
|
|
206
|
+
var salvage = this.resolveNumberArg(args[1]);
|
|
207
|
+
var life = this.resolveNumberArg(args[2]);
|
|
208
|
+
var period = this.resolveNumberArg(args[3]);
|
|
209
|
+
if (typeof cost === 'string') {
|
|
210
|
+
return cost;
|
|
211
|
+
}
|
|
212
|
+
if (typeof salvage === 'string') {
|
|
213
|
+
return salvage;
|
|
214
|
+
}
|
|
215
|
+
if (typeof life === 'string') {
|
|
216
|
+
return life;
|
|
217
|
+
}
|
|
218
|
+
if (typeof period === 'string') {
|
|
219
|
+
return period;
|
|
220
|
+
}
|
|
221
|
+
var factor = 2;
|
|
222
|
+
if (args.length === 5) {
|
|
223
|
+
var f = this.resolveNumberArg(args[4]);
|
|
224
|
+
if (typeof f === 'string') {
|
|
225
|
+
return f;
|
|
226
|
+
}
|
|
227
|
+
factor = f;
|
|
228
|
+
}
|
|
229
|
+
if (life <= 0 || period <= 0) {
|
|
230
|
+
return errCollection[CommonErrors.Num];
|
|
231
|
+
}
|
|
232
|
+
var rate = factor / life;
|
|
233
|
+
var book = cost;
|
|
234
|
+
var dep = 0;
|
|
235
|
+
for (var p = 1; p <= Math.floor(period); p++) {
|
|
236
|
+
dep = Math.min(book * rate, book - salvage);
|
|
237
|
+
book -= dep;
|
|
238
|
+
}
|
|
239
|
+
var frac = period - Math.floor(period);
|
|
240
|
+
if (frac > 0) {
|
|
241
|
+
dep = Math.min(book * rate * frac, (book - salvage) * frac);
|
|
242
|
+
}
|
|
243
|
+
return dep.toString();
|
|
244
|
+
};
|
|
245
|
+
return FinancialDepreciationFormulas;
|
|
246
|
+
}(FormulaModuleBase));
|
|
247
|
+
export { FinancialDepreciationFormulas };
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { IBasicFormula } from '../common/index';
|
|
2
|
+
import { FormulaOwner } from './formula-owner';
|
|
3
|
+
import { FormulaModuleBase } from './formula-module-base';
|
|
4
|
+
/**
|
|
5
|
+
* Interest rate and yield conversions between nominal, effective, and periodic rates.
|
|
6
|
+
*
|
|
7
|
+
* Registered functions: EFFECT, NOMINAL, FVSCHEDULE.
|
|
8
|
+
*
|
|
9
|
+
* @hidden
|
|
10
|
+
*/
|
|
11
|
+
export declare class FinancialRatesFormulas 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
|
+
/**
|
|
20
|
+
* Returns the effective annual interest rate.
|
|
21
|
+
*
|
|
22
|
+
* Excel: `EFFECT(...)`.
|
|
23
|
+
*
|
|
24
|
+
* @hidden
|
|
25
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
26
|
+
* @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```ts
|
|
30
|
+
* engine.computeFormula('=EFFECT(1)');
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
ComputeEFFECT(...args: string[]): string | number;
|
|
34
|
+
/**
|
|
35
|
+
* Returns the nominal annual interest rate.
|
|
36
|
+
*
|
|
37
|
+
* Excel: `NOMINAL(...)`.
|
|
38
|
+
*
|
|
39
|
+
* @hidden
|
|
40
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
41
|
+
* @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
|
|
42
|
+
*/
|
|
43
|
+
ComputeNOMINAL(...args: string[]): string | number;
|
|
44
|
+
/**
|
|
45
|
+
* Returns the future value of an initial principal after applying compound interest rates.
|
|
46
|
+
*
|
|
47
|
+
* Excel: `FVSCHEDULE(...)`.
|
|
48
|
+
*
|
|
49
|
+
* @hidden
|
|
50
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
51
|
+
* @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
|
|
52
|
+
*/
|
|
53
|
+
ComputeFVSCHEDULE(...args: string[]): string | number;
|
|
54
|
+
}
|
|
@@ -0,0 +1,140 @@
|
|
|
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
|
+
* Interest rate and yield conversions between nominal, effective, and periodic rates.
|
|
19
|
+
*
|
|
20
|
+
* Registered functions: EFFECT, NOMINAL, FVSCHEDULE.
|
|
21
|
+
*
|
|
22
|
+
* @hidden
|
|
23
|
+
*/
|
|
24
|
+
var FinancialRatesFormulas = /** @class */ (function (_super) {
|
|
25
|
+
__extends(FinancialRatesFormulas, _super);
|
|
26
|
+
/**
|
|
27
|
+
* @hidden
|
|
28
|
+
* @param {FormulaOwner} owner - Formula registration owner ({@link BasicFormulas}).
|
|
29
|
+
*/
|
|
30
|
+
function FinancialRatesFormulas(owner) {
|
|
31
|
+
var _this = _super.call(this, owner) || this;
|
|
32
|
+
/** Formula definitions registered with {@link BasicFormulas}. */
|
|
33
|
+
_this.formulas = [
|
|
34
|
+
{ formulaName: 'EFFECT', category: 'Financial', description: 'Returns the effective annual interest rate.' },
|
|
35
|
+
{ formulaName: 'NOMINAL', category: 'Financial', description: 'Returns the nominal annual interest rate.' },
|
|
36
|
+
{ formulaName: 'FVSCHEDULE', category: 'Financial', description: 'Returns the future value of an initial principal after applying compound interest rates.' }
|
|
37
|
+
];
|
|
38
|
+
return _this;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Returns the effective annual interest rate.
|
|
42
|
+
*
|
|
43
|
+
* Excel: `EFFECT(...)`.
|
|
44
|
+
*
|
|
45
|
+
* @hidden
|
|
46
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
47
|
+
* @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* ```ts
|
|
51
|
+
* engine.computeFormula('=EFFECT(1)');
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
FinancialRatesFormulas.prototype.ComputeEFFECT = function () {
|
|
55
|
+
var args = [];
|
|
56
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
57
|
+
args[_i] = arguments[_i];
|
|
58
|
+
}
|
|
59
|
+
var errCollection = this.parent.getErrorStrings();
|
|
60
|
+
if (isNullOrUndefined(args) || args.length !== 2) {
|
|
61
|
+
return this.parent.formulaErrorStrings[FormulasErrorsStrings.WrongNumberArguments];
|
|
62
|
+
}
|
|
63
|
+
var nominal = this.resolveNumberArg(args[0]);
|
|
64
|
+
var npery = this.resolveNumberArg(args[1]);
|
|
65
|
+
if (typeof nominal === 'string') {
|
|
66
|
+
return nominal;
|
|
67
|
+
}
|
|
68
|
+
if (typeof npery === 'string') {
|
|
69
|
+
return npery;
|
|
70
|
+
}
|
|
71
|
+
if (npery < 1) {
|
|
72
|
+
return errCollection[CommonErrors.Num];
|
|
73
|
+
}
|
|
74
|
+
return (Math.pow(1 + nominal / npery, npery) - 1).toString();
|
|
75
|
+
};
|
|
76
|
+
/**
|
|
77
|
+
* Returns the nominal annual interest rate.
|
|
78
|
+
*
|
|
79
|
+
* Excel: `NOMINAL(...)`.
|
|
80
|
+
*
|
|
81
|
+
* @hidden
|
|
82
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
83
|
+
* @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
|
|
84
|
+
*/
|
|
85
|
+
FinancialRatesFormulas.prototype.ComputeNOMINAL = function () {
|
|
86
|
+
var args = [];
|
|
87
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
88
|
+
args[_i] = arguments[_i];
|
|
89
|
+
}
|
|
90
|
+
var errCollection = this.parent.getErrorStrings();
|
|
91
|
+
if (isNullOrUndefined(args) || args.length !== 2) {
|
|
92
|
+
return this.parent.formulaErrorStrings[FormulasErrorsStrings.WrongNumberArguments];
|
|
93
|
+
}
|
|
94
|
+
var effect = this.resolveNumberArg(args[0]);
|
|
95
|
+
var npery = this.resolveNumberArg(args[1]);
|
|
96
|
+
if (typeof effect === 'string') {
|
|
97
|
+
return effect;
|
|
98
|
+
}
|
|
99
|
+
if (typeof npery === 'string') {
|
|
100
|
+
return npery;
|
|
101
|
+
}
|
|
102
|
+
if (npery < 1) {
|
|
103
|
+
return errCollection[CommonErrors.Num];
|
|
104
|
+
}
|
|
105
|
+
return (npery * (Math.pow(1 + effect, 1 / npery) - 1)).toString();
|
|
106
|
+
};
|
|
107
|
+
/**
|
|
108
|
+
* Returns the future value of an initial principal after applying compound interest rates.
|
|
109
|
+
*
|
|
110
|
+
* Excel: `FVSCHEDULE(...)`.
|
|
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
|
+
FinancialRatesFormulas.prototype.ComputeFVSCHEDULE = function () {
|
|
117
|
+
var args = [];
|
|
118
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
119
|
+
args[_i] = arguments[_i];
|
|
120
|
+
}
|
|
121
|
+
if (isNullOrUndefined(args) || args.length < 2) {
|
|
122
|
+
return this.parent.formulaErrorStrings[FormulasErrorsStrings.WrongNumberArguments];
|
|
123
|
+
}
|
|
124
|
+
var principal = this.resolveNumberArg(args[0]);
|
|
125
|
+
if (typeof principal === 'string') {
|
|
126
|
+
return principal;
|
|
127
|
+
}
|
|
128
|
+
var fv = principal;
|
|
129
|
+
for (var i = 1; i < args.length; i++) {
|
|
130
|
+
var rate = this.resolveNumberArg(args[i]);
|
|
131
|
+
if (typeof rate === 'string') {
|
|
132
|
+
return rate;
|
|
133
|
+
}
|
|
134
|
+
fv *= 1 + rate;
|
|
135
|
+
}
|
|
136
|
+
return fv.toString();
|
|
137
|
+
};
|
|
138
|
+
return FinancialRatesFormulas;
|
|
139
|
+
}(FormulaModuleBase));
|
|
140
|
+
export { FinancialRatesFormulas };
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { IBasicFormula } from '../common/index';
|
|
2
|
+
import { FormulaOwner } from './formula-owner';
|
|
3
|
+
import { FormulaModuleBase } from './formula-module-base';
|
|
4
|
+
/**
|
|
5
|
+
* Fixed-income security pricing, yield, duration, and accrued interest calculations.
|
|
6
|
+
*
|
|
7
|
+
* Registers 10 functions including DOLLARDE, DOLLARFR, DISC, DURATION, INTRATE, and others.
|
|
8
|
+
*
|
|
9
|
+
* @hidden
|
|
10
|
+
*/
|
|
11
|
+
export declare class FinancialSecuritiesFormulas 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
|
+
/**
|
|
20
|
+
* Converts a dollar price expressed as a fraction into a decimal number.
|
|
21
|
+
*
|
|
22
|
+
* Excel: `DOLLARDE(...)`.
|
|
23
|
+
*
|
|
24
|
+
* @hidden
|
|
25
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
26
|
+
* @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```ts
|
|
30
|
+
* engine.computeFormula('=DOLLARDE(1)');
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
ComputeDOLLARDE(...args: string[]): string | number;
|
|
34
|
+
/**
|
|
35
|
+
* Converts a dollar price expressed as a decimal number into a fraction.
|
|
36
|
+
*
|
|
37
|
+
* Excel: `DOLLARFR(...)`.
|
|
38
|
+
*
|
|
39
|
+
* @hidden
|
|
40
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
41
|
+
* @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
|
|
42
|
+
*/
|
|
43
|
+
ComputeDOLLARFR(...args: string[]): string | number;
|
|
44
|
+
/**
|
|
45
|
+
* Returns the discount rate for a security.
|
|
46
|
+
*
|
|
47
|
+
* Excel: `DISC(...)`.
|
|
48
|
+
*
|
|
49
|
+
* @hidden
|
|
50
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
51
|
+
* @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
|
|
52
|
+
*/
|
|
53
|
+
ComputeDISC(...args: string[]): string | number;
|
|
54
|
+
/**
|
|
55
|
+
* Returns the annual duration of a security with periodic interest payments.
|
|
56
|
+
*
|
|
57
|
+
* Excel: `DURATION(...)`.
|
|
58
|
+
*
|
|
59
|
+
* @hidden
|
|
60
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
61
|
+
* @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
|
|
62
|
+
*/
|
|
63
|
+
ComputeDURATION(...args: string[]): string | number;
|
|
64
|
+
/**
|
|
65
|
+
* Returns the interest rate for a fully invested security.
|
|
66
|
+
*
|
|
67
|
+
* Excel: `INTRATE(...)`.
|
|
68
|
+
*
|
|
69
|
+
* @hidden
|
|
70
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
71
|
+
* @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
|
|
72
|
+
*/
|
|
73
|
+
ComputeINTRATE(...args: string[]): string | number;
|
|
74
|
+
/**
|
|
75
|
+
* Returns the amount received at maturity for a fully invested security.
|
|
76
|
+
*
|
|
77
|
+
* Excel: `RECEIVED(...)`.
|
|
78
|
+
*
|
|
79
|
+
* @hidden
|
|
80
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
81
|
+
* @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
|
|
82
|
+
*/
|
|
83
|
+
ComputeRECEIVED(...args: string[]): string | number;
|
|
84
|
+
/**
|
|
85
|
+
* Returns the cumulative interest paid between two periods.
|
|
86
|
+
*
|
|
87
|
+
* Excel: `CUMIPMT(...)`.
|
|
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
|
+
ComputeCUMIPMT(...args: string[]): string | number;
|
|
94
|
+
/**
|
|
95
|
+
* Returns the cumulative principal paid on a loan between two periods.
|
|
96
|
+
*
|
|
97
|
+
* Excel: `CUMPRINC(...)`.
|
|
98
|
+
*
|
|
99
|
+
* @hidden
|
|
100
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
101
|
+
* @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
|
|
102
|
+
*/
|
|
103
|
+
ComputeCUMPRINC(...args: string[]): string | number;
|
|
104
|
+
private cumIpmtPrinc;
|
|
105
|
+
private computePmt;
|
|
106
|
+
/**
|
|
107
|
+
* Returns the depreciation of an asset for a period using the declining balance method.
|
|
108
|
+
*
|
|
109
|
+
* Excel: `VDB(...)`.
|
|
110
|
+
*
|
|
111
|
+
* @hidden
|
|
112
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
113
|
+
* @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
|
|
114
|
+
*/
|
|
115
|
+
ComputeVDB(...args: string[]): string | number;
|
|
116
|
+
/**
|
|
117
|
+
* Returns the internal rate of return for a schedule of cash flows that is not necessarily periodic.
|
|
118
|
+
*
|
|
119
|
+
* Excel: `XIRR(...)`.
|
|
120
|
+
*
|
|
121
|
+
* @hidden
|
|
122
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
123
|
+
* @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
|
|
124
|
+
*/
|
|
125
|
+
ComputeXIRR(...args: string[]): string | number;
|
|
126
|
+
}
|