@gloom-sh/terminal 0.20.5 → 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 +1 -1
- package/README.zh-CN.md +1 -1
- package/package.json +2 -1
- package/src/api-client/data.ts +10 -2
- package/src/api-client/hk-tenders.ts +59 -0
- package/src/api-client/index.ts +1 -0
- package/src/api-client/types/econ.ts +20 -2
- package/src/app.tsx +18 -13
- package/src/architecture/floating-promise-allowlist.json +313 -0
- package/src/cli/commands/market.ts +164 -40
- package/src/cli/commands/news-search.ts +22 -7
- package/src/cli/commands/overview.ts +12 -6
- 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 +76 -12
- package/src/cli/fx-pair.ts +1 -1
- package/src/cli/fx-quote-rate.ts +23 -0
- package/src/cli/help.ts +1 -0
- package/src/cli/index-roots.ts +5 -4
- package/src/cli/index.ts +40 -3
- package/src/cli/known-gaps.ts +11 -8
- package/src/cli/listing-arg.ts +6 -4
- 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/workflow/tickers.ts +2 -2
- package/src/components/data-table/view.tsx +9 -2
- 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/table-layout.ts +38 -1
- package/src/docs/snapshot.json +3 -3
- package/src/market-data/market/change-basis.ts +9 -5
- package/src/market-data/market/dated-previous-close.ts +57 -6
- 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/backtest/headless.ts +1 -1
- 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 +2 -1
- package/src/plugins/builtin/chart-composer/presets.ts +1 -0
- package/src/plugins/builtin/cloud/askg/pane.tsx +55 -13
- 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/econ/calendar-model.ts +41 -7
- package/src/plugins/builtin/econ/calendar-source.ts +7 -1
- package/src/plugins/builtin/econ/index.tsx +41 -8
- package/src/plugins/builtin/econ/types.ts +3 -0
- package/src/plugins/builtin/fixed-income/index.tsx +2 -0
- package/src/plugins/builtin/fx-matrix/index.tsx +44 -14
- package/src/plugins/builtin/help/keybindings-editor.tsx +6 -2
- 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/research/headless-schema.ts +4 -3
- 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/thirteenf/api.ts +47 -4
- 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 +6 -2
- package/src/plugins/builtin/ticker-detail/financials/tab.tsx +1 -1
- package/src/plugins/builtin/ticker-detail/headless.ts +6 -4
- package/src/plugins/builtin/treasury-auctions/cache.ts +36 -2
- package/src/plugins/builtin/treasury-auctions/headless.ts +42 -4
- 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 +14 -1
- package/src/plugins/builtin/treasury-auctions/model.ts +16 -8
- package/src/plugins/builtin/treasury-auctions/pane.tsx +45 -21
- package/src/portfolio/collection-name.ts +22 -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/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/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 +9 -5
- 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 +6 -0
- package/src/types/headless.ts +8 -0
- package/src/utils/cli-output.ts +6 -3
- package/src/utils/ebitda.ts +128 -0
- package/src/utils/format.ts +1 -1
- package/src/utils/shell-word.ts +13 -0
|
@@ -10,6 +10,9 @@ import {
|
|
|
10
10
|
isPriceGroup,
|
|
11
11
|
knownUnitSignature,
|
|
12
12
|
legName,
|
|
13
|
+
percentBasisPointRatioScale,
|
|
14
|
+
percentBasisPointUnit,
|
|
15
|
+
PLAIN_RATIO_UNIT,
|
|
13
16
|
unitMismatchMessage,
|
|
14
17
|
type SeriesUnit,
|
|
15
18
|
} from "./units";
|
|
@@ -23,6 +26,8 @@ interface FormulaLeg {
|
|
|
23
26
|
perBarrel: boolean;
|
|
24
27
|
/** The barrels in a tonne the multiplier carries (7.45 for gasoil), making a per-barrel price per tonne. */
|
|
25
28
|
perTonne: number | null;
|
|
29
|
+
/** The multiplier carries 100 (1), making a percent basis points, or 0.01 (-1), making basis points a percent. */
|
|
30
|
+
percentBp: 1 | -1 | null;
|
|
26
31
|
}
|
|
27
32
|
|
|
28
33
|
export interface FormulaTerms {
|
|
@@ -34,7 +39,7 @@ export interface FormulaTerms {
|
|
|
34
39
|
}
|
|
35
40
|
|
|
36
41
|
/**
|
|
37
|
-
* A formula study's terms: `weight1`, `perBarrel1`, `perTonne1` ... per
|
|
42
|
+
* A formula study's terms: `weight1`, `perBarrel1`, `perTonne1`, `percentBp1` ... per
|
|
38
43
|
* input it adds up, `power1` ... (1 or -1) per input it multiplies or divides
|
|
39
44
|
* the sum by, and an optional `divisor`. A saved or hand-edited spec can carry
|
|
40
45
|
* a multiplier or divisor no formula was written with (a value that is not a
|
|
@@ -55,11 +60,13 @@ export function formulaTerms(spec: ChartStudySpec, inputs: readonly ResolvedSeri
|
|
|
55
60
|
if (!isFiniteNumber(weight)) return { error: `The multiplier of ${legName(input)} is missing or not a number; write the formula again.` };
|
|
56
61
|
if (weight === 0) return { error: `${legName(input)} has a multiplier of 0, which removes it; leave it out of the formula instead.` };
|
|
57
62
|
const perTonne = spec.parameters[`perTonne${index + 1}`];
|
|
63
|
+
const percentBp = spec.parameters[`percentBp${index + 1}`];
|
|
58
64
|
legs.push({
|
|
59
65
|
index,
|
|
60
66
|
weight,
|
|
61
67
|
perBarrel: spec.parameters[`perBarrel${index + 1}`] === 1,
|
|
62
68
|
perTonne: isFiniteNumber(perTonne) && isBarrelsPerTonne(perTonne) ? perTonne : null,
|
|
69
|
+
percentBp: percentBp === 1 || percentBp === -1 ? percentBp : null,
|
|
63
70
|
});
|
|
64
71
|
}
|
|
65
72
|
if (legs.length === 0) return { error: "The formula has no series to add up, only series it divides by; write the formula again." };
|
|
@@ -71,18 +78,32 @@ export function formulaTerms(spec: ChartStudySpec, inputs: readonly ResolvedSeri
|
|
|
71
78
|
|
|
72
79
|
/**
|
|
73
80
|
* A leg's unit once its multiplier is applied: 42 gallons of a per-gallon
|
|
74
|
-
* price are a barrel's worth,
|
|
81
|
+
* price are a barrel's worth, 7.45 barrels of gasoil a tonne's, and 100 times
|
|
82
|
+
* a percent is basis points.
|
|
75
83
|
*/
|
|
76
|
-
function formulaLegUnit(leg: FormulaLeg, input: ResolvedSeries):
|
|
84
|
+
function formulaLegUnit(leg: FormulaLeg, input: ResolvedSeries): SeriesUnit {
|
|
85
|
+
const converted = leg.percentBp ? percentBasisPointUnit(input.unit, leg.percentBp) : null;
|
|
86
|
+
if (converted) return converted;
|
|
77
87
|
const unit = leg.perBarrel ? perBarrelUnit(input.unit) : input.unit;
|
|
78
|
-
return leg.perTonne ? perTonneUnit(unit) : unit;
|
|
88
|
+
return { unit: leg.perTonne ? perTonneUnit(unit) : unit, unitGroup: input.unitGroup };
|
|
79
89
|
}
|
|
80
90
|
|
|
81
91
|
/** Why a formula's legs cannot be summed, or null when every leg counts the same known unit. */
|
|
82
92
|
function formulaUnitMismatch(terms: FormulaTerms, inputs: readonly ResolvedSeries[]): string | null {
|
|
83
93
|
if (terms.legs.length < 2) return null;
|
|
84
|
-
|
|
85
|
-
|
|
94
|
+
// A 100 or 0.01 times the whole formula converts each leg it can: one it cannot convert beside one it does
|
|
95
|
+
// (a bp leg beside a % one, `(FRED:DGS5 - CAP:cdx:ig)*100`) would chart 100 times its basis points as basis points.
|
|
96
|
+
const scaled = terms.legs.filter((leg) => leg.percentBp !== null);
|
|
97
|
+
const converts = (leg: FormulaLeg) => percentBasisPointUnit(inputs[leg.index]!.unit, leg.percentBp!) !== null;
|
|
98
|
+
const converted = scaled.find(converts);
|
|
99
|
+
const unconverted = scaled.find((leg) => !converts(leg));
|
|
100
|
+
if (converted && unconverted) {
|
|
101
|
+
const [one, other] = [converted, unconverted].sort((left, right) => left.index - right.index);
|
|
102
|
+
return unitMismatchMessage("formula", { series: inputs[one!.index]!, unit: inputs[one!.index]!.unit },
|
|
103
|
+
{ series: inputs[other!.index]!, unit: inputs[other!.index]!.unit });
|
|
104
|
+
}
|
|
105
|
+
const legs = terms.legs.map((leg) => ({ series: inputs[leg.index]!, ...formulaLegUnit(leg, inputs[leg.index]!) }));
|
|
106
|
+
const signatures = legs.map((leg) => knownUnitSignature(leg));
|
|
86
107
|
const other = signatures.findIndex((signature, index) => index > 0 && (signature === null || signature !== signatures[0]));
|
|
87
108
|
if (signatures[0] !== null && other < 0) return null;
|
|
88
109
|
return unitMismatchMessage("formula", legs[0]!, legs[Math.max(1, other)]!);
|
|
@@ -149,9 +170,14 @@ export function formulaUnit(terms: FormulaTerms, inputs: readonly ResolvedSeries
|
|
|
149
170
|
const mismatch = formulaUnitMismatch(terms, inputs);
|
|
150
171
|
if (mismatch) return { error: mismatch };
|
|
151
172
|
const first = inputs[terms.legs[0]!.index]!;
|
|
152
|
-
let unit: SeriesUnit =
|
|
173
|
+
let unit: SeriesUnit = formulaLegUnit(terms.legs[0]!, first);
|
|
153
174
|
for (const factor of terms.factors) {
|
|
154
175
|
const series = inputs[factor.index]!;
|
|
176
|
+
// A percent over basis points, or basis points over a percent, is a plain number (formulaFactorScale).
|
|
177
|
+
if (factor.power < 0 && percentBasisPointRatioScale(unit, series) !== null) {
|
|
178
|
+
unit = PLAIN_RATIO_UNIT;
|
|
179
|
+
continue;
|
|
180
|
+
}
|
|
155
181
|
const next = combinedUnit(unit, series, factor.power);
|
|
156
182
|
const issue = fxConversionIssue(unit, series, factor.power, next);
|
|
157
183
|
if (issue) return { error: issue };
|
|
@@ -160,6 +186,21 @@ export function formulaUnit(terms: FormulaTerms, inputs: readonly ResolvedSeries
|
|
|
160
186
|
return unit;
|
|
161
187
|
}
|
|
162
188
|
|
|
189
|
+
/**
|
|
190
|
+
* What each series a formula divides by scales its value by besides itself:
|
|
191
|
+
* 100 over basis points when the formula is in %, 0.01 over a percent when it
|
|
192
|
+
* is in bp, so the two cancel to a plain number; 1 otherwise.
|
|
193
|
+
*/
|
|
194
|
+
function formulaFactorScales(terms: FormulaTerms, inputs: readonly ResolvedSeries[]): number[] {
|
|
195
|
+
let unit: SeriesUnit = formulaLegUnit(terms.legs[0]!, inputs[terms.legs[0]!.index]!);
|
|
196
|
+
return terms.factors.map((factor) => {
|
|
197
|
+
const series = inputs[factor.index]!;
|
|
198
|
+
const scale = factor.power < 0 ? percentBasisPointRatioScale(unit, series) : null;
|
|
199
|
+
unit = scale !== null ? PLAIN_RATIO_UNIT : combinedUnit(unit, series, factor.power);
|
|
200
|
+
return scale ?? 1;
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
|
|
163
204
|
export function resolveFormula(
|
|
164
205
|
spec: ChartStudySpec,
|
|
165
206
|
inputs: readonly ResolvedSeries[],
|
|
@@ -169,12 +210,14 @@ export function resolveFormula(
|
|
|
169
210
|
): ResolvedSeries[] {
|
|
170
211
|
const first = inputs[terms.legs[0]!.index]!;
|
|
171
212
|
// Rounded off the float's last digits: 42 × 4.6233 - 96.12 is 98.0586, not 98.05860000000001.
|
|
213
|
+
const factorScales = formulaFactorScales(terms, inputs);
|
|
172
214
|
const points = alignedSamples(inputs).map(({ point, values }) => {
|
|
173
215
|
let value: number | null = terms.legs.reduce((sum, leg) => sum + values[leg.index]! * leg.weight, 0) / terms.divisor;
|
|
174
|
-
|
|
216
|
+
terms.factors.forEach((factor, position) => {
|
|
175
217
|
const scale = values[factor.index]!;
|
|
176
|
-
value = value === null || (factor.power < 0 && scale === 0) ? null
|
|
177
|
-
|
|
218
|
+
value = value === null || (factor.power < 0 && scale === 0) ? null
|
|
219
|
+
: (factor.power < 0 ? value / scale : value * scale) * factorScales[position]!;
|
|
220
|
+
});
|
|
178
221
|
return derivedPoint({ point, value: 0 }, value === null ? null : Number(value.toPrecision(12)));
|
|
179
222
|
});
|
|
180
223
|
const frequencies = new Set(inputs.map((input) => input.nativeFrequency));
|
|
@@ -3,7 +3,7 @@ import type { ManualChartResolution } from "../resolution";
|
|
|
3
3
|
import type { ChartStudySpec, ResolvedSeries, SeriesPeriod, TimeSeriesPoint } from "../types";
|
|
4
4
|
import { isFiniteNumber } from "../../utils/guards";
|
|
5
5
|
import { derivedPoint, outputSeries, studyPeriod } from "./shared";
|
|
6
|
-
import { derivedValueDecimals, isPriceGroup, ratioUnit } from "./units";
|
|
6
|
+
import { derivedValueDecimals, isPriceGroup, PLAIN_RATIO_UNIT, percentBasisPointRatioScale, ratioUnit } from "./units";
|
|
7
7
|
|
|
8
8
|
interface PairedSample {
|
|
9
9
|
point: TimeSeriesPoint;
|
|
@@ -49,6 +49,11 @@ function pairedHistoryResolution(left: ResolvedSeries, right: ResolvedSeries): M
|
|
|
49
49
|
return left.historyResolution === right.historyResolution ? left.historyResolution : null;
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
+
/** A pair's leg as its formula names it: a published series as written, anything else by its label. */
|
|
53
|
+
function pairLegName(series: ResolvedSeries): string {
|
|
54
|
+
return series.expression ?? series.label;
|
|
55
|
+
}
|
|
56
|
+
|
|
52
57
|
export function resolvePairStudy(
|
|
53
58
|
spec: ChartStudySpec,
|
|
54
59
|
left: ResolvedSeries,
|
|
@@ -58,15 +63,19 @@ export function resolvePairStudy(
|
|
|
58
63
|
const paired = pairedSamples(left, right, spec.kind !== "correlation");
|
|
59
64
|
if (spec.kind === "ratio" || spec.kind === "spread") {
|
|
60
65
|
const multiplier = isFiniteNumber(spec.parameters.multiplier) ? spec.parameters.multiplier : 1;
|
|
66
|
+
const ratioStudy = spec.kind === "ratio";
|
|
67
|
+
// A percent over basis points cancels to a plain number, 100 times the quotient (4.1% over 61bp is 6.72),
|
|
68
|
+
// rounded off the float's last digits.
|
|
69
|
+
const percentScale = ratioStudy ? percentBasisPointRatioScale(left, right) : null;
|
|
61
70
|
const points = paired.map((sample) => derivedPoint(
|
|
62
71
|
{ point: sample.point, value: sample.left },
|
|
63
|
-
|
|
64
|
-
? sample.right === 0 ? null : sample.left / sample.right
|
|
72
|
+
ratioStudy
|
|
73
|
+
? sample.right === 0 ? null : percentScale === null ? sample.left / sample.right
|
|
74
|
+
: Number((sample.left / sample.right * percentScale).toPrecision(12))
|
|
65
75
|
: sample.left - sample.right * multiplier,
|
|
66
76
|
));
|
|
67
|
-
const ratioStudy = spec.kind === "ratio";
|
|
68
77
|
const outputUnit = ratioStudy
|
|
69
|
-
? ratioUnit(left, right)
|
|
78
|
+
? percentScale === null ? ratioUnit(left, right) : PLAIN_RATIO_UNIT
|
|
70
79
|
: { unit: left.unit, unitGroup: left.unitGroup };
|
|
71
80
|
// A price over an FX rate is a price in the other currency (EUR / barrel),
|
|
72
81
|
// stated as a future's unit is; a plain ratio keeps its own decimals.
|
|
@@ -75,9 +84,11 @@ export function resolvePairStudy(
|
|
|
75
84
|
return [outputSeries(spec, left, {
|
|
76
85
|
...(convertedPrice ? { statedUnit: outputUnit.unit, priceAssetCategory: null } : {}),
|
|
77
86
|
...(valueDecimals !== undefined ? { valueDecimals } : {}),
|
|
87
|
+
// A published series reads as it is written (FRED:BAMLC0A0CM - CAP:cdx:ig): its long title would
|
|
88
|
+
// read like the leg's own line in a legend that has to shorten.
|
|
78
89
|
label: ratioStudy
|
|
79
|
-
? `${left
|
|
80
|
-
: `${left
|
|
90
|
+
? `${pairLegName(left)} / ${pairLegName(right)}`
|
|
91
|
+
: `${pairLegName(left)} - ${multiplier === 1 ? "" : `${multiplier}×`}${pairLegName(right)}`,
|
|
81
92
|
points,
|
|
82
93
|
color,
|
|
83
94
|
unit: outputUnit.unit,
|
|
@@ -57,9 +57,9 @@ export function knownUnitSignature(series: Pick<ResolvedSeries, "unit" | "unitGr
|
|
|
57
57
|
return `${basis ?? ""}|${parts.map(unitFactorIdentity).join("/")}`;
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
-
/** A leg as an error
|
|
60
|
+
/** A leg as a formula and an error name it: its ticker (HO=F), else as it is written (FRED:BAMLC0A0CM), else its label. */
|
|
61
61
|
export function legName(series: ResolvedSeries): string {
|
|
62
|
-
return series.listing?.symbol || series.label;
|
|
62
|
+
return series.listing?.symbol || series.expression || series.label;
|
|
63
63
|
}
|
|
64
64
|
|
|
65
65
|
/** What a leg's unit is, in words: "is USD / gallon", "is in %", "is in USD per an unknown quantity". */
|
|
@@ -97,6 +97,10 @@ export function unitMismatchMessage(
|
|
|
97
97
|
if (gallons && leftCurrency === rightCurrency) {
|
|
98
98
|
return `${named}: write ${GALLONS_PER_BARREL}*${gallons} to compare per barrel.`;
|
|
99
99
|
}
|
|
100
|
+
// A percent beside basis points is 100 short of them, a known conversion as 42 gallons are a barrel.
|
|
101
|
+
const percent = isPercentUnit(left.unit) && isBasisPointUnit(right.unit) ? leftName
|
|
102
|
+
: isBasisPointUnit(left.unit) && isPercentUnit(right.unit) ? rightName : null;
|
|
103
|
+
if (percent) return `${named}: write ${BP_PER_PERCENT}*${percent} to compare in bp.`;
|
|
100
104
|
const subject = kind === "spread" ? "a spread" : "a formula";
|
|
101
105
|
if (leftCurrency && rightCurrency && leftCurrency !== rightCurrency) return `${named}: ${subject} does not convert currencies.`;
|
|
102
106
|
const known = knownUnitSignature({ unit: left.unit, unitGroup: left.series.unitGroup }) !== null
|
|
@@ -122,6 +126,49 @@ export interface SeriesUnit {
|
|
|
122
126
|
unitGroup: string;
|
|
123
127
|
}
|
|
124
128
|
|
|
129
|
+
/**
|
|
130
|
+
* Basis points, in the group a catalog series in bp draws in (CDX IG), so a
|
|
131
|
+
* spread converted to bp shares its axis.
|
|
132
|
+
*/
|
|
133
|
+
export const BASIS_POINT_UNIT: SeriesUnit = { unit: "bp", unitGroup: "series:bp" };
|
|
134
|
+
/** Percent, in the group FRED's percent series and a catalog series in % draw in. */
|
|
135
|
+
const PERCENT_UNIT: SeriesUnit = { unit: "%", unitGroup: "percent" };
|
|
136
|
+
/** Basis points in a percentage point: 0.93% is 93bp. */
|
|
137
|
+
export const BP_PER_PERCENT = 100;
|
|
138
|
+
|
|
139
|
+
function isPercentUnit(unit: string): boolean {
|
|
140
|
+
return unit.trim() === "%";
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function isBasisPointUnit(unit: string): boolean {
|
|
144
|
+
return /^bps?$/i.test(unit.trim());
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* The unit a leg reads in once its multiplier converts it: times 100, a
|
|
149
|
+
* percent is basis points (0.93% is 93bp); times 0.01, basis points are a
|
|
150
|
+
* percent. Null when the conversion does not apply to the unit.
|
|
151
|
+
*/
|
|
152
|
+
export function percentBasisPointUnit(unit: string, direction: 1 | -1): SeriesUnit | null {
|
|
153
|
+
if (direction === 1 && isPercentUnit(unit)) return BASIS_POINT_UNIT;
|
|
154
|
+
if (direction === -1 && isBasisPointUnit(unit)) return PERCENT_UNIT;
|
|
155
|
+
return null;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* What a percent over basis points, or basis points over a percent, is
|
|
160
|
+
* multiplied by to cancel to a plain number: 100 for % over bp, 0.01 for bp
|
|
161
|
+
* over %. 4.1% over 61bp is 410bp over 61bp, 6.72. Null for any other pair.
|
|
162
|
+
*/
|
|
163
|
+
export function percentBasisPointRatioScale(numerator: Pick<SeriesUnit, "unit">, denominator: Pick<SeriesUnit, "unit">): number | null {
|
|
164
|
+
if (isPercentUnit(numerator.unit) && isBasisPointUnit(denominator.unit)) return BP_PER_PERCENT;
|
|
165
|
+
if (isBasisPointUnit(numerator.unit) && isPercentUnit(denominator.unit)) return 1 / BP_PER_PERCENT;
|
|
166
|
+
return null;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/** A plain number: a ratio whose units cancel. */
|
|
170
|
+
export const PLAIN_RATIO_UNIT: SeriesUnit = { unit: "x", unitGroup: "ratio" };
|
|
171
|
+
|
|
125
172
|
const UNKNOWN_UNIT: SeriesUnit = { unit: "unknown", unitGroup: "derived-unit:unknown" };
|
|
126
173
|
|
|
127
174
|
export function isPriceGroup(unitGroup: string): boolean {
|
package/src/time-series/types.ts
CHANGED
|
@@ -238,6 +238,12 @@ export interface ResolvedSeries {
|
|
|
238
238
|
* figures of the period asked for, while its annual ones exist.
|
|
239
239
|
*/
|
|
240
240
|
unreportedPeriod?: "quarterly";
|
|
241
|
+
/**
|
|
242
|
+
* Set where the series' current value is not meaningful (N/M): EV/EBITDA
|
|
243
|
+
* over EBITDA at or below zero, or a bank's or an insurer's, with why and
|
|
244
|
+
* the period it would end on (`valuationNotMeaningful`).
|
|
245
|
+
*/
|
|
246
|
+
notMeaningful?: { reason: string; asOf: string };
|
|
241
247
|
/** Acquired market-history cadence; null is explicitly unknown, undefined is legacy or nonmarket. */
|
|
242
248
|
historyResolution?: ManualChartResolution | null;
|
|
243
249
|
/**
|
|
@@ -265,6 +271,12 @@ export interface ResolvedSeries {
|
|
|
265
271
|
* VWAP follow. Set even where no exchange time zone is known (futures).
|
|
266
272
|
*/
|
|
267
273
|
listing?: { symbol: string; exchange: string };
|
|
274
|
+
/**
|
|
275
|
+
* A dataset series as a formula writes it (`FRED:BAMLC0A0CM`,
|
|
276
|
+
* `CAP:cdx:ig`): what a formula's label and its unit errors name it by,
|
|
277
|
+
* so they read as written rather than as the source's long title.
|
|
278
|
+
*/
|
|
279
|
+
expression?: string;
|
|
268
280
|
/** Price/volume observations and their derived studies, including 24/7
|
|
269
281
|
* markets. Independent of whether the chart compresses exchange sessions.
|
|
270
282
|
* `dataset`: a capability's published observations (vessel transits),
|
|
@@ -105,4 +105,6 @@ export interface DesktopWindowBridge {
|
|
|
105
105
|
subscribeState(listener: (snapshot: DesktopSharedStateSnapshot) => void): () => void;
|
|
106
106
|
subscribeDockPreview?(listener: (preview: DesktopDockPreviewState) => void): () => void;
|
|
107
107
|
subscribeThemePreview?(listener: (preview: DesktopThemePreviewState) => void): () => void;
|
|
108
|
+
/** A window change the desktop app could not save (a window closed, a pane docked or moved), in the main window. */
|
|
109
|
+
subscribeSaveFailures?(listener: () => void): () => void;
|
|
108
110
|
}
|
package/src/types/financials.ts
CHANGED
|
@@ -167,6 +167,12 @@ export interface Quote extends DepositaryReceiptFacts {
|
|
|
167
167
|
* date the close (PreviousCloseDates); a source may set it too.
|
|
168
168
|
*/
|
|
169
169
|
previousCloseDate?: string;
|
|
170
|
+
/**
|
|
171
|
+
* A thin listing that did not trade in the session its venue's calendar
|
|
172
|
+
* puts before the move's, and whose daily closes do not say which day its
|
|
173
|
+
* previousClose is from (PreviousCloseDates): its move names no day.
|
|
174
|
+
*/
|
|
175
|
+
previousCloseUndated?: boolean;
|
|
170
176
|
/** Official close of a completed regular session, in this quote's currency. */
|
|
171
177
|
regularClose?: number;
|
|
172
178
|
/** Exchange-local date of regularClose; separate from the daily previous-close reference. */
|
package/src/types/headless.ts
CHANGED
|
@@ -497,6 +497,12 @@ interface HeadlessPaneResultBase {
|
|
|
497
497
|
*/
|
|
498
498
|
warnings?: string[];
|
|
499
499
|
metadata?: Record<string, unknown>;
|
|
500
|
+
/**
|
|
501
|
+
* Options the load settled from what it was given rather than from a flag
|
|
502
|
+
* (AUCT's market, from a search naming Hong Kong's paper): the report's
|
|
503
|
+
* `options` show these, so they name what was used, not the default.
|
|
504
|
+
*/
|
|
505
|
+
appliedOptions?: HeadlessPaneOptionValues;
|
|
500
506
|
/** What this load knows about its data's source and age; overrides the definition's `freshness`. */
|
|
501
507
|
freshness?: HeadlessPaneFreshness;
|
|
502
508
|
}
|
|
@@ -692,6 +698,8 @@ export interface HeadlessSeries {
|
|
|
692
698
|
textCompact?: boolean;
|
|
693
699
|
/** Each point's `value` is its bar's close: `--csv` and `--ndjson` write Close alone, JSON keeps both. */
|
|
694
700
|
valueIsClose?: boolean;
|
|
701
|
+
/** The series' current value is not meaningful: the report prints N/M dated by the period, and why. */
|
|
702
|
+
notMeaningful?: { reason: string; asOf: string };
|
|
695
703
|
points: HeadlessSeriesPoint[];
|
|
696
704
|
}
|
|
697
705
|
|
package/src/utils/cli-output.ts
CHANGED
|
@@ -9,7 +9,7 @@ export interface CliTableColumn {
|
|
|
9
9
|
maxWidth?: number;
|
|
10
10
|
/** The narrowest a text column wraps to (MIN_WRAPPED_COLUMN_WIDTH unless set), or a `shrink: true` column is cut to; a narrower table moves columns under their rows. */
|
|
11
11
|
minWidth?: number;
|
|
12
|
-
/** Dropped, rightmost first, before any column is cut or moved to fit a terminal. */
|
|
12
|
+
/** Dropped, rightmost first, before any column is cut or moved to fit a terminal. Plain output keeps it, moved under its row. */
|
|
13
13
|
optional?: boolean;
|
|
14
14
|
/** Among optional columns, a higher priority is dropped sooner; equal ones go rightmost first. */
|
|
15
15
|
dropPriority?: number;
|
|
@@ -711,12 +711,14 @@ function renderTableLayout(
|
|
|
711
711
|
}) : [];
|
|
712
712
|
const ownStacked = stacked.filter((entry) => !shared.includes(entry));
|
|
713
713
|
// Columns moved under the rows print there as `Header value`, as many to a line as fit.
|
|
714
|
+
// Plain output keeps a moved column's empty cell as its dash, so every row reads the same columns.
|
|
715
|
+
const keepsEmpty = cliPlainEnabled();
|
|
714
716
|
const renderStacked = (entries: readonly TableEntry[], cells: string[], rowIndex: number, lineIndent: string, width: number): string[] => {
|
|
715
717
|
const lines: string[] = [];
|
|
716
718
|
let line = "";
|
|
717
719
|
for (const { column, index } of entries) {
|
|
718
720
|
const value = cells[index] ?? "";
|
|
719
|
-
if (rowIndex >= (column.stackRows ?? Infinity) || EMPTY_CELL.test(stripAnsi(value).trim())) continue;
|
|
721
|
+
if (rowIndex >= (column.stackRows ?? Infinity) || (!keepsEmpty && EMPTY_CELL.test(stripAnsi(value).trim()))) continue;
|
|
720
722
|
const piece = `${cliStyles.muted(column.header)} ${value}`;
|
|
721
723
|
if (line && visibleLength(line) + COLUMN_GAP + visibleLength(piece) <= width) {
|
|
722
724
|
line += `${" ".repeat(COLUMN_GAP)}${piece}`;
|
|
@@ -774,7 +776,8 @@ export function renderTable(columns: CliTableColumn[], rows: string[][], options
|
|
|
774
776
|
if (available == null || tableWidth(shown.map((entry) => entry.width)) <= available) {
|
|
775
777
|
return renderTableLayout(columns, rows, options, shown, [], available, false);
|
|
776
778
|
}
|
|
777
|
-
|
|
779
|
+
// Plain output keeps every column (`--plain` promises it): an optional one moves under its row instead.
|
|
780
|
+
while (!cliPlainEnabled() && tableWidth(shown.map((entry) => entry.width)) > available) {
|
|
778
781
|
const dropped = shown.reduce<(typeof shown)[number] | undefined>((pick, entry) => (
|
|
779
782
|
entry.column.optional && (!pick || (entry.column.dropPriority ?? 0) >= (pick.column.dropPriority ?? 0)) ? entry : pick
|
|
780
783
|
), undefined);
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import type { FinancialStatement } from "../types/financials";
|
|
2
|
+
import { completeAvailability, statementFieldAvailability } from "./financial-statements";
|
|
3
|
+
|
|
4
|
+
const finite = (value: unknown): value is number => typeof value === "number" && Number.isFinite(value);
|
|
5
|
+
|
|
6
|
+
type DepreciationField = "depreciationAndAmortization" | "depreciationAmortizationDepletion";
|
|
7
|
+
|
|
8
|
+
/** The row's D&A: the cash flow statement's line, or D&A with depletion where only that is reported. */
|
|
9
|
+
function depreciation(row: FinancialStatement): { value: number; field: DepreciationField } | null {
|
|
10
|
+
for (const field of ["depreciationAndAmortization", "depreciationAmortizationDepletion"] as const) {
|
|
11
|
+
const value = row[field];
|
|
12
|
+
// An add-back: some sources sign it as the cash flow line, others as the expense.
|
|
13
|
+
if (finite(value)) return { value: Math.abs(value), field };
|
|
14
|
+
}
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** Operating income, and how it was read when the row does not report it: the lines it was derived from. */
|
|
19
|
+
interface OperatingIncome {
|
|
20
|
+
value: number;
|
|
21
|
+
/** Null where the row reports operating income; else what it was derived as ("pretax income + interest expense - other income"). */
|
|
22
|
+
basis: string | null;
|
|
23
|
+
fields: readonly (keyof FinancialStatement)[];
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* The row's operating income: the reported line, or, where a row lacks it (an
|
|
28
|
+
* energy major's quarter filed without one), derived from the lines it
|
|
29
|
+
* carries: revenue less total expenses, revenue less cost of revenue and
|
|
30
|
+
* operating expenses, else pretax income (or net income with its income tax
|
|
31
|
+
* added back) with interest expense added back and non-operating items taken
|
|
32
|
+
* out, as far as the row carries them. On Exxon Mobil's 2025 year each gives
|
|
33
|
+
* the 33.94B it reported.
|
|
34
|
+
*/
|
|
35
|
+
function operatingIncome(row: FinancialStatement, derive: boolean): OperatingIncome | null {
|
|
36
|
+
if (finite(row.operatingIncome)) return { value: row.operatingIncome, basis: null, fields: ["operatingIncome"] };
|
|
37
|
+
if (!derive) return null;
|
|
38
|
+
if (finite(row.totalRevenue) && finite(row.totalExpenses)) {
|
|
39
|
+
return { value: row.totalRevenue - row.totalExpenses, basis: "revenue less total expenses", fields: ["totalRevenue", "totalExpenses"] };
|
|
40
|
+
}
|
|
41
|
+
if (finite(row.totalRevenue) && finite(row.costOfRevenue) && finite(row.operatingExpense)) {
|
|
42
|
+
return {
|
|
43
|
+
value: row.totalRevenue - row.costOfRevenue - row.operatingExpense,
|
|
44
|
+
basis: "revenue less cost of revenue and operating expenses",
|
|
45
|
+
fields: ["totalRevenue", "costOfRevenue", "operatingExpense"],
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
const pretax = pretaxIncome(row);
|
|
49
|
+
if (!pretax) return null;
|
|
50
|
+
const interest = finite(row.interestExpense) ? Math.abs(row.interestExpense) : null;
|
|
51
|
+
// Other income and expense is every non-operating line together; the other non-operating line alone is part of it.
|
|
52
|
+
const nonOperating = finite(row.otherIncomeExpense) ? { value: row.otherIncomeExpense, field: "otherIncomeExpense" as const }
|
|
53
|
+
: finite(row.otherNonOperatingIncomeExpenses) ? { value: row.otherNonOperatingIncomeExpenses, field: "otherNonOperatingIncomeExpenses" as const }
|
|
54
|
+
: null;
|
|
55
|
+
return {
|
|
56
|
+
value: pretax.value + (interest ?? 0) - (nonOperating?.value ?? 0),
|
|
57
|
+
basis: [pretax.basis, ...interest !== null ? ["+ interest expense"] : [], ...nonOperating ? ["- non-operating items"] : []].join(" "),
|
|
58
|
+
fields: [...pretax.fields, ...interest !== null ? ["interestExpense" as const] : [], ...nonOperating ? [nonOperating.field] : []],
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** Pretax income as reported, or as net income (with minority interests) plus its income tax (Chevron's quarters file no pretax line). */
|
|
63
|
+
function pretaxIncome(row: FinancialStatement): { value: number; basis: string; fields: readonly (keyof FinancialStatement)[] } | null {
|
|
64
|
+
if (finite(row.pretaxIncome)) return { value: row.pretaxIncome, basis: "pretax income", fields: ["pretaxIncome"] };
|
|
65
|
+
if (!finite(row.taxProvision)) return null;
|
|
66
|
+
const income = finite(row.netIncomeIncludingNoncontrollingInterests) ? "netIncomeIncludingNoncontrollingInterests" as const
|
|
67
|
+
: finite(row.netIncome) ? "netIncome" as const : null;
|
|
68
|
+
return income ? { value: row[income]! + row.taxProvision, basis: "net income + income tax", fields: [income, "taxProvision"] } : null;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Whether a company's statements carry no EBITDA that means anything: a bank's
|
|
73
|
+
* or an insurer's interest and claims are its operations, so operating income
|
|
74
|
+
* is not derived for it and an EV over its EBITDA reads N/M.
|
|
75
|
+
*/
|
|
76
|
+
export function isBankOrInsurerIndustry(industry: string | null | undefined): boolean {
|
|
77
|
+
return /\b(banks?|insurance|insurers?|reinsurance)\b/i.test(industry ?? "");
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** What an EV/EBITDA reads for a bank or an insurer (isBankOrInsurerIndustry). */
|
|
81
|
+
export const BANK_OR_INSURER_EBITDA = "not meaningful for banks and insurers";
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* EBITDA as the glossary defines it and sell-side comps read it: operating
|
|
85
|
+
* income with D&A added back. Null when the row lacks either; a source's own
|
|
86
|
+
* EBITDA line can carry non-operating income and is never used in its place.
|
|
87
|
+
*/
|
|
88
|
+
function statementEbitda(row: FinancialStatement, derive: boolean): { value: number; income: OperatingIncome; amortization: { value: number; field: DepreciationField } } | null {
|
|
89
|
+
const amortization = depreciation(row);
|
|
90
|
+
const income = operatingIncome(row, derive);
|
|
91
|
+
return income && amortization ? { value: income.value + amortization.value, income, amortization } : null;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** Whether the row's EBITDA is missing for want of D&A beside a reported operating income, which a cell says. */
|
|
95
|
+
export function ebitdaLacksDepreciation(row: FinancialStatement | null | undefined): boolean {
|
|
96
|
+
return !!row && !finite(row.ebitda) && finite(row.operatingIncome) && !depreciation(row);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* How the row's EBITDA read its operating income where the row reports none:
|
|
101
|
+
* `pretax income + interest expense - non-operating items`. Null where it was
|
|
102
|
+
* reported, or where the row has no EBITDA.
|
|
103
|
+
*/
|
|
104
|
+
export function ebitdaOperatingIncomeBasis(row: FinancialStatement | null | undefined): string | null {
|
|
105
|
+
if (!row || !finite(row.ebitda) || finite(row.operatingIncome)) return null;
|
|
106
|
+
return operatingIncome(row, true)?.basis ?? null;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* The row with `ebitda` on that definition, dated by the later of its inputs:
|
|
111
|
+
* the source's figure is dropped, and a row without D&A has none. `derive`
|
|
112
|
+
* false (a bank's or an insurer's rows) reads reported operating income alone.
|
|
113
|
+
*/
|
|
114
|
+
export function withStatementEbitda<T extends FinancialStatement>(row: T, derive = true): T {
|
|
115
|
+
const ebitda = statementEbitda(row, derive);
|
|
116
|
+
const value = ebitda?.value ?? null;
|
|
117
|
+
const availableAt = ebitda
|
|
118
|
+
? completeAvailability([...ebitda.income.fields, ebitda.amortization.field].map((field) => statementFieldAvailability(row, field)))
|
|
119
|
+
: undefined;
|
|
120
|
+
if (row.ebitda === (value ?? undefined) && (!row.fieldAvailability || row.fieldAvailability.ebitda === availableAt)) return row;
|
|
121
|
+
const { ebitda: _source, ...rest } = row;
|
|
122
|
+
const next = (value === null ? rest : { ...rest, ebitda: value }) as T;
|
|
123
|
+
if (row.fieldAvailability) {
|
|
124
|
+
const { ebitda: _dated, ...fieldAvailability } = row.fieldAvailability;
|
|
125
|
+
next.fieldAvailability = availableAt ? { ...fieldAvailability, ebitda: availableAt } : fieldAvailability;
|
|
126
|
+
}
|
|
127
|
+
return next;
|
|
128
|
+
}
|
package/src/utils/format.ts
CHANGED
|
@@ -353,7 +353,7 @@ export function displayWidth(value: string): number {
|
|
|
353
353
|
return segmentGraphemes(value).reduce((total, segment) => total + graphemeWidth(segment), 0);
|
|
354
354
|
}
|
|
355
355
|
|
|
356
|
-
function truncateToWidth(value: string, width: number): string {
|
|
356
|
+
export function truncateToWidth(value: string, width: number): string {
|
|
357
357
|
if (width <= 0) return "";
|
|
358
358
|
if (SINGLE_WIDTH_ASCII_RE.test(value)) return value.slice(0, width);
|
|
359
359
|
let output = "";
|
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
|
+
}
|