@gloom-sh/terminal 0.20.22 → 0.20.23
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/package.json +1 -1
- package/src/account/heard-from-question.tsx +6 -4
- package/src/account/heard-from.ts +3 -4
- package/src/api-client/exchange-announcements.ts +2 -2
- package/src/api-client/heard-from.ts +5 -7
- package/src/api-client/ownership-disclosures.ts +38 -5
- package/src/api-client/types/ticker-data.ts +3 -1
- package/src/architecture/dom-cell-metrics-allowlist.json +2 -2
- package/src/cli/commands/market.ts +5 -3
- package/src/cli/commands/overview.ts +7 -9
- package/src/cli/listing-arg.ts +45 -18
- package/src/cli/pane-functions/catalog-snapshot.json +2 -2
- package/src/cli/pane-functions/data.ts +3 -1
- package/src/cli/pane-functions/freshness.ts +6 -1
- package/src/cli/pane-functions/function-help.ts +0 -2
- package/src/cli/pane-functions/market-session.ts +12 -2
- package/src/cli/pane-functions/screenshot-payload.ts +3 -1
- package/src/cli/symbol-list.ts +52 -14
- package/src/cli/ticker-resolution.ts +133 -38
- package/src/components/chart/composite/composite-chart.tsx +12 -0
- package/src/components/chart/composite/types.ts +18 -0
- package/src/components/chart/composite/use-composite-chart-keyboard.ts +38 -15
- package/src/components/chart-table/header.tsx +11 -5
- package/src/components/chart-table/selection.ts +20 -1
- package/src/components/data-table/view.tsx +2 -0
- package/src/components/feed-data-table/stack-view.tsx +85 -5
- package/src/components/layout/pane/header.tsx +12 -30
- package/src/components/ticker/badge/index.tsx +9 -4
- package/src/components/ticker/badge/list.tsx +3 -1
- package/src/components/ui/data-table/index.tsx +7 -1
- package/src/components/ui/data-table/muted-row.tsx +47 -0
- package/src/components/ui/data-table/opentui/index.tsx +42 -11
- package/src/components/ui/data-table/spill.ts +36 -0
- package/src/components/ui/data-table/types.ts +17 -1
- package/src/components/ui/data-table/use-column-order.ts +11 -0
- package/src/components/ui/icon.tsx +50 -3
- package/src/components/ui/list-view.tsx +2 -2
- package/src/components/ui/table-layout.ts +32 -0
- package/src/components/ui/terminal-hover-label.tsx +49 -0
- package/src/components/use-pinned-moment.ts +222 -13
- package/src/core/state/app/state.ts +11 -2
- package/src/core/state/app/types.ts +2 -1
- package/src/data/sqlite/access.ts +14 -1
- package/src/data/sqlite/checkpointer.ts +2 -2
- package/src/data/sqlite/database.ts +4 -0
- package/src/docs/snapshot.json +180 -26
- package/src/i18n/es.ts +1 -0
- package/src/i18n/ja.ts +1 -0
- package/src/i18n/ko.ts +1 -0
- package/src/i18n/zh-cn.ts +1 -0
- package/src/i18n/zh-tw.ts +1 -0
- package/src/market-data/market/freshness.ts +2 -2
- package/src/market-data/market/globex-day.ts +14 -0
- package/src/market-data/published-us-sessions.ts +3 -2
- package/src/market-data/quotes/live-valuation.ts +4 -2
- package/src/market-data/quotes/metadata.ts +48 -5
- package/src/market-data/quotes/regular-session-valuation.ts +12 -1
- package/src/plugins/builtin/alerts/history-pane.tsx +19 -3
- package/src/plugins/builtin/broker-trading/orders.tsx +4 -2
- package/src/plugins/builtin/chat/attachments/desktop.tsx +46 -12
- package/src/plugins/builtin/chat/channels.ts +5 -2
- package/src/plugins/builtin/chat/content/composer-runtime.ts +64 -65
- package/src/plugins/builtin/chat/content/footer.tsx +17 -7
- package/src/plugins/builtin/chat/content/index.tsx +108 -36
- package/src/plugins/builtin/chat/content/new-dm-dialog.tsx +21 -8
- package/src/plugins/builtin/chat/content/selection-runtime.ts +16 -0
- package/src/plugins/builtin/chat/content/shortcuts.ts +3 -0
- package/src/plugins/builtin/chat/content/snapshot.ts +37 -13
- package/src/plugins/builtin/chat/content/transcript.tsx +12 -0
- package/src/plugins/builtin/chat/content/types.ts +2 -0
- package/src/plugins/builtin/chat/controller/channels.ts +15 -15
- package/src/plugins/builtin/chat/controller/index.ts +140 -34
- package/src/plugins/builtin/chat/controller/lifecycle.ts +8 -12
- package/src/plugins/builtin/chat/controller/persistence.ts +32 -4
- package/src/plugins/builtin/chat/controller/send.ts +41 -17
- package/src/plugins/builtin/chat/controller/session-runtime.ts +28 -27
- package/src/plugins/builtin/chat/controller/state.ts +17 -8
- package/src/plugins/builtin/chat/controller/storage.ts +41 -4
- package/src/plugins/builtin/chat/controller/view.ts +6 -3
- package/src/plugins/builtin/chat/index.tsx +1 -1
- package/src/plugins/builtin/chat/layout.ts +8 -1
- package/src/plugins/builtin/chat/message/desktop.tsx +15 -11
- package/src/plugins/builtin/chat/message/header.tsx +112 -30
- package/src/plugins/builtin/chat/message/reactions.tsx +10 -11
- package/src/plugins/builtin/chat/message/render-state.ts +4 -2
- package/src/plugins/builtin/chat/message/terminal.tsx +13 -15
- package/src/plugins/builtin/chat/message/types.ts +5 -0
- package/src/plugins/builtin/cloud-tweets/table.tsx +25 -2
- package/src/plugins/builtin/company-kpis/model.ts +11 -3
- package/src/plugins/builtin/correlation/compute.ts +6 -1
- package/src/plugins/builtin/custom-view/loader.ts +95 -34
- package/src/plugins/builtin/custom-view/pane.tsx +31 -41
- package/src/plugins/builtin/custom-view/table.ts +201 -0
- package/src/plugins/builtin/dividend-yield/client.ts +14 -17
- package/src/plugins/builtin/dividend-yield/headless.ts +0 -1
- package/src/plugins/builtin/dividend-yield/model.ts +45 -6
- package/src/plugins/builtin/dividend-yield/pane.tsx +70 -7
- package/src/plugins/builtin/dividend-yield/types.ts +2 -3
- package/src/plugins/builtin/dividend-yield/view.ts +22 -2
- package/src/plugins/builtin/econ/calendar-model.ts +135 -0
- package/src/plugins/builtin/econ/columns.ts +132 -0
- package/src/plugins/builtin/econ/index.tsx +25 -65
- package/src/plugins/builtin/holders/disclosures-view.tsx +9 -6
- package/src/plugins/builtin/holders/disclosures.ts +20 -6
- package/src/plugins/builtin/holders/headless.ts +2 -2
- package/src/plugins/builtin/ipo-calendar/model.ts +30 -1
- package/src/plugins/builtin/ipo-calendar/pane.tsx +7 -3
- package/src/plugins/builtin/kelly-sizer/headless.ts +9 -4
- package/src/plugins/builtin/kelly-sizer/pane.tsx +19 -9
- package/src/plugins/builtin/kelly-sizer/units.ts +26 -0
- package/src/plugins/builtin/market-halts/pane.tsx +14 -2
- package/src/plugins/builtin/news/wire/news/row.ts +5 -12
- package/src/plugins/builtin/news/wire/news/table.tsx +32 -41
- package/src/plugins/builtin/pe-band/headless.ts +1 -1
- package/src/plugins/builtin/pe-band/model.ts +41 -18
- package/src/plugins/builtin/pe-band/pane.tsx +6 -5
- package/src/plugins/builtin/perps/equity-row.tsx +4 -6
- package/src/plugins/builtin/perps/markets-section.tsx +19 -15
- package/src/plugins/builtin/perps/model.ts +10 -2
- package/src/plugins/builtin/portfolio-list/cli/import-positions.ts +6 -18
- package/src/plugins/builtin/portfolio-list/cli/portfolio-command.ts +1 -1
- package/src/plugins/builtin/portfolio-list/pane/purchase-date-fx.ts +1 -1
- package/src/plugins/builtin/portfolio-list/positions-import/index.tsx +1 -1
- package/src/plugins/builtin/portfolio-list/positions-import/lookup.ts +28 -57
- package/src/plugins/builtin/research/event-data.ts +3 -1
- package/src/plugins/builtin/research/event-model.ts +17 -15
- package/src/plugins/builtin/research/relative-valuation-columns.ts +19 -6
- package/src/plugins/builtin/research/relative-valuation-headless.ts +1 -1
- package/src/plugins/builtin/scanner/flow-pane.tsx +10 -0
- package/src/plugins/builtin/sec/exchange-filings.ts +32 -7
- package/src/plugins/builtin/sec/headless.ts +8 -8
- package/src/plugins/builtin/sec/index.tsx +69 -29
- package/src/plugins/builtin/shared/report-freshness.ts +4 -1
- package/src/plugins/builtin/ticker-detail/financials/aggregation.ts +1 -2
- package/src/plugins/builtin/ticker-detail/financials/exchange-table.tsx +61 -0
- package/src/plugins/builtin/ticker-detail/financials/model.ts +38 -4
- package/src/plugins/builtin/ticker-detail/financials/ratio-table.tsx +9 -2
- package/src/plugins/builtin/ticker-detail/financials/tab.tsx +68 -39
- package/src/plugins/builtin/ticker-detail/headless.ts +4 -1
- package/src/plugins/builtin/ticker-detail/overview/model.ts +61 -15
- package/src/plugins/builtin/ticker-detail/overview-tab.tsx +5 -0
- package/src/plugins/builtin/time-sales/model.ts +16 -9
- package/src/plugins/builtin/time-sales/pane.tsx +27 -24
- package/src/plugins/builtin/treasury-daily/client.ts +43 -9
- package/src/plugins/builtin/treasury-daily/pane.tsx +48 -27
- package/src/plugins/builtin/treasury-daily/resource.ts +33 -0
- package/src/portfolio/positions-import/parse.ts +14 -6
- package/src/portfolio/positions-import/plan.ts +3 -2
- package/src/react/async-resource.ts +3 -1
- package/src/renderers/dom/data-table/index.tsx +40 -0
- package/src/renderers/dom/data-table/row.tsx +39 -3
- package/src/renderers/dom/desktop/icons.tsx +147 -3
- package/src/renderers/dom/desktop/popover.tsx +2 -2
- package/src/renderers/dom/host/media-surface.tsx +204 -45
- package/src/renderers/dom/host/tabs.tsx +1 -0
- package/src/renderers/dom/styles.css +14 -2
- package/src/renderers/electrobun/bun/desktop/backend.ts +2 -0
- package/src/renderers/electrobun/bun/desktop/rpc-timing.ts +9 -3
- package/src/renderers/electrobun/shared/protocol.ts +2 -0
- package/src/renderers/electrobun/view/backend-rpc.ts +5 -2
- package/src/renderers/electrobun/view/rpc-timeout.ts +44 -3
- package/src/sources/gloomberb-cloud/index.ts +8 -7
- package/src/sources/gloomberb-cloud/normalizers.ts +7 -2
- package/src/sources/listing-symbols.ts +7 -1
- package/src/sources/provider-router/cache.ts +5 -4
- package/src/sources/provider-router/financials.ts +40 -18
- package/src/state/app/tab-cursor.ts +47 -6
- package/src/telemetry/stall-clocks.ts +3 -0
- package/src/telemetry/stall-reports.ts +12 -3
- package/src/telemetry/windows-process-activity.ts +41 -0
- package/src/telemetry/windows-time.ts +32 -0
- package/src/test-support/scoped-earnings.ts +24 -0
- package/src/tickers/terminal-codes.ts +1 -6
- package/src/time-series/daily-valuation.ts +13 -6
- package/src/time-series/filed-trailing-eps.ts +16 -3
- package/src/time-series/fundamentals/current-valuation.ts +8 -0
- package/src/time-series/fundamentals/historical-valuation.ts +20 -0
- package/src/time-series/fundamentals/series.ts +13 -1
- package/src/time-series/valuation-currency.ts +2 -0
- package/src/types/financials.ts +46 -10
- package/src/ui/dialog-context.ts +8 -0
- package/src/utils/datetime-format.ts +23 -1
- package/src/utils/declared-dividends.ts +12 -2
- package/src/utils/exchange-announcements.ts +4 -1
- package/src/utils/exchange-notation.generated.ts +3 -1
- package/src/utils/exchanges.ts +2 -1
- package/src/utils/fundamentals.ts +1 -0
- package/src/utils/main-thread-stall.ts +9 -1
- package/src/utils/rpc-timeout-error.ts +36 -11
- package/src/utils/sec.ts +3 -1
- package/src/utils/share-multiples.ts +1 -1
- package/src/utils/stall-process-activity.ts +70 -0
- package/src/utils/statement-scope.ts +103 -0
- package/src/utils/trailing-eps.ts +1 -1
- package/src/utils/zoned-date-time.ts +1 -0
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { logFailure } from "../utils/log-failure";
|
|
2
2
|
import type { StallEvent } from "../utils/main-thread-stall";
|
|
3
|
+
import { formatProcessActivity, formatProcessActivitySummary, type ProcessActivityDelta } from "../utils/stall-process-activity";
|
|
3
4
|
import { VERSION } from "../version";
|
|
4
5
|
import { reportCrash } from "./crash-reports";
|
|
5
6
|
|
|
@@ -82,6 +83,7 @@ export interface StallReport {
|
|
|
82
83
|
cpuPercent?: number;
|
|
83
84
|
/** Where the platform says: the CPU the process's other threads used meanwhile, in percent of one core, by tens. */
|
|
84
85
|
otherCpuPercent?: number;
|
|
86
|
+
processActivity?: ProcessActivityDelta;
|
|
85
87
|
}
|
|
86
88
|
|
|
87
89
|
type StallBucket = "1-2s" | "2-5s" | "5-15s" | "15s+";
|
|
@@ -268,6 +270,7 @@ function formatStallLogLine(process: StallProcess, event: StallEvent, context: S
|
|
|
268
270
|
...(context.attention ? [`fg=${flag(context.attention.active)}`, `vis=${flag(context.attention.visible)}`] : []),
|
|
269
271
|
...(context.cpuPercent === undefined ? [] : [`cpu=${context.cpuPercent}`]),
|
|
270
272
|
...(context.otherCpuPercent === undefined ? [] : [`oth=${context.otherCpuPercent}`]),
|
|
273
|
+
...(event.processActivity ? formatProcessActivity(event.processActivity) : []),
|
|
271
274
|
].join(" ");
|
|
272
275
|
return `${time} ${process.padEnd(8)} froze ${formatSeconds(event.blockedMs).padStart(6)} ${last}${sqlite} [${facts}]`;
|
|
273
276
|
}
|
|
@@ -289,20 +292,25 @@ function reportArch(arch: string): StallReport["arch"] {
|
|
|
289
292
|
* One that would not fit is left out.
|
|
290
293
|
*/
|
|
291
294
|
export function formatStallReportDetails(report: StallReport): string {
|
|
295
|
+
const activity = report.processActivity;
|
|
296
|
+
const deferSummaries = activity !== undefined || report.lockWait !== undefined || report.attempts !== undefined;
|
|
292
297
|
const fields = [
|
|
293
298
|
`process=${report.process}`,
|
|
294
|
-
`count=${report.count}
|
|
299
|
+
...(!deferSummaries ? [`count=${report.count}`] : []),
|
|
295
300
|
`longest=${report.longestMs}ms`,
|
|
296
301
|
`phase=${report.phase}`,
|
|
297
302
|
`up=${report.uptime}`,
|
|
298
303
|
`gap=${report.gap}`,
|
|
299
|
-
...(report.heldPercent
|
|
304
|
+
...(!deferSummaries && report.heldPercent !== undefined ? [`held=${report.heldPercent}`] : []),
|
|
300
305
|
...(report.active === undefined ? [] : [`fg=${flag(report.active)}`]),
|
|
301
306
|
...(report.visible === undefined ? [] : [`vis=${flag(report.visible)}`]),
|
|
302
307
|
...(report.cpuPercent === undefined ? [] : [`cpu=${report.cpuPercent}`]),
|
|
303
|
-
...(report.otherCpuPercent === undefined ? [] : [`oth=${report.otherCpuPercent}`]),
|
|
304
308
|
...(report.lockWait === undefined ? [] : [`lock=${flag(report.lockWait)}`]),
|
|
305
309
|
...(report.attempts === undefined ? [] : [`try=${report.attempts}`]),
|
|
310
|
+
...(activity ? formatProcessActivitySummary(activity) : []),
|
|
311
|
+
...(deferSummaries ? [`count=${report.count}`] : []),
|
|
312
|
+
...(deferSummaries && report.heldPercent !== undefined ? [`held=${report.heldPercent}`] : []),
|
|
313
|
+
...(report.otherCpuPercent === undefined ? [] : [`oth=${report.otherCpuPercent}`]),
|
|
306
314
|
`day=${report.day}`,
|
|
307
315
|
`platform=${report.platform}-${report.arch}`,
|
|
308
316
|
];
|
|
@@ -403,6 +411,7 @@ export function recordStall(process: StallProcess, event: StallEvent): void {
|
|
|
403
411
|
...(context.attention ? { active: context.attention.active, visible: context.attention.visible } : {}),
|
|
404
412
|
...(context.cpuPercent === undefined ? {} : { cpuPercent: context.cpuPercent }),
|
|
405
413
|
...(context.otherCpuPercent === undefined ? {} : { otherCpuPercent: context.otherCpuPercent }),
|
|
414
|
+
...(event.processActivity ? { processActivity: event.processActivity } : {}),
|
|
406
415
|
...(event.sqlite && section.startsWith("sqlite.blocked")
|
|
407
416
|
? { attempts: Math.max(1, Math.min(99, Math.round(event.sqlite.attempts))), lockWait: event.sqlite.lockWait }
|
|
408
417
|
: {}),
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { dlopen, FFIType, ptr } from "bun:ffi";
|
|
2
|
+
import type { ProcessActivityReading } from "../utils/stall-process-activity";
|
|
3
|
+
|
|
4
|
+
function pageFaultReader(): () => ProcessActivityReading["pageFaults"] {
|
|
5
|
+
try {
|
|
6
|
+
if (process.arch !== "x64" && process.arch !== "arm64") return () => undefined;
|
|
7
|
+
const { symbols } = dlopen("kernel32.dll", {
|
|
8
|
+
GetCurrentProcess: { args: [], returns: FFIType.u64 },
|
|
9
|
+
K32GetProcessMemoryInfo: { args: [FFIType.u64, FFIType.ptr, FFIType.u32], returns: FFIType.i32 },
|
|
10
|
+
});
|
|
11
|
+
const processHandle = symbols.GetCurrentProcess();
|
|
12
|
+
const counters = new Uint32Array(new BigUint64Array(9).buffer);
|
|
13
|
+
counters[0] = counters.byteLength;
|
|
14
|
+
const buffer = ptr(counters);
|
|
15
|
+
return () => symbols.K32GetProcessMemoryInfo(processHandle, buffer, counters.byteLength) ? BigInt(counters[1]!) : null;
|
|
16
|
+
} catch {
|
|
17
|
+
return () => undefined;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function ioReader(): () => ProcessActivityReading["io"] {
|
|
22
|
+
try {
|
|
23
|
+
const { symbols } = dlopen("kernel32.dll", {
|
|
24
|
+
GetCurrentProcess: { args: [], returns: FFIType.u64 },
|
|
25
|
+
GetProcessIoCounters: { args: [FFIType.u64, FFIType.ptr], returns: FFIType.i32 },
|
|
26
|
+
});
|
|
27
|
+
const processHandle = symbols.GetCurrentProcess();
|
|
28
|
+
const counters = new BigUint64Array(6);
|
|
29
|
+
const buffer = ptr(counters);
|
|
30
|
+
return () => symbols.GetProcessIoCounters(processHandle, buffer) ? Array.from(counters) : null;
|
|
31
|
+
} catch {
|
|
32
|
+
return () => undefined;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** PROCESS_MEMORY_COUNTERS (total faults) and IO_COUNTERS (all process I/O, not physical disk activity). */
|
|
37
|
+
export function createWindowsProcessActivity(): () => ProcessActivityReading {
|
|
38
|
+
const pageFaults = pageFaultReader();
|
|
39
|
+
const io = ioReader();
|
|
40
|
+
return () => ({ pageFaults: pageFaults(), io: io() });
|
|
41
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { dlopen, FFIType, ptr } from "bun:ffi";
|
|
2
|
+
import type { RpcClockSample } from "../utils/rpc-timeout-error";
|
|
3
|
+
|
|
4
|
+
function createReader(): () => RpcClockSample | null {
|
|
5
|
+
try {
|
|
6
|
+
const { symbols } = dlopen("kernel32.dll", {
|
|
7
|
+
GetTickCount64: { args: [], returns: FFIType.u64 },
|
|
8
|
+
QueryUnbiasedInterruptTime: { args: [FFIType.ptr], returns: FFIType.i32 },
|
|
9
|
+
});
|
|
10
|
+
const readings = new BigUint64Array(1);
|
|
11
|
+
const awake = ptr(readings);
|
|
12
|
+
return () => {
|
|
13
|
+
const before = Date.now();
|
|
14
|
+
const elapsedMs = Number(symbols.GetTickCount64());
|
|
15
|
+
if (!symbols.QueryUnbiasedInterruptTime(awake)) return null;
|
|
16
|
+
const wallMs = Date.now();
|
|
17
|
+
if (wallMs < before || wallMs - before > 32) return null;
|
|
18
|
+
return { wallMs, elapsedMs, awakeMs: Number(readings[0]!) / 10_000 };
|
|
19
|
+
};
|
|
20
|
+
} catch {
|
|
21
|
+
return () => null;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
let read: (() => RpcClockSample | null) | undefined;
|
|
26
|
+
|
|
27
|
+
/** Time since boot includes sleep; unbiased interrupt time does not. */
|
|
28
|
+
export function readWindowsTimeoutClock(): RpcClockSample | null {
|
|
29
|
+
if (process.platform !== "win32") return null;
|
|
30
|
+
read ??= createReader();
|
|
31
|
+
return read();
|
|
32
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { mapCloudFinancials } from "../sources/gloomberb-cloud/normalizers";
|
|
2
|
+
|
|
3
|
+
export function scopedFixture() {
|
|
4
|
+
const after = Date.parse("2028-02-18T17:00Z"), before = Date.parse("2028-02-16T17:00Z");
|
|
5
|
+
const scope = { basis: "standalone" as const, entity: "vylor-standalone", registrant: "0002128626", label: "Vylor standalone (as filed)" };
|
|
6
|
+
const end = "2027-12-31", filed = "2028-02-17";
|
|
7
|
+
const quote = { symbol: "VYLR", price: 65, currency: "USD", change: 0, changePercent: 0, lastUpdated: after, listingExchangeName: "NYSE" };
|
|
8
|
+
const quarters = ["03-31", "06-30", "09-30", "12-31"].map((day, index) => ({ date: `2027-${day}`, availableAt: filed,
|
|
9
|
+
currency: "USD", statementScope: scope, eps: [0.75, 0.75, 1, 0.75][index], totalRevenue: 30e6 }));
|
|
10
|
+
const raw = { annualStatements: [{ ...quarters[3]!, eps: 3, availableAt: "2028-02-15" }], quarterlyStatements: quarters,
|
|
11
|
+
priceHistory: [before, after].map(time => ({ date: new Date(time), close: 65 })), financialCurrency: "USD", statementScope: scope,
|
|
12
|
+
statementReview: { status: "reviewed" as const, reviewedThrough: filed }, fundamentals: { eps: 3.25, epsCurrency: "USD", trailingPeriodEnd: end, trailingPE: 20 } };
|
|
13
|
+
return { raw, quarters, scope, end, filed, quote, before, after };
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function scopedNyseCloseFixture() {
|
|
17
|
+
const { raw, quarters, quote, filed } = scopedFixture();
|
|
18
|
+
const onFilingDay = (hour: number) => new Date(`${filed}T${String(hour).padStart(2, "0")}:00:00Z`);
|
|
19
|
+
const data = { ...mapCloudFinancials({ ...raw, quarterlyStatements: quarters.map(row => ({ ...row, fieldAvailability: { eps: onFilingDay(17).toISOString() } })) }),
|
|
20
|
+
quote: { ...quote, stale: true }, priceHistory: [
|
|
21
|
+
{ date: onFilingDay(0), close: 78 }, { date: onFilingDay(16), close: 65 }, { date: onFilingDay(18), close: 65 },
|
|
22
|
+
] };
|
|
23
|
+
return { data, onFilingDay };
|
|
24
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { futuresContractByCode } from "../market-data/futures-board";
|
|
2
|
-
import { getListingSymbol, hongKongListingCode, tickerHasListingSuffix } from "../sources/listing-symbols";
|
|
2
|
+
import { getListingSymbol, hongKongListingCode, hongKongWorkingCode, tickerHasListingSuffix } from "../sources/listing-symbols";
|
|
3
3
|
import { isCurrencyCode } from "../utils/currency-pair";
|
|
4
4
|
import { canonicalExchange, isKnownExchangeCode, isPredictionMarketExchange, isSharedExchangeCode, isUsListingExchange, typedExchangeVenue } from "../utils/exchanges";
|
|
5
5
|
|
|
@@ -504,11 +504,6 @@ const SLASH_CLASS = /^([A-Z]{2,5})\/([A-Z])$/;
|
|
|
504
504
|
*/
|
|
505
505
|
const HONG_KONG_CODE = /^(\d{1,5})(\.HKG?|:HKEX)$/;
|
|
506
506
|
|
|
507
|
-
/** A Hong Kong code as the app keys it: four digits at least (0700, 3042, 83042). */
|
|
508
|
-
function hongKongWorkingCode(digits: string): string | null {
|
|
509
|
-
const code = Number(digits);
|
|
510
|
-
return code > 0 ? String(code).padStart(4, "0") : null;
|
|
511
|
-
}
|
|
512
507
|
/** `6758.JP`, `MC.FP`: a symbol with a Bloomberg market code where a listing suffix goes. */
|
|
513
508
|
const MARKET_SUFFIX = /^([A-Z0-9]{1,10})\.([A-Z]{2})$/;
|
|
514
509
|
/**
|
|
@@ -18,6 +18,7 @@ export function dailyValuationHistory(
|
|
|
18
18
|
history: readonly PricePoint[],
|
|
19
19
|
bases: readonly DailyValuationBasis[],
|
|
20
20
|
exchange?: string,
|
|
21
|
+
closesKnownBy?: number,
|
|
21
22
|
): TimeSeriesPoint[] {
|
|
22
23
|
const byDate = new Map<number, PricePoint[]>();
|
|
23
24
|
for (const bar of history) {
|
|
@@ -33,22 +34,28 @@ export function dailyValuationHistory(
|
|
|
33
34
|
let next = 0;
|
|
34
35
|
let active: DailyValuationBasis | undefined;
|
|
35
36
|
const points: TimeSeriesPoint[] = [];
|
|
36
|
-
|
|
37
|
+
const closes = [...byDate].flatMap(([time, bars]) => {
|
|
37
38
|
// Daily bars name their session at midnight. A timed report belongs to
|
|
38
39
|
// that close only if it was already public, including on early closes.
|
|
39
40
|
const day = new Date(time).toISOString().slice(0, 10);
|
|
40
|
-
const closeTime = regularSessionCloseOn(exchange, day) ?? time
|
|
41
|
+
const closeTime = closesKnownBy === undefined ? regularSessionCloseOn(exchange, day) ?? time
|
|
42
|
+
: time % 86_400_000 === 0 ? regularSessionCloseOn(exchange, day) : time;
|
|
43
|
+
return closeTime === null ? [] : [{ time, bars, closeTime, pointTime: closesKnownBy === undefined ? time : closeTime }];
|
|
44
|
+
});
|
|
45
|
+
for (const { time, bars, closeTime, pointTime } of closes.sort((left, right) => left.pointTime - right.pointTime || left.time - right.time)) {
|
|
46
|
+
if (closesKnownBy !== undefined && closeTime > closesKnownBy) continue;
|
|
41
47
|
while (next < releases.length && effectiveTime(releases[next]!) <= closeTime) {
|
|
42
48
|
const release = releases[next++]!;
|
|
43
49
|
if (!active || release.observedAt >= active.observedAt) active = release;
|
|
44
50
|
}
|
|
45
|
-
const
|
|
46
|
-
const
|
|
51
|
+
const observedAt = new Date(time);
|
|
52
|
+
const date = pointTime === time ? observedAt : new Date(pointTime);
|
|
53
|
+
const price = valuationPriceAtOrBefore(bars, observedAt.toISOString());
|
|
47
54
|
const value = active && price?.price != null ? active.atPrice(price.price) : null;
|
|
48
55
|
points.push({
|
|
49
56
|
date,
|
|
50
|
-
observedAt
|
|
51
|
-
availableAt: active?.availableAt ? new Date(active.availableAt) : undefined,
|
|
57
|
+
observedAt,
|
|
58
|
+
availableAt: active?.availableAt ? new Date(closesKnownBy === undefined ? active.availableAt : closeTime) : undefined,
|
|
52
59
|
value: value !== null && Number.isFinite(value) ? value : null,
|
|
53
60
|
periodLabel: active?.periodLabel,
|
|
54
61
|
provenance: {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { Fundamentals, FinancialStatement, TickerFinancials } from "../types/financials";
|
|
2
2
|
import { resolveCurrencyUnit } from "../utils/currency-units";
|
|
3
|
-
import {
|
|
3
|
+
import { dateScopedEarnings, listingOwnsSeries, priceScopedEarnings } from "../utils/statement-scope";
|
|
4
|
+
import { areNearbyFinancialPeriodEnds, financialAvailabilityTime, statementFieldAvailability } from "../utils/financial-statements";
|
|
4
5
|
import { extractFundamentalSeries, knownWhenFiled } from "./fundamentals";
|
|
5
6
|
import type { SecuritySeriesSource, TimeSeriesPoint } from "./types";
|
|
6
7
|
|
|
@@ -49,6 +50,12 @@ export function trailingEpsSteps(
|
|
|
49
50
|
financials: TickerFinancials,
|
|
50
51
|
known: (row: FinancialStatement) => FinancialStatement = knownWhenFiled,
|
|
51
52
|
): EpsStep[] {
|
|
53
|
+
if (!listingOwnsSeries(financials)) return [];
|
|
54
|
+
if (financials.statementScope) {
|
|
55
|
+
const earnings = financials.fundamentals?.scopedEarnings;
|
|
56
|
+
return earnings?.epsAvailableAt ? [{ periodEnd: earnings.periodEnd, basis: "ttm", knownAt: new Date(financialAvailabilityTime(earnings.epsAvailableAt)), dated: true,
|
|
57
|
+
eps: earnings.eps, currency: earnings.currency }] : [];
|
|
58
|
+
}
|
|
52
59
|
const adjusted = { ...financials, quarterlyStatements: financials.quarterlyStatements.map(known),
|
|
53
60
|
annualStatements: financials.annualStatements.map(known) };
|
|
54
61
|
const toStep = (basis: EpsStep["basis"]) => (point: TimeSeriesPoint): EpsStep => ({
|
|
@@ -79,7 +86,7 @@ interface FiledTrailingEps {
|
|
|
79
86
|
*/
|
|
80
87
|
const SERVED_EPS_RATIO_LIMIT = 1.5;
|
|
81
88
|
|
|
82
|
-
type TrailingEpsInputs = Pick<TickerFinancials, "quote" | "fundamentals" | "annualStatements" | "quarterlyStatements" | "financialCurrency">;
|
|
89
|
+
type TrailingEpsInputs = Pick<TickerFinancials, "quote" | "fundamentals" | "annualStatements" | "quarterlyStatements" | "financialCurrency" | "statementScope">;
|
|
83
90
|
|
|
84
91
|
const isReceipt = (financials: TrailingEpsInputs) => !!(
|
|
85
92
|
financials.quote?.isDepositaryReceipt || financials.fundamentals?.isDepositaryReceipt
|
|
@@ -106,6 +113,7 @@ const rowKey = (row: FinancialStatement) => [
|
|
|
106
113
|
/** The trailing EPS step for the last period on record, null when that period gives none. */
|
|
107
114
|
function latestStep(financials: TrailingEpsInputs): LatestStep {
|
|
108
115
|
const rows = [...financials.quarterlyStatements, ...financials.annualStatements];
|
|
116
|
+
if (!listingOwnsSeries(financials)) return null;
|
|
109
117
|
const latest = rows.map((row) => row.date).filter((date) => Number.isFinite(Date.parse(date))).sort().at(-1);
|
|
110
118
|
if (!latest) return null;
|
|
111
119
|
const recent = (row: FinancialStatement) => Date.parse(latest) - Date.parse(row.date) <= LATEST_WINDOW_MS;
|
|
@@ -113,7 +121,7 @@ function latestStep(financials: TrailingEpsInputs): LatestStep {
|
|
|
113
121
|
const annualStatements = financials.annualStatements.filter(recent);
|
|
114
122
|
const key = [financials.financialCurrency ?? "", quarterlyStatements.map(rowKey).join(";"), annualStatements.map(rowKey).join(";")].join("#");
|
|
115
123
|
if (latestSteps.has(key)) return latestSteps.get(key)!;
|
|
116
|
-
const found = trailingEpsSteps({ financialCurrency: financials.financialCurrency, priceHistory: [], quarterlyStatements, annualStatements })
|
|
124
|
+
const found = trailingEpsSteps({ financialCurrency: financials.financialCurrency, statementScope: financials.statementScope, priceHistory: [], quarterlyStatements, annualStatements })
|
|
117
125
|
.find((candidate) => areNearbyFinancialPeriodEnds(candidate.periodEnd, latest));
|
|
118
126
|
const filed = [...quarterlyStatements, ...annualStatements]
|
|
119
127
|
.flatMap((row) => typeof row.eps === "number" ? [statementFieldAvailability(row, "eps")?.slice(0, 10)] : [])
|
|
@@ -175,6 +183,11 @@ const positive = (value: number | null | undefined): value is number => finite(v
|
|
|
175
183
|
export function withFiledTrailingEps<T extends TrailingEpsInputs>(financials: T, now = Date.now()): T {
|
|
176
184
|
const fundamentals = financials.fundamentals;
|
|
177
185
|
if (!fundamentals) return financials;
|
|
186
|
+
if (financials.statementScope) {
|
|
187
|
+
const scopedEarnings = dateScopedEarnings(financials, fundamentals.scopedEarnings);
|
|
188
|
+
const quote = financials.quote;
|
|
189
|
+
return { ...financials, fundamentals: priceScopedEarnings({ ...fundamentals, scopedEarnings }, quote?.price, quote, quote?.lastUpdated, now) };
|
|
190
|
+
}
|
|
178
191
|
const filed = filedTrailingEps(financials, now);
|
|
179
192
|
if (!filed) {
|
|
180
193
|
const served = finite(fundamentals.eps) || finite(fundamentals.trailingPE);
|
|
@@ -9,6 +9,7 @@ import { liveForwardPE, liveTrailingPE } from "../../market-data/quotes/live-val
|
|
|
9
9
|
import { listingEnterpriseValue } from "../../market-data/quotes/listing-enterprise-value";
|
|
10
10
|
import { BANK_OR_INSURER_EBITDA, isBankOrInsurerIndustry } from "../../utils/ebitda";
|
|
11
11
|
import { comparablePriceEarnings } from "../../utils/price-earnings";
|
|
12
|
+
import { listingOwnsSeries } from "../../utils/statement-scope";
|
|
12
13
|
import { buildTtmStatements, deriveQuarterlyStatements } from "./quarterly-ttm";
|
|
13
14
|
import { sourceStatements, valuationStatements } from "./source-statements";
|
|
14
15
|
import { type InternalStatement, validDate } from "./statement";
|
|
@@ -114,6 +115,11 @@ function currentDerivedValuation(
|
|
|
114
115
|
if (!quoteDate || !isFiniteNumber(quote?.price) || quote.price <= 0) return null;
|
|
115
116
|
const current = currentValuationPrice(quote);
|
|
116
117
|
if (!current) return null;
|
|
118
|
+
if (metric === "trailingPE" && financials.statementScope) {
|
|
119
|
+
const earnings = financials.fundamentals?.scopedEarnings;
|
|
120
|
+
const statement = earnings && [...financials.quarterlyStatements, ...financials.annualStatements].find(row => row.date === earnings.periodEnd);
|
|
121
|
+
return statement ? { value: servedTrailingPE(financials), date: current.date, statement } : null;
|
|
122
|
+
}
|
|
117
123
|
const quoteTime = quoteDate.getTime();
|
|
118
124
|
// Select the latest known period first. Missing inputs, a loss or incompatible
|
|
119
125
|
// currency cannot make an older period's denominator current again.
|
|
@@ -184,6 +190,7 @@ export function currentTrailingValuation(
|
|
|
184
190
|
financials: TickerFinancials,
|
|
185
191
|
metric: "evEbitda" | "evSales",
|
|
186
192
|
): { value: number | null; notMeaningful?: string; periodEnd: string; statement: FinancialStatement; annual?: true } | null {
|
|
193
|
+
if (!listingOwnsSeries(financials)) return null;
|
|
187
194
|
const current = currentValuation(financials, "ttm", metric);
|
|
188
195
|
if (current) {
|
|
189
196
|
const dated = { periodEnd: current.statement.date.slice(0, 10), statement: current.statement };
|
|
@@ -246,6 +253,7 @@ export function valuationNotMeaningful(financials: TickerFinancials, source: Sec
|
|
|
246
253
|
* its year): the latest one, or null when the latest window is incomplete.
|
|
247
254
|
*/
|
|
248
255
|
export function latestTrailingStatement(financials: TickerFinancials): FinancialStatement | null {
|
|
256
|
+
if (!listingOwnsSeries(financials)) return null;
|
|
249
257
|
const selected = sourceStatements(financials, "ttm");
|
|
250
258
|
return selected.statements.at(-1) ?? null;
|
|
251
259
|
}
|
|
@@ -31,6 +31,12 @@ export function historicalValuation(
|
|
|
31
31
|
|
|
32
32
|
export function dailyStatementValuation(financials: TickerFinancials, metric: string, exchange?: string,
|
|
33
33
|
currencies = createValuationCurrencyContext(financials)): TimeSeriesPoint[] {
|
|
34
|
+
if (metric === "trailingPE" && financials.statementScope) {
|
|
35
|
+
const earnings = financials.fundamentals?.scopedEarnings;
|
|
36
|
+
if (!earnings?.epsAvailableAt || !earnings.priced || financials.fundamentals?.notMeaningful?.trailingPE || !(earnings.eps > 0) || earnings.currency !== financials.quote?.currency) return [];
|
|
37
|
+
return dailyValuationHistory(financials.priceHistory, [{ availableAt: earnings.epsAvailableAt, observedAt: new Date(earnings.periodEnd),
|
|
38
|
+
atPrice: price => price / earnings.eps }], financials.quote.listingExchangeName || financials.quote.exchangeName || exchange, Date.now());
|
|
39
|
+
}
|
|
34
40
|
const earningsMetric = metric === "pegRatio" ? "trailingPE" : metric;
|
|
35
41
|
const selected = sourceStatements(financials, "daily", earningsMetric, exchange);
|
|
36
42
|
const yearEndMonth = fiscalYearEndMonth(financials.annualStatements);
|
|
@@ -84,10 +90,24 @@ export function dailyStatementValuation(financials: TickerFinancials, metric: st
|
|
|
84
90
|
return points.some((point) => point.value !== null) ? points : [];
|
|
85
91
|
}
|
|
86
92
|
|
|
93
|
+
export function scopedPeriodPE(financials: TickerFinancials, source: SecuritySeriesSource): TimeSeriesPoint | null {
|
|
94
|
+
const earnings = financials.fundamentals?.scopedEarnings;
|
|
95
|
+
if (!earnings) return null;
|
|
96
|
+
const yearEnd = financials.annualStatements.some(row => row.date === earnings.periodEnd);
|
|
97
|
+
if (source.period === "annual" && !yearEnd) return null;
|
|
98
|
+
const close = dailyStatementValuation(financials, "trailingPE", source.instrument.exchange).find(point => point.availableAt && point.value !== null);
|
|
99
|
+
if (!close?.availableAt) return null;
|
|
100
|
+
const period = source.period === "annual" || (source.period !== "ttm" && !financials.quarterlyStatements.length && yearEnd) ? "annual" : "ttm";
|
|
101
|
+
const statement = { date: earnings.periodEnd, currency: earnings.currency, eps: earnings.eps, availableAt: close.availableAt.toISOString() };
|
|
102
|
+
const point = pointForStatement(statement, "trailingPE", close.value, period, source.timestampMode, true, fiscalYearEndMonth(financials.annualStatements));
|
|
103
|
+
return point && { ...point, provenance: { ...point.provenance, ...close.provenance } };
|
|
104
|
+
}
|
|
105
|
+
|
|
87
106
|
/** A daily history cannot be dated at all, but the issuer still has reported figures. */
|
|
88
107
|
export function dailyValuationFallbackPeriod(financials: TickerFinancials, source: SecuritySeriesSource): "annual" | "quarterly" | "ttm" | null {
|
|
89
108
|
if (source.period !== "daily") return null;
|
|
90
109
|
const [namespace, metric = ""] = canonicalTimeSeriesFieldId(source.fieldId).split(".");
|
|
110
|
+
if (financials.statementScope && metric === "trailingPE") return null;
|
|
91
111
|
const inputMetric = metric === "pegRatio" ? "trailingPE" : metric;
|
|
92
112
|
if (namespace !== "valuation" || !QUOTE_DERIVED_VALUATION_IDS.has(inputMetric)) return null;
|
|
93
113
|
const daily = sourceStatements(financials, "daily", inputMetric, source.instrument.exchange);
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// Extracts a fundamental or valuation series from a ticker's financials, with the warnings and issues that explain it.
|
|
2
2
|
import type { TickerFinancials } from "../../types/financials";
|
|
3
|
+
import { listingOwnsSeries } from "../../utils/statement-scope";
|
|
3
4
|
import { fiscalYearEndMonth } from "../../utils/fiscal-period";
|
|
4
5
|
import { canonicalTimeSeriesFieldId, getTimeSeriesField } from "../field-catalog";
|
|
5
6
|
import { dailyForwardPeHistory, forwardPeHistory, realizedNtmPeHistory } from "../forward-valuation";
|
|
@@ -10,7 +11,7 @@ import type { SecuritySeriesSource, TimeSeriesPoint } from "../types";
|
|
|
10
11
|
import { isBankOrInsurerIndustry } from "../../utils/ebitda";
|
|
11
12
|
import { notTheShare } from "../../utils/share-multiples";
|
|
12
13
|
import { currentDerivedValuationPoint, currentValuationStatements, providerCurrentValuationPoint } from "./current-valuation";
|
|
13
|
-
import { dailyStatementValuation, dailyValuationFallbackPeriod, historicalValuation } from "./historical-valuation";
|
|
14
|
+
import { dailyStatementValuation, dailyValuationFallbackPeriod, historicalValuation, scopedPeriodPE } from "./historical-valuation";
|
|
14
15
|
import { FUNDAMENTAL_IDS, QUOTE_DERIVED_VALUATION_IDS, VALUATION_IDS, valuationSeriesUsesLiveQuote } from "./metric-ids";
|
|
15
16
|
import { dedupeFundamentalPeriods, pointForStatement } from "./period-points";
|
|
16
17
|
import { sourceStatements } from "./source-statements";
|
|
@@ -54,6 +55,7 @@ export function extractFundamentalSeries(
|
|
|
54
55
|
}
|
|
55
56
|
|
|
56
57
|
if (namespace !== "valuation" || !VALUATION_IDS.has(metric)) return [];
|
|
58
|
+
if (metric !== "forwardPE" && !listingOwnsSeries(financials)) return [];
|
|
57
59
|
// A warrant's, a right's, a unit's or an unratioed receipt's price over its company's EPS is no P/E at any date.
|
|
58
60
|
if (SHARE_PRICE_EARNINGS.has(metric) && notTheShare(financials)) return [];
|
|
59
61
|
// A bank's or an insurer's EBITDA measures nothing: its EV/EBITDA is N/M throughout (valuationNotMeaningful).
|
|
@@ -83,6 +85,12 @@ export function extractFundamentalSeries(
|
|
|
83
85
|
return current ? [current] : [];
|
|
84
86
|
}
|
|
85
87
|
|
|
88
|
+
if (metric === "trailingPE" && financials.statementScope) {
|
|
89
|
+
const historical = scopedPeriodPE(financials, source);
|
|
90
|
+
const current = currentDerivedValuationPoint(financials, [], metric, currencies);
|
|
91
|
+
return [historical, current].filter((point): point is TimeSeriesPoint => point !== null).sort((left, right) => left.date.getTime() - right.date.getTime());
|
|
92
|
+
}
|
|
93
|
+
|
|
86
94
|
const selected = sourceStatements(financials, source.period, metric);
|
|
87
95
|
const yearEndMonth = fiscalYearEndMonth(financials.annualStatements);
|
|
88
96
|
let hasHistoricalObservation = false;
|
|
@@ -156,6 +164,10 @@ export function valuationPriceIssues(financials: TickerFinancials, source: Secur
|
|
|
156
164
|
return extractFundamentalSeries(financials, source, currencyContext).flatMap((point) => point.provenance?.valuationPriceIssues ?? []);
|
|
157
165
|
}
|
|
158
166
|
if (!valuationSeriesUsesLiveQuote(source.fieldId)) return [];
|
|
167
|
+
if (financials.statementScope && canonicalTimeSeriesFieldId(source.fieldId) === "valuation.trailingPE") {
|
|
168
|
+
const issue = valuationQuoteIssue(financials.quote);
|
|
169
|
+
return [...(issue ? [issue] : []), ...(scopedPeriodPE(financials, source)?.provenance?.valuationPriceIssues ?? [])];
|
|
170
|
+
}
|
|
159
171
|
const currencies = currencyContext ?? createValuationCurrencyContext(financials);
|
|
160
172
|
const metric = canonicalTimeSeriesFieldId(source.fieldId).split(".")[1]!;
|
|
161
173
|
const selected = sourceStatements(financials, source.period, metric);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { crossFxCloseOnOrBefore, dailyFxLeg, loadDailyFxCloses, type FxCloses, type FxHistoryClient } from "../market-data/fx-closes";
|
|
2
2
|
import type { FinancialStatement, TickerFinancials } from "../types/financials";
|
|
3
3
|
import { resolveCurrencyUnit, type CurrencyUnitInfo } from "../utils/currency-units";
|
|
4
|
+
import { listingOwnsRow } from "../utils/statement-scope";
|
|
4
5
|
import { logFailure } from "../utils/log-failure";
|
|
5
6
|
|
|
6
7
|
function knownUnit(currency?: string): CurrencyUnitInfo | null {
|
|
@@ -36,6 +37,7 @@ export function createValuationCurrencyContext(financials: TickerFinancials, fx?
|
|
|
36
37
|
|
|
37
38
|
return {
|
|
38
39
|
priceInStatementUnits(row: FinancialStatement, price: number, date = row.date.slice(0, 10)): number | null {
|
|
40
|
+
if (!listingOwnsRow(financials.statementScope, row)) return null;
|
|
39
41
|
const rate = rateFor(row, date);
|
|
40
42
|
return rate == null ? null : price * rate;
|
|
41
43
|
},
|
package/src/types/financials.ts
CHANGED
|
@@ -38,8 +38,8 @@ export interface QuoteProvenance {
|
|
|
38
38
|
|
|
39
39
|
/**
|
|
40
40
|
* A US listing that no longer trades, as Gloom Cloud states it: TWTR, last
|
|
41
|
-
* traded 2022-10-27
|
|
42
|
-
*
|
|
41
|
+
* traded 2022-10-27. Its daily history ends on that session; the last trade
|
|
42
|
+
* date is not the effective delisting date. Dates are New York trading dates.
|
|
43
43
|
*/
|
|
44
44
|
export interface ListingDelisting {
|
|
45
45
|
/** "delisted": the exchange's removal of the listing is on record; "inactive": only its last trade is known. */
|
|
@@ -503,6 +503,7 @@ export interface Fundamentals extends DepositaryReceiptFacts {
|
|
|
503
503
|
marketCapUnavailable?: "receipt-priced-as-ordinary";
|
|
504
504
|
operatingCashFlow?: number;
|
|
505
505
|
freeCashFlow?: number;
|
|
506
|
+
freeCashFlowCurrency?: string | null;
|
|
506
507
|
dividendYield?: number;
|
|
507
508
|
dividendYieldBasis?: "forward" | "trailing";
|
|
508
509
|
dividendYieldSource?: "gloom";
|
|
@@ -534,6 +535,7 @@ export interface Fundamentals extends DepositaryReceiptFacts {
|
|
|
534
535
|
*/
|
|
535
536
|
trailingEpsSource?: "filed-quarters" | "served";
|
|
536
537
|
trailingEpsPeriodEnd?: string;
|
|
538
|
+
scopedEarnings?: { eps: number; currency: string; periodEnd: string; epsAvailableAt: string; priced: boolean } | null;
|
|
537
539
|
/**
|
|
538
540
|
* Why a multiple is withdrawn though its figures are numbers (utils/share-multiples): a warrant's price over its
|
|
539
541
|
* company's EPS, a receipt's with no ratio on record, an EPS that is not net income over the shares. The multiple
|
|
@@ -692,17 +694,20 @@ export interface AnalystResearchData {
|
|
|
692
694
|
revenueEstimates: AnalystEstimateRecord[];
|
|
693
695
|
}
|
|
694
696
|
|
|
697
|
+
export interface DividendNoticeSource {
|
|
698
|
+
publisher: string;
|
|
699
|
+
url: string;
|
|
700
|
+
/** Original timetable when the final cash amount was published separately. */
|
|
701
|
+
scheduleUrl?: string;
|
|
702
|
+
}
|
|
703
|
+
|
|
695
704
|
export interface DividendAction {
|
|
696
705
|
exDate: string;
|
|
697
706
|
amount: number;
|
|
698
707
|
payDate?: string;
|
|
699
708
|
recordDate?: string;
|
|
700
|
-
/**
|
|
701
|
-
|
|
702
|
-
* sponsor, for a distribution the history lacks (iShares, SPDR, J.P. Morgan,
|
|
703
|
-
* VanEck), and the page it is published on. Absent elsewhere and from older servers.
|
|
704
|
-
*/
|
|
705
|
-
source?: { publisher: string; url: string };
|
|
709
|
+
/** Original notice or sponsor page, when it supplies facts for this row. */
|
|
710
|
+
source?: DividendNoticeSource;
|
|
706
711
|
/**
|
|
707
712
|
* The dividends the row holds by the issuer's own dividend announcement
|
|
708
713
|
* forms (an HKEX listing's): each in the row's currency, summing to its
|
|
@@ -725,6 +730,7 @@ export interface DeclaredDividendAction {
|
|
|
725
730
|
declarationDate?: string;
|
|
726
731
|
recordDate?: string;
|
|
727
732
|
payDate?: string;
|
|
733
|
+
source?: DividendNoticeSource;
|
|
728
734
|
/** A one-off beside the regular payments (AIOK's $3.50), as the server marks it. */
|
|
729
735
|
special?: true;
|
|
730
736
|
}
|
|
@@ -923,11 +929,12 @@ export type ResultsFillField =
|
|
|
923
929
|
|
|
924
930
|
export type StatementFilingKind = "annual_results" | "interim_results" | "quarterly_results" | "annual_report" | "interim_report";
|
|
925
931
|
|
|
926
|
-
/**
|
|
932
|
+
/** An issuer's results announcement or report, with when it was published and read. */
|
|
927
933
|
export interface StatementFilingDocument {
|
|
928
|
-
source: "hkex" | "sgx" | "lse" | "cninfo" | "idx" | "ir" | "mops";
|
|
934
|
+
source: "hkex" | "sgx" | "lse" | "cninfo" | "idx" | "ir" | "mops" | "jpx" | "dart" | "nse";
|
|
929
935
|
kind: StatementFilingKind;
|
|
930
936
|
title: string;
|
|
937
|
+
accountingScope?: "consolidated" | "individual";
|
|
931
938
|
url: string;
|
|
932
939
|
publishedAt: string;
|
|
933
940
|
firstObserved?: true;
|
|
@@ -936,6 +943,12 @@ export interface StatementFilingDocument {
|
|
|
936
943
|
dataUrl?: string;
|
|
937
944
|
}
|
|
938
945
|
|
|
946
|
+
/** The original report for a fiscal period, independent of the source of each normalized figure. */
|
|
947
|
+
export interface StatementPeriodFiling extends StatementFilingDocument {
|
|
948
|
+
periodEnd: string;
|
|
949
|
+
periodMonths: number;
|
|
950
|
+
}
|
|
951
|
+
|
|
939
952
|
/** A row's lines read from the company's results announcement or report, for a period the statements source lags on. */
|
|
940
953
|
export interface ResultsStatementFill {
|
|
941
954
|
source: "results";
|
|
@@ -948,6 +961,7 @@ export interface ResultsStatementFill {
|
|
|
948
961
|
document: number;
|
|
949
962
|
page: number | null;
|
|
950
963
|
subtract?: { document: number; page: number | null };
|
|
964
|
+
xbrl?: { concept: string; context: string };
|
|
951
965
|
subtractDocument?: number;
|
|
952
966
|
location?: { sheet: string; cell: string };
|
|
953
967
|
}>>;
|
|
@@ -1079,7 +1093,15 @@ export interface ReportedEarningsCohort {
|
|
|
1079
1093
|
/** @deprecated No longer populated. */
|
|
1080
1094
|
export interface EarningsResultProvenance { version: 1; reported: ReportedEarningsCohort }
|
|
1081
1095
|
|
|
1096
|
+
export interface StatementScope {
|
|
1097
|
+
registrant: string;
|
|
1098
|
+
entity?: string;
|
|
1099
|
+
basis: "predecessor" | "carve-out" | "standalone";
|
|
1100
|
+
label: string;
|
|
1101
|
+
}
|
|
1102
|
+
|
|
1082
1103
|
export interface FinancialStatement {
|
|
1104
|
+
statementScope?: StatementScope;
|
|
1083
1105
|
/** The basis of this row's share counts and per-share earnings; absent when unproven. */
|
|
1084
1106
|
shareBasis?: ShareBasis;
|
|
1085
1107
|
/** @deprecated No longer populated. */
|
|
@@ -1388,7 +1410,18 @@ export interface EpsEstimateHistory {
|
|
|
1388
1410
|
snapshots: ConsensusEpsSnapshot[];
|
|
1389
1411
|
}
|
|
1390
1412
|
|
|
1413
|
+
export interface TaiwanExchangeStatement {
|
|
1414
|
+
kind: "income" | "balance";
|
|
1415
|
+
periodEnd: string;
|
|
1416
|
+
months: number;
|
|
1417
|
+
currency: "TWD";
|
|
1418
|
+
figures: { label: string; sourceLabel: string; value: number; perShare?: true }[];
|
|
1419
|
+
source: { venue: "TWSE" | "TPEX"; url: string; snapshotDate: string; observedAt: string };
|
|
1420
|
+
}
|
|
1421
|
+
|
|
1391
1422
|
export interface TickerFinancials {
|
|
1423
|
+
statementScope?: StatementScope;
|
|
1424
|
+
statementReview?: { status: "reviewed" | "pending" | "index-unavailable"; reviewedThrough: string };
|
|
1392
1425
|
/** Reported earnings-release events retained with daily valuation snapshots. */
|
|
1393
1426
|
earningsReleases?: EarningsAction[];
|
|
1394
1427
|
statementHistory?: StatementHistoryAttempt;
|
|
@@ -1405,6 +1438,9 @@ export interface TickerFinancials {
|
|
|
1405
1438
|
nextEarnings?: NextEarnings;
|
|
1406
1439
|
annualStatements: FinancialStatement[];
|
|
1407
1440
|
quarterlyStatements: FinancialStatement[];
|
|
1441
|
+
periodFilings?: StatementPeriodFiling[];
|
|
1442
|
+
/** Exchange summaries have their own reporting basis and do not enter the normalized statements. */
|
|
1443
|
+
taiwanExchangeStatements?: TaiwanExchangeStatement[];
|
|
1408
1444
|
/** Twelve months to the latest half or quarter where the quarters do not give them (a half-yearly reporter). */
|
|
1409
1445
|
trailingStatement?: FinancialStatement & { trailing: StatementTrailing };
|
|
1410
1446
|
priceHistory: PricePoint[];
|
package/src/ui/dialog-context.ts
CHANGED
|
@@ -22,3 +22,11 @@ export const DialogContext = createContext<DialogContextValue | null>(null);
|
|
|
22
22
|
export function useDialogIsTopmost(): boolean {
|
|
23
23
|
return useContext(DialogContext)?.keyboardEnabled ?? true;
|
|
24
24
|
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* True while any dialog is open, so it has the keyboard. False outside a
|
|
28
|
+
* dialog host (a pane drawn on its own), where `useDialogState` throws.
|
|
29
|
+
*/
|
|
30
|
+
export function useAnyDialogOpen(): boolean {
|
|
31
|
+
return useContext(DialogContext)?.isOpen ?? false;
|
|
32
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { MISSING_VALUE } from "./format";
|
|
2
2
|
import { toTimestampMillis } from "./timestamp";
|
|
3
|
-
import { timeZoneLabel } from "./zoned-date-time";
|
|
3
|
+
import { timeZoneLabel, zonedDateTimeParts } from "./zoned-date-time";
|
|
4
4
|
|
|
5
5
|
export type DisplayDateValue = Date | string | number | null | undefined;
|
|
6
6
|
|
|
@@ -272,3 +272,25 @@ export function formatDetailTime(value: DisplayDateValue, fallback = MISSING_VAL
|
|
|
272
272
|
if (!date) return fallback;
|
|
273
273
|
return `${formatClockTime(date, fallback, timeZone)} ${localTimeZoneShortName(date, timeZone)}`;
|
|
274
274
|
}
|
|
275
|
+
|
|
276
|
+
const zonedDayFormatters = new Map<string, Intl.DateTimeFormat>();
|
|
277
|
+
|
|
278
|
+
/**
|
|
279
|
+
* An instant on the host's clock (or `timeZone`'s) with its day and zone
|
|
280
|
+
* named, the year only when it is not this one: "20 Nov 14:30 HKT", "3 Mar
|
|
281
|
+
* 2025 09:31 ET". For one moment several panes name on the same clock, such
|
|
282
|
+
* as the tab's pinned crosshair, whatever clock their own rows read on.
|
|
283
|
+
*/
|
|
284
|
+
export function formatZonedMoment(value: DisplayDateValue, now = Date.now(), timeZone?: string): string {
|
|
285
|
+
const date = parseDisplayDate(value);
|
|
286
|
+
if (!date) return MISSING_VALUE;
|
|
287
|
+
const zone = timeZone ?? new Intl.DateTimeFormat().resolvedOptions().timeZone ?? "UTC";
|
|
288
|
+
const withYear = zonedDateTimeParts(date.getTime(), zone).year !== zonedDateTimeParts(now, zone).year;
|
|
289
|
+
const key = `${zone}:${withYear}`;
|
|
290
|
+
let formatter = zonedDayFormatters.get(key);
|
|
291
|
+
if (!formatter) {
|
|
292
|
+
formatter = new Intl.DateTimeFormat("en-US", { day: "numeric", month: "short", year: withYear ? "numeric" : undefined, timeZone: zone });
|
|
293
|
+
zonedDayFormatters.set(key, formatter);
|
|
294
|
+
}
|
|
295
|
+
return `${dayFirstParts(formatter, date)} ${formatDetailTime(date, MISSING_VALUE, zone)}`;
|
|
296
|
+
}
|
|
@@ -1,11 +1,20 @@
|
|
|
1
|
-
import type { CorporateActionsData, DeclaredDividendAction } from "../types/financials";
|
|
1
|
+
import type { CorporateActionsData, DeclaredDividendAction, DividendNoticeSource } from "../types/financials";
|
|
2
2
|
import { formatDistributionAmount } from "./format";
|
|
3
|
+
import { normalizedHttpUrl } from "./url";
|
|
3
4
|
|
|
4
5
|
const ISO_DATE = /^\d{4}-\d{2}-\d{2}$/;
|
|
5
6
|
/** A paid row this close to a declared one is that distribution, dated a day apart. */
|
|
6
7
|
const SAME_DISTRIBUTION_DAYS = 3;
|
|
7
8
|
const DAY_MS = 86_400_000;
|
|
8
9
|
|
|
10
|
+
export function dividendNoticeSource(raw: DividendNoticeSource | undefined): DividendNoticeSource | undefined {
|
|
11
|
+
const publisher = typeof raw?.publisher === "string" ? raw.publisher.trim() : "";
|
|
12
|
+
const url = normalizedHttpUrl(raw?.url);
|
|
13
|
+
if (!publisher || !url) return undefined;
|
|
14
|
+
const scheduleUrl = normalizedHttpUrl(raw?.scheduleUrl);
|
|
15
|
+
return { publisher, url, ...(scheduleUrl ? { scheduleUrl } : {}) };
|
|
16
|
+
}
|
|
17
|
+
|
|
9
18
|
export function declaredDividendCash(row: DeclaredDividendAction, currency?: string | null): { amount: string; estimate?: string } {
|
|
10
19
|
const cash = currency ? formatDistributionAmount(row.amount, currency) : String(row.amount);
|
|
11
20
|
const estimate = row.cashEstimate;
|
|
@@ -44,8 +53,9 @@ export function declaredDividends(
|
|
|
44
53
|
if ((payDate ?? exDate) < today) return [];
|
|
45
54
|
const at = Date.parse(`${exDate}T00:00:00Z`);
|
|
46
55
|
if (paid.some((time) => Math.abs(time - at) <= SAME_DISTRIBUTION_DAYS * DAY_MS)) return [];
|
|
56
|
+
const source = dividendNoticeSource(row.source);
|
|
47
57
|
return [{ exDate, amount: row.amount, ...declarationDate ? { declarationDate } : {},
|
|
48
58
|
...recordDate ? { recordDate } : {}, ...payDate ? { payDate } : {}, ...row.special === true ? { special: true as const } : {},
|
|
49
|
-
...row.cashEstimate ? { cashEstimate: row.cashEstimate } : {} }];
|
|
59
|
+
...row.cashEstimate ? { cashEstimate: row.cashEstimate } : {}, ...source ? { source } : {} }];
|
|
50
60
|
}).sort((left, right) => left.exDate.localeCompare(right.exDate));
|
|
51
61
|
}
|