@ch20026103/anysis 0.0.8-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/index.d.ts +1 -0
- package/dist/cjs/index.js +3 -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/esm/index.d.ts +1 -0
- package/dist/esm/index.js +1 -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/umd/index.js +47 -2
- package/package.json +17 -15
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
|
+
}
|
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";
|
package/dist/cjs/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
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.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");
|
|
@@ -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
|
+
});
|
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";
|
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";
|
|
@@ -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
|
+
});
|
package/dist/umd/index.js
CHANGED
|
@@ -882,6 +882,39 @@
|
|
|
882
882
|
return Ma;
|
|
883
883
|
}());
|
|
884
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
|
+
|
|
885
918
|
var __assign$3 = (undefined && undefined.__assign) || function () {
|
|
886
919
|
__assign$3 = Object.assign || function(t) {
|
|
887
920
|
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
@@ -1138,11 +1171,13 @@
|
|
|
1138
1171
|
enumerable: false,
|
|
1139
1172
|
configurable: true,
|
|
1140
1173
|
writable: true,
|
|
1141
|
-
value: function (data) {
|
|
1174
|
+
value: function (data, type) {
|
|
1142
1175
|
return {
|
|
1143
1176
|
dataset: [data],
|
|
1144
1177
|
obv: data.v,
|
|
1178
|
+
obvList: [data.v],
|
|
1145
1179
|
preClose: data.c,
|
|
1180
|
+
obvMa: 0,
|
|
1146
1181
|
};
|
|
1147
1182
|
}
|
|
1148
1183
|
});
|
|
@@ -1150,7 +1185,7 @@
|
|
|
1150
1185
|
enumerable: false,
|
|
1151
1186
|
configurable: true,
|
|
1152
1187
|
writable: true,
|
|
1153
|
-
value: function (data, preList) {
|
|
1188
|
+
value: function (data, preList, type) {
|
|
1154
1189
|
var currentVolume = data.v;
|
|
1155
1190
|
var currentClose = data.c;
|
|
1156
1191
|
// obv
|
|
@@ -1161,10 +1196,19 @@
|
|
|
1161
1196
|
else if (currentClose < preList.preClose) {
|
|
1162
1197
|
obv -= currentVolume;
|
|
1163
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;
|
|
1164
1206
|
return {
|
|
1165
1207
|
dataset: __spreadArray(__spreadArray([], preList.dataset, true), [data], false),
|
|
1166
1208
|
obv: obv,
|
|
1167
1209
|
preClose: currentClose,
|
|
1210
|
+
obvList: obvList,
|
|
1211
|
+
obvMa: vma
|
|
1168
1212
|
};
|
|
1169
1213
|
}
|
|
1170
1214
|
});
|
|
@@ -1515,6 +1559,7 @@
|
|
|
1515
1559
|
exports.Macd = MACD;
|
|
1516
1560
|
exports.Obv = Obv;
|
|
1517
1561
|
exports.Rsi = Rsi;
|
|
1562
|
+
exports.Vma = Vma;
|
|
1518
1563
|
exports.Williams = Williams;
|
|
1519
1564
|
exports.add = add;
|
|
1520
1565
|
exports.calcSeasonalIndicesNoTrend = calcSeasonalIndicesNoTrend;
|
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",
|
|
@@ -12,6 +12,21 @@
|
|
|
12
12
|
"module": "dist/esm/index.js",
|
|
13
13
|
"browser": "dist/umd/index.js",
|
|
14
14
|
"types": "dist/esm/index.d.ts",
|
|
15
|
+
"scripts": {
|
|
16
|
+
"build": "pnpm clean && pnpm build:esm && pnpm build:cjs && pnpm build:umd",
|
|
17
|
+
"build:cjs": "tsc --module commonjs --target es5 --outDir dist/cjs",
|
|
18
|
+
"build:esm": "tsc --module esnext --target es5 --outDir dist/esm",
|
|
19
|
+
"build:umd": "rollup dist/esm/index.js --file dist/umd/index.js --format umd --name anysis",
|
|
20
|
+
"clean": "rimraf dist",
|
|
21
|
+
"lint": "eslint --fix \"**/*.{js,jsx,ts,tsx,mjs}\"",
|
|
22
|
+
"prepare": "pnpm exec husky install",
|
|
23
|
+
"prettier": "pnpm exec prettier --write .",
|
|
24
|
+
"prepublishOnly": "pnpm build",
|
|
25
|
+
"published": "npm publish",
|
|
26
|
+
"unpublished": "npm unpublish --force --registry http://localhost:4873 ",
|
|
27
|
+
"test": "vitest",
|
|
28
|
+
"demo": "node demo/main.js"
|
|
29
|
+
},
|
|
15
30
|
"lint-staged": {
|
|
16
31
|
"*.{js,jsx,ts,tsx,mjs}": [
|
|
17
32
|
"pnpm lint"
|
|
@@ -42,18 +57,5 @@
|
|
|
42
57
|
},
|
|
43
58
|
"vota": {
|
|
44
59
|
"node": "16.11.0"
|
|
45
|
-
},
|
|
46
|
-
"scripts": {
|
|
47
|
-
"build": "pnpm clean && pnpm build:esm && pnpm build:cjs && pnpm build:umd",
|
|
48
|
-
"build:cjs": "tsc --module commonjs --target es5 --outDir dist/cjs",
|
|
49
|
-
"build:esm": "tsc --module esnext --target es5 --outDir dist/esm",
|
|
50
|
-
"build:umd": "rollup dist/esm/index.js --file dist/umd/index.js --format umd --name anysis",
|
|
51
|
-
"clean": "rimraf dist",
|
|
52
|
-
"lint": "eslint --fix \"**/*.{js,jsx,ts,tsx,mjs}\"",
|
|
53
|
-
"prettier": "pnpm exec prettier --write .",
|
|
54
|
-
"published": "npm publish",
|
|
55
|
-
"unpublished": "npm unpublish --force --registry http://localhost:4873 ",
|
|
56
|
-
"test": "vitest",
|
|
57
|
-
"demo": "node demo.js"
|
|
58
60
|
}
|
|
59
|
-
}
|
|
61
|
+
}
|