@quantform/core 0.3.217 → 0.3.222
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/indicator/atr.d.ts +1 -2
- package/dist/indicator/atr.js +4 -1
- package/dist/indicator/atr.js.map +1 -1
- package/dist/indicator/donchian.d.ts +7 -6
- package/dist/indicator/donchian.js +6 -15
- package/dist/indicator/donchian.js.map +1 -1
- package/dist/indicator/ema.d.ts +1 -10
- package/dist/indicator/ema.js +13 -32
- package/dist/indicator/ema.js.map +1 -1
- package/dist/indicator/ema.spec.js +4 -23
- package/dist/indicator/ema.spec.js.map +1 -1
- package/dist/indicator/envelope.js +4 -8
- package/dist/indicator/envelope.js.map +1 -1
- package/dist/indicator/index.d.ts +1 -1
- package/dist/indicator/index.js +1 -1
- package/dist/indicator/index.js.map +1 -1
- package/dist/indicator/macd.js +3 -12
- package/dist/indicator/macd.js.map +1 -1
- package/dist/indicator/min-max.d.ts +4 -11
- package/dist/indicator/min-max.js +12 -29
- package/dist/indicator/min-max.js.map +1 -1
- package/dist/indicator/rma.d.ts +1 -10
- package/dist/indicator/rma.js +13 -32
- package/dist/indicator/rma.js.map +1 -1
- package/dist/indicator/sma.d.ts +1 -10
- package/dist/indicator/sma.js +11 -22
- package/dist/indicator/sma.js.map +1 -1
- package/dist/indicator/sma.spec.js +1 -1
- package/dist/indicator/sma.spec.js.map +1 -1
- package/dist/indicator/swma.d.ts +1 -9
- package/dist/indicator/swma.js +11 -26
- package/dist/indicator/swma.js.map +1 -1
- package/dist/indicator/tma.d.ts +1 -2
- package/dist/indicator/tma.js +4 -1
- package/dist/indicator/tma.js.map +1 -1
- package/dist/indicator/tma.spec.js +1 -1
- package/dist/indicator/tma.spec.js.map +1 -1
- package/dist/indicator/truerange.d.ts +1 -1
- package/dist/indicator/truerange.js +3 -1
- package/dist/indicator/truerange.js.map +1 -1
- package/dist/indicator/truerange.spec.js +2 -2
- package/dist/indicator/truerange.spec.js.map +1 -1
- package/dist/indicator/window.d.ts +3 -0
- package/dist/indicator/window.js +22 -0
- package/dist/indicator/window.js.map +1 -0
- package/dist/indicator/wma.d.ts +1 -11
- package/dist/indicator/wma.js +13 -33
- package/dist/indicator/wma.js.map +1 -1
- package/dist/indicator/wma.spec.js +1 -1
- package/dist/indicator/wma.spec.js.map +1 -1
- package/dist/session/session-descriptor.d.ts +0 -1
- package/dist/session/session-optimizer.js.map +1 -1
- package/dist/session/session.d.ts +10 -6
- package/dist/session/session.js +26 -15
- package/dist/session/session.js.map +1 -1
- package/dist/storage/measurement.d.ts +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/indicator/atr.ts +9 -4
- package/src/indicator/donchian.ts +26 -26
- package/src/indicator/ema.spec.ts +4 -23
- package/src/indicator/ema.ts +15 -42
- package/src/indicator/envelope.ts +8 -14
- package/src/indicator/index.ts +1 -1
- package/src/indicator/macd.ts +8 -19
- package/src/indicator/min-max.ts +15 -37
- package/src/indicator/rma.ts +15 -43
- package/src/indicator/sma.spec.ts +1 -1
- package/src/indicator/sma.ts +13 -29
- package/src/indicator/swma.ts +14 -35
- package/src/indicator/tma.spec.ts +1 -1
- package/src/indicator/tma.ts +9 -4
- package/src/indicator/truerange.spec.ts +2 -2
- package/src/indicator/truerange.ts +15 -10
- package/src/indicator/window.ts +27 -0
- package/src/indicator/wma.spec.ts +1 -1
- package/src/indicator/wma.ts +16 -44
- package/src/session/session-descriptor.ts +0 -2
- package/src/session/session-optimizer.ts +1 -1
- package/src/session/session.ts +47 -17
- package/src/storage/measurement.ts +1 -2
- package/dist/indicator/window-indicator.d.ts +0 -10
- package/dist/indicator/window-indicator.js +0 -28
- package/dist/indicator/window-indicator.js.map +0 -1
- package/src/indicator/window-indicator.ts +0 -35
package/dist/indicator/atr.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
1
|
import { Observable } from 'rxjs';
|
|
2
2
|
import { Candle } from '../domain';
|
|
3
|
-
|
|
4
|
-
export declare function atr<T>(length: number, fn: (it: T) => Candle): (source: Observable<T>) => Observable<RMA>;
|
|
3
|
+
export declare function atr<T>(length: number, fn: (it: T) => Candle): (source: Observable<T>) => Observable<[T, number]>;
|
package/dist/indicator/atr.js
CHANGED
|
@@ -6,7 +6,10 @@ const rma_1 = require("./rma");
|
|
|
6
6
|
const truerange_1 = require("./truerange");
|
|
7
7
|
function atr(length, fn) {
|
|
8
8
|
return function (source) {
|
|
9
|
-
return source.pipe((0, truerange_1.truerange)(fn), (0, rma_1.rma)(length,
|
|
9
|
+
return source.pipe((0, truerange_1.truerange)(fn), (0, rma_1.rma)(length, ([, tr]) => tr), (0, operators_1.map)(([[it], truerange]) => {
|
|
10
|
+
const tuple = [it, truerange];
|
|
11
|
+
return tuple;
|
|
12
|
+
}), (0, operators_1.share)());
|
|
10
13
|
};
|
|
11
14
|
}
|
|
12
15
|
exports.atr = atr;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"atr.js","sourceRoot":"","sources":["../../src/indicator/atr.ts"],"names":[],"mappings":";;;AACA,
|
|
1
|
+
{"version":3,"file":"atr.js","sourceRoot":"","sources":["../../src/indicator/atr.ts"],"names":[],"mappings":";;;AACA,8CAA4C;AAE5C,+BAA4B;AAC5B,2CAAwC;AAExC,SAAgB,GAAG,CAAI,MAAc,EAAE,EAAqB;IAC1D,OAAO,UAAU,MAAqB;QACpC,OAAO,MAAM,CAAC,IAAI,CAChB,IAAA,qBAAS,EAAC,EAAE,CAAC,EACb,IAAA,SAAG,EAAC,MAAM,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC,EAC3B,IAAA,eAAG,EAAC,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,SAAS,CAAC,EAAE,EAAE;YACxB,MAAM,KAAK,GAAgB,CAAC,EAAE,EAAE,SAAS,CAAC,CAAC;YAE3C,OAAO,KAAK,CAAC;QACf,CAAC,CAAC,EACF,IAAA,iBAAK,GAAE,CACR,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC;AAbD,kBAaC"}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { Observable } from 'rxjs';
|
|
2
2
|
import { Candle } from '../domain';
|
|
3
|
-
export declare function donchian<T>(length: number, fn: (it: T) => Candle): (source: Observable<T>) => Observable<
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
}
|
|
3
|
+
export declare function donchian<T>(length: number, fn: (it: T) => Candle): (source: Observable<T>) => Observable<[
|
|
4
|
+
T,
|
|
5
|
+
{
|
|
6
|
+
upper: number;
|
|
7
|
+
lower: number;
|
|
8
|
+
}
|
|
9
|
+
]>;
|
|
@@ -1,25 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.donchian = void 0;
|
|
4
|
+
const rxjs_1 = require("rxjs");
|
|
4
5
|
const operators_1 = require("rxjs/operators");
|
|
5
6
|
const min_max_1 = require("./min-max");
|
|
6
7
|
function donchian(length, fn) {
|
|
7
8
|
return function (source) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
timestamp = candle.timestamp;
|
|
14
|
-
min.append(candle.low);
|
|
15
|
-
max.append(candle.high);
|
|
16
|
-
return min.isCompleted && max.isCompleted;
|
|
17
|
-
}), (0, operators_1.map)(() => ({
|
|
18
|
-
timestamp,
|
|
19
|
-
upper: max.max,
|
|
20
|
-
middle: (min.min + max.max) / 2,
|
|
21
|
-
lower: min.min
|
|
22
|
-
})), (0, operators_1.share)());
|
|
9
|
+
source = source.pipe((0, operators_1.share)());
|
|
10
|
+
return source.pipe((0, rxjs_1.withLatestFrom)(source.pipe((0, min_max_1.minMax)(length, it => fn(it).low)), source.pipe((0, min_max_1.minMax)(length, it => fn(it).high))), (0, operators_1.map)(([it, low, high]) => {
|
|
11
|
+
const tuple = [it, { lower: low[1].min, upper: high[1].max }];
|
|
12
|
+
return tuple;
|
|
13
|
+
}), (0, operators_1.share)());
|
|
23
14
|
};
|
|
24
15
|
}
|
|
25
16
|
exports.donchian = donchian;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"donchian.js","sourceRoot":"","sources":["../../src/indicator/donchian.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"donchian.js","sourceRoot":"","sources":["../../src/indicator/donchian.ts"],"names":[],"mappings":";;;AAAA,+BAAkD;AAClD,8CAA4C;AAC5C,uCAAmC;AAGnC,SAAgB,QAAQ,CAAI,MAAc,EAAE,EAAqB;IAC/D,OAAO,UAAU,MAAqB;QASpC,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,IAAA,iBAAK,GAAE,CAAC,CAAC;QAE9B,OAAO,MAAM,CAAC,IAAI,CAChB,IAAA,qBAAc,EACZ,MAAM,CAAC,IAAI,CAAC,IAAA,gBAAM,EAAC,MAAM,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,EAC7C,MAAM,CAAC,IAAI,CAAC,IAAA,gBAAM,EAAC,MAAM,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,CAC/C,EACD,IAAA,eAAG,EAAC,CAAC,CAAC,EAAE,EAAE,GAAG,EAAE,IAAI,CAAC,EAAE,EAAE;YACtB,MAAM,KAAK,GAMP,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC;YAEpD,OAAO,KAAK,CAAC;QACf,CAAC,CAAC,EACF,IAAA,iBAAK,GAAE,CACR,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC;AA/BD,4BA+BC"}
|
package/dist/indicator/ema.d.ts
CHANGED
|
@@ -1,11 +1,2 @@
|
|
|
1
1
|
import { Observable } from 'rxjs';
|
|
2
|
-
|
|
3
|
-
export declare class EMA extends WindowIndicator<number> {
|
|
4
|
-
private _alpha;
|
|
5
|
-
private _sma;
|
|
6
|
-
private _value;
|
|
7
|
-
get value(): number;
|
|
8
|
-
constructor(capacity: number);
|
|
9
|
-
calculate(added: number): void;
|
|
10
|
-
}
|
|
11
|
-
export declare function ema<T>(length: number, fn: (it: T) => number): (source: Observable<T>) => Observable<EMA>;
|
|
2
|
+
export declare function ema<T>(length: number, fn: (it: T) => number): (source: Observable<T>) => Observable<[T, number]>;
|
package/dist/indicator/ema.js
CHANGED
|
@@ -1,41 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ema =
|
|
3
|
+
exports.ema = void 0;
|
|
4
4
|
const operators_1 = require("rxjs/operators");
|
|
5
5
|
const sma_1 = require("./sma");
|
|
6
|
-
const window_indicator_1 = require("./window-indicator");
|
|
7
|
-
class EMA extends window_indicator_1.WindowIndicator {
|
|
8
|
-
constructor(capacity) {
|
|
9
|
-
super(capacity);
|
|
10
|
-
this._alpha = 0;
|
|
11
|
-
this._value = null;
|
|
12
|
-
this._alpha = 2.0 / (capacity + 1);
|
|
13
|
-
this._sma = new sma_1.SMA(capacity);
|
|
14
|
-
}
|
|
15
|
-
get value() {
|
|
16
|
-
return this._value;
|
|
17
|
-
}
|
|
18
|
-
calculate(added) {
|
|
19
|
-
this._sma.append(added);
|
|
20
|
-
if (!this._sma.isCompleted) {
|
|
21
|
-
return;
|
|
22
|
-
}
|
|
23
|
-
if (!this.value) {
|
|
24
|
-
this._value = this._sma.value;
|
|
25
|
-
}
|
|
26
|
-
else {
|
|
27
|
-
this._value = this._alpha * added + (1.0 - this._alpha) * this._value;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
exports.EMA = EMA;
|
|
32
6
|
function ema(length, fn) {
|
|
33
7
|
return function (source) {
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
8
|
+
const alpha = 2.0 / (length + 1);
|
|
9
|
+
let value = null;
|
|
10
|
+
return source.pipe((0, sma_1.sma)(length, fn), (0, operators_1.map)(([it, sma]) => {
|
|
11
|
+
if (!value) {
|
|
12
|
+
value = sma;
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
value = alpha * fn(it) + (1.0 - alpha) * value;
|
|
16
|
+
}
|
|
17
|
+
const tuple = [it, value];
|
|
18
|
+
return tuple;
|
|
19
|
+
}), (0, operators_1.share)());
|
|
39
20
|
};
|
|
40
21
|
}
|
|
41
22
|
exports.ema = ema;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ema.js","sourceRoot":"","sources":["../../src/indicator/ema.ts"],"names":[],"mappings":";;;AACA,
|
|
1
|
+
{"version":3,"file":"ema.js","sourceRoot":"","sources":["../../src/indicator/ema.ts"],"names":[],"mappings":";;;AACA,8CAA4C;AAC5C,+BAA4B;AAE5B,SAAgB,GAAG,CAAI,MAAc,EAAE,EAAqB;IAC1D,OAAO,UAAU,MAAqB;QACpC,MAAM,KAAK,GAAG,GAAG,GAAG,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;QACjC,IAAI,KAAK,GAAW,IAAI,CAAC;QAEzB,OAAO,MAAM,CAAC,IAAI,CAChB,IAAA,SAAG,EAAC,MAAM,EAAE,EAAE,CAAC,EACf,IAAA,eAAG,EAAC,CAAC,CAAC,EAAE,EAAE,GAAG,CAAC,EAAE,EAAE;YAChB,IAAI,CAAC,KAAK,EAAE;gBACV,KAAK,GAAG,GAAG,CAAC;aACb;iBAAM;gBACL,KAAK,GAAG,KAAK,GAAG,EAAE,CAAC,EAAE,CAAC,GAAG,CAAC,GAAG,GAAG,KAAK,CAAC,GAAG,KAAK,CAAC;aAChD;YAED,MAAM,KAAK,GAAgB,CAAC,EAAE,EAAE,KAAK,CAAC,CAAC;YAEvC,OAAO,KAAK,CAAC;QACf,CAAC,CAAC,EACF,IAAA,iBAAK,GAAE,CACR,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC;AArBD,kBAqBC"}
|
|
@@ -6,32 +6,13 @@ describe('ema tests', () => {
|
|
|
6
6
|
test('should return expected value', done => {
|
|
7
7
|
let value;
|
|
8
8
|
(0, rxjs_1.from)([
|
|
9
|
-
212.8,
|
|
10
|
-
214.
|
|
11
|
-
|
|
12
|
-
214.66,
|
|
13
|
-
213.95,
|
|
14
|
-
213.95,
|
|
15
|
-
214.55,
|
|
16
|
-
214.02,
|
|
17
|
-
214.51,
|
|
18
|
-
213.75,
|
|
19
|
-
214.22,
|
|
20
|
-
213.43,
|
|
21
|
-
214.21,
|
|
22
|
-
213.66,
|
|
23
|
-
215.03,
|
|
24
|
-
216.89,
|
|
25
|
-
216.66,
|
|
26
|
-
216.32,
|
|
27
|
-
214.98,
|
|
28
|
-
214.96,
|
|
29
|
-
215.05,
|
|
30
|
-
215.19
|
|
9
|
+
212.8, 214.06, 213.89, 214.66, 213.95, 213.95, 214.55, 214.02, 214.51, 213.75,
|
|
10
|
+
214.22, 213.43, 214.21, 213.66, 215.03, 216.89, 216.66, 216.32, 214.98, 214.96,
|
|
11
|
+
215.05, 215.19
|
|
31
12
|
])
|
|
32
13
|
.pipe((0, ema_1.ema)(20, it => it))
|
|
33
14
|
.subscribe({
|
|
34
|
-
next: it => (value = it
|
|
15
|
+
next: ([, it]) => (value = it),
|
|
35
16
|
complete: () => {
|
|
36
17
|
expect(parseFloat(value.toFixed(4))).toBe(214.6336);
|
|
37
18
|
done();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ema.spec.js","sourceRoot":"","sources":["../../src/indicator/ema.spec.ts"],"names":[],"mappings":";;AAAA,+BAA4B;AAC5B,+BAA4B;AAE5B,QAAQ,CAAC,WAAW,EAAE,GAAG,EAAE;IACzB,IAAI,CAAC,8BAA8B,EAAE,IAAI,CAAC,EAAE;QAC1C,IAAI,KAAK,CAAC;QAEV,IAAA,WAAI,EAAC;YACH,KAAK
|
|
1
|
+
{"version":3,"file":"ema.spec.js","sourceRoot":"","sources":["../../src/indicator/ema.spec.ts"],"names":[],"mappings":";;AAAA,+BAA4B;AAC5B,+BAA4B;AAE5B,QAAQ,CAAC,WAAW,EAAE,GAAG,EAAE;IACzB,IAAI,CAAC,8BAA8B,EAAE,IAAI,CAAC,EAAE;QAC1C,IAAI,KAAK,CAAC;QAEV,IAAA,WAAI,EAAC;YACH,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;YAC7E,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;YAC9E,MAAM,EAAE,MAAM;SACf,CAAC;aACC,IAAI,CAAC,IAAA,SAAG,EAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;aACvB,SAAS,CAAC;YACT,IAAI,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,GAAG,EAAE,CAAC;YAC9B,QAAQ,EAAE,GAAG,EAAE;gBACb,MAAM,CAAC,UAAU,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;gBACpD,IAAI,EAAE,CAAC;YACT,CAAC;SACF,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;AAgBL,CAAC,CAAC,CAAC"}
|
|
@@ -5,15 +5,11 @@ const operators_1 = require("rxjs/operators");
|
|
|
5
5
|
const sma_1 = require("./sma");
|
|
6
6
|
function envelope(length, percent, valueFn) {
|
|
7
7
|
return function (source) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
indicator.append(valueFn(it));
|
|
11
|
-
return indicator.isCompleted;
|
|
12
|
-
}), (0, operators_1.map)(it => {
|
|
13
|
-
const offset = (indicator.value * percent) / 100;
|
|
8
|
+
return source.pipe((0, sma_1.sma)(length, valueFn), (0, operators_1.map)(([it, sma]) => {
|
|
9
|
+
const offset = (sma * percent) / 100;
|
|
14
10
|
return {
|
|
15
|
-
min:
|
|
16
|
-
max:
|
|
11
|
+
min: sma - offset,
|
|
12
|
+
max: sma + offset
|
|
17
13
|
};
|
|
18
14
|
}), (0, operators_1.share)());
|
|
19
15
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"envelope.js","sourceRoot":"","sources":["../../src/indicator/envelope.ts"],"names":[],"mappings":";;;AACA,
|
|
1
|
+
{"version":3,"file":"envelope.js","sourceRoot":"","sources":["../../src/indicator/envelope.ts"],"names":[],"mappings":";;;AACA,8CAA4C;AAC5C,+BAA4B;AAE5B,SAAgB,QAAQ,CAAI,MAAc,EAAE,OAAe,EAAE,OAA0B;IACrF,OAAO,UAAU,MAAqB;QACpC,OAAO,MAAM,CAAC,IAAI,CAChB,IAAA,SAAG,EAAC,MAAM,EAAE,OAAO,CAAC,EACpB,IAAA,eAAG,EAAC,CAAC,CAAC,EAAE,EAAE,GAAG,CAAC,EAAE,EAAE;YAChB,MAAM,MAAM,GAAG,CAAC,GAAG,GAAG,OAAO,CAAC,GAAG,GAAG,CAAC;YAErC,OAAO;gBACL,GAAG,EAAE,GAAG,GAAG,MAAM;gBACjB,GAAG,EAAE,GAAG,GAAG,MAAM;aAClB,CAAC;QACJ,CAAC,CAAC,EACF,IAAA,iBAAK,GAAE,CACR,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC;AAfD,4BAeC"}
|
|
@@ -10,7 +10,7 @@ export * from './swma';
|
|
|
10
10
|
export * from './tma';
|
|
11
11
|
export * from './trailing';
|
|
12
12
|
export * from './truerange';
|
|
13
|
-
export * from './window
|
|
13
|
+
export * from './window';
|
|
14
14
|
export * from './wma';
|
|
15
15
|
export * from './donchian';
|
|
16
16
|
export * from './atr';
|
package/dist/indicator/index.js
CHANGED
|
@@ -22,7 +22,7 @@ __exportStar(require("./swma"), exports);
|
|
|
22
22
|
__exportStar(require("./tma"), exports);
|
|
23
23
|
__exportStar(require("./trailing"), exports);
|
|
24
24
|
__exportStar(require("./truerange"), exports);
|
|
25
|
-
__exportStar(require("./window
|
|
25
|
+
__exportStar(require("./window"), exports);
|
|
26
26
|
__exportStar(require("./wma"), exports);
|
|
27
27
|
__exportStar(require("./donchian"), exports);
|
|
28
28
|
__exportStar(require("./atr"), exports);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/indicator/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,0CAAwB;AACxB,wCAAsB;AACtB,6CAA2B;AAC3B,yCAAuB;AACvB,4CAA0B;AAC1B,gDAA8B;AAC9B,wCAAsB;AACtB,wCAAsB;AACtB,yCAAuB;AACvB,wCAAsB;AACtB,6CAA2B;AAC3B,8CAA4B;AAC5B,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/indicator/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,0CAAwB;AACxB,wCAAsB;AACtB,6CAA2B;AAC3B,yCAAuB;AACvB,4CAA0B;AAC1B,gDAA8B;AAC9B,wCAAsB;AACtB,wCAAsB;AACtB,yCAAuB;AACvB,wCAAsB;AACtB,6CAA2B;AAC3B,8CAA4B;AAC5B,2CAAyB;AACzB,wCAAsB;AACtB,6CAA2B;AAC3B,wCAAsB;AACtB,6CAA2B"}
|
package/dist/indicator/macd.js
CHANGED
|
@@ -1,22 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.macd = void 0;
|
|
4
|
+
const rxjs_1 = require("rxjs");
|
|
4
5
|
const operators_1 = require("rxjs/operators");
|
|
5
6
|
const ema_1 = require("./ema");
|
|
6
7
|
function macd(fast, slow, length, fn) {
|
|
7
8
|
return function (source) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
slow: new ema_1.EMA(slow),
|
|
11
|
-
macd: new ema_1.EMA(length)
|
|
12
|
-
};
|
|
13
|
-
return source.pipe((0, operators_1.filter)(it => {
|
|
14
|
-
const value = fn(it);
|
|
15
|
-
ema.fast.append(value);
|
|
16
|
-
ema.slow.append(value);
|
|
17
|
-
ema.macd.append(ema.fast.value - ema.slow.value);
|
|
18
|
-
return ema.macd.isCompleted;
|
|
19
|
-
}), (0, operators_1.map)(_ => ema.macd.value), (0, operators_1.share)());
|
|
9
|
+
source = source.pipe((0, operators_1.share)());
|
|
10
|
+
return source.pipe((0, rxjs_1.withLatestFrom)(source.pipe((0, ema_1.ema)(fast, fn)), source.pipe((0, ema_1.ema)(slow, fn))), (0, ema_1.ema)(length, it => it[1][1] - it[2][1]), (0, operators_1.map)(([it, macd]) => macd), (0, operators_1.share)());
|
|
20
11
|
};
|
|
21
12
|
}
|
|
22
13
|
exports.macd = macd;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"macd.js","sourceRoot":"","sources":["../../src/indicator/macd.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"macd.js","sourceRoot":"","sources":["../../src/indicator/macd.ts"],"names":[],"mappings":";;;AAAA,+BAAkD;AAClD,8CAA4C;AAC5C,+BAA4B;AAE5B,SAAgB,IAAI,CAClB,IAAY,EACZ,IAAY,EACZ,MAAc,EACd,EAAqB;IAErB,OAAO,UAAU,MAAqB;QACpC,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,IAAA,iBAAK,GAAE,CAAC,CAAC;QAE9B,OAAO,MAAM,CAAC,IAAI,CAChB,IAAA,qBAAc,EAAC,MAAM,CAAC,IAAI,CAAC,IAAA,SAAG,EAAC,IAAI,EAAE,EAAE,CAAC,CAAC,EAAE,MAAM,CAAC,IAAI,CAAC,IAAA,SAAG,EAAC,IAAI,EAAE,EAAE,CAAC,CAAC,CAAC,EACtE,IAAA,SAAG,EAAC,MAAM,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EACtC,IAAA,eAAG,EAAC,CAAC,CAAC,EAAE,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,EACzB,IAAA,iBAAK,GAAE,CACR,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC;AAhBD,oBAgBC"}
|
|
@@ -1,12 +1,5 @@
|
|
|
1
1
|
import { Observable } from 'rxjs';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
private _max;
|
|
7
|
-
get min(): number;
|
|
8
|
-
get max(): number;
|
|
9
|
-
constructor(capacity: number);
|
|
10
|
-
calculate(added: number, removed: number, buffer: RingBuffer<number>): void;
|
|
11
|
-
}
|
|
12
|
-
export declare function minMax<T>(length: number, fn: (it: T) => number): (source: Observable<T>) => Observable<MinMax>;
|
|
2
|
+
export declare function minMax<T>(length: number, fn: (it: T) => number): (source: Observable<T>) => Observable<[T, {
|
|
3
|
+
min: number;
|
|
4
|
+
max: number;
|
|
5
|
+
}]>;
|
|
@@ -1,37 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.minMax =
|
|
3
|
+
exports.minMax = void 0;
|
|
4
4
|
const operators_1 = require("rxjs/operators");
|
|
5
|
-
const
|
|
6
|
-
class MinMax extends window_indicator_1.WindowIndicator {
|
|
7
|
-
constructor(capacity) {
|
|
8
|
-
super(capacity);
|
|
9
|
-
this._min = 0;
|
|
10
|
-
this._max = 0;
|
|
11
|
-
}
|
|
12
|
-
get min() {
|
|
13
|
-
return this._min;
|
|
14
|
-
}
|
|
15
|
-
get max() {
|
|
16
|
-
return this._max;
|
|
17
|
-
}
|
|
18
|
-
calculate(added, removed, buffer) {
|
|
19
|
-
this._min = added;
|
|
20
|
-
this._max = added;
|
|
21
|
-
buffer.forEach(it => {
|
|
22
|
-
this._min = Math.min(it, this._min);
|
|
23
|
-
this._max = Math.max(it, this._max);
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
exports.MinMax = MinMax;
|
|
5
|
+
const window_1 = require("./window");
|
|
28
6
|
function minMax(length, fn) {
|
|
29
7
|
return function (source) {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
8
|
+
return source.pipe((0, window_1.window)(length, fn), (0, operators_1.filter)(([, buffer]) => buffer.isFull), (0, operators_1.map)(([it, buffer]) => {
|
|
9
|
+
let min = 0;
|
|
10
|
+
let max = 0;
|
|
11
|
+
buffer.forEach(it => {
|
|
12
|
+
min = Math.min(it, min);
|
|
13
|
+
max = Math.max(it, max);
|
|
14
|
+
});
|
|
15
|
+
const tuple = [it, { min, max }];
|
|
16
|
+
return tuple;
|
|
17
|
+
}), (0, operators_1.share)());
|
|
35
18
|
};
|
|
36
19
|
}
|
|
37
20
|
exports.minMax = minMax;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"min-max.js","sourceRoot":"","sources":["../../src/indicator/min-max.ts"],"names":[],"mappings":";;;AACA,8CAAoD;
|
|
1
|
+
{"version":3,"file":"min-max.js","sourceRoot":"","sources":["../../src/indicator/min-max.ts"],"names":[],"mappings":";;;AACA,8CAAoD;AACpD,qCAAkC;AAElC,SAAgB,MAAM,CAAI,MAAc,EAAE,EAAqB;IAC7D,OAAO,UAAU,MAAqB;QACpC,OAAO,MAAM,CAAC,IAAI,CAChB,IAAA,eAAM,EAAC,MAAM,EAAE,EAAE,CAAC,EAClB,IAAA,kBAAM,EAAC,CAAC,CAAC,EAAE,MAAM,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,EACrC,IAAA,eAAG,EAAC,CAAC,CAAC,EAAE,EAAE,MAAM,CAAC,EAAE,EAAE;YACnB,IAAI,GAAG,GAAG,CAAC,CAAC;YACZ,IAAI,GAAG,GAAG,CAAC,CAAC;YAEZ,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC,EAAE;gBAClB,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,GAAG,CAAC,CAAC;gBACxB,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,GAAG,CAAC,CAAC;YAC1B,CAAC,CAAC,CAAC;YACH,MAAM,KAAK,GAAsC,CAAC,EAAE,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,CAAC;YAEpE,OAAO,KAAK,CAAC;QACf,CAAC,CAAC,EACF,IAAA,iBAAK,GAAE,CACR,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC;AApBD,wBAoBC"}
|
package/dist/indicator/rma.d.ts
CHANGED
|
@@ -1,11 +1,2 @@
|
|
|
1
1
|
import { Observable } from 'rxjs';
|
|
2
|
-
|
|
3
|
-
export declare class RMA extends WindowIndicator<number> {
|
|
4
|
-
private _alpha;
|
|
5
|
-
private _sma;
|
|
6
|
-
private _value;
|
|
7
|
-
get value(): number;
|
|
8
|
-
constructor(capacity: number);
|
|
9
|
-
calculate(added: number): void;
|
|
10
|
-
}
|
|
11
|
-
export declare function rma<T>(length: number, fn: (it: T) => number): (source: Observable<T>) => Observable<RMA>;
|
|
2
|
+
export declare function rma<T>(length: number, fn: (it: T) => number): (source: Observable<T>) => Observable<[T, number]>;
|
package/dist/indicator/rma.js
CHANGED
|
@@ -1,41 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.rma =
|
|
3
|
+
exports.rma = void 0;
|
|
4
4
|
const operators_1 = require("rxjs/operators");
|
|
5
5
|
const _1 = require(".");
|
|
6
|
-
const window_indicator_1 = require("./window-indicator");
|
|
7
|
-
class RMA extends window_indicator_1.WindowIndicator {
|
|
8
|
-
constructor(capacity) {
|
|
9
|
-
super(capacity);
|
|
10
|
-
this._alpha = 0;
|
|
11
|
-
this._value = null;
|
|
12
|
-
this._alpha = 1.0 / capacity;
|
|
13
|
-
this._sma = new _1.SMA(capacity);
|
|
14
|
-
}
|
|
15
|
-
get value() {
|
|
16
|
-
return this._value;
|
|
17
|
-
}
|
|
18
|
-
calculate(added) {
|
|
19
|
-
this._sma.append(added);
|
|
20
|
-
if (!this._sma.isCompleted) {
|
|
21
|
-
return;
|
|
22
|
-
}
|
|
23
|
-
if (!this.value) {
|
|
24
|
-
this._value = this._sma.value;
|
|
25
|
-
}
|
|
26
|
-
else {
|
|
27
|
-
this._value = this._alpha * added + (1.0 - this._alpha) * this._value;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
exports.RMA = RMA;
|
|
32
6
|
function rma(length, fn) {
|
|
33
7
|
return function (source) {
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
8
|
+
const alpha = 1.0 / length;
|
|
9
|
+
let value = null;
|
|
10
|
+
return source.pipe((0, _1.sma)(length, fn), (0, operators_1.map)(([it, sma]) => {
|
|
11
|
+
if (!value) {
|
|
12
|
+
value = sma;
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
value = alpha * fn(it) + (1.0 - alpha) * value;
|
|
16
|
+
}
|
|
17
|
+
const tuple = [it, value];
|
|
18
|
+
return tuple;
|
|
19
|
+
}), (0, operators_1.share)());
|
|
39
20
|
};
|
|
40
21
|
}
|
|
41
22
|
exports.rma = rma;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rma.js","sourceRoot":"","sources":["../../src/indicator/rma.ts"],"names":[],"mappings":";;;AACA,
|
|
1
|
+
{"version":3,"file":"rma.js","sourceRoot":"","sources":["../../src/indicator/rma.ts"],"names":[],"mappings":";;;AACA,8CAA4C;AAC5C,wBAAwB;AAExB,SAAgB,GAAG,CAAI,MAAc,EAAE,EAAqB;IAC1D,OAAO,UAAU,MAAqB;QACpC,MAAM,KAAK,GAAG,GAAG,GAAG,MAAM,CAAC;QAC3B,IAAI,KAAK,GAAW,IAAI,CAAC;QAEzB,OAAO,MAAM,CAAC,IAAI,CAChB,IAAA,MAAG,EAAC,MAAM,EAAE,EAAE,CAAC,EACf,IAAA,eAAG,EAAC,CAAC,CAAC,EAAE,EAAE,GAAG,CAAC,EAAE,EAAE;YAChB,IAAI,CAAC,KAAK,EAAE;gBACV,KAAK,GAAG,GAAG,CAAC;aACb;iBAAM;gBACL,KAAK,GAAG,KAAK,GAAG,EAAE,CAAC,EAAE,CAAC,GAAG,CAAC,GAAG,GAAG,KAAK,CAAC,GAAG,KAAK,CAAC;aAChD;YAED,MAAM,KAAK,GAAgB,CAAC,EAAE,EAAE,KAAK,CAAC,CAAC;YACvC,OAAO,KAAK,CAAC;QACf,CAAC,CAAC,EACF,IAAA,iBAAK,GAAE,CACR,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC;AApBD,kBAoBC"}
|
package/dist/indicator/sma.d.ts
CHANGED
|
@@ -1,11 +1,2 @@
|
|
|
1
1
|
import { Observable } from 'rxjs';
|
|
2
|
-
|
|
3
|
-
import { WindowIndicator } from './window-indicator';
|
|
4
|
-
export declare class SMA extends WindowIndicator<number> {
|
|
5
|
-
private _accmulated;
|
|
6
|
-
private _value;
|
|
7
|
-
get value(): number;
|
|
8
|
-
constructor(capacity: number);
|
|
9
|
-
calculate(added: number, removed: number, buffer: RingBuffer<number>): void;
|
|
10
|
-
}
|
|
11
|
-
export declare function sma<T>(length: number, fn: (it: T) => number): (source: Observable<T>) => Observable<SMA>;
|
|
2
|
+
export declare function sma<T>(length: number, fn: (it: T) => number): (source: Observable<T>) => Observable<[T, number]>;
|
package/dist/indicator/sma.js
CHANGED
|
@@ -1,30 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.sma =
|
|
3
|
+
exports.sma = void 0;
|
|
4
|
+
const rxjs_1 = require("rxjs");
|
|
4
5
|
const operators_1 = require("rxjs/operators");
|
|
5
|
-
const
|
|
6
|
-
class SMA extends window_indicator_1.WindowIndicator {
|
|
7
|
-
constructor(capacity) {
|
|
8
|
-
super(capacity);
|
|
9
|
-
this._accmulated = 0;
|
|
10
|
-
}
|
|
11
|
-
get value() {
|
|
12
|
-
return this._value;
|
|
13
|
-
}
|
|
14
|
-
calculate(added, removed, buffer) {
|
|
15
|
-
this._accmulated += added;
|
|
16
|
-
this._accmulated -= removed;
|
|
17
|
-
this._value = this._accmulated / buffer.size;
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
exports.SMA = SMA;
|
|
6
|
+
const window_1 = require("./window");
|
|
21
7
|
function sma(length, fn) {
|
|
22
8
|
return function (source) {
|
|
23
|
-
|
|
24
|
-
return source.pipe((0,
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
}), (0, operators_1.
|
|
9
|
+
let accumulated = 0;
|
|
10
|
+
return source.pipe((0, window_1.window)(length, fn), (0, rxjs_1.tap)(([, , added, removed]) => {
|
|
11
|
+
accumulated += added;
|
|
12
|
+
accumulated -= removed;
|
|
13
|
+
}), (0, operators_1.filter)(([, buffer]) => buffer.isFull), (0, operators_1.map)(([it, buffer]) => {
|
|
14
|
+
const tuple = [it, accumulated / buffer.size];
|
|
15
|
+
return tuple;
|
|
16
|
+
}), (0, operators_1.share)());
|
|
28
17
|
};
|
|
29
18
|
}
|
|
30
19
|
exports.sma = sma;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sma.js","sourceRoot":"","sources":["../../src/indicator/sma.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"sma.js","sourceRoot":"","sources":["../../src/indicator/sma.ts"],"names":[],"mappings":";;;AAAA,+BAAuC;AACvC,8CAAoD;AACpD,qCAAkC;AAElC,SAAgB,GAAG,CAAI,MAAc,EAAE,EAAqB;IAC1D,OAAO,UAAU,MAAqB;QACpC,IAAI,WAAW,GAAG,CAAC,CAAC;QAEpB,OAAO,MAAM,CAAC,IAAI,CAChB,IAAA,eAAM,EAAC,MAAM,EAAE,EAAE,CAAC,EAClB,IAAA,UAAG,EAAC,CAAC,CAAC,EAAE,AAAD,EAAG,KAAK,EAAE,OAAO,CAAC,EAAE,EAAE;YAC3B,WAAW,IAAI,KAAK,CAAC;YACrB,WAAW,IAAI,OAAO,CAAC;QACzB,CAAC,CAAC,EACF,IAAA,kBAAM,EAAC,CAAC,CAAC,EAAE,MAAM,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,EACrC,IAAA,eAAG,EAAC,CAAC,CAAC,EAAE,EAAE,MAAM,CAAC,EAAE,EAAE;YACnB,MAAM,KAAK,GAAgB,CAAC,EAAE,EAAE,WAAW,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC;YAE3D,OAAO,KAAK,CAAC;QACf,CAAC,CAAC,EACF,IAAA,iBAAK,GAAE,CACR,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC;AAnBD,kBAmBC"}
|
|
@@ -8,7 +8,7 @@ describe('sma tests', () => {
|
|
|
8
8
|
(0, rxjs_1.from)([18136.17, 18092.15, 18082.39, 18065.4, 18046.47])
|
|
9
9
|
.pipe((0, sma_1.sma)(5, it => it))
|
|
10
10
|
.subscribe({
|
|
11
|
-
next: it => (value = it
|
|
11
|
+
next: ([, it]) => (value = it),
|
|
12
12
|
complete: () => {
|
|
13
13
|
expect(parseFloat(value.toFixed(2))).toBe(18084.52);
|
|
14
14
|
done();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sma.spec.js","sourceRoot":"","sources":["../../src/indicator/sma.spec.ts"],"names":[],"mappings":";;AAAA,+BAA4B;AAC5B,+BAA4B;AAE5B,QAAQ,CAAC,WAAW,EAAE,GAAG,EAAE;IACzB,IAAI,CAAC,8BAA8B,EAAE,IAAI,CAAC,EAAE;QAC1C,IAAI,KAAK,CAAC;QAGV,IAAA,WAAI,EAAC,CAAC,QAAQ,EAAE,QAAQ,EAAE,QAAQ,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAC;aACpD,IAAI,CAAC,IAAA,SAAG,EAAC,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;aACtB,SAAS,CAAC;YACT,IAAI,EAAE,EAAE,CAAC,EAAE,CAAC,CAAC,KAAK,GAAG,EAAE,CAAC
|
|
1
|
+
{"version":3,"file":"sma.spec.js","sourceRoot":"","sources":["../../src/indicator/sma.spec.ts"],"names":[],"mappings":";;AAAA,+BAA4B;AAC5B,+BAA4B;AAE5B,QAAQ,CAAC,WAAW,EAAE,GAAG,EAAE;IACzB,IAAI,CAAC,8BAA8B,EAAE,IAAI,CAAC,EAAE;QAC1C,IAAI,KAAK,CAAC;QAGV,IAAA,WAAI,EAAC,CAAC,QAAQ,EAAE,QAAQ,EAAE,QAAQ,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAC;aACpD,IAAI,CAAC,IAAA,SAAG,EAAC,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;aACtB,SAAS,CAAC;YACT,IAAI,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,GAAG,EAAE,CAAC;YAC9B,QAAQ,EAAE,GAAG,EAAE;gBACb,MAAM,CAAC,UAAU,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;gBACpD,IAAI,EAAE,CAAC;YACT,CAAC;SACF,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
package/dist/indicator/swma.d.ts
CHANGED
|
@@ -1,10 +1,2 @@
|
|
|
1
1
|
import { Observable } from 'rxjs';
|
|
2
|
-
|
|
3
|
-
import { WindowIndicator } from './window-indicator';
|
|
4
|
-
export declare class SWMA extends WindowIndicator<number> {
|
|
5
|
-
private _value;
|
|
6
|
-
get value(): number;
|
|
7
|
-
constructor();
|
|
8
|
-
calculate(added: number, removed: number, buffer: RingBuffer<number>): void;
|
|
9
|
-
}
|
|
10
|
-
export declare function swma<T>(fn: (it: T) => number): (source: Observable<T>) => Observable<SWMA>;
|
|
2
|
+
export declare function swma<T>(fn: (it: T) => number): (source: Observable<T>) => Observable<[T, number]>;
|
package/dist/indicator/swma.js
CHANGED
|
@@ -1,34 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.swma =
|
|
3
|
+
exports.swma = void 0;
|
|
4
4
|
const operators_1 = require("rxjs/operators");
|
|
5
|
-
const
|
|
6
|
-
class SWMA extends window_indicator_1.WindowIndicator {
|
|
7
|
-
constructor() {
|
|
8
|
-
super(4);
|
|
9
|
-
}
|
|
10
|
-
get value() {
|
|
11
|
-
return this._value;
|
|
12
|
-
}
|
|
13
|
-
calculate(added, removed, buffer) {
|
|
14
|
-
if (!this.isCompleted) {
|
|
15
|
-
return;
|
|
16
|
-
}
|
|
17
|
-
const x3 = buffer.at(this.capacity - (3 + 1));
|
|
18
|
-
const x2 = buffer.at(this.capacity - (2 + 1));
|
|
19
|
-
const x1 = buffer.at(this.capacity - (1 + 1));
|
|
20
|
-
const x0 = buffer.at(this.capacity - (0 + 1));
|
|
21
|
-
this._value = (x3 * 1) / 6 + (x2 * 2) / 6 + (x1 * 2) / 6 + (x0 * 1) / 6;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
exports.SWMA = SWMA;
|
|
5
|
+
const window_1 = require("./window");
|
|
25
6
|
function swma(fn) {
|
|
26
7
|
return function (source) {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
8
|
+
return source.pipe((0, window_1.window)(4, fn), (0, operators_1.filter)(([, buffer]) => buffer.isFull), (0, operators_1.map)(([it, buffer]) => {
|
|
9
|
+
const x3 = buffer.at(buffer.capacity - (3 + 1));
|
|
10
|
+
const x2 = buffer.at(buffer.capacity - (2 + 1));
|
|
11
|
+
const x1 = buffer.at(buffer.capacity - (1 + 1));
|
|
12
|
+
const x0 = buffer.at(buffer.capacity - (0 + 1));
|
|
13
|
+
const value = (x3 * 1) / 6 + (x2 * 2) / 6 + (x1 * 2) / 6 + (x0 * 1) / 6;
|
|
14
|
+
const tuple = [it, value];
|
|
15
|
+
return tuple;
|
|
16
|
+
}), (0, operators_1.share)());
|
|
32
17
|
};
|
|
33
18
|
}
|
|
34
19
|
exports.swma = swma;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"swma.js","sourceRoot":"","sources":["../../src/indicator/swma.ts"],"names":[],"mappings":";;;AACA,8CAAoD;
|
|
1
|
+
{"version":3,"file":"swma.js","sourceRoot":"","sources":["../../src/indicator/swma.ts"],"names":[],"mappings":";;;AACA,8CAAoD;AACpD,qCAAkC;AAElC,SAAgB,IAAI,CAAI,EAAqB;IAC3C,OAAO,UAAU,MAAqB;QACpC,OAAO,MAAM,CAAC,IAAI,CAChB,IAAA,eAAM,EAAC,CAAC,EAAE,EAAE,CAAC,EACb,IAAA,kBAAM,EAAC,CAAC,CAAC,EAAE,MAAM,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,EACrC,IAAA,eAAG,EAAC,CAAC,CAAC,EAAE,EAAE,MAAM,CAAC,EAAE,EAAE;YACnB,MAAM,EAAE,GAAG,MAAM,CAAC,EAAE,CAAC,MAAM,CAAC,QAAQ,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;YAChD,MAAM,EAAE,GAAG,MAAM,CAAC,EAAE,CAAC,MAAM,CAAC,QAAQ,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;YAChD,MAAM,EAAE,GAAG,MAAM,CAAC,EAAE,CAAC,MAAM,CAAC,QAAQ,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;YAChD,MAAM,EAAE,GAAG,MAAM,CAAC,EAAE,CAAC,MAAM,CAAC,QAAQ,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;YAEhD,MAAM,KAAK,GAAG,CAAC,EAAE,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC;YAExE,MAAM,KAAK,GAAgB,CAAC,EAAE,EAAE,KAAK,CAAC,CAAC;YACvC,OAAO,KAAK,CAAC;QACf,CAAC,CAAC,EACF,IAAA,iBAAK,GAAE,CACR,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC;AAnBD,oBAmBC"}
|