ohlcv-indicators 3.4.3 → 3.4.5
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 +4 -2
- package/package.json +1 -1
- package/src/core-functions/mainLoop.js +41 -35
package/index.js
CHANGED
|
@@ -30,13 +30,16 @@ import { precomputeMovingAverages } from './src/moving-averages/movingAverages.j
|
|
|
30
30
|
*/
|
|
31
31
|
|
|
32
32
|
export default class OHLCV_INDICATORS {
|
|
33
|
-
constructor({input, ticker = null, precision = true, inputParams = null}) {
|
|
33
|
+
constructor({input, ticker = null, precision = true, inputParams = null, chunkProcess = 2000}) {
|
|
34
34
|
|
|
35
35
|
validateArray(input, 'input', (ticker !== null) ? `contructor ${ticker}` : 'constuctor')
|
|
36
36
|
if(input.length === 0) throw Error('input OHLCV must not be empty: ' + ticker)
|
|
37
37
|
|
|
38
38
|
validateBoolean(precision, 'precision', 'constructor')
|
|
39
|
+
validateNumber(chunkProcess, {min: 100, max: 50000, allowDecimals: false}, 'chunkProcess', 'constructor')
|
|
39
40
|
|
|
41
|
+
|
|
42
|
+
this.chunkProcess = chunkProcess
|
|
40
43
|
this.firstRow = input[0]
|
|
41
44
|
|
|
42
45
|
const {inputTypes, arrayTypes} = assignTypes(this.firstRow)
|
|
@@ -168,7 +171,6 @@ export default class OHLCV_INDICATORS {
|
|
|
168
171
|
|
|
169
172
|
crossPairs(arr = [])
|
|
170
173
|
{
|
|
171
|
-
|
|
172
174
|
const methodName = 'crossPairs'
|
|
173
175
|
|
|
174
176
|
isAlreadyComputed(this)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ohlcv-indicators",
|
|
3
|
-
"version": "3.4.
|
|
3
|
+
"version": "3.4.5",
|
|
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",
|
|
@@ -31,7 +31,7 @@ const indicatorFunctions = {
|
|
|
31
31
|
|
|
32
32
|
|
|
33
33
|
export const mainLoop = (input, main) => {
|
|
34
|
-
const { len, inputParams, priceBased, precisionMultiplier, arrayTypes, verticalOhlcv, verticalOhlcvKeyNames, inputTypes } = main;
|
|
34
|
+
const { len, inputParams, priceBased, precisionMultiplier, arrayTypes, verticalOhlcv, verticalOhlcvKeyNames, inputTypes, chunkProcess } = main;
|
|
35
35
|
|
|
36
36
|
validateInputParams(inputParams, len)
|
|
37
37
|
|
|
@@ -41,45 +41,51 @@ export const mainLoop = (input, main) => {
|
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
// Process each row in the input
|
|
44
|
-
for (let
|
|
45
|
-
const curr = input[index]
|
|
46
|
-
|
|
47
|
-
for(const [key, formaterKey] of Object.entries(inputTypes))
|
|
48
|
-
{
|
|
49
|
-
const value = curr[key]
|
|
44
|
+
for (let chunkStart = 0; chunkStart < len; chunkStart += chunkProcess) {
|
|
50
45
|
|
|
51
|
-
|
|
52
|
-
{
|
|
53
|
-
let formatedValue = numberFormater[formaterKey](value)
|
|
46
|
+
const chunkEnd = Math.min(chunkStart + chunkProcess, len);
|
|
54
47
|
|
|
55
|
-
|
|
48
|
+
for (let index = chunkStart; index < chunkEnd; index++) {
|
|
49
|
+
const curr = input[index]
|
|
50
|
+
|
|
51
|
+
for(const [key, formaterKey] of Object.entries(inputTypes))
|
|
56
52
|
{
|
|
57
|
-
|
|
58
|
-
}
|
|
53
|
+
const value = curr[key]
|
|
59
54
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
55
|
+
if(numberFormater.hasOwnProperty(formaterKey))
|
|
56
|
+
{
|
|
57
|
+
let formatedValue = numberFormater[formaterKey](value)
|
|
58
|
+
|
|
59
|
+
if(precisionMultiplier > 1 && priceBased.has(key))
|
|
60
|
+
{
|
|
61
|
+
formatedValue = formatedValue * precisionMultiplier
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
main.pushToMain({index, key, value: formatedValue})
|
|
65
|
+
}
|
|
66
|
+
else if(dateFormaters.hasOwnProperty(formaterKey))
|
|
67
|
+
{
|
|
68
|
+
main.pushToMain({index, key, value: dateFormaters[formaterKey](value)})
|
|
69
|
+
}
|
|
70
|
+
else
|
|
71
|
+
{
|
|
72
|
+
main.pushToMain({index, key, value})
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// Run all indicator functions except for the ones processed later
|
|
77
|
+
for (const { key, params } of inputParams) {
|
|
78
|
+
if (key === 'lag' || key === 'crossPairs') continue;
|
|
79
|
+
// resolve fn on-demand, no per-item object allocation here
|
|
80
|
+
indicatorFunctions[key](main, index, ...params)
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// Process these indicators separately (ensuring their execution order)
|
|
84
|
+
lag(main, index)
|
|
85
|
+
crossPairs(main, index)
|
|
86
|
+
input[index] = null //flusing data
|
|
77
87
|
}
|
|
78
|
-
|
|
79
|
-
// Process these indicators separately (ensuring their execution order)
|
|
80
|
-
lag(main, index)
|
|
81
|
-
crossPairs(main, index)
|
|
82
88
|
}
|
|
83
89
|
|
|
84
90
|
verticalOhlcvKeyNames.push(...Object.keys(verticalOhlcv))
|
|
85
|
-
}
|
|
91
|
+
}
|