gloomberb 0.20.4 → 0.20.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -1
- package/README.zh-CN.md +1 -1
- package/bin/gloom +9 -0
- package/bin/without-bun.cjs +98 -0
- package/package.json +4 -1
- package/src/api-client/data.ts +148 -37
- package/src/api-client/hk-tenders.ts +59 -0
- package/src/api-client/index.ts +1 -0
- package/src/api-client/types/econ.ts +30 -0
- package/src/api-client/yield-curves.ts +1 -1
- package/src/app/global-shortcuts.ts +4 -1
- package/src/app/keybindings/actions.ts +6 -0
- package/src/app/keybindings/config.ts +2 -1
- package/src/app/keybindings/index.ts +1 -0
- package/src/app/keybindings/labels.ts +6 -1
- package/src/app/keybindings/resolve.ts +23 -4
- package/src/app/keybindings/terminal-keys.ts +35 -0
- package/src/app/pane-runtime/index.tsx +2 -2
- package/src/app/pane-runtime/ticker-open-runtime.ts +68 -40
- package/src/app.tsx +18 -13
- package/src/architecture/floating-promise-allowlist.json +313 -0
- package/src/architecture/ui-literals-allowlist.json +1 -1
- package/src/capabilities/chart-series.ts +27 -1
- package/src/cli/commands/keybindings.ts +5 -5
- package/src/cli/commands/market.ts +238 -57
- package/src/cli/commands/news-search.ts +81 -14
- package/src/cli/commands/overview.ts +27 -6
- package/src/cli/commands/remote.ts +16 -17
- package/src/cli/commands/system.ts +1 -1
- package/src/cli/commands/ticker.ts +3 -1
- package/src/cli/early-command.ts +2 -0
- package/src/cli/errors.ts +10 -1
- package/src/cli/fx-forward.ts +89 -7
- package/src/cli/fx-pair.ts +1 -1
- package/src/cli/fx-quote-rate.ts +23 -0
- package/src/cli/glossary.ts +19 -5
- package/src/cli/help.ts +1 -0
- package/src/cli/history-rows.ts +5 -3
- package/src/cli/index-roots.ts +5 -4
- package/src/cli/index.ts +40 -3
- package/src/cli/known-gaps.ts +38 -9
- package/src/cli/listing-arg.ts +17 -5
- package/src/cli/name-entries.ts +5 -1
- package/src/cli/not-a-ticker.ts +4 -0
- package/src/cli/options.ts +52 -3
- package/src/cli/output-file.ts +5 -3
- package/src/cli/pane-functions/catalog.ts +15 -0
- package/src/cli/pane-functions/function-help.ts +4 -4
- package/src/cli/pane-functions/headless.ts +9 -4
- package/src/cli/pane-functions/index.ts +6 -4
- package/src/cli/pane-functions/resolver.ts +2 -2
- package/src/cli/result.ts +21 -2
- package/src/cli/spreadsheet-hint.ts +7 -3
- package/src/cli/treasury-yields.ts +5 -3
- package/src/components/chart/composite/legend.tsx +40 -2
- package/src/components/command-bar/pane-settings.ts +2 -2
- package/src/components/command-bar/routes/root/results.ts +6 -2
- package/src/components/command-bar/workflow/tickers.ts +2 -2
- package/src/components/data-table/view.tsx +9 -2
- package/src/components/input-search-bar.tsx +9 -2
- package/src/components/layout/pane/header.tsx +2 -0
- package/src/components/layout/shell/pane/capture.ts +4 -1
- package/src/components/layout/status-bar.tsx +6 -1
- package/src/components/onboarding/first-run-workspace.ts +44 -2
- package/src/components/onboarding/onboarding-frame.tsx +11 -2
- package/src/components/onboarding/onboarding-keyboard.ts +16 -0
- package/src/components/onboarding/onboarding-wizard.tsx +8 -8
- package/src/components/onboarding/portfolio-step/positions-panel.tsx +62 -1
- package/src/components/onboarding/use-onboarding-progress.ts +12 -4
- package/src/components/pane-settings-dialog/desktop.tsx +2 -2
- package/src/components/pane-settings-dialog/tui.tsx +2 -2
- package/src/components/pane-settings-dialog/value.ts +6 -0
- package/src/components/pane-settings-dialog.tsx +3 -3
- package/src/components/reader/detail-reader.tsx +4 -0
- package/src/components/ui/data-table/opentui/index.tsx +11 -4
- package/src/components/ui/data-table/opentui/model.ts +8 -6
- package/src/components/ui/data-table/types.ts +6 -1
- package/src/components/ui/index.ts +1 -1
- package/src/components/ui/page-stack-view.tsx +3 -0
- package/src/components/ui/pane-link-chip.tsx +269 -54
- package/src/components/ui/query-bar.tsx +2 -1
- package/src/components/ui/table-layout.ts +38 -1
- package/src/components/ui/tabs.tsx +97 -19
- package/src/core/state/app/layout-reducer.ts +7 -0
- package/src/core/state/app/layout.ts +44 -7
- package/src/core/state/app/state.ts +1 -1
- package/src/core/state/app/types.ts +22 -2
- package/src/docs/snapshot.json +30 -13
- package/src/market-data/depositary-pair.ts +5 -3
- package/src/market-data/market/change-basis.ts +9 -5
- package/src/market-data/market/dated-previous-close.ts +147 -17
- package/src/market-data/market/status.ts +17 -1
- package/src/market-data/quotes/contributions.ts +2 -0
- package/src/market-data/quotes/listing-enterprise-value.ts +50 -0
- package/src/plugins/builtin/alerts/metric-data.ts +15 -2
- package/src/plugins/builtin/analytics/risk-client.ts +10 -4
- package/src/plugins/builtin/analytics/risk-episodes.ts +5 -4
- package/src/plugins/builtin/analytics/risk-headless.ts +4 -2
- package/src/plugins/builtin/analytics/risk-sectors.ts +91 -0
- package/src/plugins/builtin/awards/index.tsx +1 -1
- package/src/plugins/builtin/backtest/headless.ts +1 -1
- package/src/plugins/builtin/buildout/index.tsx +1 -0
- package/src/plugins/builtin/catalysts/index.tsx +2 -2
- package/src/plugins/builtin/cds/headless.ts +4 -0
- package/src/plugins/builtin/cds/model.ts +0 -6
- package/src/plugins/builtin/chart-composer/formula.ts +16 -3
- package/src/plugins/builtin/chart-composer/headless-schema.ts +2 -0
- package/src/plugins/builtin/chart-composer/headless.ts +4 -2
- package/src/plugins/builtin/chart-composer/index.tsx +1 -0
- package/src/plugins/builtin/chart-composer/presets.ts +1 -0
- package/src/plugins/builtin/chat/content/composer.tsx +5 -4
- package/src/plugins/builtin/chat/content/index.tsx +12 -2
- package/src/plugins/builtin/chat/content/layout-metrics.ts +3 -3
- package/src/plugins/builtin/chat/content/open-targets.ts +3 -3
- package/src/plugins/builtin/chat/layout.ts +5 -2
- package/src/plugins/builtin/chat/message/pane-chip.tsx +61 -40
- package/src/plugins/builtin/chat/message/terminal.tsx +13 -15
- package/src/plugins/builtin/chat/pane-links/previews.ts +51 -5
- package/src/plugins/builtin/chat/pane-links/share-card.ts +36 -0
- package/src/plugins/builtin/cloud/askg/pane.tsx +55 -13
- package/src/plugins/builtin/cloud/askg/tool-display.ts +1 -0
- package/src/plugins/builtin/cloud/terminal-relay/redact.ts +5 -3
- package/src/plugins/builtin/commodity-balances/index.tsx +1 -0
- package/src/plugins/builtin/company-attention/index.tsx +1 -1
- package/src/plugins/builtin/company-kpis/headless.ts +3 -1
- package/src/plugins/builtin/company-kpis/index.tsx +2 -2
- package/src/plugins/builtin/cot/index.tsx +1 -1
- package/src/plugins/builtin/cpi/index.tsx +1 -1
- package/src/plugins/builtin/credit-boards/cdx-pane.tsx +20 -7
- package/src/plugins/builtin/credit-boards/client.ts +8 -0
- package/src/plugins/builtin/credit-boards/headless.ts +4 -1
- package/src/plugins/builtin/credit-boards/model.ts +58 -4
- package/src/plugins/builtin/credit-boards/series.ts +63 -6
- package/src/plugins/builtin/credit-boards/sovr-pane.tsx +3 -2
- package/src/plugins/builtin/credit-conditions/headless.ts +24 -6
- package/src/plugins/builtin/credit-conditions/index.tsx +1 -1
- package/src/plugins/builtin/credit-conditions/model.ts +12 -6
- package/src/plugins/builtin/credit-conditions/series.ts +2 -1
- package/src/plugins/builtin/crypto-board/index.tsx +1 -0
- package/src/plugins/builtin/dividend-yield/index.tsx +1 -0
- package/src/plugins/builtin/doe/index.tsx +1 -1
- package/src/plugins/builtin/earnings-calls/headless.ts +5 -1
- package/src/plugins/builtin/earnings-calls/index.tsx +1 -0
- package/src/plugins/builtin/econ/calendar-model.ts +115 -8
- package/src/plugins/builtin/econ/calendar-source.ts +7 -1
- package/src/plugins/builtin/econ/fred-catalog.ts +3 -1
- package/src/plugins/builtin/econ/index.tsx +42 -8
- package/src/plugins/builtin/econ/types.ts +3 -0
- package/src/plugins/builtin/econ-statistics/index.tsx +1 -0
- package/src/plugins/builtin/econ-statistics/pane.tsx +6 -0
- package/src/plugins/builtin/estimate-revisions/index.tsx +1 -0
- package/src/plugins/builtin/executives/index.tsx +1 -0
- package/src/plugins/builtin/filing-events/index.tsx +1 -0
- package/src/plugins/builtin/fixed-income/index.tsx +3 -0
- package/src/plugins/builtin/futures-curve/headless.ts +3 -3
- package/src/plugins/builtin/futures-curve/index.tsx +1 -1
- package/src/plugins/builtin/futures-curve/model.ts +18 -0
- package/src/plugins/builtin/fx-matrix/index.tsx +44 -14
- package/src/plugins/builtin/gpu/index.tsx +1 -1
- package/src/plugins/builtin/help/functions-table.tsx +1 -1
- package/src/plugins/builtin/help/index.tsx +11 -1
- package/src/plugins/builtin/help/keybindings-editor.tsx +7 -3
- package/src/plugins/builtin/holders/index.tsx +1 -0
- package/src/plugins/builtin/holders/report-header.ts +2 -2
- package/src/plugins/builtin/insider/index.tsx +1 -0
- package/src/plugins/builtin/iv-history/index.tsx +1 -1
- package/src/plugins/builtin/jobs/index.tsx +1 -0
- package/src/plugins/builtin/macro-day/headless.ts +27 -8
- package/src/plugins/builtin/macro-day/index.tsx +1 -1
- package/src/plugins/builtin/macro-day/model.ts +19 -3
- package/src/plugins/builtin/macro-day/pane.tsx +14 -9
- package/src/plugins/builtin/macro-day/releases.ts +25 -7
- package/src/plugins/builtin/market-valuation/index.tsx +1 -0
- package/src/plugins/builtin/market-valuation/pane.tsx +8 -0
- package/src/plugins/builtin/members/index.tsx +1 -1
- package/src/plugins/builtin/mna/index.tsx +1 -0
- package/src/plugins/builtin/news/index.tsx +1 -0
- package/src/plugins/builtin/news/wire/index.tsx +5 -1
- package/src/plugins/builtin/news/wire/news/detail-view.tsx +4 -0
- package/src/plugins/builtin/news/wire/news/list-search.ts +5 -2
- package/src/plugins/builtin/options/index.tsx +1 -0
- package/src/plugins/builtin/options-positioning/index.tsx +1 -0
- package/src/plugins/builtin/pe-band/index.tsx +1 -1
- package/src/plugins/builtin/portfolio-list/cli/portfolio-command.ts +25 -0
- package/src/plugins/builtin/portfolio-list/cli/render.ts +20 -3
- package/src/plugins/builtin/portfolio-list/cli/watchlist-command.ts +5 -1
- package/src/plugins/builtin/portfolio-list/headless.ts +15 -6
- package/src/plugins/builtin/power/index.tsx +1 -1
- package/src/plugins/builtin/realized-vol/index.tsx +1 -1
- package/src/plugins/builtin/research/headless-schema.ts +4 -3
- package/src/plugins/builtin/research/headless.ts +10 -4
- package/src/plugins/builtin/research/index.tsx +4 -0
- package/src/plugins/builtin/research/relative-valuation-columns.ts +145 -47
- package/src/plugins/builtin/research/relative-valuation-currency.ts +31 -0
- package/src/plugins/builtin/research/relative-valuation-headless.ts +25 -8
- package/src/plugins/builtin/research/relative-valuation-model.ts +40 -9
- package/src/plugins/builtin/research/relative-valuation-pane.tsx +3 -2
- package/src/plugins/builtin/research/relative-valuation-peers.ts +2 -2
- package/src/plugins/builtin/research-search/index.tsx +1 -0
- package/src/plugins/builtin/research-search/pane.tsx +8 -0
- package/src/plugins/builtin/revenue-breakdown/index.tsx +1 -0
- package/src/plugins/builtin/reverse-dcf/index.tsx +1 -1
- package/src/plugins/builtin/risk-factors/index.tsx +1 -0
- package/src/plugins/builtin/scanner/headless.ts +52 -13
- package/src/plugins/builtin/seasonality/index.tsx +1 -1
- package/src/plugins/builtin/sec/index.tsx +1 -0
- package/src/plugins/builtin/series-inventory.ts +1 -1
- package/src/plugins/builtin/shared/scanner-capture.ts +11 -3
- package/src/plugins/builtin/shared/series-list-detail.tsx +5 -0
- package/src/plugins/builtin/short-interest/index.tsx +1 -0
- package/src/plugins/builtin/social-mentions/index.tsx +1 -1
- package/src/plugins/builtin/supply-chain/index.tsx +1 -0
- package/src/plugins/builtin/thirteenf/api.ts +47 -4
- package/src/plugins/builtin/thirteenf/data.ts +43 -10
- package/src/plugins/builtin/thirteenf/headless.ts +55 -11
- package/src/plugins/builtin/thirteenf/model.ts +25 -9
- package/src/plugins/builtin/thirteenf/report-notes.ts +27 -6
- package/src/plugins/builtin/thirteenf/types.ts +2 -0
- package/src/plugins/builtin/ticker-detail/adr-pair/model.ts +1 -1
- package/src/plugins/builtin/ticker-detail/data-panes/historical-prices.tsx +8 -7
- package/src/plugins/builtin/ticker-detail/data-panes/history-bars.ts +8 -5
- package/src/plugins/builtin/ticker-detail/financials/model.ts +18 -2
- package/src/plugins/builtin/ticker-detail/financials/ratio-table.tsx +3 -3
- package/src/plugins/builtin/ticker-detail/financials/tab.tsx +6 -6
- package/src/plugins/builtin/ticker-detail/headless.ts +24 -17
- package/src/plugins/builtin/ticker-detail/index.tsx +4 -0
- package/src/plugins/builtin/ticker-detail/overview/model.ts +6 -4
- package/src/plugins/builtin/ticker-detail/overview-tab.tsx +6 -4
- package/src/plugins/builtin/time-sales/client.ts +9 -11
- package/src/plugins/builtin/time-sales/index.tsx +1 -1
- package/src/plugins/builtin/treasury-auctions/after.ts +267 -0
- package/src/plugins/builtin/treasury-auctions/cache.ts +54 -5
- package/src/plugins/builtin/treasury-auctions/client.ts +33 -2
- package/src/plugins/builtin/treasury-auctions/headless.ts +150 -22
- package/src/plugins/builtin/treasury-auctions/hk-headless.ts +126 -0
- package/src/plugins/builtin/treasury-auctions/hk-view.tsx +347 -0
- package/src/plugins/builtin/treasury-auctions/hk.ts +363 -0
- package/src/plugins/builtin/treasury-auctions/index.tsx +27 -4
- package/src/plugins/builtin/treasury-auctions/model.ts +264 -28
- package/src/plugins/builtin/treasury-auctions/pane.tsx +176 -41
- package/src/plugins/builtin/treasury-auctions/treasury-direct.ts +5 -2
- package/src/plugins/builtin/treasury-auctions/types.ts +7 -1
- package/src/plugins/builtin/vol-surface/index.tsx +1 -1
- package/src/plugins/builtin/world-venue-map/index.ts +1 -0
- package/src/plugins/builtin/yield-curve/curves.ts +10 -4
- package/src/plugins/builtin/yield-curve/headless.ts +6 -2
- package/src/plugins/builtin/yield-curve/index.tsx +3 -3
- package/src/plugins/builtin/yield-curve/series.ts +10 -0
- package/src/plugins/builtin/yield-curve/world.ts +3 -1
- package/src/portfolio/collection-name.ts +22 -0
- package/src/portfolio/column-values.ts +2 -1
- package/src/public/__snapshots__/public-api.test.ts.snap +4 -0
- package/src/public/remote.ts +7 -1
- package/src/remote/client.ts +191 -11
- package/src/remote/controller-utils.ts +13 -1
- package/src/remote/controller.ts +88 -26
- package/src/remote/endpoint.ts +24 -0
- package/src/remote/form.ts +59 -4
- package/src/remote/resources.ts +44 -18
- package/src/remote/schema.ts +21 -9
- package/src/remote/secrets.ts +12 -0
- package/src/remote/semantic-tree.tsx +14 -2
- package/src/remote/server.ts +2 -1
- package/src/remote/surface.tsx +192 -0
- package/src/remote/types.ts +5 -0
- package/src/renderers/dom/data-table/frozen-column.ts +3 -1
- package/src/renderers/dom/data-table/index.tsx +27 -9
- package/src/renderers/dom/data-table/row.tsx +2 -0
- package/src/renderers/electrobun/bun/desktop/backend.ts +27 -24
- package/src/renderers/electrobun/bun/desktop/detached-windows.ts +3 -3
- package/src/renderers/electrobun/bun/desktop/snapshot-commit.ts +77 -0
- package/src/renderers/electrobun/shared/protocol.ts +4 -0
- package/src/renderers/electrobun/view/backend-rpc.ts +3 -0
- package/src/renderers/electrobun/view/desktop/window/bridge.ts +3 -0
- package/src/renderers/opentui/host.tsx +6 -0
- package/src/series/standalone.ts +2 -2
- package/src/shares/api.ts +21 -4
- package/src/shares/item.ts +73 -0
- package/src/shares/pane-item.ts +205 -0
- package/src/shares/pane.ts +4 -0
- package/src/shares/payload.ts +9 -5
- package/src/sources/gloomberb-cloud/news.ts +2 -0
- package/src/sources/gloomberb-cloud/normalizers.ts +9 -5
- package/src/sources/provider-router/cache.ts +3 -1
- package/src/sync/controller.ts +17 -2
- package/src/sync/other-window-tabs.ts +32 -1
- package/src/sync/react.ts +4 -4
- package/src/tickers/renamed-listings.ts +105 -0
- package/src/tickers/search/index.ts +103 -16
- package/src/time-series/bar-spacing.ts +33 -0
- package/src/time-series/base-series.ts +21 -3
- package/src/time-series/chart-bounds.ts +31 -0
- package/src/time-series/field-catalog.ts +17 -0
- package/src/time-series/fundamentals.ts +143 -11
- package/src/time-series/ice-credit.ts +32 -6
- package/src/time-series/resolve.ts +11 -7
- package/src/time-series/session-bar.ts +78 -9
- package/src/time-series/studies/formula.ts +53 -10
- package/src/time-series/studies/pair.ts +18 -7
- package/src/time-series/studies/units.ts +49 -2
- package/src/time-series/types.ts +12 -0
- package/src/types/desktop-window.ts +2 -0
- package/src/types/financials.ts +7 -0
- package/src/types/headless.ts +8 -0
- package/src/types/plugin-pane-settings.ts +2 -0
- package/src/types/plugin-panes.ts +22 -0
- package/src/utils/central-banks.ts +86 -1
- package/src/utils/cli-output.ts +6 -3
- package/src/utils/datetime-format.ts +12 -3
- package/src/utils/depositary-receipt.ts +28 -3
- package/src/utils/ebitda.ts +128 -0
- package/src/utils/format.ts +1 -1
- package/src/utils/fundamentals.ts +14 -0
- package/src/utils/max-drawdown.ts +97 -16
- package/src/utils/shell-word.ts +13 -0
- package/src/utils/untrusted-text.ts +29 -0
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
import { apiClient } from "../../../api-client";
|
|
2
|
+
import type { CloudCurveHistory, CloudCurveId } from "../../../api-client/yield-curves";
|
|
3
|
+
import { createTtlCache } from "../../../data/ttl-cache";
|
|
4
|
+
import { toBasisPoints } from "../../../utils/basis-points";
|
|
5
|
+
import { AUCTION_HISTORY_ALL, type AuctionHistoryWindow } from "./client";
|
|
6
|
+
import { AUCTION_HISTORY_WINDOWS, auctionBenchmark, dealerPct, indirectPct, isPendingAuction, nextAuctionHistoryWindow } from "./model";
|
|
7
|
+
import type { TreasuryAuction } from "./types";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* The after view (docs/research-data.md, Treasury auctions): how an auction
|
|
11
|
+
* ranked against its tenor's own recent history, and what the matching
|
|
12
|
+
* constant-maturity yield did after it.
|
|
13
|
+
*
|
|
14
|
+
* - B/C, indirect and dealer share are each a percentile against the tenor's
|
|
15
|
+
* previous 24 auctions with that figure: the share of them below it, half
|
|
16
|
+
* the ones equal. A tenor is the security type and the benchmark it was sold
|
|
17
|
+
* as (the 10-year note and its 9-Year 10-Month reopenings are one; a 10-year
|
|
18
|
+
* TIPS is another). Fewer than 12 earlier auctions rank nothing.
|
|
19
|
+
* - The yield change is the Treasury par (CMT) yield of the auction's tenor,
|
|
20
|
+
* or the TIPS real yield for a TIPS, from the auction day's close to the
|
|
21
|
+
* close 1, 5 and 20 sessions later, in basis points. An FRN floats and has
|
|
22
|
+
* none; a day the curve has no close for has none.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
export type AuctionView = "results" | "after";
|
|
26
|
+
export const AUCTION_VIEWS: readonly AuctionView[] = ["results", "after"];
|
|
27
|
+
|
|
28
|
+
const PERCENTILE_LOOKBACK = 24;
|
|
29
|
+
const PERCENTILE_MIN = 12;
|
|
30
|
+
|
|
31
|
+
export interface AuctionAfter {
|
|
32
|
+
btcPercentile: number | null;
|
|
33
|
+
indirectPercentile: number | null;
|
|
34
|
+
dealerPercentile: number | null;
|
|
35
|
+
/** The CMT yield's change, bp, 1, 5 and 20 sessions after the auction day's close. */
|
|
36
|
+
after1d: number | null;
|
|
37
|
+
after5d: number | null;
|
|
38
|
+
after20d: number | null;
|
|
39
|
+
/** The yield read: "7Y", "10Y real"; null when none matches. */
|
|
40
|
+
cmt: string | null;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* The window the after view reads first: two years more than it lists, which
|
|
45
|
+
* gives most tenors their 24 before the oldest row listed. A tenor sold a few
|
|
46
|
+
* times a year (the 30-year TIPS) needs more: widerAfterWindow.
|
|
47
|
+
*/
|
|
48
|
+
export function afterLoadWindow(window: AuctionHistoryWindow): AuctionHistoryWindow {
|
|
49
|
+
if (window === AUCTION_HISTORY_ALL) return AUCTION_HISTORY_ALL;
|
|
50
|
+
return AUCTION_HISTORY_WINDOWS.find((next) => next === AUCTION_HISTORY_ALL || next >= window + 730) ?? AUCTION_HISTORY_ALL;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** The first day the after view lists, for a window it read more than: undefined for ALL. */
|
|
54
|
+
export function afterWindowStart(window: AuctionHistoryWindow, now = Date.now()): string | undefined {
|
|
55
|
+
return window === AUCTION_HISTORY_ALL ? undefined : new Date(now - window * 86_400_000).toISOString().slice(0, 10);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const DAY_MS = 86_400_000;
|
|
59
|
+
/** A tenor's oldest auction read this close to the window's start may have older ones before it. */
|
|
60
|
+
const MIN_GAP_MS = 400 * DAY_MS;
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* The next window the after view should read, or null when the one read is
|
|
64
|
+
* enough: every listed tenor has its 24 auctions before the oldest one listed,
|
|
65
|
+
* or began inside the window (its oldest auction read is further from the
|
|
66
|
+
* window's start than its longest gap between auctions, and at least 400
|
|
67
|
+
* days), or the window is already ALL. Cash management bills are one-offs and
|
|
68
|
+
* never ask for more.
|
|
69
|
+
*/
|
|
70
|
+
export function widerAfterWindow(
|
|
71
|
+
listed: readonly TreasuryAuction[],
|
|
72
|
+
loaded: readonly TreasuryAuction[],
|
|
73
|
+
window: AuctionHistoryWindow,
|
|
74
|
+
now = Date.now(),
|
|
75
|
+
): AuctionHistoryWindow | null {
|
|
76
|
+
if (window === AUCTION_HISTORY_ALL) return null;
|
|
77
|
+
const start = now - window * DAY_MS;
|
|
78
|
+
const byTenor = new Map<string, number[]>();
|
|
79
|
+
for (const auction of loaded) {
|
|
80
|
+
const key = auctionTenorKey(auction);
|
|
81
|
+
if (key && !isPendingAuction(auction)) byTenor.set(key, [...byTenor.get(key) ?? [], Date.parse(auction.auctionDate)]);
|
|
82
|
+
}
|
|
83
|
+
const oldestListed = new Map<string, number>();
|
|
84
|
+
for (const auction of listed) {
|
|
85
|
+
const key = auctionTenorKey(auction);
|
|
86
|
+
if (!key || auction.secType === "CMB" || isPendingAuction(auction)) continue;
|
|
87
|
+
const date = Date.parse(auction.auctionDate);
|
|
88
|
+
oldestListed.set(key, Math.min(oldestListed.get(key) ?? date, date));
|
|
89
|
+
}
|
|
90
|
+
for (const [key, oldest] of oldestListed) {
|
|
91
|
+
const dates = (byTenor.get(key) ?? []).toSorted((left, right) => left - right);
|
|
92
|
+
if (dates.filter((date) => date < oldest).length >= PERCENTILE_LOOKBACK) continue;
|
|
93
|
+
let gap = MIN_GAP_MS;
|
|
94
|
+
for (let index = 1; index < dates.length; index++) gap = Math.max(gap, dates[index]! - dates[index - 1]!);
|
|
95
|
+
if (dates.length && dates[0]! - start <= gap) return nextAuctionHistoryWindow(window);
|
|
96
|
+
}
|
|
97
|
+
return null;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const NO_AFTER: AuctionAfter = {
|
|
101
|
+
btcPercentile: null, indirectPercentile: null, dealerPercentile: null, after1d: null, after5d: null, after20d: null, cmt: null,
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
/** The tenor an auction ranks within: its type and the benchmark it was sold as. */
|
|
105
|
+
function auctionTenorKey(auction: TreasuryAuction): string | null {
|
|
106
|
+
const benchmark = auctionBenchmark(auction.securityTerm);
|
|
107
|
+
return benchmark ? `${auction.secType}|${benchmark.count}${benchmark.unit}` : null;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** 0 to 100: the share of `history` below `value`, half of those equal. */
|
|
111
|
+
function percentileOf(value: number, history: readonly number[]): number | null {
|
|
112
|
+
if (history.length < PERCENTILE_MIN) return null;
|
|
113
|
+
const below = history.filter((entry) => entry < value).length;
|
|
114
|
+
const equal = history.filter((entry) => entry === value).length;
|
|
115
|
+
return Math.round(((below + equal / 2) / history.length) * 100);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
type Metric = (auction: TreasuryAuction) => number | null;
|
|
119
|
+
const METRICS: ReadonlyArray<[keyof Pick<AuctionAfter, "btcPercentile" | "indirectPercentile" | "dealerPercentile">, Metric]> = [
|
|
120
|
+
["btcPercentile", (auction) => auction.bidToCoverRatio],
|
|
121
|
+
["indirectPercentile", indirectPct],
|
|
122
|
+
["dealerPercentile", dealerPct],
|
|
123
|
+
];
|
|
124
|
+
|
|
125
|
+
/** Each completed auction's percentiles, by id, against the auctions of its tenor before it in `auctions`. */
|
|
126
|
+
export function auctionPercentiles(auctions: readonly TreasuryAuction[]): Map<string, Pick<AuctionAfter, "btcPercentile" | "indirectPercentile" | "dealerPercentile">> {
|
|
127
|
+
const byTenor = new Map<string, TreasuryAuction[]>();
|
|
128
|
+
for (const auction of auctions) {
|
|
129
|
+
const key = auctionTenorKey(auction);
|
|
130
|
+
if (!key || isPendingAuction(auction)) continue;
|
|
131
|
+
byTenor.set(key, [...byTenor.get(key) ?? [], auction]);
|
|
132
|
+
}
|
|
133
|
+
const ranked = new Map<string, Pick<AuctionAfter, "btcPercentile" | "indirectPercentile" | "dealerPercentile">>();
|
|
134
|
+
for (const group of byTenor.values()) {
|
|
135
|
+
group.sort((left, right) => left.auctionDate.localeCompare(right.auctionDate) || left.id.localeCompare(right.id));
|
|
136
|
+
group.forEach((auction, index) => {
|
|
137
|
+
const entry = { btcPercentile: null, indirectPercentile: null, dealerPercentile: null } as Record<string, number | null>;
|
|
138
|
+
for (const [key, metric] of METRICS) {
|
|
139
|
+
const value = metric(auction);
|
|
140
|
+
if (value == null) continue;
|
|
141
|
+
const history: number[] = [];
|
|
142
|
+
for (let earlier = index - 1; earlier >= 0 && history.length < PERCENTILE_LOOKBACK; earlier--) {
|
|
143
|
+
const past = metric(group[earlier]!);
|
|
144
|
+
if (past != null) history.push(past);
|
|
145
|
+
}
|
|
146
|
+
entry[key] = percentileOf(value, history);
|
|
147
|
+
}
|
|
148
|
+
ranked.set(auction.id, entry as Pick<AuctionAfter, "btcPercentile" | "indirectPercentile" | "dealerPercentile">);
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
return ranked;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/** A curve's tenor and its length in days, as Gloom Cloud stores the US curves. */
|
|
155
|
+
const NOMINAL_TENORS: ReadonlyArray<[string, number]> = [
|
|
156
|
+
["1M", 30], ["6W", 42], ["2M", 61], ["3M", 91], ["4M", 122], ["6M", 183], ["1Y", 365], ["2Y", 730], ["3Y", 1095],
|
|
157
|
+
["5Y", 1826], ["7Y", 2557], ["10Y", 3652], ["20Y", 7305], ["30Y", 10957],
|
|
158
|
+
];
|
|
159
|
+
const REAL_TENORS: ReadonlyArray<[string, number]> = [["5Y", 1826], ["7Y", 2557], ["10Y", 3652], ["20Y", 7305], ["30Y", 10957]];
|
|
160
|
+
const UNIT_DAYS = { day: 1, week: 7, month: 30.44, year: 365.25 } as const;
|
|
161
|
+
|
|
162
|
+
/** The curve and tenor whose yield matches an auction's: the nearest stored tenor to its benchmark; null for an FRN. */
|
|
163
|
+
export function cmtFor(auction: TreasuryAuction): { curve: CloudCurveId; tenor: string } | null {
|
|
164
|
+
if (auction.secType === "FRN") return null;
|
|
165
|
+
const benchmark = auctionBenchmark(auction.securityTerm);
|
|
166
|
+
if (!benchmark) return null;
|
|
167
|
+
const days = benchmark.count * UNIT_DAYS[benchmark.unit];
|
|
168
|
+
const real = auction.secType === "TIPS";
|
|
169
|
+
const tenors = real ? REAL_TENORS : NOMINAL_TENORS;
|
|
170
|
+
const [tenor] = tenors.reduce((best, entry) => Math.abs(entry[1] - days) < Math.abs(best[1] - days) ? entry : best);
|
|
171
|
+
return { curve: real ? "us-real" : "us", tenor };
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
const cmtLabel = (cmt: { curve: CloudCurveId; tenor: string }) => cmt.curve === "us-real" ? `${cmt.tenor} real` : cmt.tenor;
|
|
175
|
+
|
|
176
|
+
/** A curve tenor's closes, oldest first, as `date` and `value` (percent). */
|
|
177
|
+
export type CurveCloses = ReadonlyArray<{ date: string; value: number }>;
|
|
178
|
+
|
|
179
|
+
/** The change from the auction day's close to the close `sessions` later, in bp; null when either is missing. */
|
|
180
|
+
export function yieldChangeAfter(closes: CurveCloses, date: string, sessions: number): number | null {
|
|
181
|
+
let low = 0, high = closes.length;
|
|
182
|
+
while (low < high) {
|
|
183
|
+
const middle = (low + high) >> 1;
|
|
184
|
+
if (closes[middle]!.date < date) low = middle + 1;
|
|
185
|
+
else high = middle;
|
|
186
|
+
}
|
|
187
|
+
const base = closes[low];
|
|
188
|
+
const later = closes[low + sessions];
|
|
189
|
+
if (!base || base.date !== date || !later) return null;
|
|
190
|
+
return toBasisPoints(later.value - base.value, 1);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/** The after view's figures for each auction shown, by id. */
|
|
194
|
+
export function projectAuctionAfter(
|
|
195
|
+
shown: readonly TreasuryAuction[],
|
|
196
|
+
history: readonly TreasuryAuction[],
|
|
197
|
+
curves: ReadonlyMap<string, CurveCloses>,
|
|
198
|
+
): Map<string, AuctionAfter> {
|
|
199
|
+
const percentiles = auctionPercentiles(history);
|
|
200
|
+
return new Map(shown.map((auction) => {
|
|
201
|
+
const cmt = cmtFor(auction);
|
|
202
|
+
const closes = cmt ? curves.get(curveKey(cmt)) : undefined;
|
|
203
|
+
const change = (sessions: number) => closes && !isPendingAuction(auction) ? yieldChangeAfter(closes, auction.auctionDate, sessions) : null;
|
|
204
|
+
return [auction.id, {
|
|
205
|
+
...NO_AFTER,
|
|
206
|
+
...percentiles.get(auction.id),
|
|
207
|
+
after1d: change(1), after5d: change(5), after20d: change(20),
|
|
208
|
+
cmt: cmt ? cmtLabel(cmt) : null,
|
|
209
|
+
}];
|
|
210
|
+
}));
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
const curveKey = (cmt: { curve: CloudCurveId; tenor: string }) => `${cmt.curve}:${cmt.tenor}`;
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* A curve tenor's closes as read, from `from` (null: its whole history); ten
|
|
217
|
+
* minutes, since a session's close lands once a day. Keyed by curve and tenor
|
|
218
|
+
* alone, so a list that changes reads again only when it needs older closes.
|
|
219
|
+
*/
|
|
220
|
+
const curveCache = createTtlCache<{ from: string | null; history: CloudCurveHistory }>({ ttlMs: 10 * 60_000, maxEntries: 64 });
|
|
221
|
+
|
|
222
|
+
export function resetAuctionCurvesForTests(): void {
|
|
223
|
+
curveCache.clear();
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
type CurveRead = (curve: CloudCurveId, tenor: string, from: string | null) => Promise<CloudCurveHistory>;
|
|
227
|
+
|
|
228
|
+
async function readCurve(curve: CloudCurveId, tenor: string, from: string | null, read: CurveRead): Promise<CloudCurveHistory> {
|
|
229
|
+
const key = curveKey({ curve, tenor });
|
|
230
|
+
const load = async () => ({ from, history: await read(curve, tenor, from) });
|
|
231
|
+
const held = await curveCache.load(key, load);
|
|
232
|
+
const covers = held.from == null || (from != null && held.from <= from);
|
|
233
|
+
return covers ? held.history : (await curveCache.load(key, load, { force: true })).history;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
export interface AuctionCurveRead {
|
|
237
|
+
curves: Map<string, CurveCloses>;
|
|
238
|
+
/** Why a curve the view needs could not be read. */
|
|
239
|
+
errors: string[];
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* The closes of every curve tenor the shown auctions match, from `from`, the
|
|
244
|
+
* first day of the window listed (null for ALL: the whole curve).
|
|
245
|
+
*/
|
|
246
|
+
export async function loadAuctionCurves(
|
|
247
|
+
shown: readonly TreasuryAuction[],
|
|
248
|
+
from: string | null,
|
|
249
|
+
read: CurveRead = (curve, tenor, start) => apiClient.getCloudCurveHistory(curve, tenor, start),
|
|
250
|
+
): Promise<AuctionCurveRead> {
|
|
251
|
+
const needed = new Map<string, { curve: CloudCurveId; tenor: string }>();
|
|
252
|
+
for (const auction of shown) {
|
|
253
|
+
const cmt = cmtFor(auction);
|
|
254
|
+
if (cmt && !isPendingAuction(auction)) needed.set(curveKey(cmt), cmt);
|
|
255
|
+
}
|
|
256
|
+
const curves = new Map<string, CurveCloses>();
|
|
257
|
+
const errors: string[] = [];
|
|
258
|
+
await Promise.all([...needed].map(async ([key, { curve, tenor }]) => {
|
|
259
|
+
try {
|
|
260
|
+
const history = await readCurve(curve, tenor, from, read);
|
|
261
|
+
curves.set(key, history.points);
|
|
262
|
+
} catch (error) {
|
|
263
|
+
errors.push(`${cmtLabel({ curve, tenor })} Treasury yields unavailable: ${error instanceof Error ? error.message : String(error)}`);
|
|
264
|
+
}
|
|
265
|
+
}));
|
|
266
|
+
return { curves, errors };
|
|
267
|
+
}
|
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
AUCTION_ARCHIVE_PAGE_SIZE, AUCTION_HISTORY_ALL, AUCTION_HISTORY_DAYS, AUCTION_HISTORY_START, auctionArchiveBoundary,
|
|
7
7
|
auctionWindowQuery, fetchTreasuryAuctions, type AuctionHistoryWindow, type AuctionQuery,
|
|
8
8
|
} from "./client";
|
|
9
|
-
import { mergeAuctionSources } from "./model";
|
|
9
|
+
import { isPendingAuction, mergeAuctionSources } from "./model";
|
|
10
10
|
import { DIRECT_LOOKBACK_DAYS, fetchDirectAuctions } from "./treasury-direct";
|
|
11
11
|
import type { TreasuryAuction } from "./types";
|
|
12
12
|
|
|
@@ -16,8 +16,11 @@ const DIRECT_CACHE_SOURCE = "treasury-direct";
|
|
|
16
16
|
/**
|
|
17
17
|
* 3: every reported page was validated before this board was cached.
|
|
18
18
|
* 4: boards carry direct takedown and bill discount rates, which a v3 board lacks.
|
|
19
|
+
* 5: boards carry the low yield and discount rate, and early rows with their high and low swapped are put right.
|
|
19
20
|
*/
|
|
20
|
-
|
|
21
|
+
/** Raised when a board gains fields (5: the low yield; 6: early bills blank an investment rate their swapped discount rates contradict), so a saved board never lacks a column the pane shows. */
|
|
22
|
+
export const CACHE_SCHEMA_VERSION = 6;
|
|
23
|
+
export const DIRECT_CACHE_SCHEMA_VERSION = 2;
|
|
21
24
|
export const TREASURY_FISCAL_DATA_CONNECTION_ID = "treasury-fiscal-data";
|
|
22
25
|
export const TREASURY_DIRECT_CONNECTION_ID = "treasury-direct";
|
|
23
26
|
/**
|
|
@@ -59,7 +62,7 @@ const archiveCache = createPluginCache<TreasuryAuction[]>({
|
|
|
59
62
|
});
|
|
60
63
|
/** TreasuryDirect's last weeks and announcements, refreshed as often as the board they are merged into. */
|
|
61
64
|
const directCache = createPluginCache<TreasuryAuction[]>({
|
|
62
|
-
kind: CACHE_KIND, source: DIRECT_CACHE_SOURCE, schemaVersion:
|
|
65
|
+
kind: CACHE_KIND, source: DIRECT_CACHE_SOURCE, schemaVersion: DIRECT_CACHE_SCHEMA_VERSION, policy: CACHE_POLICY, decode,
|
|
63
66
|
});
|
|
64
67
|
let connectionHealth: ConnectionHealthRegistry | null = null;
|
|
65
68
|
|
|
@@ -124,9 +127,12 @@ async function loadRecentBoard(
|
|
|
124
127
|
direct: { days: number; load: DirectLoader } | null,
|
|
125
128
|
from: () => string,
|
|
126
129
|
): Promise<TreasuryAuctionsResult> {
|
|
130
|
+
const directKey = direct && `direct:${direct.days}`;
|
|
131
|
+
const unchanged = force ? null : savedRecentBoard(fiscalKey, directKey, from());
|
|
132
|
+
if (unchanged) return unchanged;
|
|
127
133
|
const [primary, supplement] = await Promise.all([
|
|
128
134
|
answer(cache.load(fiscalKey, walk(FISCAL_DATA, fiscal), { force })),
|
|
129
|
-
direct ? answer(directCache.load(
|
|
135
|
+
direct && directKey ? answer(directCache.load(directKey, walk(TREASURY_DIRECT, () => direct.load(direct.days)), { force })) : null,
|
|
130
136
|
]);
|
|
131
137
|
if ("failed" in primary && (!supplement || "failed" in supplement)) throw primary.failed;
|
|
132
138
|
|
|
@@ -144,6 +150,37 @@ async function loadRecentBoard(
|
|
|
144
150
|
};
|
|
145
151
|
}
|
|
146
152
|
|
|
153
|
+
/** A New York day (YYYY-MM-DD): an auction closes on it and its results come out that afternoon. */
|
|
154
|
+
const newYorkDay = new Intl.DateTimeFormat("en-CA", { timeZone: "America/New_York", year: "numeric", month: "2-digit", day: "2-digit" });
|
|
155
|
+
|
|
156
|
+
/** An announced auction whose day has come in the last week: its results may be out by now. */
|
|
157
|
+
function comeDue(auction: TreasuryAuction, today: string, weekAgo: string): boolean {
|
|
158
|
+
return isPendingAuction(auction) && auction.auctionDate <= today && auction.auctionDate >= weekAgo;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* A command's recent board as an earlier run saved both sources' copies, while
|
|
163
|
+
* they are within the hour the app refreshes them in and no auction they list
|
|
164
|
+
* has come due since: results in do not change, so asking again could add only
|
|
165
|
+
* an auction announced within that hour, which the app waits as long for. A
|
|
166
|
+
* command otherwise asks both sources again (saved-copy-persistence.ts), a
|
|
167
|
+
* second or more each run; an auction due today is asked for until its
|
|
168
|
+
* results are in. The app's own cache already answers from a fresh copy, and
|
|
169
|
+
* keeps the failure of a refresh, so only a run that has read nothing yet
|
|
170
|
+
* (a command) looks here.
|
|
171
|
+
*/
|
|
172
|
+
function savedRecentBoard(fiscalKey: string, directKey: string | null, from: string, now = Date.now()): TreasuryAuctionsResult | null {
|
|
173
|
+
if (cache.get(fiscalKey)) return null;
|
|
174
|
+
const fiscal = cache.get(fiscalKey, { allowExpired: true });
|
|
175
|
+
const direct = directKey ? directCache.get(directKey, { allowExpired: true }) : null;
|
|
176
|
+
if (!fiscal || fiscal.stale || (directKey && (!direct || direct.stale))) return null;
|
|
177
|
+
const auctions = mergeAuctionSources(fiscal.data, direct?.data ?? [], from);
|
|
178
|
+
const today = newYorkDay.format(now);
|
|
179
|
+
const weekAgo = newYorkDay.format(now - 7 * 86_400_000);
|
|
180
|
+
if (auctions.some((auction) => comeDue(auction, today, weekAgo))) return null;
|
|
181
|
+
return { auctions, fetchedAt: Math.min(fiscal.fetchedAt, direct?.fetchedAt ?? Infinity), stale: false };
|
|
182
|
+
}
|
|
183
|
+
|
|
147
184
|
export async function loadTreasuryAuctions(
|
|
148
185
|
force = false,
|
|
149
186
|
loader: AuctionLoader = fetchTreasuryAuctions,
|
|
@@ -167,6 +204,17 @@ function answered(result: TreasuryAuctionsResult): TreasuryAuctionsResult {
|
|
|
167
204
|
return result.savedAt != null ? servedFromSavedCopy(result, result.savedAt) : result;
|
|
168
205
|
}
|
|
169
206
|
|
|
207
|
+
/**
|
|
208
|
+
* The archive as saved, while it is still fresh: results that do not change,
|
|
209
|
+
* so a command reads the copy an earlier run saved (a command otherwise asks
|
|
210
|
+
* the source again: saved-copy-persistence.ts) and ALL answers in a second or
|
|
211
|
+
* two instead of walking 10,000 auctions again.
|
|
212
|
+
*/
|
|
213
|
+
function savedArchive(key: string): Promise<PluginCacheResult<TreasuryAuction[]>> | null {
|
|
214
|
+
const saved = archiveCache.get(key, { allowExpired: true });
|
|
215
|
+
return saved && !saved.stale ? Promise.resolve(saved) : null;
|
|
216
|
+
}
|
|
217
|
+
|
|
170
218
|
/**
|
|
171
219
|
* ALL: the recent auctions since the archive boundary, refreshed hourly, and
|
|
172
220
|
* the archive before it, from 1979-10-31, cached for weeks and never forced:
|
|
@@ -175,9 +223,10 @@ function answered(result: TreasuryAuctionsResult): TreasuryAuctionsResult {
|
|
|
175
223
|
*/
|
|
176
224
|
async function loadAllTreasuryAuctions(force: boolean, loader: AuctionLoader, direct: DirectLoader | null): Promise<TreasuryAuctionsResult> {
|
|
177
225
|
const boundary = auctionArchiveBoundary();
|
|
226
|
+
const key = `archive:${boundary}`;
|
|
178
227
|
const [recent, archive] = await Promise.all([
|
|
179
228
|
loadRecentBoard(force, `since:${boundary}`, () => loader({ from: boundary }), direct && { days: DIRECT_LOOKBACK_DAYS, load: direct }, () => boundary),
|
|
180
|
-
archiveCache.load(
|
|
229
|
+
savedArchive(key) ?? archiveCache.load(key, walk(FISCAL_DATA, () => loader({
|
|
181
230
|
from: AUCTION_HISTORY_START, before: boundary, pageSize: AUCTION_ARCHIVE_PAGE_SIZE,
|
|
182
231
|
}))).then(savedCopyForTransientFailure),
|
|
183
232
|
]);
|
|
@@ -14,6 +14,7 @@ const FIELDS = [
|
|
|
14
14
|
"high_investment_rate",
|
|
15
15
|
"high_yield",
|
|
16
16
|
"avg_med_yield",
|
|
17
|
+
"low_yield",
|
|
17
18
|
"high_price",
|
|
18
19
|
"low_price",
|
|
19
20
|
"avg_med_price",
|
|
@@ -29,6 +30,7 @@ const FIELDS = [
|
|
|
29
30
|
"high_discnt_margin",
|
|
30
31
|
"high_discnt_rate",
|
|
31
32
|
"avg_med_discnt_rate",
|
|
33
|
+
"low_discnt_rate",
|
|
32
34
|
].join(",");
|
|
33
35
|
|
|
34
36
|
export const AUCTION_HISTORY_DAYS = 120;
|
|
@@ -123,6 +125,33 @@ function toNumber(value: string | undefined | null): number | null {
|
|
|
123
125
|
return Number.isFinite(parsed) ? parsed : null;
|
|
124
126
|
}
|
|
125
127
|
|
|
128
|
+
/**
|
|
129
|
+
* A high and low in the order the auction cleared them. Fiscal Data has some
|
|
130
|
+
* early rows the other way round (the 30-year bond of 1982-02-04: high 14.47%,
|
|
131
|
+
* median 14.56%, low 14.61%; about 420 bills of 1979-83): a high below its low
|
|
132
|
+
* is read swapped when the median sits between them, and dropped when it does
|
|
133
|
+
* not, so neither reaches the stop-out as a negative spread. Prices follow a
|
|
134
|
+
* swapped pair. A bill's investment rate restates its high discount rate as
|
|
135
|
+
* the source had it, so once that pair is swapped or dropped the investment
|
|
136
|
+
* rate is blank rather than disagree with the discount rate beside it.
|
|
137
|
+
*/
|
|
138
|
+
export function inClearingOrder(auction: TreasuryAuction): TreasuryAuction {
|
|
139
|
+
let next = auction;
|
|
140
|
+
for (const [high, median, low] of [["highYield", "avgMedYield", "lowYield"], ["highDiscountRate", "avgMedDiscountRate", "lowDiscountRate"]] as const) {
|
|
141
|
+
const top = next[high], bottom = next[low], middle = next[median];
|
|
142
|
+
if (top == null || bottom == null || top >= bottom) continue;
|
|
143
|
+
const investment = high === "highDiscountRate" ? { highInvestmentRate: null } : {};
|
|
144
|
+
if (middle != null && middle >= top && middle <= bottom) {
|
|
145
|
+
const prices = next.highPrice != null && next.lowPrice != null && next.highPrice > next.lowPrice
|
|
146
|
+
? { highPrice: next.lowPrice, lowPrice: next.highPrice } : {};
|
|
147
|
+
next = { ...next, [high]: bottom, [low]: top, ...prices, ...investment };
|
|
148
|
+
} else {
|
|
149
|
+
next = { ...next, [high]: null, [low]: null, ...investment };
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
return next;
|
|
153
|
+
}
|
|
154
|
+
|
|
126
155
|
export function normalizeAuction(raw: unknown): TreasuryAuction | null {
|
|
127
156
|
if (!raw || typeof raw !== "object") return null;
|
|
128
157
|
const record = raw as TreasuryAuctionRaw;
|
|
@@ -132,7 +161,7 @@ export function normalizeAuction(raw: unknown): TreasuryAuction | null {
|
|
|
132
161
|
const cusip = (record.cusip ?? "").trim();
|
|
133
162
|
if (!secType || !auctionDate) return null;
|
|
134
163
|
|
|
135
|
-
return {
|
|
164
|
+
return inClearingOrder({
|
|
136
165
|
// A reopening reuses its original CUSIP but is auctioned on its own date,
|
|
137
166
|
// so CUSIP plus date is what keeps reopenings from collapsing into one row.
|
|
138
167
|
id: cusip ? `${cusip}|${auctionDate}` : `${secType}|${auctionDate}|${securityTerm}`,
|
|
@@ -145,9 +174,11 @@ export function normalizeAuction(raw: unknown): TreasuryAuction | null {
|
|
|
145
174
|
highInvestmentRate: toNumber(record.high_investment_rate),
|
|
146
175
|
highDiscountRate: toNumber(record.high_discnt_rate),
|
|
147
176
|
avgMedDiscountRate: toNumber(record.avg_med_discnt_rate),
|
|
177
|
+
lowDiscountRate: toNumber(record.low_discnt_rate),
|
|
148
178
|
highDiscountMargin: toNumber(record.high_discnt_margin),
|
|
149
179
|
highYield: toNumber(record.high_yield),
|
|
150
180
|
avgMedYield: toNumber(record.avg_med_yield),
|
|
181
|
+
lowYield: toNumber(record.low_yield),
|
|
151
182
|
highPrice: toNumber(record.high_price),
|
|
152
183
|
lowPrice: toNumber(record.low_price),
|
|
153
184
|
avgMedPrice: toNumber(record.avg_med_price),
|
|
@@ -158,7 +189,7 @@ export function normalizeAuction(raw: unknown): TreasuryAuction | null {
|
|
|
158
189
|
primaryDealerAccepted: toNumber(record.primary_dealer_accepted),
|
|
159
190
|
totalAccepted: toNumber(record.total_accepted),
|
|
160
191
|
offeringAmount: toNumber(record.offering_amt),
|
|
161
|
-
};
|
|
192
|
+
});
|
|
162
193
|
}
|
|
163
194
|
|
|
164
195
|
export function parseTreasuryAuctionsPayload(body: unknown): TreasuryAuction[] {
|