spreadsheet
typeScript/javascript spreadsheet parser, with formulas.
git clone https://git.vogt.world/spreadsheet.git
Log | Files | README.md
← Commit log
commit
message
[YEARFRAC, ACCRINT] Improving documentation.
author
Ben Vogt <[email protected]>
date
2017-04-29 21:27:08
stats
2 file(s) changed, 19 insertions(+), 25 deletions(-)
files
src/RawFormulas/Date.ts
src/RawFormulas/Financial.ts
 1diff --git a/src/RawFormulas/Date.ts b/src/RawFormulas/Date.ts
 2index c320ed3..37e2940 100644
 3--- a/src/RawFormulas/Date.ts
 4+++ b/src/RawFormulas/Date.ts
 5@@ -493,8 +493,8 @@ var YEARFRAC = function (...values) : number {
 6   };
 7 
 8   switch (basis) {
 9+    // US (NASD) 30/360
10     case 0:
11-      // US (NASD) 30/360
12       // Note: if eday == 31, it stays 31 if sday < 30
13       if (sday === 31 && eday === 31) {
14         sday = 30;
15@@ -510,8 +510,8 @@ var YEARFRAC = function (...values) : number {
16         sday = 30;
17       }
18       return Math.abs(((eday + emonth * 30 + eyear * 360) - (sday + smonth * 30 + syear * 360)) / 360);
19+    // Actual/actual
20     case 1:
21-      // Actual/actual
22       var ylength = 365;
23       if (syear === eyear || ((syear + 1) === eyear) && ((smonth > emonth) || ((smonth === emonth) && (sday >= eday)))) {
24         if (syear === eyear && moment.utc([syear]).isLeapYear()) {
25@@ -526,14 +526,14 @@ var YEARFRAC = function (...values) : number {
26         var average = days / years;
27         return Math.abs((end.toNumber() - start.toNumber()) / average);
28       }
29+    // Actual/360
30     case 2:
31-      // Actual/360
32       return Math.abs(e.diff(s, 'days') / 360);
33+    // Actual/365
34     case 3:
35-      // Actual/365
36       return Math.abs(e.diff(s, 'days') / 365);
37+    // European 30/360
38     case 4:
39-      // European 30/360
40       sday = sday === 31 ? 30 : sday;
41       eday = eday === 31 ? 30 : eday;
42       // Remarkably, do NOT change February 28 or February 29 at ALL
43diff --git a/src/RawFormulas/Financial.ts b/src/RawFormulas/Financial.ts
44index 8d0f716..c36a319 100644
45--- a/src/RawFormulas/Financial.ts
46+++ b/src/RawFormulas/Financial.ts
47@@ -377,28 +377,27 @@ var CUMIPMT = function (...values) : number {
48  * delivered to the buyer. Is the maturity date of the security if it is held until maturity rather than sold.
49  * @param values[3] rate - The annualized rate of interest.
50  * @param values[4] redemption - The redemption amount per 100 face value, or par.
51- * @param values[5] frequency - The number of interest or coupon payments per year (1, 2, or 4).
52+ * @param values[5] frequency - The number of coupon payments per year. For annual payments, frequency = 1; for
53+ * semiannual, frequency = 2; for quarterly, frequency = 4.
54  * @param values[6] day_count_convention - [ OPTIONAL - 0 by default ] - An indicator of what day count method to use.
55- * 0 indicates US (NASD) 30/360 - This assumes 30 day months and 360 day years as per the National Association of
56- * Securities Dealers standard, and performs specific adjustments to entered dates which fall at the end of months.
57- * 1 indicates Actual/Actual - This calculates based upon the actual number of days between the specified dates, and the
58- * actual number of days in the intervening years. Used for US Treasury Bonds and Bills, but also the most relevant for
59- * non-financial use. 2 indicates Actual/360 - This calculates based on the actual number of days between the speficied
60- * dates, but assumes a 360 day year. 3 indicates Actual/365 - This calculates based on the actual number of days
61- * between the specified dates, but assumes a 365 day year. 4 indicates European 30/360 - Similar to 0, this calculates
62- * based on a 30 day month and 360 day year, but adjusts end-of-month dates according to European financial conventions.
63+ * 0 or omitted = US (NASD) 30/360, 1 = Actual/actual, 2 = Actual/360, 3 = Actual/365, 4 = European 30/360.
64  * @returns {number}
65  * @constructor
66  */
67 var ACCRINT = function (...values) {
68   ArgsChecker.checkLengthWithin(values, 6, 7);
69   var issue = TypeCaster.firstValueAsExcelDate(values[0]);
70-  // firstPayment param is only here to check for errors for GS implementation.
71+  // "firstPayment" param is only here to check for errors for GS implementation.
72+  // In MSE, there is a 7th (zero-indexed-6th) param that indicates the calculation-method to use, which indicates
73+  // weather the total accrued interest starting at the first_intrest date, instead of the issue date.
74   var firstPayment = TypeCaster.firstValueAsExcelDate(values[1]);
75   var settlement = TypeCaster.firstValueAsExcelDate(values[2]);
76   var rate = TypeCaster.firstValueAsNumber(values[3]);
77   var redemption = TypeCaster.firstValueAsNumber(values[4]);// "par"
78-  // The frequency parameter also does not affect the resulting value of the formula.
79+  // The frequency parameter also does not affect the resulting value of the formula in the GS implementation.
80+  // In MSE, frequency is used to calculate a more accurate value, by breaking apart the year, and computing interest
81+  // on an on-going basis. In this implementation, we use YEARFRAC to get a numerical value that encompasses the
82+  // functionality of "frequency".
83   var frequency = TypeCaster.firstValueAsNumber(values[5]);
84   var dayCountConvention = values.length === 7 ? TypeCaster.firstValueAsNumber(values[6]) : 1;// "basis"
85   var factor = YEARFRAC(issue, settlement, dayCountConvention);