@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
|
@@ -71,9 +71,10 @@ export interface ListViewProps {
|
|
|
71
71
|
selectOnHover?: boolean;
|
|
72
72
|
autoScrollToIndex?: boolean;
|
|
73
73
|
/**
|
|
74
|
-
* The rows are checkboxes (ToggleList)
|
|
75
|
-
*
|
|
76
|
-
* leaves Enter to its
|
|
74
|
+
* The rows are checkboxes (ToggleList), or choices a dialog asks beside its
|
|
75
|
+
* buttons. A focused desktop row toggles or picks on Space and leaves Enter
|
|
76
|
+
* to the surface around the list, the way a checkbox leaves Enter to its
|
|
77
|
+
* dialog's default button.
|
|
77
78
|
*/
|
|
78
79
|
checkboxRows?: boolean;
|
|
79
80
|
onMouseScroll?: (event: any) => void;
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import { Box, Text, TextAttributes, useUiHost } from "../../ui";
|
|
2
|
+
import type { BoxRenderable } from "../../ui/host";
|
|
2
3
|
import { useShortcut } from "../../react/input";
|
|
3
|
-
import { useCallback, type ComponentType, type ReactNode } from "react";
|
|
4
|
+
import { useCallback, useLayoutEffect, useRef, useState, type ComponentType, type ReactNode } from "react";
|
|
4
5
|
import { colors } from "../../theme/colors";
|
|
5
6
|
import { usePaneShareItem } from "../../shares/pane-item";
|
|
7
|
+
import { observeBoxWidth } from "../../renderers/opentui/box-width";
|
|
8
|
+
import { clipToDisplayWidth } from "../../utils/format";
|
|
6
9
|
import {
|
|
7
10
|
isDetailBackNavigationKey,
|
|
8
11
|
isMouseBackNavigationEvent,
|
|
@@ -51,6 +54,25 @@ export function PageStackView({
|
|
|
51
54
|
return <OpenTuiPageStackView {...props} />;
|
|
52
55
|
}
|
|
53
56
|
|
|
57
|
+
/**
|
|
58
|
+
* The item's title on the one row Back sits in: a title longer than the room
|
|
59
|
+
* the row leaves ends in an ellipsis, it never wraps. The room is only known
|
|
60
|
+
* once the row is laid out, so until then the whole title is drawn, clipped
|
|
61
|
+
* by its box.
|
|
62
|
+
*/
|
|
63
|
+
function StackTitle({ title }: { title: string }) {
|
|
64
|
+
const boxRef = useRef<BoxRenderable>(null);
|
|
65
|
+
const [width, setWidth] = useState<number | null>(null);
|
|
66
|
+
useLayoutEffect(() => observeBoxWidth(boxRef.current, setWidth), []);
|
|
67
|
+
return (
|
|
68
|
+
<Box ref={boxRef} flexGrow={1} flexShrink={1} flexBasis={0} minWidth={0} overflow="hidden">
|
|
69
|
+
<Text fg={colors.textBright} attributes={TextAttributes.BOLD} wrapMode="none">
|
|
70
|
+
{width === null ? title : clipToDisplayWidth(title, width)}
|
|
71
|
+
</Text>
|
|
72
|
+
</Box>
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
|
|
54
76
|
function OpenTuiPageStackView({
|
|
55
77
|
focused,
|
|
56
78
|
detailOpen,
|
|
@@ -121,11 +143,7 @@ function OpenTuiPageStackView({
|
|
|
121
143
|
{detailTitle ? (
|
|
122
144
|
<>
|
|
123
145
|
<Box width={1} flexShrink={0} />
|
|
124
|
-
<
|
|
125
|
-
<Text fg={colors.textBright} attributes={TextAttributes.BOLD}>
|
|
126
|
-
{detailTitle}
|
|
127
|
-
</Text>
|
|
128
|
-
</Box>
|
|
146
|
+
<StackTitle title={detailTitle} />
|
|
129
147
|
</>
|
|
130
148
|
) : (
|
|
131
149
|
<Box flexGrow={1} />
|
|
@@ -3,6 +3,7 @@ import { t, tf } from "../../i18n";
|
|
|
3
3
|
import { useThemeColors } from "../../theme/theme-context";
|
|
4
4
|
import { Box, Text, useUiCapabilities } from "../../ui";
|
|
5
5
|
import { formatRelativeAge } from "../../utils/datetime-format";
|
|
6
|
+
import { readableError } from "../../utils/reason-codes";
|
|
6
7
|
import { Spinner } from "./loading";
|
|
7
8
|
import { ButtonActionScope } from "./action-scope";
|
|
8
9
|
import { blendForContrast, higherContrast } from "../../theme/color-utils";
|
|
@@ -206,7 +207,8 @@ function EmptyStateBody({ title, message, hint, actions, retry, status = "empty"
|
|
|
206
207
|
onPress={feedback.press}
|
|
207
208
|
/>
|
|
208
209
|
) : null;
|
|
209
|
-
// Provider messages must wrap at narrow pane widths rather than lose their tail
|
|
210
|
+
// Provider messages must wrap at narrow pane widths rather than lose their tail,
|
|
211
|
+
// and a bare reason code (UPSTREAM_ERROR) a pane passed on reads as words.
|
|
210
212
|
return (
|
|
211
213
|
<Box
|
|
212
214
|
id={domId}
|
|
@@ -215,9 +217,9 @@ function EmptyStateBody({ title, message, hint, actions, retry, status = "empty"
|
|
|
215
217
|
data-gloom-ui="empty-state"
|
|
216
218
|
style={inset ? NATIVE_STATE_INSET : undefined}
|
|
217
219
|
>
|
|
218
|
-
<Box><Text fg={status === "error" ? colors.negative : colors.textDim} wrapText>{t(title)}</Text></Box>
|
|
219
|
-
{message && <Box><Text fg={colors.textMuted} wrapText>{t(message)}</Text></Box>}
|
|
220
|
-
{hint && <Box><Text fg={colors.textMuted} wrapText>{t(hint)}</Text></Box>}
|
|
220
|
+
<Box><Text fg={status === "error" ? colors.negative : colors.textDim} wrapText>{t(readableError(title))}</Text></Box>
|
|
221
|
+
{message && <Box><Text fg={colors.textMuted} wrapText>{t(readableError(message))}</Text></Box>}
|
|
222
|
+
{hint && <Box><Text fg={colors.textMuted} wrapText>{t(readableError(hint))}</Text></Box>}
|
|
221
223
|
{/* Wraps in a narrow pane rather than clipping the second action; a terminal wraps without a blank row. */}
|
|
222
224
|
{(retryButton || actions) && (
|
|
223
225
|
<Box flexDirection="row" flexWrap="wrap" gap={1} rowGap={nativePaneChrome ? undefined : 0} marginTop={1}>
|
|
@@ -243,18 +245,19 @@ export function Notice({ children, tone = "warning", variant = "inline" }: Notic
|
|
|
243
245
|
const native = useUiCapabilities().nativePaneChrome;
|
|
244
246
|
const color = tone === "muted" ? colors.textDim : colors[tone];
|
|
245
247
|
const status = tone === "negative" ? "error" : "notice";
|
|
248
|
+
const body = typeof children === "string" ? readableError(children) : children;
|
|
246
249
|
// Inline feedback keeps its original single-text shape: a flex row here collapses inside content-sized parents.
|
|
247
250
|
if (variant !== "callout") {
|
|
248
251
|
return (
|
|
249
252
|
<Box data-gloom-status={status} data-gloom-ui="notice">
|
|
250
|
-
<Text fg={color} wrapText>{
|
|
253
|
+
<Text fg={color} wrapText>{body}</Text>
|
|
251
254
|
</Box>
|
|
252
255
|
);
|
|
253
256
|
}
|
|
254
257
|
const foreground = blendForContrast(color, colors.panel, higherContrast("#000000", "#ffffff", colors.panel), 4.5);
|
|
255
258
|
return (
|
|
256
259
|
<Box flexDirection="row" gap={1} paddingX={1} paddingY={native ? 0.35 : 0} backgroundColor={colors.panel} border={["left"]} borderColor={color} data-gloom-status={status} data-gloom-ui="notice" role={native ? tone === "negative" ? "alert" : "status" : undefined} aria-atomic={native ? true : undefined}>
|
|
257
|
-
<Text fg={foreground}>!</Text><Box flexGrow={1} minWidth={0}><Text fg={foreground} wrapText>{
|
|
260
|
+
<Text fg={foreground}>!</Text><Box flexGrow={1} minWidth={0}><Text fg={foreground} wrapText>{body}</Text></Box>
|
|
258
261
|
</Box>
|
|
259
262
|
);
|
|
260
263
|
}
|
package/src/docs/snapshot.json
CHANGED
|
@@ -787,6 +787,18 @@
|
|
|
787
787
|
"shot": "https://gloom.sh/screenshots/fn/CRYP.png",
|
|
788
788
|
"lesson": "/academy/crypto-and-prediction-markets/crypto-from-zero"
|
|
789
789
|
},
|
|
790
|
+
{
|
|
791
|
+
"code": "GTP",
|
|
792
|
+
"name": "Layer 2 metrics",
|
|
793
|
+
"description": "Ethereum and its layer 2 chains",
|
|
794
|
+
"detail": "Ethereum and its layer 2 chains side by side: transactions, active addresses, fees, transaction cost, stablecoin supply and value secured, with 30-day changes and a daily history chart. Data from growthepie.",
|
|
795
|
+
"category": "markets",
|
|
796
|
+
"plugin": {
|
|
797
|
+
"id": "growthepie",
|
|
798
|
+
"name": "growthepie"
|
|
799
|
+
},
|
|
800
|
+
"shot": "https://gloom.sh/screenshots/fn/GTP.png"
|
|
801
|
+
},
|
|
790
802
|
{
|
|
791
803
|
"code": "ETFF",
|
|
792
804
|
"name": "Crypto ETF flows",
|
|
@@ -834,6 +846,18 @@
|
|
|
834
846
|
"shot": "https://gloom.sh/screenshots/fn/FNG.png",
|
|
835
847
|
"lesson": "/academy/macro-markets-and-news/markets/sentiment-and-valuation"
|
|
836
848
|
},
|
|
849
|
+
{
|
|
850
|
+
"code": "CFNG",
|
|
851
|
+
"name": "Crypto fear and greed",
|
|
852
|
+
"description": "Crypto sentiment gauge",
|
|
853
|
+
"detail": "The crypto Fear and Greed Index from Alternative.me: today's reading, yesterday, last week and last month, and its history.",
|
|
854
|
+
"category": "markets",
|
|
855
|
+
"plugin": {
|
|
856
|
+
"id": "crypto-fear-greed",
|
|
857
|
+
"name": "Crypto Fear & Greed"
|
|
858
|
+
},
|
|
859
|
+
"shot": "https://gloom.sh/screenshots/fn/CFNG.png"
|
|
860
|
+
},
|
|
837
861
|
{
|
|
838
862
|
"code": "COT",
|
|
839
863
|
"name": "CFTC positioning",
|
|
@@ -1138,6 +1162,18 @@
|
|
|
1138
1162
|
"shot": "https://gloom.sh/screenshots/fn/PM.png",
|
|
1139
1163
|
"lesson": "/academy/crypto-and-prediction-markets/prediction-markets"
|
|
1140
1164
|
},
|
|
1165
|
+
{
|
|
1166
|
+
"code": "ADJ",
|
|
1167
|
+
"name": "Adjacent indices",
|
|
1168
|
+
"description": "Prediction-market indices",
|
|
1169
|
+
"detail": "Adjacent's indices built on prediction markets, with each one's level and 1D and 7D moves, its chart and constituents, plus reference rates and CFTC filings.",
|
|
1170
|
+
"category": "markets",
|
|
1171
|
+
"plugin": {
|
|
1172
|
+
"id": "adjacent-indices",
|
|
1173
|
+
"name": "Adjacent"
|
|
1174
|
+
},
|
|
1175
|
+
"shot": "https://gloom.sh/screenshots/fn/ADJ.png"
|
|
1176
|
+
},
|
|
1141
1177
|
{
|
|
1142
1178
|
"code": "POLL",
|
|
1143
1179
|
"name": "Polls",
|
package/src/i18n/es.ts
CHANGED
|
@@ -73,6 +73,7 @@ export const es: Record<string, string> = {
|
|
|
73
73
|
"Could not apply that setting.": "No se pudo aplicar ese ajuste.",
|
|
74
74
|
"Enter {action} · Esc cancel": "Enter {action} · Esc cancelar",
|
|
75
75
|
"y {action} · Enter or Esc {cancel}": "y {action} · Enter o Esc {cancel}",
|
|
76
|
+
"y {action} · Tab note · Enter or Esc {cancel}": "y {action} · Tab nota · Enter o Esc {cancel}",
|
|
76
77
|
"Published {date}": "Publicado {date}",
|
|
77
78
|
"Language": "Idioma",
|
|
78
79
|
"Unsupported language": "Idioma no compatible",
|
|
@@ -736,6 +737,9 @@ export const es: Record<string, string> = {
|
|
|
736
737
|
"Link copied.": "Enlace copiado.",
|
|
737
738
|
"New link copied. The old one no longer works.": "Nuevo enlace copiado. El anterior ya no funciona.",
|
|
738
739
|
"Copy failed. Select the link below.": "No se pudo copiar. Selecciona el enlace de abajo.",
|
|
740
|
+
"Invite": "Invitar",
|
|
741
|
+
"Free months earned: {earned} of {cap}": "Meses gratis obtenidos: {earned} de {cap}",
|
|
742
|
+
"Copy failed. Select the link instead.": "No se pudo copiar. Selecciona el enlace.",
|
|
739
743
|
"Failed to create the calendar link.": "No se pudo crear el enlace del calendario.",
|
|
740
744
|
"Regenerate Link": "Regenerar enlace",
|
|
741
745
|
"Calendars using the current link stop updating.": "Los calendarios con el enlace actual dejarán de actualizarse.",
|
|
@@ -794,6 +798,13 @@ export const es: Record<string, string> = {
|
|
|
794
798
|
"If you keep your trial, you can still cancel before it ends without being charged.": "Si mantienes tu prueba, aún puedes cancelar antes de que termine sin que se te cobre.",
|
|
795
799
|
"End Trial Now": "Terminar prueba ahora",
|
|
796
800
|
"Keep Trial": "Mantener prueba",
|
|
801
|
+
"What made you decide to cancel? (optional)": "¿Qué te hizo decidir cancelar? (opcional)",
|
|
802
|
+
"Bugs or reliability": "Errores o fiabilidad",
|
|
803
|
+
"Missing feature": "Falta una función",
|
|
804
|
+
"Too expensive": "Demasiado caro",
|
|
805
|
+
"Not using it enough": "No lo uso lo suficiente",
|
|
806
|
+
"Only needed it temporarily": "Solo lo necesitaba temporalmente",
|
|
807
|
+
"Anything else? (optional)": "¿Algo más? (opcional)",
|
|
797
808
|
"Ending trial...": "Terminando prueba...",
|
|
798
809
|
"Ending...": "Terminando...",
|
|
799
810
|
"Trial ended. Pro is off and you won't be charged.": "Prueba terminada. Pro está desactivado y no se te cobrará.",
|
|
@@ -1691,6 +1702,7 @@ export const es: Record<string, string> = {
|
|
|
1691
1702
|
"newline": "nueva línea",
|
|
1692
1703
|
"Denied in {seconds} s": "Se deniega en {seconds} s",
|
|
1693
1704
|
"choose": "elegir",
|
|
1705
|
+
"note": "nota",
|
|
1694
1706
|
"select": "seleccionar",
|
|
1695
1707
|
"here": "aquí",
|
|
1696
1708
|
"new pane": "panel nuevo",
|
package/src/i18n/ja.ts
CHANGED
|
@@ -73,6 +73,7 @@ export const ja: Record<string, string> = {
|
|
|
73
73
|
"Could not apply that setting.": "その設定を適用できませんでした。",
|
|
74
74
|
"Enter {action} · Esc cancel": "Enter {action} · Esc キャンセル",
|
|
75
75
|
"y {action} · Enter or Esc {cancel}": "y {action} · Enter または Esc {cancel}",
|
|
76
|
+
"y {action} · Tab note · Enter or Esc {cancel}": "y {action} · Tab メモ · Enter または Esc {cancel}",
|
|
76
77
|
"Published {date}": "{date} 公開",
|
|
77
78
|
"Language": "言語",
|
|
78
79
|
"Unsupported language": "対応していない言語",
|
|
@@ -751,6 +752,9 @@ export const ja: Record<string, string> = {
|
|
|
751
752
|
"Link copied.": "リンクをコピーしました。",
|
|
752
753
|
"New link copied. The old one no longer works.": "新しいリンクをコピーしました。古いリンクは使えなくなりました。",
|
|
753
754
|
"Copy failed. Select the link below.": "コピーできませんでした。下のリンクを選択してください。",
|
|
755
|
+
"Invite": "招待",
|
|
756
|
+
"Free months earned: {earned} of {cap}": "獲得した無料月数: {cap}か月中{earned}か月",
|
|
757
|
+
"Copy failed. Select the link instead.": "コピーできませんでした。リンクを選択してください。",
|
|
754
758
|
"Failed to create the calendar link.": "カレンダーリンクを作成できませんでした。",
|
|
755
759
|
"Regenerate Link": "リンクを再生成",
|
|
756
760
|
"Calendars using the current link stop updating.": "現在のリンクを使うカレンダーは更新されなくなります。",
|
|
@@ -809,6 +813,13 @@ export const ja: Record<string, string> = {
|
|
|
809
813
|
"If you keep your trial, you can still cancel before it ends without being charged.": "トライアルを続ける場合も、終了前に解約すれば料金はかかりません。",
|
|
810
814
|
"End Trial Now": "今すぐトライアルを終了",
|
|
811
815
|
"Keep Trial": "トライアルを続ける",
|
|
816
|
+
"What made you decide to cancel? (optional)": "解約を決めた理由は?(任意)",
|
|
817
|
+
"Bugs or reliability": "バグや安定性",
|
|
818
|
+
"Missing feature": "機能が足りない",
|
|
819
|
+
"Too expensive": "高すぎる",
|
|
820
|
+
"Not using it enough": "あまり使っていない",
|
|
821
|
+
"Only needed it temporarily": "一時的に必要だっただけ",
|
|
822
|
+
"Anything else? (optional)": "ほかに何かあれば(任意)",
|
|
812
823
|
"Ending trial...": "トライアルを終了しています...",
|
|
813
824
|
"Ending...": "終了しています...",
|
|
814
825
|
"Trial ended. Pro is off and you won't be charged.": "トライアルを終了しました。Pro はオフになり、料金はかかりません。",
|
|
@@ -1688,6 +1699,7 @@ export const ja: Record<string, string> = {
|
|
|
1688
1699
|
"newline": "改行",
|
|
1689
1700
|
"Denied in {seconds} s": "{seconds} 秒後に拒否",
|
|
1690
1701
|
"choose": "選ぶ",
|
|
1702
|
+
"note": "メモ",
|
|
1691
1703
|
"select": "決定",
|
|
1692
1704
|
"here": "ここ",
|
|
1693
1705
|
"new pane": "新しいペイン",
|
package/src/i18n/ko.ts
CHANGED
|
@@ -71,6 +71,7 @@ export const ko: Record<string, string> = {
|
|
|
71
71
|
"Could not apply that setting.": "해당 설정을 적용할 수 없습니다.",
|
|
72
72
|
"Enter {action} · Esc cancel": "Enter {action} · Esc 취소",
|
|
73
73
|
"y {action} · Enter or Esc {cancel}": "y {action} · Enter 또는 Esc {cancel}",
|
|
74
|
+
"y {action} · Tab note · Enter or Esc {cancel}": "y {action} · Tab 메모 · Enter 또는 Esc {cancel}",
|
|
74
75
|
"Published {date}": "게시일 {date}",
|
|
75
76
|
"Language": "언어",
|
|
76
77
|
"Unsupported language": "지원하지 않는 언어",
|
|
@@ -749,6 +750,9 @@ export const ko: Record<string, string> = {
|
|
|
749
750
|
"Link copied.": "링크를 복사했습니다.",
|
|
750
751
|
"New link copied. The old one no longer works.": "새 링크를 복사했습니다. 이전 링크는 더 이상 작동하지 않습니다.",
|
|
751
752
|
"Copy failed. Select the link below.": "복사하지 못했습니다. 아래 링크를 선택하세요.",
|
|
753
|
+
"Invite": "초대",
|
|
754
|
+
"Free months earned: {earned} of {cap}": "받은 무료 개월: {cap}개월 중 {earned}개월",
|
|
755
|
+
"Copy failed. Select the link instead.": "복사하지 못했습니다. 링크를 선택하세요.",
|
|
752
756
|
"Failed to create the calendar link.": "캘린더 링크를 만들지 못했습니다.",
|
|
753
757
|
"Regenerate Link": "링크 재생성",
|
|
754
758
|
"Calendars using the current link stop updating.": "현재 링크를 쓰는 캘린더는 더 이상 업데이트되지 않습니다.",
|
|
@@ -807,6 +811,13 @@ export const ko: Record<string, string> = {
|
|
|
807
811
|
"If you keep your trial, you can still cancel before it ends without being charged.": "체험을 유지해도 종료 전에 해지하면 요금이 청구되지 않습니다.",
|
|
808
812
|
"End Trial Now": "지금 체험 종료",
|
|
809
813
|
"Keep Trial": "체험 유지",
|
|
814
|
+
"What made you decide to cancel? (optional)": "해지하기로 한 이유는 무엇인가요? (선택)",
|
|
815
|
+
"Bugs or reliability": "버그 또는 안정성",
|
|
816
|
+
"Missing feature": "필요한 기능 부족",
|
|
817
|
+
"Too expensive": "너무 비쌈",
|
|
818
|
+
"Not using it enough": "충분히 사용하지 않음",
|
|
819
|
+
"Only needed it temporarily": "잠시만 필요했음",
|
|
820
|
+
"Anything else? (optional)": "더 하실 말씀이 있나요? (선택)",
|
|
810
821
|
"Ending trial...": "체험 종료 중...",
|
|
811
822
|
"Ending...": "종료 중...",
|
|
812
823
|
"Trial ended. Pro is off and you won't be charged.": "체험이 종료되었습니다. Pro가 꺼졌으며 요금은 청구되지 않습니다.",
|
|
@@ -1686,6 +1697,7 @@ export const ko: Record<string, string> = {
|
|
|
1686
1697
|
"newline": "줄바꿈",
|
|
1687
1698
|
"Denied in {seconds} s": "{seconds}초 후 거부",
|
|
1688
1699
|
"choose": "고르기",
|
|
1700
|
+
"note": "메모",
|
|
1689
1701
|
"select": "선택",
|
|
1690
1702
|
"here": "여기",
|
|
1691
1703
|
"new pane": "새 패널",
|
package/src/i18n/zh-cn.ts
CHANGED
|
@@ -73,6 +73,7 @@ export const zhCN: Record<string, string> = {
|
|
|
73
73
|
"Could not apply that setting.": "无法应用该设置。",
|
|
74
74
|
"Enter {action} · Esc cancel": "Enter {action} · Esc 取消",
|
|
75
75
|
"y {action} · Enter or Esc {cancel}": "y {action} · Enter 或 Esc {cancel}",
|
|
76
|
+
"y {action} · Tab note · Enter or Esc {cancel}": "y {action} · Tab 备注 · Enter 或 Esc {cancel}",
|
|
76
77
|
"Published {date}": "已发布 {date}",
|
|
77
78
|
"Language": "语言",
|
|
78
79
|
"Unsupported language": "不支持的语言",
|
|
@@ -751,6 +752,9 @@ export const zhCN: Record<string, string> = {
|
|
|
751
752
|
"Link copied.": "已复制链接。",
|
|
752
753
|
"New link copied. The old one no longer works.": "已复制新链接。旧链接已失效。",
|
|
753
754
|
"Copy failed. Select the link below.": "复制失败。请选择下方的链接。",
|
|
755
|
+
"Invite": "邀请",
|
|
756
|
+
"Free months earned: {earned} of {cap}": "已获得免费月数:{earned}/{cap}",
|
|
757
|
+
"Copy failed. Select the link instead.": "复制失败。请选择链接。",
|
|
754
758
|
"Failed to create the calendar link.": "无法创建日历链接。",
|
|
755
759
|
"Regenerate Link": "重新生成链接",
|
|
756
760
|
"Calendars using the current link stop updating.": "使用当前链接的日历将停止更新。",
|
|
@@ -809,6 +813,13 @@ export const zhCN: Record<string, string> = {
|
|
|
809
813
|
"If you keep your trial, you can still cancel before it ends without being charged.": "如果保留试用,在试用结束前取消仍不会扣费。",
|
|
810
814
|
"End Trial Now": "立即结束试用",
|
|
811
815
|
"Keep Trial": "保留试用",
|
|
816
|
+
"What made you decide to cancel? (optional)": "是什么让你决定取消?(可选)",
|
|
817
|
+
"Bugs or reliability": "错误或稳定性问题",
|
|
818
|
+
"Missing feature": "缺少功能",
|
|
819
|
+
"Too expensive": "太贵了",
|
|
820
|
+
"Not using it enough": "用得不够多",
|
|
821
|
+
"Only needed it temporarily": "只是临时需要",
|
|
822
|
+
"Anything else? (optional)": "还有什么想说的吗?(可选)",
|
|
812
823
|
"Ending trial...": "正在结束试用...",
|
|
813
824
|
"Ending...": "正在结束...",
|
|
814
825
|
"Trial ended. Pro is off and you won't be charged.": "试用已结束。Pro 已关闭,不会扣费。",
|
|
@@ -1688,6 +1699,7 @@ export const zhCN: Record<string, string> = {
|
|
|
1688
1699
|
"newline": "换行",
|
|
1689
1700
|
"Denied in {seconds} s": "{seconds} 秒后拒绝",
|
|
1690
1701
|
"choose": "选择",
|
|
1702
|
+
"note": "备注",
|
|
1691
1703
|
"select": "选定",
|
|
1692
1704
|
"here": "此处",
|
|
1693
1705
|
"new pane": "新面板",
|
package/src/i18n/zh-tw.ts
CHANGED
|
@@ -73,6 +73,7 @@ export const zhTW: Record<string, string> = {
|
|
|
73
73
|
"Could not apply that setting.": "無法套用該設定。",
|
|
74
74
|
"Enter {action} · Esc cancel": "Enter {action} · Esc 取消",
|
|
75
75
|
"y {action} · Enter or Esc {cancel}": "y {action} · Enter 或 Esc {cancel}",
|
|
76
|
+
"y {action} · Tab note · Enter or Esc {cancel}": "y {action} · Tab 備註 · Enter 或 Esc {cancel}",
|
|
76
77
|
"Published {date}": "已發布 {date}",
|
|
77
78
|
"Language": "語言",
|
|
78
79
|
"Unsupported language": "不支援的語言",
|
|
@@ -751,6 +752,9 @@ export const zhTW: Record<string, string> = {
|
|
|
751
752
|
"Link copied.": "已複製連結。",
|
|
752
753
|
"New link copied. The old one no longer works.": "已複製新連結。舊連結已失效。",
|
|
753
754
|
"Copy failed. Select the link below.": "複製失敗。請選取下方的連結。",
|
|
755
|
+
"Invite": "邀請",
|
|
756
|
+
"Free months earned: {earned} of {cap}": "已獲得免費月數:{earned}/{cap}",
|
|
757
|
+
"Copy failed. Select the link instead.": "複製失敗。請選取連結。",
|
|
754
758
|
"Failed to create the calendar link.": "無法建立行事曆連結。",
|
|
755
759
|
"Regenerate Link": "重新產生連結",
|
|
756
760
|
"Calendars using the current link stop updating.": "使用目前連結的行事曆將停止更新。",
|
|
@@ -809,6 +813,13 @@ export const zhTW: Record<string, string> = {
|
|
|
809
813
|
"If you keep your trial, you can still cancel before it ends without being charged.": "如果保留試用,在試用結束前取消仍不會收費。",
|
|
810
814
|
"End Trial Now": "立即結束試用",
|
|
811
815
|
"Keep Trial": "保留試用",
|
|
816
|
+
"What made you decide to cancel? (optional)": "是什麼讓你決定取消?(選填)",
|
|
817
|
+
"Bugs or reliability": "錯誤或穩定性問題",
|
|
818
|
+
"Missing feature": "缺少功能",
|
|
819
|
+
"Too expensive": "太貴了",
|
|
820
|
+
"Not using it enough": "用得不夠多",
|
|
821
|
+
"Only needed it temporarily": "只是暫時需要",
|
|
822
|
+
"Anything else? (optional)": "還有什麼想說的嗎?(選填)",
|
|
812
823
|
"Ending trial...": "正在結束試用...",
|
|
813
824
|
"Ending...": "正在結束...",
|
|
814
825
|
"Trial ended. Pro is off and you won't be charged.": "試用已結束。Pro 已關閉,不會收費。",
|
|
@@ -1688,6 +1699,7 @@ export const zhTW: Record<string, string> = {
|
|
|
1688
1699
|
"newline": "換行",
|
|
1689
1700
|
"Denied in {seconds} s": "{seconds} 秒後拒絕",
|
|
1690
1701
|
"choose": "選擇",
|
|
1702
|
+
"note": "備註",
|
|
1691
1703
|
"select": "選定",
|
|
1692
1704
|
"here": "此處",
|
|
1693
1705
|
"new pane": "新面板",
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
import type { PricePoint } from "../types/financials";
|
|
2
|
+
import { getPricePointTimestamp } from "../utils/price-history";
|
|
3
|
+
import { pricePointOpenWithheld } from "../utils/price-history-integrity";
|
|
4
|
+
|
|
5
|
+
/** What a return-based function says once about a continuous future's series (rollAdjustedHistory). */
|
|
6
|
+
export const ROLLS_BACK_ADJUSTED = "rolls back-adjusted";
|
|
7
|
+
/** What it says of a continuous future whose bars name no contract and whose root the calendar does not have. */
|
|
8
|
+
const ROLLS_LEFT_AS_TRADED = "rolls left as traded";
|
|
9
|
+
|
|
10
|
+
/** A roll in a continuous future's daily bars, as rollAdjustedHistory closed it. */
|
|
11
|
+
interface ReturnRoll {
|
|
12
|
+
/** The first bar on the incoming contract, YYYY-MM-DD. */
|
|
13
|
+
date: string;
|
|
14
|
+
/** The contracts either side (NGX26, NGZ26), from the bars or the contract calendar. */
|
|
15
|
+
from: string;
|
|
16
|
+
to: string;
|
|
17
|
+
/** Where the roll was found: a change of contract in the bars, or the contract calendar before they name one. */
|
|
18
|
+
source: "bars" | "calendar";
|
|
19
|
+
/**
|
|
20
|
+
* What the roll day's return was read from: the incoming contract's own
|
|
21
|
+
* move from the bar's open (its first trade of the session), or none
|
|
22
|
+
* (`flat`) for a bar that has no open to read.
|
|
23
|
+
*/
|
|
24
|
+
basis: "open" | "flat";
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface RollAdjustedHistory {
|
|
28
|
+
/**
|
|
29
|
+
* The same bars, every price before a roll scaled by its gap (back-adjusted
|
|
30
|
+
* by ratio), so a return across a roll is one contract's. Volumes and every
|
|
31
|
+
* other field are as served. For returns only: levels, charts and `history`
|
|
32
|
+
* show the prices as traded.
|
|
33
|
+
*/
|
|
34
|
+
points: PricePoint[];
|
|
35
|
+
rolls: ReturnRoll[];
|
|
36
|
+
/**
|
|
37
|
+
* "rolls back-adjusted"; from when, when the bars before name no contract
|
|
38
|
+
* and the calendar does not have the root ("rolls back-adjusted from
|
|
39
|
+
* 2026-09-08"); "rolls left as traded" when neither says where a roll is.
|
|
40
|
+
* Null for anything but a continuous future's daily bars.
|
|
41
|
+
*/
|
|
42
|
+
note: string | null;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const MONTH_CODES = "FGHJKMNQUVXZ";
|
|
46
|
+
const DAY_MS = 86_400_000;
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* When a root's front contract stops trading, from the exchange's rule, for
|
|
50
|
+
* the roots whose continuous series (NG=F) rolls on the session after it:
|
|
51
|
+
* - `month-start`: the nth session before the delivery month's first day
|
|
52
|
+
* (Henry Hub gas: three; its E-mini and micro one session earlier);
|
|
53
|
+
* - `before-25th`: the nth session before the 25th of the month before
|
|
54
|
+
* delivery, one more when the 25th is no session (WTI crude: three);
|
|
55
|
+
* - `month-end`: the last session of the month that many months before
|
|
56
|
+
* delivery (heating oil and RBOB one, Brent last day two).
|
|
57
|
+
* Sessions are the series' own bars, so a holiday is skipped as the exchange
|
|
58
|
+
* skips it. Checked against NG=F, QG=F, CL=F, HO=F, RB=F and BZ=F daily bars
|
|
59
|
+
* from 2021 to 2026: the session after each last trade is where their rolls
|
|
60
|
+
* show (NG=F's largest moves on it, 8.9% a day on average against 3.7%).
|
|
61
|
+
*/
|
|
62
|
+
type LastTradeRule =
|
|
63
|
+
| { kind: "month-start"; sessions: number }
|
|
64
|
+
| { kind: "before-25th"; sessions: number }
|
|
65
|
+
| { kind: "month-end"; monthsBefore: number };
|
|
66
|
+
|
|
67
|
+
const LAST_TRADE_RULES: Readonly<Record<string, LastTradeRule>> = {
|
|
68
|
+
NG: { kind: "month-start", sessions: 3 },
|
|
69
|
+
HH: { kind: "month-start", sessions: 3 },
|
|
70
|
+
QG: { kind: "month-start", sessions: 4 },
|
|
71
|
+
MNG: { kind: "month-start", sessions: 4 },
|
|
72
|
+
CL: { kind: "before-25th", sessions: 3 },
|
|
73
|
+
HO: { kind: "month-end", monthsBefore: 1 },
|
|
74
|
+
RB: { kind: "month-end", monthsBefore: 1 },
|
|
75
|
+
BZ: { kind: "month-end", monthsBefore: 2 },
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
/** The root of a continuous future's symbol (NG of NG=F), or null for anything else. */
|
|
79
|
+
function continuousRoot(symbol: string): string | null {
|
|
80
|
+
return /^([A-Z0-9]{1,6})=F$/.exec(symbol.trim().toUpperCase().split(":")[0]!)?.[1] ?? null;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** Whether a symbol is a continuous future's (NG=F), whose returns rollAdjustedHistory reads within one contract. */
|
|
84
|
+
export function isContinuousFuture(symbol: string): boolean {
|
|
85
|
+
return continuousRoot(symbol) != null;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const monthIndex = (day: string) => Number(day.slice(0, 4)) * 12 + Number(day.slice(5, 7)) - 1;
|
|
89
|
+
const monthDay = (index: number, day: number) =>
|
|
90
|
+
`${Math.floor(index / 12)}-${String((index % 12) + 1).padStart(2, "0")}-${String(day).padStart(2, "0")}`;
|
|
91
|
+
const contractCode = (root: string, delivery: number) =>
|
|
92
|
+
`${root}${MONTH_CODES[delivery % 12]}${String(Math.floor(delivery / 12) % 100).padStart(2, "0")}`;
|
|
93
|
+
|
|
94
|
+
/** The index of the first of the ascending `days` on or after `day`; `days.length` when none is. */
|
|
95
|
+
function firstOnOrAfter(days: readonly string[], day: string): number {
|
|
96
|
+
let low = 0, high = days.length;
|
|
97
|
+
while (low < high) {
|
|
98
|
+
const middle = (low + high) >> 1;
|
|
99
|
+
if (days[middle]! < day) low = middle + 1;
|
|
100
|
+
else high = middle;
|
|
101
|
+
}
|
|
102
|
+
return low;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* The rolls the contract calendar puts in `days` (ascending session dates):
|
|
107
|
+
* for each delivery month, the session after its last trade, from the
|
|
108
|
+
* contract delivered that month to the next. A last trade the sessions do not
|
|
109
|
+
* reach past is left out: the series has not shown it yet.
|
|
110
|
+
*/
|
|
111
|
+
function calendarRolls(root: string, rule: LastTradeRule, days: readonly string[]): Array<{ index: number; from: string; to: string }> {
|
|
112
|
+
if (days.length < 2) return [];
|
|
113
|
+
const rolls: Array<{ index: number; from: string; to: string }> = [];
|
|
114
|
+
for (let month = monthIndex(days[0]!); month <= monthIndex(days.at(-1)!); month++) {
|
|
115
|
+
// The month the last trade falls in, and the delivery month of the contract that stops.
|
|
116
|
+
let last: number;
|
|
117
|
+
let delivery: number;
|
|
118
|
+
if (rule.kind === "month-start") {
|
|
119
|
+
delivery = month + 1;
|
|
120
|
+
const anchor = firstOnOrAfter(days, monthDay(delivery, 1));
|
|
121
|
+
if (anchor >= days.length) continue;
|
|
122
|
+
last = anchor - rule.sessions;
|
|
123
|
+
} else if (rule.kind === "before-25th") {
|
|
124
|
+
delivery = month + 1;
|
|
125
|
+
const target = monthDay(month, 25);
|
|
126
|
+
const anchor = firstOnOrAfter(days, target);
|
|
127
|
+
if (anchor >= days.length) continue;
|
|
128
|
+
last = anchor - rule.sessions - (days[anchor] === target ? 0 : 1);
|
|
129
|
+
} else {
|
|
130
|
+
delivery = month + rule.monthsBefore;
|
|
131
|
+
const anchor = firstOnOrAfter(days, monthDay(month + 1, 1));
|
|
132
|
+
if (anchor >= days.length) continue;
|
|
133
|
+
last = anchor - 1;
|
|
134
|
+
}
|
|
135
|
+
if (last < 0 || last + 1 >= days.length) continue;
|
|
136
|
+
rolls.push({ index: last + 1, from: contractCode(root, delivery), to: contractCode(root, delivery + 1) });
|
|
137
|
+
}
|
|
138
|
+
return rolls;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/** The median days between bars: daily bars sit one to three days apart. */
|
|
142
|
+
function dailyBars(times: readonly number[]): boolean {
|
|
143
|
+
if (times.length < 2) return false;
|
|
144
|
+
const gaps = times.slice(1).map((time, index) => time - times[index]!).sort((a, b) => a - b);
|
|
145
|
+
const median = gaps[Math.floor(gaps.length / 2)]!;
|
|
146
|
+
return median >= 0.5 * DAY_MS && median <= 4 * DAY_MS;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
const positive = (value: number | undefined): value is number => typeof value === "number" && Number.isFinite(value) && value > 0;
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* A continuous future's daily bars (NG=F) as one series of returns: at every
|
|
153
|
+
* roll, the prices before it are scaled so that the roll day's return is the
|
|
154
|
+
* incoming contract's own, from the roll bar's open (that contract's first
|
|
155
|
+
* trade of the session) to its close, where a front-month series would read
|
|
156
|
+
* the gap between two contracts as a move (NG=F's 26 Oct 2026 roll from
|
|
157
|
+
* NGX26 to NGZ26 as +13.5%). A roll bar without an open is a flat day. Rolls
|
|
158
|
+
* are where the bars change contract; before the bars name one, where the
|
|
159
|
+
* contract calendar (LAST_TRADE_RULES) puts them, for the roots it has. The
|
|
160
|
+
* newest contract's prices are as traded. Anything but a continuous future's
|
|
161
|
+
* daily bars is returned as served, with no note.
|
|
162
|
+
*
|
|
163
|
+
* Every return-based function reads a continuous future through this
|
|
164
|
+
* (volatility, beta and correlation, Kelly sizing, seasonality, backtests);
|
|
165
|
+
* charts and `history` keep the prices as traded.
|
|
166
|
+
*/
|
|
167
|
+
export function rollAdjustedHistory(points: readonly PricePoint[], symbol: string): RollAdjustedHistory {
|
|
168
|
+
const asServed = (): RollAdjustedHistory => ({ points: [...points], rolls: [], note: null });
|
|
169
|
+
const root = continuousRoot(symbol);
|
|
170
|
+
if (!root) return asServed();
|
|
171
|
+
const timed = points.map((point) => ({ point, time: getPricePointTimestamp(point) }));
|
|
172
|
+
if (timed.some(({ time }) => !Number.isFinite(time))) return asServed();
|
|
173
|
+
timed.sort((left, right) => left.time - right.time);
|
|
174
|
+
if (!dailyBars(timed.map(({ time }) => time))) return asServed();
|
|
175
|
+
const sorted = timed.map(({ point }) => point);
|
|
176
|
+
const days = timed.map(({ time }) => new Date(time).toISOString().slice(0, 10));
|
|
177
|
+
|
|
178
|
+
const firstNamed = sorted.findIndex((point) => !!point.contract);
|
|
179
|
+
const unnamedEnd = firstNamed < 0 ? sorted.length : firstNamed;
|
|
180
|
+
const found: Array<{ index: number; from: string; to: string; source: ReturnRoll["source"] }> = [];
|
|
181
|
+
const rule = LAST_TRADE_RULES[root];
|
|
182
|
+
if (rule && unnamedEnd > 0) {
|
|
183
|
+
const calendar = calendarRolls(root, rule, days);
|
|
184
|
+
for (const roll of calendar) if (roll.index < unnamedEnd) found.push({ ...roll, source: "calendar" });
|
|
185
|
+
// The bars may start naming a contract other than the one the calendar holds then: the series rolled there.
|
|
186
|
+
const held = calendar.filter((roll) => roll.index < unnamedEnd).at(-1)?.to
|
|
187
|
+
?? calendar.find((roll) => roll.index >= unnamedEnd)?.from;
|
|
188
|
+
const named = sorted[firstNamed]?.contract;
|
|
189
|
+
if (firstNamed > 0 && held && named && held !== named) found.push({ index: firstNamed, from: held, to: named, source: "bars" });
|
|
190
|
+
}
|
|
191
|
+
let contract: string | null = null;
|
|
192
|
+
for (let index = Math.max(0, firstNamed); firstNamed >= 0 && index < sorted.length; index++) {
|
|
193
|
+
const own = sorted[index]!.contract;
|
|
194
|
+
if (own && contract && own !== contract) found.push({ index, from: contract, to: own, source: "bars" });
|
|
195
|
+
if (own) contract = own;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
// Each roll's factor: the roll bar's open over the close before it, or 1 (flat) on that day where there is none.
|
|
199
|
+
const rolls: ReturnRoll[] = [];
|
|
200
|
+
const factors: Array<{ index: number; factor: number }> = [];
|
|
201
|
+
for (const roll of found.sort((left, right) => left.index - right.index)) {
|
|
202
|
+
const bar = sorted[roll.index]!;
|
|
203
|
+
let before = roll.index - 1;
|
|
204
|
+
while (before >= 0 && !positive(sorted[before]!.close)) before--;
|
|
205
|
+
if (before < 0 || !positive(bar.close)) continue;
|
|
206
|
+
const open = positive(bar.open) && !pricePointOpenWithheld(bar) ? bar.open : null;
|
|
207
|
+
const factor = (open ?? bar.close) / sorted[before]!.close;
|
|
208
|
+
rolls.push({ date: days[roll.index]!, from: roll.from, to: roll.to, source: roll.source, basis: open != null ? "open" : "flat" });
|
|
209
|
+
factors.push({ index: roll.index, factor });
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
// Newest first: each roll scales every price before it, on top of the rolls after it.
|
|
213
|
+
let scale = 1;
|
|
214
|
+
let next = factors.length - 1;
|
|
215
|
+
const adjusted = new Array<PricePoint>(sorted.length);
|
|
216
|
+
for (let index = sorted.length - 1; index >= 0; index--) {
|
|
217
|
+
while (next >= 0 && index < factors[next]!.index) scale *= factors[next--]!.factor;
|
|
218
|
+
const point = sorted[index]!;
|
|
219
|
+
const move = (price: number | undefined) => typeof price === "number" ? price * scale : price;
|
|
220
|
+
adjusted[index] = scale === 1 ? point
|
|
221
|
+
: { ...point, open: move(point.open), high: move(point.high), low: move(point.low), close: point.close * scale };
|
|
222
|
+
}
|
|
223
|
+
const note = rule || firstNamed === 0 ? ROLLS_BACK_ADJUSTED
|
|
224
|
+
: firstNamed > 0 ? `${ROLLS_BACK_ADJUSTED} from ${days[firstNamed]}` : ROLLS_LEFT_AS_TRADED;
|
|
225
|
+
return { points: adjusted, rolls, note };
|
|
226
|
+
}
|
|
@@ -46,7 +46,8 @@ export function dailyFxCloses(
|
|
|
46
46
|
if (!row || typeof row.date !== "string" || !Number.isFinite(Date.parse(row.date)) || !isDay(row.date.slice(0, 10))
|
|
47
47
|
|| !Number.isFinite(row.close) || row.close <= 0) throw new FxHistoryError("unavailable");
|
|
48
48
|
const date = new Date(row.date).toISOString().slice(0, 10);
|
|
49
|
-
|
|
49
|
+
// A close the source copied from the open, which nothing rebuilt, is no day's close: the day before it stands in.
|
|
50
|
+
if (date >= today || row.closeCopied === true) continue;
|
|
50
51
|
const rate = leg.invert ? 1 / row.close : row.close;
|
|
51
52
|
const previous = closes.get(date);
|
|
52
53
|
if (previous != null && previous !== rate) throw new FxHistoryError("unavailable");
|
|
@@ -88,6 +89,11 @@ export interface FxCloseReading {
|
|
|
88
89
|
date: string;
|
|
89
90
|
/** When the close was taken, as an ISO time (17:00 New York), when the service says. */
|
|
90
91
|
closedAt?: string;
|
|
92
|
+
/**
|
|
93
|
+
* The day asked for, when its close is the source's copy of its open, which
|
|
94
|
+
* nothing rebuilt: `date` is then the trading day before it.
|
|
95
|
+
*/
|
|
96
|
+
copiedClose?: string;
|
|
91
97
|
}
|
|
92
98
|
|
|
93
99
|
/**
|
|
@@ -134,16 +140,22 @@ export async function readFxCloseOnDate(
|
|
|
134
140
|
if (response.status !== "success" && response.status !== "partial") return { reading: null, served };
|
|
135
141
|
const today = isoDay(now.getTime());
|
|
136
142
|
let best: FxCloseReading | null = null;
|
|
143
|
+
let copied: string | undefined;
|
|
137
144
|
for (const row of Array.isArray(response.data) ? response.data : []) {
|
|
138
145
|
const at = typeof row?.date === "string" ? Date.parse(row.date) : Number.NaN;
|
|
139
146
|
if (!Number.isFinite(at) || !Number.isFinite(row.close) || row.close <= 0) continue;
|
|
140
147
|
const rowDay = isoDay(at);
|
|
141
148
|
if (rowDay > date || rowDay >= today || Date.parse(`${rowDay}T00:00:00Z`) < day - FX_MAX_AGE_DAYS * DAY_MS) continue;
|
|
149
|
+
// A close the source copied from the open, which nothing rebuilt, is no day's close: the day before it stands in.
|
|
150
|
+
if (row.closeCopied === true) {
|
|
151
|
+
if (rowDay === date) copied = rowDay;
|
|
152
|
+
continue;
|
|
153
|
+
}
|
|
142
154
|
const close = fxFigureAsSent(row.close);
|
|
143
155
|
const closedAt = typeof row.closedAt === "string" && Number.isFinite(Date.parse(row.closedAt)) ? row.closedAt : undefined;
|
|
144
156
|
if (!best || rowDay > best.date) best = { rate: leg.invert ? 1 / close : close, close, date: rowDay, ...(closedAt ? { closedAt } : {}) };
|
|
145
157
|
}
|
|
146
|
-
return { reading: best, served };
|
|
158
|
+
return { reading: best && copied ? { ...best, copiedClose: copied } : best, served };
|
|
147
159
|
}
|
|
148
160
|
|
|
149
161
|
/**
|