Expand financials surfaces with ratios, KPIs, and cadence support

- Add bundled financial modeling pipeline (ratios, KPI dimensions/notes, trend series, standardization)
- Introduce company financial bundles storage (Drizzle migration + repo wiring)
- Refactor financials page/API/query flow to use surfaceKind + cadence and new response shapes
This commit is contained in:
2026-03-07 15:16:35 -05:00
parent a42622ba6e
commit db01f207a5
33 changed files with 3589 additions and 1643 deletions

View File

@@ -200,6 +200,18 @@ export type CompanyFinancialPoint = {
export type FinancialStatementKind = 'income' | 'balance' | 'cash_flow' | 'equity' | 'comprehensive_income';
export type FinancialHistoryWindow = '10y' | 'all';
export type FinancialCadence = 'annual' | 'quarterly' | 'ltm';
export type FinancialDisplayMode = 'faithful' | 'standardized';
export type FinancialSurfaceKind =
| 'income_statement'
| 'balance_sheet'
| 'cash_flow_statement'
| 'ratios'
| 'segments_kpis'
| 'adjusted'
| 'custom_metrics';
export type FinancialUnit = 'currency' | 'count' | 'shares' | 'percent' | 'ratio';
export type FinancialCategory = string;
export type FinancialStatementPeriod = {
id: string;
@@ -236,21 +248,46 @@ export type TaxonomyStatementRow = {
sourceFactIds: number[];
};
export type FinancialStatementSurfaceKind = 'faithful' | 'standardized';
export type FinancialStatementSurfaceKind = FinancialDisplayMode;
export type StandardizedStatementRow = {
export type DerivedFinancialRow = {
key: string;
label: string;
category: string;
category: FinancialCategory;
order: number;
unit: FinancialUnit;
values: Record<string, number | null>;
hasDimensions: boolean;
sourceConcepts: string[];
sourceRowKeys: string[];
sourceFactIds: number[];
formulaKey: string | null;
hasDimensions: boolean;
resolvedSourceRowKeys: Record<string, string | null>;
};
export type StandardizedFinancialRow = DerivedFinancialRow;
export type StandardizedStatementRow = StandardizedFinancialRow;
export type RatioRow = DerivedFinancialRow & {
denominatorKey: string | null;
};
export type StructuredKpiRow = {
key: string;
label: string;
category: FinancialCategory;
unit: FinancialUnit;
order: number;
segment: string | null;
axis: string | null;
member: string | null;
values: Record<string, number | null>;
sourceConcepts: string[];
sourceFactIds: number[];
provenanceType: 'taxonomy' | 'structured_note';
hasDimensions: boolean;
};
export type TaxonomyFactRow = {
id: number;
snapshotId: number;
@@ -315,11 +352,15 @@ export type DimensionBreakdownRow = {
member: string;
value: number | null;
unit: string | null;
provenanceType?: 'taxonomy' | 'structured_note';
};
export type FinancialStatementSurface<Row> = {
kind: FinancialStatementSurfaceKind;
rows: Row[];
export type TrendSeries = {
key: string;
label: string;
category: FinancialCategory;
unit: FinancialUnit;
values: Record<string, number | null>;
};
export type CompanyFinancialStatementsResponse = {
@@ -328,13 +369,26 @@ export type CompanyFinancialStatementsResponse = {
companyName: string;
cik: string | null;
};
statement: FinancialStatementKind;
window: FinancialHistoryWindow;
defaultSurface: FinancialStatementSurfaceKind;
surfaceKind: FinancialSurfaceKind;
cadence: FinancialCadence;
displayModes: FinancialDisplayMode[];
defaultDisplayMode: FinancialDisplayMode;
periods: FinancialStatementPeriod[];
surfaces: {
faithful: FinancialStatementSurface<TaxonomyStatementRow>;
standardized: FinancialStatementSurface<StandardizedStatementRow>;
statementRows: {
faithful: TaxonomyStatementRow[];
standardized: StandardizedFinancialRow[];
} | null;
ratioRows: RatioRow[] | null;
kpiRows: StructuredKpiRow[] | null;
trendSeries: TrendSeries[];
categories: Array<{
key: FinancialCategory;
label: string;
count: number;
}>;
availability: {
adjusted: boolean;
customMetrics: boolean;
};
nextCursor: string | null;
facts: {
@@ -355,28 +409,6 @@ export type CompanyFinancialStatementsResponse = {
pendingFilings: number;
queuedSync: boolean;
};
overviewMetrics: {
referencePeriodId: string | null;
referenceDate: string | null;
latest: {
revenue: number | null;
netIncome: number | null;
totalAssets: number | null;
cash: number | null;
debt: number | null;
};
series: Array<{
periodId: string;
filingDate: string;
periodEnd: string | null;
label: string;
revenue: number | null;
netIncome: number | null;
totalAssets: number | null;
cash: number | null;
debt: number | null;
}>;
};
metrics: {
taxonomy: Filing['metrics'];
validation: MetricValidationResult | null;