ohlcv-indicators 3.4.0 → 3.4.1
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/index.js +6 -2
- package/package.json +1 -1
- package/src/studies/scaler.js +12 -22
package/index.js
CHANGED
|
@@ -378,7 +378,7 @@ export default class OHLCV_INDICATORS {
|
|
|
378
378
|
return this
|
|
379
379
|
}
|
|
380
380
|
|
|
381
|
-
scaler(size, colKeys, options)
|
|
381
|
+
scaler(size, colKeys = [], options = {})
|
|
382
382
|
{
|
|
383
383
|
const methodName = 'scaler'
|
|
384
384
|
|
|
@@ -393,7 +393,11 @@ export default class OHLCV_INDICATORS {
|
|
|
393
393
|
validateArrayOfRanges(range, 'options.range', methodName)
|
|
394
394
|
validateArrayOptions(['minmax', 'zscore'], type, 'options.type', methodName)
|
|
395
395
|
|
|
396
|
-
|
|
396
|
+
const groupKey = (group) ? `${type}_${size}_group_${colKeys.join('_')}` : ''
|
|
397
|
+
const groupKeyLen = colKeys.length
|
|
398
|
+
const precomputed = {groupKey, groupKeyLen}
|
|
399
|
+
|
|
400
|
+
this.inputParams.push({key: methodName, params: [size, colKeys, {type, group, range, lag, precomputed}]})
|
|
397
401
|
return this
|
|
398
402
|
}
|
|
399
403
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ohlcv-indicators",
|
|
3
|
-
"version": "3.4.
|
|
3
|
+
"version": "3.4.1",
|
|
4
4
|
"description": "A JavaScript library featuring optimized trading indicators for OHLCV arrays [{open, high, low, close, value}]. This library is optimized for backtesting and trading bot development.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
package/src/studies/scaler.js
CHANGED
|
@@ -9,30 +9,21 @@ const normalizeMinMax = (value, min, max, [validMin, validMax]) => {
|
|
|
9
9
|
return std === 0 ? 0 : (value - mean) / std;
|
|
10
10
|
};
|
|
11
11
|
|
|
12
|
-
export const scaler = (
|
|
13
|
-
|
|
14
|
-
index,
|
|
15
|
-
size,
|
|
16
|
-
colKeys,
|
|
17
|
-
type,
|
|
18
|
-
group,
|
|
19
|
-
range, // used for minmax: [validMin, validMax]
|
|
20
|
-
lag,
|
|
21
|
-
) => {
|
|
12
|
+
export const scaler = (main, index, size, colKeys, {type, group, range, lag, precomputed}) => {
|
|
13
|
+
const {groupKey, groupKeyLen} = precomputed
|
|
22
14
|
const { verticalOhlcv, instances, arrayTypes } = main;
|
|
23
15
|
const prefix = `${type}_${size}`;
|
|
24
|
-
let groupKey = '';
|
|
25
16
|
|
|
26
17
|
if (index === 0) {
|
|
27
|
-
const { len
|
|
28
|
-
groupKey = `${prefix}_group_${colKeys.join('_')}`;
|
|
29
|
-
|
|
30
|
-
instances.scaler = {
|
|
31
|
-
groupKeyLen: colKeys.length,
|
|
32
|
-
groupKey,
|
|
33
|
-
windows: {} // stores arrays of past values for each key or group
|
|
34
|
-
};
|
|
18
|
+
const { len } = main;
|
|
35
19
|
|
|
20
|
+
if(!instances.hasOwnProperty('scaler'))
|
|
21
|
+
{
|
|
22
|
+
instances.scaler = {
|
|
23
|
+
windows: {}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
36
27
|
for (const target of colKeys) {
|
|
37
28
|
if (!verticalOhlcv.hasOwnProperty(target)) {
|
|
38
29
|
throw new Error(`Target property "${target}" not found in verticalOhlcv`);
|
|
@@ -60,8 +51,7 @@ export const scaler = (
|
|
|
60
51
|
}
|
|
61
52
|
}
|
|
62
53
|
|
|
63
|
-
const { windows } = instances.scaler
|
|
64
|
-
groupKey = instances.scaler.groupKey;
|
|
54
|
+
const { windows } = instances.scaler
|
|
65
55
|
|
|
66
56
|
// update windows with current values
|
|
67
57
|
for (const target of colKeys) {
|
|
@@ -71,7 +61,7 @@ export const scaler = (
|
|
|
71
61
|
|
|
72
62
|
win.push(val);
|
|
73
63
|
|
|
74
|
-
if (win.length > (group ? size *
|
|
64
|
+
if (win.length > (group ? size * groupKeyLen : size)) {
|
|
75
65
|
win.shift();
|
|
76
66
|
}
|
|
77
67
|
|