@tradingaction/indicators 2.0.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/LICENSE +24 -0
- package/README.md +5 -0
- package/lib/calculator/atr.d.ts +18 -0
- package/lib/calculator/atr.js +51 -0
- package/lib/calculator/atr.js.map +1 -0
- package/lib/calculator/bollingerband.d.ts +14 -0
- package/lib/calculator/bollingerband.js +72 -0
- package/lib/calculator/bollingerband.js.map +1 -0
- package/lib/calculator/change.d.ts +14 -0
- package/lib/calculator/change.js +30 -0
- package/lib/calculator/change.js.map +1 -0
- package/lib/calculator/compare.d.ts +10 -0
- package/lib/calculator/compare.js +50 -0
- package/lib/calculator/compare.js.map +1 -0
- package/lib/calculator/defaultOptionsForComputation.d.ts +91 -0
- package/lib/calculator/defaultOptionsForComputation.js +100 -0
- package/lib/calculator/defaultOptionsForComputation.js.map +1 -0
- package/lib/calculator/elderRay.d.ts +23 -0
- package/lib/calculator/elderRay.js +69 -0
- package/lib/calculator/elderRay.js.map +1 -0
- package/lib/calculator/ema.d.ts +12 -0
- package/lib/calculator/ema.js +73 -0
- package/lib/calculator/ema.js.map +1 -0
- package/lib/calculator/forceIndex.d.ts +12 -0
- package/lib/calculator/forceIndex.js +27 -0
- package/lib/calculator/forceIndex.js.map +1 -0
- package/lib/calculator/heikinAshi.d.ts +4 -0
- package/lib/calculator/heikinAshi.js +30 -0
- package/lib/calculator/heikinAshi.js.map +1 -0
- package/lib/calculator/index.d.ts +19 -0
- package/lib/calculator/index.js +20 -0
- package/lib/calculator/index.js.map +1 -0
- package/lib/calculator/kagi.d.ts +11 -0
- package/lib/calculator/kagi.js +200 -0
- package/lib/calculator/kagi.js.map +1 -0
- package/lib/calculator/macd.d.ts +18 -0
- package/lib/calculator/macd.js +57 -0
- package/lib/calculator/macd.js.map +1 -0
- package/lib/calculator/pointAndFigure.d.ts +10 -0
- package/lib/calculator/pointAndFigure.js +215 -0
- package/lib/calculator/pointAndFigure.js.map +1 -0
- package/lib/calculator/renko.d.ts +12 -0
- package/lib/calculator/renko.js +170 -0
- package/lib/calculator/renko.js.map +1 -0
- package/lib/calculator/rsi.d.ts +12 -0
- package/lib/calculator/rsi.js +87 -0
- package/lib/calculator/rsi.js.map +1 -0
- package/lib/calculator/sar.d.ts +12 -0
- package/lib/calculator/sar.js +87 -0
- package/lib/calculator/sar.js.map +1 -0
- package/lib/calculator/sma.d.ts +12 -0
- package/lib/calculator/sma.js +27 -0
- package/lib/calculator/sma.js.map +1 -0
- package/lib/calculator/smoothedForceIndex.d.ts +13 -0
- package/lib/calculator/smoothedForceIndex.js +40 -0
- package/lib/calculator/smoothedForceIndex.js.map +1 -0
- package/lib/calculator/sto.d.ts +19 -0
- package/lib/calculator/sto.js +91 -0
- package/lib/calculator/sto.js.map +1 -0
- package/lib/calculator/tma.d.ts +12 -0
- package/lib/calculator/tma.js +66 -0
- package/lib/calculator/tma.js.map +1 -0
- package/lib/calculator/wma.d.ts +12 -0
- package/lib/calculator/wma.js +33 -0
- package/lib/calculator/wma.js.map +1 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.js +2 -0
- package/lib/index.js.map +1 -0
- package/lib/indicator/algorithm.d.ts +10 -0
- package/lib/indicator/algorithm.js +35 -0
- package/lib/indicator/algorithm.js.map +1 -0
- package/lib/indicator/atr.d.ts +26 -0
- package/lib/indicator/atr.js +27 -0
- package/lib/indicator/atr.js.map +1 -0
- package/lib/indicator/baseIndicator.d.ts +16 -0
- package/lib/indicator/baseIndicator.js +59 -0
- package/lib/indicator/baseIndicator.js.map +1 -0
- package/lib/indicator/bollingerBand.d.ts +24 -0
- package/lib/indicator/bollingerBand.js +27 -0
- package/lib/indicator/bollingerBand.js.map +1 -0
- package/lib/indicator/change.d.ts +24 -0
- package/lib/indicator/change.js +25 -0
- package/lib/indicator/change.js.map +1 -0
- package/lib/indicator/compare.d.ts +24 -0
- package/lib/indicator/compare.js +29 -0
- package/lib/indicator/compare.js.map +1 -0
- package/lib/indicator/defaultOptionsForAppearance.d.ts +105 -0
- package/lib/indicator/defaultOptionsForAppearance.js +77 -0
- package/lib/indicator/defaultOptionsForAppearance.js.map +1 -0
- package/lib/indicator/elderImpulse.d.ts +7 -0
- package/lib/indicator/elderImpulse.js +61 -0
- package/lib/indicator/elderImpulse.js.map +1 -0
- package/lib/indicator/elderRay.d.ts +24 -0
- package/lib/indicator/elderRay.js +29 -0
- package/lib/indicator/elderRay.js.map +1 -0
- package/lib/indicator/ema.d.ts +24 -0
- package/lib/indicator/ema.js +29 -0
- package/lib/indicator/ema.js.map +1 -0
- package/lib/indicator/forceIndex.d.ts +24 -0
- package/lib/indicator/forceIndex.js +29 -0
- package/lib/indicator/forceIndex.js.map +1 -0
- package/lib/indicator/heikinAshi.d.ts +3 -0
- package/lib/indicator/heikinAshi.js +28 -0
- package/lib/indicator/heikinAshi.js.map +1 -0
- package/lib/indicator/index.d.ts +23 -0
- package/lib/indicator/index.js +24 -0
- package/lib/indicator/index.js.map +1 -0
- package/lib/indicator/kagi.d.ts +11 -0
- package/lib/indicator/kagi.js +13 -0
- package/lib/indicator/kagi.js.map +1 -0
- package/lib/indicator/macd.d.ts +24 -0
- package/lib/indicator/macd.js +32 -0
- package/lib/indicator/macd.js.map +1 -0
- package/lib/indicator/pointAndFigure.d.ts +10 -0
- package/lib/indicator/pointAndFigure.js +13 -0
- package/lib/indicator/pointAndFigure.js.map +1 -0
- package/lib/indicator/renko.d.ts +12 -0
- package/lib/indicator/renko.js +13 -0
- package/lib/indicator/renko.js.map +1 -0
- package/lib/indicator/rsi.d.ts +24 -0
- package/lib/indicator/rsi.js +29 -0
- package/lib/indicator/rsi.js.map +1 -0
- package/lib/indicator/sar.d.ts +24 -0
- package/lib/indicator/sar.js +29 -0
- package/lib/indicator/sar.js.map +1 -0
- package/lib/indicator/sma.d.ts +24 -0
- package/lib/indicator/sma.js +29 -0
- package/lib/indicator/sma.js.map +1 -0
- package/lib/indicator/stochasticOscillator.d.ts +24 -0
- package/lib/indicator/stochasticOscillator.js +27 -0
- package/lib/indicator/stochasticOscillator.js.map +1 -0
- package/lib/indicator/tma.d.ts +24 -0
- package/lib/indicator/tma.js +29 -0
- package/lib/indicator/tma.js.map +1 -0
- package/lib/indicator/wma.d.ts +24 -0
- package/lib/indicator/wma.js +29 -0
- package/lib/indicator/wma.js.map +1 -0
- package/lib/utils/functor.d.ts +1 -0
- package/lib/utils/functor.js +4 -0
- package/lib/utils/functor.js.map +1 -0
- package/lib/utils/identity.d.ts +1 -0
- package/lib/utils/identity.js +2 -0
- package/lib/utils/identity.js.map +1 -0
- package/lib/utils/index.d.ts +8 -0
- package/lib/utils/index.js +9 -0
- package/lib/utils/index.js.map +1 -0
- package/lib/utils/mappedSlidingWindow.d.ts +15 -0
- package/lib/utils/mappedSlidingWindow.js +77 -0
- package/lib/utils/mappedSlidingWindow.js.map +1 -0
- package/lib/utils/merge.d.ts +11 -0
- package/lib/utils/merge.js +70 -0
- package/lib/utils/merge.js.map +1 -0
- package/lib/utils/path.d.ts +1 -0
- package/lib/utils/path.js +15 -0
- package/lib/utils/path.js.map +1 -0
- package/lib/utils/rebind.d.ts +1 -0
- package/lib/utils/rebind.js +18 -0
- package/lib/utils/rebind.js.map +1 -0
- package/lib/utils/slidingWindow.d.ts +19 -0
- package/lib/utils/slidingWindow.js +111 -0
- package/lib/utils/slidingWindow.js.map +1 -0
- package/lib/utils/zipper.d.ts +7 -0
- package/lib/utils/zipper.js +36 -0
- package/lib/utils/zipper.js.map +1 -0
- package/package.json +49 -0
- package/src/calculator/atr.ts +88 -0
- package/src/calculator/bollingerband.ts +102 -0
- package/src/calculator/change.ts +53 -0
- package/src/calculator/compare.ts +68 -0
- package/src/calculator/defaultOptionsForComputation.ts +117 -0
- package/src/calculator/elderRay.ts +90 -0
- package/src/calculator/ema.ts +92 -0
- package/src/calculator/forceIndex.ts +43 -0
- package/src/calculator/heikinAshi.ts +38 -0
- package/src/calculator/index.ts +19 -0
- package/src/calculator/kagi.ts +249 -0
- package/src/calculator/macd.ts +90 -0
- package/src/calculator/pointAndFigure.ts +255 -0
- package/src/calculator/renko.ts +227 -0
- package/src/calculator/rsi.ts +114 -0
- package/src/calculator/sar.ts +117 -0
- package/src/calculator/sma.ts +41 -0
- package/src/calculator/smoothedForceIndex.ts +53 -0
- package/src/calculator/sto.ts +118 -0
- package/src/calculator/tma.ts +82 -0
- package/src/calculator/wma.ts +49 -0
- package/src/index.ts +1 -0
- package/src/indicator/algorithm.ts +53 -0
- package/src/indicator/atr.ts +58 -0
- package/src/indicator/baseIndicator.ts +97 -0
- package/src/indicator/bollingerBand.ts +55 -0
- package/src/indicator/change.ts +51 -0
- package/src/indicator/compare.ts +57 -0
- package/src/indicator/defaultOptionsForAppearance.ts +77 -0
- package/src/indicator/elderImpulse.ts +73 -0
- package/src/indicator/elderRay.ts +56 -0
- package/src/indicator/ema.ts +58 -0
- package/src/indicator/forceIndex.ts +57 -0
- package/src/indicator/heikinAshi.ts +35 -0
- package/src/indicator/index.ts +25 -0
- package/src/indicator/kagi.ts +18 -0
- package/src/indicator/macd.ts +60 -0
- package/src/indicator/pointAndFigure.ts +18 -0
- package/src/indicator/renko.ts +18 -0
- package/src/indicator/rsi.ts +58 -0
- package/src/indicator/sar.ts +56 -0
- package/src/indicator/sma.ts +57 -0
- package/src/indicator/stochasticOscillator.ts +56 -0
- package/src/indicator/tma.ts +57 -0
- package/src/indicator/wma.ts +58 -0
- package/src/utils/functor.ts +3 -0
- package/src/utils/identity.ts +1 -0
- package/src/utils/index.ts +8 -0
- package/src/utils/mappedSlidingWindow.ts +95 -0
- package/src/utils/merge.ts +93 -0
- package/src/utils/path.ts +16 -0
- package/src/utils/rebind.ts +19 -0
- package/src/utils/slidingWindow.ts +142 -0
- package/src/utils/zipper.ts +45 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
https://github.com/reactivemarkets/react-financial-charts
|
|
3
|
+
|
|
4
|
+
Copyright (c) 2015-2018 Ragu Ramaswamy
|
|
5
|
+
Copyright (c) 2016 Julien Renaux
|
|
6
|
+
Copyright (c) 2019 Reactive Markets
|
|
7
|
+
|
|
8
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
9
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
10
|
+
in the Software without restriction, including without limitation the rights
|
|
11
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
12
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
13
|
+
furnished to do so, subject to the following conditions:
|
|
14
|
+
|
|
15
|
+
The above copyright notice and this permission notice shall be included in
|
|
16
|
+
all copies or substantial portions of the Software.
|
|
17
|
+
|
|
18
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
19
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
20
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
21
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
22
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
23
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
24
|
+
THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export interface ATROptions {
|
|
2
|
+
readonly windowSize: number;
|
|
3
|
+
}
|
|
4
|
+
export interface ATRSource {
|
|
5
|
+
readonly close: number;
|
|
6
|
+
readonly high: number;
|
|
7
|
+
readonly low: number;
|
|
8
|
+
readonly open: number;
|
|
9
|
+
}
|
|
10
|
+
export interface ATRCalculator {
|
|
11
|
+
(data: any[]): any;
|
|
12
|
+
undefinedLength(): number;
|
|
13
|
+
options(): ATROptions;
|
|
14
|
+
options(newOptions: ATROptions): ATRCalculator;
|
|
15
|
+
source(): (d: any) => ATRSource;
|
|
16
|
+
source(newSource: (d: any) => ATRSource): ATRCalculator;
|
|
17
|
+
}
|
|
18
|
+
export default function (): ATRCalculator;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { sum } from "d3-array";
|
|
2
|
+
import { slidingWindow } from "../utils";
|
|
3
|
+
import { ATR as defaultOptions } from "./defaultOptionsForComputation";
|
|
4
|
+
export default function () {
|
|
5
|
+
let options = defaultOptions;
|
|
6
|
+
let source = (d) => ({ open: d.open, high: d.high, low: d.low, close: d.close });
|
|
7
|
+
const calculator = (data) => {
|
|
8
|
+
const { windowSize } = options;
|
|
9
|
+
const trueRangeAlgorithm = slidingWindow()
|
|
10
|
+
.windowSize(2)
|
|
11
|
+
.source(source)
|
|
12
|
+
.undefinedValue((d) => d.high - d.low) // the first TR value is simply the High minus the Low
|
|
13
|
+
.accumulator((values) => {
|
|
14
|
+
const prev = values[0];
|
|
15
|
+
const d = values[1];
|
|
16
|
+
return Math.max(d.high - d.low, d.high - prev.close, d.low - prev.close);
|
|
17
|
+
});
|
|
18
|
+
let prevATR;
|
|
19
|
+
const atrAlgorithm = slidingWindow()
|
|
20
|
+
.skipInitial(1) // trueRange starts from index 1 so ATR starts from 1
|
|
21
|
+
.windowSize(windowSize)
|
|
22
|
+
.accumulator((values) => {
|
|
23
|
+
const tr = values[values.length - 1];
|
|
24
|
+
const atr = prevATR !== undefined ? (prevATR * (windowSize - 1) + tr) / windowSize : sum(values) / windowSize;
|
|
25
|
+
prevATR = atr;
|
|
26
|
+
return atr;
|
|
27
|
+
});
|
|
28
|
+
const newData = atrAlgorithm(trueRangeAlgorithm(data));
|
|
29
|
+
return newData;
|
|
30
|
+
};
|
|
31
|
+
calculator.undefinedLength = () => {
|
|
32
|
+
const { windowSize } = options;
|
|
33
|
+
return windowSize - 1;
|
|
34
|
+
};
|
|
35
|
+
calculator.options = (newOptions) => {
|
|
36
|
+
if (newOptions === undefined) {
|
|
37
|
+
return options;
|
|
38
|
+
}
|
|
39
|
+
options = Object.assign(Object.assign({}, defaultOptions), newOptions);
|
|
40
|
+
return calculator;
|
|
41
|
+
};
|
|
42
|
+
calculator.source = (newSource) => {
|
|
43
|
+
if (newSource === undefined) {
|
|
44
|
+
return source;
|
|
45
|
+
}
|
|
46
|
+
source = newSource;
|
|
47
|
+
return calculator;
|
|
48
|
+
};
|
|
49
|
+
return calculator;
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=atr.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"atr.js","sourceRoot":"","sources":["../../src/calculator/atr.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAC/B,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,GAAG,IAAI,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAsBvE,MAAM,CAAC,OAAO;IACV,IAAI,OAAO,GAAe,cAAc,CAAC;IACzC,IAAI,MAAM,GAAG,CAAC,CAAM,EAAE,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,GAAG,EAAE,CAAC,CAAC,GAAG,EAAE,KAAK,EAAE,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC;IAEtF,MAAM,UAAU,GAAG,CAAC,IAAW,EAAE,EAAE;QAC/B,MAAM,EAAE,UAAU,EAAE,GAAG,OAAO,CAAC;QAE/B,MAAM,kBAAkB,GAAG,aAAa,EAAE;aACrC,UAAU,CAAC,CAAC,CAAC;aACb,MAAM,CAAC,MAAM,CAAC;aACd,cAAc,CAAC,CAAC,CAAM,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,sDAAsD;aACjG,WAAW,CAAC,CAAC,MAAW,EAAE,EAAE;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CAAC;SAClB;QAED,OAAO,mCAAQ,cAAc,GAAK,UAAU,CAAE,CAAC;QAE/C,OAAO,UAAU,CAAC;IACtB,CAAC,CAAC;IAEF,UAAU,CAAC,MAAM,GAAG,CAAC,SAAiC,EAAE,EAAE;QACtD,IAAI,SAAS,KAAK,SAAS,EAAE;YACzB,OAAO,MAAM,CAAC;SACjB;QAED,MAAM,GAAG,SAAS,CAAC;QAEnB,OAAO,UAAU,CAAC;IACtB,CAAC,CAAC;IAEF,OAAO,UAA2B,CAAC;AACvC,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export interface BollingerBandOptions {
|
|
2
|
+
readonly windowSize: number;
|
|
3
|
+
readonly sourcePath: string;
|
|
4
|
+
readonly multiplier: number;
|
|
5
|
+
readonly movingAverageType: string;
|
|
6
|
+
}
|
|
7
|
+
interface BollingerBandCalculator {
|
|
8
|
+
(data: any[]): any;
|
|
9
|
+
undefinedLength(): number;
|
|
10
|
+
options(): BollingerBandOptions;
|
|
11
|
+
options(newOptions: BollingerBandOptions): BollingerBandCalculator;
|
|
12
|
+
}
|
|
13
|
+
export default function (): BollingerBandCalculator;
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/*
|
|
2
|
+
https://github.com/ScottLogic/d3fc/blob/master/src/indicator/algorithm/calculator/bollingerBands.js
|
|
3
|
+
|
|
4
|
+
The MIT License (MIT)
|
|
5
|
+
|
|
6
|
+
Copyright (c) 2014-2015 Scott Logic Ltd.
|
|
7
|
+
|
|
8
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
9
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
10
|
+
in the Software without restriction, including without limitation the rights
|
|
11
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
12
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
13
|
+
furnished to do so, subject to the following conditions:
|
|
14
|
+
|
|
15
|
+
The above copyright notice and this permission notice shall be included in
|
|
16
|
+
all copies or substantial portions of the Software.
|
|
17
|
+
|
|
18
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
19
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
20
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
21
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
22
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
23
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
24
|
+
THE SOFTWARE.
|
|
25
|
+
*/
|
|
26
|
+
import { deviation, mean } from "d3-array";
|
|
27
|
+
import { path, slidingWindow, zipper } from "../utils";
|
|
28
|
+
import ema from "./ema";
|
|
29
|
+
import { BollingerBand as defaultOptions } from "./defaultOptionsForComputation";
|
|
30
|
+
export default function () {
|
|
31
|
+
let options = defaultOptions;
|
|
32
|
+
const calculator = (data) => {
|
|
33
|
+
const { windowSize, multiplier, movingAverageType, sourcePath } = options;
|
|
34
|
+
const source = path(sourcePath);
|
|
35
|
+
const meanAlgorithm = movingAverageType === "ema"
|
|
36
|
+
? ema().options({ windowSize, sourcePath })
|
|
37
|
+
: slidingWindow()
|
|
38
|
+
.windowSize(windowSize)
|
|
39
|
+
.accumulator((values) => mean(values))
|
|
40
|
+
.sourcePath(sourcePath);
|
|
41
|
+
const bollingerBandAlgorithm = slidingWindow()
|
|
42
|
+
.windowSize(windowSize)
|
|
43
|
+
.accumulator((values) => {
|
|
44
|
+
const avg = values[values.length - 1].mean;
|
|
45
|
+
const stdDev = deviation(values, (each) => source(each.datum));
|
|
46
|
+
if (stdDev === undefined) {
|
|
47
|
+
return undefined;
|
|
48
|
+
}
|
|
49
|
+
return {
|
|
50
|
+
top: avg + multiplier * stdDev,
|
|
51
|
+
middle: avg,
|
|
52
|
+
bottom: avg - multiplier * stdDev,
|
|
53
|
+
};
|
|
54
|
+
});
|
|
55
|
+
const zip = zipper().combine((datum, meanValue) => ({ datum, mean: meanValue }));
|
|
56
|
+
const tuples = zip(data, meanAlgorithm(data));
|
|
57
|
+
return bollingerBandAlgorithm(tuples);
|
|
58
|
+
};
|
|
59
|
+
calculator.undefinedLength = () => {
|
|
60
|
+
const { windowSize } = options;
|
|
61
|
+
return windowSize - 1;
|
|
62
|
+
};
|
|
63
|
+
calculator.options = (newOptions) => {
|
|
64
|
+
if (newOptions === undefined) {
|
|
65
|
+
return options;
|
|
66
|
+
}
|
|
67
|
+
options = Object.assign(Object.assign({}, defaultOptions), newOptions);
|
|
68
|
+
return calculator;
|
|
69
|
+
};
|
|
70
|
+
return calculator;
|
|
71
|
+
}
|
|
72
|
+
//# sourceMappingURL=bollingerband.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bollingerband.js","sourceRoot":"","sources":["../../src/calculator/bollingerband.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;EAwBE;AAEF,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAC3C,OAAO,EAAE,IAAI,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AACvD,OAAO,GAAG,MAAM,OAAO,CAAC;AACxB,OAAO,EAAE,aAAa,IAAI,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAgBjF,MAAM,CAAC,OAAO;IACV,IAAI,OAAO,GAAyB,cAAc,CAAC;IAEnD,MAAM,UAAU,GAAG,CAAC,IAAW,EAAE,EAAE;QAC/B,MAAM,EAAE,UAAU,EAAE,UAAU,EAAE,iBAAiB,EAAE,UAAU,EAAE,GAAG,OAAO,CAAC;QAE1E,MAAM,MAAM,GAAG,IAAI,CAAC,UAAU,CAAC,CAAC;QAEhC,M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AM,EAAE,UAAU,EAAE,GAAG,OAAO,CAAC;QAE/B,OAAO,UAAU,GAAG,CAAC,CAAC;IAC1B,CAAC,CAAC;IAEF,UAAU,CAAC,OAAO,GAAG,CAAC,UAAiC,EAAE,EAAE;QACvD,IAAI,UAAU,KAAK,SAAS,EAAE;YAC1B,OAAO,OAAO,CAAC;SAClB;QAED,OAAO,mCAAQ,cAAc,GAAK,UAAU,CAAE,CAAC;QAE/C,OAAO,UAAU,CAAC;IACtB,CAAC,CAAC;IAEF,OAAO,UAAqC,CAAC;AACjD,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export interface ChangeOptions {
|
|
2
|
+
readonly sourcePath: string;
|
|
3
|
+
readonly basePath: string;
|
|
4
|
+
readonly mainKeys: string[];
|
|
5
|
+
readonly compareKeys: string[];
|
|
6
|
+
}
|
|
7
|
+
interface ChangeCalculator {
|
|
8
|
+
(data: any[]): any;
|
|
9
|
+
undefinedLength(): number;
|
|
10
|
+
options(): ChangeOptions;
|
|
11
|
+
options(newOptions: ChangeOptions): ChangeCalculator;
|
|
12
|
+
}
|
|
13
|
+
export default function (): ChangeCalculator;
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { slidingWindow } from "../utils";
|
|
2
|
+
import { Change as defaultOptions } from "./defaultOptionsForComputation";
|
|
3
|
+
export default function () {
|
|
4
|
+
let options = defaultOptions;
|
|
5
|
+
const calculator = (data) => {
|
|
6
|
+
const { sourcePath } = options;
|
|
7
|
+
const algo = slidingWindow()
|
|
8
|
+
.windowSize(2)
|
|
9
|
+
.sourcePath(sourcePath)
|
|
10
|
+
.accumulator(([prev, curr]) => {
|
|
11
|
+
const absoluteChange = curr - prev;
|
|
12
|
+
const percentChange = (absoluteChange * 100) / prev;
|
|
13
|
+
return { absoluteChange, percentChange };
|
|
14
|
+
});
|
|
15
|
+
const newData = algo(data);
|
|
16
|
+
return newData;
|
|
17
|
+
};
|
|
18
|
+
calculator.undefinedLength = () => {
|
|
19
|
+
return 1;
|
|
20
|
+
};
|
|
21
|
+
calculator.options = (newOptions) => {
|
|
22
|
+
if (newOptions === undefined) {
|
|
23
|
+
return options;
|
|
24
|
+
}
|
|
25
|
+
options = Object.assign(Object.assign({}, defaultOptions), newOptions);
|
|
26
|
+
return calculator;
|
|
27
|
+
};
|
|
28
|
+
return calculator;
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=change.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"change.js","sourceRoot":"","sources":["../../src/calculator/change.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,MAAM,IAAI,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAgB1E,MAAM,CAAC,OAAO;IACV,IAAI,OAAO,GAAkB,cAAc,CAAC;IAE5C,MAAM,UAAU,GAAG,CAAC,IAAW,EAAE,EAAE;QAC/B,MAAM,EAAE,UAAU,EAAE,GAAG,OAAO,CAAC;QAE/B,MAAM,IAAI,GAAG,aAAa,EAAE;aACvB,UAAU,CAAC,CAAC,CAAC;aACb,UAAU,CAAC,UAAU,CAAC;aACtB,WAAW,CAAC,CAAC,CAAC,IAAI,EAAE,IAAI,CAAM,EAAE,EAAE;YAC/B,MAAM,cAAc,GAAG,IAAI,GAAG,IAAI,CAAC;YACnC,MAAM,aAAa,GAAG,CAAC,cAAc,GAAG,GAAG,CAAC,GAAG,IAAI,CAAC;YACpD,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,CAAC;QAC7C,CAAC,CAAC,CAAC;QAEP,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC;QAE3B,OAAO,OAAO,CAAC;IACnB,CAAC,CAAC;IAEF,UAAU,CAAC,eAAe,GAAG,GAAG,EAAE;QAC9B,OAAO,CAAC,CAAC;IACb,CAAC,CAAC;IAEF,UAAU,CAAC,OAAO,GAAG,CAAC,UAA0B,EAAE,EAAE;QAChD,IAAI,UAAU,KAAK,SAAS,EAAE;YAC1B,OAAO,OAAO,CAAC;SAClB;QAED,OAAO,mCAAQ,cAAc,GAAK,UAAU,CAAE,CAAC;QAE/C,OAAO,UAAU,CAAC;IACtB,CAAC,CAAC;IAEF,OAAO,UAA8B,CAAC;AAC1C,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export interface CompareOptions {
|
|
2
|
+
readonly basePath: string;
|
|
3
|
+
readonly compareKeys: string[];
|
|
4
|
+
readonly mainKeys: string[];
|
|
5
|
+
readonly sourcePath?: string;
|
|
6
|
+
}
|
|
7
|
+
export default function (): {
|
|
8
|
+
(data: any[]): {}[];
|
|
9
|
+
options(newOptions?: CompareOptions): CompareOptions | any;
|
|
10
|
+
};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { path } from "../utils";
|
|
2
|
+
import { Change as defaultOptions } from "./defaultOptionsForComputation";
|
|
3
|
+
export default function () {
|
|
4
|
+
let options = defaultOptions;
|
|
5
|
+
const calculator = (data) => {
|
|
6
|
+
const { basePath, mainKeys, compareKeys } = options;
|
|
7
|
+
const base = path(basePath);
|
|
8
|
+
const first = data[0];
|
|
9
|
+
const b = base(first);
|
|
10
|
+
const firsts = {};
|
|
11
|
+
const compareData = data.map((d) => {
|
|
12
|
+
const result = {};
|
|
13
|
+
mainKeys.forEach((key) => {
|
|
14
|
+
if (typeof d[key] === "object") {
|
|
15
|
+
// @ts-ignore
|
|
16
|
+
result[key] = {};
|
|
17
|
+
Object.keys(d[key]).forEach((subkey) => {
|
|
18
|
+
// @ts-ignore
|
|
19
|
+
result[key][subkey] = (d[key][subkey] - b) / b;
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
// @ts-ignore
|
|
24
|
+
result[key] = (d[key] - b) / b;
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
compareKeys.forEach((key) => {
|
|
28
|
+
if (d[key] !== undefined && firsts[key] === undefined) {
|
|
29
|
+
// @ts-ignore
|
|
30
|
+
firsts[key] = d[key];
|
|
31
|
+
}
|
|
32
|
+
if (d[key] !== undefined && firsts[key] !== undefined) {
|
|
33
|
+
// @ts-ignore
|
|
34
|
+
result[key] = (d[key] - firsts[key]) / firsts[key];
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
return result;
|
|
38
|
+
});
|
|
39
|
+
return compareData;
|
|
40
|
+
};
|
|
41
|
+
calculator.options = (newOptions) => {
|
|
42
|
+
if (newOptions === undefined) {
|
|
43
|
+
return options;
|
|
44
|
+
}
|
|
45
|
+
options = Object.assign(Object.assign({}, defaultOptions), newOptions);
|
|
46
|
+
return calculator;
|
|
47
|
+
};
|
|
48
|
+
return calculator;
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=compare.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compare.js","sourceRoot":"","sources":["../../src/calculator/compare.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAChC,OAAO,EAAE,MAAM,IAAI,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAS1E,MAAM,CAAC,OAAO;IACV,IAAI,OAAO,GAAmB,cAAc,CAAC;IAE7C,MAAM,UAAU,GAAG,CAAC,IAAW,EAAE,EAAE;QAC/B,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,WAAW,EAAE,GAAG,OAAO,CAAC;QAEpD,MAAM,IAAI,GAAG,IAAI,CAAC,QAAQ,CAAC,CAAC;QAE5B,MAAM,KAAK,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;QACtB,MAAM,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC;QAEtB,MAAM,MAAM,GAAQ,EAAE,CAAC;QAEvB,MAAM,WAAW,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE;YAC/B,MAAM,MAAM,GAAG,EAAE,CAAC;YAElB,Q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C,OAAO,GAAG,CAAC,UAA2B,EAAE,EAAE;QACjD,IAAI,UAAU,KAAK,SAAS,EAAE;YAC1B,OAAO,OAAO,CAAC;SAClB;QAED,OAAO,mCAAQ,cAAc,GAAK,UAAU,CAAE,CAAC;QAE/C,OAAO,UAAU,CAAC;IACtB,CAAC,CAAC;IAEF,OAAO,UAAU,CAAC;AACtB,CAAC"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
export declare const BollingerBand: {
|
|
2
|
+
windowSize: number;
|
|
3
|
+
sourcePath: string;
|
|
4
|
+
multiplier: number;
|
|
5
|
+
movingAverageType: string;
|
|
6
|
+
};
|
|
7
|
+
export declare const ATR: {
|
|
8
|
+
windowSize: number;
|
|
9
|
+
};
|
|
10
|
+
export declare const ForceIndex: {
|
|
11
|
+
sourcePath: string;
|
|
12
|
+
volumePath: string;
|
|
13
|
+
};
|
|
14
|
+
export declare const SmoothedForceIndex: {
|
|
15
|
+
sourcePath: string;
|
|
16
|
+
volumePath: string;
|
|
17
|
+
smoothingType: string;
|
|
18
|
+
smoothingWindow: number;
|
|
19
|
+
};
|
|
20
|
+
export declare const Change: {
|
|
21
|
+
sourcePath: string;
|
|
22
|
+
basePath: string;
|
|
23
|
+
mainKeys: never[];
|
|
24
|
+
compareKeys: never[];
|
|
25
|
+
};
|
|
26
|
+
export declare const Compare: {
|
|
27
|
+
basePath: string;
|
|
28
|
+
mainKeys: string[];
|
|
29
|
+
compareKeys: never[];
|
|
30
|
+
};
|
|
31
|
+
export declare const ElderRay: {
|
|
32
|
+
windowSize: number;
|
|
33
|
+
sourcePath: string;
|
|
34
|
+
movingAverageType: string;
|
|
35
|
+
};
|
|
36
|
+
export declare const ElderImpulse: {
|
|
37
|
+
sourcePath: string;
|
|
38
|
+
};
|
|
39
|
+
export declare const SAR: {
|
|
40
|
+
accelerationFactor: number;
|
|
41
|
+
maxAccelerationFactor: number;
|
|
42
|
+
};
|
|
43
|
+
export declare const MACD: {
|
|
44
|
+
fast: number;
|
|
45
|
+
slow: number;
|
|
46
|
+
signal: number;
|
|
47
|
+
sourcePath: string;
|
|
48
|
+
};
|
|
49
|
+
export declare const FullStochasticOscillator: {
|
|
50
|
+
windowSize: number;
|
|
51
|
+
kWindowSize: number;
|
|
52
|
+
dWindowSize: number;
|
|
53
|
+
};
|
|
54
|
+
export declare const RSI: {
|
|
55
|
+
windowSize: number;
|
|
56
|
+
sourcePath: string;
|
|
57
|
+
};
|
|
58
|
+
export declare const EMA: {
|
|
59
|
+
sourcePath: string;
|
|
60
|
+
windowSize: number;
|
|
61
|
+
};
|
|
62
|
+
export declare const SMA: {
|
|
63
|
+
sourcePath: string;
|
|
64
|
+
windowSize: number;
|
|
65
|
+
};
|
|
66
|
+
export declare const WMA: {
|
|
67
|
+
sourcePath: string;
|
|
68
|
+
windowSize: number;
|
|
69
|
+
};
|
|
70
|
+
export declare const TMA: {
|
|
71
|
+
sourcePath: string;
|
|
72
|
+
windowSize: number;
|
|
73
|
+
};
|
|
74
|
+
export declare const Kagi: {
|
|
75
|
+
reversalType: string;
|
|
76
|
+
windowSize: number;
|
|
77
|
+
reversal: number;
|
|
78
|
+
sourcePath: string;
|
|
79
|
+
};
|
|
80
|
+
export declare const Renko: {
|
|
81
|
+
reversalType: string;
|
|
82
|
+
windowSize: number;
|
|
83
|
+
fixedBrickSize: number;
|
|
84
|
+
sourcePath: string;
|
|
85
|
+
percentage: number;
|
|
86
|
+
};
|
|
87
|
+
export declare const PointAndFigure: {
|
|
88
|
+
boxSize: number;
|
|
89
|
+
reversal: number;
|
|
90
|
+
sourcePath: string;
|
|
91
|
+
};
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
export const BollingerBand = {
|
|
2
|
+
windowSize: 20,
|
|
3
|
+
// source: d => d.close, // "high", "low", "open", "close"
|
|
4
|
+
sourcePath: "close",
|
|
5
|
+
multiplier: 2,
|
|
6
|
+
movingAverageType: "sma",
|
|
7
|
+
};
|
|
8
|
+
export const ATR = {
|
|
9
|
+
windowSize: 14,
|
|
10
|
+
};
|
|
11
|
+
export const ForceIndex = {
|
|
12
|
+
sourcePath: "close",
|
|
13
|
+
volumePath: "volume",
|
|
14
|
+
};
|
|
15
|
+
export const SmoothedForceIndex = {
|
|
16
|
+
sourcePath: "close",
|
|
17
|
+
volumePath: "volume",
|
|
18
|
+
smoothingType: "ema",
|
|
19
|
+
smoothingWindow: 13,
|
|
20
|
+
};
|
|
21
|
+
export const Change = {
|
|
22
|
+
sourcePath: "close",
|
|
23
|
+
basePath: "close",
|
|
24
|
+
mainKeys: [],
|
|
25
|
+
compareKeys: [],
|
|
26
|
+
};
|
|
27
|
+
export const Compare = {
|
|
28
|
+
basePath: "close",
|
|
29
|
+
mainKeys: ["open", "high", "low", "close"],
|
|
30
|
+
compareKeys: [],
|
|
31
|
+
};
|
|
32
|
+
export const ElderRay = {
|
|
33
|
+
windowSize: 13,
|
|
34
|
+
// source: d => d.close, // "high", "low", "open", "close"
|
|
35
|
+
sourcePath: "close",
|
|
36
|
+
movingAverageType: "sma",
|
|
37
|
+
};
|
|
38
|
+
export const ElderImpulse = {
|
|
39
|
+
sourcePath: "close", // "high", "low", "open", "close"
|
|
40
|
+
};
|
|
41
|
+
export const SAR = {
|
|
42
|
+
accelerationFactor: 0.02,
|
|
43
|
+
maxAccelerationFactor: 0.2,
|
|
44
|
+
};
|
|
45
|
+
export const MACD = {
|
|
46
|
+
fast: 12,
|
|
47
|
+
slow: 26,
|
|
48
|
+
signal: 9,
|
|
49
|
+
// source: d => d.close, // "high", "low", "open", "close"
|
|
50
|
+
sourcePath: "close",
|
|
51
|
+
};
|
|
52
|
+
export const FullStochasticOscillator = {
|
|
53
|
+
windowSize: 12,
|
|
54
|
+
kWindowSize: 3,
|
|
55
|
+
dWindowSize: 3,
|
|
56
|
+
};
|
|
57
|
+
export const RSI = {
|
|
58
|
+
windowSize: 14,
|
|
59
|
+
// source: d => d.close, // "high", "low", "open", "close"
|
|
60
|
+
sourcePath: "close", // "high", "low", "open", "close"
|
|
61
|
+
};
|
|
62
|
+
export const EMA = {
|
|
63
|
+
// source: d => d.close, // "high", "low", "open", "close"
|
|
64
|
+
sourcePath: "close",
|
|
65
|
+
windowSize: 10,
|
|
66
|
+
};
|
|
67
|
+
export const SMA = {
|
|
68
|
+
// source: d => d.close, // "high", "low", "open", "close"
|
|
69
|
+
sourcePath: "close",
|
|
70
|
+
windowSize: 10,
|
|
71
|
+
};
|
|
72
|
+
export const WMA = {
|
|
73
|
+
// source: d => d.close, // "high", "low", "open", "close"
|
|
74
|
+
sourcePath: "close",
|
|
75
|
+
windowSize: 10,
|
|
76
|
+
};
|
|
77
|
+
export const TMA = {
|
|
78
|
+
// source: d => d.close, // "high", "low", "open", "close"
|
|
79
|
+
sourcePath: "close",
|
|
80
|
+
windowSize: 10,
|
|
81
|
+
};
|
|
82
|
+
export const Kagi = {
|
|
83
|
+
reversalType: "ATR",
|
|
84
|
+
windowSize: 14,
|
|
85
|
+
reversal: 2,
|
|
86
|
+
sourcePath: "close", // "high", "low", "open", "close"
|
|
87
|
+
};
|
|
88
|
+
export const Renko = {
|
|
89
|
+
reversalType: "ATR",
|
|
90
|
+
windowSize: 14,
|
|
91
|
+
fixedBrickSize: 2,
|
|
92
|
+
sourcePath: "high/low",
|
|
93
|
+
percentage: 1,
|
|
94
|
+
};
|
|
95
|
+
export const PointAndFigure = {
|
|
96
|
+
boxSize: 0.5,
|
|
97
|
+
reversal: 3,
|
|
98
|
+
sourcePath: "high/low", // "close", "high/low"
|
|
99
|
+
};
|
|
100
|
+
//# sourceMappingURL=defaultOptionsForComputation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defaultOptionsForComputation.js","sourceRoot":"","sources":["../../src/calculator/defaultOptionsForComputation.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,aAAa,GAAG;IACzB,UAAU,EAAE,EAAE;IACd,0DAA0D;IAC1D,UAAU,EAAE,OAAO;IACnB,UAAU,EAAE,CAAC;IACb,i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CAAC;IACd,WAAW,EAAE,CAAC;CACjB,CAAC;AAEF,MAAM,CAAC,MAAM,GAAG,GAAG;IACf,UAAU,EAAE,EAAE;IACd,0DAA0D;IAC1D,UAAU,EAAE,OAAO,EAAE,iCAAiC;CACzD,CAAC;AAEF,MAAM,CAAC,MAAM,GAAG,GAAG;IACf,0DAA0D;IAC1D,UAAU,EAAE,OAAO;IACnB,UAAU,EAAE,EAAE;CACjB,CAAC;AAEF,MAAM,CAAC,MAAM,GAAG,GAAG;IACf,0DAA0D;IAC1D,UAAU,EAAE,OAAO;IACnB,UAAU,EAAE,EAAE;CACjB,CAAC;AAEF,MAAM,CAAC,MAAM,GAAG,GAAG;IACf,0DAA0D;IAC1D,UAAU,EAAE,OAAO;IACnB,UAAU,EAAE,EAAE;CACjB,CAAC;AAEF,MAAM,CAAC,MAAM,GAAG,GAAG;IACf,0DAA0D;IAC1D,UAAU,EAAE,OAAO;IACnB,UAAU,EAAE,EAAE;CACjB,CAAC;AAEF,MAAM,CAAC,MAAM,IAAI,GAAG;IAChB,YAAY,EAAE,KAAK;IACnB,UAAU,EAAE,EAAE;IACd,QAAQ,EAAE,CAAC;IACX,UAAU,EAAE,OAAO,EAAE,iCAAiC;CACzD,CAAC;AAEF,MAAM,CAAC,MAAM,KAAK,GAAG;IACjB,YAAY,EAAE,KAAK;IACnB,UAAU,EAAE,EAAE;IACd,cAAc,EAAE,CAAC;IACjB,UAAU,EAAE,UAAU;IACtB,UAAU,EAAE,CAAC;CAChB,CAAC;AAEF,MAAM,CAAC,MAAM,cAAc,GAAG;IAC1B,OAAO,EAAE,GAAG;IACZ,QAAQ,EAAE,CAAC;IACX,UAAU,EAAE,UAAU,EAAE,sBAAsB;CACjD,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export interface ElderRayOptions {
|
|
2
|
+
readonly movingAverageType: string;
|
|
3
|
+
readonly sourcePath: string;
|
|
4
|
+
readonly windowSize: number;
|
|
5
|
+
}
|
|
6
|
+
export default function (): {
|
|
7
|
+
(data: any[]): {
|
|
8
|
+
bullPower: number | undefined;
|
|
9
|
+
bearPower: number | undefined;
|
|
10
|
+
}[];
|
|
11
|
+
undefinedLength(): number;
|
|
12
|
+
ohlc(ohlcAccessor?: ((d: any) => any) | undefined): ((d: any) => {
|
|
13
|
+
open: any;
|
|
14
|
+
high: any;
|
|
15
|
+
low: any;
|
|
16
|
+
close: any;
|
|
17
|
+
}) | any;
|
|
18
|
+
options(newOptions?: ElderRayOptions): {
|
|
19
|
+
windowSize: number;
|
|
20
|
+
sourcePath: string;
|
|
21
|
+
movingAverageType: string;
|
|
22
|
+
} | any;
|
|
23
|
+
};
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/*
|
|
2
|
+
https://github.com/ScottLogic/d3fc/blob/master/src/indicator/algorithm/calculator/elderRay.js
|
|
3
|
+
|
|
4
|
+
The MIT License (MIT)
|
|
5
|
+
|
|
6
|
+
Copyright (c) 2014-2015 Scott Logic Ltd.
|
|
7
|
+
|
|
8
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
9
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
10
|
+
in the Software without restriction, including without limitation the rights
|
|
11
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
12
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
13
|
+
furnished to do so, subject to the following conditions:
|
|
14
|
+
|
|
15
|
+
The above copyright notice and this permission notice shall be included in
|
|
16
|
+
all copies or substantial portions of the Software.
|
|
17
|
+
|
|
18
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
19
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
20
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
21
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
22
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
23
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
24
|
+
THE SOFTWARE.
|
|
25
|
+
*/
|
|
26
|
+
import { mean, zip } from "d3-array";
|
|
27
|
+
import { slidingWindow } from "../utils";
|
|
28
|
+
import ema from "./ema";
|
|
29
|
+
import { ElderRay as defaultOptions } from "./defaultOptionsForComputation";
|
|
30
|
+
export default function () {
|
|
31
|
+
let options = defaultOptions;
|
|
32
|
+
let ohlc = (d) => ({ open: d.open, high: d.high, low: d.low, close: d.close });
|
|
33
|
+
const calculator = (data) => {
|
|
34
|
+
const { windowSize, sourcePath, movingAverageType } = options;
|
|
35
|
+
const meanAlgorithm = movingAverageType === "ema"
|
|
36
|
+
? ema().options({ windowSize, sourcePath })
|
|
37
|
+
: slidingWindow()
|
|
38
|
+
.windowSize(windowSize)
|
|
39
|
+
.accumulator((values) => mean(values))
|
|
40
|
+
.sourcePath(sourcePath);
|
|
41
|
+
return zip(data, meanAlgorithm(data)).map((d) => {
|
|
42
|
+
const datum = d[0];
|
|
43
|
+
const meanValue = d[1];
|
|
44
|
+
const bullPower = meanValue !== undefined ? ohlc(datum).high - meanValue : undefined;
|
|
45
|
+
const bearPower = meanValue !== undefined ? ohlc(datum).low - meanValue : undefined;
|
|
46
|
+
return { bullPower, bearPower };
|
|
47
|
+
});
|
|
48
|
+
};
|
|
49
|
+
calculator.undefinedLength = () => {
|
|
50
|
+
const { windowSize } = options;
|
|
51
|
+
return windowSize - 1;
|
|
52
|
+
};
|
|
53
|
+
calculator.ohlc = (ohlcAccessor) => {
|
|
54
|
+
if (ohlcAccessor === undefined) {
|
|
55
|
+
return ohlc;
|
|
56
|
+
}
|
|
57
|
+
ohlc = ohlcAccessor;
|
|
58
|
+
return calculator;
|
|
59
|
+
};
|
|
60
|
+
calculator.options = (newOptions) => {
|
|
61
|
+
if (newOptions === undefined) {
|
|
62
|
+
return options;
|
|
63
|
+
}
|
|
64
|
+
options = Object.assign(Object.assign({}, defaultOptions), newOptions);
|
|
65
|
+
return calculator;
|
|
66
|
+
};
|
|
67
|
+
return calculator;
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=elderRay.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"elderRay.js","sourceRoot":"","sources":["../../src/calculator/elderRay.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;EAwBE;AAEF,OAAO,EAAE,IAAI,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AACrC,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,GAAG,MAAM,OAAO,CAAC;AACxB,OAAO,EAAE,QAAQ,IAAI,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAQ5E,MAAM,CAAC,OAAO;IACV,IAAI,OAAO,GAAG,cAAc,CAAC;IAC7B,IAAI,IAAI,GAAG,CAAC,CAAM,EAAE,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,GAAG,EAAE,CAAC,CAAC,GAAG,EAAE,KAAK,EAAE,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC;IAEpF,MAAM,UAAU,GAAG,CAAC,IAAW,EAAE,EAAE;QAC/B,MAAM,EAAE,UAAU,EAAE,UAAU,EAAE,iBAAiB,EAAE,GAAG,OAAO,CAAC;QAE9D,MAAM,aAAa,GACf,iBAAiB,KAAK,KAAK;YACvB,CAAC,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,EAAE,UAAU,EAAE,UAAU,EAAE,CAAC;YAC3C,CAAC,CAAC,aAAa,EAAE;iBACV,UAAU,CAAC,UAAU,CAAC;iBACtB,WAAW,CAAC,CAAC,MAAW,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM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
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export interface EMAOptions {
|
|
2
|
+
readonly windowSize: number;
|
|
3
|
+
readonly sourcePath?: string;
|
|
4
|
+
}
|
|
5
|
+
interface EMACalculator {
|
|
6
|
+
(data: any[]): (number | undefined)[];
|
|
7
|
+
undefinedLength(): number;
|
|
8
|
+
options(): EMAOptions;
|
|
9
|
+
options(newOptions: EMAOptions): EMACalculator;
|
|
10
|
+
}
|
|
11
|
+
export default function (): EMACalculator;
|
|
12
|
+
export {};
|