@tidal-ts/core 0.8.0 → 0.11.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/README.md CHANGED
@@ -15,8 +15,8 @@ version number.
15
15
  ## Install
16
16
 
17
17
  ```bash
18
- npm install --save-exact @tidal-ts/core @pond-ts/process@0.72.0
19
- npm install pond-ts@~0.72.0 @pond-ts/financial@~0.72.0
18
+ npm install --save-exact @tidal-ts/core @pond-ts/process@0.73.0
19
+ npm install pond-ts@~0.73.0 @pond-ts/financial@~0.73.0
20
20
  ```
21
21
 
22
22
  The pond packages are peer dependencies: install them once, on the version
@@ -48,7 +48,7 @@ export interface PondAppend {
48
48
  }
49
49
  /**
50
50
  * Adapt a decoded {@link PondSnapshot} into a pond `TimeSeries`. Drops string
51
- * columns (partition metadata), coerces gaps to null, and `sort: true` since
51
+ * columns (partition metadata), coerces gaps to null, and `ordering: 'reorder'` since
52
52
  * wire rows aren't guaranteed ascending.
53
53
  */
54
54
  export declare function snapshotToTimeSeries(snap: PondSnapshot): TimeSeries<import("pond-ts").SeriesSchema>;
package/dist/columnar.js CHANGED
@@ -25,7 +25,7 @@ function assertAligned(name, count, columns, schema) {
25
25
  }
26
26
  /**
27
27
  * Adapt a decoded {@link PondSnapshot} into a pond `TimeSeries`. Drops string
28
- * columns (partition metadata), coerces gaps to null, and `sort: true` since
28
+ * columns (partition metadata), coerces gaps to null, and `ordering: 'reorder'` since
29
29
  * wire rows aren't guaranteed ascending.
30
30
  */
31
31
  export function snapshotToTimeSeries(snap) {
@@ -42,7 +42,7 @@ export function snapshotToTimeSeries(snap) {
42
42
  for (const c of cols) {
43
43
  columns[c.name] = (snap.columns[c.name] ?? []).map((v) => (typeof v === 'number' ? v : null));
44
44
  }
45
- return TimeSeries.fromColumns({ name: snap.name, schema, columns, sort: true });
45
+ return TimeSeries.fromColumns({ name: snap.name, schema, columns, ordering: 'reorder' });
46
46
  }
47
47
  /**
48
48
  * Transpose a columnar {@link PondAppend} into row tuples in the numeric-schema's
package/dist/derive.d.ts CHANGED
@@ -595,6 +595,29 @@ export declare function studyPick(spec: DeriveSpec): StudyPick | undefined;
595
595
  /** `spec` reading `output` of its multi-output source instead — the same spec
596
596
  * when it has none ({@link studyPick}). A bare nested source becomes a pick. */
597
597
  export declare function withStudyOutput(spec: DeriveSpec, output: string): DeriveSpec;
598
+ /**
599
+ * The pick at the BOTTOM of a study chain — the multi-output source a chain
600
+ * of single-output studies ultimately reads, and which of its outputs.
601
+ *
602
+ * {@link studyPick} answers for a study OF a multi-output study; a study of
603
+ * THAT study nests it, so its pick is one level down, and so on. A study
604
+ * **fanned** over several outputs (`SeriesConfig.fan`) is one chain per output,
605
+ * identical except at this pick, which is why this is the one place the
606
+ * outputs are read from. Follows the first input that leads to a pick; a pair
607
+ * stops the walk, as it does for `studyPick`. `undefined` when the chain reads
608
+ * no multi-output source.
609
+ */
610
+ export declare function fanPick(spec: DeriveSpec): StudyPick | undefined;
611
+ /**
612
+ * `spec` with the pick at the bottom of its chain ({@link fanPick}) reading
613
+ * `output` instead — the same chain, run on another output of its source. The
614
+ * spec unchanged when it reads no multi-output source.
615
+ *
616
+ * This is how a fanned study names each of its lines: `sma(Upper)` and
617
+ * `sma(Lower)` are the same SMA with the pick swapped, so a retune of the SMA
618
+ * moves every line together without a list of specs to keep in step.
619
+ */
620
+ export declare function withFanOutput(spec: DeriveSpec, output: string): DeriveSpec;
598
621
  /**
599
622
  * What a study of `source` reads: the source itself, or — for a multi-output
600
623
  * source — its {@link primaryOutput}, PICKED. Never a bare nested multi-output
package/dist/derive.js CHANGED
@@ -834,6 +834,58 @@ export function withStudyOutput(spec, output) {
834
834
  inputs[pick.index] = { from: pick.from, output };
835
835
  return { ...spec, inputs };
836
836
  }
837
+ /**
838
+ * The pick at the BOTTOM of a study chain — the multi-output source a chain
839
+ * of single-output studies ultimately reads, and which of its outputs.
840
+ *
841
+ * {@link studyPick} answers for a study OF a multi-output study; a study of
842
+ * THAT study nests it, so its pick is one level down, and so on. A study
843
+ * **fanned** over several outputs (`SeriesConfig.fan`) is one chain per output,
844
+ * identical except at this pick, which is why this is the one place the
845
+ * outputs are read from. Follows the first input that leads to a pick; a pair
846
+ * stops the walk, as it does for `studyPick`. `undefined` when the chain reads
847
+ * no multi-output source.
848
+ */
849
+ export function fanPick(spec) {
850
+ if (!isSpecLike(spec) || isPairOp(spec.op))
851
+ return undefined;
852
+ const own = studyPick(spec);
853
+ if (own)
854
+ return own;
855
+ for (const i of spec.inputs ?? []) {
856
+ if (isSpecLike(i) && !isPickedInput(i)) {
857
+ const deep = fanPick(i);
858
+ if (deep)
859
+ return deep;
860
+ }
861
+ }
862
+ return undefined;
863
+ }
864
+ /**
865
+ * `spec` with the pick at the bottom of its chain ({@link fanPick}) reading
866
+ * `output` instead — the same chain, run on another output of its source. The
867
+ * spec unchanged when it reads no multi-output source.
868
+ *
869
+ * This is how a fanned study names each of its lines: `sma(Upper)` and
870
+ * `sma(Lower)` are the same SMA with the pick swapped, so a retune of the SMA
871
+ * moves every line together without a list of specs to keep in step.
872
+ */
873
+ export function withFanOutput(spec, output) {
874
+ if (!isSpecLike(spec) || isPairOp(spec.op))
875
+ return spec;
876
+ if (studyPick(spec))
877
+ return withStudyOutput(spec, output);
878
+ const inputs = spec.inputs ?? [];
879
+ for (let index = 0; index < inputs.length; index++) {
880
+ const i = inputs[index];
881
+ if (isSpecLike(i) && !isPickedInput(i) && fanPick(i)) {
882
+ const next = [...inputs];
883
+ next[index] = withFanOutput(i, output);
884
+ return { ...spec, inputs: next };
885
+ }
886
+ }
887
+ return spec;
888
+ }
837
889
  /**
838
890
  * What a study of `source` reads: the source itself, or — for a multi-output
839
891
  * source — its {@link primaryOutput}, PICKED. Never a bare nested multi-output
package/dist/fixture.d.ts CHANGED
@@ -48,7 +48,7 @@ export type PriceSeries = TimeSeries<typeof PRICE_SCHEMA>;
48
48
  /** Build a {@link PriceSeries} from raw OHLCV rows. The one place the price
49
49
  * `TimeSeries` is constructed — fixture, HTTP source, and the real ticker-history
50
50
  * adapter all funnel through here. Uses the **columnar** ingress (gap-tolerant,
51
- * `sort:true`) so a non-finite cell reads as a gap rather than being rejected —
51
+ * `ordering: 'reorder'`) so a non-finite cell reads as a gap rather than being rejected —
52
52
  * real data can carry the occasional missing OHLCV cell. */
53
53
  export declare function buildPriceSeries(name: string, rows: readonly PriceRow[]): PriceSeries;
54
54
  /**
package/dist/fixture.js CHANGED
@@ -59,7 +59,7 @@ export const PRICE_SCHEMA = [
59
59
  /** Build a {@link PriceSeries} from raw OHLCV rows. The one place the price
60
60
  * `TimeSeries` is constructed — fixture, HTTP source, and the real ticker-history
61
61
  * adapter all funnel through here. Uses the **columnar** ingress (gap-tolerant,
62
- * `sort:true`) so a non-finite cell reads as a gap rather than being rejected —
62
+ * `ordering: 'reorder'`) so a non-finite cell reads as a gap rather than being rejected —
63
63
  * real data can carry the occasional missing OHLCV cell. */
64
64
  export function buildPriceSeries(name, rows) {
65
65
  return TimeSeries.fromColumns({
@@ -73,7 +73,7 @@ export function buildPriceSeries(name, rows) {
73
73
  close: rows.map((r) => r[4]),
74
74
  volume: rows.map((r) => r[5]),
75
75
  },
76
- sort: true,
76
+ ordering: 'reorder',
77
77
  });
78
78
  }
79
79
  /**
package/dist/index.d.ts CHANGED
@@ -2,7 +2,7 @@ export { BAR_INTERVAL_MS, type Instrument, type InstrumentKind, type BarInterval
2
2
  export { generatePriceSeries, buildPriceSeries, DEMO_INSTRUMENTS, PRICE_SCHEMA, type PriceSeriesOptions, type PriceSeries, type PriceRow, } from './fixture.js';
3
3
  export { generateVolSeries, buildVolSeries, VOL_SCHEMA, VOL_TENORS, DEFAULT_VOL_TENOR, impliedCol, hvCol, rvCol, rvCenCol, skewCol, type VolSeries, type VolColumns, type VolTenor, type VolSeriesOptions, } from './vol.js';
4
4
  export { aggregateColumn, floorToWindow, liveWindowMs, ohlcWindow, sessionGrid, WINDOW_MS, WINDOW_LADDER, MIN_BAR_PX, autoBarWindow, type BarReducer, type SeriesWindow, } from './aggregate.js';
5
- export { applyDerived, applyDerivedReport, COMPARE_PREFIX, deriveId, deriveLineage, inputNames, substituteInput, hasPairOp, isBrokenId, isPairOp, isValidSpec, opHasPeriod, PERIOD_BOUNDS, readNumericColumn, partStudyLabel, readPart, readPairParts, specUnit, studyCatalog, TIDAL_OPS, BAND_OUTPUTS, opParams, studyTag, opIsBand, opInputs, opIsMulti, opOutputs, primaryOutput, studyInputOf, studyPick, withStudyOutput, type StudyPick, isPickedInput, opNeedsColumns, TARGET_ROLES, opSharesSourceAxis, type OpParam, usesCompare, type DeriveSkip, type PairPart, type PartStudy, type StudyOption, type NumericColumnReader, DEFAULT_PERIOD, type DeriveInput, type PickedDeriveOutput, type DeriveSpec, type DeriveOp, type TidalOp, type PairOp, } from './derive.js';
5
+ export { applyDerived, applyDerivedReport, COMPARE_PREFIX, deriveId, deriveLineage, inputNames, substituteInput, hasPairOp, isBrokenId, isPairOp, isValidSpec, opHasPeriod, PERIOD_BOUNDS, readNumericColumn, partStudyLabel, readPart, readPairParts, specUnit, studyCatalog, TIDAL_OPS, BAND_OUTPUTS, opParams, studyTag, opIsBand, opInputs, opIsMulti, opOutputs, primaryOutput, studyInputOf, studyPick, fanPick, withFanOutput, withStudyOutput, type StudyPick, isPickedInput, opNeedsColumns, TARGET_ROLES, opSharesSourceAxis, type OpParam, usesCompare, type DeriveSkip, type PairPart, type PartStudy, type StudyOption, type NumericColumnReader, DEFAULT_PERIOD, type DeriveInput, type PickedDeriveOutput, type DeriveSpec, type DeriveOp, type TidalOp, type PairOp, } from './derive.js';
6
6
  export { joinUnderPrefix } from './join.js';
7
7
  export { columnExtent } from './extent.js';
8
8
  export { snapshotToTimeSeries, appendToRows, type PondSnapshot, type PondAppend, type PondValue, type WireColumnSpec, } from './columnar.js';
package/dist/index.js CHANGED
@@ -2,7 +2,7 @@ export { BAR_INTERVAL_MS, } from './types.js';
2
2
  export { generatePriceSeries, buildPriceSeries, DEMO_INSTRUMENTS, PRICE_SCHEMA, } from './fixture.js';
3
3
  export { generateVolSeries, buildVolSeries, VOL_SCHEMA, VOL_TENORS, DEFAULT_VOL_TENOR, impliedCol, hvCol, rvCol, rvCenCol, skewCol, } from './vol.js';
4
4
  export { aggregateColumn, floorToWindow, liveWindowMs, ohlcWindow, sessionGrid, WINDOW_MS, WINDOW_LADDER, MIN_BAR_PX, autoBarWindow, } from './aggregate.js';
5
- export { applyDerived, applyDerivedReport, COMPARE_PREFIX, deriveId, deriveLineage, inputNames, substituteInput, hasPairOp, isBrokenId, isPairOp, isValidSpec, opHasPeriod, PERIOD_BOUNDS, readNumericColumn, partStudyLabel, readPart, readPairParts, specUnit, studyCatalog, TIDAL_OPS, BAND_OUTPUTS, opParams, studyTag, opIsBand, opInputs, opIsMulti, opOutputs, primaryOutput, studyInputOf, studyPick, withStudyOutput, isPickedInput, opNeedsColumns, TARGET_ROLES, opSharesSourceAxis, usesCompare, DEFAULT_PERIOD, } from './derive.js';
5
+ export { applyDerived, applyDerivedReport, COMPARE_PREFIX, deriveId, deriveLineage, inputNames, substituteInput, hasPairOp, isBrokenId, isPairOp, isValidSpec, opHasPeriod, PERIOD_BOUNDS, readNumericColumn, partStudyLabel, readPart, readPairParts, specUnit, studyCatalog, TIDAL_OPS, BAND_OUTPUTS, opParams, studyTag, opIsBand, opInputs, opIsMulti, opOutputs, primaryOutput, studyInputOf, studyPick, fanPick, withFanOutput, withStudyOutput, isPickedInput, opNeedsColumns, TARGET_ROLES, opSharesSourceAxis, usesCompare, DEFAULT_PERIOD, } from './derive.js';
6
6
  export { joinUnderPrefix } from './join.js';
7
7
  export { columnExtent } from './extent.js';
8
8
  export { snapshotToTimeSeries, appendToRows, } from './columnar.js';
package/dist/regrid.js CHANGED
@@ -100,9 +100,10 @@ export function holdAcrossGrid(coarse, grid, grainMs) {
100
100
  for (const spec of valueSpecs) {
101
101
  const src = coarse.column(spec.name);
102
102
  if (spec.kind === 'number') {
103
- // Through `at`, not `toFloat64Array()`: the raw buffer does not mark a
104
- // missing cell (a join's unmatched row reads 0 there). The coarse side is
105
- // the short one, so this is a few hundred reads.
103
+ // Through `at`, which reads a missing cell as `undefined`. Before pond
104
+ // 0.73 the raw buffer did not mark one (a join's unmatched row read 0);
105
+ // since 0.73 `toFloat64Array()` holds `NaN` there too, so either works.
106
+ // The coarse side is the short one, so this is a few hundred reads.
106
107
  const values = new Float64Array(n);
107
108
  for (let r = 0; r < n; r += 1) {
108
109
  const v = src.at(r);
@@ -105,26 +105,29 @@ export declare function inferBarMs(times: readonly number[]): number | undefined
105
105
  *
106
106
  * Shifting the KEY rather than fixing it at the source is deliberate: a candle
107
107
  * needs the span `[open, close]` and draws from the open, so the two styles want
108
- * different x for the same row. Charts plots a line at the key's `begin`
109
- * whichever key kind it is, so the only way to move the line is to move the key —
110
- * and only for the layers that want it moved.
111
- *
112
- * Costs one pass over the key column plus a rebuild (~14 ms at 100k rows), so it
113
- * belongs behind a per-fetch memo, never in a render path.
108
+ * different x for the same row. A line, area or band layer takes charts'
109
+ * `xOffset` for this (charts 0.73) and needs no copy; this is for a layer that
110
+ * has no such prop — `<BarChart>`, whose point-keyed histogram must sit under the
111
+ * shifted lines it explains.
112
+ *
113
+ * pond's `offsetTime` does the move: one pass over the key, value columns shared
114
+ * (0.26 ms on 97k rows × 118 columns, by pond's measurement — the rebuild this
115
+ * used to do cost 235–442 ms on the same shape).
114
116
  */
115
117
  export declare function shiftKeys(series: TimeSeries<SeriesSchema>, ms: number): TimeSeries<SeriesSchema>;
116
118
  /**
117
119
  * The series cut into one sub-series per live segment — `[start, end)` on the
118
120
  * time key, empty segments dropped.
119
121
  *
120
- * For the layer pond gives no `sessionBreaks` of its own — `<AreaChart>`
121
- * (`<LineChart>` has always had it; `<BandChart>` gained it in charts 0.70.0,
122
- * which retired this function's other caller). A fill drawn across a
123
- * collapsed overnight gap bridges seventeen hours of closed market in one
124
- * confident sweep and contradicts the line drawn over it; one layer per segment
125
- * ends the fill at the close and restarts it at the open, which is what that
126
- * line already does. The cost is `segments.length` layers instead of one, so a
127
- * caller asks only when the axis actually collapses.
122
+ * @deprecated No longer needed to break a fill at a session seam: every charts
123
+ * layer that fills or strokes takes `sessionBreaks` since charts 0.73
124
+ * (`<AreaChart>` was the last), so `TimeSeriesChart` no longer calls this. Kept
125
+ * for a host that slices a series per session for some other reason.
126
+ *
127
+ * It existed for `<AreaChart>` before it had `sessionBreaks`: a fill drawn
128
+ * across a collapsed overnight gap bridges seventeen hours of closed market in
129
+ * one confident sweep, and one layer per segment ended it at the close and
130
+ * restarted it at the open, as the line over it did.
128
131
  *
129
132
  * Pond does the cutting — `bisect` finds each edge in O(log n) on the packed key
130
133
  * buffer and `slice` is positional and half-open — so nothing here is
package/dist/sessions.js CHANGED
@@ -153,43 +153,37 @@ function median(values) {
153
153
  *
154
154
  * Shifting the KEY rather than fixing it at the source is deliberate: a candle
155
155
  * needs the span `[open, close]` and draws from the open, so the two styles want
156
- * different x for the same row. Charts plots a line at the key's `begin`
157
- * whichever key kind it is, so the only way to move the line is to move the key —
158
- * and only for the layers that want it moved.
156
+ * different x for the same row. A line, area or band layer takes charts'
157
+ * `xOffset` for this (charts 0.73) and needs no copy; this is for a layer that
158
+ * has no such prop — `<BarChart>`, whose point-keyed histogram must sit under the
159
+ * shifted lines it explains.
159
160
  *
160
- * Costs one pass over the key column plus a rebuild (~14 ms at 100k rows), so it
161
- * belongs behind a per-fetch memo, never in a render path.
161
+ * pond's `offsetTime` does the move: one pass over the key, value columns shared
162
+ * (0.26 ms on 97k rows × 118 columns, by pond's measurement — the rebuild this
163
+ * used to do cost 235–442 ms on the same shape).
162
164
  */
163
165
  export function shiftKeys(series, ms) {
164
166
  if (ms === 0)
165
167
  return series;
166
- const out = series.toColumns();
167
- const key = out.schema.find((c) => c.kind === 'time')?.name;
168
- // No time key (a value-keyed series) ⇒ nothing to shift, and shifting the wrong
169
- // column would corrupt values rather than fail.
170
- if (key === undefined)
168
+ // Only a time key moves by a constant duration; anything else comes back as it
169
+ // is rather than failing in the render path.
170
+ if (series.schema[0]?.kind !== 'time')
171
171
  return series;
172
- const src = out.columns[key];
173
- const shifted = new Float64Array(src.length);
174
- for (let i = 0; i < src.length; i += 1)
175
- shifted[i] = src[i] + ms;
176
- return TimeSeries.fromColumns({
177
- ...out,
178
- columns: { ...out.columns, [key]: shifted },
179
- });
172
+ return series.offsetTime(ms);
180
173
  }
181
174
  /**
182
175
  * The series cut into one sub-series per live segment — `[start, end)` on the
183
176
  * time key, empty segments dropped.
184
177
  *
185
- * For the layer pond gives no `sessionBreaks` of its own — `<AreaChart>`
186
- * (`<LineChart>` has always had it; `<BandChart>` gained it in charts 0.70.0,
187
- * which retired this function's other caller). A fill drawn across a
188
- * collapsed overnight gap bridges seventeen hours of closed market in one
189
- * confident sweep and contradicts the line drawn over it; one layer per segment
190
- * ends the fill at the close and restarts it at the open, which is what that
191
- * line already does. The cost is `segments.length` layers instead of one, so a
192
- * caller asks only when the axis actually collapses.
178
+ * @deprecated No longer needed to break a fill at a session seam: every charts
179
+ * layer that fills or strokes takes `sessionBreaks` since charts 0.73
180
+ * (`<AreaChart>` was the last), so `TimeSeriesChart` no longer calls this. Kept
181
+ * for a host that slices a series per session for some other reason.
182
+ *
183
+ * It existed for `<AreaChart>` before it had `sessionBreaks`: a fill drawn
184
+ * across a collapsed overnight gap bridges seventeen hours of closed market in
185
+ * one confident sweep, and one layer per segment ended it at the close and
186
+ * restarted it at the open, as the line over it did.
193
187
  *
194
188
  * Pond does the cutting — `bisect` finds each edge in O(log n) on the packed key
195
189
  * buffer and `slice` is positional and half-open — so nothing here is
package/dist/vol.js CHANGED
@@ -173,7 +173,7 @@ export function buildVolSeries(name, columns) {
173
173
  name,
174
174
  schema: VOL_SCHEMA,
175
175
  columns: columns,
176
- sort: true,
176
+ ordering: 'reorder',
177
177
  });
178
178
  }
179
179
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tidal-ts/core",
3
- "version": "0.8.0",
3
+ "version": "0.11.0",
4
4
  "private": false,
5
5
  "description": "Financial time-series vocabulary on pond-ts: the study/derive seam, the vol schema, bar windows, the columnar adapter and session helpers.",
6
6
  "license": "MIT",
@@ -31,14 +31,14 @@
31
31
  "access": "public"
32
32
  },
33
33
  "peerDependencies": {
34
- "@pond-ts/financial": "^0.72.0",
35
- "@pond-ts/process": "0.72.0",
36
- "pond-ts": "^0.72.0"
34
+ "@pond-ts/financial": "^0.73.0",
35
+ "@pond-ts/process": "0.73.0",
36
+ "pond-ts": "^0.73.0"
37
37
  },
38
38
  "devDependencies": {
39
- "@pond-ts/financial": "^0.72.0",
40
- "@pond-ts/process": "0.72.0",
41
- "pond-ts": "^0.72.0",
39
+ "@pond-ts/financial": "^0.73.0",
40
+ "@pond-ts/process": "0.73.0",
41
+ "pond-ts": "^0.73.0",
42
42
  "typescript": "^5.7.2",
43
43
  "vitest": "^2.1.8"
44
44
  },