gloomberb 0.20.13 → 0.20.14

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.
Files changed (155) hide show
  1. package/package.json +2 -1
  2. package/patches/@opentui%2Fcore@0.3.2.patch +22 -4
  3. package/src/account/auth-dialog.tsx +22 -4
  4. package/src/account/auth-form.tsx +6 -1
  5. package/src/account/checkout-handoff.tsx +7 -14
  6. package/src/account/device-signin-dialog.tsx +35 -24
  7. package/src/api-client/crypto-markets.ts +10 -0
  8. package/src/api-client/errors.ts +3 -1
  9. package/src/api-client/money-markets.ts +7 -0
  10. package/src/api-client/request.ts +12 -2
  11. package/src/architecture/floating-promise-allowlist.json +0 -1
  12. package/src/brokers/signed-in/sign-in-dialog.tsx +38 -38
  13. package/src/cli/commands/market.ts +95 -23
  14. package/src/cli/commands/overview.ts +18 -4
  15. package/src/cli/errors.ts +3 -1
  16. package/src/cli/freshness.ts +7 -2
  17. package/src/cli/glossary.ts +10 -5
  18. package/src/cli/helpers.ts +8 -16
  19. package/src/cli/history-export.ts +4 -0
  20. package/src/cli/known-gaps.ts +2 -2
  21. package/src/cli/listing-arg.ts +79 -11
  22. package/src/cli/not-a-ticker.ts +4 -0
  23. package/src/cli/pane-functions/catalog.ts +29 -8
  24. package/src/cli/pane-functions/headless.ts +5 -2
  25. package/src/cli/pane-functions/options.ts +7 -0
  26. package/src/cli/pane-functions/resolver.ts +61 -15
  27. package/src/cli/result.ts +22 -4
  28. package/src/cli/symbol-args.ts +5 -3
  29. package/src/cli/symbol-list.ts +23 -10
  30. package/src/cli/symbol-rows.ts +135 -3
  31. package/src/cli/treasury-yields.ts +15 -1
  32. package/src/components/chart/composite/format.ts +2 -1
  33. package/src/components/chart/composite/panel-surface/axis-markers.ts +133 -0
  34. package/src/components/chart/composite/panel-surface/level-labels.tsx +78 -0
  35. package/src/components/chart/composite/panel-surface/overlays.ts +108 -0
  36. package/src/components/chart/composite/panel-surface/pan-coast.ts +54 -0
  37. package/src/components/chart/composite/panel-surface/panel-cursor.tsx +138 -0
  38. package/src/components/chart/composite/panel-surface/panel-levels.ts +47 -0
  39. package/src/components/chart/composite/panel-surface/plot-gestures.ts +403 -0
  40. package/src/components/chart/composite/panel-surface/plot-pointer.ts +65 -0
  41. package/src/components/chart/composite/panel-surface/plot-wheel.ts +102 -0
  42. package/src/components/chart/composite/panel-surface/pointer.ts +12 -0
  43. package/src/components/chart/composite/panel-surface/props.ts +79 -0
  44. package/src/components/chart/composite/panel-surface/tool-readout.ts +151 -0
  45. package/src/components/chart/composite/panel-surface/value-axis-gestures.ts +152 -0
  46. package/src/components/chart/composite/panel-surface.tsx +81 -1177
  47. package/src/components/command-bar/commands/collection-list.ts +1 -0
  48. package/src/components/command-bar/routes/root/results.ts +3 -2
  49. package/src/components/command-bar/routes/root/runtime.ts +3 -2
  50. package/src/components/command-bar/routes/root/selection.ts +3 -2
  51. package/src/components/command-bar/routes/root/shortcuts.ts +15 -0
  52. package/src/components/layout/pane/title.ts +10 -4
  53. package/src/components/pane-settings-dialog/tui.tsx +6 -3
  54. package/src/components/pane-settings-dialog.tsx +2 -1
  55. package/src/components/pane-template-wizard.tsx +2 -0
  56. package/src/components/ui/choice-dialog.tsx +1 -1
  57. package/src/components/ui/confirm-dialog.tsx +3 -2
  58. package/src/components/ui/frame.tsx +7 -3
  59. package/src/components/ui/icon.tsx +4 -2
  60. package/src/components/ui/list-view.tsx +8 -0
  61. package/src/components/ui/number-prompt-dialog.tsx +2 -1
  62. package/src/components/use-pane-notice-footer.tsx +3 -1
  63. package/src/docs/snapshot.json +2 -2
  64. package/src/i18n/es.ts +1 -0
  65. package/src/i18n/ja.ts +1 -0
  66. package/src/i18n/ko.ts +1 -0
  67. package/src/i18n/zh-cn.ts +1 -0
  68. package/src/i18n/zh-tw.ts +1 -0
  69. package/src/market-data/market/format.ts +35 -1
  70. package/src/market-data/quotes/contributions.ts +13 -0
  71. package/src/market-data/quotes/export-identity.ts +36 -1
  72. package/src/market-data/quotes/resolution.ts +16 -0
  73. package/src/plugins/builtin/account-management/password-dialog.tsx +2 -2
  74. package/src/plugins/builtin/analytics/risk-client.ts +12 -2
  75. package/src/plugins/builtin/analytics/risk-headless.ts +66 -6
  76. package/src/plugins/builtin/analytics/risk-math.ts +23 -6
  77. package/src/plugins/builtin/analytics/risk-model.ts +20 -9
  78. package/src/plugins/builtin/analytics/risk-pane.tsx +2 -2
  79. package/src/plugins/builtin/chart-composer/catalog-inventory.ts +5 -2
  80. package/src/plugins/builtin/chart-composer/editor.tsx +1 -0
  81. package/src/plugins/builtin/chart-composer/pane.tsx +1 -1
  82. package/src/plugins/builtin/chart-composer/quick-add.tsx +4 -1
  83. package/src/plugins/builtin/chart-composer/series-catalog.ts +17 -1
  84. package/src/plugins/builtin/cloud/plugin.tsx +2 -0
  85. package/src/plugins/builtin/cloud/thesis/module.tsx +2 -0
  86. package/src/plugins/builtin/cloud/upgrade-status-widget.tsx +6 -2
  87. package/src/plugins/builtin/cpi/headless.ts +6 -1
  88. package/src/plugins/builtin/cpi/model.ts +17 -0
  89. package/src/plugins/builtin/cpi/pane.tsx +3 -1
  90. package/src/plugins/builtin/crypto-board/client.ts +6 -1
  91. package/src/plugins/builtin/crypto-board/headless.ts +10 -2
  92. package/src/plugins/builtin/crypto-board/model.ts +89 -11
  93. package/src/plugins/builtin/crypto-board/pane.tsx +20 -5
  94. package/src/plugins/builtin/dividend-yield/client.ts +24 -2
  95. package/src/plugins/builtin/dividend-yield/headless.ts +4 -2
  96. package/src/plugins/builtin/dividend-yield/ranking.ts +2 -1
  97. package/src/plugins/builtin/dividend-yield/view.ts +5 -1
  98. package/src/plugins/builtin/earnings/history-table.ts +8 -0
  99. package/src/plugins/builtin/earnings-ripple/index.tsx +2 -0
  100. package/src/plugins/builtin/econ/calendar-model.ts +17 -1
  101. package/src/plugins/builtin/econ/fred-catalog.ts +33 -4
  102. package/src/plugins/builtin/econ-statistics/headless.ts +21 -0
  103. package/src/plugins/builtin/macro-day/headless.ts +21 -10
  104. package/src/plugins/builtin/macro-day/model.ts +40 -3
  105. package/src/plugins/builtin/macro-day/pane.tsx +26 -8
  106. package/src/plugins/builtin/macro-day/releases.ts +24 -1
  107. package/src/plugins/builtin/money-markets/client.ts +4 -1
  108. package/src/plugins/builtin/money-markets/headless.ts +15 -4
  109. package/src/plugins/builtin/money-markets/index.tsx +1 -1
  110. package/src/plugins/builtin/money-markets/pane.tsx +7 -1
  111. package/src/plugins/builtin/portfolio-list/cli/bulk-symbols.ts +4 -2
  112. package/src/plugins/builtin/portfolio-list/cli/period-report.ts +61 -11
  113. package/src/plugins/builtin/portfolio-list/cli/portfolio-command.ts +11 -3
  114. package/src/plugins/builtin/portfolio-list/cli/watchlist-command.ts +2 -0
  115. package/src/plugins/builtin/portfolio-list/headless.ts +33 -6
  116. package/src/plugins/builtin/portfolio-list/pane/index.tsx +5 -3
  117. package/src/plugins/builtin/portfolio-list/pane/period-pnl.ts +24 -6
  118. package/src/plugins/builtin/portfolio-list/period-pnl.ts +16 -1
  119. package/src/plugins/builtin/portfolio-list/summary/index.tsx +4 -1
  120. package/src/plugins/builtin/portfolio-list/summary/totals.ts +6 -4
  121. package/src/plugins/builtin/portfolio-list/table.tsx +25 -15
  122. package/src/plugins/builtin/shared/cloud-upgrade.ts +4 -2
  123. package/src/plugins/builtin/shared/cpi-year-gap.ts +67 -0
  124. package/src/plugins/builtin/ticker-detail/adr-pair/headless.ts +45 -2
  125. package/src/plugins/builtin/ticker-detail/headless.ts +26 -1
  126. package/src/plugins/builtin/ticker-detail/overview/components.tsx +4 -5
  127. package/src/plugins/builtin/ticker-detail/overview/model.ts +4 -1
  128. package/src/plugins/builtin/ticker-detail/overview-tab.tsx +10 -2
  129. package/src/portfolio/collection-name.ts +2 -1
  130. package/src/portfolio/column-values.ts +14 -4
  131. package/src/portfolio/listed-symbol.ts +4 -2
  132. package/src/portfolio/period-pnl.ts +51 -1
  133. package/src/renderers/dom/dialog-host.tsx +5 -5
  134. package/src/renderers/electrobun/view/remote/capability-invoker.ts +1 -1
  135. package/src/renderers/opentui/dialog-host.tsx +3 -4
  136. package/src/sources/gloomberb-cloud/normalizers.ts +5 -0
  137. package/src/sources/provider-router/history.ts +5 -2
  138. package/src/test-support/plugin-persistence.ts +12 -0
  139. package/src/tickers/company-name-listing.ts +4 -3
  140. package/src/tickers/company-name.ts +19 -1
  141. package/src/tickers/instrument-coverage.ts +27 -0
  142. package/src/tickers/search/home-listing.ts +38 -1
  143. package/src/tickers/search/index.ts +3 -2
  144. package/src/tickers/search/ranking.ts +21 -2
  145. package/src/time-series/base-series.ts +4 -0
  146. package/src/time-series/types.ts +5 -2
  147. package/src/types/financials.ts +13 -0
  148. package/src/types/headless.ts +2 -0
  149. package/src/ui/dialog-stack.ts +17 -0
  150. package/src/ui/dialog.tsx +6 -2
  151. package/src/utils/crypto-pair.ts +9 -0
  152. package/src/utils/exchanges.ts +13 -0
  153. package/src/utils/financial-statements.ts +60 -3
  154. package/src/utils/futures-generic.ts +14 -0
  155. package/src/utils/trailing-dividend.ts +13 -3
@@ -8,7 +8,8 @@ import type {
8
8
  } from "../../../api-client/types";
9
9
  import { createPluginCache } from "../../../data/plugin-cache";
10
10
  import { loadCloudResource } from "../shared/cloud-resource";
11
- import { canonicalExchange, normalizeSymbol } from "../../../utils/exchanges";
11
+ import { canonicalExchange, normalizeSymbol, storedKeyListing } from "../../../utils/exchanges";
12
+ import type { TickerRecord } from "../../../types/ticker";
12
13
  import { resolveCurrencyUnit } from "../../../utils/currency-units";
13
14
  import type { PricePoint } from "../../../types/financials";
14
15
  import { resolveDatedReturns, type DatedReturn } from "../../../portfolio/return-metrics";
@@ -67,6 +68,8 @@ interface RiskMarketHistory {
67
68
  fxBridged?: string[];
68
69
  } | null;
69
70
  error: string | null;
71
+ /** Set when its daily closes did not load (the service failed or did not answer), which asked again they may. */
72
+ loadFailed?: true;
70
73
  }
71
74
  export interface RiskMarketSnapshot {
72
75
  histories: RiskMarketHistory[];
@@ -113,6 +116,9 @@ export const RISK_FACTOR_INSTRUMENTS: RiskInstrument[] = [
113
116
  ].map(([symbol, exchange]) => ({ symbol: symbol!, exchange: exchange! }));
114
117
  /** US equity venues quote only in USD, so the listing venue alone establishes currency. */
115
118
  const US_LISTING_VENUES = new Set(["NASDAQ", "NYSE", "AMEX", "ARCA", "BATS", "CBOE"]);
119
+ /** A held row as the listing its history is read for: `ES3:XSES` is ES3 on SGX, never a symbol the service does not know. */
120
+ export const riskInstrumentOf = (ticker: Pick<TickerRecord, "metadata">): RiskInstrument =>
121
+ storedKeyListing(ticker.metadata.ticker, ticker.metadata.exchange);
116
122
  export const riskInstrumentId = (instrument: RiskInstrument) =>
117
123
  `${canonicalExchange(instrument.exchange)}:${normalizeSymbol(instrument.symbol)}`;
118
124
  const message = (error: unknown) =>
@@ -650,9 +656,13 @@ export async function fetchPortfolioRiskMarket(
650
656
  entry = histories[index]!,
651
657
  conversion = conversions.get(instruments[index]![0]),
652
658
  { instrument, quote } = entry;
659
+ // Whether its closes' request failed, which asked again may answer; an answer without them, or a pair's FX, is a reason.
660
+ let requesting = false;
653
661
  try {
654
662
  const fxCloses = conversion ? await fxHistory(conversion) : null;
663
+ requesting = true;
655
664
  const response = await historyOf(instrument.symbol, instrument.exchange || quote?.listingExchangeName || "");
665
+ requesting = false;
656
666
  const { latestClose, fxBridged, ...resolved } = validateRiskHistory(
657
667
  response,
658
668
  instrument,
@@ -687,7 +697,7 @@ export async function fetchPortfolioRiskMarket(
687
697
  };
688
698
  } catch (error) {
689
699
  if (isAccessDenied(error) || signal?.aborted) throw error;
690
- histories[index] = { ...entry, error: message(error) };
700
+ histories[index] = { ...entry, error: message(error), ...(requesting ? { loadFailed: true as const } : {}) };
691
701
  }
692
702
  }
693
703
  }),
@@ -1,7 +1,7 @@
1
1
  import { portfolioSectorReport } from "./risk-sectors";
2
2
  import { loadPortfolioOptionBook } from "./risk-options";
3
3
  import type { HeadlessPaneDefinition } from "../../../types/plugin";
4
- import { fetchPortfolioRiskMarket, RISK_HISTORY_LIMIT } from "./risk-client";
4
+ import { fetchPortfolioRiskMarket, riskInstrumentOf, RISK_HISTORY_LIMIT } from "./risk-client";
5
5
  import { parsePortfolioRiskEvidence } from "./risk-evidence";
6
6
  import { cloudEpisodeReader, fetchRiskEpisodeHistory, onceEpisodeReader, riskEpisodeTargets } from "./risk-episodes";
7
7
  import { describeCollections } from "../../../portfolio/collection-name";
@@ -71,6 +71,51 @@ function emptyPortfolioHint(name: string, listed: readonly string[]): string {
71
71
  + `then their shares with gloom portfolio position set ${portfolio} AAPL 10 150.`;
72
72
  }
73
73
 
74
+ /**
75
+ * Why a view of PORT has no rows, in one line, as its section says it in
76
+ * place of a bare "No data.": what it needs, and where the trustee's question
77
+ * is answered instead. Performance reads the account's own history, which a
78
+ * book entered by hand has none of; its P&L over a period is `portfolio show
79
+ * --from`.
80
+ */
81
+ function riskSectionEmpty(
82
+ view: RiskView,
83
+ { name, brokerLinked, unvaluedOptions, failedHistories }: {
84
+ name: string; brokerLinked: boolean; unvaluedOptions: boolean;
85
+ /** Holdings whose daily closes did not load: the reason a view of returns is empty, not what the book holds. */
86
+ failedHistories: readonly string[];
87
+ },
88
+ ): string {
89
+ if (failedHistories.length > 0 && !RISK_OWN_DATA_VIEWS.has(view)) return failedClosesText(failedHistories);
90
+ switch (view) {
91
+ case "performance":
92
+ return `No account history${brokerLinked ? " from its broker" : ""} (daily values and flows) to measure. `
93
+ + `For P&L over a period: gloom portfolio show ${shellWord(name)} --from <date>.`;
94
+ case "attribution":
95
+ return "No sector weights and returns for this account and its benchmark; import them with --evidence.";
96
+ case "greeks":
97
+ return unvaluedOptions ? "No option position in this portfolio could be valued." : "No option positions in this portfolio.";
98
+ case "correlation":
99
+ return "Needs two holdings with 60 daily returns each.";
100
+ default:
101
+ return "No holding has the daily closes this view needs.";
102
+ }
103
+ }
104
+
105
+ /** Views read from the account's own records or option positions, not from its holdings' daily closes. */
106
+ const RISK_OWN_DATA_VIEWS: ReadonlySet<RiskView> = new Set(["performance", "attribution", "greeks"]);
107
+
108
+ /** The holdings whose daily closes did not load, for an empty view's reason. */
109
+ function failedHistories(coverage: RiskCoverage | undefined): string[] {
110
+ return (coverage?.leftOut ?? []).filter((line) => line.historyFailed).map((line) => line.symbol);
111
+ }
112
+
113
+ /** "Daily closes did not load for US02, US03 and 4 more; try again in a moment." */
114
+ function failedClosesText(symbols: readonly string[]): string {
115
+ const more = symbols.length > 3 ? ` and ${symbols.length - 3} more` : "";
116
+ return `Daily closes did not load for ${symbols.slice(0, 3).join(", ")}${more}; try again in a moment.`;
117
+ }
118
+
74
119
  /** Rows of one view in the compact result; the pane and reports keep every row. */
75
120
  const COMPACT_ROW_LIMIT = 100;
76
121
  /** The correlation view is every pair of holdings; the compact result keeps the strongest. */
@@ -127,7 +172,11 @@ function coverageSummary(coverage: RiskCoverage, limit = Infinity) {
127
172
  function coverageLine(coverage: RiskCoverage | undefined): { error?: string; note?: string } {
128
173
  const shortfall = riskCoverageShortfall(coverage);
129
174
  // No estimate at all is a failure; an estimate that leaves holdings out is a caveat.
130
- if (shortfall) return { error: `Basket estimates unavailable: ${shortfall.title} ${shortfall.message}`.trim() };
175
+ if (shortfall) {
176
+ // Closes that did not load are why, which asked again may not be.
177
+ const failed = failedHistories(coverage);
178
+ return { error: [`Basket estimates unavailable: ${shortfall.title} ${shortfall.message}`.trim(), ...failed.length ? [failedClosesText(failed)] : []].join(" ") };
179
+ }
131
180
  const line = coverage?.leftOut.length ? riskCoverageLine(coverage) : null;
132
181
  return line ? { note: `${line[0]!.toUpperCase()}${line.slice(1)}; metadata.coverage lists each with its reason.` } : {};
133
182
  }
@@ -307,7 +356,8 @@ export const portfolioRiskHeadless: HeadlessPaneDefinition<"bundle"> = {
307
356
  // go unused. A bigger book waits for the basket, so it reads no closes it does not replay.
308
357
  const warming = wantsEpisodes && tickers.length <= EPISODE_WARM_LIMIT
309
358
  ? fetchRiskEpisodeHistory(
310
- tickers.map((ticker) => ({ instrument: { symbol: ticker.metadata.ticker, exchange: ticker.metadata.exchange }, currency: null })),
359
+ // With the currency each is saved in, so the FX closes the replay converts at are read alongside, not after.
360
+ tickers.map((ticker) => ({ instrument: riskInstrumentOf(ticker), currency: ticker.metadata.currency || null })),
311
361
  local.portfolio.currency, episodeReader, ctx.signal,
312
362
  ).catch(() => {
313
363
  // Intentional ignore: the replayed load below reads the same closes and reports their failures.
@@ -335,7 +385,7 @@ export const portfolioRiskHeadless: HeadlessPaneDefinition<"bundle"> = {
335
385
  : loadPortfolioOptionBook(tickers, local.portfolio),
336
386
  ]);
337
387
  const episodeTargets = wantsEpisodes
338
- ? riskEpisodeTargets(prices, tickers.map((ticker) => ({ symbol: ticker.metadata.ticker, exchange: ticker.metadata.exchange })))
388
+ ? riskEpisodeTargets(prices, tickers.map(riskInstrumentOf))
339
389
  : [];
340
390
  const episodes = episodeTargets.length
341
391
  ? await fetchRiskEpisodeHistory(episodeTargets, local.portfolio.currency, episodeReader, ctx.signal)
@@ -406,7 +456,13 @@ export const portfolioRiskHeadless: HeadlessPaneDefinition<"bundle"> = {
406
456
  complete,
407
457
  errors: model.warnings,
408
458
  notes: [...riskCoverageNotices(model.coverage), ...model.notes.filter((note) => note !== fallback)],
409
- sections: shown.map(({ view, rows }) => ({ title: view, columns: RISK_COLUMNS, rows })),
459
+ // A view with nothing to show says why in one line.
460
+ sections: shown.map(({ view, rows }) => ({ title: view, columns: RISK_COLUMNS, rows, ...(rows.length === 0 ? { empty: riskSectionEmpty(view, {
461
+ name: local.portfolio.name,
462
+ brokerLinked: !!(local.portfolio.brokerId || local.portfolio.brokerInstanceId),
463
+ unvaluedOptions: (model.greeks?.warnings.length ?? 0) > 0,
464
+ failedHistories: failedHistories(model.coverage),
465
+ }) } : {}) })),
410
466
  metadata: { coverage: coverageSummary(model.coverage), model, benchmark: model.benchmark, window: model.window,
411
467
  notices: [...(shortfall ? [shortfall] : []), ...notices] },
412
468
  };
@@ -426,7 +482,11 @@ export const portfolioRiskHeadless: HeadlessPaneDefinition<"bundle"> = {
426
482
  complete: result.complete,
427
483
  ...(errors.length ? { errors } : {}),
428
484
  ...(notes.length ? { notes } : {}),
429
- sections: [{ title: view, columns: RISK_COLUMNS, rows: rows.map(displayRow) }],
485
+ sections: [{ title: view, columns: RISK_COLUMNS, rows: rows.map(displayRow), ...(rows.length === 0 ? { empty: riskSectionEmpty(view, {
486
+ name: model.portfolio.name, brokerLinked: !!(model.portfolio.brokerId || model.portfolio.brokerInstanceId),
487
+ unvaluedOptions: (model.greeks?.warnings.length ?? 0) > 0,
488
+ failedHistories: failedHistories(model.coverage),
489
+ }) } : {}) }],
430
490
  metadata: {
431
491
  portfolio: {
432
492
  id: model.portfolio.id,
@@ -106,12 +106,13 @@ function byInterval(series: readonly DatedReturn[]): Map<string, number> {
106
106
  }
107
107
  return index;
108
108
  }
109
- /** Matched start and end dates prevent pairing a multi-session return with a daily one. */
110
- export function regressReturns(
111
- asset: readonly DatedReturn[],
112
- factor: readonly DatedReturn[],
113
- minimum = 60,
114
- ): Regression | null {
109
+ /**
110
+ * The asset's returns over the same start and end dates as the factor's, in
111
+ * the asset's order, the latest `window` of them when given. The window is
112
+ * taken after matching: two series that end on different days (a US close
113
+ * today, a Singapore close yesterday) still pair their latest common returns.
114
+ */
115
+ function matchReturns(asset: readonly DatedReturn[], factor: readonly DatedReturn[], window?: number) {
115
116
  const other = byInterval(factor);
116
117
  const sample: DatedReturn[] = [],
117
118
  x: number[] = [],
@@ -124,6 +125,22 @@ export function regressReturns(
124
125
  x.push(matched);
125
126
  y.push(point.value);
126
127
  }
128
+ const from = window == null ? 0 : Math.max(0, sample.length - window);
129
+ return { sample: sample.slice(from), x: x.slice(from), y: y.slice(from) };
130
+ }
131
+ /** How many daily returns two series share, by start and end date. */
132
+ export const matchedReturnCount = (asset: readonly DatedReturn[], factor: readonly DatedReturn[]) =>
133
+ matchReturns(asset, factor).sample.length;
134
+ /**
135
+ * Matched start and end dates prevent pairing a multi-session return with a
136
+ * daily one. `window`: the latest so many matched returns, else every one.
137
+ */
138
+ export function regressReturns(
139
+ asset: readonly DatedReturn[],
140
+ factor: readonly DatedReturn[],
141
+ { window, minimum = 60 }: { window?: number; minimum?: number } = {},
142
+ ): Regression | null {
143
+ const { sample, x, y } = matchReturns(asset, factor, window);
127
144
  if (sample.length < minimum) return null;
128
145
  const meanX = x.reduce((a, b) => a + b, 0) / x.length,
129
146
  meanY = y.reduce((a, b) => a + b, 0) / y.length;
@@ -19,6 +19,7 @@ import {
19
19
  import {
20
20
  buyAndHoldReturns,
21
21
  concentration,
22
+ matchedReturnCount,
22
23
  pairedReturns,
23
24
  regressReturns,
24
25
  RISK_TAIL_CONFIDENCE,
@@ -46,6 +47,7 @@ import {
46
47
  import {
47
48
  RISK_FACTOR_INSTRUMENTS,
48
49
  riskInstrumentId,
50
+ riskInstrumentOf,
49
51
  type RiskHoldingRequest,
50
52
  type RiskMarketSnapshot,
51
53
  } from "./risk-client";
@@ -92,6 +94,8 @@ interface PortfolioRiskHolding {
92
94
  error: string | null;
93
95
  /** Why the holding is outside the basket; null when it qualifies. */
94
96
  leftOut: string | null;
97
+ /** Set when that is its daily closes not loading, which asked again they may. */
98
+ historyFailed?: true;
95
99
  }
96
100
  /** A holding or a currency's cash outside the basket, with its share of the book when one is known. */
97
101
  interface RiskLeftOut {
@@ -102,6 +106,8 @@ interface RiskLeftOut {
102
106
  share: number | null;
103
107
  /** Set on a currency's cash, which is never in the basket and does not make a report incomplete. */
104
108
  cash?: true;
109
+ /** Set when its daily closes did not load, which asked again they may. */
110
+ historyFailed?: true;
105
111
  }
106
112
  /** One currency of the book's cash, valued in the account currency. */
107
113
  interface RiskCashHolding extends RiskCashLine {
@@ -412,8 +418,7 @@ export function portfolioRiskRequests(
412
418
  ? lots.reduce((sum, row) => sum + Math.abs(row.marketValue!), 0)
413
419
  : null;
414
420
  return {
415
- symbol: ticker.metadata.ticker,
416
- exchange: ticker.metadata.exchange,
421
+ ...riskInstrumentOf(ticker),
417
422
  quantity: signedQuantity(lots),
418
423
  currency,
419
424
  snapshotValue: snapshot,
@@ -717,10 +722,7 @@ export function buildPortfolioRisk(
717
722
  tickers,
718
723
  portfolio.id,
719
724
  ).map((ticker) => {
720
- const instrument = {
721
- symbol: ticker.metadata.ticker,
722
- exchange: ticker.metadata.exchange,
723
- },
725
+ const instrument = riskInstrumentOf(ticker),
724
726
  id = riskInstrumentId(instrument);
725
727
  const history = byId.get(id),
726
728
  quote = history?.quote,
@@ -808,6 +810,7 @@ export function buildPortfolioRisk(
808
810
  fxBridged: holdingFxBridges(convertedFrom, history?.converted?.fxBridged, account, inAccount?.bridged),
809
811
  error,
810
812
  leftOut,
813
+ ...(history?.loadFailed && leftOut === history.error ? { historyFailed: true as const } : {}),
811
814
  };
812
815
  });
813
816
  // Each currency's cash once, valued in the portfolio currency.
@@ -858,6 +861,7 @@ export function buildPortfolioRisk(
858
861
  reason: row.leftOut!,
859
862
  value: row.marketValue,
860
863
  share: bookShare(row.marketValue),
864
+ ...(row.historyFailed ? { historyFailed: true as const } : {}),
861
865
  })),
862
866
  ...cashHoldings.map((row): RiskLeftOut => {
863
867
  const value = row.value == null ? null : Math.abs(row.value);
@@ -1019,17 +1023,24 @@ export function buildPortfolioRisk(
1019
1023
  : []),
1020
1024
  ].map((factor) => ({
1021
1025
  ...rollingBeta(basket, factor.series, factor.label, factor.id),
1022
- regression: regressReturns(basket.slice(-60), factor.series),
1026
+ regression: regressReturns(basket, factor.series, { window: 60 }),
1023
1027
  }));
1028
+ // The latest 60 returns both holdings have: a US close today and a Singapore close yesterday still pair their common days.
1024
1029
  const correlation = members.flatMap((left, index) =>
1025
1030
  members.slice(index + 1).map((right) => {
1026
- const regression = regressReturns(left.returns.slice(-60), right.returns);
1031
+ const regression = regressReturns(left.returns, right.returns, { window: 60 });
1032
+ const matched = regression?.samples ?? matchedReturnCount(left.returns, right.returns);
1027
1033
  return {
1028
1034
  left: left.id,
1029
1035
  right: right.id,
1030
1036
  label: `${left.symbol} / ${right.symbol}`,
1031
1037
  ...regression,
1032
1038
  value: regression?.correlation ?? null,
1039
+ // Why a pair has no correlation, in words.
1040
+ evidence: regression?.correlation != null ? `${matched} matched daily returns`
1041
+ : matched === 0 ? "no daily returns on the same dates"
1042
+ : matched < 60 ? `only ${matched} daily returns on the same dates; 60 needed`
1043
+ : `a price that did not move over ${matched} matched daily returns`,
1033
1044
  };
1034
1045
  }),
1035
1046
  );
@@ -1212,7 +1223,7 @@ export function buildPortfolioRisk(
1212
1223
  unit: "correlation",
1213
1224
  percentile: null,
1214
1225
  asOf: row.asOf ?? null,
1215
- detail: `${row.samples ?? 0} matched daily returns`,
1226
+ detail: row.evidence,
1216
1227
  }))
1217
1228
  .sort((left, right) => (right.value == null ? -1 : Math.abs(right.value)) - (left.value == null ? -1 : Math.abs(left.value))),
1218
1229
  stress: [
@@ -45,7 +45,7 @@ import { useThemeColors } from "../../../theme/theme-context";
45
45
  import type { PaneProps } from "../../../types/plugin";
46
46
  import { isAccessDenied } from "../../../api-client/errors";
47
47
  import { useResearchCloudSession } from "../shared/research-cloud-session";
48
- import { loadPortfolioRiskMarket } from "./risk-client";
48
+ import { loadPortfolioRiskMarket, riskInstrumentOf } from "./risk-client";
49
49
  import { loadRiskEpisodeHistory, riskEpisodeTargets, type RiskEpisodeState, type RiskEpisodeTarget } from "./risk-episodes";
50
50
  import { brokerPerformanceEvidence, parsePortfolioRiskEvidence } from "./risk-evidence";
51
51
  import { useBrokerPortfolioPerformance } from "./broker-performance";
@@ -443,7 +443,7 @@ export function PortfolioRiskPane({ focused, width, height }: PaneProps) {
443
443
  // load only there, once the market load says which holdings the basket takes.
444
444
  const episodeTargetsKey = useMemo(() => {
445
445
  if (frozen || view !== "stress" || !resource.data) return null;
446
- const held = localTickers.map((ticker) => ({ symbol: ticker.metadata.ticker, exchange: ticker.metadata.exchange }));
446
+ const held = localTickers.map(riskInstrumentOf);
447
447
  const targets = riskEpisodeTargets(resource.data, held);
448
448
  return targets.length ? JSON.stringify(targets) : null;
449
449
  }, [frozen, localTickers, resource.data, view]);
@@ -5,7 +5,7 @@ import {
5
5
  } from "../../../time-series/field-catalog";
6
6
  import type { SeriesCatalogEntry, SeriesFrequency, SeriesInput, SeriesPlacement } from "../../../series/types";
7
7
  import { parseOptionSymbol } from "../../../utils/options";
8
- import type { SeriesCatalogInstrument } from "./series-catalog";
8
+ import { hasCompanyFields, type SeriesCatalogInstrument } from "./series-catalog";
9
9
  import { macroReleaseTopic } from "../shared/macro-releases";
10
10
 
11
11
  export const CHART_COMPOSER_TEMPLATE_ID = "chart-composer-pane";
@@ -262,7 +262,10 @@ export function catalogRowsForResolvedInstruments(
262
262
  const symbol = catalogTickerFromInput(instrument.symbol);
263
263
  if (!symbol) return [];
264
264
  const input = instrumentInput(instrument);
265
- return templates.filter((row) => row.input === input).map((row): CatalogSeriesRow => {
265
+ // An index or a currency pair has prices, not a company's revenue or EPS.
266
+ const companyFields = hasCompanyFields(instrument);
267
+ return templates.filter((row) => row.input === input
268
+ && (companyFields || !row.id.startsWith("field:") || row.id.startsWith("field:market."))).map((row): CatalogSeriesRow => {
266
269
  const expression = fillTemplate(row.template, symbol);
267
270
  return {
268
271
  ...row,
@@ -84,6 +84,7 @@ export function SeriesEditorDialog({ dialogId, resolve, initialSpec }: SeriesEdi
84
84
  return (
85
85
  <DialogFrame
86
86
  title="Chart Series"
87
+ onClose={() => resolve(null)}
87
88
  footer={[...navigationKeys, ...seriesKeys].join(" · ")}
88
89
  // The desktop's fields take the pointer and arrows like any form.
89
90
  desktopFooter={selected
@@ -1394,7 +1394,7 @@ function ChartComposerSurface({
1394
1394
  spec={spec}
1395
1395
  setSpec={setSpec}
1396
1396
  focused={focused}
1397
- width={Math.max(8, Math.min(36, width - 1))}
1397
+ width={Math.max(8, width - 1)}
1398
1398
  height={height}
1399
1399
  shortcutEnabled={surfaceInteractive}
1400
1400
  shortcutBlocked={dialogOpen}
@@ -29,7 +29,8 @@ const CHART_TOOLBAR_HEIGHT = 1;
29
29
  const MINIMUM_CHART_HEIGHT = 4;
30
30
  const QUICK_ADD_ROW_HEIGHT = 1;
31
31
  const IDLE_QUICK_ADD_WIDTH = 14;
32
- const ACTIVE_QUICK_ADD_WIDTH = 36;
32
+ /** A pair's price row (`USDC-USD · Price (OHLCV)`) and its `Chart bars` fit whole. */
33
+ const ACTIVE_QUICK_ADD_WIDTH = 40;
33
34
 
34
35
  interface ClosestElementLike {
35
36
  closest(selector: string): {
@@ -474,6 +475,8 @@ export function ChartSeriesQuickAdd({
474
475
  surface="plain"
475
476
  bgColor={colors.panel}
476
477
  scrollable={items.length > drawerHeight}
478
+ // A scrollbar would take the rows' last column, where a press must add the row like the rest of it.
479
+ scrollbar={false}
477
480
  rowGap={0}
478
481
  selectOnHover
479
482
  onSelect={(index) => setSelectedIndex(index - (searchError ? 1 : 0))}
@@ -17,6 +17,8 @@ import {
17
17
  import { parseSeriesExpression, type ParsedSeriesExpression } from "./series-expression";
18
18
  import { parseFormulaExpression } from "./formula";
19
19
  import { currencyCodeLabel } from "../../../utils/currency-units";
20
+ import { classifyInstrumentType, kindFromListingSyntax } from "../../../tickers/instrument-kind";
21
+ import { isCryptoPairSymbol } from "../../../utils/crypto-pair";
20
22
 
21
23
  export interface SeriesCatalogInstrument {
22
24
  symbol: string;
@@ -204,7 +206,9 @@ export function fieldCategory(field: TimeSeriesFieldDefinition): string {
204
206
  return "Fundamentals";
205
207
  }
206
208
 
209
+ /** A market field is drawn at the chart's own bar size (1m on a day's chart), never fixed at its daily default. */
207
210
  function fieldFrequency(field: TimeSeriesFieldDefinition): string {
211
+ if (field.id.startsWith("market.")) return "Chart bars";
208
212
  return field.nativeFrequency === "auto"
209
213
  ? "Automatic"
210
214
  : `${field.nativeFrequency[0]!.toUpperCase()}${field.nativeFrequency.slice(1)}`;
@@ -425,6 +429,17 @@ export function buildCapabilitySeriesSuggestions(
425
429
  }));
426
430
  }
427
431
 
432
+ /**
433
+ * Whether a listing can have company fields (revenue, EPS, valuation): not a coin, a currency pair, an index or a
434
+ * future, which have prices alone. A coin's add-series list offered Revenue, Net Income and EPS.
435
+ */
436
+ export function hasCompanyFields(instrument: SeriesCatalogInstrument): boolean {
437
+ const kind = classifyInstrumentType(instrument.assetCategory)
438
+ ?? kindFromListingSyntax(instrument.symbol, instrument.exchange)
439
+ ?? (isCryptoPairSymbol(instrument.symbol.trim().toUpperCase()) ? "crypto" : null);
440
+ return kind == null || kind === "equity" || kind === "fund" || kind === "other";
441
+ }
442
+
428
443
  export function buildSeriesCatalogSuggestions(
429
444
  query: string,
430
445
  defaultInstrument: SeriesCatalogInstrument,
@@ -455,7 +470,8 @@ export function buildSeriesCatalogSuggestions(
455
470
  for (const instrument of instruments) {
456
471
  const instrumentKey = publicTickerKey(instrument.symbol, instrument.exchange);
457
472
  const instrumentLabel = canonicalTickerKey(instrument.symbol, instrument.exchange);
458
- for (const { field } of rankedFields.slice(0, fieldLimit)) {
473
+ const fields = hasCompanyFields(instrument) ? rankedFields : rankedFields.filter(({ field }) => field.id.startsWith("market."));
474
+ for (const { field } of fields.slice(0, fieldLimit)) {
459
475
  const expression: ParsedSeriesExpression = {
460
476
  kind: "security",
461
477
  symbol: instrument.symbol,
@@ -119,6 +119,8 @@ const askgModule: PluginModule = {
119
119
  description: "Ask a question about your panes and watch the tools Gloom runs",
120
120
  keywords: ["ask", "gloom", "assistant", "ai", "question", "askg"],
121
121
  shortcut: { prefix: "ASKG", argPlaceholder: "question", argKind: "text" },
122
+ // createInstance asks the open pane a question, so catalog discovery must not run it with a sample one.
123
+ catalogSettings: {},
122
124
  createInstance: (_context, options) => {
123
125
  // The question is handed to the pane directly, so it is never persisted
124
126
  // with the layout and never replayed on the next launch.
@@ -31,6 +31,8 @@ export const thesisModule: PluginModule = {
31
31
  description: "Every thesis you and your teams hold, sorted by what needs a ruling",
32
32
  keywords: ["thesis", "theses", "conviction", "invalidation", "kill", "pillars", "journal"],
33
33
  shortcut: { prefix: "THESIS", argPlaceholder: "tickers (optional)", argKind: "text" },
34
+ // createInstance starts a thesis in the open board, so catalog discovery must not run it with a sample ticker.
35
+ catalogSettings: {},
34
36
  createInstance: (_context, options) => {
35
37
  // `THESIS NVDA` opens that thesis or starts one; `THESIS NVDA AMD` starts a pair. The params name the
36
38
  // ticker to a board that is drawn without the request (a capture), which shows it without starting one.
@@ -11,6 +11,7 @@ import { chatController, type ChatController } from "../chat/controller";
11
11
  import { useCloudPlanAction, useCloudUpgradeAction } from "../shared/cloud-upgrade";
12
12
  import { CLOUD_QUOTE_DELAY_MINUTES, resolvePlanAccess } from "../../../api-client/plan-access";
13
13
  import { useTrialOfferShowing } from "./trial-offer-status-widget";
14
+ import { logFailure } from "../../../utils/log-failure";
14
15
  import {
15
16
  NARROW_STATUS_BAR_COLUMNS,
16
17
  STATUS_WIDGET_COLUMNS,
@@ -86,16 +87,19 @@ export function CloudUpgradeStatusWidget({ controller = chatController }: CloudU
86
87
 
87
88
  const mark = <DelayedMark minutes={CLOUD_QUOTE_DELAY_MINUTES} />;
88
89
  const detail = tf("{delay} delayed", { delay: `${CLOUD_QUOTE_DELAY_MINUTES}m` });
90
+ // What is late, and by how much: stock quotes. A crypto exchange's own prices are not held back.
91
+ const reason = tf("Stock quotes are {minutes} min delayed without Pro.", { minutes: CLOUD_QUOTE_DELAY_MINUTES });
92
+ const upgrade = () => { openUpgrade({ reason }).catch(logFailure("cloud.upgrade-status-widget", "Open upgrade from the delayed mark failed")); };
89
93
  return (
90
94
  <Box flexDirection="row" alignItems="center" flexShrink={0} paddingRight={1} data-gloom-role="delayed-status">
91
95
  {spelled ? (
92
96
  <Button
93
97
  label={detail}
94
- title={`${detail}. ${tf("Upgrade to Pro ({key}, then {command})", { key: commandBarKey, command: "UPGRADE" })}`}
98
+ title={`${reason} ${tf("Upgrade to Pro ({key}, then {command})", { key: commandBarKey, command: "UPGRADE" })}`}
95
99
  variant="plain"
96
100
  compact
97
101
  stopPropagation
98
- onPress={openUpgrade}
102
+ onPress={upgrade}
99
103
  >
100
104
  <Box flexDirection="row" alignItems="center" gap={1}>
101
105
  {mark}
@@ -2,7 +2,7 @@ import { MISSING_VALUE } from "../../../utils/format";
2
2
  import type { CpiRow } from "../../../api-client/cpi";
3
3
  import type { HeadlessPaneDefinition } from "../../../types/plugin";
4
4
  import { fetchCpiBoard } from "./client";
5
- import { cpiHeaderLine, cpiMonth, cpiRowOption, cpiRows } from "./model";
5
+ import { cpiHeaderLine, cpiHeadlineYearGapLine, cpiMonth, cpiRowOption, cpiRows, cpiYearGapLine } from "./model";
6
6
 
7
7
  /** Two decimals; a value that rounds to zero reads 0.00, never -0.00. */
8
8
  const percent = (value: unknown) => typeof value === "number" ? (Number(value.toFixed(2)) === 0 ? "0.00" : value.toFixed(2)) : MISSING_VALUE;
@@ -29,6 +29,8 @@ const SUMMARY_COLUMNS = [
29
29
  { key: "contributionYear", header: "Y/Y pts", align: "right" as const, format: percent },
30
30
  ];
31
31
 
32
+ const notesOf = (note: string | null) => note ? { notes: [note] } : {};
33
+
32
34
  /** The selected row's months against the headline's year over year: the chart as a table. */
33
35
  function historyRows(row: CpiRow, headline: CpiRow | null) {
34
36
  const headlineYear = new Map((headline?.history ?? []).map(([month, , yoy]) => [month, yoy]));
@@ -73,6 +75,8 @@ export const cpiHeadless: HeadlessPaneDefinition<"bundle"> = {
73
75
  rows: historyRows(row, headline) },
74
76
  ],
75
77
  errors: data.gaps,
78
+ // Why the month's y/y is empty (no October 2025 index), and the latest the row has.
79
+ ...notesOf(cpiYearGapLine(data, row)),
76
80
  freshness,
77
81
  metadata: { ...metadata, rows: [row] },
78
82
  };
@@ -80,6 +84,7 @@ export const cpiHeadless: HeadlessPaneDefinition<"bundle"> = {
80
84
  return {
81
85
  sections: [{ title: header, columns: SUMMARY_COLUMNS, rows: cpiRows(data).map((row) => reportRow(row)) }],
82
86
  errors: data.gaps,
87
+ ...notesOf(cpiHeadlineYearGapLine(data)),
83
88
  freshness,
84
89
  metadata,
85
90
  };
@@ -3,6 +3,7 @@ import type { CpiBoardPayload, CpiReleaseStatus, CpiRow } from "../../../api-cli
3
3
  import type { ChartStripSpec } from "../../../components/chart-table/header";
4
4
  import { staticSeries } from "../../../components/chart/static/series";
5
5
  import type { ResolvedSeries } from "../../../time-series/types";
6
+ import { cpiYearGapNote } from "../shared/cpi-year-gap";
6
7
 
7
8
  /**
8
9
  * The rows Gloom Cloud serves, by the ids its board uses, so `CPI shelter`
@@ -191,6 +192,22 @@ export function cpiChartSeries(row: CpiRow, headline: CpiRow | null, colors: Cpi
191
192
  return series.filter((entry) => entry.points.length > 0);
192
193
  }
193
194
 
195
+ /**
196
+ * Why a row's year-over-year change is empty for the release's month, with the
197
+ * latest month it has one for (`cpiYearGapNote`): "BLS published no October
198
+ * 2025 index, so no October 2026 y/y; All items 3.7% in September 2026." Null
199
+ * when the row has its change, or misses it for another reason.
200
+ */
201
+ export function cpiYearGapLine(payload: Pick<CpiBoardPayload, "release">, row: CpiRow | null | undefined): string | null {
202
+ if (!payload.release.period || !row || row.yoy != null) return null;
203
+ const latest = row.history.findLast(([period, , yoy]) => yoy != null && period < payload.release.period!);
204
+ return cpiYearGapNote(payload.release.period, row.label, latest ? { period: latest[0], value: latest[2]! } : null);
205
+ }
206
+
207
+ /** The headline's gap line (`cpiYearGapLine`), which the table closes on. */
208
+ export const cpiHeadlineYearGapLine = (payload: CpiBoardPayload) =>
209
+ cpiYearGapLine(payload, payload.rows.find((row) => row.code === "SA0"));
210
+
194
211
  /** One row for a short pane: the row's year-over-year line and its latest value. */
195
212
  export function cpiChartStrip(row: CpiRow, color: string): ChartStripSpec | null {
196
213
  const values = row.history.flatMap(([, , yoy]) => (yoy == null ? [] : [yoy]));
@@ -29,6 +29,7 @@ import {
29
29
  cpiChartSeries,
30
30
  cpiChartStrip,
31
31
  cpiHeaderLine,
32
+ cpiHeadlineYearGapLine,
32
33
  cpiMonthDate,
33
34
  cpiRowLabel,
34
35
  cpiRows,
@@ -146,7 +147,8 @@ export function CpiPane({ width, height, focused }: PaneProps) {
146
147
  useAutoRefresh(resource.updatedAt, resource.load);
147
148
  usePaneRefreshKey(() => resource.reload(), { focused });
148
149
  usePaneNoticeFooter({ registrationId: "cpi:notices", focused,
149
- notices: [...(data?.gaps ?? []), ...(resource.data?.refreshError ? [resource.data.refreshError] : [])] });
150
+ notices: [...(data?.gaps ?? []), ...(data ? [cpiHeadlineYearGapLine(data)].filter((line): line is string => !!line) : []),
151
+ ...(resource.data?.refreshError ? [resource.data.refreshError] : [])] });
150
152
  usePaneStatusFooter({ registrationId: "cpi", loading: resource.loading, error: notAvailable ? null : resource.error,
151
153
  stale: !!data && resource.data?.stale });
152
154
  return (
@@ -72,10 +72,15 @@ const validPeg = (peg: CryptoMarketAsset["peg"]) =>
72
72
  && (peg.price === null || (isFiniteNumber(peg.price) && peg.price > 0))
73
73
  && nullableInstant(peg.asOf);
74
74
 
75
+ const venueNames = (value: unknown) => value === undefined
76
+ || Array.isArray(value) && value.every((name) => typeof name === "string" && name.length > 0 && name.length <= 24);
77
+
75
78
  const validRange = (range: CryptoMarketAsset["range24h"]) =>
76
79
  !!range
77
80
  && [range.low, range.high].every((value) => isFiniteNumber(value) && value > 0)
78
- && [range.lowAt, range.highAt, range.start, range.end].every(instant);
81
+ && [range.lowAt, range.highAt, range.start, range.end].every(instant)
82
+ && [range.lowVenues, range.highVenues, range.venuesChecked].every(venueNames)
83
+ && (range.venuesPending === undefined || typeof range.venuesPending === "boolean");
79
84
 
80
85
  /** A malformed peg or 24h range is dropped from its coin alone; the coin and the rest of the board stay. */
81
86
  function withValidStablecoinFields(asset: CryptoMarketAsset): CryptoMarketAsset {