@tidal-ts/core 0.27.0 → 0.29.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/dist/derive.d.ts +39 -4
- package/dist/derive.js +116 -27
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/regrid.d.ts +12 -0
- package/dist/regrid.js +63 -0
- package/package.json +1 -1
package/dist/derive.d.ts
CHANGED
|
@@ -45,7 +45,7 @@ export type DeriveOp = TidalOp | (string & {});
|
|
|
45
45
|
* an identity — the column keeps its name when the compare ticker changes,
|
|
46
46
|
* so a spread's id (and the user's overrides on it) survive the swap. The
|
|
47
47
|
* fold joins the comparison with pond's join node, whose own name for these
|
|
48
|
-
* columns is `
|
|
48
|
+
* columns is `cmp_:iv21`; {@link applyDerivedReport} turns them back into this
|
|
49
49
|
* prefix, so the rest of Tidal never sees pond's form.
|
|
50
50
|
*/
|
|
51
51
|
export declare const COMPARE_PREFIX = "cmp_";
|
|
@@ -66,6 +66,36 @@ export declare const pinnedPrefix: (symbol: string) => string;
|
|
|
66
66
|
* whose reading it is. A column with neither prefix comes back as it is.
|
|
67
67
|
*/
|
|
68
68
|
export declare function stripOtherSymbol(column: string): string;
|
|
69
|
+
/**
|
|
70
|
+
* The column prefix for **another data source** of the same symbol — a compare
|
|
71
|
+
* on the price source reading a line of the vol source: `~vol_iv21` is the vol
|
|
72
|
+
* source's `iv21`, joined onto the price source's rows (compare node plan,
|
|
73
|
+
* step 6b). It goes AFTER a symbol's prefix, so the comparison's vol is
|
|
74
|
+
* `cmp_~vol_iv21` and a locked symbol's `cmp_@SPY_~vol_iv21`. A raw column of
|
|
75
|
+
* the other source, never a study's: a study on the other side runs on the
|
|
76
|
+
* metric's own rows, as every compare does.
|
|
77
|
+
*/
|
|
78
|
+
export declare const sourcePrefix: (source: string) => string;
|
|
79
|
+
/** Whether `source` can name another source's columns: letters and digits
|
|
80
|
+
* only — never `_`, which ends the prefix. */
|
|
81
|
+
export declare const isSourceKey: (source: string) => boolean;
|
|
82
|
+
/**
|
|
83
|
+
* The other-reading prefix a column starts with — the longest one: `cmp_` for
|
|
84
|
+
* `cmp_iv21`, `cmp_@SPY_~vol_` for `cmp_@SPY_~vol_iv21`, `~vol_` for
|
|
85
|
+
* `~vol_iv21` — or `null` for a column of this source on this symbol. The fold
|
|
86
|
+
* joins one series per distinct prefix its configs read.
|
|
87
|
+
*/
|
|
88
|
+
export declare function otherPrefixOf(column: string): string | null;
|
|
89
|
+
/**
|
|
90
|
+
* An other-reading prefix read apart: the symbol part (`''` for this symbol,
|
|
91
|
+
* {@link COMPARE_PREFIX}, or a {@link pinnedPrefix}) and the source it names
|
|
92
|
+
* (`undefined` for the source being folded). `null` for a string that is not
|
|
93
|
+
* a whole prefix of that shape. The fold's join reads it.
|
|
94
|
+
*/
|
|
95
|
+
export declare function parseOtherPrefix(prefix: string): {
|
|
96
|
+
symbol: string;
|
|
97
|
+
source: string | undefined;
|
|
98
|
+
} | null;
|
|
69
99
|
/** Whether `symbol` can name a locked symbol's columns: letters, digits and
|
|
70
100
|
* `.` `-` `^` only — never `_`, which ends the prefix. */
|
|
71
101
|
export declare const isPinnableSymbol: (symbol: string) => boolean;
|
|
@@ -74,7 +104,10 @@ export declare const isPinnableSymbol: (symbol: string) => boolean;
|
|
|
74
104
|
* raw column LEAVES, so a nested spec keeps its shape and reads another
|
|
75
105
|
* symbol's columns — `sma(close)` under `cmp_@SPY_` reads `cmp_@SPY_close`.
|
|
76
106
|
* A leaf already reading another symbol (any {@link COMPARE_PREFIX} column)
|
|
77
|
-
* is left alone: prefixing it again would name a column no join carries.
|
|
107
|
+
* is left alone: prefixing it again would name a column no join carries. So
|
|
108
|
+
* is a leaf already on another source, under a source prefix
|
|
109
|
+
* ({@link sourcePrefix}); a symbol prefix still goes in front of it
|
|
110
|
+
* (`~vol_iv21` under `cmp_` is `cmp_~vol_iv21`).
|
|
78
111
|
*/
|
|
79
112
|
export declare function underPrefix(input: DeriveInput, prefix: string): DeriveInput;
|
|
80
113
|
/** Whether any raw column `spec` reads, at any depth, passes `test`. */
|
|
@@ -501,8 +534,10 @@ export interface DeriveNodeTiming {
|
|
|
501
534
|
* other series at or before it, so two symbols that print at different minutes
|
|
502
535
|
* still pair (an exact-time join left those cells empty). Each is keyed by the
|
|
503
536
|
* column prefix its columns carry here — {@link COMPARE_PREFIX} for the bar's
|
|
504
|
-
* comparison, {@link pinnedPrefix} for a locked symbol
|
|
505
|
-
*
|
|
537
|
+
* comparison, {@link pinnedPrefix} for a locked symbol, {@link sourcePrefix}
|
|
538
|
+
* for another data source, after a symbol's prefix for that source on another
|
|
539
|
+
* symbol — and comes out under it: `cmp_close`, `cmp_@SPY_close`, `~vol_iv21`,
|
|
540
|
+
* `cmp_~vol_iv21`. A key of any other shape is ignored.
|
|
506
541
|
*
|
|
507
542
|
* Deliberately a **cold bind per fold** for now — same cost shape as the local
|
|
508
543
|
* fold it replaced, kept simple while semantics settle. The warm long-lived
|
package/dist/derive.js
CHANGED
|
@@ -9,7 +9,7 @@ import { bind, columnsOf, createRegistry, int, num, run, specId, explain, } from
|
|
|
9
9
|
* an identity — the column keeps its name when the compare ticker changes,
|
|
10
10
|
* so a spread's id (and the user's overrides on it) survive the swap. The
|
|
11
11
|
* fold joins the comparison with pond's join node, whose own name for these
|
|
12
|
-
* columns is `
|
|
12
|
+
* columns is `cmp_:iv21`; {@link applyDerivedReport} turns them back into this
|
|
13
13
|
* prefix, so the rest of Tidal never sees pond's form.
|
|
14
14
|
*/
|
|
15
15
|
export const COMPARE_PREFIX = 'cmp_';
|
|
@@ -30,14 +30,95 @@ export const pinnedPrefix = (symbol) => `${COMPARE_PREFIX}@${symbol}_`;
|
|
|
30
30
|
* whose reading it is. A column with neither prefix comes back as it is.
|
|
31
31
|
*/
|
|
32
32
|
export function stripOtherSymbol(column) {
|
|
33
|
-
|
|
33
|
+
let rest = column;
|
|
34
|
+
if (rest.startsWith(COMPARE_PREFIX)) {
|
|
35
|
+
rest = rest.slice(COMPARE_PREFIX.length);
|
|
36
|
+
if (rest.startsWith('@')) {
|
|
37
|
+
// A pinnable symbol never holds `_`, so the first one ends the prefix.
|
|
38
|
+
const end = rest.indexOf('_');
|
|
39
|
+
if (end > 1)
|
|
40
|
+
rest = rest.slice(end + 1);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
// Then another source's prefix, which comes after the symbol's.
|
|
44
|
+
return stripSource(rest);
|
|
45
|
+
}
|
|
46
|
+
/** The start of every other-source prefix: `~vol_`. A source key never starts
|
|
47
|
+
* a raw column with it, and `~` is not a character a symbol may hold. */
|
|
48
|
+
const SOURCE_START = '~';
|
|
49
|
+
/**
|
|
50
|
+
* The column prefix for **another data source** of the same symbol — a compare
|
|
51
|
+
* on the price source reading a line of the vol source: `~vol_iv21` is the vol
|
|
52
|
+
* source's `iv21`, joined onto the price source's rows (compare node plan,
|
|
53
|
+
* step 6b). It goes AFTER a symbol's prefix, so the comparison's vol is
|
|
54
|
+
* `cmp_~vol_iv21` and a locked symbol's `cmp_@SPY_~vol_iv21`. A raw column of
|
|
55
|
+
* the other source, never a study's: a study on the other side runs on the
|
|
56
|
+
* metric's own rows, as every compare does.
|
|
57
|
+
*/
|
|
58
|
+
export const sourcePrefix = (source) => `${SOURCE_START}${source}_`;
|
|
59
|
+
/** Whether `source` can name another source's columns: letters and digits
|
|
60
|
+
* only — never `_`, which ends the prefix. */
|
|
61
|
+
export const isSourceKey = (source) => /^[A-Za-z0-9]{1,32}$/.test(source);
|
|
62
|
+
/** A column with an other-source prefix (`~vol_`) taken off, if it has one. */
|
|
63
|
+
function stripSource(column) {
|
|
64
|
+
if (!column.startsWith(SOURCE_START))
|
|
34
65
|
return column;
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
66
|
+
const end = column.indexOf('_');
|
|
67
|
+
return end > 1 && isSourceKey(column.slice(1, end)) ? column.slice(end + 1) : column;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* The other-reading prefix a column starts with — the longest one: `cmp_` for
|
|
71
|
+
* `cmp_iv21`, `cmp_@SPY_~vol_` for `cmp_@SPY_~vol_iv21`, `~vol_` for
|
|
72
|
+
* `~vol_iv21` — or `null` for a column of this source on this symbol. The fold
|
|
73
|
+
* joins one series per distinct prefix its configs read.
|
|
74
|
+
*/
|
|
75
|
+
export function otherPrefixOf(column) {
|
|
76
|
+
let at = 0;
|
|
77
|
+
if (column.startsWith(COMPARE_PREFIX)) {
|
|
78
|
+
at = COMPARE_PREFIX.length;
|
|
79
|
+
if (column[at] === '@') {
|
|
80
|
+
const end = column.indexOf('_', at);
|
|
81
|
+
if (end > at + 1 && isPinnableSymbol(column.slice(at + 1, end)))
|
|
82
|
+
at = end + 1;
|
|
83
|
+
else
|
|
84
|
+
return null;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
if (column.startsWith(SOURCE_START, at)) {
|
|
88
|
+
const end = column.indexOf('_', at);
|
|
89
|
+
if (end > at + 1 && isSourceKey(column.slice(at + 1, end)))
|
|
90
|
+
at = end + 1;
|
|
91
|
+
else
|
|
92
|
+
return at > 0 ? column.slice(0, at) : null;
|
|
93
|
+
}
|
|
94
|
+
return at > 0 ? column.slice(0, at) : null;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* An other-reading prefix read apart: the symbol part (`''` for this symbol,
|
|
98
|
+
* {@link COMPARE_PREFIX}, or a {@link pinnedPrefix}) and the source it names
|
|
99
|
+
* (`undefined` for the source being folded). `null` for a string that is not
|
|
100
|
+
* a whole prefix of that shape. The fold's join reads it.
|
|
101
|
+
*/
|
|
102
|
+
export function parseOtherPrefix(prefix) {
|
|
103
|
+
let rest = prefix;
|
|
104
|
+
let symbol = '';
|
|
105
|
+
if (rest.startsWith(COMPARE_PREFIX)) {
|
|
106
|
+
rest = rest.slice(COMPARE_PREFIX.length);
|
|
107
|
+
symbol = COMPARE_PREFIX;
|
|
108
|
+
if (rest.startsWith('@')) {
|
|
109
|
+
const end = rest.indexOf('_');
|
|
110
|
+
if (end < 0 || !isPinnableSymbol(rest.slice(1, end)))
|
|
111
|
+
return null;
|
|
112
|
+
symbol = `${COMPARE_PREFIX}${rest.slice(0, end + 1)}`;
|
|
113
|
+
rest = rest.slice(end + 1);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
if (rest === '')
|
|
117
|
+
return symbol ? { symbol, source: undefined } : null;
|
|
118
|
+
if (!rest.startsWith(SOURCE_START) || !rest.endsWith('_'))
|
|
119
|
+
return null;
|
|
120
|
+
const source = rest.slice(SOURCE_START.length, -1);
|
|
121
|
+
return isSourceKey(source) ? { symbol, source } : null;
|
|
41
122
|
}
|
|
42
123
|
/** Whether `symbol` can name a locked symbol's columns: letters, digits and
|
|
43
124
|
* `.` `-` `^` only — never `_`, which ends the prefix. */
|
|
@@ -47,11 +128,21 @@ export const isPinnableSymbol = (symbol) => /^[A-Za-z0-9.^-]{1,32}$/.test(symbol
|
|
|
47
128
|
* raw column LEAVES, so a nested spec keeps its shape and reads another
|
|
48
129
|
* symbol's columns — `sma(close)` under `cmp_@SPY_` reads `cmp_@SPY_close`.
|
|
49
130
|
* A leaf already reading another symbol (any {@link COMPARE_PREFIX} column)
|
|
50
|
-
* is left alone: prefixing it again would name a column no join carries.
|
|
131
|
+
* is left alone: prefixing it again would name a column no join carries. So
|
|
132
|
+
* is a leaf already on another source, under a source prefix
|
|
133
|
+
* ({@link sourcePrefix}); a symbol prefix still goes in front of it
|
|
134
|
+
* (`~vol_iv21` under `cmp_` is `cmp_~vol_iv21`).
|
|
51
135
|
*/
|
|
52
136
|
export function underPrefix(input, prefix) {
|
|
53
|
-
if (typeof input === 'string')
|
|
54
|
-
|
|
137
|
+
if (typeof input === 'string') {
|
|
138
|
+
if (input.startsWith(COMPARE_PREFIX))
|
|
139
|
+
return input;
|
|
140
|
+
// A source prefix onto a leaf already on another source would name a
|
|
141
|
+
// source of a source, which nothing joins.
|
|
142
|
+
if (prefix.startsWith(SOURCE_START) && parseOtherPrefix(otherPrefixOf(input) ?? '')?.source)
|
|
143
|
+
return input;
|
|
144
|
+
return `${prefix}${input}`;
|
|
145
|
+
}
|
|
55
146
|
if (isPickedInput(input))
|
|
56
147
|
return { from: underPrefix(input.from, prefix), output: input.output };
|
|
57
148
|
return { ...input, inputs: (input.inputs ?? []).map((i) => underPrefix(i, prefix)) };
|
|
@@ -642,8 +733,10 @@ function outputUnit(spec, index, unitOf) {
|
|
|
642
733
|
* other series at or before it, so two symbols that print at different minutes
|
|
643
734
|
* still pair (an exact-time join left those cells empty). Each is keyed by the
|
|
644
735
|
* column prefix its columns carry here — {@link COMPARE_PREFIX} for the bar's
|
|
645
|
-
* comparison, {@link pinnedPrefix} for a locked symbol
|
|
646
|
-
*
|
|
736
|
+
* comparison, {@link pinnedPrefix} for a locked symbol, {@link sourcePrefix}
|
|
737
|
+
* for another data source, after a symbol's prefix for that source on another
|
|
738
|
+
* symbol — and comes out under it: `cmp_close`, `cmp_@SPY_close`, `~vol_iv21`,
|
|
739
|
+
* `cmp_~vol_iv21`. A key of any other shape is ignored.
|
|
647
740
|
*
|
|
648
741
|
* Deliberately a **cold bind per fold** for now — same cost shape as the local
|
|
649
742
|
* fold it replaced, kept simple while semantics settle. The warm long-lived
|
|
@@ -717,20 +810,16 @@ export function applyDerivedReport(input, specs, units, others) {
|
|
|
717
810
|
}));
|
|
718
811
|
return { series: result.series ?? series, skipped: [...skipped.values()], nodes };
|
|
719
812
|
}
|
|
720
|
-
/** Whether `prefix` names another
|
|
721
|
-
* locked symbol's
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
prefix.endsWith('_') &&
|
|
725
|
-
isPinnableSymbol(prefix.slice(PINNED_START.length, -1)));
|
|
726
|
-
/** The start every locked symbol's prefix shares (`cmp_@`). */
|
|
727
|
-
const PINNED_START = `${COMPARE_PREFIX}@`;
|
|
813
|
+
/** Whether `prefix` names another reading's columns: the comparison's, a
|
|
814
|
+
* locked symbol's, another source's, or another source's on either symbol
|
|
815
|
+
* ({@link parseOtherPrefix}). */
|
|
816
|
+
const isOtherPrefix = (prefix) => parseOtherPrefix(prefix) !== null;
|
|
728
817
|
/** The join's key for this symbol's own series. Pond names a joined column
|
|
729
818
|
* `<key>:<column>`, this one included (CHARTS_FRICTION F-charts-45). */
|
|
730
819
|
const BASE_KEY = 'p';
|
|
731
|
-
/** The join's key for another
|
|
732
|
-
*
|
|
733
|
-
const keyOfPrefix = (prefix) => prefix
|
|
820
|
+
/** The join's key for another reading's prefix: the prefix itself, which
|
|
821
|
+
* never holds `:` and is never {@link BASE_KEY} (every one ends in `_`). */
|
|
822
|
+
const keyOfPrefix = (prefix) => prefix;
|
|
734
823
|
/** Rewrite every raw column leaf of a spec, at any depth. A shape that is not
|
|
735
824
|
* a spec (untyped persisted state) passes through untouched, for the engine
|
|
736
825
|
* to skip and report as it would have. */
|
|
@@ -771,10 +860,10 @@ function safeId(spec) {
|
|
|
771
860
|
* symbols' series behind one as-of join node, `series` the base.
|
|
772
861
|
*
|
|
773
862
|
* Pond qualifies every joined column with its source's key, the base's too
|
|
774
|
-
* (`p:close`, `
|
|
863
|
+
* (`p:close`, `cmp_:close`), and a spec id names the columns it reads, so the
|
|
775
864
|
* fold works in pond's names and hands back Tidal's: going in, every raw
|
|
776
|
-
* leaf is rewritten (`close` → `p:close`, `cmp_close` → `
|
|
777
|
-
* `cmp_@SPY_close` →
|
|
865
|
+
* leaf is rewritten (`close` → `p:close`, `cmp_close` → `cmp_:close`,
|
|
866
|
+
* `cmp_@SPY_close` → `cmp_@SPY_:close`); coming out, the columns, the node report
|
|
778
867
|
* and the skips are named back, so a caller sees exactly the columns and ids
|
|
779
868
|
* a single-series fold would give. This is the one place the two naming
|
|
780
869
|
* schemes meet; it shrinks to the other symbols alone if pond leaves the
|
package/dist/index.d.ts
CHANGED
|
@@ -2,12 +2,12 @@ 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, pinnedPrefix, isPinnableSymbol, underPrefix, readsPrefix, readsColumn, stripOtherSymbol, deriveId, deriveLineage, inputNames, substituteInput, hasPairOp, isBrokenId, isPairOp, isValidSpec, opHasPeriod, PERIOD_BOUNDS, readNumericColumn, partStudyLabel, readPart, readPairParts, specUnit, studyCatalog, TIDAL_OPS, BAND_OUTPUTS, opParams, isStudyOp, studyTag, opIsBand, opInputs, opIsMulti, opOutputs, primaryOutput, studyInputOf, studyPick, fanPick, withFanOutput, withStudyOutput, studyColumn, BAR_PRICE_COLUMNS, withStudyColumn, type StudyPick, isPickedInput, opNeedsColumns, TARGET_ROLES, opSharesSourceAxis, type OpParam, usesCompare, type DeriveSkip, type DeriveNodeTiming, 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, pinnedPrefix, isPinnableSymbol, underPrefix, readsPrefix, readsColumn, stripOtherSymbol, sourcePrefix, isSourceKey, parseOtherPrefix, otherPrefixOf, deriveId, deriveLineage, inputNames, substituteInput, hasPairOp, isBrokenId, isPairOp, isValidSpec, opHasPeriod, PERIOD_BOUNDS, readNumericColumn, partStudyLabel, readPart, readPairParts, specUnit, studyCatalog, TIDAL_OPS, BAND_OUTPUTS, opParams, isStudyOp, studyTag, opIsBand, opInputs, opIsMulti, opOutputs, primaryOutput, studyInputOf, studyPick, fanPick, withFanOutput, withStudyOutput, studyColumn, BAR_PRICE_COLUMNS, withStudyColumn, type StudyPick, isPickedInput, opNeedsColumns, TARGET_ROLES, opSharesSourceAxis, type OpParam, usesCompare, type DeriveSkip, type DeriveNodeTiming, 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';
|
|
9
9
|
export { exactSessionSegments, inferBarMs, sessionOpenLine, sessionSegments, shiftKeys, sliceBySegments, type Segment, type SessionSegmentOptions, } from './sessions.js';
|
|
10
10
|
export { monthlyExpirations, thirdFriday } from './expirations.js';
|
|
11
|
-
export { holdAcrossGrid, holdVolAcrossGrid, type HeldSchema } from './regrid.js';
|
|
11
|
+
export { holdAcrossGrid, holdVolAcrossGrid, lastInEachGrain, type HeldSchema } from './regrid.js';
|
|
12
12
|
export { ADOPTED_STUDIES, adoptable, isBandShape, outputMark, studyLevels, studyNeedsColumns, } from './studyCatalog.js';
|
|
13
13
|
export { DATA_TIME_ZONE, LOCAL_ZONE, TIME_ZONE_CHOICES, resolveTimeZone, timeZoneLabel, type TimeZoneChoice, } from './timeZone.js';
|
package/dist/index.js
CHANGED
|
@@ -2,13 +2,13 @@ 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, pinnedPrefix, isPinnableSymbol, underPrefix, readsPrefix, readsColumn, stripOtherSymbol, deriveId, deriveLineage, inputNames, substituteInput, hasPairOp, isBrokenId, isPairOp, isValidSpec, opHasPeriod, PERIOD_BOUNDS, readNumericColumn, partStudyLabel, readPart, readPairParts, specUnit, studyCatalog, TIDAL_OPS, BAND_OUTPUTS, opParams, isStudyOp, studyTag, opIsBand, opInputs, opIsMulti, opOutputs, primaryOutput, studyInputOf, studyPick, fanPick, withFanOutput, withStudyOutput, studyColumn, BAR_PRICE_COLUMNS, withStudyColumn, isPickedInput, opNeedsColumns, TARGET_ROLES, opSharesSourceAxis, usesCompare, DEFAULT_PERIOD, } from './derive.js';
|
|
5
|
+
export { applyDerived, applyDerivedReport, COMPARE_PREFIX, pinnedPrefix, isPinnableSymbol, underPrefix, readsPrefix, readsColumn, stripOtherSymbol, sourcePrefix, isSourceKey, parseOtherPrefix, otherPrefixOf, deriveId, deriveLineage, inputNames, substituteInput, hasPairOp, isBrokenId, isPairOp, isValidSpec, opHasPeriod, PERIOD_BOUNDS, readNumericColumn, partStudyLabel, readPart, readPairParts, specUnit, studyCatalog, TIDAL_OPS, BAND_OUTPUTS, opParams, isStudyOp, studyTag, opIsBand, opInputs, opIsMulti, opOutputs, primaryOutput, studyInputOf, studyPick, fanPick, withFanOutput, withStudyOutput, studyColumn, BAR_PRICE_COLUMNS, withStudyColumn, 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';
|
|
9
9
|
export { exactSessionSegments, inferBarMs, sessionOpenLine, sessionSegments, shiftKeys, sliceBySegments, } from './sessions.js';
|
|
10
10
|
export { monthlyExpirations, thirdFriday } from './expirations.js';
|
|
11
|
-
export { holdAcrossGrid, holdVolAcrossGrid } from './regrid.js';
|
|
11
|
+
export { holdAcrossGrid, holdVolAcrossGrid, lastInEachGrain } from './regrid.js';
|
|
12
12
|
// The corpus adoption (TDL-STUDYCAT). `ADOPTED_STUDIES` is exported so the
|
|
13
13
|
// count is assertable and a widening of `adoptable` is a visible edit.
|
|
14
14
|
export { ADOPTED_STUDIES, adoptable, isBandShape, outputMark, studyLevels, studyNeedsColumns, } from './studyCatalog.js';
|
package/dist/regrid.d.ts
CHANGED
|
@@ -58,6 +58,18 @@ export type HeldSchema<S extends SeriesSchema> = readonly [
|
|
|
58
58
|
* column, rather than dropping it.
|
|
59
59
|
*/
|
|
60
60
|
export declare function holdAcrossGrid<S extends SeriesSchema>(coarse: TimeSeries<S>, grid: ArrayLike<number>, grainMs: number): TimeSeries<HeldSchema<S>>;
|
|
61
|
+
/**
|
|
62
|
+
* The reverse of {@link holdAcrossGrid}: a **finer** series read at a coarse
|
|
63
|
+
* series' keys. For each key `K` in `keys`, the last row of `fine` in
|
|
64
|
+
* `[K, K + grainMs)`, keyed at `K`; a key with no such row is a gap. So a
|
|
65
|
+
* one-minute price series read on the daily vol rows gives each day its last
|
|
66
|
+
* minute, keyed where that day's vol row is, and a join on those keys pairs
|
|
67
|
+
* the two days exactly. Joining the minutes as they are would pair each day
|
|
68
|
+
* with the last minute BEFORE its key, which is the previous day's.
|
|
69
|
+
*
|
|
70
|
+
* `keys` must be ascending. Number and string columns only, like the hold.
|
|
71
|
+
*/
|
|
72
|
+
export declare function lastInEachGrain(fine: TimeSeries<SeriesSchema>, keys: ArrayLike<number>, grainMs: number): TimeSeries<SeriesSchema>;
|
|
61
73
|
/**
|
|
62
74
|
* Re-key `coarse` onto `times`, holding each source row across every target
|
|
63
75
|
* timestamp that falls on its day.
|
package/dist/regrid.js
CHANGED
|
@@ -135,6 +135,69 @@ export function holdAcrossGrid(coarse, grid, grainMs) {
|
|
|
135
135
|
columns: columns,
|
|
136
136
|
});
|
|
137
137
|
}
|
|
138
|
+
/**
|
|
139
|
+
* The reverse of {@link holdAcrossGrid}: a **finer** series read at a coarse
|
|
140
|
+
* series' keys. For each key `K` in `keys`, the last row of `fine` in
|
|
141
|
+
* `[K, K + grainMs)`, keyed at `K`; a key with no such row is a gap. So a
|
|
142
|
+
* one-minute price series read on the daily vol rows gives each day its last
|
|
143
|
+
* minute, keyed where that day's vol row is, and a join on those keys pairs
|
|
144
|
+
* the two days exactly. Joining the minutes as they are would pair each day
|
|
145
|
+
* with the last minute BEFORE its key, which is the previous day's.
|
|
146
|
+
*
|
|
147
|
+
* `keys` must be ascending. Number and string columns only, like the hold.
|
|
148
|
+
*/
|
|
149
|
+
export function lastInEachGrain(fine, keys, grainMs) {
|
|
150
|
+
const [keySpec, ...valueSpecs] = fine.schema;
|
|
151
|
+
if (keySpec.kind !== 'time')
|
|
152
|
+
throw new Error(`lastInEachGrain: "${fine.name}" is keyed by ${keySpec.kind}, not time`);
|
|
153
|
+
if (!(grainMs > 0))
|
|
154
|
+
throw new Error(`lastInEachGrain: grainMs must be a positive number of ms, not ${grainMs}`);
|
|
155
|
+
const fineKeys = fine.keyColumn().begin;
|
|
156
|
+
const n = fine.length;
|
|
157
|
+
const rows = new Int32Array(keys.length);
|
|
158
|
+
let j = -1;
|
|
159
|
+
let prev = -Infinity;
|
|
160
|
+
for (let i = 0; i < keys.length; i += 1) {
|
|
161
|
+
const k = keys[i];
|
|
162
|
+
if (!(k >= prev))
|
|
163
|
+
throw new Error(`lastInEachGrain: keys must be ascending; key ${i} (${k}) follows ${prev}`);
|
|
164
|
+
prev = k;
|
|
165
|
+
// The last fine row before the grain ends...
|
|
166
|
+
while (j + 1 < n && fineKeys[j + 1] < k + grainMs)
|
|
167
|
+
j += 1;
|
|
168
|
+
// ...and only if it falls in the grain.
|
|
169
|
+
rows[i] = j >= 0 && fineKeys[j] >= k ? j : -1;
|
|
170
|
+
}
|
|
171
|
+
const columns = {
|
|
172
|
+
[keySpec.name]: Float64Array.from(keys),
|
|
173
|
+
};
|
|
174
|
+
for (const spec of valueSpecs) {
|
|
175
|
+
const src = fine.column(spec.name);
|
|
176
|
+
if (spec.kind === 'number') {
|
|
177
|
+
const out = new Float64Array(keys.length);
|
|
178
|
+
for (let i = 0; i < keys.length; i += 1) {
|
|
179
|
+
const v = rows[i] < 0 ? undefined : src.at(rows[i]);
|
|
180
|
+
out[i] = typeof v === 'number' ? v : NaN;
|
|
181
|
+
}
|
|
182
|
+
columns[spec.name] = out;
|
|
183
|
+
}
|
|
184
|
+
else if (spec.kind === 'string') {
|
|
185
|
+
const out = new Array(keys.length);
|
|
186
|
+
for (let i = 0; i < keys.length; i += 1)
|
|
187
|
+
out[i] = rows[i] < 0 ? undefined : src.at(rows[i]);
|
|
188
|
+
columns[spec.name] = out;
|
|
189
|
+
}
|
|
190
|
+
else {
|
|
191
|
+
throw new Error(`lastInEachGrain: column "${spec.name}" of "${fine.name}" is ${spec.kind}; only number and string columns can be read`);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
const schema = [keySpec, ...valueSpecs.map((c) => ({ ...c, required: false }))];
|
|
195
|
+
return TimeSeries.fromColumns({
|
|
196
|
+
name: fine.name,
|
|
197
|
+
schema: schema,
|
|
198
|
+
columns: columns,
|
|
199
|
+
});
|
|
200
|
+
}
|
|
138
201
|
/**
|
|
139
202
|
* Re-key `coarse` onto `times`, holding each source row across every target
|
|
140
203
|
* timestamp that falls on its day.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tidal-ts/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.29.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",
|