gloomberb 0.20.5 → 0.20.6
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/hk-tenders.ts +59 -0
- package/src/api-client/index.ts +1 -0
- 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/cli/commands/market.ts +164 -40
- package/src/cli/commands/news-search.ts +22 -7
- package/src/cli/commands/overview.ts +12 -6
- package/src/cli/commands/ticker.ts +3 -1
- 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/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/result.ts +21 -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 +3 -3
- package/src/market-data/market/change-basis.ts +9 -5
- package/src/market-data/market/dated-previous-close.ts +57 -6
- package/src/market-data/quotes/contributions.ts +2 -0
- package/src/market-data/quotes/listing-enterprise-value.ts +50 -0
- 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/portfolio-list/cli/render.ts +20 -3
- package/src/plugins/builtin/portfolio-list/cli/watchlist-command.ts +5 -1
- 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/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/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/sync/controller.ts +17 -2
- package/src/sync/other-window-tabs.ts +32 -1
- package/src/sync/react.ts +4 -4
- 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.ts +143 -11
- 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 +6 -0
- package/src/types/headless.ts +8 -0
- package/src/utils/cli-output.ts +6 -3
- package/src/utils/ebitda.ts +128 -0
- package/src/utils/format.ts +1 -1
- package/src/utils/shell-word.ts +13 -0
|
@@ -24,7 +24,7 @@ import { unknownBloombergMarket } from "../../tickers/terminal-codes";
|
|
|
24
24
|
import { notATickerWords } from "../company-name-hint";
|
|
25
25
|
import type { MarketContext } from "../types";
|
|
26
26
|
import { findWatchlist } from "../helpers";
|
|
27
|
-
import { readWatchlistArgument } from "../../portfolio/collection-name";
|
|
27
|
+
import { readWatchlistArgument, watchlistMemberSymbol } from "../../portfolio/collection-name";
|
|
28
28
|
import {
|
|
29
29
|
buildPaneFunctionLookup,
|
|
30
30
|
buildTemplateContext,
|
|
@@ -340,7 +340,7 @@ async function watchlistArgument(
|
|
|
340
340
|
if (!watchlist) return null;
|
|
341
341
|
const symbols = (await context.store.loadAllTickers())
|
|
342
342
|
.filter((ticker) => ticker.metadata.watchlists.includes(watchlist.id))
|
|
343
|
-
.map((ticker) => ticker.metadata
|
|
343
|
+
.map((ticker) => watchlistMemberSymbol(ticker.metadata));
|
|
344
344
|
if (symbols.length === 0) return null;
|
|
345
345
|
const read = readWatchlistArgument(arg, watchlist, symbols, maximum);
|
|
346
346
|
return { symbols: read.symbols, notes: [read.note] };
|
package/src/cli/result.ts
CHANGED
|
@@ -3,6 +3,7 @@ import {
|
|
|
3
3
|
cliPlainEnabled,
|
|
4
4
|
cliStyles,
|
|
5
5
|
cliTerminalWidth,
|
|
6
|
+
renderForFile,
|
|
6
7
|
renderStats,
|
|
7
8
|
renderTable,
|
|
8
9
|
statValueWidth,
|
|
@@ -623,6 +624,19 @@ function renderTextRows<T, Row extends Record<string, unknown>>(
|
|
|
623
624
|
: renderTextTable(rows as Row[], columns, renderOptions.rowNote);
|
|
624
625
|
}
|
|
625
626
|
|
|
627
|
+
/** What `printCliResult` drew for the file `--output` names, since `takeCliFileExport` last took it. */
|
|
628
|
+
let fileExport: string[] = [];
|
|
629
|
+
|
|
630
|
+
/**
|
|
631
|
+
* The export a command printed for its `--output` file, or null when it
|
|
632
|
+
* printed none: the text the file is written with (dispatchCli).
|
|
633
|
+
*/
|
|
634
|
+
export function takeCliFileExport(): string | null {
|
|
635
|
+
const taken = fileExport.filter(Boolean);
|
|
636
|
+
fileExport = [];
|
|
637
|
+
return taken.length > 0 ? taken.join("\n") : null;
|
|
638
|
+
}
|
|
639
|
+
|
|
626
640
|
/** Settles once the result `printCliResult` last wrote has left the process: a pipe can hold it back. */
|
|
627
641
|
let stdoutWritten: Promise<void> = Promise.resolve();
|
|
628
642
|
|
|
@@ -644,13 +658,18 @@ export function printCliResult<T, Row extends Record<string, unknown> = Record<s
|
|
|
644
658
|
if (options.quiet && options.format === "text") return;
|
|
645
659
|
// JSON keeps the router's own words; everything else is for a person, so a "Not a ticker" gets its hint.
|
|
646
660
|
const hinted = (text: string) => options.format === "json" ? text : withSearchHints(text, args, isFredSeries);
|
|
647
|
-
|
|
661
|
+
// An export `--output` names is drawn for the file (no colour), and held for the command's end to write.
|
|
662
|
+
const toFile = options.output !== undefined && options.format !== "text";
|
|
663
|
+
const serialized = hinted(toFile
|
|
664
|
+
? renderForFile(() => serializeCliResult(result, options, renderOptions))
|
|
665
|
+
: serializeCliResult(result, options, renderOptions));
|
|
648
666
|
// A CSV's closing source and note lines go to stderr with the warnings: in the file they are rows of junk to a spreadsheet.
|
|
649
667
|
const { csv, footer } = options.format === "csv" ? splitCsvFooter(serialized) : { csv: serialized, footer: [] };
|
|
650
668
|
const output = csv;
|
|
669
|
+
if (toFile) fileExport.push(output);
|
|
651
670
|
// Bun's console writer can truncate a large pipe write after stdout has been
|
|
652
671
|
// initialized. The stream queues the remaining bytes until the reader drains.
|
|
653
|
-
if (output && !process.stdout.write(`${output}\n`)) {
|
|
672
|
+
else if (output && !process.stdout.write(`${output}\n`)) {
|
|
654
673
|
stdoutWritten = new Promise((resolve) => process.stdout.once("drain", () => resolve()));
|
|
655
674
|
}
|
|
656
675
|
// JSON carries warnings in its envelope. Text, CSV and NDJSON are only the
|
|
@@ -1,12 +1,15 @@
|
|
|
1
|
+
import { commandWord } from "../utils/shell-word";
|
|
2
|
+
|
|
1
3
|
/** Spreadsheet formats people ask for by name, which no command writes: CSV is the one a spreadsheet opens. */
|
|
2
4
|
const SPREADSHEET_OPTIONS = new Set(["--xlsx", "--xls", "--excel", "--spreadsheet", "--sheet", "--sheets", "--tsv"]);
|
|
3
5
|
|
|
4
6
|
/** A file named after a spreadsheet flag (`--xlsx rates.xlsx`), which becomes the CSV's name. */
|
|
5
7
|
const SPREADSHEET_FILE = /\.(xlsx|xls|tsv)$/i;
|
|
6
8
|
|
|
7
|
-
/** An argument as a shell reads it back: quoted when it holds a space or a character the shell acts on. */
|
|
9
|
+
/** An argument as a shell reads it back: quoted when it holds a space or a character the shell acts on; `"^TNX"` for cmd.exe. */
|
|
8
10
|
function shellWord(arg: string): string {
|
|
9
|
-
|
|
11
|
+
if (!/^[\w^=.,:/@%+-]+$/.test(arg)) return `'${arg.replaceAll("'", "'\\''")}'`;
|
|
12
|
+
return arg.includes("^") ? commandWord(arg) : arg;
|
|
10
13
|
}
|
|
11
14
|
|
|
12
15
|
/**
|
|
@@ -39,5 +42,6 @@ export function spreadsheetOptionHint(flag: string, command: string, args: reado
|
|
|
39
42
|
// Named after the command, a function by its code (`fn QQ`: qq.csv).
|
|
40
43
|
const named = command.trim().split(/\s+/).filter((word, index) => index > 0 || word !== "fn");
|
|
41
44
|
const output = file ? file.replace(SPREADSHEET_FILE, ".csv") : `${named.join("-").toLowerCase()}.csv`;
|
|
42
|
-
|
|
45
|
+
// --output writes the file in UTF-8 in every shell, where `>` is UTF-16 in Windows PowerShell 5.1.
|
|
46
|
+
return `Exports are --csv (opens in Excel and Google Sheets), --json or --ndjson: gloom ${words.map(shellWord).join(" ")} --csv --output ${shellWord(output)}.`;
|
|
43
47
|
}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { commandWord } from "../utils/shell-word";
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* A US Treasury yield typed as if it were a ticker: US10Y, UST10Y, US10YR,
|
|
3
5
|
* USGG10YR, 10Y, TNX, "10 year yield". None is a ticker (TNX is TenX
|
|
@@ -68,18 +70,18 @@ export function treasuryYieldTenor(text: string): TreasuryYieldTenor | null {
|
|
|
68
70
|
/** The commands with the yield: its Cboe index when there is one, its FRED series, the curve. */
|
|
69
71
|
function yieldCommands(tenor: TreasuryYieldTenor): Array<readonly [command: string, gives: string]> {
|
|
70
72
|
return [
|
|
71
|
-
...tenor.index ? [[`gloom quote ${tenor.index}`, "Cboe index"] as const] : [],
|
|
73
|
+
...tenor.index ? [[`gloom quote ${commandWord(tenor.index)}`, "Cboe index"] as const] : [],
|
|
72
74
|
[`gloom fred ${tenor.fred}`, "daily"],
|
|
73
75
|
["gloom yield-curve", "every tenor"],
|
|
74
76
|
];
|
|
75
77
|
}
|
|
76
78
|
|
|
77
|
-
/**
|
|
79
|
+
/** `US 10-year Treasury yield: gloom quote "^TNX" (Cboe index), ...`, for `search`, `catalog` and a bare root. */
|
|
78
80
|
export function treasuryYieldLine(tenor: TreasuryYieldTenor): string {
|
|
79
81
|
return `US ${tenor.label} Treasury yield: ${yieldCommands(tenor).map(([command, gives]) => `${command} (${gives})`).join(", ")}.`;
|
|
80
82
|
}
|
|
81
83
|
|
|
82
|
-
/** "Try `gloom quote ^TNX`, ... for the US 10-year Treasury yield.", after "Not a ticker: US10Y." */
|
|
84
|
+
/** "Try `gloom quote \"^TNX\"`, ... for the US 10-year Treasury yield.", after "Not a ticker: US10Y." */
|
|
83
85
|
export function treasuryYieldHint(tenor: TreasuryYieldTenor): string {
|
|
84
86
|
const commands = yieldCommands(tenor).map(([command]) => `\`${command}\``);
|
|
85
87
|
return `Try ${commands.slice(0, -1).join(", ")} or ${commands.at(-1)} for the US ${tenor.label} Treasury yield.`;
|
|
@@ -2,7 +2,7 @@ import { memo, useEffect, useRef } from "react";
|
|
|
2
2
|
import { Box, ScrollBox, Span, Text, useShortcutLabel, useUiCapabilities, type ScrollBoxRenderable } from "../../../ui";
|
|
3
3
|
import { colors as themeColors, hoverBg } from "../../../theme/colors";
|
|
4
4
|
import { CANONICAL_EXCHANGE_ALIASES } from "../../../utils/exchanges";
|
|
5
|
-
import { displayWidth, formatPercentRaw, truncateToDisplayWidth } from "../../../utils/format";
|
|
5
|
+
import { displayWidth, formatPercentRaw, truncateToDisplayWidth, truncateToWidth } from "../../../utils/format";
|
|
6
6
|
import type { ResolvedSeries } from "../../../time-series/types";
|
|
7
7
|
import { consumeChartMouseEvent, type ChartMouseEvent } from "../core/pointer";
|
|
8
8
|
import {
|
|
@@ -99,6 +99,43 @@ function withoutListingExchange(label: string): string {
|
|
|
99
99
|
));
|
|
100
100
|
}
|
|
101
101
|
|
|
102
|
+
/** Characters two labels start with alike. */
|
|
103
|
+
function sharedStart(left: string, right: string): number {
|
|
104
|
+
let index = 0;
|
|
105
|
+
while (index < left.length && index < right.length && left[index] === right[index]) index += 1;
|
|
106
|
+
return index;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/** The last characters of `value` that fit in `width` cells. */
|
|
110
|
+
function tailToWidth(value: string, width: number): string {
|
|
111
|
+
let tail = "";
|
|
112
|
+
for (const char of [...value].reverse()) {
|
|
113
|
+
if (displayWidth(char + tail) > width) break;
|
|
114
|
+
tail = char + tail;
|
|
115
|
+
}
|
|
116
|
+
return tail;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* A legend name cut to `width` cells so it still tells itself from the other
|
|
121
|
+
* names in the legend: cut at its end while what shows gets past the start it
|
|
122
|
+
* shares with another; otherwise its head, `...`, then the end of what follows
|
|
123
|
+
* that shared start. `HY - IG` beside `HY` keeps `- IG`, and two formulas on
|
|
124
|
+
* one first leg keep their second (`FRED:BA...C0A0CM`, `FRED:BA...spread`).
|
|
125
|
+
*/
|
|
126
|
+
export function distinguishingLabelCut(label: string, width: number, others: readonly string[]): string {
|
|
127
|
+
const plain = truncateToDisplayWidth(label, width);
|
|
128
|
+
if (plain === label || width <= 6) return plain;
|
|
129
|
+
const shared = Math.max(0, ...others.filter((other) => other !== label).map((other) => sharedStart(label, other)));
|
|
130
|
+
const stem = truncateToWidth(label, width - 3);
|
|
131
|
+
const rest = label.slice(shared).trimStart();
|
|
132
|
+
if (stem.length > shared || !rest) return plain;
|
|
133
|
+
// The end of the rest gets the room a third of a head leaves, the head whatever a short rest leaves over.
|
|
134
|
+
const room = width - 3;
|
|
135
|
+
const head = truncateToWidth(label, Math.min(room - 1, Math.max(Math.max(1, Math.floor(room / 3)), room - displayWidth(rest)))).trimEnd();
|
|
136
|
+
return `${head}...${tailToWidth(rest, room - displayWidth(head))}`;
|
|
137
|
+
}
|
|
138
|
+
|
|
102
139
|
/**
|
|
103
140
|
* Entries laid left to right into lines of `available` cells, one cell apart,
|
|
104
141
|
* a new line when the next does not fit. With `maxLines`, what does not fit in
|
|
@@ -311,7 +348,8 @@ export function CompositeLegend({
|
|
|
311
348
|
const setEntryLabel = (target: LegendEntry, label: string, labelWidth: number) => {
|
|
312
349
|
target.label = label;
|
|
313
350
|
target.labelWidth = labelWidth;
|
|
314
|
-
|
|
351
|
+
const others = entries.filter((other) => other !== target).map((other) => other.compactLabel);
|
|
352
|
+
target.text = [distinguishingLabelCut(label, labelWidth, others), target.valueText].filter(Boolean).join(" ");
|
|
315
353
|
target.width = Math.max(1, displayWidth(target.text)) + target.markerWidth;
|
|
316
354
|
};
|
|
317
355
|
const measureSeriesWidth = () => entries.reduce(
|
|
@@ -4,7 +4,7 @@ import type { AppAction, AppState } from "../../../state/app/context";
|
|
|
4
4
|
import type { AppTickerRepositoryPort } from "../../../core/app-service-ports";
|
|
5
5
|
import type { PluginRegistry } from "../../../plugins/registry";
|
|
6
6
|
import { isManualPortfolio } from "../../../portfolio/mutations";
|
|
7
|
-
import { findNamedCollection, readWatchlistArgument } from "../../../portfolio/collection-name";
|
|
7
|
+
import { findNamedCollection, readWatchlistArgument, watchlistMemberSymbol } from "../../../portfolio/collection-name";
|
|
8
8
|
import type { DataProvider } from "../../../types/data-provider";
|
|
9
9
|
import type { Portfolio, TickerRecord, Watchlist } from "../../../types/ticker";
|
|
10
10
|
import { AmbiguousTickerError, resolveTickerSearch, upsertTickerFromSearchResult } from "../../../tickers/search";
|
|
@@ -278,7 +278,7 @@ export async function resolveTickerListInput(
|
|
|
278
278
|
const state = deps.getState();
|
|
279
279
|
const watchlist = /[,;\n]/.test(rawInput) ? null : findNamedCollection(state.config.watchlists, rawInput);
|
|
280
280
|
const members = watchlist
|
|
281
|
-
? [...state.tickers.values()].filter((ticker) => ticker.metadata.watchlists.includes(watchlist.id)).map((ticker) => ticker.metadata
|
|
281
|
+
? [...state.tickers.values()].filter((ticker) => ticker.metadata.watchlists.includes(watchlist.id)).map((ticker) => watchlistMemberSymbol(ticker.metadata))
|
|
282
282
|
: [];
|
|
283
283
|
if (watchlist && members.length > 0) {
|
|
284
284
|
const read = readWatchlistArgument(rawInput, watchlist, members, reading?.maximum);
|
|
@@ -13,7 +13,7 @@ import { useBeforeShortcut, useShortcut } from "../../react/input";
|
|
|
13
13
|
import { isPlainKey, isPlainKeyboardEvent } from "../../utils/keyboard";
|
|
14
14
|
import { DataTable, PaneStatusBody, type DataTableColumn, type DataTableProps, type PaneStatusBodyProps } from "../ui";
|
|
15
15
|
import { useDataTableSortMenu } from "./sort-menu";
|
|
16
|
-
import { tableScrollStep } from "../ui/table-layout";
|
|
16
|
+
import { tableFreezesFirstColumn, tableScrollStep } from "../ui/table-layout";
|
|
17
17
|
import {
|
|
18
18
|
TableViewFrame,
|
|
19
19
|
useResetTableScroll,
|
|
@@ -694,7 +694,14 @@ export function DataTableView<
|
|
|
694
694
|
columns: tableProps.columns,
|
|
695
695
|
columnGap: tableProps.columnGap,
|
|
696
696
|
horizontalPadding: tableProps.horizontalPadding,
|
|
697
|
-
frozenFirstColumn:
|
|
697
|
+
frozenFirstColumn: tableFreezesFirstColumn({
|
|
698
|
+
freezeFirstColumn: tableProps.freezeFirstColumn,
|
|
699
|
+
columns: tableProps.columns,
|
|
700
|
+
columnGap: tableProps.columnGap,
|
|
701
|
+
horizontalPadding: tableProps.horizontalPadding,
|
|
702
|
+
viewportWidth,
|
|
703
|
+
overflows: true,
|
|
704
|
+
}),
|
|
698
705
|
scrollLeft: currentLeft,
|
|
699
706
|
direction,
|
|
700
707
|
viewportWidth,
|
|
@@ -20,6 +20,7 @@ import {
|
|
|
20
20
|
tableColumnStarts,
|
|
21
21
|
tableContentWidthProps,
|
|
22
22
|
tableFarEdgePad,
|
|
23
|
+
tableFreezesFirstColumn,
|
|
23
24
|
tableScrollStep,
|
|
24
25
|
useMeasuredTableContentWidth,
|
|
25
26
|
} from "../../table-layout";
|
|
@@ -131,7 +132,9 @@ function OpenTuiDataTableRowInner<
|
|
|
131
132
|
flexDirection="row"
|
|
132
133
|
height={1}
|
|
133
134
|
{...tableContentWidthProps(contentWidth)}
|
|
134
|
-
|
|
135
|
+
// Beside a pinned first column the heading stays in view too, not cut to its last letters.
|
|
136
|
+
paddingLeft={horizontalPadding + (frozenColumnOffset ?? 0)}
|
|
137
|
+
paddingRight={horizontalPadding}
|
|
135
138
|
backgroundColor={selected ? colors.selected : sectionHeader.backgroundColor ?? colors.bg}
|
|
136
139
|
onMouseDown={(event: any) => {
|
|
137
140
|
focusPane();
|
|
@@ -310,7 +313,7 @@ export function OpenTuiDataTable<T, C extends DataTableColumn = DataTableColumn>
|
|
|
310
313
|
horizontalPadding = 1,
|
|
311
314
|
fillAvailableWidth = true,
|
|
312
315
|
showHorizontalScrollbar = true,
|
|
313
|
-
freezeFirstColumn
|
|
316
|
+
freezeFirstColumn: freezeFirstColumnProp,
|
|
314
317
|
scrollToIndex,
|
|
315
318
|
scrollToIndexAlign = "nearest",
|
|
316
319
|
scrollToIndexVersion = 0,
|
|
@@ -375,6 +378,10 @@ export function OpenTuiDataTable<T, C extends DataTableColumn = DataTableColumn>
|
|
|
375
378
|
} = useMeasuredTableContentWidth(tableWidth, headerScrollRef, scrollRef);
|
|
376
379
|
const horizontalScrollbarVisible = showHorizontalScrollbar
|
|
377
380
|
&& hasMeaningfulTableHorizontalOverflow(tableWidth, measuredViewportWidth, columnGap);
|
|
381
|
+
const freezeFirstColumn = tableFreezesFirstColumn({
|
|
382
|
+
freezeFirstColumn: freezeFirstColumnProp, columns, columnGap, horizontalPadding, viewportWidth: measuredViewportWidth,
|
|
383
|
+
overflows: horizontalScrollbarVisible,
|
|
384
|
+
});
|
|
378
385
|
const contentWidth = fillAvailableWidth ? measuredContentWidth : tableWidth;
|
|
379
386
|
const sectionWidth = measuredViewportWidth > 0 ? Math.min(contentWidth, measuredViewportWidth) : contentWidth;
|
|
380
387
|
const displayColumns = useMemo(
|
|
@@ -390,7 +397,7 @@ export function OpenTuiDataTable<T, C extends DataTableColumn = DataTableColumn>
|
|
|
390
397
|
const scrollContentWidth = contentWidth + (freezeFirstColumn && horizontalScrollbarVisible
|
|
391
398
|
? tableFarEdgePad({ columns: displayColumns, columnGap, horizontalPadding, contentWidth, viewportWidth: measuredViewportWidth })
|
|
392
399
|
: 0);
|
|
393
|
-
// Columns out of view past the right edge: the header row ends in "more
|
|
400
|
+
// Columns out of view past the right edge: the header row ends in "more ⇧→" there, a press on it scrolls to
|
|
394
401
|
// them, and the rows leave its cells blank, so a narrow pane says it has more than it shows. The header's
|
|
395
402
|
// scroll box is as wide as the body's viewport (measuredViewportWidth), so the header row has a blank cell
|
|
396
403
|
// past it, over the body's vertical scrollbar; the hint is laid over the row, not inside the scroll box,
|
|
@@ -488,7 +495,7 @@ export function OpenTuiDataTable<T, C extends DataTableColumn = DataTableColumn>
|
|
|
488
495
|
scrollRef: headerScrollRef,
|
|
489
496
|
onHorizontalScroll: syncBodyScroll,
|
|
490
497
|
});
|
|
491
|
-
// "more
|
|
498
|
+
// "more ⇧→" steps right as Shift+Right does: half the viewport (beside a frozen column, to a column's edge).
|
|
492
499
|
const scrollToMoreColumns = useCallback(() => {
|
|
493
500
|
const body = scrollRef.current;
|
|
494
501
|
const viewportWidth = body?.viewport?.width ?? 0;
|
|
@@ -90,11 +90,13 @@ export function reuseDataTableColumnClips(
|
|
|
90
90
|
/**
|
|
91
91
|
* What a table's header says at its right edge while columns are out of view
|
|
92
92
|
* past it, longest first: the longest that fits beside the last column shown
|
|
93
|
-
* whole is drawn.
|
|
94
|
-
*
|
|
95
|
-
*
|
|
93
|
+
* whole is drawn. It names the key that scrolls there, Shift+Right in compact
|
|
94
|
+
* notation (`⇧→`): a plain Right switches a pane's tabs. With that column
|
|
95
|
+
* against the edge, the arrow takes the blank its label ends in. The hint
|
|
96
|
+
* never hides a column: with no blank to take, the horizontal scrollbar is
|
|
97
|
+
* the only sign.
|
|
96
98
|
*/
|
|
97
|
-
const MORE_COLUMNS_LABELS = ["more
|
|
99
|
+
const MORE_COLUMNS_LABELS = ["more ⇧→", "⇧→", "→"] as const;
|
|
98
100
|
|
|
99
101
|
export interface MoreColumnsHint {
|
|
100
102
|
/** The cells the hint draws: its label, after a blank unless it takes the last column's own. */
|
|
@@ -128,7 +130,7 @@ function hasColumnsPastRightEdge(columns: readonly HintColumn[], starts: readonl
|
|
|
128
130
|
}
|
|
129
131
|
|
|
130
132
|
/**
|
|
131
|
-
* The "more
|
|
133
|
+
* The "more ⇧→" hint at the header's right edge while columns are out of view
|
|
132
134
|
* past it, or null. The header's scroll box is as wide as the viewport, and
|
|
133
135
|
* `besideHeader` blank cells follow it on the header row (the cell over the
|
|
134
136
|
* body's vertical scrollbar); the hint, laid over the row, can reach them.
|
|
@@ -193,7 +195,7 @@ export function resolveMoreColumnsHint({
|
|
|
193
195
|
* Each column's clip at the current scroll, null for a column shown whole.
|
|
194
196
|
* A frozen first column stays, and what slides under it counts as cut on the
|
|
195
197
|
* left. `rightReserve` cells at the right edge show no column (under the
|
|
196
|
-
* "more
|
|
198
|
+
* "more ⇧→" hint, `resolveMoreColumnsHint`). Null for the whole table when every column is whole or nothing is
|
|
197
199
|
* measured yet.
|
|
198
200
|
*/
|
|
199
201
|
export function resolveDataTableColumnClips({
|
|
@@ -175,7 +175,12 @@ export interface DataTableProps<
|
|
|
175
175
|
horizontalPadding?: number;
|
|
176
176
|
fillAvailableWidth?: boolean;
|
|
177
177
|
showHorizontalScrollbar?: boolean;
|
|
178
|
-
/**
|
|
178
|
+
/**
|
|
179
|
+
* Keep the row identifier visible during horizontal scrolling. Unset, the
|
|
180
|
+
* first column is pinned while the table is too wide for its viewport and
|
|
181
|
+
* that column leaves the rest at least half of it (`tableFreezesFirstColumn`);
|
|
182
|
+
* `false` lets it scroll away.
|
|
183
|
+
*/
|
|
179
184
|
freezeFirstColumn?: boolean;
|
|
180
185
|
/** Append export-only source records after the displayed table. */
|
|
181
186
|
getExportMetadata?: () => readonly (readonly unknown[])[];
|
|
@@ -141,6 +141,43 @@ export function tableColumnStarts(columns: readonly TableWidthColumn[], columnGa
|
|
|
141
141
|
return starts;
|
|
142
142
|
}
|
|
143
143
|
|
|
144
|
+
/** The narrowest first column that names its row: a short ticker. A rank (`#`) or a status dot is narrower. */
|
|
145
|
+
const ROW_LABEL_MIN_WIDTH = 4;
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Whether a table pins its first column while it scrolls sideways. A table
|
|
149
|
+
* that sets `freezeFirstColumn` gets what it set; one that leaves it unset
|
|
150
|
+
* pins its first column while it is too wide for its viewport (`overflows`)
|
|
151
|
+
* and that column leaves the others at least half the viewport, so scrolled
|
|
152
|
+
* right each row still says what it is (a 70-column Relative Valuation read
|
|
153
|
+
* `4.50T 23.6 11.7` with no ticker). A first column the pane draws itself
|
|
154
|
+
* (a name beside its kind, a badge) pins as drawn. A table that fits is drawn
|
|
155
|
+
* as it always was. A first column too narrow to name its row (a rank, a
|
|
156
|
+
* status dot, a star) or wider than half would leave nothing worth pinning or
|
|
157
|
+
* too little to scroll through, so it scrolls.
|
|
158
|
+
*/
|
|
159
|
+
export function tableFreezesFirstColumn({
|
|
160
|
+
freezeFirstColumn,
|
|
161
|
+
columns,
|
|
162
|
+
columnGap = 1,
|
|
163
|
+
horizontalPadding = 1,
|
|
164
|
+
viewportWidth,
|
|
165
|
+
overflows,
|
|
166
|
+
}: {
|
|
167
|
+
freezeFirstColumn: boolean | undefined;
|
|
168
|
+
columns: readonly TableWidthColumn[];
|
|
169
|
+
columnGap?: number;
|
|
170
|
+
horizontalPadding?: number;
|
|
171
|
+
viewportWidth: number;
|
|
172
|
+
overflows: boolean;
|
|
173
|
+
}): boolean {
|
|
174
|
+
if (freezeFirstColumn !== undefined) return freezeFirstColumn;
|
|
175
|
+
const first = columns[0];
|
|
176
|
+
if (!overflows || !first || columns.length < 2 || viewportWidth <= 0) return false;
|
|
177
|
+
const width = tableColumnWidth(first);
|
|
178
|
+
return width >= ROW_LABEL_MIN_WIDTH && (horizontalPadding + width + columnGap) * 2 <= viewportWidth;
|
|
179
|
+
}
|
|
180
|
+
|
|
144
181
|
/**
|
|
145
182
|
* Where a frozen board can stop: 0, each column's edge (its start just past
|
|
146
183
|
* the frozen column) and its end, the first edge that shows the last column
|
|
@@ -159,7 +196,7 @@ function frozenBoardStops(columns: readonly TableWidthColumn[], columnGap: numbe
|
|
|
159
196
|
|
|
160
197
|
/**
|
|
161
198
|
* Where a sideways step of a table too wide for its pane lands (Shift or
|
|
162
|
-
* Ctrl+Left/Right, "more
|
|
199
|
+
* Ctrl+Left/Right, "more ⇧→"): half the viewport on. With a frozen first
|
|
163
200
|
* column it stops at a column's edge, so the column beside the frozen one
|
|
164
201
|
* shows whole: half a viewport cut a column under it, and a rate too wide
|
|
165
202
|
* for what showed went blank. A column wider than half the viewport is
|
package/src/docs/snapshot.json
CHANGED
|
@@ -1202,7 +1202,7 @@
|
|
|
1202
1202
|
"code": "GC",
|
|
1203
1203
|
"name": "Yield curves",
|
|
1204
1204
|
"description": "Government bond curves",
|
|
1205
|
-
"detail": "Government yield curves: US Treasury, TIPS real yields and breakevens, euro AAA, Bund, Gilt, JGB and Canada, with spreads like 2s10s and their one-year percentiles, a two-date difference and a World tab. GC JGB opens a curve directly.",
|
|
1205
|
+
"detail": "Government yield curves: US Treasury, TIPS real yields and breakevens, euro AAA, Bund, Gilt, JGB and Canada, with spreads like 2s10s and their one-year percentiles, a two-date difference and a World tab that adds Mexico's and Brazil's 2- and 10-year yields. GC JGB opens a curve directly.",
|
|
1206
1206
|
"category": "macro",
|
|
1207
1207
|
"shot": "https://gloom.sh/screenshots/fn/GC.png",
|
|
1208
1208
|
"lesson": "/academy/rates-bonds-credit/rates/yield-curve"
|
|
@@ -6202,7 +6202,7 @@
|
|
|
6202
6202
|
"terminal",
|
|
6203
6203
|
"remote control"
|
|
6204
6204
|
],
|
|
6205
|
-
"updatedAt": "2026-11-
|
|
6205
|
+
"updatedAt": "2026-11-07",
|
|
6206
6206
|
"blocks": [
|
|
6207
6207
|
{
|
|
6208
6208
|
"type": "paragraph",
|
|
@@ -6374,7 +6374,7 @@
|
|
|
6374
6374
|
],
|
|
6375
6375
|
[
|
|
6376
6376
|
"`sec.insider_transactions`",
|
|
6377
|
-
"`ticker`"
|
|
6377
|
+
"`ticker`, `since?`, `until?` (trade dates, `YYYY-MM-DD`: every Form 4 of the window, and which days it covers), `offset?`"
|
|
6378
6378
|
],
|
|
6379
6379
|
[
|
|
6380
6380
|
"`sec.thirteenf_holders`",
|
|
@@ -139,19 +139,23 @@ function previousIndexSession(quote: Quote, date: string): string | null {
|
|
|
139
139
|
* calendar, with the closures in between (an index's, the venue whose days it
|
|
140
140
|
* follows); otherwise for an index from its own sessions; for a currency pair
|
|
141
141
|
* the weekday before; for any other listing the day its own daily closes date
|
|
142
|
-
* its previous close to (`previousCloseDate`, PreviousCloseDates).
|
|
143
|
-
*
|
|
142
|
+
* its previous close to (`previousCloseDate`, PreviousCloseDates). A thin
|
|
143
|
+
* listing's previous trade before the calendar's session is its own day, and
|
|
144
|
+
* one whose closes cannot name it is left undated. Null when nothing dates it.
|
|
144
145
|
*/
|
|
145
146
|
function previousSession(quote: Quote, sessionDate: string): DatedChangeBasis | null {
|
|
147
|
+
if (quote.previousCloseUndated) return null;
|
|
146
148
|
const venue = calendarVenue(quote);
|
|
149
|
+
const dated = quote.previousCloseDate && ISO_DATE.test(quote.previousCloseDate) && quote.previousCloseDate < sessionDate
|
|
150
|
+
? quote.previousCloseDate : null;
|
|
147
151
|
const published = previousPublishedSession(venue, sessionDate);
|
|
152
|
+
// A listing that did not trade in the calendar's session moves from its previous trade, an earlier day.
|
|
153
|
+
if (published && dated && dated < published.date) return { kind: "close", date: dated, venue };
|
|
148
154
|
if (published) return { kind: "close", date: published.date, venue, closed: published.closed };
|
|
149
155
|
const index = previousIndexSession(quote, sessionDate);
|
|
150
156
|
if (index) return { kind: "close", date: index };
|
|
151
157
|
if (isCurrencyPair(quote)) return { kind: "close", date: weekdayBefore(sessionDate) };
|
|
152
|
-
|
|
153
|
-
if (dated && ISO_DATE.test(dated) && dated < sessionDate) return { kind: "close", date: dated };
|
|
154
|
-
return null;
|
|
158
|
+
return dated ? { kind: "close", date: dated } : null;
|
|
155
159
|
}
|
|
156
160
|
|
|
157
161
|
/**
|
|
@@ -50,7 +50,7 @@ export interface DatedCloseListing {
|
|
|
50
50
|
|
|
51
51
|
/** A listing's recent daily closes (a month is enough), with the flags that say a bar had not closed yet. */
|
|
52
52
|
export type ReadDailyCloses = (listing: DatedCloseListing) => Promise<readonly DailyClose[]>;
|
|
53
|
-
type DailyClose = Pick<PricePoint, "date" | "close" | "partial" | "unsettled"
|
|
53
|
+
type DailyClose = Pick<PricePoint, "date" | "close" | "partial" | "unsettled"> & { volume?: number };
|
|
54
54
|
|
|
55
55
|
export interface PreviousCloseDatesOptions {
|
|
56
56
|
/** Called with the latest copy of a quote, dated, when a read lands that names its day. */
|
|
@@ -62,7 +62,7 @@ export interface PreviousCloseDatesOptions {
|
|
|
62
62
|
indexWaitMs?: number;
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
-
type ReadingFields = Pick<Reading, "date" | "close" | "sessionClose" | "awaitsSessionClose">;
|
|
65
|
+
type ReadingFields = Pick<Reading, "date" | "close" | "sessionClose" | "awaitsSessionClose" | "untraded">;
|
|
66
66
|
|
|
67
67
|
interface Reading {
|
|
68
68
|
date: string | null;
|
|
@@ -75,6 +75,12 @@ interface Reading {
|
|
|
75
75
|
sessionClose?: number;
|
|
76
76
|
/** A closed quote on such a venue whose session's bar was not in the history yet: read again until it lands. */
|
|
77
77
|
awaitsSessionClose?: boolean;
|
|
78
|
+
/**
|
|
79
|
+
* A thin listing that did not trade in the session its venue's calendar
|
|
80
|
+
* puts before the move's, whose earlier closes do not hold its previous
|
|
81
|
+
* close either (ThinPreviousTrade): no day can be named for it.
|
|
82
|
+
*/
|
|
83
|
+
untraded?: boolean;
|
|
78
84
|
at: number;
|
|
79
85
|
}
|
|
80
86
|
|
|
@@ -92,7 +98,16 @@ const OFFICIAL_PREVIOUS_CLOSE_VENUES: ReadonlyMap<string, number> = new Map([["B
|
|
|
92
98
|
* the daily bar is the official close, as history and the portfolio read it:
|
|
93
99
|
* B3's PETR4 quoted R$45.36 on Fri 6 Nov 2026 beside a R$45.30 close.
|
|
94
100
|
*/
|
|
95
|
-
const DAILY_BAR_CLOSE_VENUES: ReadonlySet<string> = new Set(["B3"]);
|
|
101
|
+
export const DAILY_BAR_CLOSE_VENUES: ReadonlySet<string> = new Set(["B3"]);
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* A session volume below which a share or fund on a venue whose calendar
|
|
105
|
+
* dates its moves may not have traded in the session before: its daily closes
|
|
106
|
+
* are read to find its previous trade (thinPreviousTrade). B95 on SGX traded
|
|
107
|
+
* 3,661 units on Fri 6 Nov 2026 and last before that on 22 Oct, while the
|
|
108
|
+
* calendar put its move "vs Thu 5 Nov".
|
|
109
|
+
*/
|
|
110
|
+
const THIN_SESSION_VOLUME = 50_000;
|
|
96
111
|
|
|
97
112
|
/** A close this far from the quote's price is another unit's or another listing's, never the session's. */
|
|
98
113
|
const MAX_SESSION_CLOSE_MOVE = 0.25;
|
|
@@ -120,11 +135,26 @@ function readingKey(quote: Quote | null | undefined, listing: DatedCloseListing,
|
|
|
120
135
|
// An index's dated close is checked against its daily close of that day as well (indexCloseOn), but for a Cboe
|
|
121
136
|
// index's, which Gloom Cloud checks against Cboe's own closes.
|
|
122
137
|
if (datedIndexClose(quote)) return calendarVenue(quote) === "CBOE" ? null : datedReadingKey(quote, listing);
|
|
123
|
-
if (isChangeBasisDatedWithoutCloses(quote, now)) return null;
|
|
138
|
+
if (isChangeBasisDatedWithoutCloses(quote, now)) return thinListingCalendarDate(quote) ? `${datedReadingKey(quote, listing)}|thin` : null;
|
|
124
139
|
if (quoteChangeBasis(quote)?.kind !== "previous close") return null;
|
|
125
140
|
return datedReadingKey(quote, listing);
|
|
126
141
|
}
|
|
127
142
|
|
|
143
|
+
/**
|
|
144
|
+
* The session a venue's calendar puts before a thin listing's move, for a
|
|
145
|
+
* share or fund whose completed session traded under THIN_SESSION_VOLUME:
|
|
146
|
+
* such a listing may not have traded in it, which only its daily closes say.
|
|
147
|
+
* Null for any other quote, so a board of busy listings reads no history.
|
|
148
|
+
*/
|
|
149
|
+
function thinListingCalendarDate(quote: Quote): string | null {
|
|
150
|
+
const kind = classifyInstrumentType(quote.instrumentType);
|
|
151
|
+
if (kind !== "equity" && kind !== "fund") return null;
|
|
152
|
+
if (quote.marketState === "REGULAR" || quote.previousCloseDate) return null;
|
|
153
|
+
if (!(typeof quote.volume === "number" && quote.volume >= 0 && quote.volume < THIN_SESSION_VOLUME)) return null;
|
|
154
|
+
const basis = quoteChangeBasis(quote);
|
|
155
|
+
return basis?.kind === "close" && basis.venue ? basis.date : null;
|
|
156
|
+
}
|
|
157
|
+
|
|
128
158
|
function datedReadingKey(quote: Quote, listing: DatedCloseListing): string | null {
|
|
129
159
|
const previousClose = quote.previousClose;
|
|
130
160
|
const sessionDate = changeBasisSessionDate(quote);
|
|
@@ -222,9 +252,29 @@ function indexCloseOn(points: readonly DailyClose[], quote: Quote, date: string)
|
|
|
222
252
|
return Math.abs(previousClose - close) <= close * SAME_INDEX_CLOSE_RELATIVE ? { date } : { date, close };
|
|
223
253
|
}
|
|
224
254
|
|
|
255
|
+
/**
|
|
256
|
+
* A thin listing's previous trade, where it is earlier than the session its
|
|
257
|
+
* venue's calendar puts before the move's: the day of its latest daily close
|
|
258
|
+
* before the move's session that traded, when that close is its previous
|
|
259
|
+
* close. When it traded in the calendar's session the calendar stands
|
|
260
|
+
* (date null); when its closes hold neither, the day is unknown (`untraded`).
|
|
261
|
+
*/
|
|
262
|
+
function thinPreviousTrade(points: readonly DailyClose[], quote: Quote, calendarDate: string): ReadingFields {
|
|
263
|
+
const sessionDate = changeBasisSessionDate(quote)!;
|
|
264
|
+
const traded = new Set(points.filter((point) => point.volume == null || point.volume > 0).map((point) => point.date.valueOf()));
|
|
265
|
+
const before = closedBars(points.filter((point) => traded.has(point.date.valueOf())), quote)
|
|
266
|
+
.filter((point) => point.date < sessionDate)
|
|
267
|
+
.sort((left, right) => left.date.localeCompare(right.date))
|
|
268
|
+
.at(-1);
|
|
269
|
+
if (!before || before.date >= calendarDate) return { date: null };
|
|
270
|
+
return sameClose(before.close, quote.previousClose!) ? { date: before.date } : { date: null, untraded: true };
|
|
271
|
+
}
|
|
272
|
+
|
|
225
273
|
function readingOf(points: readonly DailyClose[], quote: Quote): ReadingFields {
|
|
226
274
|
const indexDate = datedIndexClose(quote);
|
|
227
275
|
if (indexDate) return indexCloseOn(points, quote, indexDate);
|
|
276
|
+
const calendarDate = thinListingCalendarDate(quote);
|
|
277
|
+
if (calendarDate) return thinPreviousTrade(points, quote, calendarDate);
|
|
228
278
|
const session = sessionCloseOf(points, quote);
|
|
229
279
|
return {
|
|
230
280
|
date: latestCloseBefore(points, quote),
|
|
@@ -238,8 +288,9 @@ function withDate<T extends Quote | null | undefined>(quote: T, date: string | n
|
|
|
238
288
|
}
|
|
239
289
|
|
|
240
290
|
/** The quote as a reading has it: dated, and for an index measured from that day's close when its own disagrees. */
|
|
241
|
-
function withReading<T extends Quote | null | undefined>(quote: T, reading: Pick<Reading, "date" | "close" | "sessionClose"> | undefined): T {
|
|
291
|
+
function withReading<T extends Quote | null | undefined>(quote: T, reading: Pick<Reading, "date" | "close" | "sessionClose" | "untraded"> | undefined): T {
|
|
242
292
|
if (!quote || !reading) return quote;
|
|
293
|
+
if (reading.untraded) return { ...quote, previousCloseUndated: true };
|
|
243
294
|
const closed = withSessionClose(quote, reading.sessionClose);
|
|
244
295
|
return closed === quote ? withDatedReading(quote, reading) : withDatedReading(closed as T, reading);
|
|
245
296
|
}
|
|
@@ -369,7 +420,7 @@ export class PreviousCloseDates {
|
|
|
369
420
|
this.readings.set(key, { ...reading, at: this.now() });
|
|
370
421
|
const latest = this.latestCopies.get(key);
|
|
371
422
|
this.latestCopies.delete(key);
|
|
372
|
-
if ((reading.date || reading.sessionClose != null) && latest && this.options.onDated) {
|
|
423
|
+
if ((reading.date || reading.sessionClose != null || reading.untraded) && latest && this.options.onDated) {
|
|
373
424
|
try {
|
|
374
425
|
this.options.onDated(latest.listing, withReading(latest.quote, reading));
|
|
375
426
|
} catch (error) {
|
|
@@ -251,6 +251,8 @@ export function mergeQuoteContribution(
|
|
|
251
251
|
delete merged.previousCloseDate;
|
|
252
252
|
}
|
|
253
253
|
}
|
|
254
|
+
// So is a close its daily closes could not date: the next reading says it again.
|
|
255
|
+
if (next.previousCloseUndated === undefined) delete merged.previousCloseUndated;
|
|
254
256
|
|
|
255
257
|
if (isOtherTradingDay(current, next)) {
|
|
256
258
|
const record = merged as unknown as Record<string, unknown>;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { EnterpriseValueCheck, TickerFinancials } from "../../types/financials";
|
|
2
|
+
import {
|
|
3
|
+
enterpriseValueCheck, enterpriseValueNotMeaningful, enterpriseValueWithdrawn, reportedEnterpriseValue, withBankEnterpriseValue,
|
|
4
|
+
} from "../../utils/fundamentals";
|
|
5
|
+
import { atRegularSessionPrice } from "./regular-session-valuation";
|
|
6
|
+
|
|
7
|
+
export type ListingEnterpriseValue =
|
|
8
|
+
| {
|
|
9
|
+
kind: "value";
|
|
10
|
+
value: number;
|
|
11
|
+
currency: string;
|
|
12
|
+
/** `computed`: market cap + total debt - cash, standing in for a provider figure Gloom Cloud withdrew. */
|
|
13
|
+
basis: "served" | "computed";
|
|
14
|
+
/** The withdrawn check a computed EV comes from, which names its balance sheet and rate. */
|
|
15
|
+
check?: EnterpriseValueCheck;
|
|
16
|
+
/**
|
|
17
|
+
* The rate the EV's balance sheet check converted the statements' currency
|
|
18
|
+
* at (an ADR's EUR or TWD into its USD EV), from any check that names one.
|
|
19
|
+
*/
|
|
20
|
+
fx?: { from: string; rate: number };
|
|
21
|
+
}
|
|
22
|
+
| { kind: "not-meaningful"; reason: string }
|
|
23
|
+
| { kind: "unavailable" };
|
|
24
|
+
|
|
25
|
+
const finite = (value: unknown): value is number => typeof value === "number" && Number.isFinite(value);
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* The enterprise value every surface divides, at the regular session price:
|
|
29
|
+
* the one Gloom Cloud serves (`valuation`'s EV, RV's EV/S, the screener's
|
|
30
|
+
* EV/EBITDA), or, where it withdrew the provider's figure against the balance
|
|
31
|
+
* sheet, the market cap + total debt - cash it checked that figure against.
|
|
32
|
+
* Not meaningful at or below zero and for a bank.
|
|
33
|
+
*/
|
|
34
|
+
export function listingEnterpriseValue(financials: Pick<TickerFinancials, "quote" | "fundamentals" | "profile">): ListingEnterpriseValue {
|
|
35
|
+
const priced = atRegularSessionPrice({ quote: financials.quote, fundamentals: withBankEnterpriseValue(financials.fundamentals, financials.profile) });
|
|
36
|
+
const fundamentals = priced.fundamentals;
|
|
37
|
+
const notMeaningful = enterpriseValueNotMeaningful(fundamentals);
|
|
38
|
+
if (notMeaningful) return { kind: "not-meaningful", reason: notMeaningful };
|
|
39
|
+
const check = enterpriseValueCheck(fundamentals);
|
|
40
|
+
const served = reportedEnterpriseValue(fundamentals);
|
|
41
|
+
const currency = check?.currency ?? fundamentals?.marketCapCurrency ?? priced.quote?.currency;
|
|
42
|
+
const fx = check?.fx && check.fx.from && finite(check.fx.rate) && check.fx.rate > 0 ? { fx: check.fx } : {};
|
|
43
|
+
if (served != null) return currency ? { kind: "value", value: served, currency, basis: "served", ...fx } : { kind: "unavailable" };
|
|
44
|
+
if (enterpriseValueWithdrawn(fundamentals) && check?.status === "withdrawn" && finite(check.computed) && check.currency) {
|
|
45
|
+
return check.computed > 0
|
|
46
|
+
? { kind: "value", value: check.computed, currency: check.currency, basis: "computed", check, ...fx }
|
|
47
|
+
: { kind: "not-meaningful", reason: "Cash and short-term investments exceed market cap + total debt" };
|
|
48
|
+
}
|
|
49
|
+
return { kind: "unavailable" };
|
|
50
|
+
}
|