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,6 +1,7 @@
|
|
|
1
1
|
import { apiClient } from "../../api-client";
|
|
2
2
|
import type { NewsArticle } from "../../news/types";
|
|
3
|
-
import { mapCloudNewsArticle } from "../../sources/gloomberb-cloud/news";
|
|
3
|
+
import { ENERGY_NEWS_TOPIC, mapCloudNewsArticle, METALS_NEWS_TOPIC } from "../../sources/gloomberb-cloud/news";
|
|
4
|
+
import { centralBankNewsQueries, centralBankNewsTopic, storyNamesCentralBank, type CentralBank } from "../../utils/central-banks";
|
|
4
5
|
import { cliStyles } from "../../utils/cli-output";
|
|
5
6
|
import { logFailure } from "../../utils/log-failure";
|
|
6
7
|
import { commodityNamedIn, commoditySearchName, isCommodityName } from "../../market-data/commodity-names";
|
|
@@ -28,17 +29,31 @@ export function newsSearchText(args: readonly string[]): string | null {
|
|
|
28
29
|
/** How to type a word as text to search from a shell: `'"gold"'` keeps the quotes a shell would drop. */
|
|
29
30
|
export const quotedSearchCommand = (word: string) => `gloom news '"${word}"'`;
|
|
30
31
|
|
|
32
|
+
/**
|
|
33
|
+
* The words of a company's name, lower-cased, each run of letters split where
|
|
34
|
+
* its case changes from lower to upper: "PesoRama Inc." is peso, rama and inc.
|
|
35
|
+
*/
|
|
36
|
+
function companyNameWords(companyName: string): string[] {
|
|
37
|
+
return companyName
|
|
38
|
+
.replace(/(\p{Ll})(\p{Lu})/gu, "$1 $2")
|
|
39
|
+
.toLowerCase()
|
|
40
|
+
.split(/[^a-z]+/)
|
|
41
|
+
.filter(Boolean);
|
|
42
|
+
}
|
|
43
|
+
|
|
31
44
|
/**
|
|
32
45
|
* Whether a word typed for `news` may mean more than the listing it found:
|
|
33
46
|
* a plain word (letters only, three or more, typed with a lower-case letter,
|
|
34
|
-
* as a word is and a ticker rarely is) that is
|
|
35
|
-
*
|
|
36
|
-
*
|
|
47
|
+
* as a word is and a ticker rarely is) that is a whole word of the company's
|
|
48
|
+
* name, the name split at its case changes too ("gold" for Gold.com Inc.,
|
|
49
|
+
* "gap" for The Gap, "peso" for PesoRama Inc.); a word a name only starts
|
|
50
|
+
* with ("cost" in Costco, "app" in AppLovin) is not. The stories then decide
|
|
51
|
+
* (`wordMeansMore`).
|
|
37
52
|
*/
|
|
38
53
|
export function commonWordCandidate(typed: string, companyName: string | null | undefined): boolean {
|
|
39
54
|
const word = typed.trim();
|
|
40
55
|
if (!/^[A-Za-z]{3,}$/.test(word) || !/[a-z]/.test(word) || !companyName) return false;
|
|
41
|
-
return companyName
|
|
56
|
+
return companyNameWords(companyName).includes(word.toLowerCase());
|
|
42
57
|
}
|
|
43
58
|
|
|
44
59
|
/**
|
|
@@ -47,10 +62,11 @@ export function commonWordCandidate(typed: string, companyName: string | null |
|
|
|
47
62
|
* them filed under the ticker. "gold" is mostly the metal's market; "meta"
|
|
48
63
|
* is mostly Meta Platforms.
|
|
49
64
|
*/
|
|
50
|
-
export function wordMeansMore(stories: readonly NewsArticle[], symbol: string): boolean {
|
|
65
|
+
export function wordMeansMore(stories: readonly NewsArticle[], symbol: string, key = symbol): boolean {
|
|
51
66
|
if (stories.length < 3) return false;
|
|
52
|
-
|
|
53
|
-
const
|
|
67
|
+
// A listing outside the US is tagged with its venue (PESO:TSXV), a US one bare.
|
|
68
|
+
const tickers = new Set([symbol.toUpperCase(), key.toUpperCase()]);
|
|
69
|
+
const filed = stories.filter((story) => (story.tickers ?? []).some((entry) => tickers.has(entry.toUpperCase()))).length;
|
|
54
70
|
return filed * 2 < stories.length;
|
|
55
71
|
}
|
|
56
72
|
|
|
@@ -126,15 +142,27 @@ export function closestStoriesReason(text: string): string {
|
|
|
126
142
|
|
|
127
143
|
/** A metal's market news, for what `news` was given: its name, its future, or its board code. */
|
|
128
144
|
export interface MetalNewsRoute {
|
|
129
|
-
/** The metal the stories are searched for, in METALS: "gold". */
|
|
145
|
+
/** The metal the stories are searched for, in METALS: "gold"; for oil, in ENERGY. */
|
|
130
146
|
metal: string;
|
|
131
147
|
contract: FuturesContract;
|
|
132
148
|
/** Why what was typed reads as the metal, under the heading; null for the metal's own name. */
|
|
133
149
|
reason: string | null;
|
|
134
150
|
/** The name as typed, which in capitals may be a ticker too ("gold", GOLD for Gold.com Inc.). */
|
|
135
151
|
word: string | null;
|
|
152
|
+
/** The market's stories the search is kept to: METALS, or ENERGY for oil. */
|
|
153
|
+
topic: string;
|
|
154
|
+
/** What the heading calls those stories: "Metals", "Energy". */
|
|
155
|
+
label: string;
|
|
136
156
|
}
|
|
137
157
|
|
|
158
|
+
/**
|
|
159
|
+
* The words that are the oil market, searched in its energy stories as a
|
|
160
|
+
* metal's name is in METALS: "oil" otherwise found Oil India's stories under
|
|
161
|
+
* the iPath ETN that trades as OIL, and stories that name oil are mostly
|
|
162
|
+
* companies'. Brent, gas and the rest keep their futures route.
|
|
163
|
+
*/
|
|
164
|
+
const ENERGY_MARKET_WORDS: ReadonlySet<string> = new Set(["oil", "crude"]);
|
|
165
|
+
|
|
138
166
|
/**
|
|
139
167
|
* A metal's market news for a metal's future (GC=F, SI=F, HG=F, PL=F, PA=F,
|
|
140
168
|
* ALI=F) or its name typed as a word (gold, Silver, copper): news filed under
|
|
@@ -148,30 +176,69 @@ export function metalNewsRoute(typed: string): MetalNewsRoute | null {
|
|
|
148
176
|
if (/=F$/i.test(text)) {
|
|
149
177
|
const contract = futuresBoardContract(text);
|
|
150
178
|
const metal = contract?.sector === "metals" ? commoditySearchName(contract) : null;
|
|
151
|
-
return contract && metal ? { metal, contract, reason: `the commodity ${contract.symbol} trades`, word: null } : null;
|
|
179
|
+
return contract && metal ? { metal, contract, reason: `the commodity ${contract.symbol} trades`, word: null, ...METALS_MARKET } : null;
|
|
152
180
|
}
|
|
153
181
|
if (!/^\p{L}{3,}$/u.test(text) || !/\p{Ll}/u.test(text)) return null;
|
|
154
182
|
// One word of letters: the metal's names are one word each (gold, aluminium).
|
|
155
183
|
const contract = commodityNamedIn(text);
|
|
156
|
-
|
|
184
|
+
if (contract?.sector === "metals") return { metal: text.toLowerCase(), contract, reason: null, word: text, ...METALS_MARKET };
|
|
185
|
+
return contract?.sector === "energy" && ENERGY_MARKET_WORDS.has(text.toLowerCase())
|
|
186
|
+
? { metal: text.toLowerCase(), contract, reason: null, word: text, ...ENERGY_MARKET } : null;
|
|
157
187
|
}
|
|
158
188
|
|
|
189
|
+
const METALS_MARKET = { topic: METALS_NEWS_TOPIC, label: "Metals" } as const;
|
|
190
|
+
const ENERGY_MARKET = { topic: ENERGY_NEWS_TOPIC, label: "Energy" } as const;
|
|
191
|
+
|
|
159
192
|
/** A metal's market news for its board code typed bare (GC, SI, HG) where no listing answers to it. */
|
|
160
193
|
export function metalCodeNewsRoute(typed: string): MetalNewsRoute | null {
|
|
161
194
|
const code = typed.trim().toUpperCase();
|
|
162
195
|
const contract = /^[A-Z]{2,3}$/.test(code) ? futuresBoardContract(code) : null;
|
|
163
196
|
const metal = contract?.sector === "metals" ? commoditySearchName(contract) : null;
|
|
164
|
-
return contract && metal ? { metal, contract, reason: `${code} is the futures board's code for ${contract.name}`, word: null } : null;
|
|
197
|
+
return contract && metal ? { metal, contract, reason: `${code} is the futures board's code for ${contract.name}`, word: null, ...METALS_MARKET } : null;
|
|
165
198
|
}
|
|
166
199
|
|
|
167
200
|
/** The line above a metal's market news: "Metals news matching "gold"", with why what was typed reads as the metal. */
|
|
168
201
|
export function metalNewsHeading(route: MetalNewsRoute): string {
|
|
169
|
-
return `${cliStyles.bold(
|
|
202
|
+
return `${cliStyles.bold(`${route.label} news matching "${route.metal}"`)}${route.reason ? cliStyles.muted(` · ${route.reason}`) : ""}`;
|
|
170
203
|
}
|
|
171
204
|
|
|
172
205
|
/** What a metal's market news says when no story is tagged METALS: every story that names it is one search away. */
|
|
173
206
|
export function noMetalStoriesMessage(route: MetalNewsRoute): string {
|
|
174
|
-
return `No
|
|
207
|
+
return `No ${route.label.toLowerCase()} stories match "${route.metal}". For every story that mentions it, try: ${quotedSearchCommand(route.metal)}`;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* A central bank's latest decision stories, for its name or the committee and
|
|
212
|
+
* rate its decisions go by (`centralBankInNews`): the text as typed and every
|
|
213
|
+
* name it is reported under (`centralBankNewsQueries`), each with what else
|
|
214
|
+
* the text asks (`centralBankNewsTopic`: "rate cut" of "fed rate cut"),
|
|
215
|
+
* searched at once, newest first, and only the stories that name the bank.
|
|
216
|
+
* "banxico" alone found May's cut, not November's, reported as the Bank of
|
|
217
|
+
* Mexico's. Fails only when every search failed.
|
|
218
|
+
*/
|
|
219
|
+
export async function searchCentralBankStories(bank: CentralBank, limit: number, typed = ""): Promise<NewsArticle[]> {
|
|
220
|
+
const topic = centralBankNewsTopic(bank, typed);
|
|
221
|
+
const queries = new Map<string, string>();
|
|
222
|
+
for (const query of [typed.trim(), ...centralBankNewsQueries(bank).map((name) => topic ? `${name} ${topic}` : name)]) {
|
|
223
|
+
if (query && !queries.has(query.toLowerCase())) queries.set(query.toLowerCase(), query);
|
|
224
|
+
}
|
|
225
|
+
const answers = await Promise.allSettled([...queries.values()].map((query) => searchNewsStories(query, limit)));
|
|
226
|
+
const found = answers.flatMap((answer) => answer.status === "fulfilled" ? answer.value : []);
|
|
227
|
+
const failed = answers.find((answer): answer is PromiseRejectedResult => answer.status === "rejected");
|
|
228
|
+
if (failed && answers.every((answer) => answer.status === "rejected")) throw failed.reason;
|
|
229
|
+
const seen = new Set<string>();
|
|
230
|
+
const unique = found.filter((article) => {
|
|
231
|
+
const key = article.id || article.url;
|
|
232
|
+
if (seen.has(key) || !storyNamesCentralBank(bank, `${article.title} ${article.summary ?? ""}`)) return false;
|
|
233
|
+
seen.add(key);
|
|
234
|
+
return true;
|
|
235
|
+
});
|
|
236
|
+
return newestFirst(unique).slice(0, limit);
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
/** What the heading says of a central bank's stories: "the Bank of Mexico's stories, under each name it is reported by". */
|
|
240
|
+
export function centralBankNewsReason(bank: CentralBank): string {
|
|
241
|
+
return `the ${bank.name}'s stories, under each name it is reported by`;
|
|
175
242
|
}
|
|
176
243
|
|
|
177
244
|
/** The futures news route a search offers when no story matches it: `gloom news KC=F` for "arabica". */
|
|
@@ -44,10 +44,13 @@ import {
|
|
|
44
44
|
eventCountry,
|
|
45
45
|
matchesCountry,
|
|
46
46
|
matchesEventSearch,
|
|
47
|
+
policyDecisionsNamed,
|
|
47
48
|
matchesImpact,
|
|
48
49
|
NO_CONSENSUS_NOTE,
|
|
49
50
|
noScheduledReleasesMessage,
|
|
50
51
|
parseCountryFilter,
|
|
52
|
+
listingEnd,
|
|
53
|
+
pastReleaseListing,
|
|
51
54
|
shortCalendarEnd,
|
|
52
55
|
type CountryFilter,
|
|
53
56
|
type ImpactFilter,
|
|
@@ -409,6 +412,19 @@ function econEmptyMessage(from: string | null, listedThrough: string | null, sto
|
|
|
409
412
|
: `No matching events${range} through ${listedThrough}.`;
|
|
410
413
|
}
|
|
411
414
|
|
|
415
|
+
/**
|
|
416
|
+
* What an empty search for a bank's own names could mean: `selic` is the
|
|
417
|
+
* Copom's decision, none of which falls in the window, and CBR has the rate
|
|
418
|
+
* and its next decision. Only a bank of the countries asked for; null for
|
|
419
|
+
* any other search.
|
|
420
|
+
*/
|
|
421
|
+
function policyDecisionHint(search: string, countries: string): string | null {
|
|
422
|
+
const named = policyDecisionsNamed(search, countries);
|
|
423
|
+
if (named.length === 0) return null;
|
|
424
|
+
const events = named.map(({ country, event }) => `${event} (${country})`).join(", ");
|
|
425
|
+
return `"${search}" is the ${events}; none falls in this window. The rate and its next decision: gloom fn CBR.`;
|
|
426
|
+
}
|
|
427
|
+
|
|
412
428
|
/**
|
|
413
429
|
* A date option, read as an ISO date; null when it was not given. `expand`
|
|
414
430
|
* reads a shorthand as a full date first, and `form` is how the message names
|
|
@@ -510,10 +526,10 @@ async function runEcon(args: string[], ctx: Parameters<CliCommandDef["execute"]>
|
|
|
510
526
|
// alone keeps the newest events of the whole calendar, the past week's too.
|
|
511
527
|
const from = fromOption ?? (ctx.cliOptions.tail != null ? null : new Date(todayStart).toISOString().slice(0, 10));
|
|
512
528
|
const fromTime = from == null ? Number.NEGATIVE_INFINITY : Date.parse(`${from}T00:00:00Z`);
|
|
513
|
-
|
|
514
|
-
const listedThrough =
|
|
529
|
+
// The last day the listing reaches, as Gloom Cloud says it: past it, it lists each central bank's next decision.
|
|
530
|
+
const listedThrough = listingEnd(events, past?.listedThrough);
|
|
515
531
|
// A calendar that stops short of a week ahead says so under the table.
|
|
516
|
-
const listedAfter = shortCalendarEnd(events, Math.max(todayStart, fromTime)) ? `No events listed after ${listedThrough}` : null;
|
|
532
|
+
const listedAfter = shortCalendarEnd(events, Math.max(todayStart, fromTime), past?.listedThrough) ? `No events listed after ${listedThrough}` : null;
|
|
517
533
|
// A day before anything the calendar holds says where its listing starts.
|
|
518
534
|
const firstEvent = events.reduce<Date | null>((first, event) => (!first || event.date < first ? event.date : first), null);
|
|
519
535
|
const listedFrom = firstEvent ? firstEvent.toISOString().slice(0, 10) : null;
|
|
@@ -572,9 +588,13 @@ async function runEcon(args: string[], ctx: Parameters<CliCommandDef["execute"]>
|
|
|
572
588
|
consensusReadAt: event.consensus?.readAt ?? null,
|
|
573
589
|
};
|
|
574
590
|
});
|
|
575
|
-
// A filter of countries only, none of which has anything in the window, says so as its empty list
|
|
591
|
+
// A filter of countries only, none of which has anything in the window, says so as its empty list, with where
|
|
592
|
+
// the listing ends.
|
|
576
593
|
const allUnscheduled = unscheduled.length > 0 && unscheduled.length === country.split(",").length;
|
|
577
|
-
|
|
594
|
+
// Rows after the listing's end are each bank's next decision, and say so where the end is said.
|
|
595
|
+
const listedPast = listed.some(pastReleaseListing)
|
|
596
|
+
? `No releases listed after ${listedThrough}; the rows after it are each central bank's next decision` : null;
|
|
597
|
+
const notes = [listedBefore, listedPast ?? listedAfter, ...(rows.length > 0 ? blankTimeNotes(rows) : []),
|
|
578
598
|
rows.length > 0 && unscheduled.length > 0 ? noScheduledReleasesMessage(unscheduled) : null,
|
|
579
599
|
// A dash under Forecast on a release still to come is a consensus not in yet, not a missing figure.
|
|
580
600
|
listed.some(awaitsConsensus) ? NO_CONSENSUS_NOTE : null]
|
|
@@ -592,7 +612,8 @@ async function runEcon(args: string[], ctx: Parameters<CliCommandDef["execute"]>
|
|
|
592
612
|
}, {
|
|
593
613
|
dateKey: "date",
|
|
594
614
|
defaultLimit: 50,
|
|
595
|
-
empty: allUnscheduled ? noScheduledReleasesMessage(unscheduled
|
|
615
|
+
empty: allUnscheduled ? noScheduledReleasesMessage(unscheduled, listedThrough)
|
|
616
|
+
: [econEmptyMessage(from, listedThrough, listedAfter != null), search == null ? null : policyDecisionHint(search, country)].filter(Boolean).join(" "),
|
|
596
617
|
...(footnote ? { footnote } : {}),
|
|
597
618
|
// What the text says under the table, a script reads in the CSV's closing lines.
|
|
598
619
|
exportNotes: notes,
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { getDataDir } from "../../data/config/store";
|
|
2
2
|
import type { CliCommandContext } from "../../types/plugin";
|
|
3
|
-
import { sendRemoteControlRequest } from "../../remote/client";
|
|
3
|
+
import { RemoteAppError, RemoteAppNotRunningError, sendRemoteControlRequest } from "../../remote/client";
|
|
4
4
|
import type { RemoteAppKind, RemoteControlRequest, RemoteControlResponse } from "../../remote/types";
|
|
5
5
|
import { CLI_COMMAND_GROUPS } from "../help";
|
|
6
6
|
import type { BuiltinCliCommandDef } from "../command-options";
|
|
7
|
+
import { failWithError } from "../errors";
|
|
7
8
|
|
|
8
9
|
interface RemoteArgs {
|
|
9
10
|
args: string[];
|
|
@@ -34,7 +35,7 @@ export const remoteCliCommand: BuiltinCliCommandDef = {
|
|
|
34
35
|
{ flags: "--interval <ms>", description: "How often watch polls, at least 100 (default 1000)" },
|
|
35
36
|
{ flags: "--dry-run", description: "Check a call, patch, or batch without applying it" },
|
|
36
37
|
],
|
|
37
|
-
examples: ["remote
|
|
38
|
+
examples: ["remote help", "remote get app://snapshot", "remote get app://form", "remote watch app://layout/current --limit 5"],
|
|
38
39
|
},
|
|
39
40
|
execute: async (rawArgs, ctx) => {
|
|
40
41
|
const parsed = parseRemoteArgs(rawArgs);
|
|
@@ -46,10 +47,12 @@ export const remoteCliCommand: BuiltinCliCommandDef = {
|
|
|
46
47
|
|
|
47
48
|
// No data folder means this profile never opened the app, so none is running to drive.
|
|
48
49
|
const dataDir = await getDataDir();
|
|
49
|
-
if (!dataDir)
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
50
|
+
if (!dataDir) failToReachApp(new RemoteAppNotRunningError(parsed.appKind));
|
|
51
|
+
const send = (request: RemoteControlRequest) => sendRemoteControlRequest(request, { dataDir, appKind: parsed.appKind })
|
|
52
|
+
.catch((error: unknown) => {
|
|
53
|
+
if (error instanceof RemoteAppError) failToReachApp(error);
|
|
54
|
+
throw error;
|
|
55
|
+
});
|
|
53
56
|
|
|
54
57
|
if (action === "watch") {
|
|
55
58
|
const resource = parsed.args[1];
|
|
@@ -59,25 +62,21 @@ export const remoteCliCommand: BuiltinCliCommandDef = {
|
|
|
59
62
|
}
|
|
60
63
|
const limit = ctx.cliOptions.limit ?? Number.POSITIVE_INFINITY;
|
|
61
64
|
for (let index = 0; index < limit; index += 1) {
|
|
62
|
-
|
|
63
|
-
dataDir,
|
|
64
|
-
appKind: parsed.appKind,
|
|
65
|
-
});
|
|
66
|
-
printRemoteResponse(response, ctx);
|
|
65
|
+
printRemoteResponse(await send({ type: "get", resource }), ctx);
|
|
67
66
|
if (index < limit - 1) await new Promise((resolve) => setTimeout(resolve, parsed.intervalMs));
|
|
68
67
|
}
|
|
69
68
|
return;
|
|
70
69
|
}
|
|
71
70
|
|
|
72
|
-
|
|
73
|
-
const response = await sendRemoteControlRequest(request, {
|
|
74
|
-
dataDir,
|
|
75
|
-
appKind: parsed.appKind,
|
|
76
|
-
});
|
|
77
|
-
printRemoteResponse(response, ctx);
|
|
71
|
+
printRemoteResponse(await send(buildRemoteRequest(action, parsed, ctx.cliOptions.dryRun)), ctx);
|
|
78
72
|
},
|
|
79
73
|
};
|
|
80
74
|
|
|
75
|
+
/** No app answers, two do, or one cannot be reached from here: with how to start one, which to pick, or what may block it. */
|
|
76
|
+
function failToReachApp(error: RemoteAppError): never {
|
|
77
|
+
return failWithError({ code: error.code, message: error.message, details: error.details });
|
|
78
|
+
}
|
|
79
|
+
|
|
81
80
|
function parseRemoteArgs(rawArgs: string[]): RemoteArgs {
|
|
82
81
|
const args: string[] = [];
|
|
83
82
|
let appKind: RemoteAppKind | undefined;
|
|
@@ -283,7 +283,7 @@ export function createSystemCliCommands(): CliCommandDef[] {
|
|
|
283
283
|
"config set timezone Asia/Tokyo",
|
|
284
284
|
"config get keybindings",
|
|
285
285
|
"config set keybindings.actions.ticker-search \"Ctrl+T\"",
|
|
286
|
-
"config set keybindings.commands.Alt+
|
|
286
|
+
"config set keybindings.commands.Alt+D \"DES AAPL\"",
|
|
287
287
|
],
|
|
288
288
|
},
|
|
289
289
|
execute: async (args, ctx) => {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { logFailure } from "../../utils/log-failure";
|
|
2
|
+
import { ebitdaLacksDepreciation } from "../../utils/ebitda";
|
|
2
3
|
import { formatShortDate, parseDisplayDate } from "../../utils/datetime-format";
|
|
3
4
|
import { formatReportedMoney, REPORTING_CURRENCY_NOT_SOURCED } from "../../utils/reported-money";
|
|
4
5
|
import {
|
|
@@ -226,7 +227,8 @@ function buildStatementMetrics(
|
|
|
226
227
|
["Net Income", netIncome],
|
|
227
228
|
["Income incl. NCI", income(statement.netIncomeIncludingNoncontrollingInterests)],
|
|
228
229
|
["Income Common", income(statement.netIncomeCommonStockholders)],
|
|
229
|
-
|
|
230
|
+
// Operating income plus D&A; without D&A there is none, and the line says why.
|
|
231
|
+
["EBITDA", ebitdaLacksDepreciation(statement) ? "no D&A" : money(statement.ebitda)],
|
|
230
232
|
["Operating Cash Flow", money(statement.operatingCashFlow)],
|
|
231
233
|
["Free Cash Flow", money(statement.freeCashFlow)],
|
|
232
234
|
["Cash", balance("cashAndCashEquivalents")],
|
package/src/cli/early-command.ts
CHANGED
|
@@ -18,6 +18,8 @@ export async function dispatchEarlyCommand(args: string[]): Promise<boolean> {
|
|
|
18
18
|
}
|
|
19
19
|
const token = foldTypedText(parsed.args[0] ?? "").trim().toLowerCase();
|
|
20
20
|
if (token !== versionCommand.name && !versionCommand.aliases?.includes(token)) return false;
|
|
21
|
+
// A file to write is the regular dispatcher's to save.
|
|
22
|
+
if (parsed.options.output !== undefined) return false;
|
|
21
23
|
const options = parsed.options;
|
|
22
24
|
setCliColorEnabledOverride(options.color);
|
|
23
25
|
setCliWidthOverride(options.width ?? null);
|
package/src/cli/errors.ts
CHANGED
|
@@ -26,6 +26,15 @@ function unreachableHint(): string {
|
|
|
26
26
|
: "Check the internet connection, then try again.";
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
+
/**
|
|
30
|
+
* An answer of the data service that a source it reads failed and nothing it
|
|
31
|
+
* kept could stand in (the 13F source down): the service was reached, and
|
|
32
|
+
* asked again later it may answer.
|
|
33
|
+
*/
|
|
34
|
+
export function isSourceUnavailableAnswer(error: unknown): error is ApiRequestError {
|
|
35
|
+
return error instanceof ApiRequestError && error.code === SOURCE_UNAVAILABLE_CODE;
|
|
36
|
+
}
|
|
37
|
+
|
|
29
38
|
export interface CliErrorContext {
|
|
30
39
|
/** The command that failed, used to point at its help. */
|
|
31
40
|
command?: string;
|
|
@@ -124,7 +133,7 @@ function cliErrorObject(error: unknown): CliErrorObject {
|
|
|
124
133
|
return unreachableError();
|
|
125
134
|
}
|
|
126
135
|
// A source failed (a timeout, a rate limit) where none had the data to answer: asked again it may.
|
|
127
|
-
if (isSourceFailure(error)) {
|
|
136
|
+
if (isSourceFailure(error) || isSourceUnavailableAnswer(error)) {
|
|
128
137
|
return { code: SOURCE_UNAVAILABLE_CODE, message: error instanceof Error ? error.message : String(error), retryable: true };
|
|
129
138
|
}
|
|
130
139
|
// A listing read the data service failed to answer twice: said in Gloom's words. Any other 5xx keeps the server's.
|
package/src/cli/fx-forward.ts
CHANGED
|
@@ -61,6 +61,9 @@ export interface ImpliedForward {
|
|
|
61
61
|
premiumPercent: number;
|
|
62
62
|
/** The same premium a year: `premiumPercent` × 360 / days. */
|
|
63
63
|
annualizedPercent: number;
|
|
64
|
+
/** What one unit of the base and of the quote currency grows to over the tenor at its own rate. */
|
|
65
|
+
baseGrowth: number;
|
|
66
|
+
quoteGrowth: number;
|
|
64
67
|
}
|
|
65
68
|
|
|
66
69
|
/**
|
|
@@ -72,11 +75,12 @@ export interface ImpliedForward {
|
|
|
72
75
|
export function impliedForward(
|
|
73
76
|
spot: number,
|
|
74
77
|
days: number,
|
|
75
|
-
base: Pick<CloudShortRate, "dayCountBasis"> & { value: number },
|
|
76
|
-
quote: Pick<CloudShortRate, "dayCountBasis"> & { value: number; currency: string },
|
|
78
|
+
base: Pick<CloudShortRate, "dayCountBasis" | "compounding"> & { value: number },
|
|
79
|
+
quote: Pick<CloudShortRate, "dayCountBasis" | "compounding"> & { value: number; currency: string },
|
|
77
80
|
): ImpliedForward {
|
|
78
|
-
const
|
|
79
|
-
const
|
|
81
|
+
const baseGrowth = shortRateGrowth(base, days);
|
|
82
|
+
const quoteGrowth = shortRateGrowth(quote, days);
|
|
83
|
+
const forward = spot * quoteGrowth / baseGrowth;
|
|
80
84
|
const pointSize = forwardPointSize(quote.currency);
|
|
81
85
|
const premiumPercent = (forward / spot - 1) * 100;
|
|
82
86
|
return {
|
|
@@ -86,9 +90,34 @@ export function impliedForward(
|
|
|
86
90
|
pointSize,
|
|
87
91
|
premiumPercent,
|
|
88
92
|
annualizedPercent: premiumPercent * 360 / days,
|
|
93
|
+
baseGrowth,
|
|
94
|
+
quoteGrowth,
|
|
89
95
|
};
|
|
90
96
|
}
|
|
91
97
|
|
|
98
|
+
/**
|
|
99
|
+
* What one unit grows to over `days` at a short rate: simple interest on its
|
|
100
|
+
* day count; for a rate compounded over 252 business days (CDI),
|
|
101
|
+
* (1 + r)^(days / 365), business days taken as 252/365 of the calendar days;
|
|
102
|
+
* for one compounded daily on ACT/365 (ZARONIA), (1 + r / 365)^days.
|
|
103
|
+
*/
|
|
104
|
+
function shortRateGrowth(rate: Pick<CloudShortRate, "dayCountBasis" | "compounding"> & { value: number }, days: number): number {
|
|
105
|
+
if (rate.compounding === "business-252") return (1 + rate.value / 100) ** (days / 365);
|
|
106
|
+
if (rate.compounding === "daily-365") return (1 + rate.value / 100 / 365) ** days;
|
|
107
|
+
return 1 + (rate.value / 100) * days / rate.dayCountBasis;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* `(1 + 3.92% × 92/360)`, `(1 + 13.65%)^(92/365)` for a rate compounded over
|
|
112
|
+
* business days, `(1 + 7.099%/365)^92` for one compounded daily: one leg of
|
|
113
|
+
* the parity, as `fx --forward` prints it.
|
|
114
|
+
*/
|
|
115
|
+
export function shortRateGrowthText(rate: Pick<CloudShortRate, "dayCountBasis" | "compounding"> & { value: number }, days: number): string {
|
|
116
|
+
if (rate.compounding === "business-252") return `(1 + ${formatRatePercent(rate.value)})^(${days}/365)`;
|
|
117
|
+
if (rate.compounding === "daily-365") return `(1 + ${formatRatePercent(rate.value)}/365)^${days}`;
|
|
118
|
+
return `(1 + ${formatRatePercent(rate.value)} × ${days}/${rate.dayCountBasis})`;
|
|
119
|
+
}
|
|
120
|
+
|
|
92
121
|
/** A rate the forward can use: listed for the currency, with a value. */
|
|
93
122
|
export type ShortRateLookup = { rate: CloudShortRate & { value: number } } | { error: string };
|
|
94
123
|
|
|
@@ -109,7 +138,7 @@ export function shortRateFor(currency: string, rates: readonly CloudShortRate[])
|
|
|
109
138
|
}
|
|
110
139
|
|
|
111
140
|
/** `6.776%`: a rate as its publisher prints it, to four decimals at most. */
|
|
112
|
-
|
|
141
|
+
function formatRatePercent(value: number): string {
|
|
113
142
|
return `${Number(value.toFixed(4))}%`;
|
|
114
143
|
}
|
|
115
144
|
|
|
@@ -124,7 +153,60 @@ export function formatForwardPoints(points: number): string {
|
|
|
124
153
|
return `${points >= 0 ? "+" : ""}${points.toFixed(1)}`;
|
|
125
154
|
}
|
|
126
155
|
|
|
127
|
-
/**
|
|
156
|
+
/**
|
|
157
|
+
* `TIIE 28d 6.776% (Banco de México, 2026-10-20; ACT/360)`, `CDI 13.65% (Banco Central do Brasil, 2026-11-05; BUS/252 compounded)`,
|
|
158
|
+
* `ZARONIA 7.099% (South African Reserve Bank, 2026-11-05; ACT/365 compounded daily)`.
|
|
159
|
+
*/
|
|
128
160
|
export function describeShortRate(rate: CloudShortRate & { value: number }): string {
|
|
129
|
-
|
|
161
|
+
const basis = rate.compounding === "business-252" ? "BUS/252 compounded"
|
|
162
|
+
: rate.compounding === "daily-365" ? "ACT/365 compounded daily" : `ACT/${rate.dayCountBasis}`;
|
|
163
|
+
return `${rate.name} ${formatRatePercent(rate.value)} (${rate.publisher}, ${rate.asOf ?? "undated"}; ${basis})`;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* The carry of a forward on an amount of the pair's base currency, above
|
|
168
|
+
* zero: the forward points on it over the tenor, in the quote currency. The
|
|
169
|
+
* side that holds the currency whose rate earns more over the tenor (the
|
|
170
|
+
* larger growth factor) earns it: with the forward above spot, the seller of
|
|
171
|
+
* the base currency forward (short the pair); below spot, the buyer (long).
|
|
172
|
+
* A forward at spot has no carry.
|
|
173
|
+
*/
|
|
174
|
+
export interface ForwardCarry {
|
|
175
|
+
/** The amount, in the pair's base currency. */
|
|
176
|
+
amount: number;
|
|
177
|
+
/** Amount × |forward - spot|, in the quote currency: what one side pays the other. */
|
|
178
|
+
value: number;
|
|
179
|
+
/** The side that earns it; null when the forward is at spot. */
|
|
180
|
+
earnedBy: "long" | "short" | null;
|
|
181
|
+
/** The currency whose rate earns more over the tenor, from the two growth factors; null when they are equal. */
|
|
182
|
+
higher: "base" | "quote" | null;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
export function forwardCarry(
|
|
186
|
+
amount: number,
|
|
187
|
+
implied: Pick<ImpliedForward, "spot" | "forward" | "baseGrowth" | "quoteGrowth">,
|
|
188
|
+
): ForwardCarry {
|
|
189
|
+
const difference = implied.forward - implied.spot;
|
|
190
|
+
return {
|
|
191
|
+
amount,
|
|
192
|
+
value: Math.abs(amount * difference),
|
|
193
|
+
earnedBy: difference > 0 ? "short" : difference < 0 ? "long" : null,
|
|
194
|
+
higher: implied.quoteGrowth > implied.baseGrowth ? "quote" : implied.quoteGrowth < implied.baseGrowth ? "base" : null,
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* Who earns the carry and who pays it, by side of the pair: `Short USD/MXN
|
|
200
|
+
* (selling USD forward) earns it and long USD/MXN (buying USD forward) pays
|
|
201
|
+
* it: MXN's rate earns more over the 30 days.` A forward at spot has none.
|
|
202
|
+
*/
|
|
203
|
+
export function describeCarrySides(carry: ForwardCarry, base: string, quote: string, days: number): string {
|
|
204
|
+
if (carry.earnedBy == null || carry.higher == null) {
|
|
205
|
+
return `No carry: at these rates ${base} and ${quote} earn the same over the ${days} days, so the forward is at spot.`;
|
|
206
|
+
}
|
|
207
|
+
const short = `short ${base}/${quote} (selling ${base} forward)`;
|
|
208
|
+
const long = `long ${base}/${quote} (buying ${base} forward)`;
|
|
209
|
+
const [earns, pays] = carry.earnedBy === "short" ? [short, long] : [long, short];
|
|
210
|
+
const higher = carry.higher === "quote" ? quote : base;
|
|
211
|
+
return `${earns.charAt(0).toUpperCase()}${earns.slice(1)} earns it and ${pays} pays it: ${higher}'s rate earns more over the ${days} days.`;
|
|
130
212
|
}
|
package/src/cli/fx-pair.ts
CHANGED
|
@@ -161,7 +161,7 @@ export function parseFxArgs(words: readonly string[], baseCurrency: string): FxA
|
|
|
161
161
|
* An amount in its currency's minor units, grouped (1,234.50 EUR; 1,235 JPY).
|
|
162
162
|
* One too small for them keeps six significant figures instead of reading 0.
|
|
163
163
|
*/
|
|
164
|
-
function formatFxAmount(amount: number, currency: string): string {
|
|
164
|
+
export function formatFxAmount(amount: number, currency: string): string {
|
|
165
165
|
const digits = currencyMinorDigits(currency);
|
|
166
166
|
const rounded = Number(amount.toFixed(digits));
|
|
167
167
|
if (rounded === 0 && amount !== 0) return `${formatFxRate(amount)} ${currency}`;
|
package/src/cli/fx-quote-rate.ts
CHANGED
|
@@ -160,6 +160,29 @@ async function metalFromFuture(
|
|
|
160
160
|
};
|
|
161
161
|
}
|
|
162
162
|
|
|
163
|
+
/**
|
|
164
|
+
* The rate's move on the day, as `quote` gives its pair's: the rate against
|
|
165
|
+
* the same reading at the previous daily closes (the pair's own close, or
|
|
166
|
+
* each dollar pair's for a cross), in percent. Null for a rate priced from a
|
|
167
|
+
* future, or when a close is missing.
|
|
168
|
+
*/
|
|
169
|
+
export function fxQuoteRateMove(rate: FxQuoteRate): { percent: number; previousRate: number } | null {
|
|
170
|
+
if (rate.derivedFrom) return null;
|
|
171
|
+
const closes = rate.quotes.map(({ quote }) => quote.previousClose);
|
|
172
|
+
if (!closes.every(isUsableRate)) return null;
|
|
173
|
+
let previousRate: number;
|
|
174
|
+
if (rate.viaUsd) {
|
|
175
|
+
// Each dollar pair as USD per unit, as the cross is read: EURUSD=X as sent, USDJPY=X inverted.
|
|
176
|
+
const [from, into] = rate.quotes.map(({ symbol }, index) => symbol.startsWith("USD") ? 1 / closes[index]! : closes[index]!) as [number, number];
|
|
177
|
+
previousRate = from / into;
|
|
178
|
+
} else {
|
|
179
|
+
// The pair's own quote, inverted when the rate is (JPY/EUR read from EURJPY=X).
|
|
180
|
+
previousRate = rate.rate === rate.quotes[0]!.figure ? closes[0]! : 1 / closes[0]!;
|
|
181
|
+
}
|
|
182
|
+
const percent = (rate.rate / previousRate - 1) * 100;
|
|
183
|
+
return Number.isFinite(percent) ? { percent, previousRate } : null;
|
|
184
|
+
}
|
|
185
|
+
|
|
163
186
|
/** How long past its feed's delay a weekday FX rate stays current, counted while the FX market trades. */
|
|
164
187
|
const FX_STALE_AFTER_DELAY_MS = 15 * 60_000;
|
|
165
188
|
|
package/src/cli/glossary.ts
CHANGED
|
@@ -66,15 +66,17 @@ export const GLOSSARY: readonly GlossaryEntry[] = [
|
|
|
66
66
|
+ "Every winning bid is filled at it; for TIPS it is a real yield.",
|
|
67
67
|
},
|
|
68
68
|
{
|
|
69
|
-
term: "Stop-out vs
|
|
70
|
-
shown: ["Stop-out vs
|
|
71
|
-
definition: "The high (stop-out) yield minus the auction's
|
|
69
|
+
term: "Stop-out vs median", aliases: ["stop-out vs med", "vs med", "stop-out vs average", "stop-out vs avg", "vs avg"], functions: ["AUCT"],
|
|
70
|
+
shown: ["Stop-out vs median", "Stop-out vs average", "Stop-out vs average/median", "VS MED", "VS AVG", "VS AVG/MED"],
|
|
71
|
+
definition: "The high (stop-out) yield minus the auction's median yield, in basis points; bills compare discount rates. "
|
|
72
|
+
+ "Treasury has sold at a single price since November 1998 and publishes the median accepted bid; before, most auctions "
|
|
73
|
+
+ "were multiple-price and the figure is the average, so older auctions read stop-out vs average. "
|
|
72
74
|
+ "A wider gap means the last accepted bids cleared well above where most of the auction priced.",
|
|
73
75
|
},
|
|
74
76
|
{
|
|
75
77
|
term: "Tail", aliases: ["tailed", "tailing", "auction tail"], functions: ["AUCT"], shown: ["tail"],
|
|
76
78
|
definition: "How far an auction's high yield cleared above the when-issued yield at the 1 pm bid deadline; a tail reads as weak demand. "
|
|
77
|
-
+ "AUCT cannot show one, as its source has no when-issued yields, so it shows stop-out vs
|
|
79
|
+
+ "AUCT cannot show one, as its source has no when-issued yields, so it shows stop-out vs median instead.",
|
|
78
80
|
},
|
|
79
81
|
{
|
|
80
82
|
term: "When-issued", short: "WI", aliases: ["when issued", "wi yield", "when-issued yield"], functions: ["AUCT"],
|
|
@@ -87,6 +89,18 @@ export const GLOSSARY: readonly GlossaryEntry[] = [
|
|
|
87
89
|
definition: "A bill's yield at the highest accepted (stop-out) rate, restated as a bond-equivalent yield so it compares with "
|
|
88
90
|
+ "note yields. It reads higher than the bill's discount rate.",
|
|
89
91
|
},
|
|
92
|
+
{
|
|
93
|
+
term: "Discount rate", aliases: ["bank discount rate", "high discount rate", "discount yield"], functions: ["AUCT"],
|
|
94
|
+
shown: ["Discount rate"],
|
|
95
|
+
definition: "How a bill is bid and quoted: the discount from face value as an annual rate on a 360-day year. "
|
|
96
|
+
+ "The auction's high discount rate is the one its investment rate restates.",
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
term: "Auction percentile", aliases: ["b/c percentile", "b/c pctl", "indirect percentile", "dealer percentile"], functions: ["AUCT"],
|
|
100
|
+
shown: ["B/C pctl", "Indirect pctl", "Dealer pctl"],
|
|
101
|
+
definition: "Where an auction's bid-to-cover, indirect or dealer share ranks among the previous 24 auctions of the same "
|
|
102
|
+
+ "tenor and type, from 0 (the lowest) to 100 (the highest). Blank with fewer than 12 before it.",
|
|
103
|
+
},
|
|
90
104
|
{
|
|
91
105
|
term: "High discount margin", aliases: ["discount margin", "frn margin"], functions: ["AUCT"],
|
|
92
106
|
shown: ["High discount margin", "FRN"],
|
|
@@ -1005,7 +1019,7 @@ export interface GlossaryLookup {
|
|
|
1005
1019
|
/** The entries the query names: by the term, its abbreviation or an alias. */
|
|
1006
1020
|
exact: GlossaryEntry[];
|
|
1007
1021
|
/**
|
|
1008
|
-
* The others whose names hold each word of the query: `stop-out` finds stop-out vs
|
|
1022
|
+
* The others whose names hold each word of the query: `stop-out` finds stop-out vs median. Beside a term the
|
|
1009
1023
|
* query names they hold the words whole; otherwise a word start is enough, and the whole ones come first.
|
|
1010
1024
|
*/
|
|
1011
1025
|
partial: GlossaryEntry[];
|
package/src/cli/help.ts
CHANGED
|
@@ -47,6 +47,7 @@ const GLOBAL_OPTIONS: Array<[string, string]> = [
|
|
|
47
47
|
["--json", "Print the full result as JSON"],
|
|
48
48
|
["--csv", "Print rows as CSV under the columns the text shows; fn reports and fundamentals put each table under # section: and end with # source lines"],
|
|
49
49
|
["--ndjson", "Print one JSON object per table row"],
|
|
50
|
+
["--output <path>, --out <path>", "Write a --csv, --json or --ndjson export to this file in UTF-8, and print where it went (a redirect is UTF-16 in Windows PowerShell 5.1)"],
|
|
50
51
|
["--limit <n>", "Show at most n rows, the first n as printed"],
|
|
51
52
|
["--tail <n>", "Show the newest n rows of a dated series (history, fred, econ) in their printed order, or the last n of another list"],
|
|
52
53
|
["--refresh", "Fetch fresh data instead of reading the cache"],
|
package/src/cli/history-rows.ts
CHANGED
|
@@ -19,7 +19,7 @@ import {
|
|
|
19
19
|
isWickFlag, latestTradeIndex, missingVolumeNotice, pricePointIntegrityFlags, pricePointValues, pricePointWickFlags,
|
|
20
20
|
} from "../utils/price-history-integrity";
|
|
21
21
|
import { formatUtcTime } from "../utils/utc-time";
|
|
22
|
-
import { maxDrawdown, type MaxDrawdown } from "../utils/max-drawdown";
|
|
22
|
+
import { maxDrawdown, type DrawdownScale, type MaxDrawdown } from "../utils/max-drawdown";
|
|
23
23
|
import { historyCoverageNotice } from "../sources/history-coverage";
|
|
24
24
|
import { barLastSession, barPeriodToDate, type BarPeriodToDate } from "../market-data/market/bar-period";
|
|
25
25
|
import { barSizeFromGap, medianBarGap } from "../time-series/bar-spacing";
|
|
@@ -486,12 +486,14 @@ function historyContractRuns<Row extends Pick<HistoryRow, "contract" | "roll">>(
|
|
|
486
486
|
*/
|
|
487
487
|
export function historyContractDrawdown(
|
|
488
488
|
rows: readonly Pick<HistoryRow, "date" | "close" | "contract" | "roll">[],
|
|
489
|
+
scale: DrawdownScale = "return",
|
|
489
490
|
): { drawdown: MaxDrawdown; contract: string | null } | null {
|
|
490
491
|
const runs = historyContractRuns(rows);
|
|
491
492
|
let deepest: { drawdown: MaxDrawdown; contract: string | null } | null = null;
|
|
493
|
+
const depth = (drawdown: MaxDrawdown) => drawdown.bp ?? drawdown.drawdown;
|
|
492
494
|
for (const run of runs) {
|
|
493
|
-
const drawdown = maxDrawdown(run.rows);
|
|
494
|
-
if (drawdown && (!deepest || drawdown
|
|
495
|
+
const drawdown = maxDrawdown(run.rows, scale);
|
|
496
|
+
if (drawdown && (!deepest || depth(drawdown) < depth(deepest.drawdown))) deepest = { drawdown, contract: runs.length > 1 ? run.contract : null };
|
|
495
497
|
}
|
|
496
498
|
return deepest;
|
|
497
499
|
}
|