@ch20026103/anysis 0.0.10-alpha → 0.0.12-alpha
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/demo/main.js +13 -107
- package/dist/cjs/analyze/Angle/angle.test.d.ts +1 -0
- package/dist/cjs/analyze/Angle/angle.test.js +35 -0
- package/dist/cjs/analyze/Angle/index.d.ts +1 -0
- package/dist/cjs/analyze/Angle/index.js +16 -0
- package/dist/cjs/analyze/Slope/index.js +5 -2
- package/dist/cjs/analyze/Slope/slope.test.js +1 -1
- package/dist/cjs/index.d.ts +3 -1
- package/dist/cjs/index.js +15 -11
- package/dist/cjs/stockSkills/ma.d.ts +5 -0
- package/dist/cjs/stockSkills/ma.js +4 -3
- package/dist/cjs/stockSkills/williams.d.ts +31 -2
- package/dist/cjs/stockSkills/williams.js +40 -4
- package/dist/cjs/stockSkills/williams.test.js +11 -0
- package/dist/cjs/utils/calculateDivisionFactor.d.ts +1 -0
- package/dist/cjs/utils/calculateDivisionFactor.js +16 -0
- package/dist/cjs/utils/calculateDivisionFactor.test.d.ts +1 -0
- package/dist/cjs/utils/calculateDivisionFactor.test.js +13 -0
- package/dist/esm/analyze/Angle/angle.test.d.ts +1 -0
- package/dist/esm/analyze/Angle/angle.test.js +33 -0
- package/dist/esm/analyze/Angle/index.d.ts +1 -0
- package/dist/esm/analyze/Angle/index.js +13 -0
- package/dist/esm/analyze/Slope/index.js +5 -2
- package/dist/esm/analyze/Slope/slope.test.js +1 -1
- package/dist/esm/index.d.ts +3 -1
- package/dist/esm/index.js +3 -1
- package/dist/esm/stockSkills/ma.d.ts +5 -0
- package/dist/esm/stockSkills/ma.js +4 -3
- package/dist/esm/stockSkills/williams.d.ts +31 -2
- package/dist/esm/stockSkills/williams.js +40 -4
- package/dist/esm/stockSkills/williams.test.js +11 -0
- package/dist/esm/utils/calculateDivisionFactor.d.ts +1 -0
- package/dist/esm/utils/calculateDivisionFactor.js +13 -0
- package/dist/esm/utils/calculateDivisionFactor.test.d.ts +1 -0
- package/dist/esm/utils/calculateDivisionFactor.test.js +11 -0
- package/dist/umd/index.js +110 -42
- package/package.json +1 -1
package/demo/main.js
CHANGED
|
@@ -1,77 +1,24 @@
|
|
|
1
1
|
/* eslint @typescript-eslint/no-var-requires: "off" */
|
|
2
2
|
const axios = require("axios");
|
|
3
|
-
const {
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
const kd = new Kd();
|
|
7
|
-
const boll = new Boll();
|
|
8
|
-
const vma = new Vma();
|
|
9
|
-
const stockId = 1702;
|
|
10
|
-
// week
|
|
11
|
-
const { getWeekLine, Ma } = require("../dist/cjs/index.js");
|
|
12
|
-
const ma = new Ma();
|
|
13
|
-
|
|
14
|
-
function DemoDay() {
|
|
3
|
+
const { Williams } = require("../dist/cjs/index.js");
|
|
4
|
+
const williams = new Williams();
|
|
5
|
+
function DemoDay(stockId) {
|
|
15
6
|
axios
|
|
16
7
|
.get(
|
|
17
8
|
`https://tw.quote.finance.yahoo.net/quote/q?type=ta&perd=d&mkt=10&sym=${stockId}&v=1&callback=`
|
|
18
9
|
)
|
|
19
10
|
.then((res) => {
|
|
20
|
-
|
|
21
|
-
let
|
|
22
|
-
let
|
|
23
|
-
let
|
|
24
|
-
let
|
|
25
|
-
let bollData = boll.init(data[0]);
|
|
26
|
-
let vmaData = vma.init(data[0], 5);
|
|
27
|
-
let finallyData = [
|
|
28
|
-
{
|
|
29
|
-
...data[0],
|
|
30
|
-
vma: vmaData.vma,
|
|
31
|
-
ema12: macdData.ema12,
|
|
32
|
-
ema26: macdData.ema26,
|
|
33
|
-
macd: macdData.macd,
|
|
34
|
-
osc: macdData.osc,
|
|
35
|
-
dif: macdData.dif[macdData.dif.length - 1],
|
|
36
|
-
obv: obvData.obv,
|
|
37
|
-
obvMa: obvData.obvMa,
|
|
38
|
-
rsv: kdData.rsv,
|
|
39
|
-
k: kdData.k,
|
|
40
|
-
d: kdData.d,
|
|
41
|
-
"k-d": kdData["k-d"],
|
|
42
|
-
bollMa: bollData.bollMa,
|
|
43
|
-
bollUb: bollData.bollUb,
|
|
44
|
-
bollLb: bollData.bollLb,
|
|
45
|
-
},
|
|
46
|
-
];
|
|
47
|
-
|
|
11
|
+
res = res.data.replace(/^\(|\);$/g, "");
|
|
12
|
+
let parse = JSON.parse(res);
|
|
13
|
+
let data = parse.ta;
|
|
14
|
+
let williams9Data = williams.init(data[0], 9);
|
|
15
|
+
let williams18Data = williams.init(data[0], 18);
|
|
48
16
|
for (let i = 1; i < data.length; i++) {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
kdData = kd.next(data[i], kdData, 9);
|
|
52
|
-
bollData = boll.next(data[i], bollData, 20);
|
|
53
|
-
vmaData = vma.next(data[i], vmaData, 5);
|
|
54
|
-
finallyData.push({
|
|
55
|
-
...data[i],
|
|
56
|
-
vma: vmaData.vma,
|
|
57
|
-
ema12: macdData.ema12,
|
|
58
|
-
ema26: macdData.ema26,
|
|
59
|
-
macd: macdData.macd,
|
|
60
|
-
osc: macdData.osc,
|
|
61
|
-
dif: macdData.dif[macdData.dif.length - 1],
|
|
62
|
-
obv: obvData.obv,
|
|
63
|
-
obvMa: obvData.obvMa,
|
|
64
|
-
rsv: kdData.rsv,
|
|
65
|
-
k: kdData.k,
|
|
66
|
-
d: kdData.d,
|
|
67
|
-
"k-d": kdData["k-d"],
|
|
68
|
-
bollMa: bollData.bollMa,
|
|
69
|
-
bollUb: bollData.bollUb,
|
|
70
|
-
bollLb: bollData.bollLb,
|
|
71
|
-
});
|
|
17
|
+
williams9Data = williams.next(data[i], williams9Data, 9);
|
|
18
|
+
williams18Data = williams.next(data[i], williams18Data, 18);
|
|
72
19
|
}
|
|
73
|
-
|
|
74
|
-
console.log(
|
|
20
|
+
console.log(williams9Data);
|
|
21
|
+
console.log(williams18Data);
|
|
75
22
|
})
|
|
76
23
|
.catch((error) => {
|
|
77
24
|
console.error(error);
|
|
@@ -81,45 +28,4 @@ function DemoDay() {
|
|
|
81
28
|
});
|
|
82
29
|
}
|
|
83
30
|
|
|
84
|
-
|
|
85
|
-
axios
|
|
86
|
-
.get(
|
|
87
|
-
`https://tw.quote.finance.yahoo.net/quote/q?type=ta&perd=d&mkt=10&sym=${stockId}&v=1&callback=`
|
|
88
|
-
)
|
|
89
|
-
.then((res) => {
|
|
90
|
-
let json = res.data.match(/"ta":(\S*),"ex"/)[1];
|
|
91
|
-
let data = JSON.parse(json);
|
|
92
|
-
// week
|
|
93
|
-
let weekLine = getWeekLine(data);
|
|
94
|
-
let weekMaData5 = ma.init(weekLine[0], 5);
|
|
95
|
-
let weekMaData10 = ma.init(weekLine[0], 10);
|
|
96
|
-
let weekMaData20 = ma.init(weekLine[0], 20);
|
|
97
|
-
for (let i = 1; i < weekLine.length; i++) {
|
|
98
|
-
weekMaData5 = ma.next(weekLine[i], weekMaData5, 5);
|
|
99
|
-
weekMaData10 = ma.next(weekLine[i], weekMaData10, 10);
|
|
100
|
-
weekMaData20 = ma.next(weekLine[i], weekMaData20, 20);
|
|
101
|
-
}
|
|
102
|
-
console.log({
|
|
103
|
-
t: weekMaData5.dataset[weekMaData5.dataset.length - 1].t,
|
|
104
|
-
ma5: weekMaData5.ma,
|
|
105
|
-
ma5ExclusionValue: weekMaData5.exclusionValue,
|
|
106
|
-
ma10: weekMaData10.ma,
|
|
107
|
-
ma10ExclusionValue: weekMaData10.exclusionValue,
|
|
108
|
-
ma20: weekMaData20.ma,
|
|
109
|
-
ma20ExclusionValue: weekMaData20.exclusionValue,
|
|
110
|
-
});
|
|
111
|
-
})
|
|
112
|
-
.catch((error) => {
|
|
113
|
-
console.error(error);
|
|
114
|
-
})
|
|
115
|
-
.finally(() => {
|
|
116
|
-
console.log("week done");
|
|
117
|
-
});
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
// DemoDay();
|
|
121
|
-
|
|
122
|
-
const showWeek = true;
|
|
123
|
-
if (showWeek) {
|
|
124
|
-
DemoWeek();
|
|
125
|
-
}
|
|
31
|
+
DemoDay("2449");
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var index_1 = require("./index");
|
|
4
|
+
describe("test Angle methods", function () {
|
|
5
|
+
it("test (0,0) (1,1)", function () {
|
|
6
|
+
var y = [0, 1];
|
|
7
|
+
var angle = (0, index_1.default)(y);
|
|
8
|
+
expect(angle).toEqual(45);
|
|
9
|
+
});
|
|
10
|
+
it("test [0, 200]", function () {
|
|
11
|
+
var y = [0, 200];
|
|
12
|
+
var angle = (0, index_1.default)(y);
|
|
13
|
+
expect(angle).toEqual(63.43494882292201);
|
|
14
|
+
});
|
|
15
|
+
it("test [0, 0]", function () {
|
|
16
|
+
var y = [0, 0];
|
|
17
|
+
var angle = (0, index_1.default)(y);
|
|
18
|
+
expect(angle).toEqual(0);
|
|
19
|
+
});
|
|
20
|
+
it("test [39.73, 48.15]", function () {
|
|
21
|
+
var y = [39.73, 48.15];
|
|
22
|
+
var angle = (0, index_1.default)(y);
|
|
23
|
+
expect(angle).toEqual(40.09737861178007);
|
|
24
|
+
});
|
|
25
|
+
it("test [15.46, 30.19]", function () {
|
|
26
|
+
var y = [15.46, 30.19];
|
|
27
|
+
var angle = (0, index_1.default)(y);
|
|
28
|
+
expect(angle).toEqual(55.82794164843938);
|
|
29
|
+
});
|
|
30
|
+
it("test [35.64, 37.09]", function () {
|
|
31
|
+
var y = [35.64, 37.09];
|
|
32
|
+
var angle = (0, index_1.default)(y);
|
|
33
|
+
expect(angle).toEqual(8.250387228905515);
|
|
34
|
+
});
|
|
35
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function TwoPointAngle(y: number[]): number;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var calculateDivisionFactor_1 = require("../../utils/calculateDivisionFactor");
|
|
4
|
+
function TwoPointAngle(y) {
|
|
5
|
+
if (y.length != 2)
|
|
6
|
+
return 0;
|
|
7
|
+
// 計算 x 和 y 的平均值
|
|
8
|
+
var increment = (0, calculateDivisionFactor_1.default)(y[1]);
|
|
9
|
+
var x = Array.from({ length: y.length }, function (_, index) { return index * increment; });
|
|
10
|
+
var m = (y[1] - y[0]) / (x[1] - x[0]);
|
|
11
|
+
// 計算角度(弧度)
|
|
12
|
+
var thetaRadians = Math.atan(m); // 轉換角度為度
|
|
13
|
+
var thetaDegrees = thetaRadians * (180 / Math.PI);
|
|
14
|
+
return thetaDegrees;
|
|
15
|
+
}
|
|
16
|
+
exports.default = TwoPointAngle;
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var calculateDivisionFactor_1 = require("../../utils/calculateDivisionFactor");
|
|
3
4
|
function Slope(y) {
|
|
4
5
|
// 計算 x 和 y 的平均值
|
|
5
|
-
var x = Array.from({ length: y.length }, function (_, k) { return k + 1; });
|
|
6
|
-
var x_mean = x.reduce(function (acc, cur) { return acc + cur; }) / x.length;
|
|
7
6
|
var y_mean = y.reduce(function (acc, cur) { return acc + cur; }) / y.length;
|
|
7
|
+
var increment = (0, calculateDivisionFactor_1.default)(y_mean);
|
|
8
|
+
console.log(y_mean, increment);
|
|
9
|
+
var x = Array.from({ length: y.length }, function (_, index) { return index * increment; });
|
|
10
|
+
var x_mean = x.reduce(function (acc, cur) { return acc + cur; }) / x.length;
|
|
8
11
|
// 計算斜率
|
|
9
12
|
var numerator = x.reduce(function (acc, cur, i) { return acc + (cur - x_mean) * (y[i] - y_mean); }, 0);
|
|
10
13
|
var denominator = x.reduce(function (acc, cur) { return acc + Math.pow((cur - x_mean), 2); }, 0);
|
|
@@ -13,7 +13,7 @@ describe("test Slope methods", function () {
|
|
|
13
13
|
expect(slope).toEqual(-1);
|
|
14
14
|
});
|
|
15
15
|
it("test 654321", function () {
|
|
16
|
-
var y = [
|
|
16
|
+
var y = [60, 50, 40, 30, 20, 10];
|
|
17
17
|
var slope = (0, index_1.default)(y);
|
|
18
18
|
expect(slope).toEqual(-1);
|
|
19
19
|
});
|
package/dist/cjs/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export { default as Angle } from "./analyze/Angle/index.js";
|
|
1
2
|
export { default as simpleRegressionModel } from "./analyze/Regression/simpleRegressoinModel.js";
|
|
2
3
|
export { default as slope } from "./analyze/Slope/index.js";
|
|
3
4
|
export { exponentialSmoothing, movingAverages, weightMovingAverages, } from "./analyze/TimeSeries/R/index.js";
|
|
@@ -7,14 +8,15 @@ export { default as Ema } from "./stockSkills/ema.js";
|
|
|
7
8
|
export { default as Gold } from "./stockSkills/gold.js";
|
|
8
9
|
export { default as Kd } from "./stockSkills/kd.js";
|
|
9
10
|
export { default as Ma } from "./stockSkills/ma.js";
|
|
10
|
-
export { default as Vma } from "./stockSkills/vma.js";
|
|
11
11
|
export { default as Macd } from "./stockSkills/macd.js";
|
|
12
12
|
export { default as Obv } from "./stockSkills/obv.js";
|
|
13
13
|
export { default as Rsi } from "./stockSkills/rsi.js";
|
|
14
14
|
export { default as dateFormat } from "./stockSkills/utils/dateFormat.js";
|
|
15
15
|
export { default as getWeekLine } from "./stockSkills/utils/getWeekLine.js";
|
|
16
|
+
export { default as Vma } from "./stockSkills/vma.js";
|
|
16
17
|
export { default as Williams } from "./stockSkills/williams.js";
|
|
17
18
|
export { add } from "./test/add.js";
|
|
18
19
|
export { minus } from "./test/minus.js";
|
|
20
|
+
export { default as calculateDivisionFactor } from "./utils/calculateDivisionFactor.js";
|
|
19
21
|
export { default as isJSON } from "./utils/isJson.js";
|
|
20
22
|
export { default as parseLsusbOutput } from "./utils/parseLsusbOutput.js";
|
package/dist/cjs/index.js
CHANGED
|
@@ -1,21 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.parseLsusbOutput = exports.isJSON = exports.minus = exports.add = exports.Williams = exports.getWeekLine = exports.dateFormat = exports.Rsi = exports.Obv = exports.Macd = exports.
|
|
3
|
+
exports.parseLsusbOutput = exports.isJSON = exports.calculateDivisionFactor = exports.minus = exports.add = exports.Williams = exports.Vma = exports.getWeekLine = exports.dateFormat = exports.Rsi = exports.Obv = exports.Macd = exports.Ma = exports.Kd = exports.Gold = exports.Ema = exports.Boll = exports.calcSeasonalIndicesNoTrend = exports.weightMovingAverages = exports.movingAverages = exports.exponentialSmoothing = exports.slope = exports.simpleRegressionModel = exports.Angle = void 0;
|
|
4
4
|
/*
|
|
5
5
|
請注意,在 src/index.ts 中,我的導入包含文件擴展名(.js)。
|
|
6
6
|
如果需要支持 Node.js 和構建工具(ex: webpack),則不需要這樣做。 **因為commonJs默認js副檔名**
|
|
7
7
|
但如果要支持 ES 模塊的瀏覽器 ,則需要文件擴展名(.js)。
|
|
8
8
|
*/
|
|
9
|
+
var index_js_1 = require("./analyze/Angle/index.js");
|
|
10
|
+
Object.defineProperty(exports, "Angle", { enumerable: true, get: function () { return index_js_1.default; } });
|
|
9
11
|
var simpleRegressoinModel_js_1 = require("./analyze/Regression/simpleRegressoinModel.js");
|
|
10
12
|
Object.defineProperty(exports, "simpleRegressionModel", { enumerable: true, get: function () { return simpleRegressoinModel_js_1.default; } });
|
|
11
|
-
var
|
|
12
|
-
Object.defineProperty(exports, "slope", { enumerable: true, get: function () { return
|
|
13
|
-
var
|
|
14
|
-
Object.defineProperty(exports, "exponentialSmoothing", { enumerable: true, get: function () { return
|
|
15
|
-
Object.defineProperty(exports, "movingAverages", { enumerable: true, get: function () { return
|
|
16
|
-
Object.defineProperty(exports, "weightMovingAverages", { enumerable: true, get: function () { return
|
|
17
|
-
var
|
|
18
|
-
Object.defineProperty(exports, "calcSeasonalIndicesNoTrend", { enumerable: true, get: function () { return
|
|
13
|
+
var index_js_2 = require("./analyze/Slope/index.js");
|
|
14
|
+
Object.defineProperty(exports, "slope", { enumerable: true, get: function () { return index_js_2.default; } });
|
|
15
|
+
var index_js_3 = require("./analyze/TimeSeries/R/index.js");
|
|
16
|
+
Object.defineProperty(exports, "exponentialSmoothing", { enumerable: true, get: function () { return index_js_3.exponentialSmoothing; } });
|
|
17
|
+
Object.defineProperty(exports, "movingAverages", { enumerable: true, get: function () { return index_js_3.movingAverages; } });
|
|
18
|
+
Object.defineProperty(exports, "weightMovingAverages", { enumerable: true, get: function () { return index_js_3.weightMovingAverages; } });
|
|
19
|
+
var index_js_4 = require("./analyze/TimeSeries/RS/index.js");
|
|
20
|
+
Object.defineProperty(exports, "calcSeasonalIndicesNoTrend", { enumerable: true, get: function () { return index_js_4.calcSeasonalIndicesNoTrend; } });
|
|
19
21
|
var boll_js_1 = require("./stockSkills/boll.js");
|
|
20
22
|
Object.defineProperty(exports, "Boll", { enumerable: true, get: function () { return boll_js_1.default; } });
|
|
21
23
|
var ema_js_1 = require("./stockSkills/ema.js");
|
|
@@ -26,8 +28,6 @@ var kd_js_1 = require("./stockSkills/kd.js");
|
|
|
26
28
|
Object.defineProperty(exports, "Kd", { enumerable: true, get: function () { return kd_js_1.default; } });
|
|
27
29
|
var ma_js_1 = require("./stockSkills/ma.js");
|
|
28
30
|
Object.defineProperty(exports, "Ma", { enumerable: true, get: function () { return ma_js_1.default; } });
|
|
29
|
-
var vma_js_1 = require("./stockSkills/vma.js");
|
|
30
|
-
Object.defineProperty(exports, "Vma", { enumerable: true, get: function () { return vma_js_1.default; } });
|
|
31
31
|
var macd_js_1 = require("./stockSkills/macd.js");
|
|
32
32
|
Object.defineProperty(exports, "Macd", { enumerable: true, get: function () { return macd_js_1.default; } });
|
|
33
33
|
var obv_js_1 = require("./stockSkills/obv.js");
|
|
@@ -38,12 +38,16 @@ var dateFormat_js_1 = require("./stockSkills/utils/dateFormat.js");
|
|
|
38
38
|
Object.defineProperty(exports, "dateFormat", { enumerable: true, get: function () { return dateFormat_js_1.default; } });
|
|
39
39
|
var getWeekLine_js_1 = require("./stockSkills/utils/getWeekLine.js");
|
|
40
40
|
Object.defineProperty(exports, "getWeekLine", { enumerable: true, get: function () { return getWeekLine_js_1.default; } });
|
|
41
|
+
var vma_js_1 = require("./stockSkills/vma.js");
|
|
42
|
+
Object.defineProperty(exports, "Vma", { enumerable: true, get: function () { return vma_js_1.default; } });
|
|
41
43
|
var williams_js_1 = require("./stockSkills/williams.js");
|
|
42
44
|
Object.defineProperty(exports, "Williams", { enumerable: true, get: function () { return williams_js_1.default; } });
|
|
43
45
|
var add_js_1 = require("./test/add.js");
|
|
44
46
|
Object.defineProperty(exports, "add", { enumerable: true, get: function () { return add_js_1.add; } });
|
|
45
47
|
var minus_js_1 = require("./test/minus.js");
|
|
46
48
|
Object.defineProperty(exports, "minus", { enumerable: true, get: function () { return minus_js_1.minus; } });
|
|
49
|
+
var calculateDivisionFactor_js_1 = require("./utils/calculateDivisionFactor.js");
|
|
50
|
+
Object.defineProperty(exports, "calculateDivisionFactor", { enumerable: true, get: function () { return calculateDivisionFactor_js_1.default; } });
|
|
47
51
|
var isJson_js_1 = require("./utils/isJson.js");
|
|
48
52
|
Object.defineProperty(exports, "isJSON", { enumerable: true, get: function () { return isJson_js_1.default; } });
|
|
49
53
|
var parseLsusbOutput_js_1 = require("./utils/parseLsusbOutput.js");
|
|
@@ -37,6 +37,7 @@ interface MaType {
|
|
|
37
37
|
ma: number;
|
|
38
38
|
type: number;
|
|
39
39
|
exclusionValue: {
|
|
40
|
+
"d+1": number;
|
|
40
41
|
d: number;
|
|
41
42
|
"d-1": number;
|
|
42
43
|
};
|
|
@@ -46,6 +47,7 @@ interface MaType {
|
|
|
46
47
|
ma: number;
|
|
47
48
|
type: number;
|
|
48
49
|
exclusionValue: {
|
|
50
|
+
"d+1": number;
|
|
49
51
|
d: number;
|
|
50
52
|
"d-1": number;
|
|
51
53
|
};
|
|
@@ -54,6 +56,7 @@ interface MaType {
|
|
|
54
56
|
ma: number;
|
|
55
57
|
type: number;
|
|
56
58
|
exclusionValue: {
|
|
59
|
+
"d+1": number;
|
|
57
60
|
d: number;
|
|
58
61
|
"d-1": number;
|
|
59
62
|
};
|
|
@@ -71,6 +74,7 @@ export default class Ma implements MaType {
|
|
|
71
74
|
ma: number;
|
|
72
75
|
type: number;
|
|
73
76
|
exclusionValue: {
|
|
77
|
+
"d+1": number;
|
|
74
78
|
d: number;
|
|
75
79
|
"d-1": number;
|
|
76
80
|
};
|
|
@@ -84,6 +88,7 @@ export default class Ma implements MaType {
|
|
|
84
88
|
ma: number;
|
|
85
89
|
type: number;
|
|
86
90
|
exclusionValue: {
|
|
91
|
+
"d+1": number;
|
|
87
92
|
d: number;
|
|
88
93
|
"d-1": number;
|
|
89
94
|
};
|
|
@@ -19,7 +19,7 @@ var Ma = /** @class */ (function () {
|
|
|
19
19
|
configurable: true,
|
|
20
20
|
writable: true,
|
|
21
21
|
value: function (data, type) {
|
|
22
|
-
return { dataset: [data], ma: 0, type: type, exclusionValue: { d: 0, "d-1": 0 } };
|
|
22
|
+
return { dataset: [data], ma: 0, type: type, exclusionValue: { "d+1": 0, d: 0, "d-1": 0 } };
|
|
23
23
|
}
|
|
24
24
|
});
|
|
25
25
|
Object.defineProperty(Ma.prototype, "next", {
|
|
@@ -33,14 +33,15 @@ var Ma = /** @class */ (function () {
|
|
|
33
33
|
dataset: preList.dataset,
|
|
34
34
|
ma: 0,
|
|
35
35
|
type: type,
|
|
36
|
-
exclusionValue: { d: 0, "d-1": 0 },
|
|
36
|
+
exclusionValue: { "d+1": 0, d: 0, "d-1": 0 },
|
|
37
37
|
};
|
|
38
38
|
}
|
|
39
39
|
else {
|
|
40
|
-
var exclusionValue = { d: preList.dataset[0].c, "d-1": 0 };
|
|
40
|
+
var exclusionValue = { "d+1": preList.dataset[1].c, d: preList.dataset[0].c, "d-1": 0 };
|
|
41
41
|
if (preList.dataset.length > type) {
|
|
42
42
|
exclusionValue["d-1"] = exclusionValue.d;
|
|
43
43
|
preList.dataset.shift();
|
|
44
|
+
exclusionValue["d+1"] = preList.dataset[1].c;
|
|
44
45
|
exclusionValue.d = preList.dataset[0].c;
|
|
45
46
|
}
|
|
46
47
|
var sum = preList.dataset.reduce(function (pre, current) { return pre + current.c; }, 0);
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
type
|
|
1
|
+
type DataType = {
|
|
2
2
|
h: number;
|
|
3
3
|
l: number;
|
|
4
4
|
c: number;
|
|
5
|
-
}
|
|
5
|
+
};
|
|
6
|
+
type ListType = DataType[];
|
|
6
7
|
type ResWilliams9Type = {
|
|
7
8
|
c: number;
|
|
8
9
|
williams9: number | null;
|
|
@@ -17,11 +18,39 @@ type ResAllWilliamsType = {
|
|
|
17
18
|
williams9: number | null;
|
|
18
19
|
}[];
|
|
19
20
|
interface WilliamsType {
|
|
21
|
+
init: (data: DataType, type: number) => {
|
|
22
|
+
dataset: ListType;
|
|
23
|
+
williams: number;
|
|
24
|
+
type: number;
|
|
25
|
+
};
|
|
26
|
+
next: (data: DataType, preList: {
|
|
27
|
+
dataset: ListType;
|
|
28
|
+
williams: number;
|
|
29
|
+
type: number;
|
|
30
|
+
}, type: number) => {
|
|
31
|
+
dataset: ListType;
|
|
32
|
+
williams: number;
|
|
33
|
+
type: number;
|
|
34
|
+
};
|
|
20
35
|
getWilliams9: (list: ListType) => ResWilliams9Type;
|
|
21
36
|
getWilliams18: (list: ListType) => ResWilliams18Type;
|
|
22
37
|
getAllWillams(list: ListType): ResAllWilliamsType;
|
|
23
38
|
}
|
|
24
39
|
export default class Williams implements WilliamsType {
|
|
40
|
+
init(data: DataType, type: number): {
|
|
41
|
+
dataset: DataType[];
|
|
42
|
+
williams: number;
|
|
43
|
+
type: number;
|
|
44
|
+
};
|
|
45
|
+
next(data: DataType, preList: {
|
|
46
|
+
dataset: ListType;
|
|
47
|
+
williams: number;
|
|
48
|
+
type: number;
|
|
49
|
+
}, type: number): {
|
|
50
|
+
dataset: ListType;
|
|
51
|
+
williams: number;
|
|
52
|
+
type: number;
|
|
53
|
+
};
|
|
25
54
|
getAllWillams(list: ListType): ResAllWilliamsType;
|
|
26
55
|
getWilliams9(list: ListType): ResWilliams9Type;
|
|
27
56
|
getWilliams18(list: ListType): ResWilliams18Type;
|
|
@@ -14,6 +14,42 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
14
14
|
var Williams = /** @class */ (function () {
|
|
15
15
|
function Williams() {
|
|
16
16
|
}
|
|
17
|
+
Object.defineProperty(Williams.prototype, "init", {
|
|
18
|
+
enumerable: false,
|
|
19
|
+
configurable: true,
|
|
20
|
+
writable: true,
|
|
21
|
+
value: function (data, type) {
|
|
22
|
+
return { dataset: [data], williams: 0, type: type };
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
Object.defineProperty(Williams.prototype, "next", {
|
|
26
|
+
enumerable: false,
|
|
27
|
+
configurable: true,
|
|
28
|
+
writable: true,
|
|
29
|
+
value: function (data, preList, type) {
|
|
30
|
+
preList.dataset.push(data);
|
|
31
|
+
if (preList.dataset.length < type) {
|
|
32
|
+
return {
|
|
33
|
+
dataset: preList.dataset,
|
|
34
|
+
williams: 0,
|
|
35
|
+
type: type,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
if (preList.dataset.length > type) {
|
|
40
|
+
preList.dataset.shift();
|
|
41
|
+
}
|
|
42
|
+
var maxList = preList.dataset.map(function (item) { return item["h"]; });
|
|
43
|
+
var minList = preList.dataset.map(function (item) { return item["l"]; });
|
|
44
|
+
var max = Math.max.apply(Math, maxList);
|
|
45
|
+
var min = Math.min.apply(Math, minList);
|
|
46
|
+
var close_1 = data.c;
|
|
47
|
+
var williams = ((max - close_1) / (max - min)) * -100;
|
|
48
|
+
williams = Math.round(williams * 100) / 100;
|
|
49
|
+
return { dataset: preList.dataset, williams: williams, type: type };
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
});
|
|
17
53
|
Object.defineProperty(Williams.prototype, "getAllWillams", {
|
|
18
54
|
enumerable: false,
|
|
19
55
|
configurable: true,
|
|
@@ -42,8 +78,8 @@ var Williams = /** @class */ (function () {
|
|
|
42
78
|
var minList = list.slice(i - 8, i).map(function (item) { return item["l"]; });
|
|
43
79
|
var max = Math.max.apply(Math, maxList);
|
|
44
80
|
var min = Math.min.apply(Math, minList);
|
|
45
|
-
var
|
|
46
|
-
var williams9 = ((max -
|
|
81
|
+
var close_2 = list[i]["c"];
|
|
82
|
+
var williams9 = ((max - close_2) / (max - min)) * -100;
|
|
47
83
|
res[i] = __assign(__assign({}, list[i]), { williams9: Math.round(williams9 * 100) / 100 });
|
|
48
84
|
}
|
|
49
85
|
}
|
|
@@ -64,8 +100,8 @@ var Williams = /** @class */ (function () {
|
|
|
64
100
|
var minList = list.slice(i - 17, i).map(function (item) { return item["l"]; });
|
|
65
101
|
var max = Math.max.apply(Math, maxList);
|
|
66
102
|
var min = Math.min.apply(Math, minList);
|
|
67
|
-
var
|
|
68
|
-
var williams18 = ((max -
|
|
103
|
+
var close_3 = list[i]["c"];
|
|
104
|
+
var williams18 = ((max - close_3) / (max - min)) * -100;
|
|
69
105
|
res[i] = __assign(__assign({}, list[i]), { williams18: Math.round(williams18 * 100) / 100 });
|
|
70
106
|
}
|
|
71
107
|
}
|
|
@@ -3,6 +3,17 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
var williams_1 = require("./williams");
|
|
4
4
|
var test_data_test_1 = require("./test_data.test");
|
|
5
5
|
describe("test williams methods", function () {
|
|
6
|
+
it("test next()", function () {
|
|
7
|
+
var index = test_data_test_1.default.length - 1;
|
|
8
|
+
var williams = new williams_1.default();
|
|
9
|
+
var init = williams.init(test_data_test_1.default[0], 9);
|
|
10
|
+
var res = init;
|
|
11
|
+
for (var i = 1; i <= index; i++) {
|
|
12
|
+
var item = test_data_test_1.default[i];
|
|
13
|
+
res = williams.next(item, res, 9);
|
|
14
|
+
}
|
|
15
|
+
expect(res.williams).toEqual(-79.59);
|
|
16
|
+
});
|
|
6
17
|
it("test getWilliams9()", function () {
|
|
7
18
|
var williams = new williams_1.default();
|
|
8
19
|
expect(williams.getWilliams9(test_data_test_1.default)[test_data_test_1.default.length - 1]).toEqual({
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function calculateDivisionFactor(originalNumber: number): number;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
function calculateDivisionFactor(originalNumber) {
|
|
4
|
+
// 去除小數點
|
|
5
|
+
originalNumber = Math.floor(originalNumber);
|
|
6
|
+
// 轉換正數
|
|
7
|
+
originalNumber = Math.abs(originalNumber);
|
|
8
|
+
// 將原始數字轉換為字符串以便計算其長度
|
|
9
|
+
var originalNumberStr = originalNumber.toString();
|
|
10
|
+
// 計算原始數字的位數
|
|
11
|
+
var numberOfDigits = originalNumberStr.length;
|
|
12
|
+
// 計算需要除以的數量,即 10 的位數次方
|
|
13
|
+
var divisionFactor = Math.pow(10, numberOfDigits - 1);
|
|
14
|
+
return divisionFactor;
|
|
15
|
+
}
|
|
16
|
+
exports.default = calculateDivisionFactor;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var calculateDivisionFactor_1 = require("./calculateDivisionFactor");
|
|
4
|
+
describe("test calculateDivisionFactor methods", function () {
|
|
5
|
+
it("test 435435.13", function () {
|
|
6
|
+
var divisionFactor = (0, calculateDivisionFactor_1.default)(435435.13);
|
|
7
|
+
expect(divisionFactor).toEqual(100000);
|
|
8
|
+
});
|
|
9
|
+
it("test 0.13", function () {
|
|
10
|
+
var divisionFactor = (0, calculateDivisionFactor_1.default)(0.13);
|
|
11
|
+
expect(divisionFactor).toEqual(1);
|
|
12
|
+
});
|
|
13
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import Angle from "./index";
|
|
2
|
+
describe("test Angle methods", function () {
|
|
3
|
+
it("test (0,0) (1,1)", function () {
|
|
4
|
+
var y = [0, 1];
|
|
5
|
+
var angle = Angle(y);
|
|
6
|
+
expect(angle).toEqual(45);
|
|
7
|
+
});
|
|
8
|
+
it("test [0, 200]", function () {
|
|
9
|
+
var y = [0, 200];
|
|
10
|
+
var angle = Angle(y);
|
|
11
|
+
expect(angle).toEqual(63.43494882292201);
|
|
12
|
+
});
|
|
13
|
+
it("test [0, 0]", function () {
|
|
14
|
+
var y = [0, 0];
|
|
15
|
+
var angle = Angle(y);
|
|
16
|
+
expect(angle).toEqual(0);
|
|
17
|
+
});
|
|
18
|
+
it("test [39.73, 48.15]", function () {
|
|
19
|
+
var y = [39.73, 48.15];
|
|
20
|
+
var angle = Angle(y);
|
|
21
|
+
expect(angle).toEqual(40.09737861178007);
|
|
22
|
+
});
|
|
23
|
+
it("test [15.46, 30.19]", function () {
|
|
24
|
+
var y = [15.46, 30.19];
|
|
25
|
+
var angle = Angle(y);
|
|
26
|
+
expect(angle).toEqual(55.82794164843938);
|
|
27
|
+
});
|
|
28
|
+
it("test [35.64, 37.09]", function () {
|
|
29
|
+
var y = [35.64, 37.09];
|
|
30
|
+
var angle = Angle(y);
|
|
31
|
+
expect(angle).toEqual(8.250387228905515);
|
|
32
|
+
});
|
|
33
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function TwoPointAngle(y: number[]): number;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import calculateDivisionFactor from "../../utils/calculateDivisionFactor";
|
|
2
|
+
export default function TwoPointAngle(y) {
|
|
3
|
+
if (y.length != 2)
|
|
4
|
+
return 0;
|
|
5
|
+
// 計算 x 和 y 的平均值
|
|
6
|
+
var increment = calculateDivisionFactor(y[1]);
|
|
7
|
+
var x = Array.from({ length: y.length }, function (_, index) { return index * increment; });
|
|
8
|
+
var m = (y[1] - y[0]) / (x[1] - x[0]);
|
|
9
|
+
// 計算角度(弧度)
|
|
10
|
+
var thetaRadians = Math.atan(m); // 轉換角度為度
|
|
11
|
+
var thetaDegrees = thetaRadians * (180 / Math.PI);
|
|
12
|
+
return thetaDegrees;
|
|
13
|
+
}
|
|
@@ -1,8 +1,11 @@
|
|
|
1
|
+
import calculateDivisionFactor from "../../utils/calculateDivisionFactor";
|
|
1
2
|
export default function Slope(y) {
|
|
2
3
|
// 計算 x 和 y 的平均值
|
|
3
|
-
var x = Array.from({ length: y.length }, function (_, k) { return k + 1; });
|
|
4
|
-
var x_mean = x.reduce(function (acc, cur) { return acc + cur; }) / x.length;
|
|
5
4
|
var y_mean = y.reduce(function (acc, cur) { return acc + cur; }) / y.length;
|
|
5
|
+
var increment = calculateDivisionFactor(y_mean);
|
|
6
|
+
console.log(y_mean, increment);
|
|
7
|
+
var x = Array.from({ length: y.length }, function (_, index) { return index * increment; });
|
|
8
|
+
var x_mean = x.reduce(function (acc, cur) { return acc + cur; }) / x.length;
|
|
6
9
|
// 計算斜率
|
|
7
10
|
var numerator = x.reduce(function (acc, cur, i) { return acc + (cur - x_mean) * (y[i] - y_mean); }, 0);
|
|
8
11
|
var denominator = x.reduce(function (acc, cur) { return acc + Math.pow((cur - x_mean), 2); }, 0);
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export { default as Angle } from "./analyze/Angle/index.js";
|
|
1
2
|
export { default as simpleRegressionModel } from "./analyze/Regression/simpleRegressoinModel.js";
|
|
2
3
|
export { default as slope } from "./analyze/Slope/index.js";
|
|
3
4
|
export { exponentialSmoothing, movingAverages, weightMovingAverages, } from "./analyze/TimeSeries/R/index.js";
|
|
@@ -7,14 +8,15 @@ export { default as Ema } from "./stockSkills/ema.js";
|
|
|
7
8
|
export { default as Gold } from "./stockSkills/gold.js";
|
|
8
9
|
export { default as Kd } from "./stockSkills/kd.js";
|
|
9
10
|
export { default as Ma } from "./stockSkills/ma.js";
|
|
10
|
-
export { default as Vma } from "./stockSkills/vma.js";
|
|
11
11
|
export { default as Macd } from "./stockSkills/macd.js";
|
|
12
12
|
export { default as Obv } from "./stockSkills/obv.js";
|
|
13
13
|
export { default as Rsi } from "./stockSkills/rsi.js";
|
|
14
14
|
export { default as dateFormat } from "./stockSkills/utils/dateFormat.js";
|
|
15
15
|
export { default as getWeekLine } from "./stockSkills/utils/getWeekLine.js";
|
|
16
|
+
export { default as Vma } from "./stockSkills/vma.js";
|
|
16
17
|
export { default as Williams } from "./stockSkills/williams.js";
|
|
17
18
|
export { add } from "./test/add.js";
|
|
18
19
|
export { minus } from "./test/minus.js";
|
|
20
|
+
export { default as calculateDivisionFactor } from "./utils/calculateDivisionFactor.js";
|
|
19
21
|
export { default as isJSON } from "./utils/isJson.js";
|
|
20
22
|
export { default as parseLsusbOutput } from "./utils/parseLsusbOutput.js";
|
package/dist/esm/index.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
如果需要支持 Node.js 和構建工具(ex: webpack),則不需要這樣做。 **因為commonJs默認js副檔名**
|
|
4
4
|
但如果要支持 ES 模塊的瀏覽器 ,則需要文件擴展名(.js)。
|
|
5
5
|
*/
|
|
6
|
+
export { default as Angle } from "./analyze/Angle/index.js";
|
|
6
7
|
export { default as simpleRegressionModel } from "./analyze/Regression/simpleRegressoinModel.js";
|
|
7
8
|
export { default as slope } from "./analyze/Slope/index.js";
|
|
8
9
|
export { exponentialSmoothing, movingAverages, weightMovingAverages, } from "./analyze/TimeSeries/R/index.js";
|
|
@@ -12,14 +13,15 @@ export { default as Ema } from "./stockSkills/ema.js";
|
|
|
12
13
|
export { default as Gold } from "./stockSkills/gold.js";
|
|
13
14
|
export { default as Kd } from "./stockSkills/kd.js";
|
|
14
15
|
export { default as Ma } from "./stockSkills/ma.js";
|
|
15
|
-
export { default as Vma } from "./stockSkills/vma.js";
|
|
16
16
|
export { default as Macd } from "./stockSkills/macd.js";
|
|
17
17
|
export { default as Obv } from "./stockSkills/obv.js";
|
|
18
18
|
export { default as Rsi } from "./stockSkills/rsi.js";
|
|
19
19
|
export { default as dateFormat } from "./stockSkills/utils/dateFormat.js";
|
|
20
20
|
export { default as getWeekLine } from "./stockSkills/utils/getWeekLine.js";
|
|
21
|
+
export { default as Vma } from "./stockSkills/vma.js";
|
|
21
22
|
export { default as Williams } from "./stockSkills/williams.js";
|
|
22
23
|
export { add } from "./test/add.js";
|
|
23
24
|
export { minus } from "./test/minus.js";
|
|
25
|
+
export { default as calculateDivisionFactor } from "./utils/calculateDivisionFactor.js";
|
|
24
26
|
export { default as isJSON } from "./utils/isJson.js";
|
|
25
27
|
export { default as parseLsusbOutput } from "./utils/parseLsusbOutput.js";
|
|
@@ -37,6 +37,7 @@ interface MaType {
|
|
|
37
37
|
ma: number;
|
|
38
38
|
type: number;
|
|
39
39
|
exclusionValue: {
|
|
40
|
+
"d+1": number;
|
|
40
41
|
d: number;
|
|
41
42
|
"d-1": number;
|
|
42
43
|
};
|
|
@@ -46,6 +47,7 @@ interface MaType {
|
|
|
46
47
|
ma: number;
|
|
47
48
|
type: number;
|
|
48
49
|
exclusionValue: {
|
|
50
|
+
"d+1": number;
|
|
49
51
|
d: number;
|
|
50
52
|
"d-1": number;
|
|
51
53
|
};
|
|
@@ -54,6 +56,7 @@ interface MaType {
|
|
|
54
56
|
ma: number;
|
|
55
57
|
type: number;
|
|
56
58
|
exclusionValue: {
|
|
59
|
+
"d+1": number;
|
|
57
60
|
d: number;
|
|
58
61
|
"d-1": number;
|
|
59
62
|
};
|
|
@@ -71,6 +74,7 @@ export default class Ma implements MaType {
|
|
|
71
74
|
ma: number;
|
|
72
75
|
type: number;
|
|
73
76
|
exclusionValue: {
|
|
77
|
+
"d+1": number;
|
|
74
78
|
d: number;
|
|
75
79
|
"d-1": number;
|
|
76
80
|
};
|
|
@@ -84,6 +88,7 @@ export default class Ma implements MaType {
|
|
|
84
88
|
ma: number;
|
|
85
89
|
type: number;
|
|
86
90
|
exclusionValue: {
|
|
91
|
+
"d+1": number;
|
|
87
92
|
d: number;
|
|
88
93
|
"d-1": number;
|
|
89
94
|
};
|
|
@@ -17,7 +17,7 @@ var Ma = /** @class */ (function () {
|
|
|
17
17
|
configurable: true,
|
|
18
18
|
writable: true,
|
|
19
19
|
value: function (data, type) {
|
|
20
|
-
return { dataset: [data], ma: 0, type: type, exclusionValue: { d: 0, "d-1": 0 } };
|
|
20
|
+
return { dataset: [data], ma: 0, type: type, exclusionValue: { "d+1": 0, d: 0, "d-1": 0 } };
|
|
21
21
|
}
|
|
22
22
|
});
|
|
23
23
|
Object.defineProperty(Ma.prototype, "next", {
|
|
@@ -31,14 +31,15 @@ var Ma = /** @class */ (function () {
|
|
|
31
31
|
dataset: preList.dataset,
|
|
32
32
|
ma: 0,
|
|
33
33
|
type: type,
|
|
34
|
-
exclusionValue: { d: 0, "d-1": 0 },
|
|
34
|
+
exclusionValue: { "d+1": 0, d: 0, "d-1": 0 },
|
|
35
35
|
};
|
|
36
36
|
}
|
|
37
37
|
else {
|
|
38
|
-
var exclusionValue = { d: preList.dataset[0].c, "d-1": 0 };
|
|
38
|
+
var exclusionValue = { "d+1": preList.dataset[1].c, d: preList.dataset[0].c, "d-1": 0 };
|
|
39
39
|
if (preList.dataset.length > type) {
|
|
40
40
|
exclusionValue["d-1"] = exclusionValue.d;
|
|
41
41
|
preList.dataset.shift();
|
|
42
|
+
exclusionValue["d+1"] = preList.dataset[1].c;
|
|
42
43
|
exclusionValue.d = preList.dataset[0].c;
|
|
43
44
|
}
|
|
44
45
|
var sum = preList.dataset.reduce(function (pre, current) { return pre + current.c; }, 0);
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
type
|
|
1
|
+
type DataType = {
|
|
2
2
|
h: number;
|
|
3
3
|
l: number;
|
|
4
4
|
c: number;
|
|
5
|
-
}
|
|
5
|
+
};
|
|
6
|
+
type ListType = DataType[];
|
|
6
7
|
type ResWilliams9Type = {
|
|
7
8
|
c: number;
|
|
8
9
|
williams9: number | null;
|
|
@@ -17,11 +18,39 @@ type ResAllWilliamsType = {
|
|
|
17
18
|
williams9: number | null;
|
|
18
19
|
}[];
|
|
19
20
|
interface WilliamsType {
|
|
21
|
+
init: (data: DataType, type: number) => {
|
|
22
|
+
dataset: ListType;
|
|
23
|
+
williams: number;
|
|
24
|
+
type: number;
|
|
25
|
+
};
|
|
26
|
+
next: (data: DataType, preList: {
|
|
27
|
+
dataset: ListType;
|
|
28
|
+
williams: number;
|
|
29
|
+
type: number;
|
|
30
|
+
}, type: number) => {
|
|
31
|
+
dataset: ListType;
|
|
32
|
+
williams: number;
|
|
33
|
+
type: number;
|
|
34
|
+
};
|
|
20
35
|
getWilliams9: (list: ListType) => ResWilliams9Type;
|
|
21
36
|
getWilliams18: (list: ListType) => ResWilliams18Type;
|
|
22
37
|
getAllWillams(list: ListType): ResAllWilliamsType;
|
|
23
38
|
}
|
|
24
39
|
export default class Williams implements WilliamsType {
|
|
40
|
+
init(data: DataType, type: number): {
|
|
41
|
+
dataset: DataType[];
|
|
42
|
+
williams: number;
|
|
43
|
+
type: number;
|
|
44
|
+
};
|
|
45
|
+
next(data: DataType, preList: {
|
|
46
|
+
dataset: ListType;
|
|
47
|
+
williams: number;
|
|
48
|
+
type: number;
|
|
49
|
+
}, type: number): {
|
|
50
|
+
dataset: ListType;
|
|
51
|
+
williams: number;
|
|
52
|
+
type: number;
|
|
53
|
+
};
|
|
25
54
|
getAllWillams(list: ListType): ResAllWilliamsType;
|
|
26
55
|
getWilliams9(list: ListType): ResWilliams9Type;
|
|
27
56
|
getWilliams18(list: ListType): ResWilliams18Type;
|
|
@@ -12,6 +12,42 @@ var __assign = (this && this.__assign) || function () {
|
|
|
12
12
|
var Williams = /** @class */ (function () {
|
|
13
13
|
function Williams() {
|
|
14
14
|
}
|
|
15
|
+
Object.defineProperty(Williams.prototype, "init", {
|
|
16
|
+
enumerable: false,
|
|
17
|
+
configurable: true,
|
|
18
|
+
writable: true,
|
|
19
|
+
value: function (data, type) {
|
|
20
|
+
return { dataset: [data], williams: 0, type: type };
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
Object.defineProperty(Williams.prototype, "next", {
|
|
24
|
+
enumerable: false,
|
|
25
|
+
configurable: true,
|
|
26
|
+
writable: true,
|
|
27
|
+
value: function (data, preList, type) {
|
|
28
|
+
preList.dataset.push(data);
|
|
29
|
+
if (preList.dataset.length < type) {
|
|
30
|
+
return {
|
|
31
|
+
dataset: preList.dataset,
|
|
32
|
+
williams: 0,
|
|
33
|
+
type: type,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
if (preList.dataset.length > type) {
|
|
38
|
+
preList.dataset.shift();
|
|
39
|
+
}
|
|
40
|
+
var maxList = preList.dataset.map(function (item) { return item["h"]; });
|
|
41
|
+
var minList = preList.dataset.map(function (item) { return item["l"]; });
|
|
42
|
+
var max = Math.max.apply(Math, maxList);
|
|
43
|
+
var min = Math.min.apply(Math, minList);
|
|
44
|
+
var close_1 = data.c;
|
|
45
|
+
var williams = ((max - close_1) / (max - min)) * -100;
|
|
46
|
+
williams = Math.round(williams * 100) / 100;
|
|
47
|
+
return { dataset: preList.dataset, williams: williams, type: type };
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
});
|
|
15
51
|
Object.defineProperty(Williams.prototype, "getAllWillams", {
|
|
16
52
|
enumerable: false,
|
|
17
53
|
configurable: true,
|
|
@@ -40,8 +76,8 @@ var Williams = /** @class */ (function () {
|
|
|
40
76
|
var minList = list.slice(i - 8, i).map(function (item) { return item["l"]; });
|
|
41
77
|
var max = Math.max.apply(Math, maxList);
|
|
42
78
|
var min = Math.min.apply(Math, minList);
|
|
43
|
-
var
|
|
44
|
-
var williams9 = ((max -
|
|
79
|
+
var close_2 = list[i]["c"];
|
|
80
|
+
var williams9 = ((max - close_2) / (max - min)) * -100;
|
|
45
81
|
res[i] = __assign(__assign({}, list[i]), { williams9: Math.round(williams9 * 100) / 100 });
|
|
46
82
|
}
|
|
47
83
|
}
|
|
@@ -62,8 +98,8 @@ var Williams = /** @class */ (function () {
|
|
|
62
98
|
var minList = list.slice(i - 17, i).map(function (item) { return item["l"]; });
|
|
63
99
|
var max = Math.max.apply(Math, maxList);
|
|
64
100
|
var min = Math.min.apply(Math, minList);
|
|
65
|
-
var
|
|
66
|
-
var williams18 = ((max -
|
|
101
|
+
var close_3 = list[i]["c"];
|
|
102
|
+
var williams18 = ((max - close_3) / (max - min)) * -100;
|
|
67
103
|
res[i] = __assign(__assign({}, list[i]), { williams18: Math.round(williams18 * 100) / 100 });
|
|
68
104
|
}
|
|
69
105
|
}
|
|
@@ -1,6 +1,17 @@
|
|
|
1
1
|
import Williams from "./williams";
|
|
2
2
|
import data from "./test_data.test";
|
|
3
3
|
describe("test williams methods", function () {
|
|
4
|
+
it("test next()", function () {
|
|
5
|
+
var index = data.length - 1;
|
|
6
|
+
var williams = new Williams();
|
|
7
|
+
var init = williams.init(data[0], 9);
|
|
8
|
+
var res = init;
|
|
9
|
+
for (var i = 1; i <= index; i++) {
|
|
10
|
+
var item = data[i];
|
|
11
|
+
res = williams.next(item, res, 9);
|
|
12
|
+
}
|
|
13
|
+
expect(res.williams).toEqual(-79.59);
|
|
14
|
+
});
|
|
4
15
|
it("test getWilliams9()", function () {
|
|
5
16
|
var williams = new Williams();
|
|
6
17
|
expect(williams.getWilliams9(data)[data.length - 1]).toEqual({
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function calculateDivisionFactor(originalNumber: number): number;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export default function calculateDivisionFactor(originalNumber) {
|
|
2
|
+
// 去除小數點
|
|
3
|
+
originalNumber = Math.floor(originalNumber);
|
|
4
|
+
// 轉換正數
|
|
5
|
+
originalNumber = Math.abs(originalNumber);
|
|
6
|
+
// 將原始數字轉換為字符串以便計算其長度
|
|
7
|
+
var originalNumberStr = originalNumber.toString();
|
|
8
|
+
// 計算原始數字的位數
|
|
9
|
+
var numberOfDigits = originalNumberStr.length;
|
|
10
|
+
// 計算需要除以的數量,即 10 的位數次方
|
|
11
|
+
var divisionFactor = Math.pow(10, numberOfDigits - 1);
|
|
12
|
+
return divisionFactor;
|
|
13
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import calculateDivisionFactor from "./calculateDivisionFactor";
|
|
2
|
+
describe("test calculateDivisionFactor methods", function () {
|
|
3
|
+
it("test 435435.13", function () {
|
|
4
|
+
var divisionFactor = calculateDivisionFactor(435435.13);
|
|
5
|
+
expect(divisionFactor).toEqual(100000);
|
|
6
|
+
});
|
|
7
|
+
it("test 0.13", function () {
|
|
8
|
+
var divisionFactor = calculateDivisionFactor(0.13);
|
|
9
|
+
expect(divisionFactor).toEqual(1);
|
|
10
|
+
});
|
|
11
|
+
});
|
package/dist/umd/index.js
CHANGED
|
@@ -4,6 +4,33 @@
|
|
|
4
4
|
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.anysis = {}));
|
|
5
5
|
})(this, (function (exports) { 'use strict';
|
|
6
6
|
|
|
7
|
+
function calculateDivisionFactor(originalNumber) {
|
|
8
|
+
// 去除小數點
|
|
9
|
+
originalNumber = Math.floor(originalNumber);
|
|
10
|
+
// 轉換正數
|
|
11
|
+
originalNumber = Math.abs(originalNumber);
|
|
12
|
+
// 將原始數字轉換為字符串以便計算其長度
|
|
13
|
+
var originalNumberStr = originalNumber.toString();
|
|
14
|
+
// 計算原始數字的位數
|
|
15
|
+
var numberOfDigits = originalNumberStr.length;
|
|
16
|
+
// 計算需要除以的數量,即 10 的位數次方
|
|
17
|
+
var divisionFactor = Math.pow(10, numberOfDigits - 1);
|
|
18
|
+
return divisionFactor;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function TwoPointAngle(y) {
|
|
22
|
+
if (y.length != 2)
|
|
23
|
+
return 0;
|
|
24
|
+
// 計算 x 和 y 的平均值
|
|
25
|
+
var increment = calculateDivisionFactor(y[1]);
|
|
26
|
+
var x = Array.from({ length: y.length }, function (_, index) { return index * increment; });
|
|
27
|
+
var m = (y[1] - y[0]) / (x[1] - x[0]);
|
|
28
|
+
// 計算角度(弧度)
|
|
29
|
+
var thetaRadians = Math.atan(m); // 轉換角度為度
|
|
30
|
+
var thetaDegrees = thetaRadians * (180 / Math.PI);
|
|
31
|
+
return thetaDegrees;
|
|
32
|
+
}
|
|
33
|
+
|
|
7
34
|
function average(arr) {
|
|
8
35
|
var total = arr.reduce(function (prev, curr) { return prev + curr; });
|
|
9
36
|
var xBar = total / arr.length;
|
|
@@ -83,9 +110,11 @@
|
|
|
83
110
|
|
|
84
111
|
function Slope(y) {
|
|
85
112
|
// 計算 x 和 y 的平均值
|
|
86
|
-
var x = Array.from({ length: y.length }, function (_, k) { return k + 1; });
|
|
87
|
-
var x_mean = x.reduce(function (acc, cur) { return acc + cur; }) / x.length;
|
|
88
113
|
var y_mean = y.reduce(function (acc, cur) { return acc + cur; }) / y.length;
|
|
114
|
+
var increment = calculateDivisionFactor(y_mean);
|
|
115
|
+
console.log(y_mean, increment);
|
|
116
|
+
var x = Array.from({ length: y.length }, function (_, index) { return index * increment; });
|
|
117
|
+
var x_mean = x.reduce(function (acc, cur) { return acc + cur; }) / x.length;
|
|
89
118
|
// 計算斜率
|
|
90
119
|
var numerator = x.reduce(function (acc, cur, i) { return acc + (cur - x_mean) * (y[i] - y_mean); }, 0);
|
|
91
120
|
var denominator = x.reduce(function (acc, cur) { return acc + Math.pow((cur - x_mean), 2); }, 0);
|
|
@@ -741,7 +770,7 @@
|
|
|
741
770
|
configurable: true,
|
|
742
771
|
writable: true,
|
|
743
772
|
value: function (data, type) {
|
|
744
|
-
return { dataset: [data], ma: 0, type: type, exclusionValue: { d: 0, "d-1": 0 } };
|
|
773
|
+
return { dataset: [data], ma: 0, type: type, exclusionValue: { "d+1": 0, d: 0, "d-1": 0 } };
|
|
745
774
|
}
|
|
746
775
|
});
|
|
747
776
|
Object.defineProperty(Ma.prototype, "next", {
|
|
@@ -755,14 +784,15 @@
|
|
|
755
784
|
dataset: preList.dataset,
|
|
756
785
|
ma: 0,
|
|
757
786
|
type: type,
|
|
758
|
-
exclusionValue: { d: 0, "d-1": 0 },
|
|
787
|
+
exclusionValue: { "d+1": 0, d: 0, "d-1": 0 },
|
|
759
788
|
};
|
|
760
789
|
}
|
|
761
790
|
else {
|
|
762
|
-
var exclusionValue = { d: preList.dataset[0].c, "d-1": 0 };
|
|
791
|
+
var exclusionValue = { "d+1": preList.dataset[1].c, d: preList.dataset[0].c, "d-1": 0 };
|
|
763
792
|
if (preList.dataset.length > type) {
|
|
764
793
|
exclusionValue["d-1"] = exclusionValue.d;
|
|
765
794
|
preList.dataset.shift();
|
|
795
|
+
exclusionValue["d+1"] = preList.dataset[1].c;
|
|
766
796
|
exclusionValue.d = preList.dataset[0].c;
|
|
767
797
|
}
|
|
768
798
|
var sum = preList.dataset.reduce(function (pre, current) { return pre + current.c; }, 0);
|
|
@@ -890,39 +920,6 @@
|
|
|
890
920
|
return Ma;
|
|
891
921
|
}());
|
|
892
922
|
|
|
893
|
-
var Vma = /** @class */ (function () {
|
|
894
|
-
function Vma() {
|
|
895
|
-
}
|
|
896
|
-
Object.defineProperty(Vma.prototype, "init", {
|
|
897
|
-
enumerable: false,
|
|
898
|
-
configurable: true,
|
|
899
|
-
writable: true,
|
|
900
|
-
value: function (data, type) {
|
|
901
|
-
return { dataset: [data], vma: 0, type: type };
|
|
902
|
-
}
|
|
903
|
-
});
|
|
904
|
-
Object.defineProperty(Vma.prototype, "next", {
|
|
905
|
-
enumerable: false,
|
|
906
|
-
configurable: true,
|
|
907
|
-
writable: true,
|
|
908
|
-
value: function (data, preList, type) {
|
|
909
|
-
preList.dataset.push(data);
|
|
910
|
-
if (preList.dataset.length < type) {
|
|
911
|
-
return { dataset: preList.dataset, vma: 0, type: type };
|
|
912
|
-
}
|
|
913
|
-
else {
|
|
914
|
-
if (preList.dataset.length > type) {
|
|
915
|
-
preList.dataset.shift();
|
|
916
|
-
}
|
|
917
|
-
var sum = preList.dataset.reduce(function (pre, current) { return pre + current.v; }, 0);
|
|
918
|
-
var vma = Math.round((sum / type) * 100) / 100;
|
|
919
|
-
return { dataset: preList.dataset, vma: vma, type: type };
|
|
920
|
-
}
|
|
921
|
-
}
|
|
922
|
-
});
|
|
923
|
-
return Vma;
|
|
924
|
-
}());
|
|
925
|
-
|
|
926
923
|
var __assign$3 = (undefined && undefined.__assign) || function () {
|
|
927
924
|
__assign$3 = Object.assign || function(t) {
|
|
928
925
|
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
@@ -1448,6 +1445,39 @@
|
|
|
1448
1445
|
}
|
|
1449
1446
|
}
|
|
1450
1447
|
|
|
1448
|
+
var Vma = /** @class */ (function () {
|
|
1449
|
+
function Vma() {
|
|
1450
|
+
}
|
|
1451
|
+
Object.defineProperty(Vma.prototype, "init", {
|
|
1452
|
+
enumerable: false,
|
|
1453
|
+
configurable: true,
|
|
1454
|
+
writable: true,
|
|
1455
|
+
value: function (data, type) {
|
|
1456
|
+
return { dataset: [data], vma: 0, type: type };
|
|
1457
|
+
}
|
|
1458
|
+
});
|
|
1459
|
+
Object.defineProperty(Vma.prototype, "next", {
|
|
1460
|
+
enumerable: false,
|
|
1461
|
+
configurable: true,
|
|
1462
|
+
writable: true,
|
|
1463
|
+
value: function (data, preList, type) {
|
|
1464
|
+
preList.dataset.push(data);
|
|
1465
|
+
if (preList.dataset.length < type) {
|
|
1466
|
+
return { dataset: preList.dataset, vma: 0, type: type };
|
|
1467
|
+
}
|
|
1468
|
+
else {
|
|
1469
|
+
if (preList.dataset.length > type) {
|
|
1470
|
+
preList.dataset.shift();
|
|
1471
|
+
}
|
|
1472
|
+
var sum = preList.dataset.reduce(function (pre, current) { return pre + current.v; }, 0);
|
|
1473
|
+
var vma = Math.round((sum / type) * 100) / 100;
|
|
1474
|
+
return { dataset: preList.dataset, vma: vma, type: type };
|
|
1475
|
+
}
|
|
1476
|
+
}
|
|
1477
|
+
});
|
|
1478
|
+
return Vma;
|
|
1479
|
+
}());
|
|
1480
|
+
|
|
1451
1481
|
var __assign = (undefined && undefined.__assign) || function () {
|
|
1452
1482
|
__assign = Object.assign || function(t) {
|
|
1453
1483
|
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
@@ -1462,6 +1492,42 @@
|
|
|
1462
1492
|
var Williams = /** @class */ (function () {
|
|
1463
1493
|
function Williams() {
|
|
1464
1494
|
}
|
|
1495
|
+
Object.defineProperty(Williams.prototype, "init", {
|
|
1496
|
+
enumerable: false,
|
|
1497
|
+
configurable: true,
|
|
1498
|
+
writable: true,
|
|
1499
|
+
value: function (data, type) {
|
|
1500
|
+
return { dataset: [data], williams: 0, type: type };
|
|
1501
|
+
}
|
|
1502
|
+
});
|
|
1503
|
+
Object.defineProperty(Williams.prototype, "next", {
|
|
1504
|
+
enumerable: false,
|
|
1505
|
+
configurable: true,
|
|
1506
|
+
writable: true,
|
|
1507
|
+
value: function (data, preList, type) {
|
|
1508
|
+
preList.dataset.push(data);
|
|
1509
|
+
if (preList.dataset.length < type) {
|
|
1510
|
+
return {
|
|
1511
|
+
dataset: preList.dataset,
|
|
1512
|
+
williams: 0,
|
|
1513
|
+
type: type,
|
|
1514
|
+
};
|
|
1515
|
+
}
|
|
1516
|
+
else {
|
|
1517
|
+
if (preList.dataset.length > type) {
|
|
1518
|
+
preList.dataset.shift();
|
|
1519
|
+
}
|
|
1520
|
+
var maxList = preList.dataset.map(function (item) { return item["h"]; });
|
|
1521
|
+
var minList = preList.dataset.map(function (item) { return item["l"]; });
|
|
1522
|
+
var max = Math.max.apply(Math, maxList);
|
|
1523
|
+
var min = Math.min.apply(Math, minList);
|
|
1524
|
+
var close_1 = data.c;
|
|
1525
|
+
var williams = ((max - close_1) / (max - min)) * -100;
|
|
1526
|
+
williams = Math.round(williams * 100) / 100;
|
|
1527
|
+
return { dataset: preList.dataset, williams: williams, type: type };
|
|
1528
|
+
}
|
|
1529
|
+
}
|
|
1530
|
+
});
|
|
1465
1531
|
Object.defineProperty(Williams.prototype, "getAllWillams", {
|
|
1466
1532
|
enumerable: false,
|
|
1467
1533
|
configurable: true,
|
|
@@ -1490,8 +1556,8 @@
|
|
|
1490
1556
|
var minList = list.slice(i - 8, i).map(function (item) { return item["l"]; });
|
|
1491
1557
|
var max = Math.max.apply(Math, maxList);
|
|
1492
1558
|
var min = Math.min.apply(Math, minList);
|
|
1493
|
-
var
|
|
1494
|
-
var williams9 = ((max -
|
|
1559
|
+
var close_2 = list[i]["c"];
|
|
1560
|
+
var williams9 = ((max - close_2) / (max - min)) * -100;
|
|
1495
1561
|
res[i] = __assign(__assign({}, list[i]), { williams9: Math.round(williams9 * 100) / 100 });
|
|
1496
1562
|
}
|
|
1497
1563
|
}
|
|
@@ -1512,8 +1578,8 @@
|
|
|
1512
1578
|
var minList = list.slice(i - 17, i).map(function (item) { return item["l"]; });
|
|
1513
1579
|
var max = Math.max.apply(Math, maxList);
|
|
1514
1580
|
var min = Math.min.apply(Math, minList);
|
|
1515
|
-
var
|
|
1516
|
-
var williams18 = ((max -
|
|
1581
|
+
var close_3 = list[i]["c"];
|
|
1582
|
+
var williams18 = ((max - close_3) / (max - min)) * -100;
|
|
1517
1583
|
res[i] = __assign(__assign({}, list[i]), { williams18: Math.round(williams18 * 100) / 100 });
|
|
1518
1584
|
}
|
|
1519
1585
|
}
|
|
@@ -1559,6 +1625,7 @@
|
|
|
1559
1625
|
return devices;
|
|
1560
1626
|
}
|
|
1561
1627
|
|
|
1628
|
+
exports.Angle = TwoPointAngle;
|
|
1562
1629
|
exports.Boll = Boll;
|
|
1563
1630
|
exports.Ema = Ema;
|
|
1564
1631
|
exports.Gold = Gold;
|
|
@@ -1571,6 +1638,7 @@
|
|
|
1571
1638
|
exports.Williams = Williams;
|
|
1572
1639
|
exports.add = add;
|
|
1573
1640
|
exports.calcSeasonalIndicesNoTrend = calcSeasonalIndicesNoTrend;
|
|
1641
|
+
exports.calculateDivisionFactor = calculateDivisionFactor;
|
|
1574
1642
|
exports.dateFormat = dateFormat;
|
|
1575
1643
|
exports.exponentialSmoothing = exponentialSmoothing;
|
|
1576
1644
|
exports.getWeekLine = getWeekLine;
|