sec-edgar-api
Version:
Fetch and parse SEC earnings reports and other filings. Useful for financial analysis.
76 lines (75 loc) • 2.17 kB
TypeScript
import type { FactItem, FilingListItemTranslated } from '../../types';
export interface SetReportDatesParams {
year: number;
quarter: number;
end: string;
filed: string;
isAnnual: boolean;
accn: string;
}
/**
* Gets the fiscal period for a given date. does this by checking when the FY end periods are,
* Then measures the offset from the end date to the next/previous fiscal year end.
*/
export default class FactFiscalCalculator {
private readonly endDateByYear;
private readonly fiscalsByEndDate;
private readonly datesByFiscals;
private readonly startDateCountMap;
private readonly endDateCountMap;
private readonly filedDateCountByEndDate;
private didResolve;
private readonly fiscalYearEnd;
constructor(params?: {
facts?: Pick<FactItem, 'end' | 'filed' | 'start'>[];
filings?: Pick<FilingListItemTranslated, 'form' | 'reportDate' | 'filingDate' | 'accessionNumber'>[];
fiscalYearEnd?: {
month: number;
day: number;
} | null;
});
private useFilingsForDates;
add(fact: {
end: string;
filed: string;
start?: string;
}): void;
private getDaysBefore;
setReportDates(params: SetReportDatesParams): void;
addAnnualReportDate(reportDate: string): void;
private isAnnualReportFact;
private resolve;
getDatesByYearQuarter(params: {
year: number;
quarter: number;
}): {
filed: string;
end: string;
} | null;
/**
* Assumes year end from start dates if not provided
*/
private ensureEndDateByYear;
getFiscalYearQuarter(params: {
dateStr: string;
endDateByYear?: Map<number, Date>;
fiscalYearEnd?: {
month: number;
day: number;
} | null;
}): {
year: number;
quarter: number;
};
static getFiscalYearQuarter(params: {
dateStr: string;
endDateByYear?: Map<number, Date>;
fiscalYearEnd?: {
month: number;
day: number;
} | null;
}): {
quarter: number;
year: number;
};
}