@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,810 @@
|
|
|
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
|
+
import { FinancialBondHelpers } from './financial-bond-helpers';
|
|
18
|
+
/**
|
|
19
|
+
* Bond coupon payment schedules, accrued interest, and coupon-period date boundaries.
|
|
20
|
+
*
|
|
21
|
+
* Registers 20 functions including COUPDAYBS, COUPDAYS, COUPDAYSNC, COUPNCD, COUPNUM, and others.
|
|
22
|
+
*
|
|
23
|
+
* @hidden
|
|
24
|
+
*/
|
|
25
|
+
var FinancialCouponsFormulas = /** @class */ (function (_super) {
|
|
26
|
+
__extends(FinancialCouponsFormulas, _super);
|
|
27
|
+
/**
|
|
28
|
+
* @hidden
|
|
29
|
+
* @param {FormulaOwner} owner - Formula registration owner ({@link BasicFormulas}).
|
|
30
|
+
*/
|
|
31
|
+
function FinancialCouponsFormulas(owner) {
|
|
32
|
+
var _this = _super.call(this, owner) || this;
|
|
33
|
+
/** Formula definitions registered with {@link BasicFormulas}. */
|
|
34
|
+
_this.formulas = [
|
|
35
|
+
{ formulaName: 'COUPDAYBS', category: 'Financial', description: 'Returns the number of days from the beginning of the coupon period to the settlement date.' },
|
|
36
|
+
{ formulaName: 'COUPDAYS', category: 'Financial', description: 'Returns the number of days in the coupon period that contains the settlement date.' },
|
|
37
|
+
{ formulaName: 'COUPDAYSNC', category: 'Financial', description: 'Returns the number of days from the settlement date to the next coupon date.' },
|
|
38
|
+
{ formulaName: 'COUPNCD', category: 'Financial', description: 'Returns the next coupon date after the settlement date.' },
|
|
39
|
+
{ formulaName: 'COUPNUM', category: 'Financial', description: 'Returns the number of coupons payable between settlement and maturity.' },
|
|
40
|
+
{ formulaName: 'COUPPCD', category: 'Financial', description: 'Returns the previous coupon date before the settlement date.' },
|
|
41
|
+
{ formulaName: 'ACCRINT', category: 'Financial', description: 'Returns the accrued interest for a security that pays periodic interest.' },
|
|
42
|
+
{ formulaName: 'ACCRINTM', category: 'Financial', description: 'Returns the accrued interest for a security that pays interest at maturity.' },
|
|
43
|
+
{ formulaName: 'ISPMT', category: 'Financial', description: 'Returns the interest paid during a specific period of an investment.' },
|
|
44
|
+
{ formulaName: 'MDURATION', category: 'Financial', description: 'Returns the modified Macauley duration for a security with an assumed par value of $100.' },
|
|
45
|
+
{ formulaName: 'PRICE', category: 'Financial', description: 'Returns the price per $100 face value of a security that pays periodic interest.' },
|
|
46
|
+
{ formulaName: 'PRICEDISC', category: 'Financial', description: 'Returns the price per $100 face value of a discounted security.' },
|
|
47
|
+
{ formulaName: 'PRICEMAT', category: 'Financial', description: 'Returns the price per $100 face value of a security that pays interest at maturity.' },
|
|
48
|
+
{ formulaName: 'TBILLEQ', category: 'Financial', description: 'Returns the bond-equivalent yield for a Treasury bill.' },
|
|
49
|
+
{ formulaName: 'TBILLPRICE', category: 'Financial', description: 'Returns the price per $100 face value for a Treasury bill.' },
|
|
50
|
+
{ formulaName: 'TBILLYIELD', category: 'Financial', description: 'Returns the yield for a Treasury bill.' },
|
|
51
|
+
{ formulaName: 'XNPV', category: 'Financial', description: 'Returns the net present value for a schedule of cash flows that is not necessarily periodic.' },
|
|
52
|
+
{ formulaName: 'YIELD', category: 'Financial', description: 'Returns the yield on a security that pays periodic interest.' },
|
|
53
|
+
{ formulaName: 'YIELDDISC', category: 'Financial', description: 'Returns the annual yield for a discounted security.' },
|
|
54
|
+
{ formulaName: 'YIELDMAT', category: 'Financial', description: 'Returns the annual yield of a security that pays interest at maturity.' }
|
|
55
|
+
];
|
|
56
|
+
_this.bond = new FinancialBondHelpers(_this.parent);
|
|
57
|
+
return _this;
|
|
58
|
+
}
|
|
59
|
+
FinancialCouponsFormulas.prototype.parseBondArgs = function (args, minLen, maxLen) {
|
|
60
|
+
if (isNullOrUndefined(args) || args.length < minLen || args.length > maxLen) {
|
|
61
|
+
return this.parent.formulaErrorStrings[FormulasErrorsStrings.WrongNumberArguments];
|
|
62
|
+
}
|
|
63
|
+
var settlement = this.resolveNumberArg(args[0]);
|
|
64
|
+
var maturity = this.resolveNumberArg(args[1]);
|
|
65
|
+
if (typeof settlement === 'string') {
|
|
66
|
+
return settlement;
|
|
67
|
+
}
|
|
68
|
+
if (typeof maturity === 'string') {
|
|
69
|
+
return maturity;
|
|
70
|
+
}
|
|
71
|
+
var result = { settlement: settlement, maturity: maturity };
|
|
72
|
+
if (args.length >= 3) {
|
|
73
|
+
var rate = this.resolveNumberArg(args[2]);
|
|
74
|
+
if (typeof rate === 'string') {
|
|
75
|
+
return rate;
|
|
76
|
+
}
|
|
77
|
+
result.rate = rate;
|
|
78
|
+
}
|
|
79
|
+
if (args.length >= 4) {
|
|
80
|
+
var yld = this.resolveNumberArg(args[3]);
|
|
81
|
+
if (typeof yld === 'string') {
|
|
82
|
+
return yld;
|
|
83
|
+
}
|
|
84
|
+
result.yld = yld;
|
|
85
|
+
}
|
|
86
|
+
if (args.length >= 5) {
|
|
87
|
+
var red = this.resolveNumberArg(args[4]);
|
|
88
|
+
if (typeof red === 'string') {
|
|
89
|
+
return red;
|
|
90
|
+
}
|
|
91
|
+
result.redemption = red;
|
|
92
|
+
}
|
|
93
|
+
result.frequency = args.length >= 6 && args[5] !== '' ? this.resolveNumberArg(args[5]) : 2;
|
|
94
|
+
if (typeof result.frequency === 'string') {
|
|
95
|
+
return result.frequency;
|
|
96
|
+
}
|
|
97
|
+
result.basis = args.length >= 7 && args[6] !== '' ? this.resolveNumberArg(args[6]) : 0;
|
|
98
|
+
if (typeof result.basis === 'string') {
|
|
99
|
+
return result.basis;
|
|
100
|
+
}
|
|
101
|
+
return result;
|
|
102
|
+
};
|
|
103
|
+
FinancialCouponsFormulas.prototype.coupArgs = function (args) {
|
|
104
|
+
if (isNullOrUndefined(args) || args.length < 3 || args.length > 4) {
|
|
105
|
+
return this.parent.formulaErrorStrings[FormulasErrorsStrings.WrongNumberArguments];
|
|
106
|
+
}
|
|
107
|
+
var settlement = this.resolveNumberArg(args[0]);
|
|
108
|
+
var maturity = this.resolveNumberArg(args[1]);
|
|
109
|
+
var frequency = this.resolveNumberArg(args[2]);
|
|
110
|
+
if (typeof settlement === 'string') {
|
|
111
|
+
return settlement;
|
|
112
|
+
}
|
|
113
|
+
if (typeof maturity === 'string') {
|
|
114
|
+
return maturity;
|
|
115
|
+
}
|
|
116
|
+
if (typeof frequency === 'string') {
|
|
117
|
+
return frequency;
|
|
118
|
+
}
|
|
119
|
+
var basis = 0;
|
|
120
|
+
if (args.length === 4 && args[3] !== '') {
|
|
121
|
+
var b = this.resolveNumberArg(args[3]);
|
|
122
|
+
if (typeof b === 'string') {
|
|
123
|
+
return b;
|
|
124
|
+
}
|
|
125
|
+
basis = Math.floor(b);
|
|
126
|
+
}
|
|
127
|
+
return { settlement: settlement, maturity: maturity, frequency: Math.floor(frequency), basis: basis };
|
|
128
|
+
};
|
|
129
|
+
/**
|
|
130
|
+
* Returns the number of days from the beginning of the coupon period to the settlement date.
|
|
131
|
+
*
|
|
132
|
+
* Excel: `COUPDAYBS(...)`.
|
|
133
|
+
*
|
|
134
|
+
* @hidden
|
|
135
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
136
|
+
* @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
|
|
137
|
+
*
|
|
138
|
+
* @example
|
|
139
|
+
* ```ts
|
|
140
|
+
* engine.computeFormula('=COUPDAYBS(1)');
|
|
141
|
+
* ```
|
|
142
|
+
*/
|
|
143
|
+
FinancialCouponsFormulas.prototype.ComputeCOUPDAYBS = function () {
|
|
144
|
+
var args = [];
|
|
145
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
146
|
+
args[_i] = arguments[_i];
|
|
147
|
+
}
|
|
148
|
+
var parsed = this.coupArgs(args);
|
|
149
|
+
if (typeof parsed === 'string') {
|
|
150
|
+
return parsed;
|
|
151
|
+
}
|
|
152
|
+
return this.bond.coupDayBS(parsed.settlement, parsed.maturity, parsed.frequency, parsed.basis).toString();
|
|
153
|
+
};
|
|
154
|
+
/**
|
|
155
|
+
* Returns the number of days in the coupon period that contains the settlement date.
|
|
156
|
+
*
|
|
157
|
+
* Excel: `COUPDAYS(...)`.
|
|
158
|
+
*
|
|
159
|
+
* @hidden
|
|
160
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
161
|
+
* @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
|
|
162
|
+
*/
|
|
163
|
+
FinancialCouponsFormulas.prototype.ComputeCOUPDAYS = function () {
|
|
164
|
+
var args = [];
|
|
165
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
166
|
+
args[_i] = arguments[_i];
|
|
167
|
+
}
|
|
168
|
+
var parsed = this.coupArgs(args);
|
|
169
|
+
if (typeof parsed === 'string') {
|
|
170
|
+
return parsed;
|
|
171
|
+
}
|
|
172
|
+
return this.bond.coupDays(parsed.settlement, parsed.maturity, parsed.frequency, parsed.basis).toString();
|
|
173
|
+
};
|
|
174
|
+
/**
|
|
175
|
+
* Returns the number of days from the settlement date to the next coupon date.
|
|
176
|
+
*
|
|
177
|
+
* Excel: `COUPDAYSNC(...)`.
|
|
178
|
+
*
|
|
179
|
+
* @hidden
|
|
180
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
181
|
+
* @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
|
|
182
|
+
*/
|
|
183
|
+
FinancialCouponsFormulas.prototype.ComputeCOUPDAYSNC = function () {
|
|
184
|
+
var args = [];
|
|
185
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
186
|
+
args[_i] = arguments[_i];
|
|
187
|
+
}
|
|
188
|
+
var parsed = this.coupArgs(args);
|
|
189
|
+
if (typeof parsed === 'string') {
|
|
190
|
+
return parsed;
|
|
191
|
+
}
|
|
192
|
+
return this.bond.coupDaysNC(parsed.settlement, parsed.maturity, parsed.frequency, parsed.basis).toString();
|
|
193
|
+
};
|
|
194
|
+
/**
|
|
195
|
+
* Returns the next coupon date after the settlement date.
|
|
196
|
+
*
|
|
197
|
+
* Excel: `COUPNCD(...)`.
|
|
198
|
+
*
|
|
199
|
+
* @hidden
|
|
200
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
201
|
+
* @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
|
|
202
|
+
*/
|
|
203
|
+
FinancialCouponsFormulas.prototype.ComputeCOUPNCD = function () {
|
|
204
|
+
var args = [];
|
|
205
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
206
|
+
args[_i] = arguments[_i];
|
|
207
|
+
}
|
|
208
|
+
var parsed = this.coupArgs(args);
|
|
209
|
+
if (typeof parsed === 'string') {
|
|
210
|
+
return parsed;
|
|
211
|
+
}
|
|
212
|
+
return this.bond.coupNCD(parsed.settlement, parsed.maturity, parsed.frequency).toString();
|
|
213
|
+
};
|
|
214
|
+
/**
|
|
215
|
+
* Returns the number of coupons payable between settlement and maturity.
|
|
216
|
+
*
|
|
217
|
+
* Excel: `COUPNUM(...)`.
|
|
218
|
+
*
|
|
219
|
+
* @hidden
|
|
220
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
221
|
+
* @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
|
|
222
|
+
*/
|
|
223
|
+
FinancialCouponsFormulas.prototype.ComputeCOUPNUM = function () {
|
|
224
|
+
var args = [];
|
|
225
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
226
|
+
args[_i] = arguments[_i];
|
|
227
|
+
}
|
|
228
|
+
var parsed = this.coupArgs(args);
|
|
229
|
+
if (typeof parsed === 'string') {
|
|
230
|
+
return parsed;
|
|
231
|
+
}
|
|
232
|
+
return this.bond.coupNum(parsed.settlement, parsed.maturity, parsed.frequency, parsed.basis).toString();
|
|
233
|
+
};
|
|
234
|
+
/**
|
|
235
|
+
* Returns the previous coupon date before the settlement date.
|
|
236
|
+
*
|
|
237
|
+
* Excel: `COUPPCD(...)`.
|
|
238
|
+
*
|
|
239
|
+
* @hidden
|
|
240
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
241
|
+
* @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
|
|
242
|
+
*/
|
|
243
|
+
FinancialCouponsFormulas.prototype.ComputeCOUPPCD = function () {
|
|
244
|
+
var args = [];
|
|
245
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
246
|
+
args[_i] = arguments[_i];
|
|
247
|
+
}
|
|
248
|
+
var parsed = this.coupArgs(args);
|
|
249
|
+
if (typeof parsed === 'string') {
|
|
250
|
+
return parsed;
|
|
251
|
+
}
|
|
252
|
+
return this.bond.coupPCD(parsed.settlement, parsed.maturity, parsed.frequency).toString();
|
|
253
|
+
};
|
|
254
|
+
/**
|
|
255
|
+
* Returns the accrued interest for a security that pays periodic interest.
|
|
256
|
+
*
|
|
257
|
+
* Excel: `ACCRINT(...)`.
|
|
258
|
+
*
|
|
259
|
+
* @hidden
|
|
260
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
261
|
+
* @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
|
|
262
|
+
*/
|
|
263
|
+
FinancialCouponsFormulas.prototype.ComputeACCRINT = function () {
|
|
264
|
+
var args = [];
|
|
265
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
266
|
+
args[_i] = arguments[_i];
|
|
267
|
+
}
|
|
268
|
+
var errCollection = this.parent.getErrorStrings();
|
|
269
|
+
var parsed = this.parseBondArgs(args, 6, 8);
|
|
270
|
+
if (typeof parsed === 'string') {
|
|
271
|
+
return parsed;
|
|
272
|
+
}
|
|
273
|
+
var issue = args.length >= 8 ? this.resolveNumberArg(args[7]) : parsed.settlement;
|
|
274
|
+
if (typeof issue === 'string') {
|
|
275
|
+
return issue;
|
|
276
|
+
}
|
|
277
|
+
var rate = parsed.rate;
|
|
278
|
+
var freq = parsed.frequency;
|
|
279
|
+
var basis = parsed.basis;
|
|
280
|
+
var days = this.bond.coupDayBS(parsed.settlement, parsed.maturity, freq, basis);
|
|
281
|
+
var periodDays = this.bond.coupDays(parsed.settlement, parsed.maturity, freq, basis);
|
|
282
|
+
if (periodDays === 0) {
|
|
283
|
+
return errCollection[CommonErrors.Num];
|
|
284
|
+
}
|
|
285
|
+
var par = args.length >= 7 && args[6] !== '' ? this.resolveNumberArg(args[6]) : 1000;
|
|
286
|
+
return (par * rate / freq * days / periodDays).toString();
|
|
287
|
+
};
|
|
288
|
+
/**
|
|
289
|
+
* Returns the accrued interest for a security that pays interest at maturity.
|
|
290
|
+
*
|
|
291
|
+
* Excel: `ACCRINTM(...)`.
|
|
292
|
+
*
|
|
293
|
+
* @hidden
|
|
294
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
295
|
+
* @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
|
|
296
|
+
*/
|
|
297
|
+
FinancialCouponsFormulas.prototype.ComputeACCRINTM = function () {
|
|
298
|
+
var args = [];
|
|
299
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
300
|
+
args[_i] = arguments[_i];
|
|
301
|
+
}
|
|
302
|
+
if (isNullOrUndefined(args) || args.length < 4 || args.length > 5) {
|
|
303
|
+
return this.parent.formulaErrorStrings[FormulasErrorsStrings.WrongNumberArguments];
|
|
304
|
+
}
|
|
305
|
+
var issue = this.resolveNumberArg(args[0]);
|
|
306
|
+
var settlement = this.resolveNumberArg(args[1]);
|
|
307
|
+
var rate = this.resolveNumberArg(args[2]);
|
|
308
|
+
var par = this.resolveNumberArg(args[3]);
|
|
309
|
+
if (typeof issue === 'string') {
|
|
310
|
+
return issue;
|
|
311
|
+
}
|
|
312
|
+
if (typeof settlement === 'string') {
|
|
313
|
+
return settlement;
|
|
314
|
+
}
|
|
315
|
+
if (typeof rate === 'string') {
|
|
316
|
+
return rate;
|
|
317
|
+
}
|
|
318
|
+
if (typeof par === 'string') {
|
|
319
|
+
return par;
|
|
320
|
+
}
|
|
321
|
+
var basis = 0;
|
|
322
|
+
if (args.length === 5 && args[4] !== '') {
|
|
323
|
+
var b = this.resolveNumberArg(args[4]);
|
|
324
|
+
if (typeof b === 'string') {
|
|
325
|
+
return b;
|
|
326
|
+
}
|
|
327
|
+
basis = Math.floor(b);
|
|
328
|
+
}
|
|
329
|
+
var days = this.bond.daysBetween(issue, settlement, basis);
|
|
330
|
+
var yearDays = this.bond.yearDays(basis);
|
|
331
|
+
return (par * rate * days / yearDays).toString();
|
|
332
|
+
};
|
|
333
|
+
/**
|
|
334
|
+
* Returns the interest paid during a specific period of an investment.
|
|
335
|
+
*
|
|
336
|
+
* Excel: `ISPMT(...)`.
|
|
337
|
+
*
|
|
338
|
+
* @hidden
|
|
339
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
340
|
+
* @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
|
|
341
|
+
*/
|
|
342
|
+
FinancialCouponsFormulas.prototype.ComputeISPMT = function () {
|
|
343
|
+
var args = [];
|
|
344
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
345
|
+
args[_i] = arguments[_i];
|
|
346
|
+
}
|
|
347
|
+
var errCollection = this.parent.getErrorStrings();
|
|
348
|
+
if (isNullOrUndefined(args) || args.length !== 4) {
|
|
349
|
+
return this.parent.formulaErrorStrings[FormulasErrorsStrings.WrongNumberArguments];
|
|
350
|
+
}
|
|
351
|
+
var rate = this.resolveNumberArg(args[0]);
|
|
352
|
+
var per = this.resolveNumberArg(args[1]);
|
|
353
|
+
var nper = this.resolveNumberArg(args[2]);
|
|
354
|
+
var pv = this.resolveNumberArg(args[3]);
|
|
355
|
+
if (typeof rate === 'string') {
|
|
356
|
+
return rate;
|
|
357
|
+
}
|
|
358
|
+
if (typeof per === 'string') {
|
|
359
|
+
return per;
|
|
360
|
+
}
|
|
361
|
+
if (typeof nper === 'string') {
|
|
362
|
+
return nper;
|
|
363
|
+
}
|
|
364
|
+
if (typeof pv === 'string') {
|
|
365
|
+
return pv;
|
|
366
|
+
}
|
|
367
|
+
var p = Math.floor(per);
|
|
368
|
+
if (p < 1 || p > nper) {
|
|
369
|
+
return errCollection[CommonErrors.Num];
|
|
370
|
+
}
|
|
371
|
+
return (-pv * rate * (1 - (p - 1) / nper)).toString();
|
|
372
|
+
};
|
|
373
|
+
/**
|
|
374
|
+
* Returns the modified Macauley duration for a security with an assumed par value of $100.
|
|
375
|
+
*
|
|
376
|
+
* Excel: `MDURATION(...)`.
|
|
377
|
+
*
|
|
378
|
+
* @hidden
|
|
379
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
380
|
+
* @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
|
|
381
|
+
*/
|
|
382
|
+
FinancialCouponsFormulas.prototype.ComputeMDURATION = function () {
|
|
383
|
+
var args = [];
|
|
384
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
385
|
+
args[_i] = arguments[_i];
|
|
386
|
+
}
|
|
387
|
+
var parsed = this.parseBondArgs(args, 5, 7);
|
|
388
|
+
if (typeof parsed === 'string') {
|
|
389
|
+
return parsed;
|
|
390
|
+
}
|
|
391
|
+
var freq = parsed.frequency;
|
|
392
|
+
var yld = parsed.yld;
|
|
393
|
+
var duration = 1 / freq;
|
|
394
|
+
return (duration / (1 + yld / freq)).toString();
|
|
395
|
+
};
|
|
396
|
+
/**
|
|
397
|
+
* Returns the price per $100 face value of a security that pays periodic interest.
|
|
398
|
+
*
|
|
399
|
+
* Excel: `PRICE(...)`.
|
|
400
|
+
*
|
|
401
|
+
* @hidden
|
|
402
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
403
|
+
* @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
|
|
404
|
+
*/
|
|
405
|
+
FinancialCouponsFormulas.prototype.ComputePRICE = function () {
|
|
406
|
+
var args = [];
|
|
407
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
408
|
+
args[_i] = arguments[_i];
|
|
409
|
+
}
|
|
410
|
+
var parsed = this.parseBondArgs(args, 6, 7);
|
|
411
|
+
if (typeof parsed === 'string') {
|
|
412
|
+
return parsed;
|
|
413
|
+
}
|
|
414
|
+
var rate = parsed.rate;
|
|
415
|
+
var yld = parsed.yld;
|
|
416
|
+
var redemption = parsed.redemption;
|
|
417
|
+
var freq = parsed.frequency;
|
|
418
|
+
var basis = parsed.basis;
|
|
419
|
+
var n = this.bond.coupNum(parsed.settlement, parsed.maturity, freq, basis);
|
|
420
|
+
var dsc = this.bond.coupDaysNC(parsed.settlement, parsed.maturity, freq, basis);
|
|
421
|
+
var e = this.bond.coupDays(parsed.settlement, parsed.maturity, freq, basis);
|
|
422
|
+
var a = this.bond.coupDayBS(parsed.settlement, parsed.maturity, freq, basis);
|
|
423
|
+
var coupon = 100 * rate / freq;
|
|
424
|
+
var price = redemption / Math.pow(1 + yld / freq, n - 1 + dsc / e);
|
|
425
|
+
for (var k = 1; k <= n; k++) {
|
|
426
|
+
price += coupon / Math.pow(1 + yld / freq, k - 1 + dsc / e);
|
|
427
|
+
}
|
|
428
|
+
price -= coupon * a / e;
|
|
429
|
+
return price.toString();
|
|
430
|
+
};
|
|
431
|
+
/**
|
|
432
|
+
* Returns the price per $100 face value of a discounted security.
|
|
433
|
+
*
|
|
434
|
+
* Excel: `PRICEDISC(...)`.
|
|
435
|
+
*
|
|
436
|
+
* @hidden
|
|
437
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
438
|
+
* @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
|
|
439
|
+
*/
|
|
440
|
+
FinancialCouponsFormulas.prototype.ComputePRICEDISC = function () {
|
|
441
|
+
var args = [];
|
|
442
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
443
|
+
args[_i] = arguments[_i];
|
|
444
|
+
}
|
|
445
|
+
if (isNullOrUndefined(args) || args.length < 4 || args.length > 5) {
|
|
446
|
+
return this.parent.formulaErrorStrings[FormulasErrorsStrings.WrongNumberArguments];
|
|
447
|
+
}
|
|
448
|
+
var settlement = this.resolveNumberArg(args[0]);
|
|
449
|
+
var maturity = this.resolveNumberArg(args[1]);
|
|
450
|
+
var discount = this.resolveNumberArg(args[2]);
|
|
451
|
+
var redemption = this.resolveNumberArg(args[3]);
|
|
452
|
+
if (typeof settlement === 'string') {
|
|
453
|
+
return settlement;
|
|
454
|
+
}
|
|
455
|
+
if (typeof maturity === 'string') {
|
|
456
|
+
return maturity;
|
|
457
|
+
}
|
|
458
|
+
if (typeof discount === 'string') {
|
|
459
|
+
return discount;
|
|
460
|
+
}
|
|
461
|
+
if (typeof redemption === 'string') {
|
|
462
|
+
return redemption;
|
|
463
|
+
}
|
|
464
|
+
var basis = 0;
|
|
465
|
+
if (args.length === 5 && args[4] !== '') {
|
|
466
|
+
var b = this.resolveNumberArg(args[4]);
|
|
467
|
+
if (typeof b === 'string') {
|
|
468
|
+
return b;
|
|
469
|
+
}
|
|
470
|
+
basis = Math.floor(b);
|
|
471
|
+
}
|
|
472
|
+
var days = this.bond.daysBetween(settlement, maturity, basis);
|
|
473
|
+
var yearDays = this.bond.yearDays(basis);
|
|
474
|
+
return (redemption * (1 - discount * days / yearDays)).toString();
|
|
475
|
+
};
|
|
476
|
+
/**
|
|
477
|
+
* Returns the price per $100 face value of a security that pays interest at maturity.
|
|
478
|
+
*
|
|
479
|
+
* Excel: `PRICEMAT(...)`.
|
|
480
|
+
*
|
|
481
|
+
* @hidden
|
|
482
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
483
|
+
* @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
|
|
484
|
+
*/
|
|
485
|
+
FinancialCouponsFormulas.prototype.ComputePRICEMAT = function () {
|
|
486
|
+
var args = [];
|
|
487
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
488
|
+
args[_i] = arguments[_i];
|
|
489
|
+
}
|
|
490
|
+
if (isNullOrUndefined(args) || args.length < 5 || args.length > 6) {
|
|
491
|
+
return this.parent.formulaErrorStrings[FormulasErrorsStrings.WrongNumberArguments];
|
|
492
|
+
}
|
|
493
|
+
var settlement = this.resolveNumberArg(args[0]);
|
|
494
|
+
var maturity = this.resolveNumberArg(args[1]);
|
|
495
|
+
var issue = this.resolveNumberArg(args[2]);
|
|
496
|
+
var rate = this.resolveNumberArg(args[3]);
|
|
497
|
+
var yld = this.resolveNumberArg(args[4]);
|
|
498
|
+
if (typeof settlement === 'string') {
|
|
499
|
+
return settlement;
|
|
500
|
+
}
|
|
501
|
+
if (typeof maturity === 'string') {
|
|
502
|
+
return maturity;
|
|
503
|
+
}
|
|
504
|
+
if (typeof issue === 'string') {
|
|
505
|
+
return issue;
|
|
506
|
+
}
|
|
507
|
+
if (typeof rate === 'string') {
|
|
508
|
+
return rate;
|
|
509
|
+
}
|
|
510
|
+
if (typeof yld === 'string') {
|
|
511
|
+
return yld;
|
|
512
|
+
}
|
|
513
|
+
var basis = 0;
|
|
514
|
+
if (args.length === 6 && args[5] !== '') {
|
|
515
|
+
var b = this.resolveNumberArg(args[5]);
|
|
516
|
+
if (typeof b === 'string') {
|
|
517
|
+
return b;
|
|
518
|
+
}
|
|
519
|
+
basis = Math.floor(b);
|
|
520
|
+
}
|
|
521
|
+
var yearDays = this.bond.yearDays(basis);
|
|
522
|
+
var ds = this.bond.daysBetween(issue, settlement, basis);
|
|
523
|
+
var dm = this.bond.daysBetween(issue, maturity, basis);
|
|
524
|
+
return ((100 + rate * dm / yearDays) / (1 + yld * ds / yearDays)).toString();
|
|
525
|
+
};
|
|
526
|
+
/**
|
|
527
|
+
* Returns the price per $100 face value for a Treasury bill.
|
|
528
|
+
*
|
|
529
|
+
* Excel: `TBILLPRICE(...)`.
|
|
530
|
+
*
|
|
531
|
+
* @hidden
|
|
532
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
533
|
+
* @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
|
|
534
|
+
*/
|
|
535
|
+
FinancialCouponsFormulas.prototype.ComputeTBILLPRICE = function () {
|
|
536
|
+
var args = [];
|
|
537
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
538
|
+
args[_i] = arguments[_i];
|
|
539
|
+
}
|
|
540
|
+
if (isNullOrUndefined(args) || args.length !== 3) {
|
|
541
|
+
return this.parent.formulaErrorStrings[FormulasErrorsStrings.WrongNumberArguments];
|
|
542
|
+
}
|
|
543
|
+
var settlement = this.resolveNumberArg(args[0]);
|
|
544
|
+
var maturity = this.resolveNumberArg(args[1]);
|
|
545
|
+
var discount = this.resolveNumberArg(args[2]);
|
|
546
|
+
if (typeof settlement === 'string') {
|
|
547
|
+
return settlement;
|
|
548
|
+
}
|
|
549
|
+
if (typeof maturity === 'string') {
|
|
550
|
+
return maturity;
|
|
551
|
+
}
|
|
552
|
+
if (typeof discount === 'string') {
|
|
553
|
+
return discount;
|
|
554
|
+
}
|
|
555
|
+
var days = maturity - settlement;
|
|
556
|
+
if (days <= 0) {
|
|
557
|
+
return this.parent.getErrorStrings()[CommonErrors.Num];
|
|
558
|
+
}
|
|
559
|
+
return (100 * (1 - discount * days / 360)).toString();
|
|
560
|
+
};
|
|
561
|
+
/**
|
|
562
|
+
* Returns the yield for a Treasury bill.
|
|
563
|
+
*
|
|
564
|
+
* Excel: `TBILLYIELD(...)`.
|
|
565
|
+
*
|
|
566
|
+
* @hidden
|
|
567
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
568
|
+
* @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
|
|
569
|
+
*/
|
|
570
|
+
FinancialCouponsFormulas.prototype.ComputeTBILLYIELD = function () {
|
|
571
|
+
var args = [];
|
|
572
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
573
|
+
args[_i] = arguments[_i];
|
|
574
|
+
}
|
|
575
|
+
if (isNullOrUndefined(args) || args.length !== 3) {
|
|
576
|
+
return this.parent.formulaErrorStrings[FormulasErrorsStrings.WrongNumberArguments];
|
|
577
|
+
}
|
|
578
|
+
var settlement = this.resolveNumberArg(args[0]);
|
|
579
|
+
var maturity = this.resolveNumberArg(args[1]);
|
|
580
|
+
var pr = this.resolveNumberArg(args[2]);
|
|
581
|
+
if (typeof settlement === 'string') {
|
|
582
|
+
return settlement;
|
|
583
|
+
}
|
|
584
|
+
if (typeof maturity === 'string') {
|
|
585
|
+
return maturity;
|
|
586
|
+
}
|
|
587
|
+
if (typeof pr === 'string') {
|
|
588
|
+
return pr;
|
|
589
|
+
}
|
|
590
|
+
var days = maturity - settlement;
|
|
591
|
+
if (days <= 0 || pr <= 0) {
|
|
592
|
+
return this.parent.getErrorStrings()[CommonErrors.Num];
|
|
593
|
+
}
|
|
594
|
+
return ((100 - pr) / pr * 360 / days).toString();
|
|
595
|
+
};
|
|
596
|
+
/**
|
|
597
|
+
* Returns the bond-equivalent yield for a Treasury bill.
|
|
598
|
+
*
|
|
599
|
+
* Excel: `TBILLEQ(...)`.
|
|
600
|
+
*
|
|
601
|
+
* @hidden
|
|
602
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
603
|
+
* @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
|
|
604
|
+
*/
|
|
605
|
+
FinancialCouponsFormulas.prototype.ComputeTBILLEQ = function () {
|
|
606
|
+
var args = [];
|
|
607
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
608
|
+
args[_i] = arguments[_i];
|
|
609
|
+
}
|
|
610
|
+
var yieldResult = this.ComputeTBILLYIELD.apply(this, args);
|
|
611
|
+
var errCollection = this.parent.getErrorStrings();
|
|
612
|
+
if (typeof yieldResult === 'string' && errCollection.indexOf(yieldResult) > -1) {
|
|
613
|
+
return yieldResult;
|
|
614
|
+
}
|
|
615
|
+
var y = this.parent.parseFloat(yieldResult);
|
|
616
|
+
return ((365 * y) / (360 - y * (this.resolveNumberArg(args[1]) - this.resolveNumberArg(args[0])))).toString();
|
|
617
|
+
};
|
|
618
|
+
/**
|
|
619
|
+
* Returns the net present value for a schedule of cash flows that is not necessarily periodic.
|
|
620
|
+
*
|
|
621
|
+
* Excel: `XNPV(...)`.
|
|
622
|
+
*
|
|
623
|
+
* @hidden
|
|
624
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
625
|
+
* @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
|
|
626
|
+
*/
|
|
627
|
+
FinancialCouponsFormulas.prototype.ComputeXNPV = function () {
|
|
628
|
+
var args = [];
|
|
629
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
630
|
+
args[_i] = arguments[_i];
|
|
631
|
+
}
|
|
632
|
+
var errCollection = this.parent.getErrorStrings();
|
|
633
|
+
if (isNullOrUndefined(args) || args.length < 3) {
|
|
634
|
+
return this.parent.formulaErrorStrings[FormulasErrorsStrings.WrongNumberArguments];
|
|
635
|
+
}
|
|
636
|
+
var rate = this.resolveNumberArg(args[0]);
|
|
637
|
+
if (typeof rate === 'string') {
|
|
638
|
+
return rate;
|
|
639
|
+
}
|
|
640
|
+
var values = [];
|
|
641
|
+
var dates = [];
|
|
642
|
+
var valCells = this.parent.getCellCollection(args[1]);
|
|
643
|
+
var dateCells = this.parent.getCellCollection(args[2]);
|
|
644
|
+
var vList = Array.isArray(valCells) ? valCells : [valCells];
|
|
645
|
+
var dList = Array.isArray(dateCells) ? dateCells : [dateCells];
|
|
646
|
+
if (vList.length !== dList.length || vList.length < 1) {
|
|
647
|
+
return errCollection[CommonErrors.Num];
|
|
648
|
+
}
|
|
649
|
+
for (var i = 0; i < vList.length; i++) {
|
|
650
|
+
var v = this.parent.getValueFromArg(vList[i]);
|
|
651
|
+
var d = this.parent.getValueFromArg(dList[i]);
|
|
652
|
+
if (errCollection.indexOf(v) > -1) {
|
|
653
|
+
return v;
|
|
654
|
+
}
|
|
655
|
+
if (errCollection.indexOf(d) > -1) {
|
|
656
|
+
return d;
|
|
657
|
+
}
|
|
658
|
+
values.push(this.parent.parseFloat(v));
|
|
659
|
+
dates.push(this.parent.parseFloat(d));
|
|
660
|
+
}
|
|
661
|
+
var t0 = dates[0];
|
|
662
|
+
var npv = 0;
|
|
663
|
+
for (var i = 0; i < values.length; i++) {
|
|
664
|
+
npv += values[i] / Math.pow(1 + rate, (dates[i] - t0) / 365);
|
|
665
|
+
}
|
|
666
|
+
return npv.toString();
|
|
667
|
+
};
|
|
668
|
+
/**
|
|
669
|
+
* Returns the yield on a security that pays periodic interest.
|
|
670
|
+
*
|
|
671
|
+
* Excel: `YIELD(...)`.
|
|
672
|
+
*
|
|
673
|
+
* @hidden
|
|
674
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
675
|
+
* @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
|
|
676
|
+
*/
|
|
677
|
+
FinancialCouponsFormulas.prototype.ComputeYIELD = function () {
|
|
678
|
+
var args = [];
|
|
679
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
680
|
+
args[_i] = arguments[_i];
|
|
681
|
+
}
|
|
682
|
+
var priceResult = this.ComputePRICE.apply(this, args);
|
|
683
|
+
var errCollection = this.parent.getErrorStrings();
|
|
684
|
+
if (typeof priceResult === 'string' && (errCollection.indexOf(priceResult) > -1 || priceResult.match(/arguments/i))) {
|
|
685
|
+
return priceResult;
|
|
686
|
+
}
|
|
687
|
+
var parsed = this.parseBondArgs(args, 6, 7);
|
|
688
|
+
if (typeof parsed === 'string') {
|
|
689
|
+
return parsed;
|
|
690
|
+
}
|
|
691
|
+
var price = this.parent.parseFloat(priceResult);
|
|
692
|
+
var yld = parsed.yld || 0.05;
|
|
693
|
+
for (var iter = 0; iter < 50; iter++) {
|
|
694
|
+
parsed.yld = yld;
|
|
695
|
+
var p = this.parent.parseFloat(this.ComputePRICE(args[0], args[1], args[2], yld.toString(), args[4], args[5], args[6]));
|
|
696
|
+
var diff = p - price;
|
|
697
|
+
if (Math.abs(diff) < 1e-8) {
|
|
698
|
+
return yld.toString();
|
|
699
|
+
}
|
|
700
|
+
yld += diff * 0.0001;
|
|
701
|
+
}
|
|
702
|
+
return yld.toString();
|
|
703
|
+
};
|
|
704
|
+
/**
|
|
705
|
+
* Returns the annual yield for a discounted security.
|
|
706
|
+
*
|
|
707
|
+
* Excel: `YIELDDISC(...)`.
|
|
708
|
+
*
|
|
709
|
+
* @hidden
|
|
710
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
711
|
+
* @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
|
|
712
|
+
*/
|
|
713
|
+
FinancialCouponsFormulas.prototype.ComputeYIELDDISC = function () {
|
|
714
|
+
var args = [];
|
|
715
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
716
|
+
args[_i] = arguments[_i];
|
|
717
|
+
}
|
|
718
|
+
if (isNullOrUndefined(args) || args.length < 4 || args.length > 5) {
|
|
719
|
+
return this.parent.formulaErrorStrings[FormulasErrorsStrings.WrongNumberArguments];
|
|
720
|
+
}
|
|
721
|
+
var settlement = this.resolveNumberArg(args[0]);
|
|
722
|
+
var maturity = this.resolveNumberArg(args[1]);
|
|
723
|
+
var pr = this.resolveNumberArg(args[2]);
|
|
724
|
+
var redemption = this.resolveNumberArg(args[3]);
|
|
725
|
+
if (typeof settlement === 'string') {
|
|
726
|
+
return settlement;
|
|
727
|
+
}
|
|
728
|
+
if (typeof maturity === 'string') {
|
|
729
|
+
return maturity;
|
|
730
|
+
}
|
|
731
|
+
if (typeof pr === 'string') {
|
|
732
|
+
return pr;
|
|
733
|
+
}
|
|
734
|
+
if (typeof redemption === 'string') {
|
|
735
|
+
return redemption;
|
|
736
|
+
}
|
|
737
|
+
var basis = 0;
|
|
738
|
+
if (args.length === 5 && args[4] !== '') {
|
|
739
|
+
var b = this.resolveNumberArg(args[4]);
|
|
740
|
+
if (typeof b === 'string') {
|
|
741
|
+
return b;
|
|
742
|
+
}
|
|
743
|
+
basis = Math.floor(b);
|
|
744
|
+
}
|
|
745
|
+
var days = this.bond.daysBetween(settlement, maturity, basis);
|
|
746
|
+
var yearDays = this.bond.yearDays(basis);
|
|
747
|
+
if (days <= 0) {
|
|
748
|
+
return this.parent.getErrorStrings()[CommonErrors.Num];
|
|
749
|
+
}
|
|
750
|
+
return ((redemption - pr) / pr * yearDays / days).toString();
|
|
751
|
+
};
|
|
752
|
+
/**
|
|
753
|
+
* Returns the annual yield of a security that pays interest at maturity.
|
|
754
|
+
*
|
|
755
|
+
* Excel: `YIELDMAT(...)`.
|
|
756
|
+
*
|
|
757
|
+
* @hidden
|
|
758
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
759
|
+
* @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
|
|
760
|
+
*/
|
|
761
|
+
FinancialCouponsFormulas.prototype.ComputeYIELDMAT = function () {
|
|
762
|
+
var args = [];
|
|
763
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
764
|
+
args[_i] = arguments[_i];
|
|
765
|
+
}
|
|
766
|
+
var errCollection = this.parent.getErrorStrings();
|
|
767
|
+
if (isNullOrUndefined(args) || args.length < 5 || args.length > 6) {
|
|
768
|
+
return this.parent.formulaErrorStrings[FormulasErrorsStrings.WrongNumberArguments];
|
|
769
|
+
}
|
|
770
|
+
var settlement = this.resolveNumberArg(args[0]);
|
|
771
|
+
var maturity = this.resolveNumberArg(args[1]);
|
|
772
|
+
var issue = this.resolveNumberArg(args[2]);
|
|
773
|
+
var rate = this.resolveNumberArg(args[3]);
|
|
774
|
+
var pr = this.resolveNumberArg(args[4]);
|
|
775
|
+
if (typeof settlement === 'string') {
|
|
776
|
+
return settlement;
|
|
777
|
+
}
|
|
778
|
+
if (typeof maturity === 'string') {
|
|
779
|
+
return maturity;
|
|
780
|
+
}
|
|
781
|
+
if (typeof issue === 'string') {
|
|
782
|
+
return issue;
|
|
783
|
+
}
|
|
784
|
+
if (typeof rate === 'string') {
|
|
785
|
+
return rate;
|
|
786
|
+
}
|
|
787
|
+
if (typeof pr === 'string') {
|
|
788
|
+
return pr;
|
|
789
|
+
}
|
|
790
|
+
var basis = 0;
|
|
791
|
+
if (args.length === 6 && args[5] !== '') {
|
|
792
|
+
var b = this.resolveNumberArg(args[5]);
|
|
793
|
+
if (typeof b === 'string') {
|
|
794
|
+
return b;
|
|
795
|
+
}
|
|
796
|
+
basis = Math.floor(b);
|
|
797
|
+
}
|
|
798
|
+
var yearDays = this.bond.yearDays(basis);
|
|
799
|
+
var ds = this.bond.daysBetween(issue, settlement, basis);
|
|
800
|
+
var dm = this.bond.daysBetween(issue, maturity, basis);
|
|
801
|
+
var num = (100 + rate * dm / yearDays - pr);
|
|
802
|
+
var den = pr * ds / yearDays;
|
|
803
|
+
if (den === 0) {
|
|
804
|
+
return errCollection[CommonErrors.Num];
|
|
805
|
+
}
|
|
806
|
+
return (num / den).toString();
|
|
807
|
+
};
|
|
808
|
+
return FinancialCouponsFormulas;
|
|
809
|
+
}(FormulaModuleBase));
|
|
810
|
+
export { FinancialCouponsFormulas };
|