@gloom-sh/terminal 0.20.5 → 0.20.7
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.
- package/README.md +1 -1
- package/README.zh-CN.md +1 -1
- package/package.json +2 -1
- package/src/api-client/data.ts +10 -2
- package/src/api-client/fund-facts.ts +20 -4
- package/src/api-client/hk-tenders.ts +59 -0
- package/src/api-client/index.ts +1 -0
- package/src/api-client/socket.ts +4 -4
- package/src/api-client/types/econ.ts +20 -2
- package/src/app.tsx +18 -13
- package/src/architecture/floating-promise-allowlist.json +313 -0
- package/src/architecture/shortcut-labels-allowlist.json +1 -0
- package/src/cli/commands/market.ts +197 -57
- package/src/cli/commands/news-search.ts +22 -7
- package/src/cli/commands/overview.ts +12 -6
- package/src/cli/commands/search.ts +19 -3
- package/src/cli/commands/ticker.ts +3 -1
- package/src/cli/desktop-pane-shot.ts +61 -0
- package/src/cli/early-command.ts +2 -0
- package/src/cli/errors.ts +10 -1
- package/src/cli/fx-forward.ts +76 -12
- package/src/cli/fx-pair.ts +1 -1
- package/src/cli/fx-quote-rate.ts +23 -0
- package/src/cli/help.ts +1 -0
- package/src/cli/index-roots.ts +5 -4
- package/src/cli/index.ts +40 -3
- package/src/cli/known-gaps.ts +11 -8
- package/src/cli/listing-arg.ts +6 -4
- package/src/cli/options.ts +52 -3
- package/src/cli/output-file.ts +5 -3
- package/src/cli/pane-functions/catalog.ts +15 -0
- package/src/cli/pane-functions/dom.ts +4 -4
- package/src/cli/pane-functions/freshness.ts +38 -5
- package/src/cli/pane-functions/function-help.ts +4 -4
- package/src/cli/pane-functions/headless.ts +9 -4
- package/src/cli/pane-functions/index.ts +6 -4
- package/src/cli/pane-functions/resolver.ts +2 -2
- package/src/cli/pane-functions/screenshot-assessment.ts +16 -4
- package/src/cli/quote-answer.ts +57 -1
- package/src/cli/result.ts +38 -2
- package/src/cli/spreadsheet-hint.ts +7 -3
- package/src/cli/treasury-yields.ts +5 -3
- package/src/components/chart/composite/legend.tsx +40 -2
- package/src/components/command-bar/workflow/tickers.ts +2 -2
- package/src/components/data-table/view.tsx +9 -2
- package/src/components/ui/data-table/opentui/index.tsx +11 -4
- package/src/components/ui/data-table/opentui/model.ts +8 -6
- package/src/components/ui/data-table/types.ts +6 -1
- package/src/components/ui/table-layout.ts +38 -1
- package/src/docs/snapshot.json +58 -19
- package/src/i18n/es.ts +2 -0
- package/src/i18n/ja.ts +2 -0
- package/src/i18n/ko.ts +2 -0
- package/src/i18n/zh-cn.ts +2 -0
- package/src/i18n/zh-tw.ts +2 -0
- package/src/market-data/market/change-basis.ts +57 -12
- package/src/market-data/market/dated-previous-close.ts +184 -10
- package/src/market-data/market/freshness.ts +18 -6
- package/src/market-data/market/status.ts +9 -1
- package/src/market-data/published-nse-sessions.ts +16 -1
- package/src/market-data/quotes/contributions.ts +2 -0
- package/src/market-data/quotes/freshness.ts +15 -0
- package/src/market-data/quotes/listing-enterprise-value.ts +50 -0
- package/src/plugins/builtin/alerts/alert-engine.ts +15 -0
- package/src/plugins/builtin/alerts/cli.ts +22 -9
- package/src/plugins/builtin/alerts/headless.ts +1 -1
- package/src/plugins/builtin/alerts/index.tsx +5 -1
- package/src/plugins/builtin/alerts/metric-command.ts +1 -1
- package/src/plugins/builtin/alerts/metric-data.ts +15 -2
- package/src/plugins/builtin/backtest/headless.ts +1 -1
- package/src/plugins/builtin/cds/model.ts +0 -6
- package/src/plugins/builtin/chart-composer/formula.ts +16 -3
- package/src/plugins/builtin/chart-composer/headless-schema.ts +2 -0
- package/src/plugins/builtin/chart-composer/headless.ts +2 -1
- package/src/plugins/builtin/chart-composer/presets.ts +1 -0
- package/src/plugins/builtin/cloud/askg/pane.tsx +55 -13
- package/src/plugins/builtin/credit-boards/cdx-pane.tsx +20 -7
- package/src/plugins/builtin/credit-boards/client.ts +8 -0
- package/src/plugins/builtin/credit-boards/headless.ts +4 -1
- package/src/plugins/builtin/credit-boards/model.ts +58 -4
- package/src/plugins/builtin/credit-boards/series.ts +63 -6
- package/src/plugins/builtin/credit-boards/sovr-pane.tsx +3 -2
- package/src/plugins/builtin/credit-conditions/headless.ts +24 -6
- package/src/plugins/builtin/credit-conditions/index.tsx +1 -1
- package/src/plugins/builtin/credit-conditions/model.ts +12 -6
- package/src/plugins/builtin/credit-conditions/series.ts +2 -1
- package/src/plugins/builtin/econ/calendar-model.ts +41 -7
- package/src/plugins/builtin/econ/calendar-source.ts +7 -1
- package/src/plugins/builtin/econ/index.tsx +41 -8
- package/src/plugins/builtin/econ/types.ts +3 -0
- package/src/plugins/builtin/fixed-income/index.tsx +2 -0
- package/src/plugins/builtin/fx-matrix/index.tsx +44 -14
- package/src/plugins/builtin/help/keybindings-editor.tsx +6 -2
- package/src/plugins/builtin/holders/fund-holders.ts +22 -1
- package/src/plugins/builtin/holders/headless.ts +5 -4
- package/src/plugins/builtin/holders/pane.tsx +7 -3
- package/src/plugins/builtin/holders/report-header.ts +23 -0
- package/src/plugins/builtin/members/client.ts +1 -1
- package/src/plugins/builtin/members/headless.ts +2 -0
- package/src/plugins/builtin/members/model.ts +10 -8
- package/src/plugins/builtin/members/pane.tsx +4 -1
- package/src/plugins/builtin/portfolio-list/cli/portfolio-command.ts +5 -2
- package/src/plugins/builtin/portfolio-list/cli/render.ts +86 -26
- package/src/plugins/builtin/portfolio-list/cli/watchlist-command.ts +5 -1
- package/src/plugins/builtin/portfolio-list/headless.ts +2 -1
- package/src/plugins/builtin/portfolio-list/income.ts +46 -22
- package/src/plugins/builtin/portfolio-list/pane/data.ts +16 -6
- package/src/plugins/builtin/portfolio-list/pane/index.tsx +5 -4
- package/src/plugins/builtin/portfolio-list/use-throttled-ticker-order.ts +40 -3
- package/src/plugins/builtin/research/headless-schema.ts +4 -3
- package/src/plugins/builtin/research/relative-valuation-columns.ts +145 -47
- package/src/plugins/builtin/research/relative-valuation-currency.ts +31 -0
- package/src/plugins/builtin/research/relative-valuation-headless.ts +25 -8
- package/src/plugins/builtin/research/relative-valuation-model.ts +40 -9
- package/src/plugins/builtin/research/relative-valuation-pane.tsx +3 -2
- package/src/plugins/builtin/research/relative-valuation-peers.ts +2 -2
- package/src/plugins/builtin/sec/fund-facts.ts +25 -5
- package/src/plugins/builtin/shared/report-freshness.ts +15 -6
- package/src/plugins/builtin/supply-chain/model.ts +18 -6
- package/src/plugins/builtin/thirteenf/api.ts +47 -4
- package/src/plugins/builtin/ticker-detail/data-panes/historical-prices.tsx +8 -7
- package/src/plugins/builtin/ticker-detail/data-panes/history-bars.ts +8 -5
- package/src/plugins/builtin/ticker-detail/financials/model.ts +6 -2
- package/src/plugins/builtin/ticker-detail/financials/tab.tsx +1 -1
- package/src/plugins/builtin/ticker-detail/headless.ts +6 -4
- package/src/plugins/builtin/treasury-auctions/cache.ts +36 -2
- package/src/plugins/builtin/treasury-auctions/headless.ts +42 -4
- package/src/plugins/builtin/treasury-auctions/hk-headless.ts +126 -0
- package/src/plugins/builtin/treasury-auctions/hk-view.tsx +347 -0
- package/src/plugins/builtin/treasury-auctions/hk.ts +363 -0
- package/src/plugins/builtin/treasury-auctions/index.tsx +14 -1
- package/src/plugins/builtin/treasury-auctions/model.ts +16 -8
- package/src/plugins/builtin/treasury-auctions/pane.tsx +45 -21
- package/src/portfolio/collection-name.ts +22 -0
- package/src/portfolio/column-values.ts +3 -0
- package/src/portfolio/valuation-basis.ts +23 -1
- package/src/renderers/dom/data-table/frozen-column.ts +3 -1
- package/src/renderers/dom/data-table/index.tsx +27 -9
- package/src/renderers/dom/data-table/row.tsx +2 -0
- package/src/renderers/electrobun/bun/desktop/backend.ts +27 -24
- package/src/renderers/electrobun/bun/desktop/detached-windows.ts +3 -3
- package/src/renderers/electrobun/bun/desktop/snapshot-commit.ts +77 -0
- package/src/renderers/electrobun/shared/protocol.ts +4 -0
- package/src/renderers/electrobun/view/backend-rpc.ts +3 -0
- package/src/renderers/electrobun/view/desktop/window/bridge.ts +3 -0
- package/src/sources/gloomberb-cloud/normalizers.ts +9 -5
- package/src/sources/provider-router/cache.ts +3 -1
- package/src/state/hooks/quote-streaming.ts +14 -6
- package/src/sync/controller.ts +17 -2
- package/src/sync/other-window-tabs.ts +32 -1
- package/src/sync/react.ts +4 -4
- package/src/tickers/instrument-kind.ts +22 -1
- package/src/tickers/search/index.ts +5 -0
- package/src/tickers/terminal-codes.ts +17 -5
- package/src/time-series/bar-spacing.ts +33 -0
- package/src/time-series/base-series.ts +21 -3
- package/src/time-series/chart-bounds.ts +31 -0
- package/src/time-series/field-catalog.ts +17 -0
- package/src/time-series/fundamentals/current-valuation.ts +244 -0
- package/src/time-series/fundamentals/historical-valuation.ts +99 -0
- package/src/time-series/fundamentals/metric-ids.ts +61 -0
- package/src/time-series/fundamentals/period-points.ts +104 -0
- package/src/time-series/fundamentals/quarterly-ttm.ts +220 -0
- package/src/time-series/fundamentals/series.ts +164 -0
- package/src/time-series/fundamentals/source-statements.ts +177 -0
- package/src/time-series/fundamentals/statement-fields.ts +154 -0
- package/src/time-series/fundamentals/statement-merge.ts +124 -0
- package/src/time-series/fundamentals/statement.ts +114 -0
- package/src/time-series/fundamentals/valuation-multiples.ts +50 -0
- package/src/time-series/fundamentals.ts +18 -1275
- package/src/time-series/ice-credit.ts +32 -6
- package/src/time-series/resolve.ts +9 -5
- package/src/time-series/session-bar.ts +78 -9
- package/src/time-series/studies/formula.ts +53 -10
- package/src/time-series/studies/pair.ts +18 -7
- package/src/time-series/studies/units.ts +49 -2
- package/src/time-series/types.ts +12 -0
- package/src/types/desktop-window.ts +2 -0
- package/src/types/financials.ts +15 -0
- package/src/types/headless.ts +8 -0
- package/src/utils/cli-output.ts +6 -3
- package/src/utils/debug-log.ts +29 -0
- package/src/utils/ebitda.ts +128 -0
- package/src/utils/format.ts +1 -1
- package/src/utils/shell-word.ts +13 -0
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
// Which fundamental and valuation metrics exist, and which of them read the live quote or the price history.
|
|
2
|
+
import { canonicalTimeSeriesFieldId } from "../field-catalog";
|
|
3
|
+
import type { SeriesPeriod } from "../types";
|
|
4
|
+
|
|
5
|
+
export const FUNDAMENTAL_IDS = new Set([
|
|
6
|
+
"totalRevenue",
|
|
7
|
+
"grossProfit",
|
|
8
|
+
"grossMargin",
|
|
9
|
+
"operatingIncome",
|
|
10
|
+
"operatingMargin",
|
|
11
|
+
"netIncome",
|
|
12
|
+
"netMargin",
|
|
13
|
+
"ebitda",
|
|
14
|
+
"depreciationAndAmortization",
|
|
15
|
+
"operatingCashFlow",
|
|
16
|
+
"freeCashFlow",
|
|
17
|
+
"freeCashFlowMargin",
|
|
18
|
+
"totalAssets",
|
|
19
|
+
"totalDebt",
|
|
20
|
+
"totalEquity",
|
|
21
|
+
"eps",
|
|
22
|
+
]);
|
|
23
|
+
|
|
24
|
+
export const VALUATION_IDS = new Set([
|
|
25
|
+
"trailingPE",
|
|
26
|
+
"forwardPE",
|
|
27
|
+
"realizedNtmPE",
|
|
28
|
+
"pegRatio",
|
|
29
|
+
"priceSales",
|
|
30
|
+
"evSales",
|
|
31
|
+
"evEbitda",
|
|
32
|
+
"priceFcf",
|
|
33
|
+
]);
|
|
34
|
+
|
|
35
|
+
/** Statement-based multiples whose latest point is the regular session price over the latest trailing period. */
|
|
36
|
+
export const QUOTE_DERIVED_VALUATION_IDS = new Set([
|
|
37
|
+
"trailingPE",
|
|
38
|
+
"priceSales",
|
|
39
|
+
"evSales",
|
|
40
|
+
"evEbitda",
|
|
41
|
+
"priceFcf",
|
|
42
|
+
]);
|
|
43
|
+
|
|
44
|
+
/** Multiples priced from history at each observation date; forward P/E also ends on the live quote. */
|
|
45
|
+
const PRICE_HISTORY_VALUATION_IDS = new Set([
|
|
46
|
+
...QUOTE_DERIVED_VALUATION_IDS,
|
|
47
|
+
"forwardPE",
|
|
48
|
+
"realizedNtmPE",
|
|
49
|
+
]);
|
|
50
|
+
|
|
51
|
+
/** Whether a valuation field derives a current point from the latest quote. */
|
|
52
|
+
export function valuationSeriesUsesLiveQuote(fieldId: string): boolean {
|
|
53
|
+
const [namespace, metric = ""] = canonicalTimeSeriesFieldId(fieldId).split(".");
|
|
54
|
+
return namespace === "valuation" && (QUOTE_DERIVED_VALUATION_IDS.has(metric) || metric === "forwardPE");
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** Whether a valuation field needs the full price history to date its observations. */
|
|
58
|
+
export function valuationSeriesUsesPriceHistory(fieldId: string, period?: SeriesPeriod): boolean {
|
|
59
|
+
const [namespace, metric = ""] = canonicalTimeSeriesFieldId(fieldId).split(".");
|
|
60
|
+
return namespace === "valuation" && (PRICE_HISTORY_VALUATION_IDS.has(metric) || (metric === "pegRatio" && period === "daily"));
|
|
61
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
// Turns a statement into a dated series point, and keeps one point per financial period.
|
|
2
|
+
import type { FinancialStatement } from "../../types/financials";
|
|
3
|
+
import { areNearbyFinancialPeriodEnds } from "../../utils/financial-statements";
|
|
4
|
+
import { fiscalPeriodLabel, ttmPeriodLabel } from "../../utils/fiscal-period";
|
|
5
|
+
import { hasStatementGap } from "../../utils/statement-gaps";
|
|
6
|
+
import type { SecuritySeriesSource, TimeSeriesPoint } from "../types";
|
|
7
|
+
import { validDate } from "./statement";
|
|
8
|
+
import { metricAvailability } from "./statement-fields";
|
|
9
|
+
|
|
10
|
+
export function pointForStatement(
|
|
11
|
+
statement: FinancialStatement,
|
|
12
|
+
metric: string,
|
|
13
|
+
value: number | null,
|
|
14
|
+
period: "annual" | "quarterly" | "ttm",
|
|
15
|
+
timestampMode: SecuritySeriesSource["timestampMode"],
|
|
16
|
+
derived: boolean,
|
|
17
|
+
/** The month the issuer's fiscal year ends; null names the period by its end date. */
|
|
18
|
+
yearEndMonth: number | null,
|
|
19
|
+
): TimeSeriesPoint | null {
|
|
20
|
+
const observedAt = validDate(statement.date);
|
|
21
|
+
if (!observedAt) return null;
|
|
22
|
+
// A missing metric is known to be unavailable with its statement. It has
|
|
23
|
+
// no metric-specific publication date to substitute for that boundary.
|
|
24
|
+
const availableAtString = metricAvailability(statement, metric)
|
|
25
|
+
?? (value === null ? statement.availableAt : undefined);
|
|
26
|
+
const availableAt = validDate(availableAtString);
|
|
27
|
+
const date = timestampMode !== "period-end" && availableAt ? availableAt : observedAt;
|
|
28
|
+
return {
|
|
29
|
+
date,
|
|
30
|
+
observedAt,
|
|
31
|
+
availableAt: availableAt ?? undefined,
|
|
32
|
+
value,
|
|
33
|
+
// Providers do not supply a reliable issuer fiscal-year/quarter identity.
|
|
34
|
+
// Calendar-month numbering would mislabel non-calendar fiscal years.
|
|
35
|
+
periodLabel: `${period === "annual" ? "Year" : period === "ttm" ? "TTM" : "Quarter"} ended ${statement.date}`,
|
|
36
|
+
// The period as FA's columns name it (`Q3 FY26`), which the legend prints beside the value.
|
|
37
|
+
fiscalPeriod: period === "ttm" ? ttmPeriodLabel(statement.date, yearEndMonth) : fiscalPeriodLabel(statement.date, period, yearEndMonth),
|
|
38
|
+
provenance: {
|
|
39
|
+
quality: derived || (metric === "eps" && statement.epsBasis?.factor !== undefined && statement.epsBasis.factor !== 1) ? "derived" : "reported",
|
|
40
|
+
...((metric === "eps" || metric === "trailingPE") && statement.epsBasis ? { secEpsBasis: statement.epsBasis } : {}),
|
|
41
|
+
...((metric === "eps" || metric === "trailingPE") && hasStatementGap(statement, "eps")
|
|
42
|
+
? { unavailableEarnings: ["eps" as const] } : {}),
|
|
43
|
+
currency: statement.currency,
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function preferredPeriodPoint(
|
|
49
|
+
existing: TimeSeriesPoint,
|
|
50
|
+
candidate: TimeSeriesPoint,
|
|
51
|
+
): TimeSeriesPoint {
|
|
52
|
+
if (existing.provenance?.quality !== candidate.provenance?.quality) {
|
|
53
|
+
return candidate.provenance?.quality === "reported" ? candidate : existing;
|
|
54
|
+
}
|
|
55
|
+
const existingAvailableAt = existing.availableAt?.getTime();
|
|
56
|
+
const candidateAvailableAt = candidate.availableAt?.getTime();
|
|
57
|
+
const existingHasAvailability = Number.isFinite(existingAvailableAt);
|
|
58
|
+
const candidateHasAvailability = Number.isFinite(candidateAvailableAt);
|
|
59
|
+
if (existingHasAvailability !== candidateHasAvailability) {
|
|
60
|
+
return candidateHasAvailability ? candidate : existing;
|
|
61
|
+
}
|
|
62
|
+
if (
|
|
63
|
+
existingHasAvailability
|
|
64
|
+
&& candidateHasAvailability
|
|
65
|
+
&& candidateAvailableAt! !== existingAvailableAt!
|
|
66
|
+
) {
|
|
67
|
+
const preferLater = !Object.is(existing.value, candidate.value);
|
|
68
|
+
const candidateWins = preferLater
|
|
69
|
+
? candidateAvailableAt! > existingAvailableAt!
|
|
70
|
+
: candidateAvailableAt! < existingAvailableAt!;
|
|
71
|
+
return candidateWins ? candidate : existing;
|
|
72
|
+
}
|
|
73
|
+
return candidate.observedAt.getTime() < existing.observedAt.getTime()
|
|
74
|
+
? candidate
|
|
75
|
+
: existing;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Provider snapshots can contain both an issuer fiscal-period row and a
|
|
80
|
+
* calendar-normalized row for the same observation. Their period ends and
|
|
81
|
+
* display timestamps differ slightly, so timestamp-only deduplication renders
|
|
82
|
+
* paired bars. A financial period is the observation identity; publication
|
|
83
|
+
* time only decides when that observation became available.
|
|
84
|
+
*/
|
|
85
|
+
export function dedupeFundamentalPeriods(points: readonly TimeSeriesPoint[]): TimeSeriesPoint[] {
|
|
86
|
+
const groups: TimeSeriesPoint[][] = [];
|
|
87
|
+
const sorted = [...points].sort((left, right) => (
|
|
88
|
+
left.observedAt.getTime() - right.observedAt.getTime()
|
|
89
|
+
));
|
|
90
|
+
for (const point of sorted) {
|
|
91
|
+
const lastGroup = groups.at(-1);
|
|
92
|
+
if (lastGroup && areNearbyFinancialPeriodEnds(lastGroup[0]!.observedAt, point.observedAt)
|
|
93
|
+
&& (lastGroup[0]!.observedAt.getTime() === point.observedAt.getTime()
|
|
94
|
+
|| ![point, ...lastGroup].some(item => item.provenance?.unavailableEarnings?.length))) {
|
|
95
|
+
lastGroup.push(point);
|
|
96
|
+
} else groups.push([point]);
|
|
97
|
+
}
|
|
98
|
+
return groups
|
|
99
|
+
.map((group) => group.slice(1).reduce(preferredPeriodPoint, group[0]!))
|
|
100
|
+
.sort((left, right) => (
|
|
101
|
+
left.date.getTime() - right.date.getTime()
|
|
102
|
+
|| left.observedAt.getTime() - right.observedAt.getTime()
|
|
103
|
+
));
|
|
104
|
+
}
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
// Derives fiscal fourth quarters from their year and builds trailing-twelve-month statements.
|
|
2
|
+
import type { FinancialStatement } from "../../types/financials";
|
|
3
|
+
import { areNearbyFinancialPeriodEnds, completeAvailability, statementFieldAvailability } from "../../utils/financial-statements";
|
|
4
|
+
import { hasStatementGap } from "../../utils/statement-gaps";
|
|
5
|
+
import { trailingEpsAcrossFiscalYearEnd } from "../../utils/trailing-eps";
|
|
6
|
+
import { isFiniteNumber } from "../../utils/guards";
|
|
7
|
+
import {
|
|
8
|
+
completeStatementAvailability,
|
|
9
|
+
DAY_MS,
|
|
10
|
+
type InternalStatement,
|
|
11
|
+
type NumericStatementField,
|
|
12
|
+
QUARTERLY_AVERAGE_FIELDS,
|
|
13
|
+
QUARTERLY_FLOW_FIELDS,
|
|
14
|
+
QUARTERLY_SNAPSHOT_FIELDS,
|
|
15
|
+
setStatementNumber,
|
|
16
|
+
statementNumber,
|
|
17
|
+
statementTime,
|
|
18
|
+
TTM_SUM_FIELDS,
|
|
19
|
+
} from "./statement";
|
|
20
|
+
import { mergeStatementsByPeriod } from "./statement-merge";
|
|
21
|
+
|
|
22
|
+
/** Internal calendar bucket for selecting adjacent inputs, not an issuer fiscal label. */
|
|
23
|
+
function calendarQuarterBucket(date: string): string {
|
|
24
|
+
const parsedYear = Number(date.slice(0, 4));
|
|
25
|
+
let year = Number.isFinite(parsedYear) ? parsedYear : 0;
|
|
26
|
+
|
|
27
|
+
let month = Number(date.slice(5, 7));
|
|
28
|
+
const day = Number(date.slice(8, 10));
|
|
29
|
+
if (Number.isFinite(month) && Number.isFinite(day) && day <= 7 && (month - 1) % 3 === 0) {
|
|
30
|
+
month -= 1;
|
|
31
|
+
if (month === 0) {
|
|
32
|
+
month = 12;
|
|
33
|
+
year -= 1;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
const quarter = Number.isFinite(month) && month > 0 ? Math.ceil(month / 3) : 0;
|
|
37
|
+
return quarter > 0 && year > 0 ? `${year} Q${quarter}` : date;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
interface PrecedingQuarterInput {
|
|
41
|
+
date: string;
|
|
42
|
+
time: number;
|
|
43
|
+
value: number;
|
|
44
|
+
availableAt?: string;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function precedingQuarterInputs(
|
|
48
|
+
quarterlyStatements: readonly FinancialStatement[],
|
|
49
|
+
annualStatement: FinancialStatement,
|
|
50
|
+
field: NumericStatementField,
|
|
51
|
+
): PrecedingQuarterInput[] {
|
|
52
|
+
const annualTime = statementTime(annualStatement);
|
|
53
|
+
if (!Number.isFinite(annualTime)) return [];
|
|
54
|
+
|
|
55
|
+
const annualCategory = calendarQuarterBucket(annualStatement.date);
|
|
56
|
+
const byCategory = new Map<string, PrecedingQuarterInput>();
|
|
57
|
+
for (const statement of quarterlyStatements) {
|
|
58
|
+
if (statement.currency !== annualStatement.currency) continue;
|
|
59
|
+
const time = statementTime(statement);
|
|
60
|
+
if (!Number.isFinite(time) || time >= annualTime || annualTime - time > 370 * DAY_MS) continue;
|
|
61
|
+
const category = calendarQuarterBucket(statement.date);
|
|
62
|
+
if (category === annualCategory) continue;
|
|
63
|
+
const value = statementNumber(statement, field);
|
|
64
|
+
if (value === null) continue;
|
|
65
|
+
const previous = byCategory.get(category);
|
|
66
|
+
if (!previous || statement.date.localeCompare(previous.date) > 0) {
|
|
67
|
+
byCategory.set(category, {
|
|
68
|
+
date: statement.date,
|
|
69
|
+
time,
|
|
70
|
+
value,
|
|
71
|
+
availableAt: statementFieldAvailability(statement, field),
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
return [...byCategory.values()]
|
|
77
|
+
.sort((left, right) => right.time - left.time)
|
|
78
|
+
.slice(0, 3)
|
|
79
|
+
.sort((left, right) => left.time - right.time);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Completes additive fiscal Q4 flows from the annual total and three reported
|
|
84
|
+
* quarters. EPS and weighted-average shares require reported quarter values;
|
|
85
|
+
* neither is an additive flow. Snapshots come from the annual balance sheet. Derived
|
|
86
|
+
* values become available only after the annual total and every quarterly
|
|
87
|
+
* input used in the derivation are public.
|
|
88
|
+
*/
|
|
89
|
+
export function deriveQuarterlyStatements(
|
|
90
|
+
quarterlyStatements: readonly FinancialStatement[],
|
|
91
|
+
annualStatements: readonly FinancialStatement[],
|
|
92
|
+
): FinancialStatement[] {
|
|
93
|
+
const mergedQuarterly = mergeStatementsByPeriod(quarterlyStatements);
|
|
94
|
+
const byDate = new Map(mergedQuarterly.map((statement) => [statement.date, { ...statement }]));
|
|
95
|
+
|
|
96
|
+
for (const annualStatement of mergeStatementsByPeriod(annualStatements)) {
|
|
97
|
+
let target: InternalStatement = byDate.get(annualStatement.date) ?? { date: annualStatement.date, currency: annualStatement.currency };
|
|
98
|
+
if (target.currency !== annualStatement.currency) continue;
|
|
99
|
+
let changed = false;
|
|
100
|
+
|
|
101
|
+
for (const field of QUARTERLY_FLOW_FIELDS) {
|
|
102
|
+
// A line unavailable for the fourth quarter stays a gap: the full year
|
|
103
|
+
// minus the other quarters would recreate the value a source withheld.
|
|
104
|
+
if (hasStatementGap(target, field) || mergedQuarterly.some((statement) => (
|
|
105
|
+
areNearbyFinancialPeriodEnds(statement.date, annualStatement.date) && hasStatementGap(statement, field)
|
|
106
|
+
))) continue;
|
|
107
|
+
if (statementNumber(target, field) !== null) continue;
|
|
108
|
+
const annualValue = statementNumber(annualStatement, field);
|
|
109
|
+
if (annualValue === null) continue;
|
|
110
|
+
const previousInputs = precedingQuarterInputs(mergedQuarterly, annualStatement, field);
|
|
111
|
+
if (previousInputs.length !== 3) continue;
|
|
112
|
+
const inputTimes = [...previousInputs.map((input) => input.time), statementTime(annualStatement)];
|
|
113
|
+
if (inputTimes.some((time, index) => index > 0 && (time - inputTimes[index - 1]! < 60 * DAY_MS || time - inputTimes[index - 1]! > 120 * DAY_MS))) continue;
|
|
114
|
+
const derived = annualValue - previousInputs.reduce((sum, input) => sum + input.value, 0);
|
|
115
|
+
if (!Number.isFinite(derived)) continue;
|
|
116
|
+
const availableAt = completeAvailability([
|
|
117
|
+
statementFieldAvailability(annualStatement, field),
|
|
118
|
+
...previousInputs.map((input) => input.availableAt),
|
|
119
|
+
]);
|
|
120
|
+
setStatementNumber(target, field, derived, availableAt);
|
|
121
|
+
changed = true;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
for (const field of QUARTERLY_SNAPSHOT_FIELDS) {
|
|
125
|
+
if (statementNumber(target, field) !== null) continue;
|
|
126
|
+
const annualValue = statementNumber(annualStatement, field);
|
|
127
|
+
if (annualValue === null) continue;
|
|
128
|
+
const availableAt = statementFieldAvailability(annualStatement, field);
|
|
129
|
+
setStatementNumber(target, field, annualValue, availableAt);
|
|
130
|
+
changed = true;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
if (changed) {
|
|
134
|
+
target.availableAt = completeStatementAvailability(target);
|
|
135
|
+
byDate.set(target.date, target);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
return mergeStatementsByPeriod([...byDate.values()]);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export function buildTtmStatements(
|
|
143
|
+
statements: readonly FinancialStatement[],
|
|
144
|
+
annualStatements: readonly FinancialStatement[],
|
|
145
|
+
): InternalStatement[] {
|
|
146
|
+
const sorted = mergeStatementsByPeriod(statements);
|
|
147
|
+
const annual = mergeStatementsByPeriod(annualStatements);
|
|
148
|
+
const result: InternalStatement[] = [];
|
|
149
|
+
for (let index = 3; index < sorted.length; index += 1) {
|
|
150
|
+
const window = sorted.slice(index - 3, index + 1);
|
|
151
|
+
const latest = window.at(-1)!;
|
|
152
|
+
const times = window.map(statementTime);
|
|
153
|
+
if (new Set(window.map((statement) => statement.currency)).size > 1
|
|
154
|
+
|| times.some((time, index) => !Number.isFinite(time) || (index > 0 && (time - times[index - 1]! < 60 * DAY_MS || time - times[index - 1]! > 120 * DAY_MS)))) {
|
|
155
|
+
// Retain the known period as a gap. Removing an incomplete window joins
|
|
156
|
+
// the last usable TTM observation to the first recovered one.
|
|
157
|
+
result.push({ date: latest.date, currency: latest.currency, availableAt: latest.availableAt,
|
|
158
|
+
__timeSeriesTtm: true });
|
|
159
|
+
continue;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
const ttm: InternalStatement = {
|
|
163
|
+
date: latest.date,
|
|
164
|
+
currency: latest.currency,
|
|
165
|
+
fieldAvailability: {},
|
|
166
|
+
__timeSeriesTtm: true,
|
|
167
|
+
__timeSeriesDerivedFields: [],
|
|
168
|
+
};
|
|
169
|
+
const unresolvedEps = window.find((statement) => statement.epsBasis?.status === "unresolved");
|
|
170
|
+
if (unresolvedEps) ttm.epsBasis = unresolvedEps.epsBasis;
|
|
171
|
+
const commonIncomeCount = window.filter((statement) => isFiniteNumber(statement.netIncomeCommonStockholders)).length;
|
|
172
|
+
// Known common claims in some quarters cannot be ignored by substituting
|
|
173
|
+
// aggregate income for the entire window or only its missing quarters.
|
|
174
|
+
if ((commonIncomeCount > 0 && commonIncomeCount < window.length)
|
|
175
|
+
|| window.some(statement => statement.unavailableFields?.includes("netIncomeCommonStockholders"))) ttm.__timeSeriesIncompleteCommonIncome = true;
|
|
176
|
+
const hasAverageShareInputs = window.some(statement => QUARTERLY_AVERAGE_FIELDS
|
|
177
|
+
.some(field => statementNumber(statement, field) !== null));
|
|
178
|
+
const hasCompleteAverageShares = QUARTERLY_AVERAGE_FIELDS.some(field => window.every(statement => {
|
|
179
|
+
const value = statementNumber(statement, field);
|
|
180
|
+
return value !== null && value > 0;
|
|
181
|
+
}));
|
|
182
|
+
// A missing quarter cannot replace a known weighted-period denominator
|
|
183
|
+
// with a year-end ordinary/issued-share snapshot. Capitalization may still
|
|
184
|
+
// use the snapshot; this guard is specific to the fallback earnings ratio.
|
|
185
|
+
if (hasAverageShareInputs && !hasCompleteAverageShares) ttm.__timeSeriesIncompleteAverageShares = true;
|
|
186
|
+
|
|
187
|
+
for (const field of [...TTM_SUM_FIELDS, ...QUARTERLY_AVERAGE_FIELDS]) {
|
|
188
|
+
const values = window.map((statement) => statementNumber(statement, field));
|
|
189
|
+
if (!values.every((value): value is number => value !== null)) continue;
|
|
190
|
+
if (QUARTERLY_AVERAGE_FIELDS.includes(field) && !values.every(value => value > 0)) continue;
|
|
191
|
+
(ttm as unknown as Record<string, unknown>)[field] = values.reduce((sum, value) => sum + value, 0)
|
|
192
|
+
/ (QUARTERLY_AVERAGE_FIELDS.includes(field) ? 4 : 1);
|
|
193
|
+
ttm.__timeSeriesDerivedFields!.push(field);
|
|
194
|
+
const availableAt = completeAvailability(window.map((statement) => (
|
|
195
|
+
statementFieldAvailability(statement, field)
|
|
196
|
+
)));
|
|
197
|
+
if (availableAt) ttm.fieldAvailability![field] = availableAt;
|
|
198
|
+
}
|
|
199
|
+
// A fiscal Q4 the 10-K reports only inside its year: the year's EPS plus the quarters since, less the same quarters a year earlier.
|
|
200
|
+
const acrossYearEnd = statementNumber(ttm, "eps") === null && !unresolvedEps
|
|
201
|
+
? trailingEpsAcrossFiscalYearEnd(window, sorted, annual, "eps") : null;
|
|
202
|
+
if (acrossYearEnd) {
|
|
203
|
+
ttm.eps = acrossYearEnd.value;
|
|
204
|
+
ttm.__timeSeriesDerivedFields!.push("eps");
|
|
205
|
+
const availableAt = completeAvailability(acrossYearEnd.inputs.map((statement) => statementFieldAvailability(statement, "eps")));
|
|
206
|
+
if (availableAt) ttm.fieldAvailability!.eps = availableAt;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
for (const field of QUARTERLY_SNAPSHOT_FIELDS) {
|
|
210
|
+
const value = statementNumber(latest, field);
|
|
211
|
+
if (value === null) continue;
|
|
212
|
+
(ttm as unknown as Record<string, unknown>)[field] = value;
|
|
213
|
+
const availableAt = statementFieldAvailability(latest, field);
|
|
214
|
+
if (availableAt) ttm.fieldAvailability![field] = availableAt;
|
|
215
|
+
}
|
|
216
|
+
ttm.availableAt = completeStatementAvailability(ttm) ?? latest.availableAt;
|
|
217
|
+
result.push(ttm);
|
|
218
|
+
}
|
|
219
|
+
return result;
|
|
220
|
+
}
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
// Extracts a fundamental or valuation series from a ticker's financials, with the warnings and issues that explain it.
|
|
2
|
+
import type { TickerFinancials } from "../../types/financials";
|
|
3
|
+
import { fiscalYearEndMonth } from "../../utils/fiscal-period";
|
|
4
|
+
import { canonicalTimeSeriesFieldId, getTimeSeriesField } from "../field-catalog";
|
|
5
|
+
import { dailyForwardPeHistory, forwardPeHistory, realizedNtmPeHistory } from "../forward-valuation";
|
|
6
|
+
import { reportingCurrencySeries } from "../reporting-currency";
|
|
7
|
+
import { createValuationCurrencyContext } from "../valuation-currency";
|
|
8
|
+
import { valuationPriceAtOrBefore, valuationQuoteIssue, type ValuationPriceIssue } from "../valuation-price";
|
|
9
|
+
import type { SecuritySeriesSource, TimeSeriesPoint } from "../types";
|
|
10
|
+
import { isBankOrInsurerIndustry } from "../../utils/ebitda";
|
|
11
|
+
import { currentDerivedValuationPoint, currentValuationStatements, providerCurrentValuationPoint } from "./current-valuation";
|
|
12
|
+
import { dailyStatementValuation, dailyValuationFallbackPeriod, historicalValuation } from "./historical-valuation";
|
|
13
|
+
import { FUNDAMENTAL_IDS, QUOTE_DERIVED_VALUATION_IDS, VALUATION_IDS, valuationSeriesUsesLiveQuote } from "./metric-ids";
|
|
14
|
+
import { dedupeFundamentalPeriods, pointForStatement } from "./period-points";
|
|
15
|
+
import { sourceStatements } from "./source-statements";
|
|
16
|
+
import { fundamentalValue, metricAvailability } from "./statement-fields";
|
|
17
|
+
import { valuationAtPrice } from "./valuation-multiples";
|
|
18
|
+
|
|
19
|
+
/** Extracts the selected statement snapshot, retaining known availability dates without reconstructing prior vintages. */
|
|
20
|
+
export function extractFundamentalSeries(
|
|
21
|
+
financials: TickerFinancials | null,
|
|
22
|
+
source: SecuritySeriesSource,
|
|
23
|
+
): TimeSeriesPoint[] {
|
|
24
|
+
if (!financials) return [];
|
|
25
|
+
const canonicalId = canonicalTimeSeriesFieldId(source.fieldId);
|
|
26
|
+
const [namespace, metric = ""] = canonicalId.split(".");
|
|
27
|
+
if (namespace === "fundamental" && FUNDAMENTAL_IDS.has(metric)) {
|
|
28
|
+
const selected = sourceStatements(financials, source.period);
|
|
29
|
+
const yearEndMonth = fiscalYearEndMonth(financials.annualStatements);
|
|
30
|
+
let hasObservation = false;
|
|
31
|
+
const points = selected.statements.flatMap((statement) => {
|
|
32
|
+
const result = fundamentalValue(statement, metric);
|
|
33
|
+
if (result.value !== null) hasObservation = true;
|
|
34
|
+
const point = pointForStatement(
|
|
35
|
+
statement,
|
|
36
|
+
metric,
|
|
37
|
+
result.value,
|
|
38
|
+
selected.period,
|
|
39
|
+
source.timestampMode,
|
|
40
|
+
result.derived,
|
|
41
|
+
yearEndMonth,
|
|
42
|
+
);
|
|
43
|
+
return point ? [point] : [];
|
|
44
|
+
});
|
|
45
|
+
if (!hasObservation) return [];
|
|
46
|
+
const deduped = dedupeFundamentalPeriods(points);
|
|
47
|
+
return getTimeSeriesField(canonicalId)?.unit.startsWith("currency")
|
|
48
|
+
? reportingCurrencySeries(deduped, financials.financialCurrency).points : deduped;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if (namespace !== "valuation" || !VALUATION_IDS.has(metric)) return [];
|
|
52
|
+
// A bank's or an insurer's EBITDA measures nothing: its EV/EBITDA is N/M throughout (valuationNotMeaningful).
|
|
53
|
+
if (metric === "evEbitda" && isBankOrInsurerIndustry(financials.profile?.industry)) return [];
|
|
54
|
+
const fallback = dailyValuationFallbackPeriod(financials, source);
|
|
55
|
+
if (fallback) return extractFundamentalSeries(financials, { ...source, period: fallback });
|
|
56
|
+
if (source.period === "daily" && metric !== "realizedNtmPE") {
|
|
57
|
+
if (metric !== "forwardPE") return dailyStatementValuation(financials, metric, source.instrument.exchange);
|
|
58
|
+
const points = dailyForwardPeHistory(financials, createValuationCurrencyContext(financials), source.instrument.exchange);
|
|
59
|
+
if (points.some((point) => point.value !== null)) return points;
|
|
60
|
+
const current = providerCurrentValuationPoint(financials, metric);
|
|
61
|
+
return current ? [current] : [];
|
|
62
|
+
}
|
|
63
|
+
if (metric === "forwardPE") {
|
|
64
|
+
const points = forwardPeHistory(financials, createValuationCurrencyContext(financials));
|
|
65
|
+
if (points.length > 0) return points;
|
|
66
|
+
// Without an estimate history the provider's own figure is all there is.
|
|
67
|
+
const current = providerCurrentValuationPoint(financials, metric);
|
|
68
|
+
return current ? [current] : [];
|
|
69
|
+
}
|
|
70
|
+
if (metric === "realizedNtmPE") {
|
|
71
|
+
return realizedNtmPeHistory(financials, createValuationCurrencyContext(financials));
|
|
72
|
+
}
|
|
73
|
+
if (metric === "pegRatio") {
|
|
74
|
+
const current = providerCurrentValuationPoint(financials, metric);
|
|
75
|
+
return current ? [current] : [];
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const selected = sourceStatements(financials, source.period, metric);
|
|
79
|
+
const currencies = createValuationCurrencyContext(financials);
|
|
80
|
+
const yearEndMonth = fiscalYearEndMonth(financials.annualStatements);
|
|
81
|
+
let hasHistoricalObservation = false;
|
|
82
|
+
const historical = selected.statements.flatMap((statement) => {
|
|
83
|
+
const historical = historicalValuation(financials, statement, metric, currencies);
|
|
84
|
+
if (historical !== null) hasHistoricalObservation = true;
|
|
85
|
+
const point = pointForStatement(
|
|
86
|
+
statement,
|
|
87
|
+
metric,
|
|
88
|
+
historical?.value ?? null,
|
|
89
|
+
selected.period,
|
|
90
|
+
source.timestampMode,
|
|
91
|
+
true,
|
|
92
|
+
yearEndMonth,
|
|
93
|
+
);
|
|
94
|
+
if (point && historical?.integrity) point.provenance = { ...point.provenance, priceHistoryIntegrity: historical.integrity };
|
|
95
|
+
if (point && historical?.issue) point.provenance = { ...point.provenance,
|
|
96
|
+
valuationPriceIssues: [{ ...historical.issue, affectedAt: point.date.toISOString() }] };
|
|
97
|
+
return point ? [point] : [];
|
|
98
|
+
});
|
|
99
|
+
const current = currentDerivedValuationPoint(financials, currentValuationStatements(financials, selected, metric), metric, currencies);
|
|
100
|
+
if (!hasHistoricalObservation && !current) return [];
|
|
101
|
+
const dedupedHistorical = dedupeFundamentalPeriods(historical);
|
|
102
|
+
// Publication timestamps can be shared by distinct fiscal periods. Their
|
|
103
|
+
// period identities were deduplicated above; a gap must not overwrite a
|
|
104
|
+
// different period's usable observation released on the same date.
|
|
105
|
+
return (current ? [...dedupedHistorical, current] : dedupedHistorical).sort((left, right) => (
|
|
106
|
+
left.date.getTime() - right.date.getTime() || left.observedAt.getTime() - right.observedAt.getTime()
|
|
107
|
+
));
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* The period a fundamental series asks for that its company reports no figure
|
|
112
|
+
* of, though it reports annual ones: `quarterly` for an issuer that reports
|
|
113
|
+
* twice a year. Null for any other series, and when the annual figures are as
|
|
114
|
+
* missing as the quarterly ones.
|
|
115
|
+
*/
|
|
116
|
+
export function unreportedStatementPeriod(
|
|
117
|
+
financials: TickerFinancials,
|
|
118
|
+
source: SecuritySeriesSource,
|
|
119
|
+
): "quarterly" | null {
|
|
120
|
+
if (source.period !== "quarterly" || !canonicalTimeSeriesFieldId(source.fieldId).startsWith("fundamental.")) return null;
|
|
121
|
+
return extractFundamentalSeries(financials, { ...source, period: "annual" }).length > 0 ? "quarterly" : null;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export function fundamentalSeriesUsesAvailabilityFallback(
|
|
125
|
+
financials: TickerFinancials | null,
|
|
126
|
+
source: SecuritySeriesSource,
|
|
127
|
+
): boolean {
|
|
128
|
+
if (!financials || source.timestampMode === "period-end") return false;
|
|
129
|
+
// A gap has no value to place, so it has no date to fall back for.
|
|
130
|
+
const points = extractFundamentalSeries(financials, source);
|
|
131
|
+
return points.some((point) => point.value != null && point.availableAt === undefined);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/** Explains withheld currency-dependent values through chart and export metadata. */
|
|
135
|
+
export function valuationCurrencyWarning(financials: TickerFinancials, source: SecuritySeriesSource): string | undefined {
|
|
136
|
+
const [namespace, metric = ""] = canonicalTimeSeriesFieldId(source.fieldId).split(".");
|
|
137
|
+
if (namespace !== "valuation" || !QUOTE_DERIVED_VALUATION_IDS.has(metric)) return undefined;
|
|
138
|
+
const selected = sourceStatements(financials, source.period, metric);
|
|
139
|
+
return createValuationCurrencyContext(financials).warning(selected.statements.filter((row) => (
|
|
140
|
+
valuationAtPrice(row, metric, 1) !== null
|
|
141
|
+
)));
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/** Structured failures preserve source values independently of the chart's ratios. */
|
|
145
|
+
export function valuationPriceIssues(financials: TickerFinancials, source: SecuritySeriesSource): ValuationPriceIssue[] {
|
|
146
|
+
if (source.period === "daily" && canonicalTimeSeriesFieldId(source.fieldId).startsWith("valuation.")) {
|
|
147
|
+
return extractFundamentalSeries(financials, source).flatMap((point) => point.provenance?.valuationPriceIssues ?? []);
|
|
148
|
+
}
|
|
149
|
+
if (!valuationSeriesUsesLiveQuote(source.fieldId)) return [];
|
|
150
|
+
const metric = canonicalTimeSeriesFieldId(source.fieldId).split(".")[1]!;
|
|
151
|
+
const currencies = createValuationCurrencyContext(financials);
|
|
152
|
+
const selected = sourceStatements(financials, source.period, metric);
|
|
153
|
+
const rows = selected.statements.filter((row) => (
|
|
154
|
+
currencies.priceInStatementUnits(row, 1) !== null && valuationAtPrice(row, metric, 1) !== null
|
|
155
|
+
));
|
|
156
|
+
if (!rows.length) return [];
|
|
157
|
+
const quoteIssue = valuationQuoteIssue(financials.quote);
|
|
158
|
+
const issues = rows.flatMap((row) => {
|
|
159
|
+
const price = valuationPriceAtOrBefore(financials.priceHistory, metricAvailability(row, metric) ?? row.date);
|
|
160
|
+
const date = pointForStatement(row, metric, null, selected.period, source.timestampMode, true, null)?.date;
|
|
161
|
+
return price?.issue && date ? [{ ...price.issue, affectedAt: date.toISOString() }] : [];
|
|
162
|
+
});
|
|
163
|
+
return [...(quoteIssue ? [quoteIssue] : []), ...new Map(issues.map((issue) => [JSON.stringify(issue), issue])).values()];
|
|
164
|
+
}
|