@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
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { path } from "../utils";
|
|
2
|
+
import { Change as defaultOptions } from "./defaultOptionsForComputation";
|
|
3
|
+
|
|
4
|
+
export interface CompareOptions {
|
|
5
|
+
readonly basePath: string;
|
|
6
|
+
readonly compareKeys: string[];
|
|
7
|
+
readonly mainKeys: string[];
|
|
8
|
+
readonly sourcePath?: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export default function () {
|
|
12
|
+
let options: CompareOptions = defaultOptions;
|
|
13
|
+
|
|
14
|
+
const calculator = (data: any[]) => {
|
|
15
|
+
const { basePath, mainKeys, compareKeys } = options;
|
|
16
|
+
|
|
17
|
+
const base = path(basePath);
|
|
18
|
+
|
|
19
|
+
const first = data[0];
|
|
20
|
+
const b = base(first);
|
|
21
|
+
|
|
22
|
+
const firsts: any = {};
|
|
23
|
+
|
|
24
|
+
const compareData = data.map((d) => {
|
|
25
|
+
const result = {};
|
|
26
|
+
|
|
27
|
+
mainKeys.forEach((key) => {
|
|
28
|
+
if (typeof d[key] === "object") {
|
|
29
|
+
// @ts-ignore
|
|
30
|
+
result[key] = {};
|
|
31
|
+
Object.keys(d[key]).forEach((subkey) => {
|
|
32
|
+
// @ts-ignore
|
|
33
|
+
result[key][subkey] = (d[key][subkey] - b) / b;
|
|
34
|
+
});
|
|
35
|
+
} else {
|
|
36
|
+
// @ts-ignore
|
|
37
|
+
result[key] = (d[key] - b) / b;
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
compareKeys.forEach((key) => {
|
|
42
|
+
if (d[key] !== undefined && firsts[key] === undefined) {
|
|
43
|
+
// @ts-ignore
|
|
44
|
+
firsts[key] = d[key];
|
|
45
|
+
}
|
|
46
|
+
if (d[key] !== undefined && firsts[key] !== undefined) {
|
|
47
|
+
// @ts-ignore
|
|
48
|
+
result[key] = (d[key] - firsts[key]) / firsts[key];
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
return result;
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
return compareData;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
calculator.options = (newOptions?: CompareOptions) => {
|
|
58
|
+
if (newOptions === undefined) {
|
|
59
|
+
return options;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
options = { ...defaultOptions, ...newOptions };
|
|
63
|
+
|
|
64
|
+
return calculator;
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
return calculator;
|
|
68
|
+
}
|
|
@@ -0,0 +1,117 @@
|
|
|
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
|
+
|
|
9
|
+
export const ATR = {
|
|
10
|
+
windowSize: 14,
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export const ForceIndex = {
|
|
14
|
+
sourcePath: "close", // "high", "low", "open", "close"
|
|
15
|
+
volumePath: "volume",
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export const SmoothedForceIndex = {
|
|
19
|
+
sourcePath: "close", // "high", "low", "open", "close"
|
|
20
|
+
volumePath: "volume",
|
|
21
|
+
smoothingType: "ema",
|
|
22
|
+
smoothingWindow: 13,
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export const Change = {
|
|
26
|
+
sourcePath: "close", // "high", "low", "open", "close"
|
|
27
|
+
basePath: "close",
|
|
28
|
+
mainKeys: [],
|
|
29
|
+
compareKeys: [],
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export const Compare = {
|
|
33
|
+
basePath: "close",
|
|
34
|
+
mainKeys: ["open", "high", "low", "close"],
|
|
35
|
+
compareKeys: [],
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
export const ElderRay = {
|
|
39
|
+
windowSize: 13,
|
|
40
|
+
// source: d => d.close, // "high", "low", "open", "close"
|
|
41
|
+
sourcePath: "close", // "high", "low", "open", "close"
|
|
42
|
+
movingAverageType: "sma",
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export const ElderImpulse = {
|
|
46
|
+
sourcePath: "close", // "high", "low", "open", "close"
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
export const SAR = {
|
|
50
|
+
accelerationFactor: 0.02,
|
|
51
|
+
maxAccelerationFactor: 0.2,
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
export const MACD = {
|
|
55
|
+
fast: 12,
|
|
56
|
+
slow: 26,
|
|
57
|
+
signal: 9,
|
|
58
|
+
// source: d => d.close, // "high", "low", "open", "close"
|
|
59
|
+
sourcePath: "close",
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
export const FullStochasticOscillator = {
|
|
63
|
+
windowSize: 12,
|
|
64
|
+
kWindowSize: 3,
|
|
65
|
+
dWindowSize: 3,
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
export const RSI = {
|
|
69
|
+
windowSize: 14,
|
|
70
|
+
// source: d => d.close, // "high", "low", "open", "close"
|
|
71
|
+
sourcePath: "close", // "high", "low", "open", "close"
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
export const EMA = {
|
|
75
|
+
// source: d => d.close, // "high", "low", "open", "close"
|
|
76
|
+
sourcePath: "close",
|
|
77
|
+
windowSize: 10,
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
export const SMA = {
|
|
81
|
+
// source: d => d.close, // "high", "low", "open", "close"
|
|
82
|
+
sourcePath: "close",
|
|
83
|
+
windowSize: 10,
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
export const WMA = {
|
|
87
|
+
// source: d => d.close, // "high", "low", "open", "close"
|
|
88
|
+
sourcePath: "close",
|
|
89
|
+
windowSize: 10,
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
export const TMA = {
|
|
93
|
+
// source: d => d.close, // "high", "low", "open", "close"
|
|
94
|
+
sourcePath: "close",
|
|
95
|
+
windowSize: 10,
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
export const Kagi = {
|
|
99
|
+
reversalType: "ATR", // "ATR", "FIXED"
|
|
100
|
+
windowSize: 14,
|
|
101
|
+
reversal: 2,
|
|
102
|
+
sourcePath: "close", // "high", "low", "open", "close"
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
export const Renko = {
|
|
106
|
+
reversalType: "ATR", // "ATR", "FIXED", "Percentage LTP"
|
|
107
|
+
windowSize: 14,
|
|
108
|
+
fixedBrickSize: 2,
|
|
109
|
+
sourcePath: "high/low", // "close", "high/low"
|
|
110
|
+
percentage: 1,
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
export const PointAndFigure = {
|
|
114
|
+
boxSize: 0.5,
|
|
115
|
+
reversal: 3,
|
|
116
|
+
sourcePath: "high/low", // "close", "high/low"
|
|
117
|
+
};
|
|
@@ -0,0 +1,90 @@
|
|
|
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
|
+
|
|
27
|
+
import { mean, zip } from "d3-array";
|
|
28
|
+
import { slidingWindow } from "../utils";
|
|
29
|
+
import ema from "./ema";
|
|
30
|
+
import { ElderRay as defaultOptions } from "./defaultOptionsForComputation";
|
|
31
|
+
|
|
32
|
+
export interface ElderRayOptions {
|
|
33
|
+
readonly movingAverageType: string;
|
|
34
|
+
readonly sourcePath: string;
|
|
35
|
+
readonly windowSize: number;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export default function () {
|
|
39
|
+
let options = defaultOptions;
|
|
40
|
+
let ohlc = (d: any) => ({ open: d.open, high: d.high, low: d.low, close: d.close });
|
|
41
|
+
|
|
42
|
+
const calculator = (data: any[]) => {
|
|
43
|
+
const { windowSize, sourcePath, movingAverageType } = options;
|
|
44
|
+
|
|
45
|
+
const meanAlgorithm =
|
|
46
|
+
movingAverageType === "ema"
|
|
47
|
+
? ema().options({ windowSize, sourcePath })
|
|
48
|
+
: slidingWindow()
|
|
49
|
+
.windowSize(windowSize)
|
|
50
|
+
.accumulator((values: any) => mean(values))
|
|
51
|
+
.sourcePath(sourcePath);
|
|
52
|
+
|
|
53
|
+
return zip(data, meanAlgorithm(data)).map((d) => {
|
|
54
|
+
const datum = d[0];
|
|
55
|
+
const meanValue = d[1];
|
|
56
|
+
|
|
57
|
+
const bullPower = meanValue !== undefined ? ohlc(datum).high - meanValue : undefined;
|
|
58
|
+
const bearPower = meanValue !== undefined ? ohlc(datum).low - meanValue : undefined;
|
|
59
|
+
return { bullPower, bearPower };
|
|
60
|
+
});
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
calculator.undefinedLength = () => {
|
|
64
|
+
const { windowSize } = options;
|
|
65
|
+
|
|
66
|
+
return windowSize - 1;
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
calculator.ohlc = (ohlcAccessor?: (d: any) => any) => {
|
|
70
|
+
if (ohlcAccessor === undefined) {
|
|
71
|
+
return ohlc;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
ohlc = ohlcAccessor;
|
|
75
|
+
|
|
76
|
+
return calculator;
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
calculator.options = (newOptions?: ElderRayOptions) => {
|
|
80
|
+
if (newOptions === undefined) {
|
|
81
|
+
return options;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
options = { ...defaultOptions, ...newOptions };
|
|
85
|
+
|
|
86
|
+
return calculator;
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
return calculator;
|
|
90
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/*
|
|
2
|
+
https://github.com/ScottLogic/d3fc/blob/master/src/indicator/algorithm/calculator/exponentialMovingAverage.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
|
+
|
|
27
|
+
import { path } from "../utils";
|
|
28
|
+
import { EMA as defaultOptions } from "./defaultOptionsForComputation";
|
|
29
|
+
|
|
30
|
+
export interface EMAOptions {
|
|
31
|
+
readonly windowSize: number;
|
|
32
|
+
readonly sourcePath?: string;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
interface EMACalculator {
|
|
36
|
+
(data: any[]): (number | undefined)[];
|
|
37
|
+
undefinedLength(): number;
|
|
38
|
+
options(): EMAOptions;
|
|
39
|
+
options(newOptions: EMAOptions): EMACalculator;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export default function () {
|
|
43
|
+
let options: EMAOptions = defaultOptions;
|
|
44
|
+
|
|
45
|
+
const calculator = (data: any[]) => {
|
|
46
|
+
const { windowSize, sourcePath } = options;
|
|
47
|
+
|
|
48
|
+
const source = path(sourcePath);
|
|
49
|
+
const alpha = 2 / (windowSize + 1);
|
|
50
|
+
let previous: any;
|
|
51
|
+
let initialAccumulator = 0;
|
|
52
|
+
let skip = 0;
|
|
53
|
+
|
|
54
|
+
return data.map(function (d, i) {
|
|
55
|
+
const v = source(d, i);
|
|
56
|
+
if (previous === undefined && v === undefined) {
|
|
57
|
+
skip++;
|
|
58
|
+
return undefined;
|
|
59
|
+
} else if (i < windowSize + skip - 1) {
|
|
60
|
+
initialAccumulator += v;
|
|
61
|
+
return undefined;
|
|
62
|
+
} else if (i === windowSize + skip - 1) {
|
|
63
|
+
initialAccumulator += v;
|
|
64
|
+
const initialValue = initialAccumulator / windowSize;
|
|
65
|
+
previous = initialValue;
|
|
66
|
+
return initialValue;
|
|
67
|
+
} else {
|
|
68
|
+
const nextValue = v * alpha + (1 - alpha) * previous;
|
|
69
|
+
previous = nextValue;
|
|
70
|
+
return nextValue;
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
calculator.undefinedLength = () => {
|
|
76
|
+
const { windowSize } = options;
|
|
77
|
+
|
|
78
|
+
return windowSize - 1;
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
calculator.options = (newOptions?: EMAOptions) => {
|
|
82
|
+
if (newOptions === undefined) {
|
|
83
|
+
return options;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
options = { ...defaultOptions, ...newOptions };
|
|
87
|
+
|
|
88
|
+
return calculator;
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
return calculator as EMACalculator;
|
|
92
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { path, slidingWindow } from "../utils";
|
|
2
|
+
import { ForceIndex as defaultOptions } from "./defaultOptionsForComputation";
|
|
3
|
+
|
|
4
|
+
export interface ForceIndexOptions {
|
|
5
|
+
readonly sourcePath: string;
|
|
6
|
+
readonly volumePath: string;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export default function () {
|
|
10
|
+
let options = defaultOptions;
|
|
11
|
+
|
|
12
|
+
const calculator = (data: any[]) => {
|
|
13
|
+
const { sourcePath, volumePath } = options;
|
|
14
|
+
|
|
15
|
+
const source = path(sourcePath);
|
|
16
|
+
|
|
17
|
+
const volume = path(volumePath);
|
|
18
|
+
|
|
19
|
+
const forceIndexCalulator = slidingWindow()
|
|
20
|
+
.windowSize(2)
|
|
21
|
+
.accumulator(([prev, curr]: any) => (source(curr) - source(prev)) * volume(curr));
|
|
22
|
+
|
|
23
|
+
const forceIndex = forceIndexCalulator(data);
|
|
24
|
+
|
|
25
|
+
return forceIndex;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
calculator.undefinedLength = () => {
|
|
29
|
+
return 2;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
calculator.options = (newOptions?: ForceIndexOptions) => {
|
|
33
|
+
if (newOptions === undefined) {
|
|
34
|
+
return options;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
options = { ...defaultOptions, ...newOptions };
|
|
38
|
+
|
|
39
|
+
return calculator;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
return calculator;
|
|
43
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { mappedSlidingWindow } from "../utils";
|
|
2
|
+
|
|
3
|
+
export default function () {
|
|
4
|
+
let source = (x: any) => x;
|
|
5
|
+
|
|
6
|
+
const calculator = (data: any[]) => {
|
|
7
|
+
const algorithm = mappedSlidingWindow()
|
|
8
|
+
.windowSize(2)
|
|
9
|
+
.undefinedValue(
|
|
10
|
+
({ open, high, low, close }: { open: number; high: number; low: number; close: number }) => {
|
|
11
|
+
close = (open + high + low + close) / 4;
|
|
12
|
+
return { open, high, low, close };
|
|
13
|
+
},
|
|
14
|
+
)
|
|
15
|
+
.accumulator(([prev, now]: any) => {
|
|
16
|
+
const { date, volume } = now;
|
|
17
|
+
const close = (now.open + now.high + now.low + now.close) / 4;
|
|
18
|
+
const open = (prev.open + prev.close) / 2;
|
|
19
|
+
const high = Math.max(open, now.high, close);
|
|
20
|
+
const low = Math.min(open, now.low, close);
|
|
21
|
+
return { date, open, high, low, close, volume };
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
return algorithm(data);
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
calculator.source = (newSource?: any) => {
|
|
28
|
+
if (newSource === undefined) {
|
|
29
|
+
return source;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
source = newSource;
|
|
33
|
+
|
|
34
|
+
return calculator;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
return calculator;
|
|
38
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export { default as ema } from "./ema";
|
|
2
|
+
export { default as sma } from "./sma";
|
|
3
|
+
export { default as wma } from "./wma";
|
|
4
|
+
export { default as tma } from "./tma";
|
|
5
|
+
export { default as bollingerband } from "./bollingerband";
|
|
6
|
+
export { default as heikinAshi } from "./heikinAshi";
|
|
7
|
+
export { default as kagi } from "./kagi";
|
|
8
|
+
export { default as pointAndFigure } from "./pointAndFigure";
|
|
9
|
+
export { default as renko } from "./renko";
|
|
10
|
+
export { default as macd } from "./macd";
|
|
11
|
+
export { default as rsi } from "./rsi";
|
|
12
|
+
export { default as sto } from "./sto";
|
|
13
|
+
export { default as atr } from "./atr";
|
|
14
|
+
export { default as forceIndex } from "./forceIndex";
|
|
15
|
+
export { default as smoothedForceIndex } from "./smoothedForceIndex";
|
|
16
|
+
export { default as elderRay } from "./elderRay";
|
|
17
|
+
export { default as sar } from "./sar";
|
|
18
|
+
export { default as compare } from "./compare";
|
|
19
|
+
export { default as change } from "./change";
|