@tidal-ts/core 0.1.0
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/LICENSE +21 -0
- package/dist/aggregate.d.ts +193 -0
- package/dist/aggregate.js +288 -0
- package/dist/columnar.d.ts +61 -0
- package/dist/columnar.js +63 -0
- package/dist/derive.d.ts +555 -0
- package/dist/derive.js +740 -0
- package/dist/expirations.d.ts +85 -0
- package/dist/expirations.js +151 -0
- package/dist/extent.d.ts +20 -0
- package/dist/extent.js +44 -0
- package/dist/fixture.d.ts +64 -0
- package/dist/fixture.js +116 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +16 -0
- package/dist/join.d.ts +31 -0
- package/dist/join.js +36 -0
- package/dist/regrid.d.ts +22 -0
- package/dist/regrid.js +85 -0
- package/dist/sessions.d.ts +141 -0
- package/dist/sessions.js +232 -0
- package/dist/studyCatalog.d.ts +129 -0
- package/dist/studyCatalog.js +361 -0
- package/dist/timeZone.d.ts +51 -0
- package/dist/timeZone.js +80 -0
- package/dist/types.d.ts +20 -0
- package/dist/types.js +12 -0
- package/dist/vol.d.ts +160 -0
- package/dist/vol.js +252 -0
- package/package.json +50 -0
package/dist/derive.d.ts
ADDED
|
@@ -0,0 +1,555 @@
|
|
|
1
|
+
import type { SeriesSchema, TimeSeries } from 'pond-ts';
|
|
2
|
+
import { BAND_OUTPUTS } from './studyCatalog.js';
|
|
3
|
+
import { type OpContext, type OpResult, type Units } from '@pond-ts/process';
|
|
4
|
+
/**
|
|
5
|
+
* The **derive seam** — a `SeriesConfig` that *induces* its column instead of
|
|
6
|
+
* only referencing one (a study: `sma(20)` of `iv21`; a spread: `iv21 / hv21`).
|
|
7
|
+
* Since TDL-PROCESS the engine underneath is **`@pond-ts/process`** (the
|
|
8
|
+
* processing graph Tidal's RFC pond#543 argued for): Tidal declares its op
|
|
9
|
+
* vocabulary in a process `Registry`, a spec is a process plan node, the id is
|
|
10
|
+
* the engine's content-addressed `specId`, and the fold is `bind` + `run`.
|
|
11
|
+
* This module remains the thin, pure seam Tidal renders against — React-free,
|
|
12
|
+
* extraction-ready — but it now *configures* an engine rather than being one.
|
|
13
|
+
*
|
|
14
|
+
* Design of record: Tidal's indicator-integration note; the adoption program:
|
|
15
|
+
* Tidal's pairs plan. Consumer positions filed
|
|
16
|
+
* on pond#543 (2026-08-16).
|
|
17
|
+
*/
|
|
18
|
+
/** The schema-erased series the fold reads/writes (like aggregate.ts): an op
|
|
19
|
+
* appends a numeric column, callers work in the base schema + name their
|
|
20
|
+
* column. */
|
|
21
|
+
type DerivedSeries = TimeSeries<SeriesSchema>;
|
|
22
|
+
/** Derive operators Tidal registers. `sma`/`ema` are windowed trend studies
|
|
23
|
+
* (bound to `@pond-ts/financial`, param `period`); `realizedVol` is a
|
|
24
|
+
* pointwise domain transform (√(var·252)) the corpus doesn't carry
|
|
25
|
+
* (F-charts-11). `diff`/`ratio`/`logRatio` are the **pair** ops (TDL-PAIR):
|
|
26
|
+
* pointwise two-input transforms — the A-vs-B spread family, where the
|
|
27
|
+
* derived line is the signal and the legs are context. */
|
|
28
|
+
export type TidalOp = 'sma' | 'ema' | 'bollinger' | 'realizedVol' | 'diff' | 'ratio' | 'logRatio';
|
|
29
|
+
/**
|
|
30
|
+
* An op name the registry knows.
|
|
31
|
+
*
|
|
32
|
+
* A literal union until TDL-STUDYCAT: the corpus's names arrive as DATA from
|
|
33
|
+
* `@pond-ts/financial/catalog`, so the set is no longer knowable at compile
|
|
34
|
+
* time and pinning it would mean transcribing 109 names — the exact thing
|
|
35
|
+
* F-charts-25 existed to stop. {@link TidalOp} keeps the hand-declared names
|
|
36
|
+
* available where a caller genuinely means one of those (the pair ops), and
|
|
37
|
+
* the registry remains the runtime authority: `specId` throws on an unknown op,
|
|
38
|
+
* so a bad name fails loudly at the seam rather than silently downstream.
|
|
39
|
+
*/
|
|
40
|
+
export type DeriveOp = TidalOp | (string & {});
|
|
41
|
+
/**
|
|
42
|
+
* Column prefix for the **compare role's** columns when the host joins the
|
|
43
|
+
* comparison ticker's series onto the primary (role-bound pair legs,
|
|
44
|
+
* TDL-PAIR stage 1): `cmp_iv21` is "the compare ticker's iv21". A ROLE, not
|
|
45
|
+
* an identity — the column keeps its name when the compare ticker changes,
|
|
46
|
+
* so a spread's id (and the user's overrides on it) survive the swap. This
|
|
47
|
+
* is the consumer-side stand-in for per-input source qualification
|
|
48
|
+
* (PND-PROCJOIN — position 5 on pond#543).
|
|
49
|
+
*/
|
|
50
|
+
export declare const COMPARE_PREFIX = "cmp_";
|
|
51
|
+
/** The two-input (pair) subset of {@link DeriveOp}. */
|
|
52
|
+
export type PairOp = 'diff' | 'ratio' | 'logRatio';
|
|
53
|
+
/** True if `op` takes a second input. */
|
|
54
|
+
export declare const isPairOp: (op: DeriveOp) => op is PairOp;
|
|
55
|
+
/** An input of a spec: a raw source column name, or a **nested spec** (the
|
|
56
|
+
* engine's own recursion — an id string naming another spec is NOT an input;
|
|
57
|
+
* the engine reads a string input as a raw column, so composition nests). */
|
|
58
|
+
export type DeriveInput = string | DeriveSpec;
|
|
59
|
+
/** A derive spec — structurally a `@pond-ts/process` plan `Spec`, narrowed to
|
|
60
|
+
* Tidal's op vocabulary. Content-addressed by the engine: params are
|
|
61
|
+
* defaulted + key-sorted inside `specId`, so an omitted param and its
|
|
62
|
+
* explicit default are one identity. Absent on a `SeriesConfig` ⇒ a raw
|
|
63
|
+
* data column. */
|
|
64
|
+
export interface DeriveSpec {
|
|
65
|
+
op: DeriveOp;
|
|
66
|
+
params?: Readonly<Record<string, number>>;
|
|
67
|
+
inputs: readonly DeriveInput[];
|
|
68
|
+
}
|
|
69
|
+
/** The default bar-count period a study uses when none is given. */
|
|
70
|
+
export declare const DEFAULT_PERIOD = 20;
|
|
71
|
+
/** The slice of pond's public column API we read: a length + a per-cell read that
|
|
72
|
+
* yields `undefined` for a gap. (Structural, so an erased-schema series can be
|
|
73
|
+
* read without fighting the schema-narrowed `column()` signature.) */
|
|
74
|
+
export interface NumericColumnReader {
|
|
75
|
+
readonly length: number;
|
|
76
|
+
read(i: number): number | undefined;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* A numeric column off a series by name, or `undefined` if it has none —
|
|
80
|
+
* pond's **columnar** read path (`series.column(name)`), which walks the packed
|
|
81
|
+
* typed array instead of materializing an object per bar. Prefer this to
|
|
82
|
+
* `toObjects()` for any per-bar fold (pond 0.52 made the same change inside its
|
|
83
|
+
* own study kernels; the guidance is "columns, not events").
|
|
84
|
+
*/
|
|
85
|
+
export declare function readNumericColumn(series: DerivedSeries, name: string): NumericColumnReader | undefined;
|
|
86
|
+
/** The output suffixes a band declares, in declaration order — also the order
|
|
87
|
+
* {@link bollingerRun} returns its columns in. Defined in `studyCatalog.ts`
|
|
88
|
+
* (the lower layer) so the adoption filter and the band style read ONE list;
|
|
89
|
+
* re-exported here because this is where consumers already import it from. */
|
|
90
|
+
export { BAND_OUTPUTS };
|
|
91
|
+
/** **Bollinger Bands** — the corpus's `bollinger` (one rolling avg+stdev pass),
|
|
92
|
+
* surfaced as a THREE-output op. The engine names the columns `${id}Middle` /
|
|
93
|
+
* `Upper` / `Lower` from the suffixes declared below, which is the corpus's own
|
|
94
|
+
* `prefix` convention, so no mapping layer sits between them.
|
|
95
|
+
*
|
|
96
|
+
* Returned in {@link BAND_OUTPUTS} order — positional, per `OpResult`. */
|
|
97
|
+
declare function bollingerRun(ctx: OpContext): OpResult;
|
|
98
|
+
/** Annualized realized volatility from a **daily variance** column: √(var·252),
|
|
99
|
+
* scaled to a percent. Pointwise (no window); a non-finite or negative input
|
|
100
|
+
* reads as a gap, and the RESULT is guarded finite too (a huge-but-finite
|
|
101
|
+
* variance can overflow — that cell becomes a gap, not a dropped column). */
|
|
102
|
+
declare function realizedVolRun(ctx: OpContext): OpResult;
|
|
103
|
+
/** The study period's legal range — the SINGLE source both the registry param
|
|
104
|
+
* and every gate (machine guards, the UI period input) read, so no caller can
|
|
105
|
+
* mint a spec the registry will reject (`specId` THROWS on out-of-range
|
|
106
|
+
* params — an ungated value killed the terminal actor; PR #130 review). */
|
|
107
|
+
export declare const PERIOD_BOUNDS: {
|
|
108
|
+
readonly min: 2;
|
|
109
|
+
readonly max: 5000;
|
|
110
|
+
};
|
|
111
|
+
/**
|
|
112
|
+
* Tidal's op vocabulary as a **process registry** — the single declaration the
|
|
113
|
+
* engine validates against, `specId` names from, `explain` derives lineage
|
|
114
|
+
* from, and (TDL-STUDYMENU) a picker will be generated from. Locally defined
|
|
115
|
+
* ops are citizens, per the RFC; the pair ops are the multi-input workload
|
|
116
|
+
* posted as position 5 on pond#543.
|
|
117
|
+
*
|
|
118
|
+
* Unit notes: `ratio` is unitless (`''`), `logRatio` is `'log'`. `diff`
|
|
119
|
+
* declares `'inherit'`, which reads input 0 unconditionally — WRONG when the
|
|
120
|
+
* legs' units differ, which is exactly the `'inheritCommon'` ask in position 2
|
|
121
|
+
* on pond#543. Until that lands the graph's unit answer for an unlike-unit
|
|
122
|
+
* diff is untrusted: the CONFIG layer computes the displayed unit itself
|
|
123
|
+
* (`pairConfig`: a like-unit diff keeps the unit, anything else reads `''`).
|
|
124
|
+
*/
|
|
125
|
+
declare const HAND_OPS: import("@pond-ts/process").Registry<Omit<Omit<Omit<Omit<Omit<Omit<Omit<{}, D["name"]> & Readonly<Record<"sma", {
|
|
126
|
+
readonly name: "sma";
|
|
127
|
+
readonly family: "trend";
|
|
128
|
+
readonly summary: "Simple moving average";
|
|
129
|
+
readonly params: {
|
|
130
|
+
readonly period: import("@pond-ts/process").NumberParam;
|
|
131
|
+
};
|
|
132
|
+
readonly inputs: readonly [{
|
|
133
|
+
readonly role: "input";
|
|
134
|
+
}];
|
|
135
|
+
readonly outputs: readonly [{
|
|
136
|
+
readonly id: "";
|
|
137
|
+
readonly unit: "inherit";
|
|
138
|
+
}];
|
|
139
|
+
readonly lookback: (p: Readonly<Record<string, import("@pond-ts/process").ParamValue>>) => number;
|
|
140
|
+
readonly label: (p: Readonly<Record<string, import("@pond-ts/process").ParamValue>>, inputs: string) => string;
|
|
141
|
+
readonly run: (ctx: OpContext) => OpResult;
|
|
142
|
+
}>>, "ema"> & Readonly<Record<"ema", {
|
|
143
|
+
readonly name: "ema";
|
|
144
|
+
readonly family: "trend";
|
|
145
|
+
readonly summary: "Exponential moving average";
|
|
146
|
+
readonly params: {
|
|
147
|
+
readonly period: import("@pond-ts/process").NumberParam;
|
|
148
|
+
};
|
|
149
|
+
readonly inputs: readonly [{
|
|
150
|
+
readonly role: "input";
|
|
151
|
+
}];
|
|
152
|
+
readonly outputs: readonly [{
|
|
153
|
+
readonly id: "";
|
|
154
|
+
readonly unit: "inherit";
|
|
155
|
+
}];
|
|
156
|
+
readonly lookback: (p: Readonly<Record<string, import("@pond-ts/process").ParamValue>>) => number;
|
|
157
|
+
readonly label: (p: Readonly<Record<string, import("@pond-ts/process").ParamValue>>, inputs: string) => string;
|
|
158
|
+
readonly run: (ctx: OpContext) => OpResult;
|
|
159
|
+
}>>, "bollinger"> & Readonly<Record<"bollinger", {
|
|
160
|
+
readonly name: "bollinger";
|
|
161
|
+
readonly family: "trend";
|
|
162
|
+
readonly summary: "Bollinger Bands — an SMA with bands at ±k standard deviations";
|
|
163
|
+
readonly params: {
|
|
164
|
+
readonly period: import("@pond-ts/process").NumberParam;
|
|
165
|
+
readonly stdDev: import("@pond-ts/process").NumberParam;
|
|
166
|
+
};
|
|
167
|
+
readonly inputs: readonly [{
|
|
168
|
+
readonly role: "input";
|
|
169
|
+
}];
|
|
170
|
+
readonly outputs: {
|
|
171
|
+
id: "Middle" | "Upper" | "Lower";
|
|
172
|
+
unit: "inherit";
|
|
173
|
+
}[];
|
|
174
|
+
readonly lookback: (p: Readonly<Record<string, import("@pond-ts/process").ParamValue>>) => number;
|
|
175
|
+
readonly label: (p: Readonly<Record<string, import("@pond-ts/process").ParamValue>>, inputs: string) => string;
|
|
176
|
+
readonly run: typeof bollingerRun;
|
|
177
|
+
}>>, "realizedVol"> & Readonly<Record<"realizedVol", {
|
|
178
|
+
readonly name: "realizedVol";
|
|
179
|
+
readonly family: "volatility";
|
|
180
|
+
readonly summary: "Annualized realized vol from a daily variance: √(var·252), in percent";
|
|
181
|
+
readonly params: {};
|
|
182
|
+
readonly inputs: readonly [{
|
|
183
|
+
readonly role: "input";
|
|
184
|
+
}];
|
|
185
|
+
readonly outputs: readonly [{
|
|
186
|
+
readonly id: "";
|
|
187
|
+
readonly unit: "%";
|
|
188
|
+
}];
|
|
189
|
+
readonly lookback: () => number;
|
|
190
|
+
readonly label: (_p: Readonly<Record<string, import("@pond-ts/process").ParamValue>>, inputs: string) => string;
|
|
191
|
+
readonly run: typeof realizedVolRun;
|
|
192
|
+
}>>, "diff"> & Readonly<Record<"diff", {
|
|
193
|
+
readonly name: "diff";
|
|
194
|
+
readonly family: "pair";
|
|
195
|
+
readonly summary: "A − B, pointwise";
|
|
196
|
+
readonly params: {};
|
|
197
|
+
readonly inputs: readonly [{
|
|
198
|
+
readonly role: "a";
|
|
199
|
+
}, {
|
|
200
|
+
readonly role: "b";
|
|
201
|
+
}];
|
|
202
|
+
readonly outputs: readonly [{
|
|
203
|
+
readonly id: "";
|
|
204
|
+
readonly unit: "inherit";
|
|
205
|
+
}];
|
|
206
|
+
readonly lookback: () => number;
|
|
207
|
+
readonly label: (_p: Readonly<Record<string, import("@pond-ts/process").ParamValue>>, inputs: string) => string;
|
|
208
|
+
readonly run: (ctx: OpContext) => OpResult;
|
|
209
|
+
}>>, "ratio"> & Readonly<Record<"ratio", {
|
|
210
|
+
readonly name: "ratio";
|
|
211
|
+
readonly family: "pair";
|
|
212
|
+
readonly summary: "A / B, pointwise (gaps on a zero denominator)";
|
|
213
|
+
readonly params: {};
|
|
214
|
+
readonly inputs: readonly [{
|
|
215
|
+
readonly role: "a";
|
|
216
|
+
}, {
|
|
217
|
+
readonly role: "b";
|
|
218
|
+
}];
|
|
219
|
+
readonly outputs: readonly [{
|
|
220
|
+
readonly id: "";
|
|
221
|
+
readonly unit: "";
|
|
222
|
+
}];
|
|
223
|
+
readonly lookback: () => number;
|
|
224
|
+
readonly label: (_p: Readonly<Record<string, import("@pond-ts/process").ParamValue>>, inputs: string) => string;
|
|
225
|
+
readonly run: (ctx: OpContext) => OpResult;
|
|
226
|
+
}>>, "logRatio"> & Readonly<Record<"logRatio", {
|
|
227
|
+
readonly name: "logRatio";
|
|
228
|
+
readonly family: "pair";
|
|
229
|
+
readonly summary: "log(A / B), pointwise (gaps unless both legs are positive)";
|
|
230
|
+
readonly params: {};
|
|
231
|
+
readonly inputs: readonly [{
|
|
232
|
+
readonly role: "a";
|
|
233
|
+
}, {
|
|
234
|
+
readonly role: "b";
|
|
235
|
+
}];
|
|
236
|
+
readonly outputs: readonly [{
|
|
237
|
+
readonly id: "";
|
|
238
|
+
readonly unit: "log";
|
|
239
|
+
}];
|
|
240
|
+
readonly lookback: () => number;
|
|
241
|
+
readonly label: (_p: Readonly<Record<string, import("@pond-ts/process").ParamValue>>, inputs: string) => string;
|
|
242
|
+
readonly run: (ctx: OpContext) => OpResult;
|
|
243
|
+
}>>>;
|
|
244
|
+
/** The registry's type tracks its defs, which is what gives `define` its
|
|
245
|
+
* compile-time checking — but the corpus arrives as DATA, so the folded-in
|
|
246
|
+
* studies cannot appear in that type. The cast is the honest statement of
|
|
247
|
+
* that boundary: below it the registry is the runtime authority (`specId`
|
|
248
|
+
* throws on an unknown op), and above it only the hand-declared names are
|
|
249
|
+
* known statically. See {@link DeriveOp}. */
|
|
250
|
+
type OpRegistry = typeof HAND_OPS;
|
|
251
|
+
/**
|
|
252
|
+
* Tidal's op vocabulary: the hand-declared ops above, then **the corpus**,
|
|
253
|
+
* folded in from `@pond-ts/financial`'s runtime catalog rather than transcribed
|
|
254
|
+
* (F-charts-25, asked for and delivered).
|
|
255
|
+
*
|
|
256
|
+
* `ADOPTED_STUDIES` is narrow on purpose. A study that reaches this registry
|
|
257
|
+
* reaches the picker, the param controls, the labels and band detection — all
|
|
258
|
+
* of which generate themselves from here — so the filter is the only gate, and
|
|
259
|
+
* `adoptable` says why for each exclusion. TDL-STUDYCAT.
|
|
260
|
+
*/
|
|
261
|
+
export declare const TIDAL_OPS: OpRegistry;
|
|
262
|
+
/** True if an id names a spec the registry REJECTS (bad params, wrong shape —
|
|
263
|
+
* a persisted-garbage spec). Such a spec can never fold, anywhere — distinct
|
|
264
|
+
* from a valid spec whose column merely isn't in the current feed. */
|
|
265
|
+
export declare const isBrokenId: (id: string) => boolean;
|
|
266
|
+
/**
|
|
267
|
+
* Deterministic id / output-column name for a spec — the engine's
|
|
268
|
+
* content-addressed `specId` (`p1:op(inputs;params)`: versioned, params
|
|
269
|
+
* defaulted + key-sorted, separators escaped, nested inputs inlined by their
|
|
270
|
+
* own id). It doubles as the chart theme id, tracker label key, and selection
|
|
271
|
+
* id (every role `SeriesConfig.id` plays), and it is a stable **persisted**
|
|
272
|
+
* key: a preset spec and a freshly composed one land on the same identity by
|
|
273
|
+
* construction.
|
|
274
|
+
*
|
|
275
|
+
* TOTAL since 0.62.0 (`validate: false`): a spec the registry rejects gets a
|
|
276
|
+
* distinct `p1?:`-prefixed id (type-preserving param encoding) instead of a
|
|
277
|
+
* throw — a broken persisted spec can no longer name (and key onto) the
|
|
278
|
+
* working node, and naming never kills a caller (the old guard-totality
|
|
279
|
+
* hazard). Validity itself is {@link isValidSpec}.
|
|
280
|
+
*/
|
|
281
|
+
export declare function deriveId(spec: DeriveSpec): string;
|
|
282
|
+
/** Human lineage for a spec, derived from the registry (`explain`) — never
|
|
283
|
+
* hand-built, so `ema(sma(x))` keeps its inner study. The `TDL-LINEAGE`
|
|
284
|
+
* sub-line reads this. */
|
|
285
|
+
export declare function deriveLineage(spec: DeriveSpec): string;
|
|
286
|
+
/** The **column names** a spec's top-level inputs resolve to: a string input
|
|
287
|
+
* is a raw column, a nested spec's column is its id. The machine's dependency
|
|
288
|
+
* walks (removal closure, travel sets) match configs against these. */
|
|
289
|
+
export declare function inputNames(spec: DeriveSpec): string[];
|
|
290
|
+
/**
|
|
291
|
+
* Rewrite every reference to the column `from`, at any depth, to `to` — the
|
|
292
|
+
* substitution behind **edit propagation**: when a config's spec changes, the
|
|
293
|
+
* column it publishes moves, and everything built on it must be re-pointed at
|
|
294
|
+
* the new computation rather than left naming a column that no longer folds.
|
|
295
|
+
*
|
|
296
|
+
* Both ways a spec can name another are handled: a raw string input, and a
|
|
297
|
+
* NESTED spec (composition nests, so a seated dependent carries a copy of its
|
|
298
|
+
* source's spec — matched by its id, which is that source's column).
|
|
299
|
+
*
|
|
300
|
+
* Returns the SAME object when nothing matched, so callers can use identity as
|
|
301
|
+
* a cheap "did this change" test.
|
|
302
|
+
*/
|
|
303
|
+
export declare function substituteInput(spec: DeriveSpec, from: string, to: DeriveInput): DeriveSpec;
|
|
304
|
+
/**
|
|
305
|
+
* True if the registry accepts this spec — the op exists, the shape is sound,
|
|
306
|
+
* and every param is in range. Since 0.62.0 this reads the lenient id's
|
|
307
|
+
* `p1?:` marker ({@link deriveId} is total), so it can never throw — but the
|
|
308
|
+
* machine's guards still gate on it before ACTING: an invalid spec must be
|
|
309
|
+
* refused, not seated (the try/catch stays as a belt for pathological
|
|
310
|
+
* persisted shapes the totality claim was never made about).
|
|
311
|
+
*/
|
|
312
|
+
export declare function isValidSpec(spec: DeriveSpec): boolean;
|
|
313
|
+
/**
|
|
314
|
+
* True if a spec is, or is built on, a **pair** — the test for "this series
|
|
315
|
+
* states its own symbols".
|
|
316
|
+
*
|
|
317
|
+
* A pair names a symbol per leg, so the blanket compare counterpart (a dashed
|
|
318
|
+
* second copy of every series on the comparison symbol) is meaningless for it:
|
|
319
|
+
* `A − B` on the primary does not imply you wanted `A − B` on the comparison —
|
|
320
|
+
* that is a different pair, and the grammar says to ask for it as one. Recursive
|
|
321
|
+
* because a STUDY of a spread inherits the same argument (Peter, 2026-08-18).
|
|
322
|
+
*/
|
|
323
|
+
export declare function hasPairOp(spec: DeriveSpec): boolean;
|
|
324
|
+
/** True if any input (recursively) reads a compare-role column — the host
|
|
325
|
+
* must join the comparison series on before folding such a spec. */
|
|
326
|
+
export declare function usesCompare(spec: DeriveSpec): boolean;
|
|
327
|
+
/** One study wrapping a part, as read off the spec. */
|
|
328
|
+
export interface PartStudy {
|
|
329
|
+
op: DeriveOp;
|
|
330
|
+
params?: Readonly<Record<string, number>>;
|
|
331
|
+
}
|
|
332
|
+
/**
|
|
333
|
+
* One leg of a pair, read back OUT of the pair's spec — the Metric/Part node.
|
|
334
|
+
*
|
|
335
|
+
* A leg is written by `boundLeg` as: the metric, wrapped in an optional study,
|
|
336
|
+
* with a compare rebind pushed down to the LEAVES. Reading it back inverts
|
|
337
|
+
* exactly that, which is why `entity` is decided at the leaf and not at the top.
|
|
338
|
+
*/
|
|
339
|
+
export interface PairPart {
|
|
340
|
+
/** The metric this leg reads, compare prefix INTACT — the spec node to keep
|
|
341
|
+
* when rebuilding the leg (a raw column, or a derived metric's own spec). */
|
|
342
|
+
metric: DeriveInput;
|
|
343
|
+
/** {@link metric}'s published column with the compare prefix stripped: the
|
|
344
|
+
* name to look up for a display label, which is role-independent. */
|
|
345
|
+
base: string;
|
|
346
|
+
/** Which symbol the leg reads — `compare` when its leaves are prefixed. */
|
|
347
|
+
entity: 'primary' | 'compare';
|
|
348
|
+
/** The studies wrapping the metric, **innermost first** (application order). */
|
|
349
|
+
studies: readonly PartStudy[];
|
|
350
|
+
}
|
|
351
|
+
/**
|
|
352
|
+
* Decompose one pair leg into metric + binding + study chain, or **null** when
|
|
353
|
+
* the leg isn't that shape — a leg can be any graph input, including a nested
|
|
354
|
+
* PAIR (a spread of spreads is legal: `resolveLeg` accepts a seated spread).
|
|
355
|
+
* Such a leg has no single metric to name, so the panel degrades to rendering
|
|
356
|
+
* it flat rather than inventing a decomposition.
|
|
357
|
+
*
|
|
358
|
+
* "Study" here means a WINDOWED op ({@link opHasPeriod}) — the same
|
|
359
|
+
* discriminator the config layer uses (`isStudySeries`). A single-input op with
|
|
360
|
+
* no period (`realizedVol`) is a derived METRIC and terminates the walk, so
|
|
361
|
+
* `RV · SMA(20)` reads as one metric with one study rather than two studies.
|
|
362
|
+
*/
|
|
363
|
+
export declare function readPart(input: DeriveInput): PairPart | null;
|
|
364
|
+
/**
|
|
365
|
+
* How a part's study prints — `SMA(20)`.
|
|
366
|
+
*
|
|
367
|
+
* An OMITTED period is the default, not an absent one: `deriveId` defaults and
|
|
368
|
+
* key-sorts params, so `sma(x)` and `sma(x;period=20)` are one identity. Printed
|
|
369
|
+
* naively that spec read `SMA(undefined)` (PR #141 review, LOW). One helper so
|
|
370
|
+
* the pair's label and the panel's part row can't spell it differently.
|
|
371
|
+
*/
|
|
372
|
+
export declare const partStudyLabel: (st: PartStudy) => string;
|
|
373
|
+
/** A pair spec's two legs as parts, or **null** if this isn't a pair op or
|
|
374
|
+
* either leg doesn't decompose. Pairs are strictly binary, so anything else
|
|
375
|
+
* is a shape we didn't write. */
|
|
376
|
+
export declare function readPairParts(spec: DeriveSpec): readonly [PairPart, PairPart] | null;
|
|
377
|
+
/**
|
|
378
|
+
* The unit a spec's output reads in, from the registry's own declaration —
|
|
379
|
+
* `unitOf` resolves a RAW column's unit (the host's catalog).
|
|
380
|
+
*
|
|
381
|
+
* `'inherit'` is resolved as **inheritCommon**: the shared unit of the inputs,
|
|
382
|
+
* else unitless. That distinction only bites on a pair — `diff` declares
|
|
383
|
+
* `inherit` and the engine reads input 0 unconditionally, which is wrong for
|
|
384
|
+
* unlike legs (`%` − `$` is not `%`). Computing it here is the local stand-in
|
|
385
|
+
* for the `inheritCommon` ask on pond#543 position 2; when the engine gains it
|
|
386
|
+
* this collapses to reading the graph's answer.
|
|
387
|
+
*/
|
|
388
|
+
export declare function specUnit(spec: DeriveSpec, unitOf: (column: string) => string): string;
|
|
389
|
+
/** One spec the fold could not compute, keyed by the spec's own id (a broken
|
|
390
|
+
* spec's id carries the `p1?:` prefix — see {@link isBrokenId}). `code` is
|
|
391
|
+
* the engine's per-class literal (`'UnknownColumnError'` = the column isn't
|
|
392
|
+
* in this feed, could fold elsewhere → a dimmed-removable chip;
|
|
393
|
+
* `'ParamError'` = the spec itself is garbage → a broken chip); ABSENT code
|
|
394
|
+
* means the throw came from op code, not the plan layer. Compare the string
|
|
395
|
+
* literal, never `err.name` — bundlers rename classes. */
|
|
396
|
+
export interface DeriveSkip {
|
|
397
|
+
id: string;
|
|
398
|
+
code?: string;
|
|
399
|
+
reason: string;
|
|
400
|
+
}
|
|
401
|
+
/**
|
|
402
|
+
* Fold a set of derive specs onto a series, appending each spec's output
|
|
403
|
+
* column (`deriveId(spec)`) and REPORTING what didn't fold — `bind` + `run`
|
|
404
|
+
* over {@link TIDAL_OPS} with `onError: 'skip'`: a spec that can't resolve
|
|
405
|
+
* (unknown column, bad params — a preset can reference a column that no
|
|
406
|
+
* longer exists) is skipped rather than thrown, its dependents skip with it,
|
|
407
|
+
* and each lands in `skipped` exactly once (the engine reports a failing spec
|
|
408
|
+
* per pass — plan + selector — so entries dedupe on the spec's id). Since
|
|
409
|
+
* 0.62.0 nothing is pre-filtered: broken specs flow through and report, which
|
|
410
|
+
* is what the chip UI reads (Tidal's pairs plan, the ghost-spread debt).
|
|
411
|
+
* Duplicate specs in the set are one node by content-addressing. Pure +
|
|
412
|
+
* deterministic (memo-friendly).
|
|
413
|
+
*
|
|
414
|
+
* Deliberately a **cold bind per fold** for now — same cost shape as the local
|
|
415
|
+
* fold it replaced, kept simple while semantics settle. The warm long-lived
|
|
416
|
+
* graph (a `Host` keyed by source, `setSourceFrom` on live appends, ranged
|
|
417
|
+
* recompute) is the follow-up where the engine's caching starts paying.
|
|
418
|
+
*/
|
|
419
|
+
export declare function applyDerivedReport(series: DerivedSeries, specs: readonly DeriveSpec[], units?: Units): {
|
|
420
|
+
series: DerivedSeries;
|
|
421
|
+
skipped: DeriveSkip[];
|
|
422
|
+
};
|
|
423
|
+
/** {@link applyDerivedReport} without the report — the fold most render paths
|
|
424
|
+
* want (the chart's column-absence handling is the render half of the skip
|
|
425
|
+
* contract). */
|
|
426
|
+
export declare function applyDerived(series: DerivedSeries, specs: readonly DeriveSpec[], units?: Units): DerivedSeries;
|
|
427
|
+
/** One op the study menu can offer, straight from the registry — so a new op
|
|
428
|
+
* appears in the picker by being defined, never by being listed twice. */
|
|
429
|
+
export interface StudyOption {
|
|
430
|
+
op: DeriveOp;
|
|
431
|
+
/** Display name (`SMA`, `Realized vol`). */
|
|
432
|
+
label: string;
|
|
433
|
+
/** The registry's one-line summary — the picker's muted description. */
|
|
434
|
+
summary: string;
|
|
435
|
+
family: string;
|
|
436
|
+
}
|
|
437
|
+
/** Whether an op declares a `period` param — i.e. whether it is WINDOWED, and
|
|
438
|
+
* so whether a study of it should carry one. Stamping `{period}` onto an op
|
|
439
|
+
* that declares no params mints a spec the registry rejects, and the machine's
|
|
440
|
+
* guard then refuses the add with no feedback (PR #137 review, MEDIUM). */
|
|
441
|
+
export declare function opHasPeriod(op: DeriveOp): boolean;
|
|
442
|
+
/** One tunable param of an op, as the registry declares it — the study controls
|
|
443
|
+
* are generated from these rather than from a hardcoded list, so a new op with
|
|
444
|
+
* a second param gets a control by being defined. */
|
|
445
|
+
export interface OpParam {
|
|
446
|
+
name: string;
|
|
447
|
+
/** `'integer'` steps whole; `'number'` accepts fractions (a band's `stdDev`). */
|
|
448
|
+
kind: 'number' | 'integer';
|
|
449
|
+
default: number;
|
|
450
|
+
/** Legal bounds — outside them the registry REJECTS the spec. */
|
|
451
|
+
min?: number;
|
|
452
|
+
max?: number;
|
|
453
|
+
/** The useful range a control should be drawn on, when narrower than legal. */
|
|
454
|
+
suggest?: readonly [number, number];
|
|
455
|
+
}
|
|
456
|
+
/**
|
|
457
|
+
* An op's numeric params, in declaration order.
|
|
458
|
+
*
|
|
459
|
+
* The registry is the single source of truth for what a study can be tuned by
|
|
460
|
+
* — `sma` has one param, a band has two — so anything that offers those knobs
|
|
461
|
+
* reads them from here. Non-numeric params (none today) are skipped rather
|
|
462
|
+
* than coerced.
|
|
463
|
+
*/
|
|
464
|
+
export declare function opParams(op: DeriveOp): OpParam[];
|
|
465
|
+
/**
|
|
466
|
+
* How a study names itself — the op, then the params it was actually tuned
|
|
467
|
+
* with, in the registry's declared order: `SMA(20)`, `BOLLINGER(20, 2)`.
|
|
468
|
+
*
|
|
469
|
+
* Read off the spec against the registry rather than off a known field, so a
|
|
470
|
+
* study with a second param cannot lose half its name to a reader that only
|
|
471
|
+
* knew about `period`.
|
|
472
|
+
*/
|
|
473
|
+
export declare function studyTag(spec: DeriveSpec): string;
|
|
474
|
+
/**
|
|
475
|
+
* Whether a study of this op may draw on its SOURCE's axis.
|
|
476
|
+
*
|
|
477
|
+
* Pond's rule, shipped with the catalog's `unit` field: only `'inherit'` may
|
|
478
|
+
* share. A study that reads in its own units needs its own scale, or it
|
|
479
|
+
* stretches the axis it landed on — an RSI (0..100) beside a vol reading (~20)
|
|
480
|
+
* is the case that made this visible.
|
|
481
|
+
*
|
|
482
|
+
* The hand-declared ops answer from the registry (`sma`/`ema`/`bollinger` are
|
|
483
|
+
* `inherit` and do share); the corpus answers from the catalog, because the
|
|
484
|
+
* registry holds a TRANSLATED unit in which `delta` reads as `inherit` — it
|
|
485
|
+
* formats like its source but must not sit on its axis.
|
|
486
|
+
*/
|
|
487
|
+
export declare function opSharesSourceAxis(op: DeriveOp): boolean;
|
|
488
|
+
/**
|
|
489
|
+
* An op's declared input ROLES, in declaration order — what a spec's `inputs`
|
|
490
|
+
* array must line up with positionally.
|
|
491
|
+
*
|
|
492
|
+
* `[{ role: 'column' }]` for a study of one column, which is what composes (an
|
|
493
|
+
* SMA of an SMA nests). A multi-input study names bar columns instead
|
|
494
|
+
* (`high`/`low`/`close`), because it is a study of a SERIES rather than of a
|
|
495
|
+
* column, and its `default` is the column to bind.
|
|
496
|
+
*/
|
|
497
|
+
export declare function opInputs(op: DeriveOp): {
|
|
498
|
+
role: string;
|
|
499
|
+
default?: string;
|
|
500
|
+
}[];
|
|
501
|
+
/**
|
|
502
|
+
* Input roles that bind to the study's TARGET rather than to a bar column.
|
|
503
|
+
*
|
|
504
|
+
* Two spellings for one idea: the corpus calls it `column` and Tidal's
|
|
505
|
+
* hand-declared ops call it `input`. Everything else names the bar column it
|
|
506
|
+
* wants (`high`, `low`, `close`, `volume`), and a multi-input study has no
|
|
507
|
+
* target role at all — an ATR is of a SERIES, not of a column.
|
|
508
|
+
*/
|
|
509
|
+
export declare const TARGET_ROLES: ReadonlySet<string>;
|
|
510
|
+
/**
|
|
511
|
+
* The raw bar columns a study of this op needs beyond its target's own column
|
|
512
|
+
* — empty for a single-column study.
|
|
513
|
+
*
|
|
514
|
+
* The picker asks this to decide whether an op is offerable on a given series:
|
|
515
|
+
* only the PRICE series carries bars, so an ATR is offerable there and not on a
|
|
516
|
+
* vol series, where `high` names nothing and the fold would skip the spec.
|
|
517
|
+
*/
|
|
518
|
+
export declare function opNeedsColumns(op: DeriveOp): string[];
|
|
519
|
+
/**
|
|
520
|
+
* An op's declared output SUFFIXES, in declaration order — the engine names one
|
|
521
|
+
* column per entry off the spec id, and a runner returns them in this order.
|
|
522
|
+
*
|
|
523
|
+
* `['']` for a single-output op, whose column IS the id. More than one entry
|
|
524
|
+
* makes the config's `column` a PREFIX rather than a readable column, which is
|
|
525
|
+
* the thing every data scanner has to go through `configColumns` for.
|
|
526
|
+
*/
|
|
527
|
+
export declare function opOutputs(op: DeriveOp): string[];
|
|
528
|
+
/**
|
|
529
|
+
* Whether an op's outputs are a BAND — the exact `Middle`/`Upper`/`Lower`
|
|
530
|
+
* triple, in any order.
|
|
531
|
+
*
|
|
532
|
+
* This was "more than one output", which was true only while a band was the
|
|
533
|
+
* only wide mark Tidal could draw. It is not any more: a MACD is three outputs
|
|
534
|
+
* and no band, and `bandColumns` would have looked for a `…Middle` column that
|
|
535
|
+
* does not exist. The shape is the test, and it agrees with the adoption
|
|
536
|
+
* filter's by reading the same {@link BAND_OUTPUTS} list.
|
|
537
|
+
*/
|
|
538
|
+
export declare function opIsBand(op: DeriveOp): boolean;
|
|
539
|
+
/** Whether an op produces SEVERAL columns that are not a band — drawn as N
|
|
540
|
+
* lines off one spec (`style: 'lines'`), one per declared output. */
|
|
541
|
+
export declare function opIsMulti(op: DeriveOp): boolean;
|
|
542
|
+
/**
|
|
543
|
+
* The ops offerable as a **study** of one series: every single-input,
|
|
544
|
+
* column-producing op in {@link TIDAL_OPS}. Generated from the registry's own
|
|
545
|
+
* descriptors (`describe()`), which is the point of declaring a vocabulary —
|
|
546
|
+
* the picker's names, groups and descriptions cannot drift from what the
|
|
547
|
+
* engine will actually run (`TDL-STUDYMENU`).
|
|
548
|
+
*
|
|
549
|
+
* Pair ops are excluded by arity (they take two inputs and are built through
|
|
550
|
+
* the pair picker instead). NOTE: the registry cannot yet declare what UNIT an
|
|
551
|
+
* input expects, so a domain transform like `realizedVol` (which wants a
|
|
552
|
+
* variance) is offered on any series — see the unit-expectation ask logged in
|
|
553
|
+
* CHARTS_FRICTION.
|
|
554
|
+
*/
|
|
555
|
+
export declare function studyCatalog(): StudyOption[];
|