@ch20026103/anysis 0.0.2-release → 0.0.3-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.
@@ -0,0 +1 @@
1
+ export default function Slope(x: number[], y: number[]): number;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ function Slope(x, y) {
4
+ // 計算 x 和 y 的平均值
5
+ var x_mean = x.reduce(function (acc, cur) { return acc + cur; }) / x.length;
6
+ var y_mean = y.reduce(function (acc, cur) { return acc + cur; }) / y.length;
7
+ // 計算斜率
8
+ var numerator = x.reduce(function (acc, cur, i) { return acc + (cur - x_mean) * (y[i] - y_mean); }, 0);
9
+ var denominator = x.reduce(function (acc, cur) { return acc + Math.pow((cur - x_mean), 2); }, 0);
10
+ var slope = numerator / denominator;
11
+ return slope;
12
+ }
13
+ exports.default = Slope;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var index_1 = require("./index");
4
+ describe("test Slope methods", function () {
5
+ it("test 123456", function () {
6
+ var x = [1, 2, 3, 4, 5, 6];
7
+ var y = [1, 2, 3, 4, 5, 6];
8
+ var slope = (0, index_1.default)(x, y);
9
+ expect(slope).toEqual(1);
10
+ });
11
+ it("test -123456", function () {
12
+ var x = [1, 2, 3, 4, 5, 6];
13
+ var y = [-1, -2, -3, -4, -5, -6];
14
+ var slope = (0, index_1.default)(x, y);
15
+ expect(slope).toEqual(-1);
16
+ });
17
+ it("test 654321", function () {
18
+ var x = [1, 2, 3, 4, 5, 6];
19
+ var y = [6, 5, 4, 3, 2, 1];
20
+ var slope = (0, index_1.default)(x, y);
21
+ expect(slope).toEqual(-1);
22
+ });
23
+ it("test 222222", function () {
24
+ var x = [1, 2, 3, 4, 5, 6];
25
+ var y = [2, 2, 2, 2, 2, 2];
26
+ var slope = (0, index_1.default)(x, y);
27
+ expect(slope).toEqual(0);
28
+ });
29
+ });
@@ -1,4 +1,5 @@
1
1
  export { default as simpleRegressionModel } from "./analyze/Regression/simpleRegressoinModel.js";
2
+ export { default as slope } from "./analyze/Slope/index.js";
2
3
  export { exponentialSmoothing, movingAverages, weightMovingAverages, } from "./analyze/TimeSeries/R/index.js";
3
4
  export { calcSeasonalIndicesNoTrend } from "./analyze/TimeSeries/RS/index.js";
4
5
  export { default as Gold } from "./stockSkills/gold.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.minus = exports.add = exports.Williams = exports.getWeekLine = exports.dateFormat = exports.Rsi = exports.Macd = exports.Ma = exports.Kd = exports.Gold = exports.calcSeasonalIndicesNoTrend = exports.weightMovingAverages = exports.movingAverages = exports.exponentialSmoothing = exports.simpleRegressionModel = void 0;
3
+ exports.minus = exports.add = exports.Williams = exports.getWeekLine = exports.dateFormat = exports.Rsi = exports.Macd = exports.Ma = exports.Kd = exports.Gold = 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副檔名**
@@ -8,12 +8,14 @@ exports.minus = exports.add = exports.Williams = exports.getWeekLine = exports.d
8
8
  */
9
9
  var simpleRegressoinModel_js_1 = require("./analyze/Regression/simpleRegressoinModel.js");
10
10
  Object.defineProperty(exports, "simpleRegressionModel", { enumerable: true, get: function () { return simpleRegressoinModel_js_1.default; } });
11
- var index_js_1 = require("./analyze/TimeSeries/R/index.js");
12
- Object.defineProperty(exports, "exponentialSmoothing", { enumerable: true, get: function () { return index_js_1.exponentialSmoothing; } });
13
- Object.defineProperty(exports, "movingAverages", { enumerable: true, get: function () { return index_js_1.movingAverages; } });
14
- Object.defineProperty(exports, "weightMovingAverages", { enumerable: true, get: function () { return index_js_1.weightMovingAverages; } });
15
- var index_js_2 = require("./analyze/TimeSeries/RS/index.js");
16
- Object.defineProperty(exports, "calcSeasonalIndicesNoTrend", { enumerable: true, get: function () { return index_js_2.calcSeasonalIndicesNoTrend; } });
11
+ var index_js_1 = require("./analyze/Slope/index.js");
12
+ Object.defineProperty(exports, "slope", { enumerable: true, get: function () { return index_js_1.default; } });
13
+ var index_js_2 = require("./analyze/TimeSeries/R/index.js");
14
+ Object.defineProperty(exports, "exponentialSmoothing", { enumerable: true, get: function () { return index_js_2.exponentialSmoothing; } });
15
+ Object.defineProperty(exports, "movingAverages", { enumerable: true, get: function () { return index_js_2.movingAverages; } });
16
+ Object.defineProperty(exports, "weightMovingAverages", { enumerable: true, get: function () { return index_js_2.weightMovingAverages; } });
17
+ var index_js_3 = require("./analyze/TimeSeries/RS/index.js");
18
+ Object.defineProperty(exports, "calcSeasonalIndicesNoTrend", { enumerable: true, get: function () { return index_js_3.calcSeasonalIndicesNoTrend; } });
17
19
  var gold_js_1 = require("./stockSkills/gold.js");
18
20
  Object.defineProperty(exports, "Gold", { enumerable: true, get: function () { return gold_js_1.default; } });
19
21
  var kd_js_1 = require("./stockSkills/kd.js");
@@ -0,0 +1 @@
1
+ export default function Slope(x: number[], y: number[]): number;
@@ -0,0 +1,10 @@
1
+ export default function Slope(x, y) {
2
+ // 計算 x 和 y 的平均值
3
+ var x_mean = x.reduce(function (acc, cur) { return acc + cur; }) / x.length;
4
+ var y_mean = y.reduce(function (acc, cur) { return acc + cur; }) / y.length;
5
+ // 計算斜率
6
+ var numerator = x.reduce(function (acc, cur, i) { return acc + (cur - x_mean) * (y[i] - y_mean); }, 0);
7
+ var denominator = x.reduce(function (acc, cur) { return acc + Math.pow((cur - x_mean), 2); }, 0);
8
+ var slope = numerator / denominator;
9
+ return slope;
10
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,27 @@
1
+ import Slope from "./index";
2
+ describe("test Slope methods", function () {
3
+ it("test 123456", function () {
4
+ var x = [1, 2, 3, 4, 5, 6];
5
+ var y = [1, 2, 3, 4, 5, 6];
6
+ var slope = Slope(x, y);
7
+ expect(slope).toEqual(1);
8
+ });
9
+ it("test -123456", function () {
10
+ var x = [1, 2, 3, 4, 5, 6];
11
+ var y = [-1, -2, -3, -4, -5, -6];
12
+ var slope = Slope(x, y);
13
+ expect(slope).toEqual(-1);
14
+ });
15
+ it("test 654321", function () {
16
+ var x = [1, 2, 3, 4, 5, 6];
17
+ var y = [6, 5, 4, 3, 2, 1];
18
+ var slope = Slope(x, y);
19
+ expect(slope).toEqual(-1);
20
+ });
21
+ it("test 222222", function () {
22
+ var x = [1, 2, 3, 4, 5, 6];
23
+ var y = [2, 2, 2, 2, 2, 2];
24
+ var slope = Slope(x, y);
25
+ expect(slope).toEqual(0);
26
+ });
27
+ });
@@ -1,4 +1,5 @@
1
1
  export { default as simpleRegressionModel } from "./analyze/Regression/simpleRegressoinModel.js";
2
+ export { default as slope } from "./analyze/Slope/index.js";
2
3
  export { exponentialSmoothing, movingAverages, weightMovingAverages, } from "./analyze/TimeSeries/R/index.js";
3
4
  export { calcSeasonalIndicesNoTrend } from "./analyze/TimeSeries/RS/index.js";
4
5
  export { default as Gold } from "./stockSkills/gold.js";
package/dist/esm/index.js CHANGED
@@ -4,6 +4,7 @@
4
4
  但如果要支持 ES 模塊的瀏覽器 ,則需要文件擴展名(.js)。
5
5
  */
6
6
  export { default as simpleRegressionModel } from "./analyze/Regression/simpleRegressoinModel.js";
7
+ export { default as slope } from "./analyze/Slope/index.js";
7
8
  export { exponentialSmoothing, movingAverages, weightMovingAverages, } from "./analyze/TimeSeries/R/index.js";
8
9
  export { calcSeasonalIndicesNoTrend } from "./analyze/TimeSeries/RS/index.js";
9
10
  export { default as Gold } from "./stockSkills/gold.js";
package/dist/umd/index.js CHANGED
@@ -81,6 +81,17 @@
81
81
  return response;
82
82
  }
83
83
 
84
+ function Slope(x, y) {
85
+ // 計算 x 和 y 的平均值
86
+ var x_mean = x.reduce(function (acc, cur) { return acc + cur; }) / x.length;
87
+ var y_mean = y.reduce(function (acc, cur) { return acc + cur; }) / y.length;
88
+ // 計算斜率
89
+ var numerator = x.reduce(function (acc, cur, i) { return acc + (cur - x_mean) * (y[i] - y_mean); }, 0);
90
+ var denominator = x.reduce(function (acc, cur) { return acc + Math.pow((cur - x_mean), 2); }, 0);
91
+ var slope = numerator / denominator;
92
+ return slope;
93
+ }
94
+
84
95
  function movingAverages(arr, periods) {
85
96
  var response = new Array(periods).fill(0);
86
97
  for (var i = periods; i < arr.length; i++) {
@@ -1122,6 +1133,7 @@
1122
1133
  exports.minus = minus;
1123
1134
  exports.movingAverages = movingAverages;
1124
1135
  exports.simpleRegressionModel = simpleRegressionModel;
1136
+ exports.slope = Slope;
1125
1137
  exports.weightMovingAverages = weightMovingAverages;
1126
1138
 
1127
1139
  Object.defineProperty(exports, '__esModule', { value: true });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ch20026103/anysis",
3
- "version": "0.0.2-release",
3
+ "version": "0.0.3-alpha",
4
4
  "description": "provide many analyze methods in the library.",
5
5
  "keywords": [],
6
6
  "bugs": "git@github.com:cosmic1330/anysis/issues",