gloomberb 0.20.5 → 0.20.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (185) hide show
  1. package/README.md +1 -1
  2. package/README.zh-CN.md +1 -1
  3. package/package.json +2 -1
  4. package/src/api-client/data.ts +10 -2
  5. package/src/api-client/fund-facts.ts +20 -4
  6. package/src/api-client/hk-tenders.ts +59 -0
  7. package/src/api-client/index.ts +1 -0
  8. package/src/api-client/socket.ts +4 -4
  9. package/src/api-client/types/econ.ts +20 -2
  10. package/src/app.tsx +18 -13
  11. package/src/architecture/floating-promise-allowlist.json +313 -0
  12. package/src/architecture/shortcut-labels-allowlist.json +1 -0
  13. package/src/cli/commands/market.ts +197 -57
  14. package/src/cli/commands/news-search.ts +22 -7
  15. package/src/cli/commands/overview.ts +12 -6
  16. package/src/cli/commands/search.ts +19 -3
  17. package/src/cli/commands/ticker.ts +3 -1
  18. package/src/cli/desktop-pane-shot.ts +61 -0
  19. package/src/cli/early-command.ts +2 -0
  20. package/src/cli/errors.ts +10 -1
  21. package/src/cli/fx-forward.ts +76 -12
  22. package/src/cli/fx-pair.ts +1 -1
  23. package/src/cli/fx-quote-rate.ts +23 -0
  24. package/src/cli/help.ts +1 -0
  25. package/src/cli/index-roots.ts +5 -4
  26. package/src/cli/index.ts +40 -3
  27. package/src/cli/known-gaps.ts +11 -8
  28. package/src/cli/listing-arg.ts +6 -4
  29. package/src/cli/options.ts +52 -3
  30. package/src/cli/output-file.ts +5 -3
  31. package/src/cli/pane-functions/catalog.ts +15 -0
  32. package/src/cli/pane-functions/dom.ts +4 -4
  33. package/src/cli/pane-functions/freshness.ts +38 -5
  34. package/src/cli/pane-functions/function-help.ts +4 -4
  35. package/src/cli/pane-functions/headless.ts +9 -4
  36. package/src/cli/pane-functions/index.ts +6 -4
  37. package/src/cli/pane-functions/resolver.ts +2 -2
  38. package/src/cli/pane-functions/screenshot-assessment.ts +16 -4
  39. package/src/cli/quote-answer.ts +57 -1
  40. package/src/cli/result.ts +38 -2
  41. package/src/cli/spreadsheet-hint.ts +7 -3
  42. package/src/cli/treasury-yields.ts +5 -3
  43. package/src/components/chart/composite/legend.tsx +40 -2
  44. package/src/components/command-bar/workflow/tickers.ts +2 -2
  45. package/src/components/data-table/view.tsx +9 -2
  46. package/src/components/ui/data-table/opentui/index.tsx +11 -4
  47. package/src/components/ui/data-table/opentui/model.ts +8 -6
  48. package/src/components/ui/data-table/types.ts +6 -1
  49. package/src/components/ui/table-layout.ts +38 -1
  50. package/src/docs/snapshot.json +58 -19
  51. package/src/i18n/es.ts +2 -0
  52. package/src/i18n/ja.ts +2 -0
  53. package/src/i18n/ko.ts +2 -0
  54. package/src/i18n/zh-cn.ts +2 -0
  55. package/src/i18n/zh-tw.ts +2 -0
  56. package/src/market-data/market/change-basis.ts +57 -12
  57. package/src/market-data/market/dated-previous-close.ts +184 -10
  58. package/src/market-data/market/freshness.ts +18 -6
  59. package/src/market-data/market/status.ts +9 -1
  60. package/src/market-data/published-nse-sessions.ts +16 -1
  61. package/src/market-data/quotes/contributions.ts +2 -0
  62. package/src/market-data/quotes/freshness.ts +15 -0
  63. package/src/market-data/quotes/listing-enterprise-value.ts +50 -0
  64. package/src/plugins/builtin/alerts/alert-engine.ts +15 -0
  65. package/src/plugins/builtin/alerts/cli.ts +22 -9
  66. package/src/plugins/builtin/alerts/headless.ts +1 -1
  67. package/src/plugins/builtin/alerts/index.tsx +5 -1
  68. package/src/plugins/builtin/alerts/metric-command.ts +1 -1
  69. package/src/plugins/builtin/alerts/metric-data.ts +15 -2
  70. package/src/plugins/builtin/backtest/headless.ts +1 -1
  71. package/src/plugins/builtin/cds/model.ts +0 -6
  72. package/src/plugins/builtin/chart-composer/formula.ts +16 -3
  73. package/src/plugins/builtin/chart-composer/headless-schema.ts +2 -0
  74. package/src/plugins/builtin/chart-composer/headless.ts +2 -1
  75. package/src/plugins/builtin/chart-composer/presets.ts +1 -0
  76. package/src/plugins/builtin/cloud/askg/pane.tsx +55 -13
  77. package/src/plugins/builtin/credit-boards/cdx-pane.tsx +20 -7
  78. package/src/plugins/builtin/credit-boards/client.ts +8 -0
  79. package/src/plugins/builtin/credit-boards/headless.ts +4 -1
  80. package/src/plugins/builtin/credit-boards/model.ts +58 -4
  81. package/src/plugins/builtin/credit-boards/series.ts +63 -6
  82. package/src/plugins/builtin/credit-boards/sovr-pane.tsx +3 -2
  83. package/src/plugins/builtin/credit-conditions/headless.ts +24 -6
  84. package/src/plugins/builtin/credit-conditions/index.tsx +1 -1
  85. package/src/plugins/builtin/credit-conditions/model.ts +12 -6
  86. package/src/plugins/builtin/credit-conditions/series.ts +2 -1
  87. package/src/plugins/builtin/econ/calendar-model.ts +41 -7
  88. package/src/plugins/builtin/econ/calendar-source.ts +7 -1
  89. package/src/plugins/builtin/econ/index.tsx +41 -8
  90. package/src/plugins/builtin/econ/types.ts +3 -0
  91. package/src/plugins/builtin/fixed-income/index.tsx +2 -0
  92. package/src/plugins/builtin/fx-matrix/index.tsx +44 -14
  93. package/src/plugins/builtin/help/keybindings-editor.tsx +6 -2
  94. package/src/plugins/builtin/holders/fund-holders.ts +22 -1
  95. package/src/plugins/builtin/holders/headless.ts +5 -4
  96. package/src/plugins/builtin/holders/pane.tsx +7 -3
  97. package/src/plugins/builtin/holders/report-header.ts +23 -0
  98. package/src/plugins/builtin/members/client.ts +1 -1
  99. package/src/plugins/builtin/members/headless.ts +2 -0
  100. package/src/plugins/builtin/members/model.ts +10 -8
  101. package/src/plugins/builtin/members/pane.tsx +4 -1
  102. package/src/plugins/builtin/portfolio-list/cli/portfolio-command.ts +5 -2
  103. package/src/plugins/builtin/portfolio-list/cli/render.ts +86 -26
  104. package/src/plugins/builtin/portfolio-list/cli/watchlist-command.ts +5 -1
  105. package/src/plugins/builtin/portfolio-list/headless.ts +2 -1
  106. package/src/plugins/builtin/portfolio-list/income.ts +46 -22
  107. package/src/plugins/builtin/portfolio-list/pane/data.ts +16 -6
  108. package/src/plugins/builtin/portfolio-list/pane/index.tsx +5 -4
  109. package/src/plugins/builtin/portfolio-list/use-throttled-ticker-order.ts +40 -3
  110. package/src/plugins/builtin/research/headless-schema.ts +4 -3
  111. package/src/plugins/builtin/research/relative-valuation-columns.ts +145 -47
  112. package/src/plugins/builtin/research/relative-valuation-currency.ts +31 -0
  113. package/src/plugins/builtin/research/relative-valuation-headless.ts +25 -8
  114. package/src/plugins/builtin/research/relative-valuation-model.ts +40 -9
  115. package/src/plugins/builtin/research/relative-valuation-pane.tsx +3 -2
  116. package/src/plugins/builtin/research/relative-valuation-peers.ts +2 -2
  117. package/src/plugins/builtin/sec/fund-facts.ts +25 -5
  118. package/src/plugins/builtin/shared/report-freshness.ts +15 -6
  119. package/src/plugins/builtin/supply-chain/model.ts +18 -6
  120. package/src/plugins/builtin/thirteenf/api.ts +47 -4
  121. package/src/plugins/builtin/ticker-detail/data-panes/historical-prices.tsx +8 -7
  122. package/src/plugins/builtin/ticker-detail/data-panes/history-bars.ts +8 -5
  123. package/src/plugins/builtin/ticker-detail/financials/model.ts +6 -2
  124. package/src/plugins/builtin/ticker-detail/financials/tab.tsx +1 -1
  125. package/src/plugins/builtin/ticker-detail/headless.ts +6 -4
  126. package/src/plugins/builtin/treasury-auctions/cache.ts +36 -2
  127. package/src/plugins/builtin/treasury-auctions/headless.ts +42 -4
  128. package/src/plugins/builtin/treasury-auctions/hk-headless.ts +126 -0
  129. package/src/plugins/builtin/treasury-auctions/hk-view.tsx +347 -0
  130. package/src/plugins/builtin/treasury-auctions/hk.ts +363 -0
  131. package/src/plugins/builtin/treasury-auctions/index.tsx +14 -1
  132. package/src/plugins/builtin/treasury-auctions/model.ts +16 -8
  133. package/src/plugins/builtin/treasury-auctions/pane.tsx +45 -21
  134. package/src/portfolio/collection-name.ts +22 -0
  135. package/src/portfolio/column-values.ts +3 -0
  136. package/src/portfolio/valuation-basis.ts +23 -1
  137. package/src/renderers/dom/data-table/frozen-column.ts +3 -1
  138. package/src/renderers/dom/data-table/index.tsx +27 -9
  139. package/src/renderers/dom/data-table/row.tsx +2 -0
  140. package/src/renderers/electrobun/bun/desktop/backend.ts +27 -24
  141. package/src/renderers/electrobun/bun/desktop/detached-windows.ts +3 -3
  142. package/src/renderers/electrobun/bun/desktop/snapshot-commit.ts +77 -0
  143. package/src/renderers/electrobun/shared/protocol.ts +4 -0
  144. package/src/renderers/electrobun/view/backend-rpc.ts +3 -0
  145. package/src/renderers/electrobun/view/desktop/window/bridge.ts +3 -0
  146. package/src/sources/gloomberb-cloud/normalizers.ts +9 -5
  147. package/src/sources/provider-router/cache.ts +3 -1
  148. package/src/state/hooks/quote-streaming.ts +14 -6
  149. package/src/sync/controller.ts +17 -2
  150. package/src/sync/other-window-tabs.ts +32 -1
  151. package/src/sync/react.ts +4 -4
  152. package/src/tickers/instrument-kind.ts +22 -1
  153. package/src/tickers/search/index.ts +5 -0
  154. package/src/tickers/terminal-codes.ts +17 -5
  155. package/src/time-series/bar-spacing.ts +33 -0
  156. package/src/time-series/base-series.ts +21 -3
  157. package/src/time-series/chart-bounds.ts +31 -0
  158. package/src/time-series/field-catalog.ts +17 -0
  159. package/src/time-series/fundamentals/current-valuation.ts +244 -0
  160. package/src/time-series/fundamentals/historical-valuation.ts +99 -0
  161. package/src/time-series/fundamentals/metric-ids.ts +61 -0
  162. package/src/time-series/fundamentals/period-points.ts +104 -0
  163. package/src/time-series/fundamentals/quarterly-ttm.ts +220 -0
  164. package/src/time-series/fundamentals/series.ts +164 -0
  165. package/src/time-series/fundamentals/source-statements.ts +177 -0
  166. package/src/time-series/fundamentals/statement-fields.ts +154 -0
  167. package/src/time-series/fundamentals/statement-merge.ts +124 -0
  168. package/src/time-series/fundamentals/statement.ts +114 -0
  169. package/src/time-series/fundamentals/valuation-multiples.ts +50 -0
  170. package/src/time-series/fundamentals.ts +18 -1275
  171. package/src/time-series/ice-credit.ts +32 -6
  172. package/src/time-series/resolve.ts +9 -5
  173. package/src/time-series/session-bar.ts +78 -9
  174. package/src/time-series/studies/formula.ts +53 -10
  175. package/src/time-series/studies/pair.ts +18 -7
  176. package/src/time-series/studies/units.ts +49 -2
  177. package/src/time-series/types.ts +12 -0
  178. package/src/types/desktop-window.ts +2 -0
  179. package/src/types/financials.ts +15 -0
  180. package/src/types/headless.ts +8 -0
  181. package/src/utils/cli-output.ts +6 -3
  182. package/src/utils/debug-log.ts +29 -0
  183. package/src/utils/ebitda.ts +128 -0
  184. package/src/utils/format.ts +1 -1
  185. package/src/utils/shell-word.ts +13 -0
@@ -1,3 +1,4 @@
1
+ import { isYieldIndexSymbol } from "../../tickers/index-roots";
1
2
  import { classifyInstrumentType, kindFromListingSyntax } from "../../tickers/instrument-kind";
2
3
  import { isPerpetualExchange } from "../../tickers/perpetual-listing";
3
4
  import type { Quote } from "../../types/financials";
@@ -9,7 +10,7 @@ import { zonedDateKey } from "../../utils/zoned-date-time";
9
10
  import { futuresChangeBasis, futuresQuoteMonth, futuresSettleText, isFuturesInstrument } from "../futures-contract";
10
11
  import { quoteTradingDay } from "../quotes/day-range";
11
12
  import { splitRatioText } from "../quotes/session-split";
12
- import { hasPublishedSessionCalendar, previousPublishedSession } from "./freshness";
13
+ import { hasPublishedSessionCalendar, isVenueTradingDay, latestRegularSessionOpen, previousPublishedSession, sessionCalendarTimeZone } from "./freshness";
13
14
  import { getActiveQuoteDisplay, getRegularSessionDisplay, regularSessionDisplayDate } from "./status";
14
15
 
15
16
  const DAY_MS = 86_400_000;
@@ -92,8 +93,7 @@ const INDEX_CALENDAR_VENUES: Readonly<Record<string, string>> = {
92
93
  /** The venue whose published calendar dates the quote's sessions, and whose zone dates its daily bars. */
93
94
  export function calendarVenue(quote: Quote): string {
94
95
  const venue = quoteVenue(quote);
95
- const index = classifyInstrumentType(quote.instrumentType) === "index" || kindFromListingSyntax(quote.symbol) === "index";
96
- return (index && INDEX_CALENDAR_VENUES[venue]) || venue;
96
+ return (isIndexQuote(quote) && INDEX_CALENDAR_VENUES[venue]) || venue;
97
97
  }
98
98
 
99
99
  function isCurrencyPair(quote: Quote): boolean {
@@ -105,12 +105,48 @@ function isCurrencyPair(quote: Quote): boolean {
105
105
  * The trading day a quote describes (quoteTradingDay); for a currency pair,
106
106
  * whose venue has no clock, the FX trading day of its print, which turns at
107
107
  * 17:00 New York, so every pair on a board is dated alike. Null for a pair's
108
- * print made while FX is shut, which belongs to no trading day.
108
+ * print made while FX is shut, which belongs to no trading day. An index
109
+ * whose quote names no session is dated by its home venue (indexPrintSession).
109
110
  */
110
111
  function tradingDayOf(quote: Quote): string | null {
111
112
  const day = quoteTradingDay(quote);
112
- if (day || !isCurrencyPair(quote) || !Number.isFinite(quote.lastUpdated) || quote.lastUpdated <= 0) return day;
113
- return fxPrintTradingDay(quote.lastUpdated);
113
+ if (day || !Number.isFinite(quote.lastUpdated) || quote.lastUpdated <= 0) return day;
114
+ if (isIndexQuote(quote)) return indexPrintSession(quote);
115
+ return isCurrencyPair(quote) ? fxPrintTradingDay(quote.lastUpdated) : null;
116
+ }
117
+
118
+ function isIndexQuote(quote: Quote): boolean {
119
+ return classifyInstrumentType(quote.instrumentType) === "index" || kindFromListingSyntax(quote.symbol) === "index";
120
+ }
121
+
122
+ /**
123
+ * One of Cboe's Treasury yield indices (^IRX, ^FVX, ^TNX, ^TYX): computed on
124
+ * the bond market's days, whose holidays (Veterans Day, Columbus Day) the
125
+ * equity calendar Cboe's venue follows does not have.
126
+ */
127
+ function isCboeYieldIndex(quote: Quote): boolean {
128
+ return isIndexQuote(quote) && isYieldIndexSymbol(quote.symbol);
129
+ }
130
+
131
+ /**
132
+ * The session of the venue whose calendar an index follows (calendarVenue)
133
+ * that its last print sits in: the print's date in that venue's zone, when
134
+ * its published calendar has a session that day and the print came after it
135
+ * opened. The S&P 500's closing print at 16:37 New York on Fri 6 Nov 2026 is
136
+ * Friday's, so its move is from Thursday's close. A print before the day's
137
+ * open, on a day the calendar has no session for, or on a venue with no
138
+ * published calendar, names none; nor does a Cboe index's, whose days are
139
+ * Cboe's own (a yield index skips the bond market's holidays).
140
+ */
141
+ function indexPrintSession(quote: Quote): string | null {
142
+ const venue = calendarVenue(quote);
143
+ if (venue === "CBOE") return null;
144
+ const zone = sessionCalendarTimeZone(venue) ?? quote.indexSession?.timeZone;
145
+ if (!zone) return null;
146
+ const date = zonedDateKey(quote.lastUpdated, zone);
147
+ if (!date || !hasPublishedSessionCalendar(venue, date) || !isVenueTradingDay(venue, date)) return null;
148
+ const open = latestRegularSessionOpen(venue, quote.lastUpdated);
149
+ return open != null && zonedDateKey(open, zone) === date ? date : null;
114
150
  }
115
151
 
116
152
  /** A coin on the spot crypto venue: its day is the UTC day. */
@@ -139,31 +175,40 @@ function previousIndexSession(quote: Quote, date: string): string | null {
139
175
  * calendar, with the closures in between (an index's, the venue whose days it
140
176
  * follows); otherwise for an index from its own sessions; for a currency pair
141
177
  * the weekday before; for any other listing the day its own daily closes date
142
- * its previous close to (`previousCloseDate`, PreviousCloseDates). Null
143
- * when nothing dates it.
178
+ * its previous close to (`previousCloseDate`, PreviousCloseDates). A thin
179
+ * listing's previous trade before the calendar's session is its own day, and
180
+ * one whose closes cannot name it is left undated. A Cboe yield index is
181
+ * dated by its own closes alone. Null when nothing dates it.
144
182
  */
145
183
  function previousSession(quote: Quote, sessionDate: string): DatedChangeBasis | null {
184
+ if (quote.previousCloseUndated) return null;
146
185
  const venue = calendarVenue(quote);
186
+ const dated = quote.previousCloseDate && ISO_DATE.test(quote.previousCloseDate) && quote.previousCloseDate < sessionDate
187
+ ? quote.previousCloseDate : null;
188
+ // A yield index's days are the bond market's: only its own daily closes date it, never its venue's equity calendar.
189
+ if (isCboeYieldIndex(quote)) return dated ? { kind: "close", date: dated } : null;
147
190
  const published = previousPublishedSession(venue, sessionDate);
191
+ // A listing that did not trade in the calendar's session moves from its previous trade, an earlier day.
192
+ if (published && dated && dated < published.date) return { kind: "close", date: dated, venue };
148
193
  if (published) return { kind: "close", date: published.date, venue, closed: published.closed };
149
194
  const index = previousIndexSession(quote, sessionDate);
150
195
  if (index) return { kind: "close", date: index };
151
196
  if (isCurrencyPair(quote)) return { kind: "close", date: weekdayBefore(sessionDate) };
152
- const dated = quote.previousCloseDate;
153
- if (dated && ISO_DATE.test(dated) && dated < sessionDate) return { kind: "close", date: dated };
154
- return null;
197
+ return dated ? { kind: "close", date: dated } : null;
155
198
  }
156
199
 
157
200
  /**
158
201
  * Whether something other than the listing's own daily closes dates every
159
202
  * move of the quote: a future's terms, a coin's UTC day, a perpetual's 24
160
203
  * hours, a currency pair's weekday, or its venue's calendar for the year of
161
- * `now`. A few lookups, for a caller that runs on every tick before it asks
204
+ * `now`; never a Cboe yield index's, which its own closes date. A few
205
+ * lookups, for a caller that runs on every tick before it asks
162
206
  * quoteChangeBasis.
163
207
  */
164
208
  export function isChangeBasisDatedWithoutCloses(quote: Quote, now = Date.now()): boolean {
165
209
  if (isSpotCoin(quote) || isCurrencyPair(quote) || isFuturesInstrument(quote.symbol, quote.instrumentType)) return true;
166
210
  if (isPerpetualExchange(quote.listingExchangeName || quote.exchangeName)) return true;
211
+ if (isCboeYieldIndex(quote)) return false;
167
212
  return hasPublishedSessionCalendar(calendarVenue(quote), new Date(now).toISOString().slice(0, 10));
168
213
  }
169
214
 
@@ -6,6 +6,7 @@ import { logFailure } from "../../utils/log-failure";
6
6
  import { dailyBarDate } from "../../utils/price-history";
7
7
  import { classifyInstrumentType } from "../../tickers/instrument-kind";
8
8
  import { calendarVenue, changeBasisSessionDate, isChangeBasisDatedWithoutCloses, quoteChangeBasis } from "./change-basis";
9
+ import { latestRegularSessionClose, latestRegularSessionOpen } from "./freshness";
9
10
  import { cleanFloat32Price } from "../../utils/float32-price";
10
11
 
11
12
  /** History closes come as float32 (30.93000030517578) where the quote says 30.93: one close. */
@@ -50,7 +51,7 @@ export interface DatedCloseListing {
50
51
 
51
52
  /** A listing's recent daily closes (a month is enough), with the flags that say a bar had not closed yet. */
52
53
  export type ReadDailyCloses = (listing: DatedCloseListing) => Promise<readonly DailyClose[]>;
53
- type DailyClose = Pick<PricePoint, "date" | "close" | "partial" | "unsettled">;
54
+ type DailyClose = Pick<PricePoint, "date" | "close" | "partial" | "unsettled"> & Partial<Pick<PricePoint, "open" | "high" | "low">> & { volume?: number };
54
55
 
55
56
  export interface PreviousCloseDatesOptions {
56
57
  /** Called with the latest copy of a quote, dated, when a read lands that names its day. */
@@ -62,7 +63,7 @@ export interface PreviousCloseDatesOptions {
62
63
  indexWaitMs?: number;
63
64
  }
64
65
 
65
- type ReadingFields = Pick<Reading, "date" | "close" | "sessionClose" | "awaitsSessionClose">;
66
+ type ReadingFields = Pick<Reading, "date" | "close" | "sessionClose" | "awaitsSessionClose" | "untraded" | "session">;
66
67
 
67
68
  interface Reading {
68
69
  date: string | null;
@@ -75,9 +76,33 @@ interface Reading {
75
76
  sessionClose?: number;
76
77
  /** A closed quote on such a venue whose session's bar was not in the history yet: read again until it lands. */
77
78
  awaitsSessionClose?: boolean;
79
+ /**
80
+ * A thin listing that did not trade in the session its venue's calendar
81
+ * puts before the move's, whose earlier closes do not hold its previous
82
+ * close either (ThinPreviousTrade): no day can be named for it.
83
+ */
84
+ untraded?: boolean;
85
+ /**
86
+ * A quote its source left behind its listing's daily bars (laggingSession):
87
+ * the later session whose close is its price, that bar's range, and the
88
+ * day the listing last traded when nothing traded in it.
89
+ */
90
+ session?: LaggingSession;
78
91
  at: number;
79
92
  }
80
93
 
94
+ interface LaggingSession {
95
+ date: string;
96
+ open?: number;
97
+ high?: number;
98
+ low?: number;
99
+ volume?: number;
100
+ nominal?: { lastTraded: string | null };
101
+ }
102
+
103
+ /** A daily bar that shows a trade: some volume. One with none, or none reported, proves nothing traded. */
104
+ const tradedBar = (point: Pick<DailyClose, "volume">): boolean => typeof point.volume === "number" && point.volume > 0;
105
+
81
106
  /**
82
107
  * Venues whose quoted previous close is the exchange's official close, not
83
108
  * the last trade its daily bar closes on, with how far apart the two can be:
@@ -92,7 +117,16 @@ const OFFICIAL_PREVIOUS_CLOSE_VENUES: ReadonlyMap<string, number> = new Map([["B
92
117
  * the daily bar is the official close, as history and the portfolio read it:
93
118
  * B3's PETR4 quoted R$45.36 on Fri 6 Nov 2026 beside a R$45.30 close.
94
119
  */
95
- const DAILY_BAR_CLOSE_VENUES: ReadonlySet<string> = new Set(["B3"]);
120
+ export const DAILY_BAR_CLOSE_VENUES: ReadonlySet<string> = new Set(["B3"]);
121
+
122
+ /**
123
+ * A session volume below which a share or fund on a venue whose calendar
124
+ * dates its moves may not have traded in the session before: its daily closes
125
+ * are read to find its previous trade (thinPreviousTrade). B95 on SGX traded
126
+ * 3,661 units on Fri 6 Nov 2026 and last before that on 22 Oct, while the
127
+ * calendar put its move "vs Thu 5 Nov".
128
+ */
129
+ const THIN_SESSION_VOLUME = 50_000;
96
130
 
97
131
  /** A close this far from the quote's price is another unit's or another listing's, never the session's. */
98
132
  const MAX_SESSION_CLOSE_MOVE = 0.25;
@@ -117,14 +151,65 @@ function sameClose(left: number, right: number): boolean {
117
151
  */
118
152
  function readingKey(quote: Quote | null | undefined, listing: DatedCloseListing, now: number): string | null {
119
153
  if (!quote || classifyInstrumentType(quote.instrumentType) === "option") return null;
154
+ // A stale share or fund may stand at a price its venue set in a later session than its source dated (laggingSession).
155
+ if (laggingQuote(quote, now)) return `${datedCloseListingKey(listing)}|${changeBasisSessionDate(quote)}|${quote.price}|${quote.previousClose}|lagging`;
120
156
  // An index's dated close is checked against its daily close of that day as well (indexCloseOn), but for a Cboe
121
157
  // index's, which Gloom Cloud checks against Cboe's own closes.
122
158
  if (datedIndexClose(quote)) return calendarVenue(quote) === "CBOE" ? null : datedReadingKey(quote, listing);
123
- if (isChangeBasisDatedWithoutCloses(quote, now)) return null;
159
+ if (isChangeBasisDatedWithoutCloses(quote, now)) return thinListingCalendarDate(quote) ? `${datedReadingKey(quote, listing)}|thin` : null;
124
160
  if (quoteChangeBasis(quote)?.kind !== "previous close") return null;
125
161
  return datedReadingKey(quote, listing);
126
162
  }
127
163
 
164
+ /**
165
+ * The session a venue's calendar puts before a thin listing's move, for a
166
+ * share or fund whose completed session traded under THIN_SESSION_VOLUME:
167
+ * such a listing may not have traded in it, which only its daily closes say.
168
+ * Null for any other quote, so a board of busy listings reads no history.
169
+ */
170
+ function thinListingCalendarDate(quote: Quote): string | null {
171
+ const kind = classifyInstrumentType(quote.instrumentType);
172
+ if (kind !== "equity" && kind !== "fund") return null;
173
+ if (quote.marketState === "REGULAR" || quote.previousCloseDate) return null;
174
+ if (!(typeof quote.volume === "number" && quote.volume >= 0 && quote.volume < THIN_SESSION_VOLUME)) return null;
175
+ const basis = quoteChangeBasis(quote);
176
+ return basis?.kind === "close" && basis.venue ? basis.date : null;
177
+ }
178
+
179
+ /**
180
+ * A share or fund whose source marked its quote stale: its venue may have set
181
+ * nominal prices in the sessions since (HKEX does for a counter nothing traded
182
+ * on), which its daily bars carry while the quote keeps the day of its last
183
+ * print. 9042.HK, the USD counter of a bitcoin fund, read on Sun 8 Nov 2026:
184
+ * Fri 6 Nov's nominal 1.172 against Thu 5 Nov's 1.244, dated Wed 4 Nov by its
185
+ * last print. While its venue's session is in progress (sessionInProgressOpen),
186
+ * only one with no print since it opened, whatever state the quote names: a
187
+ * trade today is the quote's own session. Otherwise not one its source still
188
+ * calls open.
189
+ */
190
+ function laggingQuote(quote: Quote, now: number): boolean {
191
+ const kind = classifyInstrumentType(quote.instrumentType);
192
+ if ((kind !== "equity" && kind !== "fund") || quote.stale !== true || quote.delisting) return false;
193
+ if (!(quote.price > 0 && typeof quote.previousClose === "number" && quote.previousClose > 0 && changeBasisSessionDate(quote))) return false;
194
+ const open = sessionInProgressOpen(quote, now);
195
+ if (open != null) return Number.isFinite(quote.lastUpdated) && quote.lastUpdated < open;
196
+ return quote.marketState !== "REGULAR";
197
+ }
198
+
199
+ /**
200
+ * When the regular session in progress at `now` on the quote's venue opened,
201
+ * its midday break included: HKEX's 12:00 to 13:00 is still the day's
202
+ * session, whatever state the source names then. Null between sessions and on
203
+ * a venue whose hours are unknown.
204
+ */
205
+ function sessionInProgressOpen(quote: Quote, now: number): number | null {
206
+ const venue = calendarVenue(quote);
207
+ const open = latestRegularSessionOpen(venue, now);
208
+ if (open == null) return null;
209
+ const close = latestRegularSessionClose(venue, now);
210
+ return !close || close.close < open ? open : null;
211
+ }
212
+
128
213
  function datedReadingKey(quote: Quote, listing: DatedCloseListing): string | null {
129
214
  const previousClose = quote.previousClose;
130
215
  const sessionDate = changeBasisSessionDate(quote);
@@ -141,15 +226,56 @@ function datedReadingKey(quote: Quote, listing: DatedCloseListing): string | nul
141
226
  * future's session awaiting settlement, is no close: a copy kept from the
142
227
  * session before (a US holiday) must never stand for that session's close.
143
228
  */
144
- function closedBars(points: readonly DailyClose[], quote: Quote): Array<{ date: string; close: number }> {
229
+ function closedBars(points: readonly DailyClose[], quote: Quote): Array<{ date: string; close: number; point: DailyClose }> {
145
230
  const venue = calendarVenue(quote);
146
231
  return points.flatMap((point) => {
147
232
  const time = new Date(point.date).getTime();
148
233
  if (point.partial || point.unsettled || !Number.isFinite(time) || !Number.isFinite(point.close)) return [];
149
- return [{ date: dailyBarDate(time, venue), close: point.close }];
234
+ return [{ date: dailyBarDate(time, venue), close: point.close, point }];
150
235
  });
151
236
  }
152
237
 
238
+ const positiveBarPrice = (value: number | undefined) => typeof value === "number" && Number.isFinite(value) && value > 0 ? cleanFloat32Price(value) : undefined;
239
+
240
+ /**
241
+ * The session a lagging quote's price is from (laggingQuote): the listing's
242
+ * latest daily bar, when it is later than the session the quote is dated to,
243
+ * its close is the quote's price and the bar before it closed at the quote's
244
+ * previous close; while the venue's session is in progress, the latest bar
245
+ * before today's. A bar that shows no trade (no volume, or none reported) is
246
+ * a nominal price: the reading then names the latest day the bars show a
247
+ * trade. Null when the bars do not say so, and the quote stands as its
248
+ * source dated it.
249
+ */
250
+ function laggingSession(points: readonly DailyClose[], quote: Quote, now: number): ReadingFields | null {
251
+ const quoted = changeBasisSessionDate(quote);
252
+ // While today's session is in progress, a bar of today's is not a completed session, whatever its source marks.
253
+ const sessionOpen = sessionInProgressOpen(quote, now);
254
+ const today = sessionOpen != null ? dailyBarDate(sessionOpen, calendarVenue(quote)) : null;
255
+ const bars = closedBars(points, quote)
256
+ .filter((bar) => !today || bar.date < today)
257
+ .sort((left, right) => left.date.localeCompare(right.date));
258
+ const last = bars.at(-1);
259
+ const before = bars.at(-2);
260
+ if (!quoted || !last || !before || last.date <= quoted) return null;
261
+ if (!sameClose(last.close, quote.price) || !sameClose(before.close, quote.previousClose!)) return null;
262
+ if (!tradedBar(last.point)) {
263
+ const lastTraded = bars.findLast((bar) => tradedBar(bar.point))?.date ?? null;
264
+ return { date: before.date, session: { date: last.date, ...last.point.volume === 0 ? { volume: 0 } : {}, nominal: { lastTraded } } };
265
+ }
266
+ const { open, high, low, volume } = last.point;
267
+ return {
268
+ date: before.date,
269
+ session: {
270
+ date: last.date,
271
+ ...positiveBarPrice(open) != null ? { open: positiveBarPrice(open) } : {},
272
+ ...positiveBarPrice(high) != null ? { high: positiveBarPrice(high) } : {},
273
+ ...positiveBarPrice(low) != null ? { low: positiveBarPrice(low) } : {},
274
+ ...typeof volume === "number" && Number.isFinite(volume) ? { volume } : {},
275
+ },
276
+ };
277
+ }
278
+
153
279
  /**
154
280
  * The day of the latest daily close before the move's session, when that
155
281
  * close is the quote's previous close; null otherwise, so a gap in the
@@ -222,9 +348,36 @@ function indexCloseOn(points: readonly DailyClose[], quote: Quote, date: string)
222
348
  return Math.abs(previousClose - close) <= close * SAME_INDEX_CLOSE_RELATIVE ? { date } : { date, close };
223
349
  }
224
350
 
225
- function readingOf(points: readonly DailyClose[], quote: Quote): ReadingFields {
351
+ /**
352
+ * A thin listing's previous trade, where it is earlier than the session its
353
+ * venue's calendar puts before the move's: the day of its latest daily close
354
+ * before the move's session that traded, when that close is its previous
355
+ * close. When it traded in the calendar's session the calendar stands
356
+ * (date null), and so it does when the calendar's session closed at the
357
+ * previous close with nothing traded: the venue's nominal price of that day
358
+ * (83042.HK's 8.315 on Thu 5 Nov 2026, its last trade on Wed 4 Nov at
359
+ * 8.095). When its closes hold none of these, the day is unknown (`untraded`).
360
+ */
361
+ function thinPreviousTrade(points: readonly DailyClose[], quote: Quote, calendarDate: string): ReadingFields {
362
+ const sessionDate = changeBasisSessionDate(quote)!;
363
+ const traded = new Set(points.filter((point) => point.volume == null || point.volume > 0).map((point) => point.date.valueOf()));
364
+ const before = closedBars(points.filter((point) => traded.has(point.date.valueOf())), quote)
365
+ .filter((point) => point.date < sessionDate)
366
+ .sort((left, right) => left.date.localeCompare(right.date))
367
+ .at(-1);
368
+ if (!before || before.date >= calendarDate) return { date: null };
369
+ if (sameClose(before.close, quote.previousClose!)) return { date: before.date };
370
+ const nominal = closedBars(points, quote).findLast((point) => point.date === calendarDate);
371
+ return nominal && sameClose(nominal.close, quote.previousClose!) ? { date: null } : { date: null, untraded: true };
372
+ }
373
+
374
+ function readingOf(points: readonly DailyClose[], quote: Quote, now: number): ReadingFields {
226
375
  const indexDate = datedIndexClose(quote);
227
376
  if (indexDate) return indexCloseOn(points, quote, indexDate);
377
+ const lagging = laggingQuote(quote, now) ? laggingSession(points, quote, now) : null;
378
+ if (lagging) return lagging;
379
+ const calendarDate = thinListingCalendarDate(quote);
380
+ if (calendarDate) return thinPreviousTrade(points, quote, calendarDate);
228
381
  const session = sessionCloseOf(points, quote);
229
382
  return {
230
383
  date: latestCloseBefore(points, quote),
@@ -238,12 +391,33 @@ function withDate<T extends Quote | null | undefined>(quote: T, date: string | n
238
391
  }
239
392
 
240
393
  /** The quote as a reading has it: dated, and for an index measured from that day's close when its own disagrees. */
241
- function withReading<T extends Quote | null | undefined>(quote: T, reading: Pick<Reading, "date" | "close" | "sessionClose"> | undefined): T {
394
+ function withReading<T extends Quote | null | undefined>(quote: T, reading: Pick<Reading, "date" | "close" | "sessionClose" | "untraded" | "session"> | undefined): T {
242
395
  if (!quote || !reading) return quote;
396
+ if (reading.untraded) return { ...quote, previousCloseUndated: true };
397
+ if (reading.session && reading.date) return withDate(withLaggingSession(quote, reading.session), reading.date);
243
398
  const closed = withSessionClose(quote, reading.sessionClose);
244
399
  return closed === quote ? withDatedReading(quote, reading) : withDatedReading(closed as T, reading);
245
400
  }
246
401
 
402
+ /**
403
+ * A lagging quote as its bars date it: its move is the later session's, with
404
+ * that bar's range and volume. Its last print, and whether its source calls
405
+ * it stale, stay as they were: the bars date the price, not a trade. A
406
+ * nominal price has no range, nothing having traded, and says which
407
+ * session's it is (Quote.nominalPrice).
408
+ */
409
+ function withLaggingSession<T extends Quote>(quote: T, session: LaggingSession): T {
410
+ return {
411
+ ...quote,
412
+ changeSessionDate: session.date,
413
+ open: session.open,
414
+ high: session.high,
415
+ low: session.low,
416
+ volume: session.volume,
417
+ ...session.nominal ? { nominalPrice: { session: session.date, lastTraded: session.nominal.lastTraded } } : {},
418
+ };
419
+ }
420
+
247
421
  /** A closed quote that ended on a later print headlines its session's official close, as history and the portfolio read it. */
248
422
  function withSessionClose<T extends Quote>(quote: T, close: number | undefined): T {
249
423
  const sessionDate = close != null && quote.marketState === "CLOSED" && !(typeof quote.regularClose === "number" && quote.regularClose > 0)
@@ -360,7 +534,7 @@ export class PreviousCloseDates {
360
534
 
361
535
  private read(key: string, quote: Quote, listing: DatedCloseListing): Promise<ReadingFields> {
362
536
  const read = this.inSlot(datedIndexClose(quote) ? "index" : "dating", () => withDeadline(Promise.resolve().then(() => this.readCloses(listing)), this.readDeadlineMs, "Reading daily closes timed out"))
363
- .then((points) => readingOf(points, quote))
537
+ .then((points) => readingOf(points, quote, this.now()))
364
538
  .catch(logFailure("market-data.dated-previous-close", "Read daily closes failed", { date: null } as ReadingFields))
365
539
  .then((reading) => {
366
540
  this.pending.delete(key);
@@ -369,7 +543,7 @@ export class PreviousCloseDates {
369
543
  this.readings.set(key, { ...reading, at: this.now() });
370
544
  const latest = this.latestCopies.get(key);
371
545
  this.latestCopies.delete(key);
372
- if ((reading.date || reading.sessionClose != null) && latest && this.options.onDated) {
546
+ if ((reading.date || reading.sessionClose != null || reading.untraded || reading.session) && latest && this.options.onDated) {
373
547
  try {
374
548
  this.options.onDated(latest.listing, withReading(latest.quote, reading));
375
549
  } catch (error) {
@@ -4,7 +4,7 @@ import { hasPublishedApacCalendar, isPublishedApacClosure, publishedApacEarlyClo
4
4
  import { hasPublishedCnCalendar, isPublishedCnClosure } from "../published-cn-sessions";
5
5
  import { hasPublishedFuturesCalendar, isPublishedFuturesClosure, isPublishedFuturesVenue } from "../published-futures-sessions";
6
6
  import { hasPublishedJpxCalendar, isPublishedJpxClosure } from "../published-jpx-sessions";
7
- import { hasPublishedNseCalendar, isPublishedNseClosure } from "../published-nse-sessions";
7
+ import { hasPublishedNseCalendar, isPublishedNseClosure, publishedNseSpecialSession } from "../published-nse-sessions";
8
8
  import { getPublishedUsEquityCalendarDay, getPublishedUsEquityCalendarYears, getPublishedUsEquitySession } from "../published-us-sessions";
9
9
  import { quoteFutureToleranceMs } from "../quotes/clock";
10
10
  import { zonedDateKey, zonedDateTimeParts, zonedWallClockToUtcMs } from "../../utils/zoned-date-time";
@@ -256,7 +256,8 @@ function formatExchangeLocalMinuteOfDay(timeZone: string, timestampMs: number):
256
256
 
257
257
  function isBeforeKnownRegularOpen(exchange: string, timestampMs: number): boolean {
258
258
  const canonical = canonicalExchange(exchange);
259
- const openMinute = REGULAR_OPEN_MINUTES[canonical];
259
+ const date = exchangeLocalDate(canonical, timestampMs);
260
+ const openMinute = (date ? publishedSpecialSession(canonical, date)?.open : undefined) ?? REGULAR_OPEN_MINUTES[canonical];
260
261
  const localMinute = exchangeLocalMinuteOfDay(canonical, timestampMs);
261
262
  return openMinute != null && localMinute != null && localMinute < openMinute;
262
263
  }
@@ -281,6 +282,11 @@ function isPublishedClosure(exchange: string, date: string): boolean {
281
282
  return getPublishedUsEquityCalendarDay(exchange, date) === "closed";
282
283
  }
283
284
 
285
+ /** A published special session on a day the venue is otherwise shut (NSE's and BSE's Sunday Muhurat session), with its local hours. */
286
+ function publishedSpecialSession(exchange: string, date: string): { open: number; close: number } | undefined {
287
+ return exchange === "NSE" || exchange === "BSE" ? publishedNseSpecialSession(date) : undefined;
288
+ }
289
+
284
290
  /** Whether `weekday` (0 is Sunday) is in the venue's trading week. */
285
291
  export function isTradingWeekday(exchange: string, weekday: number, weekendDays?: readonly number[]): boolean {
286
292
  return !(weekendDays ?? WEEKEND_DAYS[exchange] ?? DEFAULT_WEEKEND_DAYS).includes(weekday);
@@ -316,6 +322,7 @@ export function venueSessionOnOrBefore(exchange: string | undefined, date: strin
316
322
 
317
323
  /** `weekendDays` replaces the venue's days off (historySourceWeekendDays). */
318
324
  function isLocalTradingDay(exchange: string, date: string, weekendDays?: readonly number[]): boolean {
325
+ if (publishedSpecialSession(exchange, date)) return true;
319
326
  const weekday = localWeekday(date);
320
327
  return weekday != null && isTradingWeekday(exchange, weekday, weekendDays) && !isPublishedClosure(exchange, date);
321
328
  }
@@ -345,6 +352,8 @@ function localWeekday(date: string): number | null {
345
352
 
346
353
  /** The local close of the venue's regular session on `date`, in minutes of the day, a published half day's included. */
347
354
  function regularCloseMinutes(exchange: string, date: string): number | undefined {
355
+ const special = publishedSpecialSession(exchange, date);
356
+ if (special) return special.close;
348
357
  const early = publishedApacEarlyClose(exchange, date);
349
358
  if (early !== undefined) return early;
350
359
  const weekday = localWeekday(date);
@@ -462,8 +471,9 @@ export function latestRegularSessionOpen(
462
471
  } else if (minutes === undefined) {
463
472
  return null;
464
473
  } else if (isLocalTradingDay(canonical, date, weekendDays)) {
474
+ const opens = publishedSpecialSession(canonical, date)?.open ?? minutes;
465
475
  open = zonedWallClockToUtcMs(timeZone, Number(date.slice(0, 4)), Number(date.slice(5, 7)),
466
- Number(date.slice(8, 10)), Math.floor(minutes / 60), minutes % 60, 0);
476
+ Number(date.slice(8, 10)), Math.floor(opens / 60), opens % 60, 0);
467
477
  }
468
478
  if (open != null && open <= time) return open;
469
479
  }
@@ -496,8 +506,9 @@ export function nextRegularSessionOpen(
496
506
  } else if (minutes === undefined) {
497
507
  return null;
498
508
  } else if (isLocalTradingDay(canonical, date)) {
509
+ const opens = publishedSpecialSession(canonical, date)?.open ?? minutes;
499
510
  open = zonedWallClockToUtcMs(timeZone, Number(date.slice(0, 4)), Number(date.slice(5, 7)),
500
- Number(date.slice(8, 10)), Math.floor(minutes / 60), minutes % 60, 0);
511
+ Number(date.slice(8, 10)), Math.floor(opens / 60), opens % 60, 0);
501
512
  }
502
513
  if (open != null && open > time) return { date, open, timeZone };
503
514
  }
@@ -567,9 +578,10 @@ export function previousPublishedSession(
567
578
  for (let offset = 0; offset <= SESSION_LOOKBACK_DAYS * 2; offset++) {
568
579
  const at = new Date((day - offset) * MS_PER_DAY);
569
580
  const iso = at.toISOString().slice(0, 10);
570
- if (!isTradingWeekday(canonical, at.getUTCDay())) continue;
581
+ const special = !!publishedSpecialSession(canonical, iso);
582
+ if (!special && !isTradingWeekday(canonical, at.getUTCDay())) continue;
571
583
  if (!hasPublishedSessionCalendar(canonical, iso)) return null;
572
- const open = !isPublishedClosure(canonical, iso);
584
+ const open = special || !isPublishedClosure(canonical, iso);
573
585
  // First the session the move is from's own day, then the one before it.
574
586
  if (session == null) {
575
587
  if (open) session = offset;
@@ -67,6 +67,12 @@ export function marketStateLabel(state: MarketState): string {
67
67
 
68
68
  /** What a quote's session reads as once its last print is older than its venue's latest completed session. */
69
69
  const STALE_SESSION_LABEL = "STALE";
70
+ /**
71
+ * What a quote's session reads as when nothing traded in the session its price
72
+ * is from, nor today while its venue trades: its price is the venue's nominal
73
+ * one (Quote.nominalPrice).
74
+ */
75
+ const NO_TRADES_SESSION_LABEL = "NO TRADES";
70
76
 
71
77
  const WEEKDAYS = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"] as const;
72
78
  const MONTHS = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"] as const;
@@ -139,6 +145,7 @@ function quoteMarketState(quote: Quote | null | undefined, now = Date.now()): Ma
139
145
  */
140
146
  export function quoteMarketStateLabel(quote: Quote | null | undefined, now = Date.now()): string | null {
141
147
  if (quote?.delisting) return delistingLabel(quote.delisting);
148
+ if (quote?.nominalPrice) return NO_TRADES_SESSION_LABEL;
142
149
  if (!quote?.marketState) return null;
143
150
  if (isQuoteBeforeLatestSession(quote, now)) return STALE_SESSION_LABEL;
144
151
  const awaiting = preMarketCloseAwaitingPrint(quote);
@@ -245,6 +252,7 @@ export function quoteSessionStateLabel(quote: Quote | null | undefined, now = Da
245
252
 
246
253
  function sessionLabel(quote: Quote | null | undefined, now: number, standingClose: boolean): string | null {
247
254
  if (quote?.delisting) return standingClose ? delistingLabel(quote.delisting) : delistingStateLabel(quote.delisting);
255
+ if (quote?.nominalPrice) return NO_TRADES_SESSION_LABEL;
248
256
  if (!quote?.marketState) return null;
249
257
  if (isQuoteBeforeLatestSession(quote, now)) return STALE_SESSION_LABEL;
250
258
  if (overnightSessionDisplay(quote)) return "OVERNIGHT";
@@ -259,7 +267,7 @@ function sessionLabel(quote: Quote | null | undefined, now: number, standingClos
259
267
  * pre-market still stands at.
260
268
  */
261
269
  export function quoteSessionColor(quote: Quote | null | undefined, palette: ThemeColors = colors, now = Date.now()): string {
262
- if (quote?.delisting) return palette.warning;
270
+ if (quote?.delisting || quote?.nominalPrice) return palette.warning;
263
271
  if (!quote?.marketState) return palette.textDim;
264
272
  if (isQuoteBeforeLatestSession(quote, now)) return palette.warning;
265
273
  if (overnightSessionDisplay(quote)) return marketStateColor("POST", palette);
@@ -1,7 +1,6 @@
1
1
  // Published NSE equity closures (weekend dates omitted), not a holiday-rule engine.
2
2
  // BSE closes on the same days. Source: https://www.nseindia.com/resources/exchange-communication-holidays
3
3
  // (checked 2026-10-04; past dates match the days missing from NSE bhavcopy).
4
- // The Diwali Muhurat session falls on a weekend and is not modelled.
5
4
  const NSE_CLOSURES: Record<number, readonly string[]> = {
6
5
  2026: [
7
6
  "01-15", "01-26", "03-03", "03-26", "03-31", "04-03", "04-14", "05-01",
@@ -18,3 +17,19 @@ export function isPublishedNseClosure(date: string): boolean {
18
17
  export function hasPublishedNseCalendar(year: number): boolean {
19
18
  return NSE_CLOSURES[year] !== undefined;
20
19
  }
20
+
21
+ /**
22
+ * Published special sessions on days NSE and BSE are otherwise shut (the
23
+ * Diwali Muhurat session), as local minutes: the normal market's open, and
24
+ * its close with the closing auction and post-close, as a regular day's 09:15
25
+ * and 16:00 are. 2026: Sun 8 Nov, normal market from 14:20, closing auction
26
+ * to 15:30 (NSE circular NSE/CMTR/76941 of 19 Oct 2026; BSE trades the same session).
27
+ */
28
+ const NSE_SPECIAL_SESSIONS: Record<string, { open: number; close: number }> = {
29
+ "2026-11-08": { open: 14 * 60 + 20, close: 16 * 60 },
30
+ };
31
+
32
+ /** A published special session on `date` (YYYY-MM-DD), with its local hours; undefined on every other day. */
33
+ export function publishedNseSpecialSession(date: string): { open: number; close: number } | undefined {
34
+ return NSE_SPECIAL_SESSIONS[date];
35
+ }
@@ -251,6 +251,8 @@ export function mergeQuoteContribution(
251
251
  delete merged.previousCloseDate;
252
252
  }
253
253
  }
254
+ // So is a close its daily closes could not date: the next reading says it again.
255
+ if (next.previousCloseUndated === undefined) delete merged.previousCloseUndated;
254
256
 
255
257
  if (isOtherTradingDay(current, next)) {
256
258
  const record = merged as unknown as Record<string, unknown>;
@@ -183,6 +183,21 @@ export function noPrintsTodayText(quote: Quote | null | undefined, now = Date.no
183
183
  return `no prints today since ${time} (${quoteAgeText(since, now)})`;
184
184
  }
185
185
 
186
+ /**
187
+ * What a quote nothing traded on says beside its price (Quote.nominalPrice):
188
+ * "no trades since Thu 29 Oct, nominal price", or "no recent trades, nominal
189
+ * price" when its bars reach back to no trade. In the regular session too,
190
+ * until it trades. Null for any other quote.
191
+ */
192
+ export function nominalPriceText(quote: Pick<Quote, "nominalPrice"> | null | undefined): string | null {
193
+ const nominal = quote?.nominalPrice;
194
+ if (!nominal) return null;
195
+ const traded = nominal.lastTraded ? new Date(`${nominal.lastTraded}T00:00:00Z`) : null;
196
+ return traded && Number.isFinite(traded.getTime())
197
+ ? `no trades since ${PRINT_WEEKDAYS[traded.getUTCDay()]} ${traded.getUTCDate()} ${PRINT_MONTHS[traded.getUTCMonth()]}, nominal price`
198
+ : "no recent trades, nominal price";
199
+ }
200
+
186
201
  export function hasFreshQuoteForCurrentSession(
187
202
  quotes: Iterable<Quote | null | undefined>,
188
203
  now = Date.now(),
@@ -0,0 +1,50 @@
1
+ import type { EnterpriseValueCheck, TickerFinancials } from "../../types/financials";
2
+ import {
3
+ enterpriseValueCheck, enterpriseValueNotMeaningful, enterpriseValueWithdrawn, reportedEnterpriseValue, withBankEnterpriseValue,
4
+ } from "../../utils/fundamentals";
5
+ import { atRegularSessionPrice } from "./regular-session-valuation";
6
+
7
+ export type ListingEnterpriseValue =
8
+ | {
9
+ kind: "value";
10
+ value: number;
11
+ currency: string;
12
+ /** `computed`: market cap + total debt - cash, standing in for a provider figure Gloom Cloud withdrew. */
13
+ basis: "served" | "computed";
14
+ /** The withdrawn check a computed EV comes from, which names its balance sheet and rate. */
15
+ check?: EnterpriseValueCheck;
16
+ /**
17
+ * The rate the EV's balance sheet check converted the statements' currency
18
+ * at (an ADR's EUR or TWD into its USD EV), from any check that names one.
19
+ */
20
+ fx?: { from: string; rate: number };
21
+ }
22
+ | { kind: "not-meaningful"; reason: string }
23
+ | { kind: "unavailable" };
24
+
25
+ const finite = (value: unknown): value is number => typeof value === "number" && Number.isFinite(value);
26
+
27
+ /**
28
+ * The enterprise value every surface divides, at the regular session price:
29
+ * the one Gloom Cloud serves (`valuation`'s EV, RV's EV/S, the screener's
30
+ * EV/EBITDA), or, where it withdrew the provider's figure against the balance
31
+ * sheet, the market cap + total debt - cash it checked that figure against.
32
+ * Not meaningful at or below zero and for a bank.
33
+ */
34
+ export function listingEnterpriseValue(financials: Pick<TickerFinancials, "quote" | "fundamentals" | "profile">): ListingEnterpriseValue {
35
+ const priced = atRegularSessionPrice({ quote: financials.quote, fundamentals: withBankEnterpriseValue(financials.fundamentals, financials.profile) });
36
+ const fundamentals = priced.fundamentals;
37
+ const notMeaningful = enterpriseValueNotMeaningful(fundamentals);
38
+ if (notMeaningful) return { kind: "not-meaningful", reason: notMeaningful };
39
+ const check = enterpriseValueCheck(fundamentals);
40
+ const served = reportedEnterpriseValue(fundamentals);
41
+ const currency = check?.currency ?? fundamentals?.marketCapCurrency ?? priced.quote?.currency;
42
+ const fx = check?.fx && check.fx.from && finite(check.fx.rate) && check.fx.rate > 0 ? { fx: check.fx } : {};
43
+ if (served != null) return currency ? { kind: "value", value: served, currency, basis: "served", ...fx } : { kind: "unavailable" };
44
+ if (enterpriseValueWithdrawn(fundamentals) && check?.status === "withdrawn" && finite(check.computed) && check.currency) {
45
+ return check.computed > 0
46
+ ? { kind: "value", value: check.computed, currency: check.currency, basis: "computed", check, ...fx }
47
+ : { kind: "not-meaningful", reason: "Cash and short-term investments exceed market cap + total debt" };
48
+ }
49
+ return { kind: "unavailable" };
50
+ }