@ch20026103/anysis 0.0.7-alpha → 0.0.9-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 +122 -0
- package/dist/cjs/analyze/Slope/index.d.ts +1 -1
- package/dist/cjs/analyze/Slope/index.js +2 -1
- package/dist/cjs/analyze/Slope/slope.test.js +5 -10
- package/dist/cjs/index.d.ts +2 -0
- package/dist/cjs/index.js +5 -1
- package/dist/cjs/stockSkills/obv.d.ts +16 -4
- package/dist/cjs/stockSkills/obv.js +13 -2
- package/dist/cjs/stockSkills/obv.test.js +3 -3
- package/dist/cjs/stockSkills/vma.d.ts +38 -0
- package/dist/cjs/stockSkills/vma.js +35 -0
- package/dist/cjs/stockSkills/vma.test.d.ts +1 -0
- package/dist/cjs/stockSkills/vma.test.js +17 -0
- package/dist/cjs/utils/isJson.test.d.ts +1 -0
- package/dist/cjs/utils/isJson.test.js +20 -0
- package/dist/cjs/utils/parseLsusbOutput.d.ts +6 -0
- package/dist/cjs/utils/parseLsusbOutput.js +20 -0
- package/dist/cjs/utils/parseLsusbOutput.test.d.ts +1 -0
- package/dist/cjs/utils/parseLsusbOutput.test.js +23 -0
- package/dist/esm/analyze/Slope/index.d.ts +1 -1
- package/dist/esm/analyze/Slope/index.js +2 -1
- package/dist/esm/analyze/Slope/slope.test.js +5 -10
- package/dist/esm/index.d.ts +2 -0
- package/dist/esm/index.js +2 -0
- package/dist/esm/stockSkills/obv.d.ts +16 -4
- package/dist/esm/stockSkills/obv.js +13 -2
- package/dist/esm/stockSkills/obv.test.js +3 -3
- package/dist/esm/stockSkills/vma.d.ts +38 -0
- package/dist/esm/stockSkills/vma.js +33 -0
- package/dist/esm/stockSkills/vma.test.d.ts +1 -0
- package/dist/esm/stockSkills/vma.test.js +15 -0
- package/dist/esm/utils/isJson.test.d.ts +1 -0
- package/dist/esm/utils/isJson.test.js +18 -0
- package/dist/esm/utils/parseLsusbOutput.d.ts +6 -0
- package/dist/esm/utils/parseLsusbOutput.js +17 -0
- package/dist/esm/utils/parseLsusbOutput.test.d.ts +1 -0
- package/dist/esm/utils/parseLsusbOutput.test.js +21 -0
- package/dist/umd/index.js +68 -3
- package/package.json +2 -2
package/demo/main.js
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/* eslint @typescript-eslint/no-var-requires: "off" */
|
|
2
|
+
const axios = require("axios");
|
|
3
|
+
const { Obv, Macd, Kd, Boll, Vma } = require("../dist/cjs/index.js");
|
|
4
|
+
const obv = new Obv();
|
|
5
|
+
const macd = new Macd();
|
|
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() {
|
|
15
|
+
axios
|
|
16
|
+
.get(
|
|
17
|
+
`https://tw.quote.finance.yahoo.net/quote/q?type=ta&perd=d&mkt=10&sym=${stockId}&v=1&callback=`
|
|
18
|
+
)
|
|
19
|
+
.then((res) => {
|
|
20
|
+
let json = res.data.match(/"ta":(\S*),"ex"/)[1];
|
|
21
|
+
let data = JSON.parse(json).slice(0, -21);
|
|
22
|
+
let obvData = obv.init(data[0], 5);
|
|
23
|
+
let macdData = macd.init(data[0]);
|
|
24
|
+
let kdData = kd.init(data[0]);
|
|
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
|
+
|
|
48
|
+
for (let i = 1; i < data.length; i++) {
|
|
49
|
+
obvData = obv.next(data[i], obvData, 5);
|
|
50
|
+
macdData = macd.next(data[i], macdData);
|
|
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
|
+
});
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
console.log(finallyData[finallyData.length - 1]);
|
|
75
|
+
})
|
|
76
|
+
.catch((error) => {
|
|
77
|
+
console.error(error);
|
|
78
|
+
})
|
|
79
|
+
.finally(() => {
|
|
80
|
+
console.log("day done");
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function DemoWeek() {
|
|
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
|
+
ma10: weekMaData10.ma,
|
|
106
|
+
ma20: weekMaData20.ma,
|
|
107
|
+
});
|
|
108
|
+
})
|
|
109
|
+
.catch((error) => {
|
|
110
|
+
console.error(error);
|
|
111
|
+
})
|
|
112
|
+
.finally(() => {
|
|
113
|
+
console.log("week done");
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
DemoDay();
|
|
118
|
+
|
|
119
|
+
const showWeek = false;
|
|
120
|
+
if (showWeek) {
|
|
121
|
+
DemoWeek();
|
|
122
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export default function Slope(
|
|
1
|
+
export default function Slope(y: number[]): number;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
function Slope(
|
|
3
|
+
function Slope(y) {
|
|
4
4
|
// 計算 x 和 y 的平均值
|
|
5
|
+
var x = Array.from({ length: y.length }, function (_, k) { return k + 1; });
|
|
5
6
|
var x_mean = x.reduce(function (acc, cur) { return acc + cur; }) / x.length;
|
|
6
7
|
var y_mean = y.reduce(function (acc, cur) { return acc + cur; }) / y.length;
|
|
7
8
|
// 計算斜率
|
|
@@ -3,33 +3,28 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
var index_1 = require("./index");
|
|
4
4
|
describe("test Slope methods", function () {
|
|
5
5
|
it("test 123456", function () {
|
|
6
|
-
var x = [1, 2, 3, 4, 5, 6];
|
|
7
6
|
var y = [1, 2, 3, 4, 5, 6];
|
|
8
|
-
var slope = (0, index_1.default)(
|
|
7
|
+
var slope = (0, index_1.default)(y);
|
|
9
8
|
expect(slope).toEqual(1);
|
|
10
9
|
});
|
|
11
10
|
it("test -123456", function () {
|
|
12
|
-
var x = [1, 2, 3, 4, 5, 6];
|
|
13
11
|
var y = [-1, -2, -3, -4, -5, -6];
|
|
14
|
-
var slope = (0, index_1.default)(
|
|
12
|
+
var slope = (0, index_1.default)(y);
|
|
15
13
|
expect(slope).toEqual(-1);
|
|
16
14
|
});
|
|
17
15
|
it("test 654321", function () {
|
|
18
|
-
var x = [1, 2, 3, 4, 5, 6];
|
|
19
16
|
var y = [6, 5, 4, 3, 2, 1];
|
|
20
|
-
var slope = (0, index_1.default)(
|
|
17
|
+
var slope = (0, index_1.default)(y);
|
|
21
18
|
expect(slope).toEqual(-1);
|
|
22
19
|
});
|
|
23
20
|
it("test 222222", function () {
|
|
24
|
-
var x = [1, 2, 3, 4, 5, 6];
|
|
25
21
|
var y = [2, 2, 2, 2, 2, 2];
|
|
26
|
-
var slope = (0, index_1.default)(
|
|
22
|
+
var slope = (0, index_1.default)(y);
|
|
27
23
|
expect(slope).toEqual(0);
|
|
28
24
|
});
|
|
29
25
|
it("test 1,4,6,8,10,12", function () {
|
|
30
|
-
var x = [1, 2, 3, 4, 5, 6];
|
|
31
26
|
var y = [1, 4, 6, 8, 10, 12];
|
|
32
|
-
var slope = (0, index_1.default)(
|
|
27
|
+
var slope = (0, index_1.default)(y);
|
|
33
28
|
expect(slope).toEqual(2.142857142857143);
|
|
34
29
|
});
|
|
35
30
|
});
|
package/dist/cjs/index.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ export { default as Ema } from "./stockSkills/ema.js";
|
|
|
7
7
|
export { default as Gold } from "./stockSkills/gold.js";
|
|
8
8
|
export { default as Kd } from "./stockSkills/kd.js";
|
|
9
9
|
export { default as Ma } from "./stockSkills/ma.js";
|
|
10
|
+
export { default as Vma } from "./stockSkills/vma.js";
|
|
10
11
|
export { default as Macd } from "./stockSkills/macd.js";
|
|
11
12
|
export { default as Obv } from "./stockSkills/obv.js";
|
|
12
13
|
export { default as Rsi } from "./stockSkills/rsi.js";
|
|
@@ -16,3 +17,4 @@ export { default as Williams } from "./stockSkills/williams.js";
|
|
|
16
17
|
export { add } from "./test/add.js";
|
|
17
18
|
export { minus } from "./test/minus.js";
|
|
18
19
|
export { default as isJSON } from "./utils/isJson.js";
|
|
20
|
+
export { default as parseLsusbOutput } from "./utils/parseLsusbOutput.js";
|
package/dist/cjs/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isJSON = exports.minus = exports.add = exports.Williams = 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 = void 0;
|
|
3
|
+
exports.parseLsusbOutput = exports.isJSON = exports.minus = exports.add = exports.Williams = exports.getWeekLine = exports.dateFormat = exports.Rsi = exports.Obv = exports.Macd = exports.Vma = exports.Ma = exports.Kd = exports.Gold = exports.Ema = exports.Boll = exports.calcSeasonalIndicesNoTrend = exports.weightMovingAverages = exports.movingAverages = exports.exponentialSmoothing = exports.slope = exports.simpleRegressionModel = void 0;
|
|
4
4
|
/*
|
|
5
5
|
請注意,在 src/index.ts 中,我的導入包含文件擴展名(.js)。
|
|
6
6
|
如果需要支持 Node.js 和構建工具(ex: webpack),則不需要這樣做。 **因為commonJs默認js副檔名**
|
|
@@ -26,6 +26,8 @@ var kd_js_1 = require("./stockSkills/kd.js");
|
|
|
26
26
|
Object.defineProperty(exports, "Kd", { enumerable: true, get: function () { return kd_js_1.default; } });
|
|
27
27
|
var ma_js_1 = require("./stockSkills/ma.js");
|
|
28
28
|
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; } });
|
|
29
31
|
var macd_js_1 = require("./stockSkills/macd.js");
|
|
30
32
|
Object.defineProperty(exports, "Macd", { enumerable: true, get: function () { return macd_js_1.default; } });
|
|
31
33
|
var obv_js_1 = require("./stockSkills/obv.js");
|
|
@@ -44,3 +46,5 @@ var minus_js_1 = require("./test/minus.js");
|
|
|
44
46
|
Object.defineProperty(exports, "minus", { enumerable: true, get: function () { return minus_js_1.minus; } });
|
|
45
47
|
var isJson_js_1 = require("./utils/isJson.js");
|
|
46
48
|
Object.defineProperty(exports, "isJSON", { enumerable: true, get: function () { return isJson_js_1.default; } });
|
|
49
|
+
var parseLsusbOutput_js_1 = require("./utils/parseLsusbOutput.js");
|
|
50
|
+
Object.defineProperty(exports, "parseLsusbOutput", { enumerable: true, get: function () { return parseLsusbOutput_js_1.default; } });
|
|
@@ -8,36 +8,48 @@ type ResObv = {
|
|
|
8
8
|
obv: number;
|
|
9
9
|
} & ItemType;
|
|
10
10
|
interface ObvType {
|
|
11
|
-
init: (data: ItemType) => {
|
|
11
|
+
init: (data: ItemType, type: number) => {
|
|
12
12
|
dataset: ItemType[];
|
|
13
13
|
obv: number;
|
|
14
|
+
obvList: number[];
|
|
14
15
|
preClose: number;
|
|
16
|
+
obvMa: number;
|
|
15
17
|
};
|
|
16
18
|
next: (data: ItemType, preList: {
|
|
17
19
|
dataset: ItemType[];
|
|
18
20
|
obv: number;
|
|
21
|
+
obvList: number[];
|
|
19
22
|
preClose: number;
|
|
20
|
-
|
|
23
|
+
obvMa: number;
|
|
24
|
+
}, type: number) => {
|
|
21
25
|
dataset: ItemType[];
|
|
22
26
|
obv: number;
|
|
27
|
+
obvList: number[];
|
|
23
28
|
preClose: number;
|
|
29
|
+
obvMa: number;
|
|
24
30
|
};
|
|
25
31
|
getObv: (list: ItemType[], period: number) => ResObv[];
|
|
26
32
|
}
|
|
27
33
|
export default class Obv implements ObvType {
|
|
28
|
-
init(data: ItemType): {
|
|
34
|
+
init(data: ItemType, type: number): {
|
|
29
35
|
dataset: ItemType[];
|
|
30
36
|
obv: number;
|
|
37
|
+
obvList: number[];
|
|
31
38
|
preClose: number;
|
|
39
|
+
obvMa: number;
|
|
32
40
|
};
|
|
33
41
|
next(data: ItemType, preList: {
|
|
34
42
|
dataset: ItemType[];
|
|
35
43
|
obv: number;
|
|
44
|
+
obvList: number[];
|
|
36
45
|
preClose: number;
|
|
37
|
-
|
|
46
|
+
obvMa: number;
|
|
47
|
+
}, type: number): {
|
|
38
48
|
dataset: ItemType[];
|
|
39
49
|
obv: number;
|
|
40
50
|
preClose: number;
|
|
51
|
+
obvList: number[];
|
|
52
|
+
obvMa: number;
|
|
41
53
|
};
|
|
42
54
|
getObv(list: ItemType[]): ResObv[];
|
|
43
55
|
}
|
|
@@ -27,11 +27,13 @@ var Obv = /** @class */ (function () {
|
|
|
27
27
|
enumerable: false,
|
|
28
28
|
configurable: true,
|
|
29
29
|
writable: true,
|
|
30
|
-
value: function (data) {
|
|
30
|
+
value: function (data, type) {
|
|
31
31
|
return {
|
|
32
32
|
dataset: [data],
|
|
33
33
|
obv: data.v,
|
|
34
|
+
obvList: [data.v],
|
|
34
35
|
preClose: data.c,
|
|
36
|
+
obvMa: 0,
|
|
35
37
|
};
|
|
36
38
|
}
|
|
37
39
|
});
|
|
@@ -39,7 +41,7 @@ var Obv = /** @class */ (function () {
|
|
|
39
41
|
enumerable: false,
|
|
40
42
|
configurable: true,
|
|
41
43
|
writable: true,
|
|
42
|
-
value: function (data, preList) {
|
|
44
|
+
value: function (data, preList, type) {
|
|
43
45
|
var currentVolume = data.v;
|
|
44
46
|
var currentClose = data.c;
|
|
45
47
|
// obv
|
|
@@ -50,10 +52,19 @@ var Obv = /** @class */ (function () {
|
|
|
50
52
|
else if (currentClose < preList.preClose) {
|
|
51
53
|
obv -= currentVolume;
|
|
52
54
|
}
|
|
55
|
+
// obv Ma
|
|
56
|
+
var obvList = preList.obvList;
|
|
57
|
+
obvList.push(obv);
|
|
58
|
+
if (obvList.length > type)
|
|
59
|
+
obvList.shift();
|
|
60
|
+
var sum = obvList.reduce(function (pre, current) { return pre + current; }, 0);
|
|
61
|
+
var vma = Math.round((sum / type) * 100) / 100;
|
|
53
62
|
return {
|
|
54
63
|
dataset: __spreadArray(__spreadArray([], preList.dataset, true), [data], false),
|
|
55
64
|
obv: obv,
|
|
56
65
|
preClose: currentClose,
|
|
66
|
+
obvList: obvList,
|
|
67
|
+
obvMa: vma
|
|
57
68
|
};
|
|
58
69
|
}
|
|
59
70
|
});
|
|
@@ -5,13 +5,13 @@ var test_data_test_1 = require("./test_data.test");
|
|
|
5
5
|
describe("test obv methods", function () {
|
|
6
6
|
it("test init", function () {
|
|
7
7
|
var obv = new obv_1.default();
|
|
8
|
-
var init = obv.init(test_data_test_1.data_9904[0]);
|
|
8
|
+
var init = obv.init(test_data_test_1.data_9904[0], 5);
|
|
9
9
|
var res = init;
|
|
10
10
|
for (var i = 1; i < test_data_test_1.data_9904.length; i++) {
|
|
11
11
|
var item = test_data_test_1.data_9904[i];
|
|
12
|
-
res = obv.next(item, res);
|
|
12
|
+
res = obv.next(item, res, 5);
|
|
13
13
|
}
|
|
14
|
-
expect(res.obv).toEqual(504538);
|
|
14
|
+
expect({ obv: res.obv, obvMa: res.obvMa }).toEqual({ obv: 504538, obvMa: 494302.2 });
|
|
15
15
|
});
|
|
16
16
|
it("test getObv()", function () {
|
|
17
17
|
var kd = new obv_1.default();
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
type DataType = {
|
|
2
|
+
v: number;
|
|
3
|
+
[key: string]: unknown;
|
|
4
|
+
};
|
|
5
|
+
type ListType = DataType[];
|
|
6
|
+
interface VmaType {
|
|
7
|
+
init: (data: DataType, type: number) => {
|
|
8
|
+
dataset: ListType;
|
|
9
|
+
vma: number;
|
|
10
|
+
type: number;
|
|
11
|
+
};
|
|
12
|
+
next: (data: DataType, preList: {
|
|
13
|
+
dataset: ListType;
|
|
14
|
+
vma: number;
|
|
15
|
+
type: number;
|
|
16
|
+
}, type: number) => {
|
|
17
|
+
dataset: ListType;
|
|
18
|
+
vma: number;
|
|
19
|
+
type: number;
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
export default class Vma implements VmaType {
|
|
23
|
+
init(data: DataType, type: number): {
|
|
24
|
+
dataset: DataType[];
|
|
25
|
+
vma: number;
|
|
26
|
+
type: number;
|
|
27
|
+
};
|
|
28
|
+
next(data: DataType, preList: {
|
|
29
|
+
dataset: ListType;
|
|
30
|
+
vma: number;
|
|
31
|
+
type: number;
|
|
32
|
+
}, type: number): {
|
|
33
|
+
dataset: ListType;
|
|
34
|
+
vma: number;
|
|
35
|
+
type: number;
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
export {};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var Vma = /** @class */ (function () {
|
|
4
|
+
function Vma() {
|
|
5
|
+
}
|
|
6
|
+
Object.defineProperty(Vma.prototype, "init", {
|
|
7
|
+
enumerable: false,
|
|
8
|
+
configurable: true,
|
|
9
|
+
writable: true,
|
|
10
|
+
value: function (data, type) {
|
|
11
|
+
return { dataset: [data], vma: 0, type: type };
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
Object.defineProperty(Vma.prototype, "next", {
|
|
15
|
+
enumerable: false,
|
|
16
|
+
configurable: true,
|
|
17
|
+
writable: true,
|
|
18
|
+
value: function (data, preList, type) {
|
|
19
|
+
preList.dataset.push(data);
|
|
20
|
+
if (preList.dataset.length < type) {
|
|
21
|
+
return { dataset: preList.dataset, vma: 0, type: type };
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
if (preList.dataset.length > type) {
|
|
25
|
+
preList.dataset.shift();
|
|
26
|
+
}
|
|
27
|
+
var sum = preList.dataset.reduce(function (pre, current) { return pre + current.v; }, 0);
|
|
28
|
+
var vma = Math.round((sum / type) * 100) / 100;
|
|
29
|
+
return { dataset: preList.dataset, vma: vma, type: type };
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
return Vma;
|
|
34
|
+
}());
|
|
35
|
+
exports.default = Vma;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var test_data_test_1 = require("./test_data.test");
|
|
4
|
+
var vma_1 = require("./vma");
|
|
5
|
+
describe("test vma methods", function () {
|
|
6
|
+
it("test init & next", function () {
|
|
7
|
+
var index = test_data_test_1.default.length - 1;
|
|
8
|
+
var vma = new vma_1.default();
|
|
9
|
+
var init = vma.init(test_data_test_1.default[0], 5);
|
|
10
|
+
var res = init;
|
|
11
|
+
for (var i = 1; i <= index; i++) {
|
|
12
|
+
var item = test_data_test_1.default[i];
|
|
13
|
+
res = vma.next(item, res, 5);
|
|
14
|
+
}
|
|
15
|
+
expect(res.vma).toEqual(12251.6);
|
|
16
|
+
});
|
|
17
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var isJson_1 = require("./isJson");
|
|
4
|
+
describe("test isJSON methods", function () {
|
|
5
|
+
it("test {}", function () {
|
|
6
|
+
var text = "{}";
|
|
7
|
+
var json = (0, isJson_1.default)(text);
|
|
8
|
+
expect(json).toEqual(true);
|
|
9
|
+
});
|
|
10
|
+
it("test [{}]", function () {
|
|
11
|
+
var text = "[{}]";
|
|
12
|
+
var json = (0, isJson_1.default)(text);
|
|
13
|
+
expect(json).toEqual(true);
|
|
14
|
+
});
|
|
15
|
+
it("test [{}]);", function () {
|
|
16
|
+
var text = "[{}]);";
|
|
17
|
+
var json = (0, isJson_1.default)(text);
|
|
18
|
+
expect(json).toEqual(false);
|
|
19
|
+
});
|
|
20
|
+
});
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
function parseLsusbOutput(output) {
|
|
4
|
+
var lines = output.trim().split("\n");
|
|
5
|
+
var devices = lines
|
|
6
|
+
.map(function (line) {
|
|
7
|
+
var match = line.match(/Bus (\d+) Device (\d+): ID ([a-f0-9]+:[a-f0-9]+) (.+)/);
|
|
8
|
+
if (match) {
|
|
9
|
+
var bus = match[1];
|
|
10
|
+
var device = match[2];
|
|
11
|
+
var id = match[3];
|
|
12
|
+
var description = match[4];
|
|
13
|
+
return { bus: bus, device: device, id: id, description: description };
|
|
14
|
+
}
|
|
15
|
+
return null;
|
|
16
|
+
})
|
|
17
|
+
.filter(function (device) { return device !== null; });
|
|
18
|
+
return devices;
|
|
19
|
+
}
|
|
20
|
+
exports.default = parseLsusbOutput;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var parseLsusbOutput_1 = require("./parseLsusbOutput");
|
|
4
|
+
describe("test parseLsusbOutput methods", function () {
|
|
5
|
+
it("test case1", function () {
|
|
6
|
+
var lsusbOutput = "\n Bus 001 Device 002: ID 8087:0024 Intel Corp. Integrated Rate Matching Hub\n Bus 001 Device 003: ID 0c45:64ad Microdia \n ";
|
|
7
|
+
var arr = (0, parseLsusbOutput_1.default)(lsusbOutput);
|
|
8
|
+
expect(arr).toEqual([
|
|
9
|
+
{
|
|
10
|
+
bus: "001",
|
|
11
|
+
device: "002",
|
|
12
|
+
id: "8087:0024",
|
|
13
|
+
description: "Intel Corp. Integrated Rate Matching Hub",
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
bus: "001",
|
|
17
|
+
device: "003",
|
|
18
|
+
id: "0c45:64ad",
|
|
19
|
+
description: "Microdia",
|
|
20
|
+
},
|
|
21
|
+
]);
|
|
22
|
+
});
|
|
23
|
+
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export default function Slope(
|
|
1
|
+
export default function Slope(y: number[]): number;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
export default function Slope(
|
|
1
|
+
export default function Slope(y) {
|
|
2
2
|
// 計算 x 和 y 的平均值
|
|
3
|
+
var x = Array.from({ length: y.length }, function (_, k) { return k + 1; });
|
|
3
4
|
var x_mean = x.reduce(function (acc, cur) { return acc + cur; }) / x.length;
|
|
4
5
|
var y_mean = y.reduce(function (acc, cur) { return acc + cur; }) / y.length;
|
|
5
6
|
// 計算斜率
|
|
@@ -1,33 +1,28 @@
|
|
|
1
1
|
import Slope from "./index";
|
|
2
2
|
describe("test Slope methods", function () {
|
|
3
3
|
it("test 123456", function () {
|
|
4
|
-
var x = [1, 2, 3, 4, 5, 6];
|
|
5
4
|
var y = [1, 2, 3, 4, 5, 6];
|
|
6
|
-
var slope = Slope(
|
|
5
|
+
var slope = Slope(y);
|
|
7
6
|
expect(slope).toEqual(1);
|
|
8
7
|
});
|
|
9
8
|
it("test -123456", function () {
|
|
10
|
-
var x = [1, 2, 3, 4, 5, 6];
|
|
11
9
|
var y = [-1, -2, -3, -4, -5, -6];
|
|
12
|
-
var slope = Slope(
|
|
10
|
+
var slope = Slope(y);
|
|
13
11
|
expect(slope).toEqual(-1);
|
|
14
12
|
});
|
|
15
13
|
it("test 654321", function () {
|
|
16
|
-
var x = [1, 2, 3, 4, 5, 6];
|
|
17
14
|
var y = [6, 5, 4, 3, 2, 1];
|
|
18
|
-
var slope = Slope(
|
|
15
|
+
var slope = Slope(y);
|
|
19
16
|
expect(slope).toEqual(-1);
|
|
20
17
|
});
|
|
21
18
|
it("test 222222", function () {
|
|
22
|
-
var x = [1, 2, 3, 4, 5, 6];
|
|
23
19
|
var y = [2, 2, 2, 2, 2, 2];
|
|
24
|
-
var slope = Slope(
|
|
20
|
+
var slope = Slope(y);
|
|
25
21
|
expect(slope).toEqual(0);
|
|
26
22
|
});
|
|
27
23
|
it("test 1,4,6,8,10,12", function () {
|
|
28
|
-
var x = [1, 2, 3, 4, 5, 6];
|
|
29
24
|
var y = [1, 4, 6, 8, 10, 12];
|
|
30
|
-
var slope = Slope(
|
|
25
|
+
var slope = Slope(y);
|
|
31
26
|
expect(slope).toEqual(2.142857142857143);
|
|
32
27
|
});
|
|
33
28
|
});
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ export { default as Ema } from "./stockSkills/ema.js";
|
|
|
7
7
|
export { default as Gold } from "./stockSkills/gold.js";
|
|
8
8
|
export { default as Kd } from "./stockSkills/kd.js";
|
|
9
9
|
export { default as Ma } from "./stockSkills/ma.js";
|
|
10
|
+
export { default as Vma } from "./stockSkills/vma.js";
|
|
10
11
|
export { default as Macd } from "./stockSkills/macd.js";
|
|
11
12
|
export { default as Obv } from "./stockSkills/obv.js";
|
|
12
13
|
export { default as Rsi } from "./stockSkills/rsi.js";
|
|
@@ -16,3 +17,4 @@ export { default as Williams } from "./stockSkills/williams.js";
|
|
|
16
17
|
export { add } from "./test/add.js";
|
|
17
18
|
export { minus } from "./test/minus.js";
|
|
18
19
|
export { default as isJSON } from "./utils/isJson.js";
|
|
20
|
+
export { default as parseLsusbOutput } from "./utils/parseLsusbOutput.js";
|
package/dist/esm/index.js
CHANGED
|
@@ -12,6 +12,7 @@ export { default as Ema } from "./stockSkills/ema.js";
|
|
|
12
12
|
export { default as Gold } from "./stockSkills/gold.js";
|
|
13
13
|
export { default as Kd } from "./stockSkills/kd.js";
|
|
14
14
|
export { default as Ma } from "./stockSkills/ma.js";
|
|
15
|
+
export { default as Vma } from "./stockSkills/vma.js";
|
|
15
16
|
export { default as Macd } from "./stockSkills/macd.js";
|
|
16
17
|
export { default as Obv } from "./stockSkills/obv.js";
|
|
17
18
|
export { default as Rsi } from "./stockSkills/rsi.js";
|
|
@@ -21,3 +22,4 @@ export { default as Williams } from "./stockSkills/williams.js";
|
|
|
21
22
|
export { add } from "./test/add.js";
|
|
22
23
|
export { minus } from "./test/minus.js";
|
|
23
24
|
export { default as isJSON } from "./utils/isJson.js";
|
|
25
|
+
export { default as parseLsusbOutput } from "./utils/parseLsusbOutput.js";
|
|
@@ -8,36 +8,48 @@ type ResObv = {
|
|
|
8
8
|
obv: number;
|
|
9
9
|
} & ItemType;
|
|
10
10
|
interface ObvType {
|
|
11
|
-
init: (data: ItemType) => {
|
|
11
|
+
init: (data: ItemType, type: number) => {
|
|
12
12
|
dataset: ItemType[];
|
|
13
13
|
obv: number;
|
|
14
|
+
obvList: number[];
|
|
14
15
|
preClose: number;
|
|
16
|
+
obvMa: number;
|
|
15
17
|
};
|
|
16
18
|
next: (data: ItemType, preList: {
|
|
17
19
|
dataset: ItemType[];
|
|
18
20
|
obv: number;
|
|
21
|
+
obvList: number[];
|
|
19
22
|
preClose: number;
|
|
20
|
-
|
|
23
|
+
obvMa: number;
|
|
24
|
+
}, type: number) => {
|
|
21
25
|
dataset: ItemType[];
|
|
22
26
|
obv: number;
|
|
27
|
+
obvList: number[];
|
|
23
28
|
preClose: number;
|
|
29
|
+
obvMa: number;
|
|
24
30
|
};
|
|
25
31
|
getObv: (list: ItemType[], period: number) => ResObv[];
|
|
26
32
|
}
|
|
27
33
|
export default class Obv implements ObvType {
|
|
28
|
-
init(data: ItemType): {
|
|
34
|
+
init(data: ItemType, type: number): {
|
|
29
35
|
dataset: ItemType[];
|
|
30
36
|
obv: number;
|
|
37
|
+
obvList: number[];
|
|
31
38
|
preClose: number;
|
|
39
|
+
obvMa: number;
|
|
32
40
|
};
|
|
33
41
|
next(data: ItemType, preList: {
|
|
34
42
|
dataset: ItemType[];
|
|
35
43
|
obv: number;
|
|
44
|
+
obvList: number[];
|
|
36
45
|
preClose: number;
|
|
37
|
-
|
|
46
|
+
obvMa: number;
|
|
47
|
+
}, type: number): {
|
|
38
48
|
dataset: ItemType[];
|
|
39
49
|
obv: number;
|
|
40
50
|
preClose: number;
|
|
51
|
+
obvList: number[];
|
|
52
|
+
obvMa: number;
|
|
41
53
|
};
|
|
42
54
|
getObv(list: ItemType[]): ResObv[];
|
|
43
55
|
}
|
|
@@ -25,11 +25,13 @@ var Obv = /** @class */ (function () {
|
|
|
25
25
|
enumerable: false,
|
|
26
26
|
configurable: true,
|
|
27
27
|
writable: true,
|
|
28
|
-
value: function (data) {
|
|
28
|
+
value: function (data, type) {
|
|
29
29
|
return {
|
|
30
30
|
dataset: [data],
|
|
31
31
|
obv: data.v,
|
|
32
|
+
obvList: [data.v],
|
|
32
33
|
preClose: data.c,
|
|
34
|
+
obvMa: 0,
|
|
33
35
|
};
|
|
34
36
|
}
|
|
35
37
|
});
|
|
@@ -37,7 +39,7 @@ var Obv = /** @class */ (function () {
|
|
|
37
39
|
enumerable: false,
|
|
38
40
|
configurable: true,
|
|
39
41
|
writable: true,
|
|
40
|
-
value: function (data, preList) {
|
|
42
|
+
value: function (data, preList, type) {
|
|
41
43
|
var currentVolume = data.v;
|
|
42
44
|
var currentClose = data.c;
|
|
43
45
|
// obv
|
|
@@ -48,10 +50,19 @@ var Obv = /** @class */ (function () {
|
|
|
48
50
|
else if (currentClose < preList.preClose) {
|
|
49
51
|
obv -= currentVolume;
|
|
50
52
|
}
|
|
53
|
+
// obv Ma
|
|
54
|
+
var obvList = preList.obvList;
|
|
55
|
+
obvList.push(obv);
|
|
56
|
+
if (obvList.length > type)
|
|
57
|
+
obvList.shift();
|
|
58
|
+
var sum = obvList.reduce(function (pre, current) { return pre + current; }, 0);
|
|
59
|
+
var vma = Math.round((sum / type) * 100) / 100;
|
|
51
60
|
return {
|
|
52
61
|
dataset: __spreadArray(__spreadArray([], preList.dataset, true), [data], false),
|
|
53
62
|
obv: obv,
|
|
54
63
|
preClose: currentClose,
|
|
64
|
+
obvList: obvList,
|
|
65
|
+
obvMa: vma
|
|
55
66
|
};
|
|
56
67
|
}
|
|
57
68
|
});
|
|
@@ -3,13 +3,13 @@ import { data_9904 as data } from "./test_data.test";
|
|
|
3
3
|
describe("test obv methods", function () {
|
|
4
4
|
it("test init", function () {
|
|
5
5
|
var obv = new Obv();
|
|
6
|
-
var init = obv.init(data[0]);
|
|
6
|
+
var init = obv.init(data[0], 5);
|
|
7
7
|
var res = init;
|
|
8
8
|
for (var i = 1; i < data.length; i++) {
|
|
9
9
|
var item = data[i];
|
|
10
|
-
res = obv.next(item, res);
|
|
10
|
+
res = obv.next(item, res, 5);
|
|
11
11
|
}
|
|
12
|
-
expect(res.obv).toEqual(504538);
|
|
12
|
+
expect({ obv: res.obv, obvMa: res.obvMa }).toEqual({ obv: 504538, obvMa: 494302.2 });
|
|
13
13
|
});
|
|
14
14
|
it("test getObv()", function () {
|
|
15
15
|
var kd = new Obv();
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
type DataType = {
|
|
2
|
+
v: number;
|
|
3
|
+
[key: string]: unknown;
|
|
4
|
+
};
|
|
5
|
+
type ListType = DataType[];
|
|
6
|
+
interface VmaType {
|
|
7
|
+
init: (data: DataType, type: number) => {
|
|
8
|
+
dataset: ListType;
|
|
9
|
+
vma: number;
|
|
10
|
+
type: number;
|
|
11
|
+
};
|
|
12
|
+
next: (data: DataType, preList: {
|
|
13
|
+
dataset: ListType;
|
|
14
|
+
vma: number;
|
|
15
|
+
type: number;
|
|
16
|
+
}, type: number) => {
|
|
17
|
+
dataset: ListType;
|
|
18
|
+
vma: number;
|
|
19
|
+
type: number;
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
export default class Vma implements VmaType {
|
|
23
|
+
init(data: DataType, type: number): {
|
|
24
|
+
dataset: DataType[];
|
|
25
|
+
vma: number;
|
|
26
|
+
type: number;
|
|
27
|
+
};
|
|
28
|
+
next(data: DataType, preList: {
|
|
29
|
+
dataset: ListType;
|
|
30
|
+
vma: number;
|
|
31
|
+
type: number;
|
|
32
|
+
}, type: number): {
|
|
33
|
+
dataset: ListType;
|
|
34
|
+
vma: number;
|
|
35
|
+
type: number;
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
export {};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
var Vma = /** @class */ (function () {
|
|
2
|
+
function Vma() {
|
|
3
|
+
}
|
|
4
|
+
Object.defineProperty(Vma.prototype, "init", {
|
|
5
|
+
enumerable: false,
|
|
6
|
+
configurable: true,
|
|
7
|
+
writable: true,
|
|
8
|
+
value: function (data, type) {
|
|
9
|
+
return { dataset: [data], vma: 0, type: type };
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
Object.defineProperty(Vma.prototype, "next", {
|
|
13
|
+
enumerable: false,
|
|
14
|
+
configurable: true,
|
|
15
|
+
writable: true,
|
|
16
|
+
value: function (data, preList, type) {
|
|
17
|
+
preList.dataset.push(data);
|
|
18
|
+
if (preList.dataset.length < type) {
|
|
19
|
+
return { dataset: preList.dataset, vma: 0, type: type };
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
if (preList.dataset.length > type) {
|
|
23
|
+
preList.dataset.shift();
|
|
24
|
+
}
|
|
25
|
+
var sum = preList.dataset.reduce(function (pre, current) { return pre + current.v; }, 0);
|
|
26
|
+
var vma = Math.round((sum / type) * 100) / 100;
|
|
27
|
+
return { dataset: preList.dataset, vma: vma, type: type };
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
return Vma;
|
|
32
|
+
}());
|
|
33
|
+
export default Vma;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import data from "./test_data.test";
|
|
2
|
+
import Vma from "./vma";
|
|
3
|
+
describe("test vma methods", function () {
|
|
4
|
+
it("test init & next", function () {
|
|
5
|
+
var index = data.length - 1;
|
|
6
|
+
var vma = new Vma();
|
|
7
|
+
var init = vma.init(data[0], 5);
|
|
8
|
+
var res = init;
|
|
9
|
+
for (var i = 1; i <= index; i++) {
|
|
10
|
+
var item = data[i];
|
|
11
|
+
res = vma.next(item, res, 5);
|
|
12
|
+
}
|
|
13
|
+
expect(res.vma).toEqual(12251.6);
|
|
14
|
+
});
|
|
15
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import isJSON from "./isJson";
|
|
2
|
+
describe("test isJSON methods", function () {
|
|
3
|
+
it("test {}", function () {
|
|
4
|
+
var text = "{}";
|
|
5
|
+
var json = isJSON(text);
|
|
6
|
+
expect(json).toEqual(true);
|
|
7
|
+
});
|
|
8
|
+
it("test [{}]", function () {
|
|
9
|
+
var text = "[{}]";
|
|
10
|
+
var json = isJSON(text);
|
|
11
|
+
expect(json).toEqual(true);
|
|
12
|
+
});
|
|
13
|
+
it("test [{}]);", function () {
|
|
14
|
+
var text = "[{}]);";
|
|
15
|
+
var json = isJSON(text);
|
|
16
|
+
expect(json).toEqual(false);
|
|
17
|
+
});
|
|
18
|
+
});
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export default function parseLsusbOutput(output) {
|
|
2
|
+
var lines = output.trim().split("\n");
|
|
3
|
+
var devices = lines
|
|
4
|
+
.map(function (line) {
|
|
5
|
+
var match = line.match(/Bus (\d+) Device (\d+): ID ([a-f0-9]+:[a-f0-9]+) (.+)/);
|
|
6
|
+
if (match) {
|
|
7
|
+
var bus = match[1];
|
|
8
|
+
var device = match[2];
|
|
9
|
+
var id = match[3];
|
|
10
|
+
var description = match[4];
|
|
11
|
+
return { bus: bus, device: device, id: id, description: description };
|
|
12
|
+
}
|
|
13
|
+
return null;
|
|
14
|
+
})
|
|
15
|
+
.filter(function (device) { return device !== null; });
|
|
16
|
+
return devices;
|
|
17
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import parseLsusbOutput from "./parseLsusbOutput";
|
|
2
|
+
describe("test parseLsusbOutput methods", function () {
|
|
3
|
+
it("test case1", function () {
|
|
4
|
+
var lsusbOutput = "\n Bus 001 Device 002: ID 8087:0024 Intel Corp. Integrated Rate Matching Hub\n Bus 001 Device 003: ID 0c45:64ad Microdia \n ";
|
|
5
|
+
var arr = parseLsusbOutput(lsusbOutput);
|
|
6
|
+
expect(arr).toEqual([
|
|
7
|
+
{
|
|
8
|
+
bus: "001",
|
|
9
|
+
device: "002",
|
|
10
|
+
id: "8087:0024",
|
|
11
|
+
description: "Intel Corp. Integrated Rate Matching Hub",
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
bus: "001",
|
|
15
|
+
device: "003",
|
|
16
|
+
id: "0c45:64ad",
|
|
17
|
+
description: "Microdia",
|
|
18
|
+
},
|
|
19
|
+
]);
|
|
20
|
+
});
|
|
21
|
+
});
|
package/dist/umd/index.js
CHANGED
|
@@ -81,8 +81,9 @@
|
|
|
81
81
|
return response;
|
|
82
82
|
}
|
|
83
83
|
|
|
84
|
-
function Slope(
|
|
84
|
+
function Slope(y) {
|
|
85
85
|
// 計算 x 和 y 的平均值
|
|
86
|
+
var x = Array.from({ length: y.length }, function (_, k) { return k + 1; });
|
|
86
87
|
var x_mean = x.reduce(function (acc, cur) { return acc + cur; }) / x.length;
|
|
87
88
|
var y_mean = y.reduce(function (acc, cur) { return acc + cur; }) / y.length;
|
|
88
89
|
// 計算斜率
|
|
@@ -881,6 +882,39 @@
|
|
|
881
882
|
return Ma;
|
|
882
883
|
}());
|
|
883
884
|
|
|
885
|
+
var Vma = /** @class */ (function () {
|
|
886
|
+
function Vma() {
|
|
887
|
+
}
|
|
888
|
+
Object.defineProperty(Vma.prototype, "init", {
|
|
889
|
+
enumerable: false,
|
|
890
|
+
configurable: true,
|
|
891
|
+
writable: true,
|
|
892
|
+
value: function (data, type) {
|
|
893
|
+
return { dataset: [data], vma: 0, type: type };
|
|
894
|
+
}
|
|
895
|
+
});
|
|
896
|
+
Object.defineProperty(Vma.prototype, "next", {
|
|
897
|
+
enumerable: false,
|
|
898
|
+
configurable: true,
|
|
899
|
+
writable: true,
|
|
900
|
+
value: function (data, preList, type) {
|
|
901
|
+
preList.dataset.push(data);
|
|
902
|
+
if (preList.dataset.length < type) {
|
|
903
|
+
return { dataset: preList.dataset, vma: 0, type: type };
|
|
904
|
+
}
|
|
905
|
+
else {
|
|
906
|
+
if (preList.dataset.length > type) {
|
|
907
|
+
preList.dataset.shift();
|
|
908
|
+
}
|
|
909
|
+
var sum = preList.dataset.reduce(function (pre, current) { return pre + current.v; }, 0);
|
|
910
|
+
var vma = Math.round((sum / type) * 100) / 100;
|
|
911
|
+
return { dataset: preList.dataset, vma: vma, type: type };
|
|
912
|
+
}
|
|
913
|
+
}
|
|
914
|
+
});
|
|
915
|
+
return Vma;
|
|
916
|
+
}());
|
|
917
|
+
|
|
884
918
|
var __assign$3 = (undefined && undefined.__assign) || function () {
|
|
885
919
|
__assign$3 = Object.assign || function(t) {
|
|
886
920
|
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
@@ -1137,11 +1171,13 @@
|
|
|
1137
1171
|
enumerable: false,
|
|
1138
1172
|
configurable: true,
|
|
1139
1173
|
writable: true,
|
|
1140
|
-
value: function (data) {
|
|
1174
|
+
value: function (data, type) {
|
|
1141
1175
|
return {
|
|
1142
1176
|
dataset: [data],
|
|
1143
1177
|
obv: data.v,
|
|
1178
|
+
obvList: [data.v],
|
|
1144
1179
|
preClose: data.c,
|
|
1180
|
+
obvMa: 0,
|
|
1145
1181
|
};
|
|
1146
1182
|
}
|
|
1147
1183
|
});
|
|
@@ -1149,7 +1185,7 @@
|
|
|
1149
1185
|
enumerable: false,
|
|
1150
1186
|
configurable: true,
|
|
1151
1187
|
writable: true,
|
|
1152
|
-
value: function (data, preList) {
|
|
1188
|
+
value: function (data, preList, type) {
|
|
1153
1189
|
var currentVolume = data.v;
|
|
1154
1190
|
var currentClose = data.c;
|
|
1155
1191
|
// obv
|
|
@@ -1160,10 +1196,19 @@
|
|
|
1160
1196
|
else if (currentClose < preList.preClose) {
|
|
1161
1197
|
obv -= currentVolume;
|
|
1162
1198
|
}
|
|
1199
|
+
// obv Ma
|
|
1200
|
+
var obvList = preList.obvList;
|
|
1201
|
+
obvList.push(obv);
|
|
1202
|
+
if (obvList.length > type)
|
|
1203
|
+
obvList.shift();
|
|
1204
|
+
var sum = obvList.reduce(function (pre, current) { return pre + current; }, 0);
|
|
1205
|
+
var vma = Math.round((sum / type) * 100) / 100;
|
|
1163
1206
|
return {
|
|
1164
1207
|
dataset: __spreadArray(__spreadArray([], preList.dataset, true), [data], false),
|
|
1165
1208
|
obv: obv,
|
|
1166
1209
|
preClose: currentClose,
|
|
1210
|
+
obvList: obvList,
|
|
1211
|
+
obvMa: vma
|
|
1167
1212
|
};
|
|
1168
1213
|
}
|
|
1169
1214
|
});
|
|
@@ -1488,6 +1533,24 @@
|
|
|
1488
1533
|
}
|
|
1489
1534
|
}
|
|
1490
1535
|
|
|
1536
|
+
function parseLsusbOutput(output) {
|
|
1537
|
+
var lines = output.trim().split("\n");
|
|
1538
|
+
var devices = lines
|
|
1539
|
+
.map(function (line) {
|
|
1540
|
+
var match = line.match(/Bus (\d+) Device (\d+): ID ([a-f0-9]+:[a-f0-9]+) (.+)/);
|
|
1541
|
+
if (match) {
|
|
1542
|
+
var bus = match[1];
|
|
1543
|
+
var device = match[2];
|
|
1544
|
+
var id = match[3];
|
|
1545
|
+
var description = match[4];
|
|
1546
|
+
return { bus: bus, device: device, id: id, description: description };
|
|
1547
|
+
}
|
|
1548
|
+
return null;
|
|
1549
|
+
})
|
|
1550
|
+
.filter(function (device) { return device !== null; });
|
|
1551
|
+
return devices;
|
|
1552
|
+
}
|
|
1553
|
+
|
|
1491
1554
|
exports.Boll = Boll;
|
|
1492
1555
|
exports.Ema = Ema;
|
|
1493
1556
|
exports.Gold = Gold;
|
|
@@ -1496,6 +1559,7 @@
|
|
|
1496
1559
|
exports.Macd = MACD;
|
|
1497
1560
|
exports.Obv = Obv;
|
|
1498
1561
|
exports.Rsi = Rsi;
|
|
1562
|
+
exports.Vma = Vma;
|
|
1499
1563
|
exports.Williams = Williams;
|
|
1500
1564
|
exports.add = add;
|
|
1501
1565
|
exports.calcSeasonalIndicesNoTrend = calcSeasonalIndicesNoTrend;
|
|
@@ -1505,6 +1569,7 @@
|
|
|
1505
1569
|
exports.isJSON = isJSON;
|
|
1506
1570
|
exports.minus = minus;
|
|
1507
1571
|
exports.movingAverages = movingAverages;
|
|
1572
|
+
exports.parseLsusbOutput = parseLsusbOutput;
|
|
1508
1573
|
exports.simpleRegressionModel = simpleRegressionModel;
|
|
1509
1574
|
exports.slope = Slope;
|
|
1510
1575
|
exports.weightMovingAverages = weightMovingAverages;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ch20026103/anysis",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.9-alpha",
|
|
4
4
|
"description": "provide many analyze methods in the library.",
|
|
5
5
|
"keywords": [],
|
|
6
6
|
"bugs": "git@github.com:cosmic1330/anysis/issues",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"published": "npm publish",
|
|
26
26
|
"unpublished": "npm unpublish --force --registry http://localhost:4873 ",
|
|
27
27
|
"test": "vitest",
|
|
28
|
-
"demo": "node demo.js"
|
|
28
|
+
"demo": "node demo/main.js"
|
|
29
29
|
},
|
|
30
30
|
"lint-staged": {
|
|
31
31
|
"*.{js,jsx,ts,tsx,mjs}": [
|