gloomberb 0.20.4 → 0.20.5
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 +2 -0
- package/bin/gloom +9 -0
- package/bin/without-bun.cjs +98 -0
- package/package.json +3 -1
- package/src/api-client/data.ts +138 -35
- package/src/api-client/types/econ.ts +12 -0
- package/src/api-client/yield-curves.ts +1 -1
- package/src/app/global-shortcuts.ts +4 -1
- package/src/app/keybindings/actions.ts +6 -0
- package/src/app/keybindings/config.ts +2 -1
- package/src/app/keybindings/index.ts +1 -0
- package/src/app/keybindings/labels.ts +6 -1
- package/src/app/keybindings/resolve.ts +23 -4
- package/src/app/keybindings/terminal-keys.ts +35 -0
- package/src/app/pane-runtime/index.tsx +2 -2
- package/src/app/pane-runtime/ticker-open-runtime.ts +68 -40
- package/src/architecture/ui-literals-allowlist.json +1 -1
- package/src/capabilities/chart-series.ts +27 -1
- package/src/cli/commands/keybindings.ts +5 -5
- package/src/cli/commands/market.ts +78 -21
- package/src/cli/commands/news-search.ts +59 -7
- package/src/cli/commands/overview.ts +16 -1
- package/src/cli/commands/remote.ts +16 -17
- package/src/cli/commands/system.ts +1 -1
- package/src/cli/fx-forward.ts +25 -7
- package/src/cli/glossary.ts +19 -5
- package/src/cli/history-rows.ts +5 -3
- package/src/cli/known-gaps.ts +27 -1
- package/src/cli/listing-arg.ts +11 -1
- package/src/cli/name-entries.ts +5 -1
- package/src/cli/not-a-ticker.ts +4 -0
- package/src/cli/pane-functions/function-help.ts +2 -2
- package/src/components/command-bar/pane-settings.ts +2 -2
- package/src/components/command-bar/routes/root/results.ts +6 -2
- package/src/components/input-search-bar.tsx +9 -2
- package/src/components/layout/pane/header.tsx +2 -0
- package/src/components/layout/shell/pane/capture.ts +4 -1
- package/src/components/layout/status-bar.tsx +6 -1
- package/src/components/onboarding/first-run-workspace.ts +44 -2
- package/src/components/onboarding/onboarding-frame.tsx +11 -2
- package/src/components/onboarding/onboarding-keyboard.ts +16 -0
- package/src/components/onboarding/onboarding-wizard.tsx +8 -8
- package/src/components/onboarding/portfolio-step/positions-panel.tsx +62 -1
- package/src/components/onboarding/use-onboarding-progress.ts +12 -4
- package/src/components/pane-settings-dialog/desktop.tsx +2 -2
- package/src/components/pane-settings-dialog/tui.tsx +2 -2
- package/src/components/pane-settings-dialog/value.ts +6 -0
- package/src/components/pane-settings-dialog.tsx +3 -3
- package/src/components/reader/detail-reader.tsx +4 -0
- package/src/components/ui/index.ts +1 -1
- package/src/components/ui/page-stack-view.tsx +3 -0
- package/src/components/ui/pane-link-chip.tsx +269 -54
- package/src/components/ui/query-bar.tsx +2 -1
- package/src/components/ui/tabs.tsx +97 -19
- package/src/core/state/app/layout-reducer.ts +7 -0
- package/src/core/state/app/layout.ts +44 -7
- package/src/core/state/app/state.ts +1 -1
- package/src/core/state/app/types.ts +22 -2
- package/src/docs/snapshot.json +27 -10
- package/src/market-data/depositary-pair.ts +5 -3
- package/src/market-data/market/dated-previous-close.ts +94 -15
- package/src/market-data/market/status.ts +17 -1
- package/src/plugins/builtin/analytics/risk-client.ts +10 -4
- package/src/plugins/builtin/analytics/risk-episodes.ts +5 -4
- package/src/plugins/builtin/analytics/risk-headless.ts +4 -2
- package/src/plugins/builtin/analytics/risk-sectors.ts +91 -0
- package/src/plugins/builtin/awards/index.tsx +1 -1
- package/src/plugins/builtin/buildout/index.tsx +1 -0
- package/src/plugins/builtin/catalysts/index.tsx +2 -2
- package/src/plugins/builtin/cds/headless.ts +4 -0
- package/src/plugins/builtin/chart-composer/headless.ts +2 -1
- package/src/plugins/builtin/chart-composer/index.tsx +1 -0
- package/src/plugins/builtin/chat/content/composer.tsx +5 -4
- package/src/plugins/builtin/chat/content/index.tsx +12 -2
- package/src/plugins/builtin/chat/content/layout-metrics.ts +3 -3
- package/src/plugins/builtin/chat/content/open-targets.ts +3 -3
- package/src/plugins/builtin/chat/layout.ts +5 -2
- package/src/plugins/builtin/chat/message/pane-chip.tsx +61 -40
- package/src/plugins/builtin/chat/message/terminal.tsx +13 -15
- package/src/plugins/builtin/chat/pane-links/previews.ts +51 -5
- package/src/plugins/builtin/chat/pane-links/share-card.ts +36 -0
- package/src/plugins/builtin/cloud/askg/tool-display.ts +1 -0
- package/src/plugins/builtin/cloud/terminal-relay/redact.ts +5 -3
- package/src/plugins/builtin/commodity-balances/index.tsx +1 -0
- package/src/plugins/builtin/company-attention/index.tsx +1 -1
- package/src/plugins/builtin/company-kpis/headless.ts +3 -1
- package/src/plugins/builtin/company-kpis/index.tsx +2 -2
- package/src/plugins/builtin/cot/index.tsx +1 -1
- package/src/plugins/builtin/cpi/index.tsx +1 -1
- package/src/plugins/builtin/crypto-board/index.tsx +1 -0
- package/src/plugins/builtin/dividend-yield/index.tsx +1 -0
- package/src/plugins/builtin/doe/index.tsx +1 -1
- package/src/plugins/builtin/earnings-calls/headless.ts +5 -1
- package/src/plugins/builtin/earnings-calls/index.tsx +1 -0
- package/src/plugins/builtin/econ/calendar-model.ts +74 -1
- package/src/plugins/builtin/econ/fred-catalog.ts +3 -1
- package/src/plugins/builtin/econ/index.tsx +1 -0
- package/src/plugins/builtin/econ-statistics/index.tsx +1 -0
- package/src/plugins/builtin/econ-statistics/pane.tsx +6 -0
- package/src/plugins/builtin/estimate-revisions/index.tsx +1 -0
- package/src/plugins/builtin/executives/index.tsx +1 -0
- package/src/plugins/builtin/filing-events/index.tsx +1 -0
- package/src/plugins/builtin/fixed-income/index.tsx +1 -0
- package/src/plugins/builtin/futures-curve/headless.ts +3 -3
- package/src/plugins/builtin/futures-curve/index.tsx +1 -1
- package/src/plugins/builtin/futures-curve/model.ts +18 -0
- package/src/plugins/builtin/gpu/index.tsx +1 -1
- package/src/plugins/builtin/help/functions-table.tsx +1 -1
- package/src/plugins/builtin/help/index.tsx +11 -1
- package/src/plugins/builtin/help/keybindings-editor.tsx +1 -1
- package/src/plugins/builtin/holders/index.tsx +1 -0
- package/src/plugins/builtin/holders/report-header.ts +2 -2
- package/src/plugins/builtin/insider/index.tsx +1 -0
- package/src/plugins/builtin/iv-history/index.tsx +1 -1
- package/src/plugins/builtin/jobs/index.tsx +1 -0
- package/src/plugins/builtin/macro-day/headless.ts +27 -8
- package/src/plugins/builtin/macro-day/index.tsx +1 -1
- package/src/plugins/builtin/macro-day/model.ts +19 -3
- package/src/plugins/builtin/macro-day/pane.tsx +14 -9
- package/src/plugins/builtin/macro-day/releases.ts +25 -7
- package/src/plugins/builtin/market-valuation/index.tsx +1 -0
- package/src/plugins/builtin/market-valuation/pane.tsx +8 -0
- package/src/plugins/builtin/members/index.tsx +1 -1
- package/src/plugins/builtin/mna/index.tsx +1 -0
- package/src/plugins/builtin/news/index.tsx +1 -0
- package/src/plugins/builtin/news/wire/index.tsx +5 -1
- package/src/plugins/builtin/news/wire/news/detail-view.tsx +4 -0
- package/src/plugins/builtin/news/wire/news/list-search.ts +5 -2
- package/src/plugins/builtin/options/index.tsx +1 -0
- package/src/plugins/builtin/options-positioning/index.tsx +1 -0
- package/src/plugins/builtin/pe-band/index.tsx +1 -1
- package/src/plugins/builtin/portfolio-list/cli/portfolio-command.ts +25 -0
- package/src/plugins/builtin/portfolio-list/headless.ts +15 -6
- package/src/plugins/builtin/power/index.tsx +1 -1
- package/src/plugins/builtin/realized-vol/index.tsx +1 -1
- package/src/plugins/builtin/research/headless.ts +10 -4
- package/src/plugins/builtin/research/index.tsx +4 -0
- package/src/plugins/builtin/research-search/index.tsx +1 -0
- package/src/plugins/builtin/research-search/pane.tsx +8 -0
- package/src/plugins/builtin/revenue-breakdown/index.tsx +1 -0
- package/src/plugins/builtin/reverse-dcf/index.tsx +1 -1
- package/src/plugins/builtin/risk-factors/index.tsx +1 -0
- package/src/plugins/builtin/scanner/headless.ts +52 -13
- package/src/plugins/builtin/seasonality/index.tsx +1 -1
- package/src/plugins/builtin/sec/index.tsx +1 -0
- package/src/plugins/builtin/series-inventory.ts +1 -1
- package/src/plugins/builtin/shared/scanner-capture.ts +11 -3
- package/src/plugins/builtin/shared/series-list-detail.tsx +5 -0
- package/src/plugins/builtin/short-interest/index.tsx +1 -0
- package/src/plugins/builtin/social-mentions/index.tsx +1 -1
- package/src/plugins/builtin/supply-chain/index.tsx +1 -0
- package/src/plugins/builtin/thirteenf/data.ts +43 -10
- package/src/plugins/builtin/thirteenf/headless.ts +55 -11
- package/src/plugins/builtin/thirteenf/model.ts +25 -9
- package/src/plugins/builtin/thirteenf/report-notes.ts +27 -6
- package/src/plugins/builtin/thirteenf/types.ts +2 -0
- package/src/plugins/builtin/ticker-detail/adr-pair/model.ts +1 -1
- package/src/plugins/builtin/ticker-detail/financials/model.ts +12 -0
- package/src/plugins/builtin/ticker-detail/financials/ratio-table.tsx +3 -3
- package/src/plugins/builtin/ticker-detail/financials/tab.tsx +5 -5
- package/src/plugins/builtin/ticker-detail/headless.ts +18 -13
- package/src/plugins/builtin/ticker-detail/index.tsx +4 -0
- package/src/plugins/builtin/ticker-detail/overview/model.ts +6 -4
- package/src/plugins/builtin/ticker-detail/overview-tab.tsx +6 -4
- package/src/plugins/builtin/time-sales/client.ts +9 -11
- package/src/plugins/builtin/time-sales/index.tsx +1 -1
- package/src/plugins/builtin/treasury-auctions/after.ts +267 -0
- package/src/plugins/builtin/treasury-auctions/cache.ts +18 -3
- package/src/plugins/builtin/treasury-auctions/client.ts +33 -2
- package/src/plugins/builtin/treasury-auctions/headless.ts +109 -19
- package/src/plugins/builtin/treasury-auctions/index.tsx +14 -4
- package/src/plugins/builtin/treasury-auctions/model.ts +256 -28
- package/src/plugins/builtin/treasury-auctions/pane.tsx +139 -28
- package/src/plugins/builtin/treasury-auctions/treasury-direct.ts +5 -2
- package/src/plugins/builtin/treasury-auctions/types.ts +7 -1
- package/src/plugins/builtin/vol-surface/index.tsx +1 -1
- package/src/plugins/builtin/world-venue-map/index.ts +1 -0
- package/src/plugins/builtin/yield-curve/curves.ts +10 -4
- package/src/plugins/builtin/yield-curve/headless.ts +6 -2
- package/src/plugins/builtin/yield-curve/index.tsx +3 -3
- package/src/plugins/builtin/yield-curve/series.ts +10 -0
- package/src/plugins/builtin/yield-curve/world.ts +3 -1
- package/src/portfolio/column-values.ts +2 -1
- package/src/public/__snapshots__/public-api.test.ts.snap +4 -0
- package/src/public/remote.ts +7 -1
- package/src/remote/client.ts +191 -11
- package/src/remote/controller-utils.ts +13 -1
- package/src/remote/controller.ts +88 -26
- package/src/remote/endpoint.ts +24 -0
- package/src/remote/form.ts +59 -4
- package/src/remote/resources.ts +44 -18
- package/src/remote/schema.ts +21 -9
- package/src/remote/secrets.ts +12 -0
- package/src/remote/semantic-tree.tsx +14 -2
- package/src/remote/server.ts +2 -1
- package/src/remote/surface.tsx +192 -0
- package/src/remote/types.ts +5 -0
- package/src/renderers/opentui/host.tsx +6 -0
- package/src/series/standalone.ts +2 -2
- package/src/shares/api.ts +21 -4
- package/src/shares/item.ts +73 -0
- package/src/shares/pane-item.ts +205 -0
- package/src/shares/pane.ts +4 -0
- package/src/shares/payload.ts +9 -5
- package/src/sources/gloomberb-cloud/news.ts +2 -0
- package/src/tickers/renamed-listings.ts +105 -0
- package/src/tickers/search/index.ts +103 -16
- package/src/time-series/resolve.ts +2 -2
- package/src/types/financials.ts +1 -0
- package/src/types/plugin-pane-settings.ts +2 -0
- package/src/types/plugin-panes.ts +22 -0
- package/src/utils/central-banks.ts +86 -1
- package/src/utils/datetime-format.ts +12 -3
- package/src/utils/depositary-receipt.ts +28 -3
- package/src/utils/fundamentals.ts +14 -0
- package/src/utils/max-drawdown.ts +97 -16
- package/src/utils/untrusted-text.ts +29 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { compactFloatingZ, getDockLeafLayouts, getDockedPaneIds, showDockTab } from "../../../layout/pane-manager";
|
|
1
|
+
import { compactFloatingZ, getDockLeafLayouts, getDockedPaneIds, removePane, showDockTab } from "../../../layout/pane-manager";
|
|
2
2
|
import { pinFollowingPane } from "../../../layout/pane-follow";
|
|
3
3
|
import {
|
|
4
4
|
cloneLayout,
|
|
@@ -18,7 +18,7 @@ import {
|
|
|
18
18
|
import type { DesktopSharedStateSnapshot } from "../../../types/desktop-window";
|
|
19
19
|
import type { BrokerAccount } from "../../../types/trading";
|
|
20
20
|
import { isBrokerPortfolioId } from "../../../utils/broker-instances";
|
|
21
|
-
import type { AppState, LayoutHistoryEntry, PaneRuntimeState } from "./types";
|
|
21
|
+
import type { AppState, LayoutHistoryEntry, OpeningPaneSettlement, PaneRuntimeState } from "./types";
|
|
22
22
|
|
|
23
23
|
function getDefaultCollectionId(config: AppConfig): string {
|
|
24
24
|
return config.portfolios[0]?.id || config.watchlists[0]?.id || "";
|
|
@@ -510,6 +510,44 @@ export function moveHistoryIndex(
|
|
|
510
510
|
return next;
|
|
511
511
|
}
|
|
512
512
|
|
|
513
|
+
/**
|
|
514
|
+
* The undo history once a research pane opened ahead of its ticker's lookup
|
|
515
|
+
* settles, `current` being the layout it settled into. One that found its
|
|
516
|
+
* listing has its binding and title in every step that holds it. One whose
|
|
517
|
+
* open came to nothing leaves no step: the history goes back to what it was
|
|
518
|
+
* before the open, redo steps included, or, when steps were taken since, those
|
|
519
|
+
* steps lose it and any that then repeats the step nearer the current layout goes.
|
|
520
|
+
*/
|
|
521
|
+
export function settleOpeningPaneHistory(
|
|
522
|
+
entry: LayoutHistoryEntry,
|
|
523
|
+
current: LayoutConfig,
|
|
524
|
+
{ paneId, symbol, settled, before }: OpeningPaneSettlement,
|
|
525
|
+
): LayoutHistoryEntry {
|
|
526
|
+
if (!settled && before) return before;
|
|
527
|
+
const settle = (layout: LayoutConfig): LayoutConfig => {
|
|
528
|
+
const pane = findPaneInstance(layout, paneId);
|
|
529
|
+
if (pane?.binding?.kind !== "fixed" || pane.binding.symbol !== symbol) return layout;
|
|
530
|
+
return settled
|
|
531
|
+
? { ...layout, instances: layout.instances.map((instance) => instance.instanceId === paneId ? { ...instance, ...settled } : instance) }
|
|
532
|
+
: removePane(layout, paneId);
|
|
533
|
+
};
|
|
534
|
+
const past = entry.past.map(settle);
|
|
535
|
+
const future = entry.future.map(settle);
|
|
536
|
+
if (settled) return { past, future };
|
|
537
|
+
return { past: withoutRepeats(past.reverse(), current).reverse(), future: withoutRepeats(future, current) };
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
/** Steps leading away from `current`, less each that repeats the one nearer to it: undoing it would change nothing. */
|
|
541
|
+
function withoutRepeats(steps: LayoutConfig[], current: LayoutConfig): LayoutConfig[] {
|
|
542
|
+
let nearer = JSON.stringify(current);
|
|
543
|
+
return steps.filter((step) => {
|
|
544
|
+
const key = JSON.stringify(step);
|
|
545
|
+
const repeats = key === nearer;
|
|
546
|
+
nearer = key;
|
|
547
|
+
return !repeats;
|
|
548
|
+
});
|
|
549
|
+
}
|
|
550
|
+
|
|
513
551
|
/** If paneId is a floating pane, bump its zIndex to the top, renumbering a stack that would climb past the shell's overlays. */
|
|
514
552
|
export function bringFloatingToFront(layout: LayoutConfig, paneId: string): LayoutConfig {
|
|
515
553
|
const entryIndex = layout.floating.findIndex((e) => e.instanceId === paneId);
|
|
@@ -538,14 +576,13 @@ export function materializeDetachedLayouts(config: AppConfig): AppConfig {
|
|
|
538
576
|
};
|
|
539
577
|
}
|
|
540
578
|
|
|
541
|
-
export function focusPaneState(state: AppState, paneId: string): AppState {
|
|
579
|
+
export function focusPaneState(state: AppState, paneId: string, trackTicker = true): AppState {
|
|
542
580
|
// A tab of a stack is shown when it takes focus.
|
|
543
581
|
const layout = showDockTab(bringFloatingToFront(state.config.layout, paneId), paneId);
|
|
544
582
|
const config = layout !== state.config.layout ? { ...state.config, layout } : state.config;
|
|
545
|
-
const recentTickers =
|
|
546
|
-
state.recentTickers,
|
|
547
|
-
|
|
548
|
-
);
|
|
583
|
+
const recentTickers = trackTicker
|
|
584
|
+
? nextRecentTickers(state.recentTickers, resolveTickerForPane(state, paneId))
|
|
585
|
+
: state.recentTickers;
|
|
549
586
|
if (
|
|
550
587
|
config === state.config &&
|
|
551
588
|
state.focusedPaneId === paneId &&
|
|
@@ -265,7 +265,7 @@ export function appReducer(state: AppState, action: AppAction): AppState {
|
|
|
265
265
|
}
|
|
266
266
|
|
|
267
267
|
case "FOCUS_PANE": {
|
|
268
|
-
return focusPaneState(state, action.paneId);
|
|
268
|
+
return focusPaneState(state, action.paneId, action.trackTicker ?? true);
|
|
269
269
|
}
|
|
270
270
|
|
|
271
271
|
case "FOCUS_NEXT": {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { BrokerAccount } from "../../../types/trading";
|
|
2
|
-
import type { AppConfig, KeybindingsConfig, LayoutConfig, LayoutOrigin, OnboardingProgress, StarPromptConfig } from "../../../types/config";
|
|
2
|
+
import type { AppConfig, KeybindingsConfig, LayoutConfig, LayoutOrigin, OnboardingProgress, PaneInstanceConfig, StarPromptConfig } from "../../../types/config";
|
|
3
3
|
import type { DesktopSharedStateSnapshot } from "../../../types/desktop-window";
|
|
4
4
|
import type { Quote, TickerFinancials } from "../../../types/financials";
|
|
5
5
|
import type { TickerRecord } from "../../../types/ticker";
|
|
@@ -20,6 +20,20 @@ export interface LayoutHistoryEntry {
|
|
|
20
20
|
future: LayoutConfig[];
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
+
/** How a research pane opened ahead of the lookup that finds its ticker settled. */
|
|
24
|
+
export interface OpeningPaneSettlement {
|
|
25
|
+
paneId: string;
|
|
26
|
+
/** The key it was bound to while it loaded. */
|
|
27
|
+
symbol: string;
|
|
28
|
+
/**
|
|
29
|
+
* The binding and title the lookup gave it, or null when its open came to
|
|
30
|
+
* nothing: no listing, a choice of listings, or another pane already on it.
|
|
31
|
+
*/
|
|
32
|
+
settled: Pick<PaneInstanceConfig, "binding" | "title"> | null;
|
|
33
|
+
/** The history before the open, when no step was taken, undone or redone since. */
|
|
34
|
+
before?: LayoutHistoryEntry;
|
|
35
|
+
}
|
|
36
|
+
|
|
23
37
|
type SortDirection = "asc" | "desc";
|
|
24
38
|
|
|
25
39
|
export interface CollectionSortPreference {
|
|
@@ -194,7 +208,13 @@ export type AppAction =
|
|
|
194
208
|
| { type: "MOVE_PANE_TO_NEW_LAYOUT"; paneId: string; name: string; sourceLayoutId: string }
|
|
195
209
|
/** Returns a pane Move to New Layout moved to the layout it came from, which becomes active. */
|
|
196
210
|
| { type: "MOVE_PANE_BACK"; paneId: string }
|
|
197
|
-
|
|
211
|
+
/** `trackTicker: false` keeps the pane's ticker out of the recent tickers: a pane still looking its ticker up. */
|
|
212
|
+
| { type: "FOCUS_PANE"; paneId: string; trackTicker?: boolean }
|
|
213
|
+
/**
|
|
214
|
+
* A research pane opened ahead of the lookup that finds its ticker settles
|
|
215
|
+
* in the active layout's undo history (`settleOpeningPaneHistory`).
|
|
216
|
+
*/
|
|
217
|
+
| { type: "SETTLE_OPENING_PANE"; settlement: OpeningPaneSettlement }
|
|
198
218
|
| { type: "FOCUS_NEXT"; paneOrder: string[] }
|
|
199
219
|
| { type: "FOCUS_PREV"; paneOrder: string[] }
|
|
200
220
|
| { type: "HYDRATE_DESKTOP_SNAPSHOT"; snapshot: DesktopSharedStateSnapshot }
|
package/src/docs/snapshot.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"format": 1,
|
|
3
3
|
"site": "https://gloom.sh",
|
|
4
|
-
"updatedAt": "2026-11-
|
|
4
|
+
"updatedAt": "2026-11-07",
|
|
5
5
|
"categories": [
|
|
6
6
|
{
|
|
7
7
|
"id": "research",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"code": "DES",
|
|
42
42
|
"name": "Security overview",
|
|
43
43
|
"description": "Quote, chart, and research tabs",
|
|
44
|
-
"detail": "The starting point for any ticker: live quote, day and 52-week range, price chart, fundamentals, and tabs into every other research pane. A bond fund shows its SEC yield, yield to worst and duration beside its distribution yield. T is the same pane; search Ticker Research to open a second one.",
|
|
44
|
+
"detail": "The starting point for any ticker: live quote, day and 52-week range, price chart, fundamentals, and tabs into every other research pane. A bond fund shows its SEC yield, yield to worst and duration beside its distribution yield, and --tax-rate 40.8 adds a muni fund's tax-equivalent yield and muni/Treasury ratio. T is the same pane; search Ticker Research to open a second one.",
|
|
45
45
|
"category": "research",
|
|
46
46
|
"arg": "NVDA",
|
|
47
47
|
"shot": "https://gloom.sh/screenshots/fn/DES.png",
|
|
@@ -430,7 +430,7 @@
|
|
|
430
430
|
"code": "DVD",
|
|
431
431
|
"name": "Dividend yield",
|
|
432
432
|
"description": "Payout history and yield",
|
|
433
|
-
"detail": "Cash distributions, trailing yield, indicated rate when available, and payout growth. A bond fund's distribution yield is labelled as not its SEC yield, which follows it dated with yield to worst and duration; --tax-rate 40.8 adds a muni fund's tax-equivalent yield and muni/Treasury ratio. Several tickers rank in one table. Future payments are not forecast.",
|
|
433
|
+
"detail": "Cash distributions, trailing yield, indicated rate when available, and payout growth. A bond fund's distribution yield is labelled as not its SEC yield, which follows it dated with yield to worst and duration; --tax-rate 40.8 adds a muni fund's tax-equivalent yield and muni/Treasury ratio. Several tickers rank in one table, with those columns too under --tax-rate. Future payments are not forecast.",
|
|
434
434
|
"category": "research",
|
|
435
435
|
"arg": "KO",
|
|
436
436
|
"shot": "https://gloom.sh/screenshots/fn/DVD.png",
|
|
@@ -1388,7 +1388,7 @@
|
|
|
1388
1388
|
"code": "ETF",
|
|
1389
1389
|
"name": "ETF facts and filings",
|
|
1390
1390
|
"description": "A fund's facts and SEC filings",
|
|
1391
|
-
"detail": "A US-listed fund's facts from its sponsor (fee, NAV, premium, net assets, and a bond fund's SEC yield, yield to worst and duration), then its SEC filings: registration statements, prospectus updates, shareholder reports, N-CEN and N-PORT reports. Open any of them inline.",
|
|
1391
|
+
"detail": "A US-listed fund's facts from its sponsor (fee, NAV, premium, net assets, and a bond fund's SEC yield, yield to worst and duration), then its SEC filings: registration statements, prospectus updates, shareholder reports, N-CEN and N-PORT reports. Open any of them inline. --tax-rate 40.8 adds a muni fund's tax-equivalent yield and muni/Treasury ratio.",
|
|
1392
1392
|
"category": "ownership",
|
|
1393
1393
|
"arg": "SPY",
|
|
1394
1394
|
"shot": "https://gloom.sh/screenshots/fn/ETF.png",
|
|
@@ -2547,6 +2547,8 @@
|
|
|
2547
2547
|
"currency",
|
|
2548
2548
|
"TRY",
|
|
2549
2549
|
"cost FX",
|
|
2550
|
+
"real return",
|
|
2551
|
+
"inflation",
|
|
2550
2552
|
"target weights",
|
|
2551
2553
|
"drift",
|
|
2552
2554
|
"rebalance",
|
|
@@ -2565,7 +2567,7 @@
|
|
|
2565
2567
|
"E*TRADE",
|
|
2566
2568
|
"Merrill"
|
|
2567
2569
|
],
|
|
2568
|
-
"updatedAt": "2026-11-
|
|
2570
|
+
"updatedAt": "2026-11-07",
|
|
2569
2571
|
"blocks": [
|
|
2570
2572
|
{
|
|
2571
2573
|
"type": "heading",
|
|
@@ -2591,12 +2593,23 @@
|
|
|
2591
2593
|
},
|
|
2592
2594
|
{
|
|
2593
2595
|
"type": "code",
|
|
2594
|
-
"code": "gloom portfolio create Lira --currency TRY\ngloom portfolio position set Lira THYAO 100 280 # a BIST stock, cost in TRY\ngloom portfolio position set Lira BRK-B 10 20310 TRY # a US stock at what it cost in lira\ngloom portfolio position set Lira BRK-B 10 410 USD --date 2024-03-01 # or in dollars, converted at that day's FX close\ngloom portfolio position set Lira KO 40 62.50 USD --cost-fx 32.15 # or at the rate you paid, TRY per USD\ngloom portfolio show Lira --from 2025-11-06 # P&L since a date, with the currency's move on its own line"
|
|
2596
|
+
"code": "gloom portfolio create Lira --currency TRY\ngloom portfolio position set Lira THYAO 100 280 # a BIST stock, cost in TRY\ngloom portfolio position set Lira BRK-B 10 20310 TRY # a US stock at what it cost in lira\ngloom portfolio position set Lira BRK-B 10 410 USD --date 2024-03-01 # or in dollars, converted at that day's FX close\ngloom portfolio position set Lira KO 40 62.50 USD --cost-fx 32.15 # or at the rate you paid, TRY per USD\ngloom portfolio show Lira --from 2025-11-06 # P&L since a date, with the currency's move on its own line\ngloom portfolio show Lira --from 2025-11-06 --real # and the return after Turkish consumer prices"
|
|
2595
2597
|
},
|
|
2596
2598
|
{
|
|
2597
2599
|
"type": "paragraph",
|
|
2598
2600
|
"text": "A cost in the holding's own currency without `--date` or `--cost-fx` converts at today's rate, and `portfolio show` names the holdings it does that for. Use the date or the rate so P&L carries the currency's move since you bought. A name whose last word is a currency code in capitals (`Baht THB`) creates the portfolio in that currency too."
|
|
2599
2601
|
},
|
|
2602
|
+
{
|
|
2603
|
+
"type": "paragraph",
|
|
2604
|
+
"text": "`--real` deflates the period's total by the consumer prices of the portfolio's currency, from the CPI month before the start's month to the one before the end's (or the latest month published), and names both months:"
|
|
2605
|
+
},
|
|
2606
|
+
{
|
|
2607
|
+
"type": "list",
|
|
2608
|
+
"items": [
|
|
2609
|
+
"**USD**: the ratio of the BLS index at those two months, not seasonally adjusted (FRED's `CPIAUCNS`), as a period's inflation is quoted. A month the BLS did not publish reads the month before it.",
|
|
2610
|
+
"**TRY**: the central bank's table gives TurkStat's changes rather than the index, so the figure is chained from the end month back. Each whole year takes TurkStat's year-on-year change, and each month left over takes its monthly change. Every change is applied as one plus the change, and the factors are multiplied. A twelve-month period is TurkStat's published annual rate: October 2025 to October 2026 reads 29.77%. A month without its change leaves the period without a real return."
|
|
2611
|
+
]
|
|
2612
|
+
},
|
|
2600
2613
|
{
|
|
2601
2614
|
"type": "heading",
|
|
2602
2615
|
"level": 2,
|
|
@@ -5642,7 +5655,7 @@
|
|
|
5642
5655
|
"functions",
|
|
5643
5656
|
"screenshots"
|
|
5644
5657
|
],
|
|
5645
|
-
"updatedAt": "2026-11-
|
|
5658
|
+
"updatedAt": "2026-11-07",
|
|
5646
5659
|
"blocks": [
|
|
5647
5660
|
{
|
|
5648
5661
|
"type": "paragraph",
|
|
@@ -5717,6 +5730,10 @@
|
|
|
5717
5730
|
"`financials`, `fundamentals`, `valuation`, `events`, `analyst` `<symbol>`",
|
|
5718
5731
|
"Revenue and EPS, profile, multiples, dividends and splits, ratings and targets"
|
|
5719
5732
|
],
|
|
5733
|
+
[
|
|
5734
|
+
"`fn CMP <symbols> [--from <date>] [--to <date>] [--total-return] [--currency <code>]`",
|
|
5735
|
+
"Returns side by side, each in its listing's currency: price returns, or with `--total-return` each distribution reinvested at its ex-date close. `--currency USD` converts every close at that day's FX close, so a lira stock's return carries the lira's move"
|
|
5736
|
+
],
|
|
5720
5737
|
[
|
|
5721
5738
|
"`fn DVD <symbols>`",
|
|
5722
5739
|
"Dividend yield and history; several symbols rank in one table by yield, with payout, growth, last ex-date and pay date"
|
|
@@ -5753,7 +5770,7 @@
|
|
|
5753
5770
|
],
|
|
5754
5771
|
[
|
|
5755
5772
|
"`earnings <symbols>`, `fx <currency>`",
|
|
5756
|
-
"Earnings dates; a currency into your base currency"
|
|
5773
|
+
"Earnings dates; a currency into your base currency. Gold, silver, platinum and palladium have no spot quote, so `fx XAU/TRY` is derived from the front-month future (GC=F) and the dollar pair, and says so"
|
|
5757
5774
|
],
|
|
5758
5775
|
[
|
|
5759
5776
|
"`econ [--country all|US|G7|EU|<codes>] [--impact high|medium|low|all] [--search <words>] [--from <date>] [--tz <zone>]`",
|
|
@@ -5783,7 +5800,7 @@
|
|
|
5783
5800
|
"rows": [
|
|
5784
5801
|
[
|
|
5785
5802
|
"`portfolio list|show|create|delete <name>`",
|
|
5786
|
-
"Manual portfolios; `show` lists value, weight, a year of dividend income and its yield, target, drift and the trade to rebalance; `show --explain` adds what those terms mean, `show --drip [--years 1-5] [--withholding <pct>]` projects reinvested dividends, and `show --from <date> [--to <date>]` gives the P&L between two closes with the FX move"
|
|
5803
|
+
"Manual portfolios; `show` lists value, weight, a year of dividend income and its yield, target, drift and the trade to rebalance; `show --explain` adds what those terms mean, `show --drip [--years 1-5] [--withholding <pct>]` projects reinvested dividends, and `show --from <date> [--to <date>]` gives the P&L between two closes with the FX move; `--real` adds the return after the portfolio currency's consumer prices (USD and TRY) and names the CPI months it used"
|
|
5787
5804
|
],
|
|
5788
5805
|
[
|
|
5789
5806
|
"`portfolio create <name> --currency <code>`",
|
|
@@ -5907,7 +5924,7 @@
|
|
|
5907
5924
|
],
|
|
5908
5925
|
[
|
|
5909
5926
|
"`catalog glossary [term]`, `catalog explain <term>`",
|
|
5910
|
-
"What a term means, such as `stop-out`, `B/C`, `drift` or `
|
|
5927
|
+
"What a term means, such as `stop-out`, `B/C`, `drift`, `NAV`, `beta`, `R²` or `VaR`"
|
|
5911
5928
|
],
|
|
5912
5929
|
[
|
|
5913
5930
|
"`fn <function> [argument] [--option value] [--explain]`",
|
|
@@ -3,6 +3,7 @@ import { canonicalExchange, parsePublicTickerKey } from "../utils/exchanges";
|
|
|
3
3
|
import { formatNumber } from "../utils/format";
|
|
4
4
|
import { formatUtcDayTime } from "../utils/utc-time";
|
|
5
5
|
import { heldCurrencyUnit } from "../utils/currency-units";
|
|
6
|
+
import { adrRatioText } from "../utils/depositary-receipt";
|
|
6
7
|
import { regularSessionCloseOn } from "./market/freshness";
|
|
7
8
|
import { getRegularSessionDisplay, regularSessionDisplayDate } from "./market/status";
|
|
8
9
|
|
|
@@ -72,12 +73,13 @@ function homeLineRatioText(pair: DepositaryPair): string {
|
|
|
72
73
|
|
|
73
74
|
/**
|
|
74
75
|
* The ratio as a listing's report states it, from its side of the pair:
|
|
75
|
-
* `1 ADR = 10 ordinary shares of GGAL.BA` on the receipt
|
|
76
|
-
* of
|
|
76
|
+
* `1 ADR = 10 ordinary shares of GGAL.BA` on the receipt (`2 preferred
|
|
77
|
+
* shares of PETR4.SA`, homeShareClass), `1 GGAL ADR = 10 of these shares`
|
|
78
|
+
* on a home line.
|
|
77
79
|
*/
|
|
78
80
|
export function depositaryPairText(pair: DepositaryPair, receiptSide: boolean): string {
|
|
79
81
|
if (!receiptSide) return homeLineRatioText(pair);
|
|
80
|
-
return `1 ADR = ${ratioCount(pair.ratio)}
|
|
82
|
+
return `${adrRatioText(pair.ratio, pair.ordinary[0]) ?? `1 ADR = ${ratioCount(pair.ratio)}`} of ${pair.ordinary.join(" / ")}`;
|
|
81
83
|
}
|
|
82
84
|
|
|
83
85
|
/** A price as the comparison reads it, with when it was observed. */
|
|
@@ -17,9 +17,10 @@ const SAME_CLOSE_RELATIVE = 1e-5;
|
|
|
17
17
|
*/
|
|
18
18
|
const SAME_INDEX_CLOSE_RELATIVE = 1e-4;
|
|
19
19
|
/**
|
|
20
|
-
* How long a reading that named no day,
|
|
21
|
-
*
|
|
22
|
-
*
|
|
20
|
+
* How long a reading that named no day, corrected an index's close, or found
|
|
21
|
+
* no official close yet for a closed B3 session stands before the closes are
|
|
22
|
+
* read again: a history a session behind catches up, a failed read is
|
|
23
|
+
* retried, a correction is checked again.
|
|
23
24
|
*/
|
|
24
25
|
const UNDATED_RETRY_MS = 10 * 60_000;
|
|
25
26
|
/** Readings kept at once; the oldest goes first. */
|
|
@@ -61,6 +62,8 @@ export interface PreviousCloseDatesOptions {
|
|
|
61
62
|
indexWaitMs?: number;
|
|
62
63
|
}
|
|
63
64
|
|
|
65
|
+
type ReadingFields = Pick<Reading, "date" | "close" | "sessionClose" | "awaitsSessionClose">;
|
|
66
|
+
|
|
64
67
|
interface Reading {
|
|
65
68
|
date: string | null;
|
|
66
69
|
/**
|
|
@@ -68,9 +71,32 @@ interface Reading {
|
|
|
68
71
|
* disagrees with it: an index's, whose move is then measured from it.
|
|
69
72
|
*/
|
|
70
73
|
close?: number;
|
|
74
|
+
/** The official close of the quote's own session, from its daily bar, where the quote ends on a later print (B3). */
|
|
75
|
+
sessionClose?: number;
|
|
76
|
+
/** A closed quote on such a venue whose session's bar was not in the history yet: read again until it lands. */
|
|
77
|
+
awaitsSessionClose?: boolean;
|
|
71
78
|
at: number;
|
|
72
79
|
}
|
|
73
80
|
|
|
81
|
+
/**
|
|
82
|
+
* Venues whose quoted previous close is the exchange's official close, not
|
|
83
|
+
* the last trade its daily bar closes on, with how far apart the two can be:
|
|
84
|
+
* the BMV's closing auction gave WALMEX 53.57 on Thu 5 Nov 2026 beside a
|
|
85
|
+
* 53.68 last trade. The bar of the trading weekday right before the move's
|
|
86
|
+
* session still dates it, when the two are that close.
|
|
87
|
+
*/
|
|
88
|
+
const OFFICIAL_PREVIOUS_CLOSE_VENUES: ReadonlyMap<string, number> = new Map([["BMV", 0.01]]);
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Venues whose closed quote can end on a print after the closing call while
|
|
92
|
+
* the daily bar is the official close, as history and the portfolio read it:
|
|
93
|
+
* B3's PETR4 quoted R$45.36 on Fri 6 Nov 2026 beside a R$45.30 close.
|
|
94
|
+
*/
|
|
95
|
+
const DAILY_BAR_CLOSE_VENUES: ReadonlySet<string> = new Set(["B3"]);
|
|
96
|
+
|
|
97
|
+
/** A close this far from the quote's price is another unit's or another listing's, never the session's. */
|
|
98
|
+
const MAX_SESSION_CLOSE_MOVE = 0.25;
|
|
99
|
+
|
|
74
100
|
/** One listing whatever spelling of its exchange a request used. */
|
|
75
101
|
export function datedCloseListingKey(listing: DatedCloseListing): string {
|
|
76
102
|
return `${listing.symbol.trim().toUpperCase()}|${canonicalExchange(listing.exchange)}`;
|
|
@@ -103,7 +129,9 @@ function datedReadingKey(quote: Quote, listing: DatedCloseListing): string | nul
|
|
|
103
129
|
const previousClose = quote.previousClose;
|
|
104
130
|
const sessionDate = changeBasisSessionDate(quote);
|
|
105
131
|
if (previousClose == null || !Number.isFinite(previousClose) || !sessionDate) return null;
|
|
106
|
-
|
|
132
|
+
// A session read while it traded has no close yet: once closed it is read again for its official close.
|
|
133
|
+
const closed = DAILY_BAR_CLOSE_VENUES.has(calendarVenue(quote)) && quote.marketState === "CLOSED" ? "|closed" : "";
|
|
134
|
+
return `${datedCloseListingKey(listing)}|${sessionDate}|${previousClose}${closed}`;
|
|
107
135
|
}
|
|
108
136
|
|
|
109
137
|
/**
|
|
@@ -133,7 +161,37 @@ function latestCloseBefore(points: readonly DailyClose[], quote: Quote): string
|
|
|
133
161
|
.filter((point) => point.date < sessionDate)
|
|
134
162
|
.sort((left, right) => left.date.localeCompare(right.date))
|
|
135
163
|
.at(-1);
|
|
136
|
-
|
|
164
|
+
if (!before) return null;
|
|
165
|
+
if (sameClose(before.close, quote.previousClose!)) return before.date;
|
|
166
|
+
const apart = OFFICIAL_PREVIOUS_CLOSE_VENUES.get(calendarVenue(quote));
|
|
167
|
+
return apart != null && before.date === weekdayBefore(sessionDate)
|
|
168
|
+
&& Math.abs(before.close - quote.previousClose!) <= before.close * apart ? before.date : null;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/** The weekday before a local `YYYY-MM-DD`: Friday for a Monday. */
|
|
172
|
+
function weekdayBefore(date: string): string {
|
|
173
|
+
const day = new Date(`${date}T00:00:00Z`);
|
|
174
|
+
do day.setUTCDate(day.getUTCDate() - 1);
|
|
175
|
+
while (day.getUTCDay() === 0 || day.getUTCDay() === 6);
|
|
176
|
+
return day.toISOString().slice(0, 10);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* The official close of a closed quote's own session on a venue whose quote
|
|
181
|
+
* can end on a later print (DAILY_BAR_CLOSE_VENUES): the session's finished
|
|
182
|
+
* daily bar, when it differs from the quote's price; undefined when it does
|
|
183
|
+
* not. `awaits` when the history has no finished bar of that session yet.
|
|
184
|
+
*/
|
|
185
|
+
function sessionCloseOf(points: readonly DailyClose[], quote: Quote): { close?: number; awaits?: true } {
|
|
186
|
+
if (quote.marketState !== "CLOSED" || !DAILY_BAR_CLOSE_VENUES.has(calendarVenue(quote))) return {};
|
|
187
|
+
if (typeof quote.regularClose === "number" && quote.regularClose > 0) return {};
|
|
188
|
+
const sessionDate = changeBasisSessionDate(quote);
|
|
189
|
+
if (!sessionDate) return {};
|
|
190
|
+
const bar = closedBars(points, quote).findLast((point) => point.date === sessionDate && point.close > 0);
|
|
191
|
+
if (!bar) return { awaits: true };
|
|
192
|
+
if (!(quote.price > 0) || sameClose(bar.close, quote.price)) return {};
|
|
193
|
+
const close = cleanFloat32Price(bar.close);
|
|
194
|
+
return Math.abs(close / quote.price - 1) <= MAX_SESSION_CLOSE_MOVE ? { close } : {};
|
|
137
195
|
}
|
|
138
196
|
|
|
139
197
|
/**
|
|
@@ -164,9 +222,15 @@ function indexCloseOn(points: readonly DailyClose[], quote: Quote, date: string)
|
|
|
164
222
|
return Math.abs(previousClose - close) <= close * SAME_INDEX_CLOSE_RELATIVE ? { date } : { date, close };
|
|
165
223
|
}
|
|
166
224
|
|
|
167
|
-
function readingOf(points: readonly DailyClose[], quote: Quote):
|
|
225
|
+
function readingOf(points: readonly DailyClose[], quote: Quote): ReadingFields {
|
|
168
226
|
const indexDate = datedIndexClose(quote);
|
|
169
|
-
|
|
227
|
+
if (indexDate) return indexCloseOn(points, quote, indexDate);
|
|
228
|
+
const session = sessionCloseOf(points, quote);
|
|
229
|
+
return {
|
|
230
|
+
date: latestCloseBefore(points, quote),
|
|
231
|
+
...session.close != null ? { sessionClose: session.close } : {},
|
|
232
|
+
...session.awaits ? { awaitsSessionClose: true } : {},
|
|
233
|
+
};
|
|
170
234
|
}
|
|
171
235
|
|
|
172
236
|
function withDate<T extends Quote | null | undefined>(quote: T, date: string | null | undefined): T {
|
|
@@ -174,7 +238,20 @@ function withDate<T extends Quote | null | undefined>(quote: T, date: string | n
|
|
|
174
238
|
}
|
|
175
239
|
|
|
176
240
|
/** The quote as a reading has it: dated, and for an index measured from that day's close when its own disagrees. */
|
|
177
|
-
function withReading<T extends Quote | null | undefined>(quote: T, reading: Pick<Reading, "date" | "close"> | undefined): T {
|
|
241
|
+
function withReading<T extends Quote | null | undefined>(quote: T, reading: Pick<Reading, "date" | "close" | "sessionClose"> | undefined): T {
|
|
242
|
+
if (!quote || !reading) return quote;
|
|
243
|
+
const closed = withSessionClose(quote, reading.sessionClose);
|
|
244
|
+
return closed === quote ? withDatedReading(quote, reading) : withDatedReading(closed as T, reading);
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
/** A closed quote that ended on a later print headlines its session's official close, as history and the portfolio read it. */
|
|
248
|
+
function withSessionClose<T extends Quote>(quote: T, close: number | undefined): T {
|
|
249
|
+
const sessionDate = close != null && quote.marketState === "CLOSED" && !(typeof quote.regularClose === "number" && quote.regularClose > 0)
|
|
250
|
+
? changeBasisSessionDate(quote) : null;
|
|
251
|
+
return sessionDate ? { ...quote, regularClose: close, regularCloseSessionDate: sessionDate } : quote;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
function withDatedReading<T extends Quote | null | undefined>(quote: T, reading: Pick<Reading, "date" | "close"> | undefined): T {
|
|
178
255
|
if (!quote || !reading?.date) return quote;
|
|
179
256
|
if (reading.close == null) return withDate(quote, reading.date);
|
|
180
257
|
const close = reading.close;
|
|
@@ -204,7 +281,7 @@ function withReading<T extends Quote | null | undefined>(quote: T, reading: Pick
|
|
|
204
281
|
*/
|
|
205
282
|
export class PreviousCloseDates {
|
|
206
283
|
private readonly readings = new Map<string, Reading>();
|
|
207
|
-
private readonly pending = new Map<string, Promise<
|
|
284
|
+
private readonly pending = new Map<string, Promise<ReadingFields>>();
|
|
208
285
|
/** The latest copy of each quote a read is pending for, which the read dates when it lands. */
|
|
209
286
|
private readonly latestCopies = new Map<string, { quote: Quote; listing: DatedCloseListing }>();
|
|
210
287
|
/** Dating reads and index checks queue apart, so neither waits behind the other. */
|
|
@@ -268,21 +345,23 @@ export class PreviousCloseDates {
|
|
|
268
345
|
* Whether a reading answers without another read: a day it named that
|
|
269
346
|
* agreed with the quote's close, or any other reading taken lately. A
|
|
270
347
|
* correction (an index's close the quote disagreed with) is read again as
|
|
271
|
-
* an undated one is, so a wrong close cannot stand for the session
|
|
348
|
+
* an undated one is, so a wrong close cannot stand for the session, and so
|
|
349
|
+
* is a closed B3 quote's whose session's official close had not landed.
|
|
272
350
|
*/
|
|
273
351
|
private stands(reading: Reading | undefined): boolean {
|
|
274
|
-
return !!reading && ((!!reading.date && reading.close == null
|
|
352
|
+
return !!reading && ((!!reading.date && reading.close == null && !reading.awaitsSessionClose)
|
|
353
|
+
|| this.now() - reading.at < UNDATED_RETRY_MS);
|
|
275
354
|
}
|
|
276
355
|
|
|
277
|
-
private start(key: string, quote: Quote, listing: DatedCloseListing): Promise<
|
|
356
|
+
private start(key: string, quote: Quote, listing: DatedCloseListing): Promise<ReadingFields> {
|
|
278
357
|
this.latestCopies.set(key, { quote, listing });
|
|
279
358
|
return this.pending.get(key) ?? this.read(key, quote, listing);
|
|
280
359
|
}
|
|
281
360
|
|
|
282
|
-
private read(key: string, quote: Quote, listing: DatedCloseListing): Promise<
|
|
361
|
+
private read(key: string, quote: Quote, listing: DatedCloseListing): Promise<ReadingFields> {
|
|
283
362
|
const read = this.inSlot(datedIndexClose(quote) ? "index" : "dating", () => withDeadline(Promise.resolve().then(() => this.readCloses(listing)), this.readDeadlineMs, "Reading daily closes timed out"))
|
|
284
363
|
.then((points) => readingOf(points, quote))
|
|
285
|
-
.catch(logFailure("market-data.dated-previous-close", "Read daily closes failed", { date: null }))
|
|
364
|
+
.catch(logFailure("market-data.dated-previous-close", "Read daily closes failed", { date: null } as ReadingFields))
|
|
286
365
|
.then((reading) => {
|
|
287
366
|
this.pending.delete(key);
|
|
288
367
|
this.readings.delete(key);
|
|
@@ -290,7 +369,7 @@ export class PreviousCloseDates {
|
|
|
290
369
|
this.readings.set(key, { ...reading, at: this.now() });
|
|
291
370
|
const latest = this.latestCopies.get(key);
|
|
292
371
|
this.latestCopies.delete(key);
|
|
293
|
-
if (reading.date && latest && this.options.onDated) {
|
|
372
|
+
if ((reading.date || reading.sessionClose != null) && latest && this.options.onDated) {
|
|
294
373
|
try {
|
|
295
374
|
this.options.onDated(latest.listing, withReading(latest.quote, reading));
|
|
296
375
|
} catch (error) {
|
|
@@ -89,9 +89,25 @@ export function quoteBookSessionLabel(quote: Quote): string | null {
|
|
|
89
89
|
if (extended) return extended;
|
|
90
90
|
const day = quoteTradingDay(quote);
|
|
91
91
|
const date = day ? new Date(`${day}T00:00:00Z`) : null;
|
|
92
|
-
|
|
92
|
+
const label = date && Number.isFinite(date.getTime())
|
|
93
93
|
? `last quote, ${WEEKDAYS[date.getUTCDay()]} ${date.getUTCDate()} ${MONTHS[date.getUTCMonth()]}`
|
|
94
94
|
: "last quote";
|
|
95
|
+
return offMarketBook(quote) ? `${label}, off-market` : label;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** Past this share of the last price, a closed market's bid or ask is no market for it. */
|
|
99
|
+
const OFF_MARKET_SHARE = 0.05;
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Whether a closed market's last bid or ask is more than 5% off the last
|
|
103
|
+
* price: FMX's $118.00 / $135.00 around a $129.85 close on 6 Nov 2026 is a
|
|
104
|
+
* book left after the close, not where it trades.
|
|
105
|
+
*/
|
|
106
|
+
function offMarketBook(quote: Pick<Quote, "price" | "bid" | "ask">): boolean {
|
|
107
|
+
const last = quote.price;
|
|
108
|
+
if (typeof last !== "number" || !Number.isFinite(last) || last <= 0) return false;
|
|
109
|
+
return [quote.bid, quote.ask].some((side) =>
|
|
110
|
+
typeof side === "number" && Number.isFinite(side) && side > 0 && Math.abs(side - last) / last > OFF_MARKET_SHARE);
|
|
95
111
|
}
|
|
96
112
|
|
|
97
113
|
/** `Thu close`: the weekday of the session whose close a quote still stands at. */
|
|
@@ -83,15 +83,20 @@ export interface RiskMarketSnapshot {
|
|
|
83
83
|
}
|
|
84
84
|
/**
|
|
85
85
|
* The most holdings one load requests daily history for, largest current USD
|
|
86
|
-
* value first. Each holding costs one
|
|
87
|
-
*
|
|
86
|
+
* value first. Each holding costs one read of up to 18 months of closes,
|
|
87
|
+
* sixteen to a batch request, again after every two-minute cache expiry, and the
|
|
88
88
|
* correlation view pairs every basket holding with every other. See
|
|
89
89
|
* docs/research-data.md for the measured cost behind the number.
|
|
90
90
|
*/
|
|
91
91
|
export const RISK_HISTORY_LIMIT = 150;
|
|
92
92
|
/** Holdings quoted in one load, 50 to a batch request. */
|
|
93
93
|
const RISK_QUOTE_LIMIT = 500;
|
|
94
|
-
|
|
94
|
+
/**
|
|
95
|
+
* Histories asked at once. They go out sixteen to a batch request, side by
|
|
96
|
+
* side (getCloudHistory's `batch`): a 60-holding book is four requests, where
|
|
97
|
+
* four single reads at a time took about 6 s.
|
|
98
|
+
*/
|
|
99
|
+
const HISTORY_CONCURRENCY = 64;
|
|
95
100
|
const MAX_FX_CURRENCIES = 24;
|
|
96
101
|
export const BEYOND_SIZE_REASON = `Beyond the supported size: only the ${RISK_HISTORY_LIMIT} largest holdings by value are modelled`;
|
|
97
102
|
// Listing venues as the quotes report them; MTUM and QUAL list on Cboe BZX, not Arca.
|
|
@@ -402,7 +407,8 @@ export async function fetchPortfolioRiskMarket(
|
|
|
402
407
|
const key = `${canonicalExchange(exchange)}:${normalizeSymbol(symbol)}`;
|
|
403
408
|
let loading = dailyHistories.get(key);
|
|
404
409
|
if (!loading) {
|
|
405
|
-
|
|
410
|
+
// Read over the window every holding shares, so they go out together; the signal stops the wait, not a batch others share.
|
|
411
|
+
dailyHistories.set(key, loading = client.getCloudHistory(symbol, exchange, historyParams, { batch: true, sharedWindow: true, ...(signal ? { signal } : {}) }));
|
|
406
412
|
loading.catch(() => {
|
|
407
413
|
// Intentional ignore: the failure is raised where the history is read.
|
|
408
414
|
});
|
|
@@ -72,7 +72,8 @@ export interface RiskEpisodeTarget {
|
|
|
72
72
|
const DAY_MS = 86_400_000;
|
|
73
73
|
/** A boundary close may be this many days before its date: a weekend, a holiday or a market's own closure. */
|
|
74
74
|
const BOUNDARY_DAYS = 7;
|
|
75
|
-
|
|
75
|
+
/** Reads asked at once; they go out sixteen to a batch request over the episodes' one window. */
|
|
76
|
+
const EPISODE_CONCURRENCY = 64;
|
|
76
77
|
const SPY = RISK_FACTOR_INSTRUMENTS[0]!;
|
|
77
78
|
|
|
78
79
|
/** The one window every episode fits in, with room for a start date's close a holiday before it. */
|
|
@@ -149,12 +150,12 @@ export function cloudEpisodeReader(client: EpisodeClient = apiClient): EpisodeRe
|
|
|
149
150
|
const params = { interval: "1day", ...episodeSpan(), outputsize: 1500 } as const;
|
|
150
151
|
return {
|
|
151
152
|
async instrument(instrument, signal) {
|
|
152
|
-
return episodeCloses(dailyCloses(await client.getCloudHistory(instrument.symbol, instrument.exchange, params, signal ? { signal } :
|
|
153
|
+
return episodeCloses(dailyCloses(await client.getCloudHistory(instrument.symbol, instrument.exchange, params, { batch: true, sharedWindow: true, ...(signal ? { signal } : {}) })));
|
|
153
154
|
},
|
|
154
155
|
async currency(currency, signal) {
|
|
155
156
|
const leg = riskConversion(currency)?.leg;
|
|
156
157
|
if (!leg) throw new Error(`No daily FX pair for ${currency}`);
|
|
157
|
-
const points = dailyCloses(await client.getCloudHistory(leg.instrument.symbol, leg.instrument.exchange ?? "", params, signal ? { signal } :
|
|
158
|
+
const points = dailyCloses(await client.getCloudHistory(leg.instrument.symbol, leg.instrument.exchange ?? "", params, { batch: true, sharedWindow: true, ...(signal ? { signal } : {}) }));
|
|
158
159
|
return episodeCloses(points.map((point) => ({ ...point, close: leg.invert ? 1 / point.close : point.close })));
|
|
159
160
|
},
|
|
160
161
|
};
|
|
@@ -181,7 +182,7 @@ export function onceEpisodeReader(reader: EpisodeReader): EpisodeReader {
|
|
|
181
182
|
/**
|
|
182
183
|
* The closes the episode replays read: SPY's, every target's, and the daily
|
|
183
184
|
* FX closes of each currency a target quotes in and of a non-USD account,
|
|
184
|
-
*
|
|
185
|
+
* all asked at once, sixteen to a batch request. A read that fails is named in `errors`, and the
|
|
185
186
|
* replays move that holding by proxy; the signal stops the load.
|
|
186
187
|
*/
|
|
187
188
|
export async function fetchRiskEpisodeHistory(
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { portfolioSectorReport } from "./risk-sectors";
|
|
1
2
|
import { loadPortfolioOptionBook } from "./risk-options";
|
|
2
3
|
import type { HeadlessPaneDefinition } from "../../../types/plugin";
|
|
3
4
|
import { fetchPortfolioRiskMarket, RISK_HISTORY_LIMIT } from "./risk-client";
|
|
@@ -188,8 +189,8 @@ export const portfolioRiskHeadless: HeadlessPaneDefinition<"bundle"> = {
|
|
|
188
189
|
type: "enum",
|
|
189
190
|
settingKey: "riskView",
|
|
190
191
|
// No default: left out, the report prints every view.
|
|
191
|
-
values: RISK_VIEWS.map((value) => ({ value })),
|
|
192
|
-
description: "One portfolio risk view;
|
|
192
|
+
values: [...RISK_VIEWS, "sectors"].map((value) => ({ value })),
|
|
193
|
+
description: "One portfolio risk view; sectors compares direct company sector weights, cash and unclassified holdings against SPY (S&P 500) in percentage points. Every standard risk view when left out.",
|
|
193
194
|
},
|
|
194
195
|
{
|
|
195
196
|
key: "since",
|
|
@@ -262,6 +263,7 @@ export const portfolioRiskHeadless: HeadlessPaneDefinition<"bundle"> = {
|
|
|
262
263
|
describe: (args, result) =>
|
|
263
264
|
`Portfolio risk | ${reportPortfolioName(result?.metadata) || args.rawArgument || "local portfolio"}`,
|
|
264
265
|
async load(args, ctx) {
|
|
266
|
+
if (args.options.view === "sectors") return portfolioSectorReport(args, ctx);
|
|
265
267
|
// The host reads the argument by id or name, in any case; everything after goes by the configured id.
|
|
266
268
|
const requested = args.rawArgument.trim() || ctx.config.portfolios[0]?.id;
|
|
267
269
|
if (!requested || !ctx.resolvePortfolio)
|