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
|
@@ -1,64 +1,145 @@
|
|
|
1
|
+
import { toBasisPoints } from "./basis-points";
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* The largest fall from a close to a later close (docs/usage.md, under `history`):
|
|
3
5
|
* the peak it fell from and the trough it reached, each with its date, the
|
|
4
6
|
* fall as a fraction of the peak, and the first later close back at the peak,
|
|
5
7
|
* if any. Read off closes, as returns are; a missing or non-positive close is
|
|
6
8
|
* passed over. The earliest of equal falls is the one named.
|
|
9
|
+
*
|
|
10
|
+
* A series in yield units (^TNX, a yield in percent) falls and rises by its
|
|
11
|
+
* level: the largest fall in percentage points, said in basis points (`bp`),
|
|
12
|
+
* and its largest rise as well (`maxRunUp`). A ratio of two yields is no
|
|
13
|
+
* move anyone reads.
|
|
7
14
|
*/
|
|
8
15
|
export interface MaxDrawdown {
|
|
9
16
|
peak: { date: string; close: number };
|
|
10
17
|
trough: { date: string; close: number };
|
|
11
18
|
/** trough / peak - 1: 0 when no close fell below an earlier one, else negative. */
|
|
12
19
|
drawdown: number;
|
|
20
|
+
/** A yield's fall, trough - peak in basis points to a tenth; absent for a price. */
|
|
21
|
+
bp?: number;
|
|
13
22
|
/** The first date after the trough whose close is back at the peak; null when none is in the series. */
|
|
14
23
|
recovered: string | null;
|
|
15
24
|
/** The last date in the series, which a fall not yet recovered is measured to. */
|
|
16
25
|
through: string;
|
|
17
26
|
}
|
|
18
27
|
|
|
28
|
+
/** A yield's largest rise from a close to a later close: the low it rose from and the high it reached. */
|
|
29
|
+
export interface MaxRunUp {
|
|
30
|
+
low: { date: string; close: number };
|
|
31
|
+
high: { date: string; close: number };
|
|
32
|
+
/** high - low in basis points, to a tenth: 0 when no close rose above an earlier one. */
|
|
33
|
+
bp: number;
|
|
34
|
+
/** The first date after the high whose close is back at the low; null when none is in the series. */
|
|
35
|
+
recovered: string | null;
|
|
36
|
+
through: string;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** How a series moves: a price by its return, a yield in percent by its level. */
|
|
40
|
+
export type DrawdownScale = "return" | "yield";
|
|
41
|
+
|
|
19
42
|
interface ClosePoint {
|
|
20
43
|
/** An ISO date or instant; points sort by it. */
|
|
21
44
|
date: string;
|
|
22
45
|
close: number | null | undefined;
|
|
23
46
|
}
|
|
24
47
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
.filter((point): point is { date: string; close: number } => typeof point.close === "number" && Number.isFinite(point.close)
|
|
48
|
+
function sortedCloses(points: readonly ClosePoint[], scale: DrawdownScale) {
|
|
49
|
+
// A yield can sit at or below zero; a price there is no close.
|
|
50
|
+
return points
|
|
51
|
+
.filter((point): point is { date: string; close: number } => typeof point.close === "number" && Number.isFinite(point.close)
|
|
52
|
+
&& (scale === "yield" || point.close > 0))
|
|
29
53
|
.toSorted((left, right) => left.date.localeCompare(right.date));
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** The series' max drawdown, or null with fewer than two closes. */
|
|
57
|
+
export function maxDrawdown(points: readonly ClosePoint[], scale: DrawdownScale = "return"): MaxDrawdown | null {
|
|
58
|
+
const closes = sortedCloses(points, scale);
|
|
30
59
|
if (closes.length < 2) return null;
|
|
60
|
+
const fallOf = (from: number, to: number) => scale === "yield" ? to - from : to / from - 1;
|
|
31
61
|
let peak = closes[0]!;
|
|
32
|
-
let worst = { peak, trough: peak,
|
|
62
|
+
let worst = { peak, trough: peak, fall: 0 };
|
|
33
63
|
for (const point of closes) {
|
|
34
64
|
if (point.close > peak.close) peak = point;
|
|
35
|
-
const fall =
|
|
36
|
-
if (fall < worst.
|
|
65
|
+
const fall = fallOf(peak.close, point.close);
|
|
66
|
+
if (fall < worst.fall) worst = { peak, trough: point, fall };
|
|
37
67
|
}
|
|
38
|
-
const recovered = worst.
|
|
68
|
+
const recovered = worst.fall < 0
|
|
39
69
|
? closes.find((point) => point.date > worst.trough.date && point.close >= worst.peak.close)?.date ?? null
|
|
40
70
|
: null;
|
|
41
71
|
return {
|
|
42
72
|
peak: { date: worst.peak.date, close: worst.peak.close },
|
|
43
73
|
trough: { date: worst.trough.date, close: worst.trough.close },
|
|
44
|
-
drawdown: worst.
|
|
74
|
+
drawdown: scale === "yield" ? (worst.peak.close > 0 ? worst.trough.close / worst.peak.close - 1 : 0) : worst.fall,
|
|
75
|
+
...(scale === "yield" ? { bp: toBasisPoints(worst.fall, 1) } : {}),
|
|
45
76
|
recovered,
|
|
46
77
|
through: closes.at(-1)!.date,
|
|
47
78
|
};
|
|
48
79
|
}
|
|
49
80
|
|
|
81
|
+
/** A yield series' largest rise from a close to a later close, or null with fewer than two closes. */
|
|
82
|
+
export function maxRunUp(points: readonly ClosePoint[]): MaxRunUp | null {
|
|
83
|
+
const closes = sortedCloses(points, "yield");
|
|
84
|
+
if (closes.length < 2) return null;
|
|
85
|
+
let low = closes[0]!;
|
|
86
|
+
let best = { low, high: low, rise: 0 };
|
|
87
|
+
for (const point of closes) {
|
|
88
|
+
if (point.close < low.close) low = point;
|
|
89
|
+
const rise = point.close - low.close;
|
|
90
|
+
if (rise > best.rise) best = { low, high: point, rise };
|
|
91
|
+
}
|
|
92
|
+
const recovered = best.rise > 0
|
|
93
|
+
? closes.find((point) => point.date > best.high.date && point.close <= best.low.close)?.date ?? null
|
|
94
|
+
: null;
|
|
95
|
+
return {
|
|
96
|
+
low: { date: best.low.date, close: best.low.close },
|
|
97
|
+
high: { date: best.high.date, close: best.high.close },
|
|
98
|
+
bp: toBasisPoints(best.rise, 1),
|
|
99
|
+
recovered,
|
|
100
|
+
through: closes.at(-1)!.date,
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
interface MoveTextOptions { basis: string; price: (value: number) => string; date?: (text: string) => string }
|
|
105
|
+
|
|
106
|
+
/** Whole basis points, signed; a move that rounds to nothing is still a move, which 0bp would hide. */
|
|
107
|
+
function bpText(bp: number): string {
|
|
108
|
+
const whole = Math.round(bp);
|
|
109
|
+
if (whole === 0) return bp === 0 ? "0bp" : "under 1bp";
|
|
110
|
+
return `${whole > 0 ? "+" : ""}${whole}bp`;
|
|
111
|
+
}
|
|
112
|
+
|
|
50
113
|
/**
|
|
51
114
|
* The report line: `Max drawdown -69.6% (daily closes): peak 53.25 on 2007-05-30, trough 16.19 on 2009-03-09,
|
|
52
|
-
* not back to the peak by 2009-12-31
|
|
115
|
+
* not back to the peak by 2009-12-31`; a yield's fall in bp: `Max drawdown -16bp (daily closes): ...`.
|
|
116
|
+
* `price` and `date` draw a close and a date as the table does.
|
|
53
117
|
*/
|
|
54
|
-
export function maxDrawdownText(
|
|
55
|
-
value: MaxDrawdown,
|
|
56
|
-
{ basis, price, date = (text) => text.slice(0, 10) }: { basis: string; price: (value: number) => string; date?: (text: string) => string },
|
|
57
|
-
): string {
|
|
118
|
+
export function maxDrawdownText(value: MaxDrawdown, { basis, price, date = (text) => text.slice(0, 10) }: MoveTextOptions): string {
|
|
58
119
|
const percent = (value.drawdown * 100).toFixed(1);
|
|
59
120
|
// A fall that rounds to nothing is still a fall, which -0.0% would hide.
|
|
60
|
-
const
|
|
61
|
-
|
|
121
|
+
const size = value.bp != null ? bpText(value.bp) : percent === "-0.0" ? "under 0.1%" : `${percent}%`;
|
|
122
|
+
const head = `Max drawdown ${size} (${basis})`;
|
|
123
|
+
if (value.peak.date === value.trough.date) return `${head}: no close fell below an earlier one`;
|
|
62
124
|
const back = value.recovered ? `back to the peak on ${date(value.recovered)}` : `not back to the peak by ${date(value.through)}`;
|
|
63
125
|
return `${head}: peak ${price(value.peak.close)} on ${date(value.peak.date)}, trough ${price(value.trough.close)} on ${date(value.trough.date)}, ${back}`;
|
|
64
126
|
}
|
|
127
|
+
|
|
128
|
+
/** `Max run-up +45bp (daily closes): low 3.998 on 2025-11-26, high 4.448 on 2026-01-14, not back to the low by 2026-02-02`. */
|
|
129
|
+
export function maxRunUpText(value: MaxRunUp, { basis, price, date = (text) => text.slice(0, 10) }: MoveTextOptions): string {
|
|
130
|
+
const head = `Max run-up ${bpText(value.bp)} (${basis})`;
|
|
131
|
+
if (value.low.date === value.high.date) return `${head}: no close rose above an earlier one`;
|
|
132
|
+
const back = value.recovered ? `back to the low on ${date(value.recovered)}` : `not back to the low by ${date(value.through)}`;
|
|
133
|
+
return `${head}: low ${price(value.low.close)} on ${date(value.low.date)}, high ${price(value.high.close)} on ${date(value.high.date)}, ${back}`;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/** A series' largest fall, and a yield's largest rise as well, with the lines a report says them in. */
|
|
137
|
+
export function closeMoves(points: readonly ClosePoint[], scale: DrawdownScale, text: MoveTextOptions): {
|
|
138
|
+
drawdown: MaxDrawdown | null;
|
|
139
|
+
runUp: MaxRunUp | null;
|
|
140
|
+
lines: string[];
|
|
141
|
+
} {
|
|
142
|
+
const drawdown = maxDrawdown(points, scale);
|
|
143
|
+
const runUp = scale === "yield" ? maxRunUp(points) : null;
|
|
144
|
+
return { drawdown, runUp, lines: [...drawdown ? [maxDrawdownText(drawdown, text)] : [], ...runUp ? [maxRunUpText(runUp, text)] : []] };
|
|
145
|
+
}
|
package/src/utils/shell-word.ts
CHANGED
|
@@ -6,3 +6,16 @@
|
|
|
6
6
|
export function shellWord(word: string): string {
|
|
7
7
|
return /^[\p{L}\p{N}._:@%+,/][\p{L}\p{N}._:@%+,/=-]*$/u.test(word) ? word : `'${word.replaceAll("'", "'\\''")}'`;
|
|
8
8
|
}
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* A word of a command the CLI suggests, which may be run in cmd.exe or
|
|
12
|
+
* PowerShell as well as a POSIX shell: as written when nothing in it is
|
|
13
|
+
* special (`NVDA`, `SAN:EPA`), else in double quotes, which all three read as
|
|
14
|
+
* typed (`"^SPX"`, `"Main Portfolio"`). cmd.exe reads `^` as its escape and
|
|
15
|
+
* dropped it, so `gloom quote ^SPX` asked for SPX there. A word with a
|
|
16
|
+
* character double quotes would expand is quoted as `shellWord` quotes it.
|
|
17
|
+
*/
|
|
18
|
+
export function commandWord(word: string): string {
|
|
19
|
+
if (/^[\p{L}\p{N}._:@%+,/][\p{L}\p{N}._:@%+,/=-]*$/u.test(word)) return word;
|
|
20
|
+
return /["$`!%\\]/.test(word) ? shellWord(word) : `"${word}"`;
|
|
21
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Terminal escape sequences: a CSI (`ESC [` or its one-byte C1 form) to its
|
|
3
|
+
* final byte, an OSC, DCS, SOS, PM or APC string to its BEL or ST (or the
|
|
4
|
+
* end), and the two-byte escapes.
|
|
5
|
+
*/
|
|
6
|
+
const ESCAPE_SEQUENCE =
|
|
7
|
+
/(?:\u001b\[|\u009b)[0-?]*[ -/]*[@-~]|(?:\u001b[\]PX^_]|[\u0090\u0098\u009d-\u009f])[^\u0007\u001b\u009c]*(?:\u0007|\u001b\\|\u009c)?|\u001b[ -/]*[0-~]/g;
|
|
8
|
+
/** Marks that turn, embed or hide text without showing themselves: bidi controls and zero-width characters. */
|
|
9
|
+
const INVISIBLE = /[\u061c\u200b-\u200f\u202a-\u202e\u2060-\u2064\u2066-\u2069\ufeff]/g;
|
|
10
|
+
/** Half of a broken surrogate pair, which no font draws and Postgres does not store. */
|
|
11
|
+
const LONE_SURROGATE = /[\ud800-\udbff](?![\udc00-\udfff])|(?<![\ud800-\udbff])[\udc00-\udfff]/g;
|
|
12
|
+
/** C0 and C1 controls: a line, a tab, a bell, what a terminal takes as a command. */
|
|
13
|
+
const CONTROL = /[\u0000-\u001f\u007f-\u009f]/g;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Text another person's app wrote (a shared pane's item, a share's title), as
|
|
17
|
+
* one line that draws as what it says: no terminal escape sequence, control
|
|
18
|
+
* character, bidi control or zero-width character, and no broken surrogate
|
|
19
|
+
* pair. The share service keeps an item's text to the same rule.
|
|
20
|
+
*/
|
|
21
|
+
export function plainUntrustedLine(value: string): string {
|
|
22
|
+
return value
|
|
23
|
+
.replace(ESCAPE_SEQUENCE, "")
|
|
24
|
+
.replace(INVISIBLE, "")
|
|
25
|
+
.replace(LONE_SURROGATE, "")
|
|
26
|
+
.replace(CONTROL, " ")
|
|
27
|
+
.replace(/\s+/g, " ")
|
|
28
|
+
.trim();
|
|
29
|
+
}
|