sec-edgar-api 0.2.3 → 0.2.4

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.
@@ -7,7 +7,7 @@ var FactRecordBuilder = /** @class */ (function () {
7
7
  function FactRecordBuilder() {
8
8
  }
9
9
  FactRecordBuilder.prototype.createFacts = function (data, filterDuplicates) {
10
- if (filterDuplicates === void 0) { filterDuplicates = true; }
10
+ if (filterDuplicates === void 0) { filterDuplicates = false; }
11
11
  var facts = data.facts, cik = data.cik;
12
12
  var factsByKey = new Map();
13
13
  var keyIndex = 0;
@@ -6,6 +6,7 @@ interface SplitData {
6
6
  value: number;
7
7
  firstFiled: string;
8
8
  fiscalYear: number;
9
+ fiscalPeriod: FiscalPeriod;
9
10
  }
10
11
  type FactItemWithFiscalsNumeric = Omit<FactItemWithFiscals, 'cik' | 'value'> & {
11
12
  value: number;
@@ -22,7 +23,10 @@ export default class FactSplitAdjuster {
22
23
  private readonly resolvedProperties;
23
24
  private sortedSplits;
24
25
  private getMap;
25
- add(fact: FactItemWithFiscalsNumeric): void;
26
+ private filedFirstLastBySplitKey;
27
+ add(fact: FactItemWithFiscalsNumeric & {
28
+ filedLast?: string;
29
+ }): void;
26
30
  getSplitsAsc(): SplitData[];
27
31
  isSplitProperty(propertyName: string): boolean;
28
32
  addSplitData(data: Omit<SplitData, 'firstFiled'>): void;
@@ -23,15 +23,17 @@ var FactSplitAdjuster = /** @class */ (function () {
23
23
  this.factsAnnaulByYearByPropertyName = new Map();
24
24
  this.resolvedProperties = new Set();
25
25
  this.sortedSplits = null;
26
+ this.filedFirstLastBySplitKey = new Map();
26
27
  }
27
28
  FactSplitAdjuster.prototype.getMap = function (map, propertyName) {
28
29
  var _a;
29
30
  return (_a = map.get(propertyName)) !== null && _a !== void 0 ? _a : map.set(propertyName, new Map()).get(propertyName);
30
31
  };
31
32
  FactSplitAdjuster.prototype.add = function (fact) {
33
+ var _a;
32
34
  var propertyName = fact.name, year = fact.year, fiscalPeriod = fact.fiscalPeriod, unit = fact.unit, filed = fact.filed, value = fact.value, end = fact.end;
33
35
  if (this.isSplitProperty(propertyName)) {
34
- this.addSplitData({ end: end, filed: filed, fiscalYear: year, value: Number(value) });
36
+ this.addSplitData({ end: end, filed: filed, fiscalYear: year, value: Number(value), fiscalPeriod: fiscalPeriod });
35
37
  return;
36
38
  }
37
39
  if (!this.isSplitAdjustableUnit(unit))
@@ -44,6 +46,10 @@ var FactSplitAdjuster = /** @class */ (function () {
44
46
  ? this.getMap(this.factsAnnaulByYearByPropertyName, propertyName)
45
47
  : this.getMap(this.factsByYearQuarterByPropertyName, propertyName);
46
48
  var key = "".concat(year, "_").concat(fiscalPeriod);
49
+ this.filedFirstLastBySplitKey.set(key, {
50
+ firstFiled: filed,
51
+ lastFiled: (_a = fact.filedLast) !== null && _a !== void 0 ? _a : filed,
52
+ });
47
53
  map.set(key, fact);
48
54
  };
49
55
  FactSplitAdjuster.prototype.getSplitsAsc = function () {
@@ -92,29 +98,29 @@ var FactSplitAdjuster = /** @class */ (function () {
92
98
  * TODO: Find a more reliable way of checking if the split has already been applied.
93
99
  */
94
100
  FactSplitAdjuster.prototype.didApplySplit = function (params) {
95
- var nextValue = params.nextValue, prevValue = params.prevValue, split = params.split, isShareRatio = params.isShareRatio, value = params.value, filed = params.filed;
96
- if (filed > split.filed) {
101
+ var _a;
102
+ var isShareRatio = params.isShareRatio, nextFact = params.nextFact, prevFact = params.prevFact, fact = params.fact, split = params.split;
103
+ var _b = (_a = this.filedFirstLastBySplitKey.get("".concat(split.fiscalYear, "_").concat(split.fiscalPeriod))) !== null && _a !== void 0 ? _a : {}, firstFiled = _b.firstFiled, lastFiled = _b.lastFiled;
104
+ if (fact.filed > lastFiled) {
97
105
  return true;
98
106
  }
99
- var dateFiled = new Date(filed);
100
- // TODO: adust by adding a year because sometimes the already adjusted facts are filed within the
101
- // year before the split. this might be because the split is listed under a different property? Look into this...
102
- if (dateFiled.setFullYear(dateFiled.getFullYear() + 1) < new Date(split.firstFiled).getTime()) {
107
+ if (fact.filed < firstFiled) {
103
108
  return false;
104
109
  }
105
- var valWithSplit = isShareRatio ? value / split.value : value * split.value;
106
- // if we still don't know, see if applying the split puts us closer or further from the prev/next quarter value.
107
- if (prevValue !== null) {
108
- var difference = Math.abs(prevValue - value);
109
- var differenceSplit = Math.abs(prevValue - valWithSplit);
110
+ var val = fact.value;
111
+ var splitVal = split.value;
112
+ var valWithSplit = isShareRatio ? splitVal * val : val / splitVal;
113
+ if (nextFact) {
114
+ var difference = Math.abs(nextFact.value - val);
115
+ var differenceSplit = Math.abs(nextFact.value - valWithSplit);
110
116
  return difference < differenceSplit;
111
117
  }
112
- if (nextValue !== null) {
113
- var difference = Math.abs(nextValue - value);
114
- var differenceSplit = Math.abs(nextValue - valWithSplit);
118
+ if (prevFact) {
119
+ var difference = Math.abs(prevFact.value - val);
120
+ var differenceSplit = Math.abs(prevFact.value - valWithSplit);
115
121
  return difference < differenceSplit;
116
122
  }
117
- return true;
123
+ return false;
118
124
  };
119
125
  FactSplitAdjuster.prototype.isSplitAdjustableUnit = function (unit) {
120
126
  return unit.toLowerCase().includes('share');
@@ -165,7 +171,7 @@ var FactSplitAdjuster = /** @class */ (function () {
165
171
  });
166
172
  };
167
173
  FactSplitAdjuster.prototype.adjustValuesForSplits = function (params) {
168
- var _a, _b, _c, _d;
174
+ var _a, _b;
169
175
  var facts = params.facts;
170
176
  var splits = this.getSplitsAsc();
171
177
  if (facts.length === 0 || splits.length === 0)
@@ -176,15 +182,20 @@ var FactSplitAdjuster = /** @class */ (function () {
176
182
  for (var factIndex = facts.length - 1; factIndex >= 0; factIndex--) {
177
183
  var fact = facts[factIndex];
178
184
  var value = fact.value, filed = fact.filed;
179
- var nextValue = (_b = (_a = facts[factIndex + 1]) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : null;
180
- var prevValue = (_d = (_c = facts[factIndex - 1]) === null || _c === void 0 ? void 0 : _c.value) !== null && _d !== void 0 ? _d : null;
185
+ var nextFact = (_a = facts[factIndex + 1]) !== null && _a !== void 0 ? _a : null;
186
+ var prevFact = (_b = facts[factIndex - 1]) !== null && _b !== void 0 ? _b : null;
187
+ // const nextValue = facts[factIndex + 1]?.value ?? null
188
+ // const prevValue = facts[factIndex - 1]?.value ?? null
181
189
  var didApplySplit = this.didApplySplit({
182
- filed: filed,
190
+ // filed,
183
191
  isShareRatio: isShareRatio,
184
- nextValue: nextValue,
185
- prevValue: prevValue,
192
+ // nextValue,
193
+ // prevValue,
194
+ fact: fact,
195
+ nextFact: nextFact,
196
+ prevFact: prevFact,
186
197
  split: split,
187
- value: value,
198
+ // value,
188
199
  });
189
200
  if (didApplySplit || !split.value) {
190
201
  continue;
@@ -15,7 +15,7 @@ var ReportBuilder = /** @class */ (function () {
15
15
  return this.factRecordBuilder.createFacts(companyFacts);
16
16
  };
17
17
  ReportBuilder.prototype.buildReports = function (params) {
18
- var _a, _b, _c, _d, _e;
18
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
19
19
  var facts = params.facts, reportDates = params.reportDates;
20
20
  if (facts.length === 0) {
21
21
  return [];
@@ -38,6 +38,7 @@ var ReportBuilder = /** @class */ (function () {
38
38
  var maxYear = -Infinity;
39
39
  var countByAccnByYearQuarter = new Map();
40
40
  var filedByPropertyYearQuarterValue = new Map();
41
+ var filedLastByPropertyYearQuarterValue = new Map();
41
42
  for (var _i = 0, facts_1 = facts; _i < facts_1.length; _i++) {
42
43
  var fact = facts_1[_i];
43
44
  var end = fact.end, name_1 = fact.name, unit = fact.unit, segments = fact.segments, start = fact.start, value = fact.value, cik = fact.cik, form = fact.form, filed = fact.filed, accn = fact.accn;
@@ -47,7 +48,7 @@ var ReportBuilder = /** @class */ (function () {
47
48
  var segmentValue = segments === null || segments === void 0 ? void 0 : segments.map(function (seg) { return "".concat(seg.dimension, "_").concat(seg.value); }).join('&');
48
49
  var propertyName = (_a = name_1.split(':').pop()) !== null && _a !== void 0 ? _a : '';
49
50
  var propertyNameWithSegment = propertyName + (segmentValue ? "_".concat(segmentValue) : '');
50
- var _f = factFiscalCalculator.getFiscalYearQuarter({ dateStr: end }), quarter = _f.quarter, year = _f.year;
51
+ var _m = factFiscalCalculator.getFiscalYearQuarter({ dateStr: end }), quarter = _m.quarter, year = _m.year;
51
52
  if (year < minYear)
52
53
  minYear = year;
53
54
  if (year > maxYear)
@@ -56,17 +57,30 @@ var ReportBuilder = /** @class */ (function () {
56
57
  var factFiledKey = "".concat(year, "_").concat(quarter, "_").concat(propertyNameWithSegment, "_").concat(value);
57
58
  var isSplit = factSplitAdjuster.isSplitProperty(propertyName);
58
59
  unitByPropertyName.set(propertyNameWithSegment, unit);
59
- filedByPropertyYearQuarterValue.set(factFiledKey, filed);
60
- if (isSplit && new Date(end) > new Date((_c = (_b = splitDateDataByKey.get(splitKey)) === null || _b === void 0 ? void 0 : _b.end) !== null && _c !== void 0 ? _c : 0)) {
61
- splitDateDataByKey.set(splitKey, { end: end, quarter: quarter });
60
+ var prevFirstFiled = filedByPropertyYearQuarterValue.get(factFiledKey);
61
+ var prevLastFiled = filedLastByPropertyYearQuarterValue.get(factFiledKey);
62
+ if (!prevFirstFiled || prevFirstFiled > filed) {
63
+ filedByPropertyYearQuarterValue.set(factFiledKey, filed);
64
+ }
65
+ if (!prevLastFiled || prevLastFiled < filed) {
66
+ filedLastByPropertyYearQuarterValue.set(factFiledKey, filed);
67
+ }
68
+ if (isSplit) {
69
+ var isNewLatestDate = new Date(end) > new Date((_c = (_b = splitDateDataByKey.get(splitKey)) === null || _b === void 0 ? void 0 : _b.end) !== null && _c !== void 0 ? _c : 0);
70
+ splitDateDataByKey.set(splitKey, {
71
+ end: isNewLatestDate ? end : (_e = (_d = splitDateDataByKey.get(splitKey)) === null || _d === void 0 ? void 0 : _d.end) !== null && _e !== void 0 ? _e : end,
72
+ quarter: isNewLatestDate ? quarter : (_g = (_f = splitDateDataByKey.get(splitKey)) === null || _f === void 0 ? void 0 : _f.quarter) !== null && _g !== void 0 ? _g : quarter,
73
+ firstFiled: (_h = filedByPropertyYearQuarterValue.get(factFiledKey)) !== null && _h !== void 0 ? _h : filed,
74
+ lastFiled: (_j = filedLastByPropertyYearQuarterValue.get(factFiledKey)) !== null && _j !== void 0 ? _j : filed,
75
+ });
62
76
  }
63
77
  var accnKey = "".concat(year, "_").concat(quarter);
64
78
  var accnGiven = accessionByYearQuarter.get(accnKey);
65
79
  var filedDistance = Math.abs(new Date(filed).getTime() - new Date(end !== null && end !== void 0 ? end : 0).getTime()) / 86400000;
66
80
  var isFiledRecent = filedDistance < 60;
67
81
  if (!accnGiven && isFiledRecent && accn && (!form || form === '10-K' || form === '10-Q')) {
68
- var countByAccn = (_d = countByAccnByYearQuarter.get(accnKey)) !== null && _d !== void 0 ? _d : new Map();
69
- countByAccn.set(accn, ((_e = countByAccn.get(accn)) !== null && _e !== void 0 ? _e : 0) + 1);
82
+ var countByAccn = (_k = countByAccnByYearQuarter.get(accnKey)) !== null && _k !== void 0 ? _k : new Map();
83
+ countByAccn.set(accn, ((_l = countByAccn.get(accn)) !== null && _l !== void 0 ? _l : 0) + 1);
70
84
  countByAccnByYearQuarter.set(accnKey, countByAccn);
71
85
  }
72
86
  factPeriodResolver.add({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sec-edgar-api",
3
- "version": "0.2.3",
3
+ "version": "0.2.4",
4
4
  "description": "Fetch and parse SEC earnings reports and other filings. Useful for financial analysis.",
5
5
  "main": "build/index.js",
6
6
  "author": "Andrew Evers (https://github.com/andyevers)",