@thi.ng/transducers-stats 2.1.81 → 2.1.82
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/CHANGELOG.md +1 -1
- package/bollinger.js +21 -14
- package/bounds.js +12 -14
- package/donchian.js +5 -4
- package/dot.js +9 -13
- package/ema.js +31 -29
- package/hma.js +10 -4
- package/macd.js +27 -25
- package/momentum.js +21 -18
- package/mse.js +9 -12
- package/package.json +10 -7
- package/roc.js +20 -17
- package/rsi.js +19 -4
- package/sd.js +17 -8
- package/sma.js +21 -18
- package/stochastic.js +23 -21
- package/trix.js +5 -4
- package/wma.js +20 -15
package/CHANGELOG.md
CHANGED
package/bollinger.js
CHANGED
|
@@ -6,18 +6,25 @@ import { multiplex } from "@thi.ng/transducers/multiplex";
|
|
|
6
6
|
import { partition } from "@thi.ng/transducers/partition";
|
|
7
7
|
import { mse } from "./mse.js";
|
|
8
8
|
import { sma } from "./sma.js";
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
9
|
+
function bollinger(...args) {
|
|
10
|
+
const iter = __iter(bollinger, args);
|
|
11
|
+
if (iter) {
|
|
12
|
+
return iter;
|
|
13
|
+
}
|
|
14
|
+
const period = args[0] || 20;
|
|
15
|
+
const sd = args[1] || 2;
|
|
16
|
+
return comp(
|
|
17
|
+
multiplex(partition(period, 1), sma(period)),
|
|
18
|
+
drop(period - 1),
|
|
19
|
+
map(([window, mean]) => {
|
|
20
|
+
const std = Math.sqrt(mse(window, mean) / period) * sd;
|
|
21
|
+
const min = mean - std;
|
|
22
|
+
const max = mean + std;
|
|
23
|
+
const pb = (window[period - 1] - min) / (max - min);
|
|
24
|
+
return { min, max, mean, pb };
|
|
25
|
+
})
|
|
26
|
+
);
|
|
23
27
|
}
|
|
28
|
+
export {
|
|
29
|
+
bollinger
|
|
30
|
+
};
|
package/bounds.js
CHANGED
|
@@ -1,15 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
14
|
-
return [min, max];
|
|
1
|
+
const bounds = (window) => {
|
|
2
|
+
let min = window[0];
|
|
3
|
+
let max = min;
|
|
4
|
+
for (let i = window.length - 1; i > 0; i--) {
|
|
5
|
+
const v = window[i];
|
|
6
|
+
min = Math.min(min, v);
|
|
7
|
+
max = Math.max(max, v);
|
|
8
|
+
}
|
|
9
|
+
return [min, max];
|
|
10
|
+
};
|
|
11
|
+
export {
|
|
12
|
+
bounds
|
|
15
13
|
};
|
package/donchian.js
CHANGED
|
@@ -3,8 +3,9 @@ import { iterator } from "@thi.ng/transducers/iterator";
|
|
|
3
3
|
import { map } from "@thi.ng/transducers/map";
|
|
4
4
|
import { partition } from "@thi.ng/transducers/partition";
|
|
5
5
|
import { bounds } from "./bounds.js";
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
? iterator(donchian(period), src)
|
|
9
|
-
: comp(partition(period, 1), map(bounds));
|
|
6
|
+
function donchian(period, src) {
|
|
7
|
+
return src ? iterator(donchian(period), src) : comp(partition(period, 1), map(bounds));
|
|
10
8
|
}
|
|
9
|
+
export {
|
|
10
|
+
donchian
|
|
11
|
+
};
|
package/dot.js
CHANGED
|
@@ -1,14 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
*
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
export
|
|
9
|
-
|
|
10
|
-
for (let i = a.length - 1; i >= 0; i--) {
|
|
11
|
-
sum += a[i] * b[i];
|
|
12
|
-
}
|
|
13
|
-
return sum;
|
|
1
|
+
const dot = (a, b) => {
|
|
2
|
+
let sum = 0;
|
|
3
|
+
for (let i = a.length - 1; i >= 0; i--) {
|
|
4
|
+
sum += a[i] * b[i];
|
|
5
|
+
}
|
|
6
|
+
return sum;
|
|
7
|
+
};
|
|
8
|
+
export {
|
|
9
|
+
dot
|
|
14
10
|
};
|
package/ema.js
CHANGED
|
@@ -1,33 +1,35 @@
|
|
|
1
1
|
import { illegalArgs } from "@thi.ng/errors/illegal-arguments";
|
|
2
2
|
import { compR } from "@thi.ng/transducers/compr";
|
|
3
3
|
import { iterator1 } from "@thi.ng/transducers/iterator";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
};
|
|
4
|
+
function ema(period, src) {
|
|
5
|
+
if (src) {
|
|
6
|
+
return iterator1(ema(period), src);
|
|
7
|
+
}
|
|
8
|
+
period |= 0;
|
|
9
|
+
period < 2 && illegalArgs("period must be >= 2");
|
|
10
|
+
const k = 2 / (period + 1);
|
|
11
|
+
return (rfn) => {
|
|
12
|
+
const reduce = rfn[2];
|
|
13
|
+
let window = [];
|
|
14
|
+
let ema2;
|
|
15
|
+
let sum = 0;
|
|
16
|
+
return compR(rfn, (acc, x) => {
|
|
17
|
+
if (ema2 != null) {
|
|
18
|
+
ema2 += (x - ema2) * k;
|
|
19
|
+
return rfn[2](acc, ema2);
|
|
20
|
+
} else {
|
|
21
|
+
window.push(x);
|
|
22
|
+
sum += x;
|
|
23
|
+
if (window.length == period) {
|
|
24
|
+
ema2 = sum / period;
|
|
25
|
+
window = null;
|
|
26
|
+
return reduce(acc, ema2);
|
|
27
|
+
}
|
|
28
|
+
return acc;
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
};
|
|
33
32
|
}
|
|
33
|
+
export {
|
|
34
|
+
ema
|
|
35
|
+
};
|
package/hma.js
CHANGED
|
@@ -4,8 +4,14 @@ import { iterator1 } from "@thi.ng/transducers/iterator";
|
|
|
4
4
|
import { map } from "@thi.ng/transducers/map";
|
|
5
5
|
import { multiplex } from "@thi.ng/transducers/multiplex";
|
|
6
6
|
import { wma } from "./wma.js";
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
function hma(period, src) {
|
|
8
|
+
return src ? iterator1(hma(period), src) : comp(
|
|
9
|
+
multiplex(wma(period / 2 | 0), wma(period)),
|
|
10
|
+
drop(period - 1),
|
|
11
|
+
map((w) => 2 * w[0] - w[1]),
|
|
12
|
+
wma(Math.sqrt(period))
|
|
13
|
+
);
|
|
11
14
|
}
|
|
15
|
+
export {
|
|
16
|
+
hma
|
|
17
|
+
};
|
package/macd.js
CHANGED
|
@@ -2,29 +2,31 @@ import { compR } from "@thi.ng/transducers/compr";
|
|
|
2
2
|
import { __iter } from "@thi.ng/transducers/iterator";
|
|
3
3
|
import { step } from "@thi.ng/transducers/step";
|
|
4
4
|
import { ema } from "./ema.js";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}));
|
|
5
|
+
function macd(...args) {
|
|
6
|
+
return __iter(macd, args) || ((rfn) => {
|
|
7
|
+
const reduce = rfn[2];
|
|
8
|
+
const maFast = step(ema(args[0] || 12));
|
|
9
|
+
const maSlow = step(ema(args[1] || 26));
|
|
10
|
+
const maSmooth = step(ema(args[2] || 9));
|
|
11
|
+
return compR(rfn, (acc, x) => {
|
|
12
|
+
const fast = maFast(x);
|
|
13
|
+
const slow = maSlow(x);
|
|
14
|
+
if (slow == null)
|
|
15
|
+
return acc;
|
|
16
|
+
const macd2 = fast - slow;
|
|
17
|
+
const signal = maSmooth(macd2);
|
|
18
|
+
if (signal == null)
|
|
19
|
+
return acc;
|
|
20
|
+
return reduce(acc, {
|
|
21
|
+
macd: macd2,
|
|
22
|
+
signal,
|
|
23
|
+
div: macd2 - signal,
|
|
24
|
+
fast,
|
|
25
|
+
slow
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
});
|
|
30
29
|
}
|
|
30
|
+
export {
|
|
31
|
+
macd
|
|
32
|
+
};
|
package/momentum.js
CHANGED
|
@@ -2,22 +2,25 @@ import { DCons } from "@thi.ng/dcons/dcons";
|
|
|
2
2
|
import { illegalArgs } from "@thi.ng/errors/illegal-arguments";
|
|
3
3
|
import { compR } from "@thi.ng/transducers/compr";
|
|
4
4
|
import { iterator1 } from "@thi.ng/transducers/iterator";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
5
|
+
function momentum(period, src) {
|
|
6
|
+
if (src) {
|
|
7
|
+
return iterator1(momentum(period), src);
|
|
8
|
+
}
|
|
9
|
+
period |= 0;
|
|
10
|
+
period < 1 && illegalArgs("period must be >= 1");
|
|
11
|
+
return (rfn) => {
|
|
12
|
+
const reduce = rfn[2];
|
|
13
|
+
const window = new DCons();
|
|
14
|
+
return compR(rfn, (acc, x) => {
|
|
15
|
+
window.push(x);
|
|
16
|
+
if (window.length <= period) {
|
|
17
|
+
return acc;
|
|
18
|
+
}
|
|
19
|
+
const prev = window.drop();
|
|
20
|
+
return reduce(acc, x - prev);
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
23
|
}
|
|
24
|
+
export {
|
|
25
|
+
momentum
|
|
26
|
+
};
|
package/mse.js
CHANGED
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
sum += Math.pow(window[i] - mean, 2);
|
|
11
|
-
}
|
|
12
|
-
return sum;
|
|
1
|
+
const mse = (window, mean) => {
|
|
2
|
+
let sum = 0;
|
|
3
|
+
for (let i = window.length - 1; i >= 0; i--) {
|
|
4
|
+
sum += Math.pow(window[i] - mean, 2);
|
|
5
|
+
}
|
|
6
|
+
return sum;
|
|
7
|
+
};
|
|
8
|
+
export {
|
|
9
|
+
mse
|
|
13
10
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thi.ng/transducers-stats",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.82",
|
|
4
4
|
"description": "Transducers for statistical / technical analysis",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -24,7 +24,9 @@
|
|
|
24
24
|
"author": "Karsten Schmidt (https://thi.ng)",
|
|
25
25
|
"license": "Apache-2.0",
|
|
26
26
|
"scripts": {
|
|
27
|
-
"build": "yarn
|
|
27
|
+
"build": "yarn build:esbuild && yarn build:decl",
|
|
28
|
+
"build:decl": "tsc --declaration --emitDeclarationOnly",
|
|
29
|
+
"build:esbuild": "esbuild --format=esm --platform=neutral --target=es2022 --tsconfig=tsconfig.json --outdir=. src/**/*.ts",
|
|
28
30
|
"clean": "rimraf --glob '*.js' '*.d.ts' '*.map' doc",
|
|
29
31
|
"doc": "typedoc --excludePrivate --excludeInternal --out doc src/index.ts",
|
|
30
32
|
"doc:ae": "mkdir -p .ae/doc .ae/temp && api-extractor run --local --verbose",
|
|
@@ -33,13 +35,14 @@
|
|
|
33
35
|
"test": "bun test"
|
|
34
36
|
},
|
|
35
37
|
"dependencies": {
|
|
36
|
-
"@thi.ng/checks": "^3.4.
|
|
37
|
-
"@thi.ng/dcons": "^3.2.
|
|
38
|
-
"@thi.ng/errors": "^2.4.
|
|
39
|
-
"@thi.ng/transducers": "^8.8.
|
|
38
|
+
"@thi.ng/checks": "^3.4.12",
|
|
39
|
+
"@thi.ng/dcons": "^3.2.77",
|
|
40
|
+
"@thi.ng/errors": "^2.4.6",
|
|
41
|
+
"@thi.ng/transducers": "^8.8.15"
|
|
40
42
|
},
|
|
41
43
|
"devDependencies": {
|
|
42
44
|
"@microsoft/api-extractor": "^7.38.3",
|
|
45
|
+
"esbuild": "^0.19.8",
|
|
43
46
|
"rimraf": "^5.0.5",
|
|
44
47
|
"tools": "^0.0.1",
|
|
45
48
|
"typedoc": "^0.25.4",
|
|
@@ -129,5 +132,5 @@
|
|
|
129
132
|
"parent": "@thi.ng/transducers",
|
|
130
133
|
"year": 2017
|
|
131
134
|
},
|
|
132
|
-
"gitHead": "
|
|
135
|
+
"gitHead": "5e7bafedfc3d53bc131469a28de31dd8e5b4a3ff\n"
|
|
133
136
|
}
|
package/roc.js
CHANGED
|
@@ -2,21 +2,24 @@ import { DCons } from "@thi.ng/dcons/dcons";
|
|
|
2
2
|
import { illegalArgs } from "@thi.ng/errors/illegal-arguments";
|
|
3
3
|
import { compR } from "@thi.ng/transducers/compr";
|
|
4
4
|
import { iterator1 } from "@thi.ng/transducers/iterator";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
5
|
+
function roc(period, src) {
|
|
6
|
+
if (src) {
|
|
7
|
+
return iterator1(roc(period), src);
|
|
8
|
+
}
|
|
9
|
+
period < 1 && illegalArgs("period must be >= 1");
|
|
10
|
+
return (rfn) => {
|
|
11
|
+
const reduce = rfn[2];
|
|
12
|
+
const window = new DCons();
|
|
13
|
+
return compR(rfn, (acc, x) => {
|
|
14
|
+
window.push(x);
|
|
15
|
+
if (window.length <= period) {
|
|
16
|
+
return acc;
|
|
17
|
+
}
|
|
18
|
+
const prev = window.drop();
|
|
19
|
+
return reduce(acc, (x - prev) / prev);
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
22
|
}
|
|
23
|
+
export {
|
|
24
|
+
roc
|
|
25
|
+
};
|
package/rsi.js
CHANGED
|
@@ -5,8 +5,23 @@ import { map } from "@thi.ng/transducers/map";
|
|
|
5
5
|
import { multiplex } from "@thi.ng/transducers/multiplex";
|
|
6
6
|
import { momentum } from "./momentum.js";
|
|
7
7
|
import { sma } from "./sma.js";
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
function rsi(period, src) {
|
|
9
|
+
return src ? iterator1(rsi(period), src) : comp(
|
|
10
|
+
momentum(1),
|
|
11
|
+
multiplex(
|
|
12
|
+
comp(
|
|
13
|
+
map((x) => x > 0 ? x : 0),
|
|
14
|
+
sma(period)
|
|
15
|
+
),
|
|
16
|
+
comp(
|
|
17
|
+
map((x) => x < 0 ? -x : 0),
|
|
18
|
+
sma(period)
|
|
19
|
+
)
|
|
20
|
+
),
|
|
21
|
+
drop(period - 1),
|
|
22
|
+
map((hl) => 100 - 100 / (1 + hl[0] / Math.max(1e-6, hl[1])))
|
|
23
|
+
);
|
|
12
24
|
}
|
|
25
|
+
export {
|
|
26
|
+
rsi
|
|
27
|
+
};
|
package/sd.js
CHANGED
|
@@ -6,12 +6,21 @@ import { multiplex } from "@thi.ng/transducers/multiplex";
|
|
|
6
6
|
import { partition } from "@thi.ng/transducers/partition";
|
|
7
7
|
import { mse } from "./mse.js";
|
|
8
8
|
import { sma } from "./sma.js";
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
9
|
+
function sd(...args) {
|
|
10
|
+
const iter = __iter(sd, args);
|
|
11
|
+
if (iter) {
|
|
12
|
+
return iter;
|
|
13
|
+
}
|
|
14
|
+
const period = args[0] || 20;
|
|
15
|
+
const scale = args[1] || 1;
|
|
16
|
+
return comp(
|
|
17
|
+
multiplex(partition(period, 1), sma(period)),
|
|
18
|
+
drop(period - 1),
|
|
19
|
+
map(
|
|
20
|
+
([window, mean]) => Math.sqrt(mse(window, mean) / period) * scale
|
|
21
|
+
)
|
|
22
|
+
);
|
|
17
23
|
}
|
|
24
|
+
export {
|
|
25
|
+
sd
|
|
26
|
+
};
|
package/sma.js
CHANGED
|
@@ -2,22 +2,25 @@ import { DCons } from "@thi.ng/dcons/dcons";
|
|
|
2
2
|
import { illegalArgs } from "@thi.ng/errors/illegal-arguments";
|
|
3
3
|
import { compR } from "@thi.ng/transducers/compr";
|
|
4
4
|
import { iterator1 } from "@thi.ng/transducers/iterator";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
5
|
+
function sma(period, src) {
|
|
6
|
+
if (src) {
|
|
7
|
+
return iterator1(sma(period), src);
|
|
8
|
+
}
|
|
9
|
+
period |= 0;
|
|
10
|
+
period < 2 && illegalArgs("period must be >= 2");
|
|
11
|
+
return (rfn) => {
|
|
12
|
+
const reduce = rfn[2];
|
|
13
|
+
const window = new DCons();
|
|
14
|
+
let sum = 0;
|
|
15
|
+
return compR(rfn, (acc, x) => {
|
|
16
|
+
window.push(x);
|
|
17
|
+
const n = window.length;
|
|
18
|
+
sum += x;
|
|
19
|
+
n > period && (sum -= window.drop());
|
|
20
|
+
return n >= period ? reduce(acc, sum / period) : acc;
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
23
|
}
|
|
24
|
+
export {
|
|
25
|
+
sma
|
|
26
|
+
};
|
package/stochastic.js
CHANGED
|
@@ -3,25 +3,27 @@ import { __iter } from "@thi.ng/transducers/iterator";
|
|
|
3
3
|
import { step } from "@thi.ng/transducers/step";
|
|
4
4
|
import { donchian } from "./donchian.js";
|
|
5
5
|
import { sma } from "./sma.js";
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}));
|
|
6
|
+
function stochastic(...args) {
|
|
7
|
+
return __iter(stochastic, args) || ((rfn) => {
|
|
8
|
+
const reduce = rfn[2];
|
|
9
|
+
const xfD = step(donchian(args[0] || 5));
|
|
10
|
+
const ma1 = step(sma(args[1] || 3));
|
|
11
|
+
const ma2 = step(sma(args[2] || 3));
|
|
12
|
+
return compR(rfn, (acc, x) => {
|
|
13
|
+
const b = xfD(x);
|
|
14
|
+
if (b == null)
|
|
15
|
+
return acc;
|
|
16
|
+
const k = (x - b[0]) / (b[1] - b[0]);
|
|
17
|
+
const d1 = ma1(k);
|
|
18
|
+
if (d1 == null)
|
|
19
|
+
return acc;
|
|
20
|
+
const d2 = ma2(d1);
|
|
21
|
+
if (d2 == null)
|
|
22
|
+
return acc;
|
|
23
|
+
return reduce(acc, { k, d1, d2 });
|
|
24
|
+
});
|
|
25
|
+
});
|
|
27
26
|
}
|
|
27
|
+
export {
|
|
28
|
+
stochastic
|
|
29
|
+
};
|
package/trix.js
CHANGED
|
@@ -2,8 +2,9 @@ import { comp } from "@thi.ng/transducers/comp";
|
|
|
2
2
|
import { iterator1 } from "@thi.ng/transducers/iterator";
|
|
3
3
|
import { ema } from "./ema.js";
|
|
4
4
|
import { roc } from "./roc.js";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
? iterator1(trix(period), src)
|
|
8
|
-
: comp(ema(period), ema(period), ema(period), roc(1));
|
|
5
|
+
function trix(period, src) {
|
|
6
|
+
return src ? iterator1(trix(period), src) : comp(ema(period), ema(period), ema(period), roc(1));
|
|
9
7
|
}
|
|
8
|
+
export {
|
|
9
|
+
trix
|
|
10
|
+
};
|
package/wma.js
CHANGED
|
@@ -5,19 +5,24 @@ import { map } from "@thi.ng/transducers/map";
|
|
|
5
5
|
import { partition } from "@thi.ng/transducers/partition";
|
|
6
6
|
import { range } from "@thi.ng/transducers/range";
|
|
7
7
|
import { dot } from "./dot.js";
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
8
|
+
function wma(weights, src) {
|
|
9
|
+
if (src) {
|
|
10
|
+
return iterator1(wma(weights), src);
|
|
11
|
+
}
|
|
12
|
+
let period, wsum;
|
|
13
|
+
if (isNumber(weights)) {
|
|
14
|
+
period = weights | 0;
|
|
15
|
+
weights = [...range(1, period + 1)];
|
|
16
|
+
wsum = period * (period + 1) / 2;
|
|
17
|
+
} else {
|
|
18
|
+
period = weights.length;
|
|
19
|
+
wsum = weights.reduce((acc, x) => acc + x, 0);
|
|
20
|
+
}
|
|
21
|
+
return comp(
|
|
22
|
+
partition(period, 1),
|
|
23
|
+
map((window) => dot(window, weights) / wsum)
|
|
24
|
+
);
|
|
23
25
|
}
|
|
26
|
+
export {
|
|
27
|
+
wma
|
|
28
|
+
};
|