oakscriptjs 0.9.5 → 0.10.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 +1 -1
- package/dist/cjs/array/index.d.ts +93 -50
- package/dist/cjs/array/index.d.ts.map +1 -1
- package/dist/cjs/array/index.js +239 -78
- package/dist/cjs/array/index.js.map +3 -3
- package/dist/cjs/callsite/index.d.ts +81 -2
- package/dist/cjs/callsite/index.d.ts.map +1 -1
- package/dist/cjs/callsite/index.js +62 -1
- package/dist/cjs/callsite/index.js.map +2 -2
- package/dist/cjs/color/index.d.ts +7 -3
- package/dist/cjs/color/index.d.ts.map +1 -1
- package/dist/cjs/color/index.js +6 -1
- package/dist/cjs/color/index.js.map +2 -2
- package/dist/cjs/drawing/bar-time.d.ts +24 -0
- package/dist/cjs/drawing/bar-time.d.ts.map +1 -0
- package/dist/cjs/drawing/bar-time.js +47 -0
- package/dist/cjs/drawing/bar-time.js.map +7 -0
- package/dist/cjs/drawing/output.d.ts +32 -0
- package/dist/cjs/drawing/output.d.ts.map +1 -0
- package/dist/cjs/drawing/output.js +184 -0
- package/dist/cjs/drawing/output.js.map +7 -0
- package/dist/cjs/drawing/registry.d.ts +5 -4
- package/dist/cjs/drawing/registry.d.ts.map +1 -1
- package/dist/cjs/drawing/registry.js +11 -2
- package/dist/cjs/drawing/registry.js.map +2 -2
- package/dist/cjs/index.d.ts +6 -3
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js +9 -2
- package/dist/cjs/index.js.map +2 -2
- package/dist/cjs/label/index.d.ts.map +1 -1
- package/dist/cjs/label/index.js +2 -1
- package/dist/cjs/label/index.js.map +2 -2
- package/dist/cjs/linefill/index.d.ts.map +1 -1
- package/dist/cjs/linefill/index.js +1 -0
- package/dist/cjs/linefill/index.js.map +2 -2
- package/dist/cjs/math/index.d.ts +76 -21
- package/dist/cjs/math/index.d.ts.map +1 -1
- package/dist/cjs/math/index.js +155 -41
- package/dist/cjs/math/index.js.map +3 -3
- package/dist/cjs/matrix/index.d.ts.map +1 -1
- package/dist/cjs/matrix/index.js +42 -36
- package/dist/cjs/matrix/index.js.map +2 -2
- package/dist/cjs/polyline/index.d.ts +3 -5
- package/dist/cjs/polyline/index.d.ts.map +1 -1
- package/dist/cjs/polyline/index.js +0 -5
- package/dist/cjs/polyline/index.js.map +2 -2
- package/dist/cjs/runtime/series.d.ts +9 -0
- package/dist/cjs/runtime/series.d.ts.map +1 -1
- package/dist/cjs/runtime/series.js +16 -2
- package/dist/cjs/runtime/series.js.map +2 -2
- package/dist/cjs/runtime/types.d.ts +22 -0
- package/dist/cjs/runtime/types.d.ts.map +1 -1
- package/dist/cjs/runtime/types.js.map +1 -1
- package/dist/cjs/script/index.d.ts +97 -36
- package/dist/cjs/script/index.d.ts.map +1 -1
- package/dist/cjs/script/index.js +173 -26
- package/dist/cjs/script/index.js.map +3 -3
- package/dist/cjs/session/calendar.d.ts.map +1 -1
- package/dist/cjs/session/calendar.js +15 -2
- package/dist/cjs/session/calendar.js.map +2 -2
- package/dist/cjs/str/index.d.ts +50 -38
- package/dist/cjs/str/index.d.ts.map +1 -1
- package/dist/cjs/str/index.js +43 -15
- package/dist/cjs/str/index.js.map +2 -2
- package/dist/cjs/str/messageformat.d.ts +2 -1
- package/dist/cjs/str/messageformat.d.ts.map +1 -1
- package/dist/cjs/str/messageformat.js +4 -1
- package/dist/cjs/str/messageformat.js.map +2 -2
- package/dist/cjs/str/numberformat.d.ts +4 -0
- package/dist/cjs/str/numberformat.d.ts.map +1 -1
- package/dist/cjs/str/numberformat.js +26 -4
- package/dist/cjs/str/numberformat.js.map +3 -3
- package/dist/cjs/ta/index.d.ts +86 -43
- package/dist/cjs/ta/index.d.ts.map +1 -1
- package/dist/cjs/ta/index.js +173 -267
- package/dist/cjs/ta/index.js.map +3 -3
- package/dist/cjs/ta/running-sum.d.ts +54 -2
- package/dist/cjs/ta/running-sum.d.ts.map +1 -1
- package/dist/cjs/ta/running-sum.js +132 -52
- package/dist/cjs/ta/running-sum.js.map +2 -2
- package/dist/cjs/ta-series.d.ts +4 -4
- package/dist/cjs/ta-series.d.ts.map +1 -1
- package/dist/cjs/ta-series.js +4 -3
- package/dist/cjs/ta-series.js.map +2 -2
- package/dist/cjs/table/index.d.ts +87 -0
- package/dist/cjs/table/index.d.ts.map +1 -0
- package/dist/cjs/table/index.js +150 -0
- package/dist/cjs/table/index.js.map +7 -0
- package/dist/cjs/text/index.d.ts +17 -2
- package/dist/cjs/text/index.d.ts.map +1 -1
- package/dist/cjs/text/index.js +15 -1
- package/dist/cjs/text/index.js.map +2 -2
- package/dist/cjs/time/datestring.d.ts +1 -0
- package/dist/cjs/time/datestring.d.ts.map +1 -1
- package/dist/cjs/time/datestring.js +7 -0
- package/dist/cjs/time/datestring.js.map +2 -2
- package/dist/cjs/time/index.d.ts.map +1 -1
- package/dist/cjs/time/index.js +2 -1
- package/dist/cjs/time/index.js.map +2 -2
- package/dist/cjs/time/session.d.ts +28 -9
- package/dist/cjs/time/session.d.ts.map +1 -1
- package/dist/cjs/time/session.js +74 -28
- package/dist/cjs/time/session.js.map +2 -2
- package/dist/cjs/time/timezone.d.ts +5 -0
- package/dist/cjs/time/timezone.d.ts.map +1 -1
- package/dist/cjs/time/timezone.js +15 -1
- package/dist/cjs/time/timezone.js.map +2 -2
- package/dist/cjs/types/index.d.ts +30 -1
- package/dist/cjs/types/index.d.ts.map +1 -1
- package/dist/cjs/types/index.js +12 -0
- package/dist/cjs/types/index.js.map +2 -2
- package/dist/cjs/types/metadata.d.ts +258 -26
- package/dist/cjs/types/metadata.d.ts.map +1 -1
- package/dist/cjs/types/metadata.js.map +1 -1
- package/dist/esm/array/index.d.ts +93 -50
- package/dist/esm/array/index.d.ts.map +1 -1
- package/dist/esm/array/index.js +383 -133
- package/dist/esm/array/index.js.map +1 -1
- package/dist/esm/callsite/index.d.ts +81 -2
- package/dist/esm/callsite/index.d.ts.map +1 -1
- package/dist/esm/callsite/index.js +145 -3
- package/dist/esm/callsite/index.js.map +1 -1
- package/dist/esm/color/index.d.ts +7 -3
- package/dist/esm/color/index.d.ts.map +1 -1
- package/dist/esm/color/index.js +15 -3
- package/dist/esm/color/index.js.map +1 -1
- package/dist/esm/drawing/bar-time.d.ts +24 -0
- package/dist/esm/drawing/bar-time.d.ts.map +1 -0
- package/dist/esm/drawing/bar-time.js +44 -0
- package/dist/esm/drawing/bar-time.js.map +1 -0
- package/dist/esm/drawing/output.d.ts +32 -0
- package/dist/esm/drawing/output.d.ts.map +1 -0
- package/dist/esm/drawing/output.js +190 -0
- package/dist/esm/drawing/output.js.map +1 -0
- package/dist/esm/drawing/registry.d.ts +5 -4
- package/dist/esm/drawing/registry.d.ts.map +1 -1
- package/dist/esm/drawing/registry.js +12 -2
- package/dist/esm/drawing/registry.js.map +1 -1
- package/dist/esm/index.d.ts +6 -3
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +7 -3
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/label/index.d.ts.map +1 -1
- package/dist/esm/label/index.js +2 -1
- package/dist/esm/label/index.js.map +1 -1
- package/dist/esm/linefill/index.d.ts.map +1 -1
- package/dist/esm/linefill/index.js +3 -0
- package/dist/esm/linefill/index.js.map +1 -1
- package/dist/esm/math/index.d.ts +76 -21
- package/dist/esm/math/index.d.ts.map +1 -1
- package/dist/esm/math/index.js +227 -61
- package/dist/esm/math/index.js.map +1 -1
- package/dist/esm/matrix/index.d.ts.map +1 -1
- package/dist/esm/matrix/index.js +57 -43
- package/dist/esm/matrix/index.js.map +1 -1
- package/dist/esm/polyline/index.d.ts +3 -5
- package/dist/esm/polyline/index.d.ts.map +1 -1
- package/dist/esm/polyline/index.js +3 -9
- package/dist/esm/polyline/index.js.map +1 -1
- package/dist/esm/runtime/series.d.ts +9 -0
- package/dist/esm/runtime/series.d.ts.map +1 -1
- package/dist/esm/runtime/series.js +18 -1
- package/dist/esm/runtime/series.js.map +1 -1
- package/dist/esm/runtime/types.d.ts +22 -0
- package/dist/esm/runtime/types.d.ts.map +1 -1
- package/dist/esm/script/index.d.ts +97 -36
- package/dist/esm/script/index.d.ts.map +1 -1
- package/dist/esm/script/index.js +211 -22
- package/dist/esm/script/index.js.map +1 -1
- package/dist/esm/session/calendar.d.ts.map +1 -1
- package/dist/esm/session/calendar.js +22 -2
- package/dist/esm/session/calendar.js.map +1 -1
- package/dist/esm/str/index.d.ts +50 -38
- package/dist/esm/str/index.d.ts.map +1 -1
- package/dist/esm/str/index.js +103 -52
- package/dist/esm/str/index.js.map +1 -1
- package/dist/esm/str/messageformat.d.ts +2 -1
- package/dist/esm/str/messageformat.d.ts.map +1 -1
- package/dist/esm/str/messageformat.js +7 -2
- package/dist/esm/str/messageformat.js.map +1 -1
- package/dist/esm/str/numberformat.d.ts +4 -0
- package/dist/esm/str/numberformat.d.ts.map +1 -1
- package/dist/esm/str/numberformat.js +38 -4
- package/dist/esm/str/numberformat.js.map +1 -1
- package/dist/esm/ta/index.d.ts +86 -43
- package/dist/esm/ta/index.d.ts.map +1 -1
- package/dist/esm/ta/index.js +296 -348
- package/dist/esm/ta/index.js.map +1 -1
- package/dist/esm/ta/running-sum.d.ts +54 -2
- package/dist/esm/ta/running-sum.d.ts.map +1 -1
- package/dist/esm/ta/running-sum.js +166 -71
- package/dist/esm/ta/running-sum.js.map +1 -1
- package/dist/esm/ta-series.d.ts +4 -4
- package/dist/esm/ta-series.d.ts.map +1 -1
- package/dist/esm/ta-series.js +5 -4
- package/dist/esm/ta-series.js.map +1 -1
- package/dist/esm/table/index.d.ts +87 -0
- package/dist/esm/table/index.d.ts.map +1 -0
- package/dist/esm/table/index.js +169 -0
- package/dist/esm/table/index.js.map +1 -0
- package/dist/esm/text/index.d.ts +17 -2
- package/dist/esm/text/index.d.ts.map +1 -1
- package/dist/esm/text/index.js +17 -2
- package/dist/esm/text/index.js.map +1 -1
- package/dist/esm/time/datestring.d.ts +1 -0
- package/dist/esm/time/datestring.d.ts.map +1 -1
- package/dist/esm/time/datestring.js +12 -0
- package/dist/esm/time/datestring.js.map +1 -1
- package/dist/esm/time/index.d.ts.map +1 -1
- package/dist/esm/time/index.js +3 -1
- package/dist/esm/time/index.js.map +1 -1
- package/dist/esm/time/session.d.ts +28 -9
- package/dist/esm/time/session.d.ts.map +1 -1
- package/dist/esm/time/session.js +113 -42
- package/dist/esm/time/session.js.map +1 -1
- package/dist/esm/time/timezone.d.ts +5 -0
- package/dist/esm/time/timezone.d.ts.map +1 -1
- package/dist/esm/time/timezone.js +21 -1
- package/dist/esm/time/timezone.js.map +1 -1
- package/dist/esm/types/index.d.ts +30 -1
- package/dist/esm/types/index.d.ts.map +1 -1
- package/dist/esm/types/index.js +14 -0
- package/dist/esm/types/index.js.map +1 -1
- package/dist/esm/types/metadata.d.ts +258 -26
- package/dist/esm/types/metadata.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/array/index.ts +364 -150
- package/src/callsite/index.ts +147 -3
- package/src/color/index.ts +15 -5
- package/src/drawing/bar-time.ts +42 -0
- package/src/drawing/output.ts +214 -0
- package/src/drawing/registry.ts +16 -6
- package/src/index.ts +9 -3
- package/src/label/index.ts +2 -1
- package/src/linefill/index.ts +2 -0
- package/src/math/index.ts +256 -74
- package/src/matrix/index.ts +52 -52
- package/src/polyline/index.ts +3 -12
- package/src/runtime/series.ts +22 -1
- package/src/runtime/types.ts +23 -0
- package/src/script/index.ts +307 -25
- package/src/session/calendar.ts +22 -2
- package/src/str/index.ts +95 -51
- package/src/str/messageformat.ts +7 -2
- package/src/str/numberformat.ts +39 -4
- package/src/ta/index.ts +306 -386
- package/src/ta/running-sum.ts +187 -74
- package/src/ta-series.ts +8 -7
- package/src/table/index.ts +221 -0
- package/src/text/index.ts +18 -2
- package/src/time/datestring.ts +10 -0
- package/src/time/index.ts +3 -1
- package/src/time/session.ts +97 -47
- package/src/time/timezone.ts +21 -1
- package/src/types/index.ts +32 -1
- package/src/types/metadata.ts +325 -26
|
@@ -6,14 +6,57 @@
|
|
|
6
6
|
* - each bar first removes, with a Kahan step, the compensated value that was added for the value that leaves the
|
|
7
7
|
* window, then adds the new value with a Kahan step and keeps its compensated value;
|
|
8
8
|
* - when the compensation of the previous step would be lost when applied to the new value, the sum is computed
|
|
9
|
-
* again from the window values (newest first) and the compensation is reset. The test
|
|
10
|
-
*
|
|
9
|
+
* again from the window values (newest first) and the compensation is reset. The test moves the new value toward
|
|
10
|
+
* +infinity by the size of the compensation, in floating point (#136, #142).
|
|
11
11
|
*
|
|
12
12
|
* So the result can differ from the exact window sum in the last bits (e.g. a small residue on a window of zeros),
|
|
13
13
|
* as in PineScript.
|
|
14
14
|
*
|
|
15
15
|
* @internal
|
|
16
16
|
*/
|
|
17
|
+
/** A value PineScript treats as na in window functions (also +/-Infinity). */
|
|
18
|
+
export declare function isNa(v: number | null | undefined): boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Running sum state, one value at a time. {@link step} computes the sum with a new value from the kept state without
|
|
21
|
+
* changing it; {@link commit} keeps the last step. So several candidate values can be tried on one bar and only the
|
|
22
|
+
* last one kept (a ta.* call in a loop).
|
|
23
|
+
*
|
|
24
|
+
* The length can change from one step to the next (a series length). PineScript then first moves the kept sum to the
|
|
25
|
+
* new length with Kahan steps of the raw values (not the stored compensated values): a smaller length removes the
|
|
26
|
+
* values that leave the window, oldest first; a larger length adds back the values from the one before the old window
|
|
27
|
+
* down to the one `length` values back, newest first (one more than the window needs). Then the usual step runs with
|
|
28
|
+
* the new length: it removes the stored value of the one `length` values back and adds the new value.
|
|
29
|
+
*/
|
|
30
|
+
export declare class RunningSum {
|
|
31
|
+
private readonly values;
|
|
32
|
+
private readonly stored;
|
|
33
|
+
private keptLength;
|
|
34
|
+
private s;
|
|
35
|
+
private c;
|
|
36
|
+
private stepLength;
|
|
37
|
+
private stepX;
|
|
38
|
+
private stepY;
|
|
39
|
+
private stepS;
|
|
40
|
+
private stepC;
|
|
41
|
+
/** Kahan steps that move the kept sum from the kept length to `len`; the result goes to stepS / stepC. */
|
|
42
|
+
private resize;
|
|
43
|
+
/**
|
|
44
|
+
* The running sum of the last `length` values with the (not na) value `x` added, from the kept state; the state is
|
|
45
|
+
* unchanged until {@link commit}.
|
|
46
|
+
*
|
|
47
|
+
* @returns The sum, or NaN while fewer than `length` values exist (with `x`)
|
|
48
|
+
*/
|
|
49
|
+
step(x: number, length: number): number;
|
|
50
|
+
/**
|
|
51
|
+
* The running sum of the last `length` values on a bar with an na value (no value added), from the kept state; the
|
|
52
|
+
* state is unchanged until {@link commit}. With an unchanged length, it is the previous result.
|
|
53
|
+
*
|
|
54
|
+
* @returns The sum, or NaN while fewer than `length` values exist
|
|
55
|
+
*/
|
|
56
|
+
stepNa(length: number): number;
|
|
57
|
+
/** Keeps the state of the last {@link step} or {@link stepNa}. */
|
|
58
|
+
commit(): void;
|
|
59
|
+
}
|
|
17
60
|
/**
|
|
18
61
|
* The sum of the last `length` non-na values on each bar, as PineScript computes it.
|
|
19
62
|
*
|
|
@@ -23,9 +66,18 @@
|
|
|
23
66
|
* previous result
|
|
24
67
|
*/
|
|
25
68
|
export declare function runningSum(source: ArrayLike<number | null | undefined>, length: number): number[];
|
|
69
|
+
/**
|
|
70
|
+
* The sum of the last `lengths[i]` non-na values on each bar `i` (a series length), as PineScript computes it (see
|
|
71
|
+
* {@link RunningSum}). A bar with an na value gives the sum of the last `lengths[i]` earlier values.
|
|
72
|
+
*
|
|
73
|
+
* @param name - Function name for the error messages
|
|
74
|
+
*/
|
|
75
|
+
export declare function runningSumSeries(source: ArrayLike<number | null | undefined>, lengths: ArrayLike<number>, name?: string): number[];
|
|
26
76
|
/**
|
|
27
77
|
* Window variance from the running sums of the values and of their squares, as PineScript computes it:
|
|
28
78
|
* biased `sumSq / n - mean * mean`, unbiased `sumSq / (n - 1) - mean * sum / (n - 1)`, with `mean = sum / n`.
|
|
29
79
|
*/
|
|
30
80
|
export declare function runningVariance(source: ArrayLike<number | null | undefined>, length: number, biased: boolean): number[];
|
|
81
|
+
/** {@link runningVariance} with a series length (the length of bar `i` is `lengths[i]`). */
|
|
82
|
+
export declare function runningVarianceSeries(source: ArrayLike<number | null | undefined>, lengths: ArrayLike<number>, biased: boolean, name?: string): number[];
|
|
31
83
|
//# sourceMappingURL=running-sum.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"running-sum.d.ts","sourceRoot":"","sources":["../../../src/ta/running-sum.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;
|
|
1
|
+
{"version":3,"file":"running-sum.d.ts","sourceRoot":"","sources":["../../../src/ta/running-sum.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAaH,8EAA8E;AAC9E,wBAAgB,IAAI,CAAC,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,OAAO,CAE1D;AAED;;;;;;;;;;GAUG;AACH,qBAAa,UAAU;IACrB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAgB;IACvC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAgB;IACvC,OAAO,CAAC,UAAU,CAAO;IACzB,OAAO,CAAC,CAAC,CAAK;IACd,OAAO,CAAC,CAAC,CAAK;IACd,OAAO,CAAC,UAAU,CAAO;IACzB,OAAO,CAAC,KAAK,CAAO;IACpB,OAAO,CAAC,KAAK,CAAO;IACpB,OAAO,CAAC,KAAK,CAAK;IAClB,OAAO,CAAC,KAAK,CAAK;IAElB,0GAA0G;IAC1G,OAAO,CAAC,MAAM;IAqBd;;;;;OAKG;IACH,IAAI,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM;IAkCvC;;;;;OAKG;IACH,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM;IAQ9B,kEAAkE;IAClE,MAAM,IAAI,IAAI;CASf;AAeD;;;;;;;GAOG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,SAAS,CAAC,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAIjG;AAcD;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAC9B,MAAM,EAAE,SAAS,CAAC,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC,EAC5C,OAAO,EAAE,SAAS,CAAC,MAAM,CAAC,EAC1B,IAAI,SAAa,GAChB,MAAM,EAAE,CAGV;AAuBD;;;GAGG;AACH,wBAAgB,eAAe,CAC7B,MAAM,EAAE,SAAS,CAAC,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC,EAC5C,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,OAAO,GACd,MAAM,EAAE,CAGV;AAED,4FAA4F;AAC5F,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,SAAS,CAAC,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC,EAC5C,OAAO,EAAE,SAAS,CAAC,MAAM,CAAC,EAC1B,MAAM,EAAE,OAAO,EACf,IAAI,SAAgB,GACnB,MAAM,EAAE,CAGV"}
|
|
@@ -18,87 +18,167 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
var running_sum_exports = {};
|
|
20
20
|
__export(running_sum_exports, {
|
|
21
|
+
RunningSum: () => RunningSum,
|
|
22
|
+
isNa: () => isNa,
|
|
21
23
|
runningSum: () => runningSum,
|
|
22
|
-
|
|
24
|
+
runningSumSeries: () => runningSumSeries,
|
|
25
|
+
runningVariance: () => runningVariance,
|
|
26
|
+
runningVarianceSeries: () => runningVarianceSeries
|
|
23
27
|
});
|
|
24
28
|
module.exports = __toCommonJS(running_sum_exports);
|
|
25
|
-
const view = new DataView(new ArrayBuffer(8));
|
|
26
|
-
function exponentOf(x) {
|
|
27
|
-
view.setFloat64(0, x);
|
|
28
|
-
const e = view.getUint16(0) >> 4 & 2047;
|
|
29
|
-
return e === 0 ? -1074 : e - 1023;
|
|
30
|
-
}
|
|
31
|
-
function spacingUp(x) {
|
|
32
|
-
const e = exponentOf(x);
|
|
33
|
-
const powerOfTwo = (view.getUint16(0) & 15) === 0 && view.getUint16(2) === 0 && view.getUint32(4) === 0;
|
|
34
|
-
return 2 ** (e - (x < 0 && powerOfTwo && e > -1022 ? 53 : 52));
|
|
35
|
-
}
|
|
36
29
|
function compensationLost(x, c) {
|
|
37
30
|
if (c === 0 || x === 0) return false;
|
|
38
|
-
const
|
|
39
|
-
|
|
40
|
-
const mantissa = x / ulp;
|
|
41
|
-
const f = Math.floor(q);
|
|
42
|
-
const d = q - f;
|
|
43
|
-
const applied = d > 0.5 ? f + 1 : d < 0.5 ? f : Math.abs(mantissa % 2) === Math.abs(f % 2) ? f : f + 1;
|
|
44
|
-
return Math.abs(applied) < Math.abs(q);
|
|
31
|
+
const size = Math.abs(c);
|
|
32
|
+
return Math.abs(x + size - x) < size;
|
|
45
33
|
}
|
|
46
34
|
function isNa(v) {
|
|
47
35
|
return v === void 0 || v === null || !Number.isFinite(v);
|
|
48
36
|
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
37
|
+
class RunningSum {
|
|
38
|
+
values = [];
|
|
39
|
+
stored = [];
|
|
40
|
+
keptLength = NaN;
|
|
41
|
+
s = 0;
|
|
42
|
+
c = 0;
|
|
43
|
+
stepLength = NaN;
|
|
44
|
+
stepX = NaN;
|
|
45
|
+
stepY = NaN;
|
|
46
|
+
stepS = 0;
|
|
47
|
+
stepC = 0;
|
|
48
|
+
/** Kahan steps that move the kept sum from the kept length to `len`; the result goes to stepS / stepC. */
|
|
49
|
+
resize(len) {
|
|
50
|
+
const values = this.values;
|
|
51
|
+
const n = values.length;
|
|
52
|
+
const kept = this.keptLength;
|
|
53
|
+
let s = this.s;
|
|
54
|
+
let c = this.c;
|
|
55
|
+
const add = (v) => {
|
|
56
|
+
const y = v - c;
|
|
57
|
+
const t = s + y;
|
|
58
|
+
c = t - s - y;
|
|
59
|
+
s = t;
|
|
60
|
+
};
|
|
61
|
+
if (len < kept) {
|
|
62
|
+
for (let k = Math.max(0, n - kept); k <= n - len - 1; k++) add(-values[k]);
|
|
63
|
+
} else if (len > kept) {
|
|
64
|
+
for (let k = n - kept - 1; k >= Math.max(0, n - len); k--) add(values[k]);
|
|
70
65
|
}
|
|
71
|
-
|
|
66
|
+
this.stepS = s;
|
|
67
|
+
this.stepC = c;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* The running sum of the last `length` values with the (not na) value `x` added, from the kept state; the state is
|
|
71
|
+
* unchanged until {@link commit}.
|
|
72
|
+
*
|
|
73
|
+
* @returns The sum, or NaN while fewer than `length` values exist (with `x`)
|
|
74
|
+
*/
|
|
75
|
+
step(x, length) {
|
|
76
|
+
const len = length;
|
|
77
|
+
const values = this.values;
|
|
78
|
+
this.resize(len);
|
|
79
|
+
let s = this.stepS;
|
|
80
|
+
let c = this.stepC;
|
|
72
81
|
const c0 = c;
|
|
73
82
|
const n = values.length;
|
|
74
|
-
if (n >= len)
|
|
75
|
-
|
|
83
|
+
if (n >= len) {
|
|
84
|
+
const y = -this.stored[n - len] - c;
|
|
85
|
+
const t = s + y;
|
|
86
|
+
c = t - s - y;
|
|
87
|
+
s = t;
|
|
88
|
+
}
|
|
76
89
|
if (compensationLost(x, c0)) {
|
|
77
|
-
let fresh =
|
|
78
|
-
for (let k =
|
|
90
|
+
let fresh = x;
|
|
91
|
+
for (let k = n - 1; k >= Math.max(0, n + 1 - len); k--) fresh += values[k];
|
|
79
92
|
s = fresh;
|
|
80
93
|
c = 0;
|
|
81
|
-
|
|
94
|
+
this.stepY = x;
|
|
82
95
|
} else {
|
|
83
|
-
|
|
96
|
+
const y = x - c;
|
|
97
|
+
const t = s + y;
|
|
98
|
+
c = t - s - y;
|
|
99
|
+
s = t;
|
|
100
|
+
this.stepY = y;
|
|
84
101
|
}
|
|
85
|
-
|
|
86
|
-
|
|
102
|
+
this.stepLength = len;
|
|
103
|
+
this.stepX = x;
|
|
104
|
+
this.stepS = s;
|
|
105
|
+
this.stepC = c;
|
|
106
|
+
return n + 1 >= len ? s : NaN;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* The running sum of the last `length` values on a bar with an na value (no value added), from the kept state; the
|
|
110
|
+
* state is unchanged until {@link commit}. With an unchanged length, it is the previous result.
|
|
111
|
+
*
|
|
112
|
+
* @returns The sum, or NaN while fewer than `length` values exist
|
|
113
|
+
*/
|
|
114
|
+
stepNa(length) {
|
|
115
|
+
this.resize(length);
|
|
116
|
+
this.stepLength = length;
|
|
117
|
+
this.stepX = NaN;
|
|
118
|
+
const n = this.values.length;
|
|
119
|
+
return n > 0 && n >= length ? this.stepS : NaN;
|
|
120
|
+
}
|
|
121
|
+
/** Keeps the state of the last {@link step} or {@link stepNa}. */
|
|
122
|
+
commit() {
|
|
123
|
+
if (!Number.isNaN(this.stepX)) {
|
|
124
|
+
this.values.push(this.stepX);
|
|
125
|
+
this.stored.push(this.stepY);
|
|
126
|
+
}
|
|
127
|
+
this.keptLength = this.stepLength;
|
|
128
|
+
this.s = this.stepS;
|
|
129
|
+
this.c = this.stepC;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
function sumWindows(source, lengthAt) {
|
|
133
|
+
const out = new Array(source.length);
|
|
134
|
+
const sum = new RunningSum();
|
|
135
|
+
for (let i = 0; i < source.length; i++) {
|
|
136
|
+
const v = source[i];
|
|
137
|
+
const len = lengthAt(i);
|
|
138
|
+
out[i] = isNa(v) ? sum.stepNa(len) : sum.step(v, len);
|
|
139
|
+
sum.commit();
|
|
87
140
|
}
|
|
88
141
|
return out;
|
|
89
142
|
}
|
|
90
|
-
function
|
|
143
|
+
function runningSum(source, length) {
|
|
91
144
|
const len = Math.floor(length);
|
|
145
|
+
if (!(len >= 1)) return new Array(source.length).fill(NaN);
|
|
146
|
+
return sumWindows(source, () => len);
|
|
147
|
+
}
|
|
148
|
+
function seriesLengths(lengths, count, name) {
|
|
149
|
+
if (lengths.length < count) {
|
|
150
|
+
throw new Error(`${name}: the length series has ${lengths.length} values for ${count} bars`);
|
|
151
|
+
}
|
|
152
|
+
return Array.from({ length: count }, (_, i) => {
|
|
153
|
+
const len = Math.floor(lengths[i]);
|
|
154
|
+
if (!(len >= 1)) throw new Error(`${name}: length must be at least 1 (bar ${i}: ${lengths[i]})`);
|
|
155
|
+
return len;
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
function runningSumSeries(source, lengths, name = "math.sum") {
|
|
159
|
+
const lens = seriesLengths(lengths, source.length, name);
|
|
160
|
+
return sumWindows(source, (i) => lens[i]);
|
|
161
|
+
}
|
|
162
|
+
function varianceFromSums(source, sumOf, lengthAt, biased) {
|
|
92
163
|
const squares = Array.from({ length: source.length }, (_, i) => {
|
|
93
164
|
const v = source[i];
|
|
94
165
|
return isNa(v) ? NaN : v * v;
|
|
95
166
|
});
|
|
96
|
-
const sums =
|
|
97
|
-
const sumSquares =
|
|
167
|
+
const sums = sumOf(source);
|
|
168
|
+
const sumSquares = sumOf(squares);
|
|
98
169
|
return sums.map((sum, i) => {
|
|
170
|
+
const len = lengthAt(i);
|
|
99
171
|
const mean = sum / len;
|
|
100
172
|
const sq = sumSquares[i];
|
|
101
173
|
return biased ? sq / len - mean * mean : sq / (len - 1) - mean * sum / (len - 1);
|
|
102
174
|
});
|
|
103
175
|
}
|
|
176
|
+
function runningVariance(source, length, biased) {
|
|
177
|
+
const len = Math.floor(length);
|
|
178
|
+
return varianceFromSums(source, (src) => runningSum(src, len), () => len, biased);
|
|
179
|
+
}
|
|
180
|
+
function runningVarianceSeries(source, lengths, biased, name = "ta.variance") {
|
|
181
|
+
const lens = seriesLengths(lengths, source.length, name);
|
|
182
|
+
return varianceFromSums(source, (src) => sumWindows(src, (i) => lens[i]), (i) => lens[i], biased);
|
|
183
|
+
}
|
|
104
184
|
//# sourceMappingURL=running-sum.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/ta/running-sum.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * Running window sum with the floating-point behaviour of PineScript `math.sum` / `ta.sma` / `ta.stdev` /\n * `ta.variance` (bit for bit).\n *\n * PineScript does not sum the window again on each bar. It keeps a compensated (Kahan) running sum:\n * - each bar first removes, with a Kahan step, the compensated value that was added for the value that leaves the\n * window, then adds the new value with a Kahan step and keeps its compensated value;\n * - when the compensation of the previous step would be lost when applied to the new value, the sum is computed\n * again from the window values (newest first) and the compensation is reset. The test
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;
|
|
4
|
+
"sourcesContent": ["/**\n * Running window sum with the floating-point behaviour of PineScript `math.sum` / `ta.sma` / `ta.stdev` /\n * `ta.variance` (bit for bit).\n *\n * PineScript does not sum the window again on each bar. It keeps a compensated (Kahan) running sum:\n * - each bar first removes, with a Kahan step, the compensated value that was added for the value that leaves the\n * window, then adds the new value with a Kahan step and keeps its compensated value;\n * - when the compensation of the previous step would be lost when applied to the new value, the sum is computed\n * again from the window values (newest first) and the compensation is reset. The test moves the new value toward\n * +infinity by the size of the compensation, in floating point (#136, #142).\n *\n * So the result can differ from the exact window sum in the last bits (e.g. a small residue on a window of zeros),\n * as in PineScript.\n *\n * @internal\n */\n\n/**\n * Whether the compensation `c` is (partly) lost when it is applied to `x`: `x + |c|` in floating point moves `x` by\n * less than `|c|`. Moving toward +infinity uses the grid above `x` (the coarser binade just below a power of two, the\n * finer binade for a negative power of two), as PineScript (measured bit for bit, #142).\n */\nfunction compensationLost(x: number, c: number): boolean {\n if (c === 0 || x === 0) return false;\n const size = Math.abs(c);\n return Math.abs(x + size - x) < size;\n}\n\n/** A value PineScript treats as na in window functions (also +/-Infinity). */\nexport function isNa(v: number | null | undefined): boolean {\n return v === undefined || v === null || !Number.isFinite(v);\n}\n\n/**\n * Running sum state, one value at a time. {@link step} computes the sum with a new value from the kept state without\n * changing it; {@link commit} keeps the last step. So several candidate values can be tried on one bar and only the\n * last one kept (a ta.* call in a loop).\n *\n * The length can change from one step to the next (a series length). PineScript then first moves the kept sum to the\n * new length with Kahan steps of the raw values (not the stored compensated values): a smaller length removes the\n * values that leave the window, oldest first; a larger length adds back the values from the one before the old window\n * down to the one `length` values back, newest first (one more than the window needs). Then the usual step runs with\n * the new length: it removes the stored value of the one `length` values back and adds the new value.\n */\nexport class RunningSum {\n private readonly values: number[] = [];\n private readonly stored: number[] = [];\n private keptLength = NaN;\n private s = 0;\n private c = 0;\n private stepLength = NaN;\n private stepX = NaN;\n private stepY = NaN;\n private stepS = 0;\n private stepC = 0;\n\n /** Kahan steps that move the kept sum from the kept length to `len`; the result goes to stepS / stepC. */\n private resize(len: number): void {\n const values = this.values;\n const n = values.length;\n const kept = this.keptLength;\n let s = this.s;\n let c = this.c;\n const add = (v: number) => {\n const y = v - c;\n const t = s + y;\n c = (t - s) - y;\n s = t;\n };\n if (len < kept) {\n for (let k = Math.max(0, n - kept); k <= n - len - 1; k++) add(-values[k]!);\n } else if (len > kept) {\n for (let k = n - kept - 1; k >= Math.max(0, n - len); k--) add(values[k]!);\n }\n this.stepS = s;\n this.stepC = c;\n }\n\n /**\n * The running sum of the last `length` values with the (not na) value `x` added, from the kept state; the state is\n * unchanged until {@link commit}.\n *\n * @returns The sum, or NaN while fewer than `length` values exist (with `x`)\n */\n step(x: number, length: number): number {\n const len = length;\n const values = this.values;\n this.resize(len);\n let s = this.stepS;\n let c = this.stepC;\n const c0 = c;\n const n = values.length;\n if (n >= len) {\n const y = -this.stored[n - len]! - c;\n const t = s + y;\n c = (t - s) - y;\n s = t;\n }\n if (compensationLost(x, c0)) {\n let fresh = x;\n for (let k = n - 1; k >= Math.max(0, n + 1 - len); k--) fresh += values[k]!;\n s = fresh;\n c = 0;\n this.stepY = x;\n } else {\n const y = x - c;\n const t = s + y;\n c = (t - s) - y;\n s = t;\n this.stepY = y;\n }\n this.stepLength = len;\n this.stepX = x;\n this.stepS = s;\n this.stepC = c;\n return n + 1 >= len ? s : NaN;\n }\n\n /**\n * The running sum of the last `length` values on a bar with an na value (no value added), from the kept state; the\n * state is unchanged until {@link commit}. With an unchanged length, it is the previous result.\n *\n * @returns The sum, or NaN while fewer than `length` values exist\n */\n stepNa(length: number): number {\n this.resize(length);\n this.stepLength = length;\n this.stepX = NaN;\n const n = this.values.length;\n return n > 0 && n >= length ? this.stepS : NaN;\n }\n\n /** Keeps the state of the last {@link step} or {@link stepNa}. */\n commit(): void {\n if (!Number.isNaN(this.stepX)) {\n this.values.push(this.stepX);\n this.stored.push(this.stepY);\n }\n this.keptLength = this.stepLength;\n this.s = this.stepS;\n this.c = this.stepC;\n }\n}\n\n/** The running sums of `source` with the length `lengthAt(i)` on bar `i`. */\nfunction sumWindows(source: ArrayLike<number | null | undefined>, lengthAt: (i: number) => number): number[] {\n const out: number[] = new Array<number>(source.length);\n const sum = new RunningSum();\n for (let i = 0; i < source.length; i++) {\n const v = source[i];\n const len = lengthAt(i);\n out[i] = isNa(v) ? sum.stepNa(len) : sum.step(v as number, len);\n sum.commit();\n }\n return out;\n}\n\n/**\n * The sum of the last `length` non-na values on each bar, as PineScript computes it.\n *\n * @param source - Values (na: NaN, null, undefined or +/-Infinity, skipped)\n * @param length - Number of non-na values in the window\n * @returns The running sum per bar: NaN until `length` non-na values exist; a bar with an na value keeps the\n * previous result\n */\nexport function runningSum(source: ArrayLike<number | null | undefined>, length: number): number[] {\n const len = Math.floor(length);\n if (!(len >= 1)) return new Array<number>(source.length).fill(NaN);\n return sumWindows(source, () => len);\n}\n\n/** The values of a series length, floored, checked to be at least 1 on every bar. */\nfunction seriesLengths(lengths: ArrayLike<number>, count: number, name: string): number[] {\n if (lengths.length < count) {\n throw new Error(`${name}: the length series has ${lengths.length} values for ${count} bars`);\n }\n return Array.from({ length: count }, (_, i) => {\n const len = Math.floor(lengths[i]!);\n if (!(len >= 1)) throw new Error(`${name}: length must be at least 1 (bar ${i}: ${lengths[i]})`);\n return len;\n });\n}\n\n/**\n * The sum of the last `lengths[i]` non-na values on each bar `i` (a series length), as PineScript computes it (see\n * {@link RunningSum}). A bar with an na value gives the sum of the last `lengths[i]` earlier values.\n *\n * @param name - Function name for the error messages\n */\nexport function runningSumSeries(\n source: ArrayLike<number | null | undefined>,\n lengths: ArrayLike<number>,\n name = 'math.sum'\n): number[] {\n const lens = seriesLengths(lengths, source.length, name);\n return sumWindows(source, (i) => lens[i]!);\n}\n\n/** Variance from the running sums of the values and of their squares; rules in {@link runningVariance}. */\nfunction varianceFromSums(\n source: ArrayLike<number | null | undefined>,\n sumOf: (src: ArrayLike<number | null | undefined>) => number[],\n lengthAt: (i: number) => number,\n biased: boolean\n): number[] {\n const squares = Array.from({ length: source.length }, (_, i) => {\n const v = source[i];\n return isNa(v) ? NaN : (v as number) * (v as number);\n });\n const sums = sumOf(source);\n const sumSquares = sumOf(squares);\n return sums.map((sum, i) => {\n const len = lengthAt(i);\n const mean = sum / len;\n const sq = sumSquares[i]!;\n return biased ? sq / len - mean * mean : sq / (len - 1) - (mean * sum) / (len - 1);\n });\n}\n\n/**\n * Window variance from the running sums of the values and of their squares, as PineScript computes it:\n * biased `sumSq / n - mean * mean`, unbiased `sumSq / (n - 1) - mean * sum / (n - 1)`, with `mean = sum / n`.\n */\nexport function runningVariance(\n source: ArrayLike<number | null | undefined>,\n length: number,\n biased: boolean\n): number[] {\n const len = Math.floor(length);\n return varianceFromSums(source, (src) => runningSum(src, len), () => len, biased);\n}\n\n/** {@link runningVariance} with a series length (the length of bar `i` is `lengths[i]`). */\nexport function runningVarianceSeries(\n source: ArrayLike<number | null | undefined>,\n lengths: ArrayLike<number>,\n biased: boolean,\n name = 'ta.variance'\n): number[] {\n const lens = seriesLengths(lengths, source.length, name);\n return varianceFromSums(source, (src) => sumWindows(src, (i) => lens[i]!), (i) => lens[i]!, biased);\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAsBA,SAAS,iBAAiB,GAAW,GAAoB;AACvD,MAAI,MAAM,KAAK,MAAM,EAAG,QAAO;AAC/B,QAAM,OAAO,KAAK,IAAI,CAAC;AACvB,SAAO,KAAK,IAAI,IAAI,OAAO,CAAC,IAAI;AAClC;AAGO,SAAS,KAAK,GAAuC;AAC1D,SAAO,MAAM,UAAa,MAAM,QAAQ,CAAC,OAAO,SAAS,CAAC;AAC5D;AAaO,MAAM,WAAW;AAAA,EACL,SAAmB,CAAC;AAAA,EACpB,SAAmB,CAAC;AAAA,EAC7B,aAAa;AAAA,EACb,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,aAAa;AAAA,EACb,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,QAAQ;AAAA;AAAA,EAGR,OAAO,KAAmB;AAChC,UAAM,SAAS,KAAK;AACpB,UAAM,IAAI,OAAO;AACjB,UAAM,OAAO,KAAK;AAClB,QAAI,IAAI,KAAK;AACb,QAAI,IAAI,KAAK;AACb,UAAM,MAAM,CAAC,MAAc;AACzB,YAAM,IAAI,IAAI;AACd,YAAM,IAAI,IAAI;AACd,UAAK,IAAI,IAAK;AACd,UAAI;AAAA,IACN;AACA,QAAI,MAAM,MAAM;AACd,eAAS,IAAI,KAAK,IAAI,GAAG,IAAI,IAAI,GAAG,KAAK,IAAI,MAAM,GAAG,IAAK,KAAI,CAAC,OAAO,CAAC,CAAE;AAAA,IAC5E,WAAW,MAAM,MAAM;AACrB,eAAS,IAAI,IAAI,OAAO,GAAG,KAAK,KAAK,IAAI,GAAG,IAAI,GAAG,GAAG,IAAK,KAAI,OA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AAGA,SAAS,iBACP,QACA,OACA,UACA,QACU;AACV,QAAM,UAAU,MAAM,KAAK,EAAE,QAAQ,OAAO,OAAO,GAAG,CAAC,GAAG,MAAM;AAC9D,UAAM,IAAI,OAAO,CAAC;AAClB,WAAO,KAAK,CAAC,IAAI,MAAO,IAAgB;AAAA,EAC1C,CAAC;AACD,QAAM,OAAO,MAAM,MAAM;AACzB,QAAM,aAAa,MAAM,OAAO;AAChC,SAAO,KAAK,IAAI,CAAC,KAAK,MAAM;AAC1B,UAAM,MAAM,SAAS,CAAC;AACtB,UAAM,OAAO,MAAM;AACnB,UAAM,KAAK,WAAW,CAAC;AACvB,WAAO,SAAS,KAAK,MAAM,OAAO,OAAO,MAAM,MAAM,KAAM,OAAO,OAAQ,MAAM;AAAA,EAClF,CAAC;AACH;AAMO,SAAS,gBACd,QACA,QACA,QACU;AACV,QAAM,MAAM,KAAK,MAAM,MAAM;AAC7B,SAAO,iBAAiB,QAAQ,CAAC,QAAQ,WAAW,KAAK,GAAG,GAAG,MAAM,KAAK,MAAM;AAClF;AAGO,SAAS,sBACd,QACA,SACA,QACA,OAAO,eACG;AACV,QAAM,OAAO,cAAc,SAAS,OAAO,QAAQ,IAAI;AACvD,SAAO,iBAAiB,QAAQ,CAAC,QAAQ,WAAW,KAAK,CAAC,MAAM,KAAK,CAAC,CAAE,GAAG,CAAC,MAAM,KAAK,CAAC,GAAI,MAAM;AACpG;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/cjs/ta-series.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ import type { Bar } from './types/index.js';
|
|
|
11
11
|
* @param length - Period length
|
|
12
12
|
* @returns Series with SMA values
|
|
13
13
|
*/
|
|
14
|
-
export declare function sma(source: Series, length: number): Series;
|
|
14
|
+
export declare function sma(source: Series, length: number | Series): Series;
|
|
15
15
|
/**
|
|
16
16
|
* Exponential Moving Average
|
|
17
17
|
* @param source - Source series
|
|
@@ -64,7 +64,7 @@ export declare function bb(source: Series, length: number, mult: number): [Serie
|
|
|
64
64
|
* @param biased - true (default): divide by length; false: by length - 1
|
|
65
65
|
* @returns Series with standard deviation values
|
|
66
66
|
*/
|
|
67
|
-
export declare function stdev(source: Series, length: number, biased?: boolean): Series;
|
|
67
|
+
export declare function stdev(source: Series, length: number | Series, biased?: boolean): Series;
|
|
68
68
|
/**
|
|
69
69
|
* Average True Range
|
|
70
70
|
* @param bars - Bar data
|
|
@@ -280,7 +280,7 @@ export declare function dev(source: Series, length: number): Series;
|
|
|
280
280
|
* @param biased - Use biased estimation (default: true)
|
|
281
281
|
* @returns Series with variance values
|
|
282
282
|
*/
|
|
283
|
-
export declare function variance(source: Series, length: number, biased?: boolean): Series;
|
|
283
|
+
export declare function variance(source: Series, length: number | Series, biased?: boolean): Series;
|
|
284
284
|
/**
|
|
285
285
|
* Median
|
|
286
286
|
* @param source - Source series
|
|
@@ -369,7 +369,7 @@ export declare function dmi(bars: Bar[], diLength: number, adxSmoothing: number)
|
|
|
369
369
|
* @param source - Source series
|
|
370
370
|
* @param shortLength - Short smoothing period
|
|
371
371
|
* @param longLength - Long smoothing period
|
|
372
|
-
* @returns Series with TSI values
|
|
372
|
+
* @returns Series with TSI values, in [-1, 1] as PineScript
|
|
373
373
|
*/
|
|
374
374
|
export declare function tsi(source: Series, shortLength: number, longLength: number): Series;
|
|
375
375
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ta-series.d.ts","sourceRoot":"","sources":["../../src/ta-series.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC7C,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAC;AAE5C;;;;;GAKG;AACH,wBAAgB,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,
|
|
1
|
+
{"version":3,"file":"ta-series.d.ts","sourceRoot":"","sources":["../../src/ta-series.ts"],"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,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAG5D;AAGL;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAIlE;AAED;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAIjE;AAEG;;;;GAIG;AACH,wBAAgB,GAAG,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAG1C;AAGD;;;;GAIG;AACH,wBAAgB,GAAG,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAG1C;AAGL;;;;;GAKG;AACH,wBAAgB,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,GAAE,MAAW,GAAG,MAAM,CAI/D;AAED;;;;;GAKG;AACH,wBAAgB,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAI3D;AAED;;;;;;GAMG;AACH,wBAAgB,+BAA+B,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM,CAI1G;AAED;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM,CAIlG;AAED;;;;;GAKG;AACH,wBAAgB,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAI1D;AAGD,eAAO,MAAM,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAsEd,CAAC"}
|
package/dist/cjs/ta-series.js
CHANGED
|
@@ -105,7 +105,7 @@ var import_series = require("./runtime/series.js");
|
|
|
105
105
|
function sma(source, length) {
|
|
106
106
|
const bars = source.bars;
|
|
107
107
|
const sourceValues = source.toArray();
|
|
108
|
-
const result = taCore.sma(sourceValues, length);
|
|
108
|
+
const result = taCore.sma(sourceValues, length instanceof import_series.Series ? length.toArray() : length);
|
|
109
109
|
return import_series.Series.fromArray(bars, result);
|
|
110
110
|
}
|
|
111
111
|
function ema(source, length) {
|
|
@@ -152,7 +152,8 @@ function bb(source, length, mult) {
|
|
|
152
152
|
}
|
|
153
153
|
function stdev(source, length, biased = true) {
|
|
154
154
|
const bars = source.bars;
|
|
155
|
-
|
|
155
|
+
const len = length instanceof import_series.Series ? length.toArray() : length;
|
|
156
|
+
return import_series.Series.fromArray(bars, taCore.stdev(source.toArray(), len, biased));
|
|
156
157
|
}
|
|
157
158
|
function atr(bars, length) {
|
|
158
159
|
const high = bars.map((b) => b.high);
|
|
@@ -379,7 +380,7 @@ function dev(source, length) {
|
|
|
379
380
|
}
|
|
380
381
|
function variance(source, length, biased = true) {
|
|
381
382
|
const bars = source.bars;
|
|
382
|
-
const result = taCore.variance(source.toArray(), length, biased);
|
|
383
|
+
const result = taCore.variance(source.toArray(), length instanceof import_series.Series ? length.toArray() : length, biased);
|
|
383
384
|
return import_series.Series.fromArray(bars, result);
|
|
384
385
|
}
|
|
385
386
|
function median(source, length) {
|