sec-edgar-api
Version:
Fetch and parse SEC earnings reports and other filings. Useful for financial analysis.
86 lines (85 loc) • 3.36 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.resolveFiscalYearCumulativeProperties = void 0;
/**
* Properties where the quarters add up to FY resolved if 1 of the 5 reports is missing.
*/
function resolveFiscalYearCumulativeProperties(report) {
var _a = report.getReportsFiscalYearByPeriod(), FY = _a.FY, Q1 = _a.Q1, Q2 = _a.Q2, Q3 = _a.Q3, Q4 = _a.Q4;
if (!FY || !Q1 || !Q2 || !Q3 || !Q4)
return;
// these properties should be the same for Q4 and FY
matchProperty('assetNonCurrentPPEGross', Q4, FY);
matchProperty('assetNonCurrentPPENet', Q4, FY);
matchProperty('expenseDepreciationAccumulated', Q4, FY);
var keysToInclude = new Set([
'cashFlowCapex',
'cashFlowDeferredTax',
'cashFlowDividendsPaid',
'cashFlowDividendsPaidPreferred',
'cashFlowFree',
'cashFlowOperating',
'cashFlowWorkingCapitalNonCash',
'assetNonCurrentIntangibleLessGoodwill',
'expenseDepreciation',
'expenseInterest',
'expenseNonCashOther',
'expenseOperating',
'expenseResearchDevelopment',
'expenseStockCompensation',
'expenseTax',
'expenseTotal',
'ebit',
'ebitda',
'eps',
'epsDiluted',
'incomeNet',
'incomeOperating',
'profitGross',
'revenueCost',
'revenueOperating',
'revenueTotal',
]);
var reportKeys = Object.keys(Q1);
var keysToResolve = reportKeys.filter(function (key) {
var reportsWithVal = [FY, Q1, Q2, Q3, Q4].filter(function (report) {
return typeof report[key] === 'number' && keysToInclude.has(key);
});
// we want to get the keys that are in 4 of the 5 reports
return reportsWithVal.length === 4;
});
var _loop_1 = function (key) {
var valueFY = FY[key];
// this will be the sum of the 3 quarters if a quarter is missing, and sum of 4 quarters if FY is missing
var sumQuarters = [Q1, Q2, Q3, Q4].reduce(function (acc, rep) { var _a; return acc + ((_a = rep === null || rep === void 0 ? void 0 : rep[key]) !== null && _a !== void 0 ? _a : 0); }, 0);
// if FY is missing use the sum of the 4 quarters, otherwise use FY - sum of 3 other quarters
if (typeof FY[key] !== 'number') {
;
FY[key] = sumQuarters;
}
else {
for (var _b = 0, _c = [Q1, Q2, Q3, Q4]; _b < _c.length; _b++) {
var rep = _c[_b];
if (rep && typeof rep[key] !== 'number') {
;
rep[key] =
Math.round((valueFY - sumQuarters) * 10000) / 10000;
break;
}
}
}
};
for (var _i = 0, keysToResolve_1 = keysToResolve; _i < keysToResolve_1.length; _i++) {
var key = keysToResolve_1[_i];
_loop_1(key);
}
}
exports.resolveFiscalYearCumulativeProperties = resolveFiscalYearCumulativeProperties;
function matchProperty(propertyName, reportA, reportB) {
var isReportANull = reportA[propertyName] === null;
var value = isReportANull ? reportB[propertyName] : reportA[propertyName];
if (typeof value !== 'number')
return;
reportA[propertyName] = value;
reportB[propertyName] = value;
}