@gloom-sh/terminal 0.20.8 → 0.20.10
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/package.json +1 -1
- package/src/api-client/auth.ts +6 -0
- package/src/api-client/data.ts +1 -0
- package/src/api-client/earnings.ts +15 -0
- package/src/api-client/futures-curve.ts +5 -1
- package/src/api-client/index.ts +14 -3
- package/src/api-client/types/account.ts +10 -0
- package/src/api-client/types/billing.ts +10 -0
- package/src/api-client/types/econ.ts +19 -7
- package/src/api-client/types/market.ts +7 -0
- package/src/api-client/types/screener.ts +2 -0
- package/src/cli/commands/market.ts +18 -8
- package/src/cli/commands/overview.ts +28 -7
- package/src/cli/commands/ticker.ts +40 -15
- package/src/cli/desktop-pane-shot.ts +39 -0
- package/src/cli/errors.ts +20 -3
- package/src/cli/fx-pair.ts +11 -2
- package/src/cli/history-rows.ts +34 -3
- package/src/cli/index.ts +1 -1
- package/src/cli/listing-arg.ts +51 -13
- package/src/cli/pane-functions/data.ts +3 -2
- package/src/cli/pane-functions/headless.ts +5 -2
- package/src/cli/pane-functions/index.ts +1 -0
- package/src/cli/pane-functions/resolver.ts +2 -1
- package/src/cli/pane-functions/screenshot-assessment.ts +73 -5
- package/src/cli/pane-functions/screenshot-types.ts +4 -0
- package/src/cli/symbol-cells.ts +6 -0
- package/src/cli/symbol-list.ts +14 -6
- package/src/cli/symbol-rows.ts +12 -5
- package/src/components/chart/composite/chart-layout.ts +7 -4
- package/src/components/chart/composite/composite-chart.tsx +6 -16
- package/src/components/chart/composite/toolbar.tsx +258 -82
- package/src/components/chart/composite/use-composite-chart-keyboard.ts +5 -6
- package/src/components/command-bar/list/model.ts +13 -0
- package/src/components/command-bar/routes/ticker-search/actions.ts +2 -0
- package/src/components/command-bar/routes/ticker-search/results.ts +15 -8
- package/src/components/command-bar/surface/index.tsx +10 -5
- package/src/components/command-bar/workflow/alert.ts +21 -7
- package/src/components/data-table/table-pane.ts +3 -1
- package/src/components/layout/pane/footer/model.ts +26 -1
- package/src/components/metric-treemap/heat-surface.tsx +2 -1
- package/src/components/metric-treemap/index.tsx +3 -2
- package/src/components/ui/confirm-dialog.tsx +253 -7
- package/src/components/ui/data-table/index.tsx +1 -1
- package/src/components/ui/data-table/types.ts +7 -0
- package/src/components/ui/list-view.tsx +4 -3
- package/src/components/ui/page-stack-view.tsx +24 -6
- package/src/components/ui/status.tsx +9 -6
- package/src/docs/snapshot.json +36 -0
- package/src/i18n/es.ts +12 -0
- package/src/i18n/ja.ts +12 -0
- package/src/i18n/ko.ts +12 -0
- package/src/i18n/zh-cn.ts +12 -0
- package/src/i18n/zh-tw.ts +12 -0
- package/src/market-data/futures-roll-returns.ts +226 -0
- package/src/market-data/fx-closes.ts +14 -2
- package/src/market-data/market/change-basis.ts +35 -1
- package/src/market-data/market/session-close-note.ts +41 -4
- package/src/market-data/market/status.ts +37 -0
- package/src/market-data/performance.ts +4 -1
- package/src/market-data/quotes/listing-enterprise-value.ts +8 -4
- package/src/market-data/quotes/live-valuation.ts +25 -2
- package/src/market-data/realized-volatility.ts +3 -0
- package/src/market-data/us-bond-market.ts +115 -0
- package/src/plugins/builtin/account-management/invite-row.tsx +54 -0
- package/src/plugins/builtin/account-management/keyboard.ts +3 -0
- package/src/plugins/builtin/account-management/model.ts +1 -0
- package/src/plugins/builtin/account-management/pane.tsx +51 -5
- package/src/plugins/builtin/account-management/trial-cancel.ts +32 -7
- package/src/plugins/builtin/backtest/client.ts +9 -2
- package/src/plugins/builtin/backtest/pane.tsx +1 -1
- package/src/plugins/builtin/backtest/report.ts +22 -6
- package/src/plugins/builtin/backtest/window.ts +17 -9
- package/src/plugins/builtin/cloud/askg/pane-session.ts +94 -0
- package/src/plugins/builtin/cloud/askg/pane.tsx +40 -83
- package/src/plugins/builtin/congress-trades/pane.tsx +8 -2
- package/src/plugins/builtin/correlation/compute.ts +4 -3
- package/src/plugins/builtin/correlation/headless.ts +6 -2
- package/src/plugins/builtin/correlation/index.tsx +7 -3
- package/src/plugins/builtin/correlation/matrix/model.ts +15 -1
- package/src/plugins/builtin/correlation/relationship/model.ts +15 -1
- package/src/plugins/builtin/correlation/relationship/pane.tsx +4 -2
- package/src/plugins/builtin/earnings/board-model.ts +33 -0
- package/src/plugins/builtin/earnings/board-table.ts +50 -11
- package/src/plugins/builtin/earnings/board.tsx +29 -13
- package/src/plugins/builtin/earnings/calendar.tsx +15 -3
- package/src/plugins/builtin/earnings/client.ts +4 -1
- package/src/plugins/builtin/earnings/headless.ts +27 -14
- package/src/plugins/builtin/econ/calendar-source.ts +3 -0
- package/src/plugins/builtin/futures-curve/headless.ts +4 -1
- package/src/plugins/builtin/futures-curve/model.ts +24 -0
- package/src/plugins/builtin/help/index.tsx +1 -1
- package/src/plugins/builtin/ipo-calendar/model.ts +3 -3
- package/src/plugins/builtin/iv-history/headless.ts +12 -10
- package/src/plugins/builtin/kelly-sizer/headless.ts +2 -2
- package/src/plugins/builtin/kelly-sizer/history.ts +10 -3
- package/src/plugins/builtin/kelly-sizer/pane.tsx +2 -2
- package/src/plugins/builtin/kelly-sizer/sections.tsx +1 -1
- package/src/plugins/builtin/macro-day/headless.ts +15 -5
- package/src/plugins/builtin/macro-day/model.ts +17 -4
- package/src/plugins/builtin/macro-day/releases.ts +36 -15
- package/src/plugins/builtin/market-halts/model.ts +3 -2
- package/src/plugins/builtin/market-movers/headless.ts +2 -1
- package/src/plugins/builtin/market-movers/index.tsx +3 -2
- package/src/plugins/builtin/market-movers/model.ts +75 -22
- package/src/plugins/builtin/market-movers/screener.ts +2 -1
- package/src/plugins/builtin/market-movers/table.ts +7 -5
- package/src/plugins/builtin/pe-band/model.ts +4 -0
- package/src/plugins/builtin/portfolio-list/cell-version.ts +4 -4
- package/src/plugins/builtin/portfolio-list/cli/render.ts +9 -4
- package/src/plugins/builtin/portfolio-list/pane/index.tsx +2 -1
- package/src/plugins/builtin/portfolio-list/summary/index.tsx +24 -7
- package/src/plugins/builtin/portfolio-list/summary/totals.ts +40 -11
- package/src/plugins/builtin/portfolio-list/table.tsx +13 -1
- package/src/plugins/builtin/realized-vol/headless.ts +11 -6
- package/src/plugins/builtin/realized-vol/model.ts +14 -6
- package/src/plugins/builtin/realized-vol/pane.tsx +2 -1
- package/src/plugins/builtin/realized-vol/settings.ts +2 -1
- package/src/plugins/builtin/research/analyst-headless.ts +9 -1
- package/src/plugins/builtin/research/analyst-pane.tsx +10 -4
- package/src/plugins/builtin/research/client.ts +25 -1
- package/src/plugins/builtin/research/corporate-actions-pane.tsx +2 -1
- package/src/plugins/builtin/research/event-model.ts +3 -13
- package/src/plugins/builtin/research/event-sources.ts +3 -1
- package/src/plugins/builtin/seasonality/client.ts +66 -17
- package/src/plugins/builtin/seasonality/headless.ts +7 -2
- package/src/plugins/builtin/seasonality/model.ts +12 -3
- package/src/plugins/builtin/seasonality/pane.tsx +4 -2
- package/src/plugins/builtin/shared/use-quote-board.ts +28 -6
- package/src/plugins/builtin/short-interest/headless.ts +2 -0
- package/src/plugins/builtin/short-interest/publications-headless.ts +2 -0
- package/src/plugins/builtin/short-interest/watch-headless.ts +1 -0
- package/src/plugins/builtin/yield-curve/headless.ts +5 -1
- package/src/plugins/builtin/yield-curve/index.tsx +5 -0
- package/src/portfolio/column-values.ts +47 -14
- package/src/portfolio/return-metrics.ts +4 -2
- package/src/renderers/dom/desktop/controls.tsx +1 -1
- package/src/renderers/dom/host/image-surface.tsx +19 -9
- package/src/renderers/dom/host/input.tsx +4 -0
- package/src/renderers/dom/styles.css +7 -4
- package/src/renderers/electrobun/view/cli-pane-shot-entry.tsx +23 -1
- package/src/renderers/opentui/box-width.ts +30 -0
- package/src/sources/gloomberb-cloud/normalizers.ts +2 -0
- package/src/sources/provider-errors.ts +12 -0
- package/src/sources/provider-router/index.ts +12 -4
- package/src/state/pane-session.ts +145 -0
- package/src/tickers/search/home-listing.ts +44 -1
- package/src/tickers/search/index.ts +5 -2
- package/src/tickers/search/ranking.ts +7 -7
- package/src/tickers/us-listing.ts +11 -5
- package/src/time-series/base-series.ts +7 -1
- package/src/time-series/fundamentals/current-valuation.ts +8 -0
- package/src/time-series/fundamentals/series.ts +6 -0
- package/src/time-series/resolve.ts +1 -0
- package/src/types/financials.ts +36 -3
- package/src/types/headless.ts +15 -0
- package/src/ui/host.tsx +2 -0
- package/src/utils/exchanges.ts +13 -8
- package/src/utils/fundamentals.ts +49 -8
- package/src/utils/price-earnings.ts +17 -10
- package/src/utils/price-history-integrity.ts +15 -0
- package/src/utils/reason-codes.ts +79 -0
- package/src/utils/share-multiples.cases.json +889 -0
- package/src/utils/share-multiples.ts +254 -0
- package/src/utils/untrusted-text.ts +11 -0
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
import type { FinancialStatement, Fundamentals, TickerFinancials } from "../types/financials";
|
|
2
|
+
import { resolveCurrencyUnit } from "./currency-units";
|
|
3
|
+
import { canonicalExchange, US_LISTING_EXCHANGES } from "./exchanges";
|
|
4
|
+
import { quarterRows } from "./financial-statements";
|
|
5
|
+
|
|
6
|
+
/** Beyond this either way, a trailing EPS is not net income over the shares. */
|
|
7
|
+
const OWN_EPS_RATIO_LIMIT = 10;
|
|
8
|
+
|
|
9
|
+
/** Nasdaq's fifth letter W, R or U is a warrant, a right or a unit (BZFDW, TDWDR, SAAQU). */
|
|
10
|
+
const NASDAQ_INSTRUMENT = /^[A-Z]{4}([WRU])$/;
|
|
11
|
+
/** NYSE's suffixes: NWAX.WS, ABC.U, ABC.RT. */
|
|
12
|
+
const NYSE_INSTRUMENT = /[.\-/ ](WS|WT|U|RT)(?:\.[A-Z])?$/;
|
|
13
|
+
/** A preferred share's symbol (PSA.PR.U): its last letter is its series, not a unit. */
|
|
14
|
+
const PREFERRED_SYMBOL = /\.PR(?:\.|$)/;
|
|
15
|
+
/** A warrant, right or unit by its name: the word at its end, or before its terms. */
|
|
16
|
+
const INSTRUMENT_NAME =
|
|
17
|
+
/(?:^|[\s,.(-])(warrants?|wts?|rights?|units?)(?:\s*(?:\([^)]*\))?\s*$|[\s,]+(?:each|exp(?:iring|ire|\.)?|exercisable|to\s+(?:purchase|buy|acquire|subscribe)|consisting)\b)/i;
|
|
18
|
+
/**
|
|
19
|
+
* Units that are the share: a partnership's, a trust's, a REIT's, an income
|
|
20
|
+
* fund's, depositary units and a holding company's (Brookfield Renewable
|
|
21
|
+
* Partners L.P. Units, Choice Properties REIT Units, Boralex Income Fund -
|
|
22
|
+
* Units, Icahn Enterprises Depositary Units, Hess Midstream Holdings Unit).
|
|
23
|
+
*/
|
|
24
|
+
const SHARE_UNITS = /\b(?:common|partnership|ordinary|stapled|beneficial|trust|lp|l\.p\.|llc|class\s+[a-z]|reit|fund|depositary|holdings?)\s*[-–]?\s*units?\b/i;
|
|
25
|
+
/** A blank-check company's words: its units are a share and a warrant together. */
|
|
26
|
+
const SPAC_NAME = /\b(?:acquisition|blank\s+check|spac)\b/i;
|
|
27
|
+
/** SET's own warrants: JMART-W4. */
|
|
28
|
+
const SET_WARRANT = /-W\d*$/;
|
|
29
|
+
/**
|
|
30
|
+
* A Thai depositary receipt: the foreign company's code and the two-digit
|
|
31
|
+
* number of the Thai broker that issued it (SOFTBANK80, AAPL01, NVDA19). Its
|
|
32
|
+
* ratio to the company's share is the issuer's and is not on record.
|
|
33
|
+
*/
|
|
34
|
+
const THAI_RECEIPT = /^[A-Z][A-Z0-9]{1,7}(?:01|03|06|11|13|19|23|24|80)$/;
|
|
35
|
+
|
|
36
|
+
type Instrument = "warrant" | "right" | "unit";
|
|
37
|
+
|
|
38
|
+
const instrumentOf = (code: string): Instrument => {
|
|
39
|
+
const lower = code.toLowerCase();
|
|
40
|
+
return lower.startsWith("r") ? "right" : lower.startsWith("u") ? "unit" : "warrant";
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
type ShareInputs = Pick<TickerFinancials, "quote" | "profile" | "fundamentals">;
|
|
44
|
+
type EpsInputs = ShareInputs & Partial<Pick<TickerFinancials, "financialCurrency" | "annualStatements" | "quarterlyStatements" | "trailingStatement">>;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Why a listing's price over its company's EPS is no P/E, if it is not: a
|
|
48
|
+
* warrant, a right or a unit is not the share (BZFDW, BuzzFeed's warrant at
|
|
49
|
+
* $0.0054, read 0.03x), and a depositary receipt with no ratio on record is
|
|
50
|
+
* on another count than the share (SOFTBANK80 on SET, a Thai receipt at
|
|
51
|
+
* 7.85 THB over SoftBank's 203.71 THB a share, read 0.04x; AMD on the TSX, a
|
|
52
|
+
* Canadian receipt Gloom Cloud flags because AMD's home line is elsewhere,
|
|
53
|
+
* read 17.1x for about 120x on the share). Gloom Cloud puts a receipt whose
|
|
54
|
+
* ratio is on record on the receipt already (TSM's 5 shares, a CEDEAR's
|
|
55
|
+
* published ratio). A unit is told by its name only on a US venue or for a
|
|
56
|
+
* blank-check company; a REIT's, a fund's or a partnership's units are its
|
|
57
|
+
* share, and PSA.PR.U is a preferred.
|
|
58
|
+
*/
|
|
59
|
+
export function notTheShare(financials: ShareInputs): string | undefined {
|
|
60
|
+
const quote = financials.quote;
|
|
61
|
+
if (!quote) return undefined;
|
|
62
|
+
const venue = canonicalExchange(quote.listingExchangeName || quote.exchangeName);
|
|
63
|
+
const code = (quote.symbol ?? "").split(":")[0]!.trim().toUpperCase();
|
|
64
|
+
const name = quote.name ?? "";
|
|
65
|
+
const named = INSTRUMENT_NAME.exec(name)?.[1];
|
|
66
|
+
const byName = named && !(instrumentOf(named) === "unit"
|
|
67
|
+
&& (SHARE_UNITS.test(name) || !(US_LISTING_EXCHANGES.has(venue) || SPAC_NAME.test(name))))
|
|
68
|
+
? instrumentOf(named) : undefined;
|
|
69
|
+
const bySymbol = PREFERRED_SYMBOL.test(code) ? undefined
|
|
70
|
+
: US_LISTING_EXCHANGES.has(venue)
|
|
71
|
+
? (venue === "NASDAQ" ? NASDAQ_INSTRUMENT.exec(code)?.[1] : undefined) ?? NYSE_INSTRUMENT.exec(code)?.[1]
|
|
72
|
+
: venue === "SET" && SET_WARRANT.test(code) ? "W" : undefined;
|
|
73
|
+
const instrument = byName ?? (bySymbol ? instrumentOf(bySymbol) : undefined);
|
|
74
|
+
if (instrument) return `a ${instrument} is not the share the EPS is per`;
|
|
75
|
+
const country = financials.profile?.country?.trim().toUpperCase();
|
|
76
|
+
const fundamentals = financials.fundamentals;
|
|
77
|
+
const receipt = quote.isDepositaryReceipt || fundamentals?.isDepositaryReceipt || fundamentals?.shareBasis === "depositary_receipt"
|
|
78
|
+
// Thai receipts are not flagged as receipts.
|
|
79
|
+
|| (venue === "SET" && THAI_RECEIPT.test(code) && country !== "TH");
|
|
80
|
+
const ratio = [quote.adrRatio, fundamentals?.adrRatio].some((value) => typeof value === "number" && value > 0)
|
|
81
|
+
|| !!(quote.cedearRatio ?? fundamentals?.cedearRatio) || !!fundamentals?.trailingEpsBasis;
|
|
82
|
+
return receipt && !ratio ? "a depositary receipt with no ratio on record to the share the EPS is per" : undefined;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const isReceipt = (financials: ShareInputs) => !!(
|
|
86
|
+
financials.quote?.isDepositaryReceipt || financials.fundamentals?.isDepositaryReceipt
|
|
87
|
+
|| financials.fundamentals?.shareBasis === "depositary_receipt" || financials.quote?.adrRatio || financials.fundamentals?.adrRatio
|
|
88
|
+
);
|
|
89
|
+
|
|
90
|
+
const finite = (value: number | null | undefined): value is number => typeof value === "number" && Number.isFinite(value);
|
|
91
|
+
/** A per-share figure in a reason: whole above 100, cents above 0.01, else two significant digits (BZT's 0.000089). */
|
|
92
|
+
const perShare = (value: number) => Math.abs(value) >= 100 ? value.toFixed(0)
|
|
93
|
+
: Math.abs(value) >= 0.01 ? value.toFixed(2) : value.toPrecision(2);
|
|
94
|
+
const majorCurrency = (currency: string | null | undefined) => resolveCurrencyUnit(currency).currency || undefined;
|
|
95
|
+
|
|
96
|
+
/** The latest statement's currency. */
|
|
97
|
+
function statementsCurrency(financials: EpsInputs): string | undefined {
|
|
98
|
+
return [...(financials.quarterlyStatements ?? []), ...(financials.annualStatements ?? [])]
|
|
99
|
+
.filter((row) => row.currency)
|
|
100
|
+
.sort((left, right) => left.date.localeCompare(right.date))
|
|
101
|
+
.at(-1)?.currency;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** The currency of the trailing net income: the block's, else the financials', else the latest statement's. */
|
|
105
|
+
function incomeCurrency(financials: EpsInputs): string | undefined {
|
|
106
|
+
return majorCurrency(financials.fundamentals?.financialCurrency ?? financials.financialCurrency ?? statementsCurrency(financials));
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
const DAY_MS = 86_400_000;
|
|
110
|
+
const SAME_DATE_DAYS = 10;
|
|
111
|
+
const days = (from: string, to: string) => (Date.parse(to) - Date.parse(from)) / DAY_MS;
|
|
112
|
+
const quarterApart = (from: string, to: string) => days(from, to) >= 80 && days(from, to) <= 100;
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* The statements' trailing net income in `currency`: the latest fiscal year
|
|
116
|
+
* when no quarter runs past it, four consecutive quarters, the year plus the
|
|
117
|
+
* half since it where Gloom Cloud serves one, or the latest year plus the
|
|
118
|
+
* quarters since it less the same quarters a year earlier. Gloom Cloud reads
|
|
119
|
+
* the same window to tell an EPS in the reporting currency.
|
|
120
|
+
*/
|
|
121
|
+
function statementsTrailingNetIncome(financials: EpsInputs, currency: string): number | undefined {
|
|
122
|
+
const usable = (rows: readonly FinancialStatement[]) => rows
|
|
123
|
+
.filter((row) => finite(row.netIncome) && Number.isFinite(Date.parse(row.date)) && row.currency === currency)
|
|
124
|
+
.sort((left, right) => left.date.localeCompare(right.date));
|
|
125
|
+
const quarters = usable(quarterRows(financials.quarterlyStatements ?? []));
|
|
126
|
+
const annual = usable(financials.annualStatements ?? []).at(-1);
|
|
127
|
+
const latest = quarters.at(-1);
|
|
128
|
+
const trailing = financials.trailingStatement;
|
|
129
|
+
const served = trailing?.trailing?.method === "annual-plus-interim" && Number.isFinite(Date.parse(trailing.date))
|
|
130
|
+
&& trailing.currency === currency && finite(trailing.netIncome)
|
|
131
|
+
&& !(annual && days(annual.date, trailing.date) <= SAME_DATE_DAYS)
|
|
132
|
+
&& !(latest && days(trailing.date, latest.date) > SAME_DATE_DAYS)
|
|
133
|
+
? { value: trailing.netIncome, end: trailing.date } : undefined;
|
|
134
|
+
if (!served && annual && (!latest || days(annual.date, latest.date) <= SAME_DATE_DAYS)) return annual.netIncome!;
|
|
135
|
+
if (!latest) return served?.value;
|
|
136
|
+
const lastFour = quarters.slice(-4);
|
|
137
|
+
if ((!served || Math.abs(days(latest.date, served.end)) <= SAME_DATE_DAYS) && lastFour.length === 4
|
|
138
|
+
&& lastFour.every((row, index) => index === 0 || quarterApart(lastFour[index - 1]!.date, row.date))) {
|
|
139
|
+
return lastFour.reduce((total, row) => total + row.netIncome!, 0);
|
|
140
|
+
}
|
|
141
|
+
if (served) return served.value;
|
|
142
|
+
if (!annual) return undefined;
|
|
143
|
+
const interims = quarters.filter((row) => days(annual.date, row.date) > SAME_DATE_DAYS);
|
|
144
|
+
let previous = annual.date;
|
|
145
|
+
for (const row of interims) {
|
|
146
|
+
if (!quarterApart(previous, row.date)) return undefined;
|
|
147
|
+
previous = row.date;
|
|
148
|
+
}
|
|
149
|
+
const prior = interims.map((row) => quarters.find((candidate) => Math.abs(days(candidate.date, row.date) - 365) <= SAME_DATE_DAYS));
|
|
150
|
+
if (prior.some((row) => !row)) return undefined;
|
|
151
|
+
return annual.netIncome! + interims.reduce((total, row) => total + row.netIncome!, 0)
|
|
152
|
+
- prior.reduce((total, row) => total + row!.netIncome!, 0);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Why a trailing EPS in the statements' reporting currency beside a price in
|
|
157
|
+
* another gives no P/E: there is no rate on record to price it at (the served
|
|
158
|
+
* P/E's `trailingPEConversion`). U.UN on the TSX divided its CA$26.47 by a
|
|
159
|
+
* USD 1.64 and read 16.14; NEW on Stuttgart €1.63 by GBP 0.0241, 67.63. The
|
|
160
|
+
* EPS is shown to be in the reporting currency where it is labelled so, sits
|
|
161
|
+
* beside a trailing block in it, or the block's net income is the statements'
|
|
162
|
+
* own in it. Gloom Cloud's screener reads the same. Undefined for an EPS the
|
|
163
|
+
* filed quarters give (in the price's currency), a receipt's on its home
|
|
164
|
+
* line, and one whose currency cannot be told.
|
|
165
|
+
*/
|
|
166
|
+
function noRateForEps(financials: EpsInputs): string | undefined {
|
|
167
|
+
const fundamentals = financials.fundamentals;
|
|
168
|
+
const eps = fundamentals?.eps;
|
|
169
|
+
const listing = majorCurrency(financials.quote?.currency);
|
|
170
|
+
const reporting = incomeCurrency(financials);
|
|
171
|
+
if (!fundamentals || !finite(eps) || !listing || !reporting || listing === reporting
|
|
172
|
+
|| fundamentals.trailingEpsBasis || fundamentals.trailingEpsSource === "filed-quarters") return undefined;
|
|
173
|
+
const stated = majorCurrency(fundamentals.epsCurrency);
|
|
174
|
+
if (stated === listing) return undefined;
|
|
175
|
+
const conversion = fundamentals.trailingPEConversion;
|
|
176
|
+
if (conversion && majorCurrency(conversion.from) === reporting && finite(conversion.rate) && conversion.rate > 0) return undefined;
|
|
177
|
+
const income = fundamentals.netIncome;
|
|
178
|
+
const statements = finite(income) ? statementsTrailingNetIncome(financials, reporting) : undefined;
|
|
179
|
+
const inReporting = stated === reporting || (!!fundamentals.financialCurrency && !fundamentals.epsCurrency)
|
|
180
|
+
|| (finite(income) && finite(statements) && Math.abs(income - statements) <= 0.01 * Math.max(Math.abs(income), Math.abs(statements)));
|
|
181
|
+
return inReporting ? `EPS (TTM) in ${reporting} beside a price in ${listing}, with no rate on record` : undefined;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Why a trailing EPS is not the company's, if it is not: of the other sign
|
|
186
|
+
* than the block's trailing net income over its shares outstanding, or more
|
|
187
|
+
* than OWN_EPS_RATIO_LIMIT times off it either way. STKH served an EPS of
|
|
188
|
+
* 96.00 beside a 7.01M loss over 605,876 shares (-11.57) and read 0.02x;
|
|
189
|
+
* SNBN's 577,618 CHF over 100,000 shares is its own and stands at 0.01x. The
|
|
190
|
+
* size is judged only on one share and in one currency: not for a receipt,
|
|
191
|
+
* whose shares can be ordinary ones, and not where the EPS is in another
|
|
192
|
+
* currency than the net income. The net income is in the block's currency,
|
|
193
|
+
* else the financials', else the latest statement's; the EPS in the one it
|
|
194
|
+
* is labelled in, else the statements' for one summed from the filed
|
|
195
|
+
* quarters, else the listing's. PAN on the JSE reports in dollars and is
|
|
196
|
+
* quoted in rand: its EPS of 2.98 beside 0.07 dollars a share is no sign of
|
|
197
|
+
* another company's. Undefined without the three figures.
|
|
198
|
+
*/
|
|
199
|
+
export function epsAgainstIncome(financials: EpsInputs): string | undefined {
|
|
200
|
+
const fundamentals = financials.fundamentals;
|
|
201
|
+
const eps = fundamentals?.eps;
|
|
202
|
+
const income = fundamentals?.netIncome;
|
|
203
|
+
const shares = fundamentals?.sharesOutstanding;
|
|
204
|
+
if (!finite(eps) || eps === 0 || !finite(income) || income === 0 || !finite(shares) || shares <= 0) return undefined;
|
|
205
|
+
const own = income / shares;
|
|
206
|
+
const text = `trailing net income over shares outstanding (${perShare(own)})`;
|
|
207
|
+
if (Math.sign(eps) !== Math.sign(own)) return `EPS (TTM) ${perShare(eps)} has the other sign than ${text}`;
|
|
208
|
+
const epsCurrency = majorCurrency(fundamentals?.epsCurrency
|
|
209
|
+
?? (fundamentals?.trailingEpsSource === "filed-quarters" ? statementsCurrency(financials) : undefined)
|
|
210
|
+
?? financials.quote?.currency);
|
|
211
|
+
const incomeIn = incomeCurrency(financials);
|
|
212
|
+
if (isReceipt(financials) || (epsCurrency && incomeIn && epsCurrency !== incomeIn)) return undefined;
|
|
213
|
+
const ratio = eps / own;
|
|
214
|
+
return ratio > OWN_EPS_RATIO_LIMIT || ratio < 1 / OWN_EPS_RATIO_LIMIT
|
|
215
|
+
? `EPS (TTM) ${perShare(eps)} is more than ${OWN_EPS_RATIO_LIMIT} times off ${text}`
|
|
216
|
+
: undefined;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
type Withdrawn = NonNullable<Fundamentals["notMeaningful"]>;
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* The financials with the multiples that are no multiple of the share
|
|
223
|
+
* withdrawn and their reason under `notMeaningful`: every P/E and the PEG of
|
|
224
|
+
* a warrant, a right, a unit or a receipt with no ratio (notTheShare), and
|
|
225
|
+
* the trailing P/E and the PEG over an EPS in another currency with no rate
|
|
226
|
+
* (noRateForEps) or one that is not the company's (epsAgainstIncome), in
|
|
227
|
+
* that order. Only a multiple the block has, or a trailing one its EPS would
|
|
228
|
+
* give, is withdrawn: one it never had stays absent. Reads the trailing EPS
|
|
229
|
+
* withFiledTrailingEps leaves, so it runs after it. Returns the same object
|
|
230
|
+
* when nothing is withdrawn.
|
|
231
|
+
*/
|
|
232
|
+
export function withShareMultiples<T extends EpsInputs>(financials: T): T {
|
|
233
|
+
const fundamentals = financials.fundamentals;
|
|
234
|
+
if (!fundamentals) return financials;
|
|
235
|
+
const share = notTheShare(financials);
|
|
236
|
+
const reason = share ?? noRateForEps(financials) ?? epsAgainstIncome(financials);
|
|
237
|
+
// A multiple an earlier pass withdrew is one the block had.
|
|
238
|
+
const had = fundamentals.notMeaningful ?? {};
|
|
239
|
+
const has: Record<keyof Withdrawn, boolean> = {
|
|
240
|
+
trailingPE: finite(fundamentals.trailingPE) || finite(fundamentals.eps) || !!had.trailingPE,
|
|
241
|
+
forwardPE: !!share && (finite(fundamentals.forwardPE) || !!had.forwardPE),
|
|
242
|
+
pegRatio: finite(fundamentals.pegRatio) || !!had.pegRatio,
|
|
243
|
+
};
|
|
244
|
+
const fields = reason ? (Object.keys(has) as Array<keyof Withdrawn>).filter((field) => has[field]) : [];
|
|
245
|
+
const reasons: Withdrawn = Object.fromEntries(fields.map((field) => [field, reason]));
|
|
246
|
+
if (fields.length === 0) {
|
|
247
|
+
if (!fundamentals.notMeaningful) return financials;
|
|
248
|
+
const { notMeaningful: _stale, ...rest } = fundamentals;
|
|
249
|
+
return { ...financials, fundamentals: rest };
|
|
250
|
+
}
|
|
251
|
+
const next: Fundamentals = { ...fundamentals, notMeaningful: reasons };
|
|
252
|
+
for (const field of fields) delete next[field];
|
|
253
|
+
return { ...financials, fundamentals: next };
|
|
254
|
+
}
|
|
@@ -26,6 +26,17 @@ export function withoutControlCharacters(value: string): string {
|
|
|
26
26
|
return HAS_COMMAND_CONTROL.test(value) ? value.replace(COMMAND_CONTROL, "") : value;
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
+
/**
|
|
30
|
+
* At most `maxLength` UTF-16 units of `value`, as a JavaScript string or a
|
|
31
|
+
* JSON Schema `maxLength` counts them, cut before a surrogate pair rather than
|
|
32
|
+
* through it, so an emoji at the limit is left out instead of halved.
|
|
33
|
+
*/
|
|
34
|
+
export function sliceWholeCharacters(value: string, maxLength: number): string {
|
|
35
|
+
if (value.length <= maxLength) return value;
|
|
36
|
+
const last = value.charCodeAt(maxLength - 1);
|
|
37
|
+
return value.slice(0, last >= 0xd800 && last <= 0xdbff ? maxLength - 1 : maxLength);
|
|
38
|
+
}
|
|
39
|
+
|
|
29
40
|
/**
|
|
30
41
|
* Text another person's app wrote (a shared pane's item, a share's title), as
|
|
31
42
|
* one line that draws as what it says: no terminal escape sequence, control
|