@gloom-sh/terminal 0.19.5 → 0.19.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (208) hide show
  1. package/package.json +1 -1
  2. package/patches/@opentui%2Fcore@0.3.2.patch +86 -25
  3. package/src/api-client/equity-screener.ts +23 -0
  4. package/src/app/pane-runtime/index.tsx +2 -0
  5. package/src/app/pane-runtime/plugin-bindings.ts +10 -1
  6. package/src/app.tsx +63 -16
  7. package/src/cli/commands/market.ts +149 -10
  8. package/src/cli/commands/search.ts +21 -3
  9. package/src/cli/commands/ticker.ts +74 -33
  10. package/src/cli/glossary.ts +3 -3
  11. package/src/cli/known-gaps.ts +8 -0
  12. package/src/cli/listing-arg.ts +12 -0
  13. package/src/cli/pane-functions/capabilities.ts +2 -0
  14. package/src/cli/pane-functions/catalog.ts +22 -4
  15. package/src/cli/pane-functions/function-help.ts +8 -5
  16. package/src/cli/pane-functions/headless.ts +4 -3
  17. package/src/cli/pane-functions/resolver.ts +75 -2
  18. package/src/cli/quote-answer.ts +9 -0
  19. package/src/cli/symbol-list.ts +54 -2
  20. package/src/cli/symbol-rows.ts +14 -2
  21. package/src/cli/ticker-resolution.ts +89 -20
  22. package/src/components/chart/composite/axis-overlays.tsx +60 -27
  23. package/src/components/chart/composite/composite-chart.tsx +118 -63
  24. package/src/components/chart/composite/cursor-source.ts +111 -0
  25. package/src/components/chart/composite/format.ts +168 -6
  26. package/src/components/chart/composite/legend.tsx +8 -4
  27. package/src/components/chart/composite/panel-labels.ts +20 -1
  28. package/src/components/chart/composite/panel-surface.tsx +201 -92
  29. package/src/components/chart/composite/price-axis-labels.tsx +92 -46
  30. package/src/components/chart/composite/price-series.ts +31 -8
  31. package/src/components/chart/composite/scene.ts +154 -59
  32. package/src/components/chart/composite/series-axis-tags.tsx +4 -2
  33. package/src/components/chart/composite/time-axis.ts +13 -5
  34. package/src/components/chart/composite/time-scale.ts +211 -56
  35. package/src/components/chart/composite/types.ts +11 -1
  36. package/src/components/chart/composite/use-composite-chart-keyboard.ts +32 -12
  37. package/src/components/chart/curve/curve-surface.tsx +5 -2
  38. package/src/components/chart/curve/model.ts +4 -1
  39. package/src/components/chart/native/use-bitmap-metrics.ts +81 -0
  40. package/src/components/chart/static/series.ts +3 -0
  41. package/src/components/command-bar/commands/collection-list.ts +81 -0
  42. package/src/components/command-bar/commands/direct/index.ts +6 -0
  43. package/src/components/command-bar/commands/registry.ts +8 -0
  44. package/src/components/command-bar/layout-items/current-layout.ts +22 -1
  45. package/src/components/command-bar/layout-items/focused-pane.ts +22 -1
  46. package/src/components/command-bar/pane-templates/items.ts +19 -3
  47. package/src/components/command-bar/pane-templates/workflow.ts +5 -0
  48. package/src/components/command-bar/routes/root/results.ts +23 -3
  49. package/src/components/command-bar/routes/root/selection.ts +4 -2
  50. package/src/components/command-bar/routes/root/shortcut-feedback.ts +1 -1
  51. package/src/components/command-bar/routes/root/shortcut-items.ts +3 -4
  52. package/src/components/command-bar/routes/root/shortcuts.ts +58 -14
  53. package/src/components/command-bar/routes/root/ticker-first.ts +32 -0
  54. package/src/components/command-bar/surface/environment.ts +2 -0
  55. package/src/components/command-bar/view-model.ts +7 -0
  56. package/src/components/command-bar/workflow/ops.ts +2 -1
  57. package/src/components/command-bar/workflow/tickers.ts +20 -0
  58. package/src/components/layout/shell/menu.ts +15 -1
  59. package/src/components/layout/shell/pane/actions.ts +4 -0
  60. package/src/components/layout/shell/ticker-link-menu.ts +12 -3
  61. package/src/components/layout/status-bar.tsx +20 -0
  62. package/src/components/onboarding/onboarding-keyboard.ts +5 -1
  63. package/src/components/onboarding/onboarding-wizard.tsx +15 -4
  64. package/src/components/onboarding/portfolio-step/positions-panel.tsx +8 -5
  65. package/src/components/onboarding/use-onboarding-progress.ts +20 -1
  66. package/src/components/price-sparkline/view.tsx +14 -6
  67. package/src/components/ticker/badge/index.tsx +8 -4
  68. package/src/components/ticker/badge/list.tsx +23 -7
  69. package/src/components/ui/column-grid.tsx +8 -2
  70. package/src/components/ui/data-table/opentui/model.ts +4 -1
  71. package/src/components/ui/tabs.tsx +5 -2
  72. package/src/core/state/app/layout.ts +18 -3
  73. package/src/core/state/app/state.ts +2 -0
  74. package/src/core/state/app/types.ts +5 -0
  75. package/src/data/config/layout.ts +3 -0
  76. package/src/data/config/store/normalize.ts +39 -4
  77. package/src/i18n/es.ts +10 -0
  78. package/src/i18n/ja.ts +10 -0
  79. package/src/i18n/ko.ts +10 -0
  80. package/src/i18n/zh-cn.ts +10 -0
  81. package/src/i18n/zh-tw.ts +10 -0
  82. package/src/layout/pane-manager/floating-placement.ts +7 -4
  83. package/src/layout/pane-manager/floating.ts +5 -2
  84. package/src/market-data/bond-funds.ts +19 -0
  85. package/src/market-data/futures-contract.ts +14 -3
  86. package/src/market-data/market/freshness.ts +18 -0
  87. package/src/market-data/market/status.ts +15 -2
  88. package/src/plugins/builtin/bond-calculator/headless.ts +2 -1
  89. package/src/plugins/builtin/bond-calculator/index.tsx +1 -1
  90. package/src/plugins/builtin/bond-calculator/model.ts +14 -5
  91. package/src/plugins/builtin/bond-calculator/pane.tsx +1 -1
  92. package/src/plugins/builtin/buildout/cells.tsx +25 -45
  93. package/src/plugins/builtin/buildout/detail/company.tsx +3 -3
  94. package/src/plugins/builtin/buildout/detail/index.tsx +1 -1
  95. package/src/plugins/builtin/buildout/detail/intel.tsx +4 -7
  96. package/src/plugins/builtin/buildout/detail/site.tsx +4 -4
  97. package/src/plugins/builtin/buildout/detail/ui.tsx +39 -38
  98. package/src/plugins/builtin/buildout/format.ts +23 -1
  99. package/src/plugins/builtin/buildout/model/types.ts +1 -0
  100. package/src/plugins/builtin/buildout/pane/index.tsx +2 -8
  101. package/src/plugins/builtin/buildout/table-model.ts +12 -4
  102. package/src/plugins/builtin/cds/headless.ts +1 -0
  103. package/src/plugins/builtin/cds/index.tsx +1 -1
  104. package/src/plugins/builtin/cloud/plugin.tsx +2 -0
  105. package/src/plugins/builtin/cloud/upgrade-status-widget.tsx +28 -3
  106. package/src/plugins/builtin/correlation/headless.ts +3 -2
  107. package/src/plugins/builtin/crypto-board/pane.tsx +5 -4
  108. package/src/plugins/builtin/debt-maturities/headless.ts +11 -2
  109. package/src/plugins/builtin/debt-maturities/model.ts +66 -0
  110. package/src/plugins/builtin/debt-maturities/pane.tsx +23 -4
  111. package/src/plugins/builtin/earnings-ripple/pane.tsx +1 -1
  112. package/src/plugins/builtin/econ/calendar-model.ts +28 -6
  113. package/src/plugins/builtin/equity-screener/client.ts +1 -1
  114. package/src/plugins/builtin/equity-screener/criterion-editor.tsx +4 -16
  115. package/src/plugins/builtin/equity-screener/headless.ts +4 -2
  116. package/src/plugins/builtin/equity-screener/ideas.ts +67 -3
  117. package/src/plugins/builtin/equity-screener/model.ts +180 -12
  118. package/src/plugins/builtin/equity-screener/pane.tsx +52 -12
  119. package/src/plugins/builtin/equity-screener/screen-check.ts +7 -4
  120. package/src/plugins/builtin/equity-screener/watchlist.ts +33 -0
  121. package/src/plugins/builtin/futures-curve/client.ts +19 -0
  122. package/src/plugins/builtin/futures-curve/headless.ts +52 -13
  123. package/src/plugins/builtin/futures-curve/index.tsx +1 -1
  124. package/src/plugins/builtin/futures-curve/model.ts +77 -6
  125. package/src/plugins/builtin/futures-curve/pane.tsx +19 -3
  126. package/src/plugins/builtin/macro-day/client.ts +41 -0
  127. package/src/plugins/builtin/macro-day/headless.ts +19 -9
  128. package/src/plugins/builtin/macro-day/model.ts +3 -1
  129. package/src/plugins/builtin/market-movers/index.tsx +4 -3
  130. package/src/plugins/builtin/mna/distress/headless.ts +1 -0
  131. package/src/plugins/builtin/perps/pane.tsx +3 -1
  132. package/src/plugins/builtin/portfolio-list/cli/bulk-symbols.ts +17 -0
  133. package/src/plugins/builtin/portfolio-list/cli/portfolio-command.ts +2 -1
  134. package/src/plugins/builtin/portfolio-list/cli/watchlist-command.ts +2 -1
  135. package/src/plugins/builtin/rate-path/headless.ts +24 -10
  136. package/src/plugins/builtin/research/event-model.ts +10 -3
  137. package/src/plugins/builtin/research/events-headless.ts +20 -2
  138. package/src/plugins/builtin/sec/fund-facts.ts +17 -1
  139. package/src/plugins/builtin/sec/index.tsx +1 -1
  140. package/src/plugins/builtin/shared/members-menu.tsx +103 -38
  141. package/src/plugins/builtin/short-interest/publications-model.ts +22 -1
  142. package/src/plugins/builtin/short-interest/publications-pane.tsx +13 -4
  143. package/src/plugins/builtin/short-interest/watch-model.ts +1 -1
  144. package/src/plugins/builtin/time-sales/pane.tsx +3 -2
  145. package/src/plugins/builtin/trace-bonds/client.ts +7 -4
  146. package/src/plugins/builtin/trace-bonds/index.tsx +1 -1
  147. package/src/plugins/builtin/volatility/client.ts +6 -1
  148. package/src/plugins/builtin/volatility/headless.ts +0 -1
  149. package/src/plugins/builtin/yield-curve/curves.ts +15 -0
  150. package/src/plugins/builtin/yield-curve/headless.ts +6 -1
  151. package/src/plugins/builtin/yield-curve/index.tsx +5 -8
  152. package/src/plugins/host-modules.ts +22 -3
  153. package/src/plugins/host-smoke.ts +6 -3
  154. package/src/portfolio/collection-name.ts +19 -0
  155. package/src/renderers/browser/http-proxy-transport.ts +78 -8
  156. package/src/renderers/cloudflare/http-proxy.ts +13 -2
  157. package/src/renderers/cloudflare/proxy-session.ts +47 -24
  158. package/src/renderers/cloudflare/worker.ts +15 -2
  159. package/src/renderers/desktop/geometry.ts +279 -0
  160. package/src/renderers/desktop/screen-setup.ts +246 -0
  161. package/src/renderers/desktop/sequential-window-host.ts +179 -0
  162. package/src/renderers/desktop/test-utils.ts +71 -0
  163. package/src/renderers/desktop/window-controller.ts +433 -0
  164. package/src/renderers/desktop/window-host.ts +70 -0
  165. package/src/renderers/desktop/window-layouts.ts +630 -0
  166. package/src/renderers/dom/data-frames.ts +15 -4
  167. package/src/renderers/electrobun/bun/application-menu/click.ts +1 -0
  168. package/src/renderers/electrobun/bun/application-menu/index.ts +4 -1
  169. package/src/renderers/electrobun/bun/desktop/backend-requests.ts +19 -8
  170. package/src/renderers/electrobun/bun/desktop/backend.ts +320 -19
  171. package/src/renderers/electrobun/bun/desktop/detached-windows.ts +83 -61
  172. package/src/renderers/electrobun/bun/desktop/host-requests.ts +4 -14
  173. package/src/renderers/electrobun/bun/desktop/initialization.ts +30 -11
  174. package/src/renderers/electrobun/bun/desktop/screen-setup-file.ts +55 -0
  175. package/src/renderers/electrobun/bun/desktop/state-broadcaster.ts +44 -8
  176. package/src/renderers/electrobun/bun/desktop/workspace/index.ts +298 -97
  177. package/src/renderers/electrobun/bun/desktop/workspace/requests.ts +44 -6
  178. package/src/renderers/electrobun/bun/index.ts +4 -97
  179. package/src/renderers/electrobun/bun/window/electrobun-window-host.ts +306 -0
  180. package/src/renderers/electrobun/bun/window/focus.ts +0 -25
  181. package/src/renderers/electrobun/bun/window/remembered-frame.ts +4 -82
  182. package/src/renderers/electrobun/shared/protocol.ts +44 -2
  183. package/src/renderers/electrobun/view/backend-rpc.ts +15 -0
  184. package/src/renderers/electrobun/view/desktop/window/bridge.ts +63 -3
  185. package/src/renderers/electrobun/view/main.tsx +13 -7
  186. package/src/series/fred-argument.ts +17 -0
  187. package/src/sources/provider-router/financial-routes.ts +7 -1
  188. package/src/state/app/context/index.tsx +16 -2
  189. package/src/state/desktop-windows.ts +63 -0
  190. package/src/sync/other-window-tabs.ts +62 -0
  191. package/src/tickers/company-name-listing.ts +23 -3
  192. package/src/tickers/listing-fate.ts +147 -1
  193. package/src/tickers/terminal-codes.ts +5 -0
  194. package/src/time-series/types.ts +6 -0
  195. package/src/types/config.ts +10 -1
  196. package/src/types/desktop-window.ts +71 -2
  197. package/src/types/financials.ts +4 -0
  198. package/src/types/headless.ts +19 -0
  199. package/src/types/plugin.ts +6 -0
  200. package/src/ui/index.tsx +14 -13
  201. package/src/ui/same-props.ts +58 -0
  202. package/src/utils/cli-output.ts +33 -4
  203. package/src/utils/format.ts +7 -2
  204. package/src/utils/futures-generic.ts +12 -0
  205. package/src/utils/http-proxy-upstream.ts +6 -2
  206. package/src/utils/plugin-proxy-hosts.json +0 -4
  207. package/src/utils/plugin-proxy-hosts.ts +22 -0
  208. package/src/utils/sec-filings.ts +7 -1
@@ -39,6 +39,7 @@ import { useThemeColors } from "../../../theme/theme-context";
39
39
  import { priceColor, shownPriceColor } from "../../../theme/colors";
40
40
  import { apiClient } from "../../../api-client";
41
41
  import {
42
+ LETTER_GRADE_FIELDS,
42
43
  NUMERIC_FIELDS,
43
44
  type NumericField,
44
45
  type ScreenDefinition,
@@ -46,8 +47,10 @@ import {
46
47
  } from "../../../api-client/equity-screener";
47
48
  import type { PaneProps } from "../../../types/plugin";
48
49
  import { formatPercentileRank, formatPercentRaw } from "../../../utils/format";
50
+ import { wrapTextLines } from "../../../utils/text-wrap";
49
51
  import { EXTENDED_SESSION_LABELS, extendedSessionStateLabel, type ExtendedSession } from "../../../market-data/market/status";
50
52
  import { useOpenDescription } from "../shared/open-description";
53
+ import { useMembersMenu } from "../shared/members-menu";
51
54
  import { useResearchCloudSession } from "../shared/research-cloud-session";
52
55
  import { INITIAL_STREAM_RANGE, streamWindowRows } from "../shared/use-quote-board";
53
56
  import { useSampledValue } from "../../../state/hooks/live-ticker-financials";
@@ -55,7 +58,7 @@ import { usePlanAccess } from "../../../api-client/plan-access";
55
58
  import { useQuoteDelayFooter } from "../shared/cloud-upgrade";
56
59
  import { SignInWall } from "../cloud/auth-actions";
57
60
  import { CriterionEditor } from "./criterion-editor";
58
- import { SCREEN_IDEAS, screenIdea } from "./ideas";
61
+ import { ideaMetricSetting, SCREEN_IDEAS, screenIdea } from "./ideas";
59
62
  import { ScreenTickerCheck } from "./ticker-check";
60
63
  import {
61
64
  fetchSavedScreens,
@@ -70,20 +73,25 @@ import {
70
73
  dividendYieldBasis,
71
74
  formatScreenMetric,
72
75
  formatScreenValue,
76
+ GRADE_DISPLAY_FIELDS,
77
+ gradeRankText,
73
78
  metricDate,
74
79
  parseScreenDefinition,
75
80
  pickerFields,
76
81
  resultFields,
77
82
  screenMetricSetting,
78
- SIGN_COLORED,
79
83
  screenColumnLabel,
80
84
  screenCurrencyEmpty,
81
85
  screenDefinitionKey,
86
+ screenDetailValue,
82
87
  screenLabel,
83
88
  screenRowId,
89
+ screenSignValue,
84
90
  screenYtdBase,
91
+ splitGradeReason,
85
92
  } from "./model";
86
93
  import { useScreenResults } from "./results";
94
+ import { screenWatchlistList } from "./watchlist";
87
95
  import { unmatchedCategoryText, unmatchedCategoryValues } from "./categories";
88
96
  import { overlayLiveScreenRows, screenExtendedMove, screenExtendedSessions, sortLiveScreenRows, type LiveScreenRow } from "./live";
89
97
  import { useLiveQuoteEntries } from "../../../state/hooks/quote-streaming";
@@ -169,6 +177,19 @@ export function resultColumns(
169
177
  return fits(named) ? named : build(compact.slice(0, shown), exchange, sector, "compact");
170
178
  }
171
179
  const loadFields = () => fetchScreenFields();
180
+ const DETAIL_LABEL_WIDTH = 24;
181
+ /** A long note under a value, wrapped to the detail's width rather than cut: one row per line, the label on the first. */
182
+ function WrappedDetailRows({ label, text, width }: { label: string; text: string; width: number }) {
183
+ // The detail's padding, the label column and the gap after it.
184
+ const lines = wrapTextLines(text, Math.max(16, width - 2 - DETAIL_LABEL_WIDTH - 1));
185
+ return (
186
+ <>
187
+ {lines.map((line, index) => (
188
+ <KeyValueRow key={index} label={index === 0 ? label : ""} labelWidth={DETAIL_LABEL_WIDTH} value={line} emphasis={false} />
189
+ ))}
190
+ </>
191
+ );
192
+ }
172
193
  function ScreenDetail({
173
194
  row,
174
195
  width,
@@ -189,19 +210,25 @@ function ScreenDetail({
189
210
  {NUMERIC_FIELDS.map((field) => {
190
211
  const metric = row.metrics[field];
191
212
  const stamp = metricDate(metric);
213
+ // A grade's company note (graded on another line of the company) is said once, above the grades.
214
+ const reason = GRADE_DISPLAY_FIELDS.has(field) ? splitGradeReason(metric.reason).own : metric.reason;
215
+ const company = field === LETTER_GRADE_FIELDS[0] ? splitGradeReason(metric.reason).company : null;
192
216
  const extended = field === "changePercent" ? row.extended : undefined;
193
217
  const basis = field === "dividendYieldPercent" ? dividendYieldBasis(metric) : null;
218
+ // A grade's rank in its sector and the inputs it read, and its notes: peers, N/M or stale inputs, its company.
219
+ const graded = GRADE_DISPLAY_FIELDS.has(field) && metric.value !== null ? gradeRankText(metric) : null;
194
220
  return (
195
221
  <Fragment key={field}>
222
+ {company ? <WrappedDetailRows label="Grades" text={company} width={width} /> : null}
196
223
  <KeyValueRow
197
224
  label={screenLabel(field)}
198
225
  labelWidth={24}
199
- value={metric.value == null && metric.notMeaningful ? formatScreenMetric(field, metric) : `${formatScreenValue(field, metric.value)} ${metric.unit}`}
226
+ value={screenDetailValue(field, metric)}
200
227
  detail={
201
228
  metric.value === null
202
- ? (metric.reason ?? "unavailable")
229
+ ? (reason ?? "unavailable")
203
230
  : [
204
- metric.percentile.value == null ? null : formatPercentileRank(metric.percentile.value),
231
+ graded || metric.percentile.value == null ? null : formatPercentileRank(metric.percentile.value),
205
232
  stamp.collected ? `collected ${stamp.text}` : stamp.text,
206
233
  metric.state === "available" ? null : metric.state,
207
234
  ].filter(Boolean).join(" \u00b7 ")
@@ -217,6 +244,8 @@ function ScreenDetail({
217
244
  />
218
245
  ) : null}
219
246
  {basis ? <KeyValueRow label="Yield basis" labelWidth={24} value={basis} /> : null}
247
+ {graded ? <WrappedDetailRows label="Ranked" text={graded} width={width} /> : null}
248
+ {graded && reason ? <WrappedDetailRows label="Note" text={reason} width={width} /> : null}
220
249
  </Fragment>
221
250
  );
222
251
  })}
@@ -247,6 +276,7 @@ export function EquityScreenerPane(props: PaneProps) {
247
276
  {...props}
248
277
  initial={initial}
249
278
  initialMetric={preset?.metric ?? "marketCap"}
279
+ initialMetricSetting={preset ? ideaMetricSetting(preset) : undefined}
250
280
  />
251
281
  );
252
282
  }
@@ -256,7 +286,8 @@ function EquityScreenView({
256
286
  focused,
257
287
  initial,
258
288
  initialMetric,
259
- }: PaneProps & { initial: ScreenDefinition; initialMetric: NumericField }) {
289
+ initialMetricSetting,
290
+ }: PaneProps & { initial: ScreenDefinition; initialMetric: NumericField; initialMetricSetting?: string }) {
260
291
  const colors = useThemeColors(),
261
292
  dialog = useDialog(),
262
293
  host = useRendererHost();
@@ -268,7 +299,7 @@ function EquityScreenView({
268
299
  const [definition, setDefinition] = usePluginPaneState("definition", initial);
269
300
  const [metricSetting, setMetric] = usePaneSettingValue<string>(
270
301
  "metric",
271
- initialMetric,
302
+ initialMetricSetting ?? initialMetric,
272
303
  );
273
304
  // `--metric trailingPE,dividendYieldPercent` leads with the first and adds the others as columns.
274
305
  const [metric, ...otherMetrics] = screenMetricSetting(metricSetting, initialMetric);
@@ -348,6 +379,16 @@ function EquityScreenView({
348
379
  const selected =
349
380
  opened ?? rows.find((row) => screenRowId(row) === selectedId) ?? rows[0];
350
381
  const currentSaved = saved.data?.find((row) => row.id === currentSavedId);
382
+ // The pane menu's Save to Watchlist… takes the matches loaded, in the order shown (the first page is 100). A live
383
+ // quote changes the rows but not who they are, so the menu is rebuilt only when the order does.
384
+ const shownOrder = rows.map(screenRowId).join(" ");
385
+ const watchlistList = useMemo(
386
+ () => mode === "results" && !openId && data && screenDefinitionKey(data.definition) === screenDefinitionKey(definition)
387
+ ? screenWatchlistList({ definition, rows, matched: data.universe.matched, savedName: currentSaved?.name })
388
+ : null,
389
+ [currentSaved?.name, data, definition, mode, openId, shownOrder], // eslint-disable-line react-hooks/exhaustive-deps
390
+ );
391
+ useMembersMenu("equity-screener:watchlist", watchlistList);
351
392
  const selectedSaved =
352
393
  saved.data?.find((row) => row.id === savedSelectedId) ?? saved.data?.[0];
353
394
  useEffect(() => {
@@ -910,7 +951,7 @@ function EquityScreenView({
910
951
  onChange: setIdeaSelectedId,
911
952
  }}
912
953
  onActivate={(row) => {
913
- setMetric(row.metric);
954
+ setMetric(ideaMetricSetting(row));
914
955
  apply(row.definition);
915
956
  setCurrentSavedId(null);
916
957
  setMode("results");
@@ -1053,10 +1094,9 @@ function EquityScreenView({
1053
1094
  : null;
1054
1095
  if (field) {
1055
1096
  const observation = row.metrics[field];
1056
- const change = SIGN_COLORED.has(field) && observation.value != null
1057
- // A move that prints 0.0 stays neutral.
1058
- ? priceColor(Math.abs(observation.value) < 0.05 ? 0 : observation.value, colors)
1059
- : undefined;
1097
+ // A move by its sign (one that prints 0.0 stays neutral), a grade by its side of the middle.
1098
+ const sign = screenSignValue(field, observation.value);
1099
+ const change = sign == null ? undefined : priceColor(sign, colors);
1060
1100
  return {
1061
1101
  text: formatScreenMetric(field, observation),
1062
1102
  color: observation.state === "stale" ? colors.warning : change,
@@ -1,6 +1,6 @@
1
- import type { ScreenCheckPayload, ScreenCriterion, ScreenDefinition } from "../../../api-client/equity-screener";
1
+ import type { NumericField, ScreenCheckPayload, ScreenCriterion, ScreenDefinition } from "../../../api-client/equity-screener";
2
2
  import { canonicalExchange, parsePublicTickerKey } from "../../../utils/exchanges";
3
- import { criterionText, parseScreenDefinition, screenDefinitionKey, screenLabel } from "./model";
3
+ import { criterionText, formatScreenValue, GRADE_DISPLAY_FIELDS, parseScreenDefinition, screenDefinitionKey, screenLabel } from "./model";
4
4
 
5
5
  /** One listing, with the same exchange aliases the rest of the app accepts. */
6
6
  export function screenCheckTicker(text: string): { symbol: string; exchange?: string } {
@@ -64,7 +64,8 @@ export function validateScreenCheck(
64
64
 
65
65
  const number = (value: number) => value.toLocaleString("en-US", { maximumSignificantDigits: 21 });
66
66
  function checkCriterionText(criterion: ScreenCriterion): string {
67
- if (!("value" in criterion) || criterion.op === "in") return criterionText(criterion);
67
+ // A grade compares letters (`Value grade >= B+`), and the composite reads as the screen writes it.
68
+ if (!("value" in criterion) || criterion.op === "in" || GRADE_DISPLAY_FIELDS.has(criterion.field)) return criterionText(criterion);
68
69
  const operators = { gte: ">=", lte: "<=", gt: ">", lt: "<", eq: "=", between: "between" };
69
70
  const threshold = Array.isArray(criterion.value) ? criterion.value.map(number).join(", ") : number(criterion.value);
70
71
  return `${screenLabel(criterion.field)} ${operators[criterion.op]} ${threshold}`;
@@ -102,7 +103,9 @@ export function checkRows(data: ScreenCheckPayload) {
102
103
  id: String(index),
103
104
  criterion: checkCriterionText(entry.criterion),
104
105
  value: entry.state === "not-covered" ? "Not covered" : entry.value === null ? "Missing" : typeof entry.value === "number"
105
- ? checkValueText(entry.value, entry.unit, entry.criterion) : entry.value,
106
+ ? GRADE_DISPLAY_FIELDS.has(entry.criterion.field) ? formatScreenValue(entry.criterion.field as NumericField, entry.value)
107
+ : checkValueText(entry.value, entry.unit, entry.criterion)
108
+ : entry.value,
106
109
  result: entry.passes === null ? "Not evaluated" : entry.passes ? "Pass" : "Fail",
107
110
  asOf: entry.asOf?.slice(0, 10) ?? (entry.observedAt ? `${entry.observedAt.slice(0, 10)} (collected)` : "--"),
108
111
  state: entry.state,
@@ -0,0 +1,33 @@
1
+ import type { ScreenDefinition, ScreenRow } from "../../../api-client/equity-screener";
2
+ import type { MemberList } from "../shared/members-menu";
3
+ import { SCREEN_IDEAS } from "./ideas";
4
+ import { screenDefinitionKey } from "./model";
5
+
6
+ /** What a screen is called: the idea it is, else the saved screen it was opened from, else EQS. */
7
+ function screenTitle(definition: ScreenDefinition, savedName?: string | null): string {
8
+ const key = screenDefinitionKey(definition);
9
+ return SCREEN_IDEAS.find((idea) => screenDefinitionKey(idea.definition) === key)?.name ?? (savedName?.trim() || "EQS");
10
+ }
11
+
12
+ /**
13
+ * A screen's matches as the shared watchlist menu takes them: the rows loaded, in
14
+ * the order shown, each listing with its exchange and quote currency, and how
15
+ * many match in all. A watchlist keeps at most the first 100 of them.
16
+ */
17
+ export function screenWatchlistList(options: {
18
+ definition: ScreenDefinition;
19
+ rows: readonly Pick<ScreenRow, "symbol" | "name" | "exchange" | "currency">[];
20
+ matched: number;
21
+ savedName?: string | null;
22
+ }): MemberList | null {
23
+ if (!options.rows.length) return null;
24
+ const title = screenTitle(options.definition, options.savedName);
25
+ return {
26
+ title,
27
+ watchlistName: title === "EQS" ? "EQS screen" : title,
28
+ noun: "matches",
29
+ total: options.matched,
30
+ openIn: false,
31
+ members: options.rows.map((row) => ({ symbol: row.symbol, name: row.name, exchange: row.exchange, currency: row.currency })),
32
+ };
33
+ }
@@ -111,6 +111,25 @@ export async function loadCurveSpot(symbol: string, provider: Pick<DataProvider,
111
111
  return curveSpot(symbol, await provider.getQuote(symbol, "").catch(logFailure("futures-curve.client", "Load curve spot quote failed", null)), now);
112
112
  }
113
113
 
114
+ /**
115
+ * A month of the spot index's daily closes, read through the same history path
116
+ * the charts use, which the front premium takes its settlement session's close
117
+ * from. A failed read has none: the curve stands, its premium saying why.
118
+ */
119
+ export async function loadCurveSpotCloses(symbol: string,
120
+ provider: Pick<AssetDataProvider, "getPriceHistoryForResolutionWithMetadata" | "getPriceHistoryForResolution">, force = false): Promise<{ date: Date; close: number }[]> {
121
+ const context = force ? { cacheMode: "refresh" as const } : undefined;
122
+ try {
123
+ if (provider.getPriceHistoryForResolutionWithMetadata) {
124
+ const history = await provider.getPriceHistoryForResolutionWithMetadata(symbol, "", "1M", "1d", context);
125
+ return history.resolution && history.resolution !== "1d" ? [] : history.points;
126
+ }
127
+ return provider.getPriceHistoryForResolution ? await provider.getPriceHistoryForResolution(symbol, "", "1M", "1d", context) : [];
128
+ } catch (error) {
129
+ return logFailure("futures-curve.client", "Load curve spot closes failed", [] as { date: Date; close: number }[])(error);
130
+ }
131
+ }
132
+
114
133
  /** The last day of one-minute bars: the reach of a curve's trades a basis is read for, the far months' older ones aside. */
115
134
  const SPOT_BAR_RANGE: TimeRange = "1D";
116
135
 
@@ -4,8 +4,8 @@ import type { HeadlessPaneColumn, HeadlessPaneDefinition, HeadlessPaneEntry, Hea
4
4
  import { formatPercentRaw } from "../../../utils/format";
5
5
  import { DATE_OPTION_EXAMPLES } from "../../../utils/calendar-date";
6
6
  import { newestReportTime, oldestReportTime } from "../../../utils/utc-time";
7
- import { fetchFuturesCurve, loadCurveSpot, loadCurveSpotBars, loadFuturesCurveAsOf } from "./client";
8
- import { basisSpotSymbol, BASIS_CONVENTION, blankBasisNote, catalogueCurveUnit, curveAsOfDate, curveBasisPercent, curveBasisRows, curveChangeText, curveContractCode, curvePrice, curveRoundedPrice, curveSpotSource, curveSpreadLabel, curveTimestamp, curveNoTradeSince, curveUnitLabel, noTradeChangeNote, normalizeCurveRoot, shortDatedBasisNote, thinSpreadNotice, unpairedContractCount, unsupportedCurveRootMessage, type ContractBasis } from "./model";
7
+ import { fetchFuturesCurve, loadCurveSpot, loadCurveSpotBars, loadCurveSpotCloses, loadFuturesCurveAsOf } from "./client";
8
+ import { basisSpotSymbol, BASIS_CONVENTION, blankBasisNote, catalogueCurveUnit, curveAsOfDate, curveBasisPercent, curveBasisRows, curveChangeText, curveContractCode, curvePrice, curveReadsThirtySeconds, curveRoundedPrice, curveSpotSource, curveSpotPremium, curveSpreadLabel, curveTimestamp, curveNoTradeSince, curveUnitLabel, noTradeChangeNote, normalizeCurveRoot, shortDatedBasisNote, spotIndexSymbol, thinSpreadNotice, unpairedContractCount, unsupportedCurveRootMessage, type ContractBasis, type CurveSpotPremium } from "./model";
9
9
  import { COMMODITIES_VIEW_STATE } from "../commodities-energy/view-state";
10
10
  import { knownGapMessage } from "../../../cli/known-gaps";
11
11
 
@@ -91,6 +91,23 @@ const FRONT_SPREAD_FIELDS = ["label", "frontSymbol", "nextSymbol", "value", "ann
91
91
  const GHOST_FIELDS = ["symbol", "expiration", "price", "asOf"];
92
92
  /** The annualized roll yield reads as the percent it is (+32.36%); an export keeps the number. */
93
93
  const ROLL_YIELD_FORMAT = { annualizedRollYield: (value: unknown) => typeof value === "number" ? formatPercentRaw(value) : "--" };
94
+ /** A Treasury root's prices read in 32nds in every section, as its contracts do; an export keeps the number. */
95
+ const thirtySecondsFormat = (root: string, key: string): Record<string, HeadlessPaneColumn["textFormat"]> => curveReadsThirtySeconds(root)
96
+ ? { [key]: (value: unknown) => typeof value === "number" ? curvePrice(value, root) : "--" } : {};
97
+
98
+ /**
99
+ * Spot against the front contract, both marks of the curve's settlement
100
+ * session: the index close and the front settlement's premium to it.
101
+ */
102
+ function spotPremiumEntries(premium: CurveSpotPremium, root: string): HeadlessPaneEntry[] {
103
+ return [
104
+ { key: "spot", label: premium.label, value: premium.close,
105
+ formatted: premium.close == null ? "--" : `${premium.close.toFixed(2)}${premium.date ? `, ${premium.date} close` : ""}` },
106
+ { key: "frontPremium", label: "Front premium", value: premium.premium,
107
+ formatted: premium.premium == null ? "--"
108
+ : `${curveChangeText(premium.premium, root)}${premium.frontSymbol ? `, ${curveContractCode(premium.frontSymbol)} settle less spot` : ""}` },
109
+ ];
110
+ }
94
111
 
95
112
  /** What one contract is: the terms a hedge is sized on, once rather than on every row, worded as `ticker` words them. */
96
113
  function specEntries(data: FuturesCurvePayload): HeadlessPaneEntry[] {
@@ -100,18 +117,33 @@ function specEntries(data: FuturesCurvePayload): HeadlessPaneEntry[] {
100
117
  const unit = catalogueCurveUnit(data.root);
101
118
  return unit ? [{ key: "unit", label: "Unit", value: unit }] : [];
102
119
  }
103
- return futuresSpecLines(spec).map((line) => {
104
- const value = spec[line.key as keyof typeof spec];
105
- return { key: line.key, label: line.label, value, ...line.value === String(value) ? {} : { formatted: line.value } };
106
- });
120
+ return [
121
+ ...futuresSpecLines(spec).map((line) => {
122
+ const value = spec[line.key as keyof typeof spec];
123
+ return { key: line.key, label: line.label, value, ...line.value === String(value) ? {} : { formatted: line.value } };
124
+ }),
125
+ ...curveReadsThirtySeconds(data.root) ? [TREASURY_DV01_ENTRY] : [],
126
+ ];
107
127
  }
108
128
 
129
+ /**
130
+ * A Treasury contract's DV01 is its cheapest-to-deliver note's divided by
131
+ * that note's conversion factor. CME publishes the factors, but not where they
132
+ * can be read, so the terms say how to size it rather than print a figure.
133
+ */
134
+ const TREASURY_DV01_ENTRY: HeadlessPaneEntry = {
135
+ key: "dv01", label: "DV01", value: null,
136
+ formatted: "not published here; price the cheapest-to-deliver in fn YAS and divide its DV01 by its CME conversion factor",
137
+ };
138
+
109
139
  export const futuresCurveHeadless: HeadlessPaneDefinition<"bundle"> = {
110
140
  discovery: { aliases: ["CTM"], dataRequirements: ["Gloom Cloud futures curve endpoint"],
111
141
  limitations: ["Listed-contract catalogues can be incomplete.", "Ghosts and percentiles use the same listed contracts.", "Cboe VIX is daily settlement.",
112
142
  "Ann Basis is simple actual/365, each last trade against spot in the same minute, and noisy under 7 days to expiry."],
113
- intents: ["futures basis trade", "cash and carry", "basis against spot"] },
114
- shape: "bundle", argument: { kind: "free-text", optional: true, placeholder: "root", description: "FUT root such as CL, ES, ZN or VX, or a CME crypto root (BTC, ETH, SOL, XRP). Defaults to ES." },
143
+ intents: ["futures basis trade", "cash and carry", "basis against spot"],
144
+ opens: [{ words: ["VX", "vix futures", "vix futures curve"], argument: "VIX" }] },
145
+ shape: "bundle", argument: { kind: "free-text", optional: true, placeholder: "root", description: "FUT root such as CL, ES, ZN or VX, or a CME crypto root (BTC, ETH, SOL, XRP). Defaults to ES.",
146
+ examples: ["VIX", "CL", "BTC"] },
115
147
  // Only the pane reads the tab; the report always carries both.
116
148
  options: [{ key: "tab", description: "Curve or the full contract table.", type: "enum",
117
149
  values: [{ value: "curve" }, { value: "contracts", aliases: ["contract", "table"] }], defaultValue: "curve",
@@ -129,13 +161,17 @@ export const futuresCurveHeadless: HeadlessPaneDefinition<"bundle"> = {
129
161
  const date = curveAsOfDate(args.options.date, new Date(), "--date");
130
162
  // The archive keeps no spot history, so a past curve has no basis.
131
163
  const spotSymbol = date ? null : basisSpotSymbol(root);
164
+ // VX reads against spot VIX's daily closes instead.
165
+ const indexSymbol = date ? null : spotIndexSymbol(root);
132
166
  const now = Date.now();
133
167
  // The quote names the spot and its feed; the one-minute bars price each trade's own minute.
134
- const [data, spot, bars] = await Promise.all([
168
+ const [data, spot, bars, closes] = await Promise.all([
135
169
  date ? loadFuturesCurveAsOf(root, date, ctx.apiClient) : fetchFuturesCurve(root, ctx.apiClient),
136
170
  spotSymbol ? loadCurveSpot(spotSymbol, ctx.marketData, now) : null,
137
171
  spotSymbol ? loadCurveSpotBars(spotSymbol, ctx.marketData, ctx.refresh === true) : null,
172
+ indexSymbol ? loadCurveSpotCloses(indexSymbol, ctx.marketData, ctx.refresh === true) : null,
138
173
  ]);
174
+ const spotPremium = closes ? curveSpotPremium(data, closes) : null;
139
175
  const bases = spot && bars ? curveBasisRows(data.contracts, bars) : null;
140
176
  const unit = curveUnitLabel(data);
141
177
  const terms = specEntries(data);
@@ -148,7 +184,8 @@ export const futuresCurveHeadless: HeadlessPaneDefinition<"bundle"> = {
148
184
  // A blank Change says why, as a blank basis does; a past curve has no session change to blank.
149
185
  const changeNote = date ? null : noTradeChangeNote(data.contracts, data);
150
186
  const thinSpread = thinSpreadNotice(data);
151
- const notes = [...thinSpread ? [`${thinSpread}.`] : [], ...changeNote ? [changeNote] : [], ...basisNotes];
187
+ const notes = [...thinSpread ? [`${thinSpread}.`] : [], ...changeNote ? [changeNote] : [], ...basisNotes,
188
+ ...spotPremium?.reason ? [`Front premium blank: ${spotPremium.reason}.`] : []];
152
189
  const columnOptions = { basis: !!bases, last: data.source !== "cboe", notice: data.contracts.some((row) => row.firstNotice) };
153
190
  // Dated by the contracts' own quotes; the same-contract history rows are a year of context, not observations.
154
191
  const quoted = data.contracts.map((row) => row.asOf);
@@ -162,16 +199,18 @@ export const futuresCurveHeadless: HeadlessPaneDefinition<"bundle"> = {
162
199
  { title: "Contracts", columns: contractColumns(root, data.settlementDate ?? null, columnOptions),
163
200
  ...bases ? { textColumns: contractColumns(root, data.settlementDate ?? null, { ...columnOptions, text: true }) } : {},
164
201
  rows: data.contracts.map((row) => contractRow(row, data, root, !!date, bases?.get(row.symbol))) },
165
- { title: "Front spread", columns: fieldColumns(FRONT_SPREAD_FIELDS, data.slope, ROLL_YIELD_FORMAT), rows: [{ label: curveSpreadLabel(data.slope), ...data.slope, value: curveRoundedPrice(data.slope.value, root),
202
+ { title: "Front spread", columns: fieldColumns(FRONT_SPREAD_FIELDS, data.slope, { ...ROLL_YIELD_FORMAT, ...thirtySecondsFormat(root, "value") }), rows: [{ label: curveSpreadLabel(data.slope), ...data.slope, value: curveRoundedPrice(data.slope.value, root),
166
203
  annualizedRollYield: data.slope.annualizedRollYield == null ? null : Number(data.slope.annualizedRollYield.toFixed(2)),
167
204
  percentile: rank(data.slope.percentile), rollPercentile: rank(data.slope.rollPercentile) }] },
205
+ ...spotPremium ? [{ title: "Front vs spot", entries: spotPremiumEntries(spotPremium, root) }] : [],
168
206
  ...terms.length ? [{ title: "Contract terms", entries: terms }] : [],
169
- ...data.ghosts.map((ghost) => ({ title: `${ghost.label} same-contract history`, columns: fieldColumns(GHOST_FIELDS, ghost.points[0] ?? {}),
207
+ ...data.ghosts.map((ghost) => ({ title: `${ghost.label} same-contract history`, columns: fieldColumns(GHOST_FIELDS, ghost.points[0] ?? {}, thirtySecondsFormat(root, "price")),
170
208
  rows: ghost.points.map((point) => ({ ...point })) })),
171
209
  ],
172
210
  errors: data.gaps,
173
211
  ...(notes.length ? { notes } : {}),
174
- metadata: { ...data, quoteUnit: unit, ...(spot && bases ? { spot, basisBlankedUnpaired: unpairedContractCount(bases.values()) } : {}), ...(args.argument ? {} : { defaultArgument: DEFAULT_ROOT }),
212
+ metadata: { ...data, quoteUnit: unit, ...(spot && bases ? { spot, basisBlankedUnpaired: unpairedContractCount(bases.values()) } : {}),
213
+ ...(spotPremium ? { spotPremium } : {}), ...(args.argument ? {} : { defaultArgument: DEFAULT_ROOT }),
175
214
  ...(notices.length ? { notices } : {}),
176
215
  complete: data.status === "available", percentileBasis: "Same-contract observations within one year; actual sample start/end retained" },
177
216
  };
@@ -17,7 +17,7 @@ export const futuresCurveModule: PluginModule = {
17
17
  }],
18
18
  paneTemplates: [{ id: "futures-curve-pane", paneId: "futures-curve", label: "Futures Curve",
19
19
  description: `Listed futures contracts, historical curves, roll yield and open interest including VIX and CME crypto futures, which add basis against spot: Ann Basis = ${BASIS_FORMULA}, simple actual/365.`,
20
- keywords: ["ctm", "futures", "curve", "term structure", "contango", "backwardation", "roll", "basis", "basis trade", "carry", "annualised basis", "vix", "crude oil", "natural gas"],
20
+ keywords: ["ctm", "futures", "curve", "term structure", "contango", "backwardation", "roll", "basis", "basis trade", "carry", "annualised basis", "vix", "crude oil", "natural gas", "treasury futures", "dv01", "hedge ratio", "steepener", "flattener"],
21
21
  shortcut: { prefix: "CTM", aliases: ["CT"], argKind: "text", argPlaceholder: "root", argOptional: true,
22
22
  argOptions: () => CURVE_ROOTS },
23
23
  headless: futuresCurveHeadless,
@@ -4,8 +4,10 @@ import { spanDigits } from "../../../components/chart-table";
4
4
  import { compositeAxisTicks } from "../../../components/chart/composite/format";
5
5
  import type { CompositeAxisDomain } from "../../../components/chart/composite/types";
6
6
  import { FUTURES_CONTRACTS, futuresBoardContractForTicker, futuresContractByCode, tickDecimals } from "../../../market-data/futures-board";
7
+ import { futuresContractCode } from "../../../market-data/futures-contract";
7
8
  import { contractMonthLabel } from "../../../utils/contract-month";
8
9
  import { formatPercentileRank } from "../../../utils/format";
10
+ import { formatThirtySeconds } from "../../../market-data/market/format";
9
11
  import { cryptoPairCoin, isFuturesSymbol } from "../shared/crypto-pair";
10
12
  import { parseReportTime } from "../../../utils/utc-time";
11
13
  import { zonedWallClockToUtcMs } from "../../../utils/zoned-date-time";
@@ -88,13 +90,17 @@ export function curveRootForTicker(ticker: unknown): string | null {
88
90
 
89
91
  /**
90
92
  * Treasury futures trade in fractions of a 32nd (ZT to 1/256, ZF 1/128, ZN
91
- * 1/64, ZB and UB 1/32), so the catalogue leaves their tick unset. A root
92
- * shows every price at the decimals its tick needs to stay exact (ZT 8, ZN 6),
93
- * so a column and the M2-M1 spread keep one width: 103.50000000 next to
94
- * 103.51562500, never 103.50 next to 103.515625.
93
+ * 1/64, ZB and UB 1/32), so the catalogue leaves their tick unset. Their
94
+ * prices read in 32nds (106-20\u00bd); a report's numbers keep the decimals the
95
+ * tick needs to stay exact (ZT 8, ZN 6), never float noise.
95
96
  */
96
97
  const RATE_TICKS: Readonly<Record<string, number>> = { ZT: 1 / 256, ZF: 1 / 128, ZN: 1 / 64, ZB: 1 / 32, UB: 1 / 32 };
97
98
 
99
+ /** Whether a root's prices read in 32nds of par (the Treasury futures), not decimals. */
100
+ export function curveReadsThirtySeconds(root: string): boolean {
101
+ return RATE_TICKS[root] != null;
102
+ }
103
+
98
104
  function curvePriceDecimals(root: string): number {
99
105
  const rateTick = RATE_TICKS[root];
100
106
  if (rateTick != null) return tickDecimals(rateTick);
@@ -105,6 +111,8 @@ function curvePriceDecimals(root: string): number {
105
111
 
106
112
  export function curvePrice(value: number | null, root: string): string {
107
113
  if (value == null) return "--";
114
+ // A Treasury future reads in 32nds, as `quote` and FUT write it: 106-20\u00bd, never 106.640625.
115
+ if (RATE_TICKS[root] != null) return formatThirtySeconds(Math.abs(value) < 1e-9 ? 0 : value);
108
116
  const text = value.toFixed(curvePriceDecimals(root));
109
117
  // A spread that rounds to zero is unsigned: 0.00, never -0.00.
110
118
  return /[1-9]/.test(text) ? text : text.replace("-", "");
@@ -136,7 +144,7 @@ export function curveUnitLabel(data: Pick<FuturesCurvePayload, "root" | "spec" |
136
144
 
137
145
  /** A contract as traders write it: GCZ26.CMX is GCZ26; a VX symbol stays as Cboe lists it. */
138
146
  export function curveContractCode(symbol: string): string {
139
- return symbol.replace(/\.[A-Z]+$/, "");
147
+ return futuresContractCode({ contract: null, contractSymbol: symbol });
140
148
  }
141
149
 
142
150
  /**
@@ -184,13 +192,26 @@ export function thinSpreadNotice(data: Pick<FuturesCurvePayload, "slope" | "cont
184
192
  return reason ? `${curveSpreadLabel(data.slope)} is thin (${reason}): no contango or backwardation call` : null;
185
193
  }
186
194
 
195
+ /**
196
+ * The grid a Treasury root's chart axis ticks on, in points: its own fraction
197
+ * of a 32nd, no finer than a quarter (ZT and ZF quarter 32nds, ZN half, ZB and
198
+ * UB whole 32nds), so a tick reads 104-25½, never 104-25.60. Undefined for a
199
+ * root quoted in decimals, whose axis steps 1, 2, 5.
200
+ */
201
+ export function curveAxisGrid(root: string): number | undefined {
202
+ const tick = RATE_TICKS[root];
203
+ return tick == null ? undefined : Math.max(tick, 1 / 128);
204
+ }
205
+
187
206
  /**
188
207
  * Axis gridlines sit on round values, so they need no tick precision: one
189
208
  * decimal count across the gutter, as many as the plotted range asks for and
190
209
  * enough to keep every tick within a percent of that range. A span of hundreds
191
- * of index points reads 7800, a VIX strip 18.5, a Treasury 1/64 grid 112.25.
210
+ * of index points reads 7800, a VIX strip 18.5. A Treasury axis reads in 32nds,
211
+ * its ticks on the root's grid (`curveAxisGrid`).
192
212
  */
193
213
  export function curveAxisPrice(value: number, domain: CompositeAxisDomain, root: string): string {
214
+ if (RATE_TICKS[root] != null) return formatThirtySeconds(value);
194
215
  const cap = curvePriceDecimals(root);
195
216
  const tolerance = Math.abs(domain.max - domain.min) / 100;
196
217
  const needed = (tick: number) => {
@@ -407,6 +428,56 @@ export function spotBarsFromHistory(points: readonly { date: Date | string | num
407
428
  return [...byMinute].sort((a, b) => a[0] - b[0]).map(([minute, price]) => ({ minute, price }));
408
429
  }
409
430
 
431
+ /**
432
+ * The cash index a settlement-only root's front contract is read against: VX
433
+ * against spot VIX. A root missing here shows no spot.
434
+ */
435
+ const SPOT_INDEX_SYMBOLS: ReadonlyMap<string, { symbol: string; label: string }> = new Map([
436
+ ["VX", { symbol: "^VIX", label: "Spot VIX" }],
437
+ ]);
438
+
439
+ export function spotIndexSymbol(root: string): string | null {
440
+ return SPOT_INDEX_SYMBOLS.get(root)?.symbol ?? null;
441
+ }
442
+
443
+ /**
444
+ * Spot against the front contract: the index's close on the curve's
445
+ * settlement session and the front settlement's premium to it, so both are
446
+ * marks of one session and a live index is never read against an older
447
+ * settlement. `reason` says why a figure is blank.
448
+ */
449
+ export interface CurveSpotPremium {
450
+ symbol: string;
451
+ label: string;
452
+ close: number | null;
453
+ /** The session of `close`, the curve's settlement date. */
454
+ date: string | null;
455
+ frontSymbol: string | null;
456
+ /** The front settlement less `close`, at the root's precision. */
457
+ premium: number | null;
458
+ reason: string | null;
459
+ }
460
+
461
+ /** The front contract's settlement less the index's close on the curve's settlement session. */
462
+ export function curveSpotPremium(data: Pick<FuturesCurvePayload, "root" | "contracts" | "slope" | "settlementDate">,
463
+ closes: readonly { date: Date | string | number; close: number }[]): CurveSpotPremium | null {
464
+ const index = SPOT_INDEX_SYMBOLS.get(data.root);
465
+ if (!index) return null;
466
+ const front = data.contracts.find((row) => row.symbol === data.slope.frontSymbol)
467
+ ?? [...data.contracts].filter((row) => row.settlement != null).sort((a, b) => a.expiration.localeCompare(b.expiration))[0];
468
+ const date = data.settlementDate ?? null;
469
+ const bar = date ? closes.find((point) => {
470
+ const time = new Date(point.date).getTime();
471
+ return Number.isFinite(time) && new Date(time).toISOString().slice(0, 10) === date && positive(point.close);
472
+ }) : undefined;
473
+ const close = bar ? bar.close : null;
474
+ const settle = front ? front.settlement ?? front.price : null;
475
+ const premium = close != null && positive(settle) ? curveRoundedPrice(settle - close, data.root) : null;
476
+ const reason = !date ? "the curve has no settlement date" : close == null ? `no ${index.symbol} close on ${date}`
477
+ : premium == null ? "no front settlement" : null;
478
+ return { symbol: index.symbol, label: index.label, close, date, frontSymbol: front?.symbol ?? null, premium, reason };
479
+ }
480
+
410
481
  /** The bar in `minute`, else the one nearest it; null when there are none. */
411
482
  function nearestSpotBar(bars: readonly SpotBar[], minute: number): SpotBar | null {
412
483
  let low = 0;
@@ -16,8 +16,8 @@ import { useAutoRefresh } from "../../../react/auto-refresh";
16
16
  import { futuresSessionRefreshInterval } from "../shared/futures-session";
17
17
  import { useResearchCloudSession } from "../shared/research-cloud-session";
18
18
  import { useQuoteBoard } from "../shared/use-quote-board";
19
- import { getCachedFuturesCurve, loadCurveSpotBars, loadFuturesCurve, loadFuturesCurveAsOf } from "./client";
20
- import { BASIS_CONVENTION, basisSpotSymbol, blankBasisNote, curveAsOfDate, curveAxisPrice, curveBasisPercent, curveBasisRows, curveChangeText, curveContractChanges, curveContractCode, curvePrice, curveRank, curveSpot, curveSpotLabel, curveSpotSource, curveSpreadBasis, curveSpreadLabel, curveTimestamp, curveTitle, curveUnitLabel, DEFAULT_CURVE_HORIZON, futuresCurveSeries, newestQuote, noTradeChangeNote, normalizeCurveRoot, paneCurveRoot, shortDatedBasis, shortDatedBasisNote, sortCurveContracts, thinSpreadNotice, unsupportedCurveRootMessage, type CurveContractChanges, type CurveSpot } from "./model";
19
+ import { getCachedFuturesCurve, loadCurveSpotBars, loadCurveSpotCloses, loadFuturesCurve, loadFuturesCurveAsOf } from "./client";
20
+ import { BASIS_CONVENTION, basisSpotSymbol, blankBasisNote, curveAsOfDate, curveAxisGrid, curveAxisPrice, curveBasisPercent, curveBasisRows, curveChangeText, curveContractChanges, curveContractCode, curvePrice, curveRank, curveSpot, curveSpotLabel, curveSpotPremium, curveSpotSource, curveSpreadBasis, curveSpreadLabel, curveTimestamp, curveTitle, curveUnitLabel, DEFAULT_CURVE_HORIZON, futuresCurveSeries, newestQuote, noTradeChangeNote, normalizeCurveRoot, paneCurveRoot, shortDatedBasis, shortDatedBasisNote, sortCurveContracts, spotIndexSymbol, thinSpreadNotice, unsupportedCurveRootMessage, type CurveContractChanges, type CurveSpot } from "./model";
21
21
 
22
22
  const TABS = [{ value: "curve", label: "Curve" }, { value: "contracts", label: "Contracts" }];
23
23
  // One column order for every root. SETTLE is the exchange settlement for the
@@ -140,6 +140,12 @@ function FuturesCurveView({ width, height, focused, root, ownsTitle }: PaneProps
140
140
  ? (force: boolean) => loadCurveSpotBars(spotSymbol, assetData, force) : null,
141
141
  [assetData, basisActive, spotSymbol, resource.updatedAt]);
142
142
  const spotBars = useAsyncResource(barsLoader, { keepPreviousData: true });
143
+ // VX reads its front settlement against spot VIX's close on the same session, re-read whenever the curve is.
144
+ const indexSymbol = requestedDate ? null : spotIndexSymbol(root);
145
+ const closesLoader = useMemo(() => indexSymbol && assetData
146
+ ? (force: boolean) => loadCurveSpotCloses(indexSymbol, assetData, force) : null,
147
+ [assetData, indexSymbol, resource.updatedAt]);
148
+ const spotCloses = useAsyncResource(closesLoader, { keepPreviousData: true });
143
149
  // Until the first answer there is nothing to say: no reason, only blank cells.
144
150
  const spot = useMemo(() => !basisActive || !spotSymbol || !spotState || spotState.loading && !spotState.quote ? null
145
151
  : curveSpot(spotSymbol, spotState.quote, clock), [basisActive, clock, spotState, spotSymbol]);
@@ -171,6 +177,9 @@ function FuturesCurveView({ width, height, focused, root, ownsTitle }: PaneProps
171
177
  const thin = data?.slope.state === "thin";
172
178
  const spreadRank = data && !thin ? curveRank(data.slope.percentile, data.slope.samples) : null;
173
179
  const thinSpread = data ? thinSpreadNotice(data) : null;
180
+ // Until the closes first answer there is nothing to say.
181
+ const spotPremium = useMemo(() => data && indexSymbol && spotCloses.data ? curveSpotPremium(data, spotCloses.data) : null,
182
+ [data, indexSymbol, spotCloses.data]);
174
183
  const statItems: StatItem[] = data ? [
175
184
  { id: "roll", label: "Ann. roll yield", value: signedPercent(data.slope.annualizedRollYield),
176
185
  ...thin ? { tone: "warning" as const } : { detail: curveRank(data.slope.rollPercentile, data.slope.samples) } },
@@ -178,6 +187,13 @@ function FuturesCurveView({ width, height, focused, root, ownsTitle }: PaneProps
178
187
  { id: "spread", label: curveSpreadLabel(data.slope), value: data.slope.value == null ? "--" : curvePrice(data.slope.value, root),
179
188
  ...thin ? { tone: "warning" as const } : {},
180
189
  detail: [data.slope.state, spreadBasis, spreadRank, slopeDate].filter(Boolean).join(" · ") },
190
+ ...spotPremium ? [
191
+ { id: "spot", label: spotPremium.label, value: spotPremium.close == null ? "--" : spotPremium.close.toFixed(2),
192
+ detail: spotPremium.date ? `${spotPremium.date.slice(5)} close` : undefined },
193
+ { id: "premium", label: "Front premium", value: curveChangeText(spotPremium.premium, root),
194
+ ...spotPremium.premium == null ? { tone: "warning" as const, detail: spotPremium.reason ?? undefined }
195
+ : { detail: spotPremium.frontSymbol ? `${curveContractCode(spotPremium.frontSymbol)} settle` : undefined } },
196
+ ] : [],
181
197
  ...data.spec ? [{ id: "contract", label: "Contract", value: data.spec.size, detail: `tick ${futuresTickText(data.spec)}` }] : [],
182
198
  ] : [];
183
199
  const { strip: tabStrip, rows: tabRows } = usePaneTabs({ tabs: TABS, activeValue: tab, onSelect: setTab, focused, dense: true, queryBarWidth: width });
@@ -260,7 +276,7 @@ function FuturesCurveView({ width, height, focused, root, ownsTitle }: PaneProps
260
276
  const chart = strip ? {
261
277
  render: (size: { width: number; height: number }) => <CurveSurface series={curves} width={size.width} height={size.height} display="chart"
262
278
  caption={caption} xScale="linear" formatValue={formatValue} formatChange={formatChange}
263
- formatAxisValue={(value, domain) => curveAxisPrice(value, domain, root)}
279
+ formatAxisValue={(value, domain) => curveAxisPrice(value, domain, root)} valueGrid={curveAxisGrid(root)}
264
280
  selectedPointId={selectedId} onSelectedPointChange={setSelected} />,
265
281
  minRows: curveSurfaceMinRows({ series: curves, width, caption }),
266
282
  strip,