w-trade-solve 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.editorconfig +9 -0
- package/.eslintignore +3 -0
- package/.eslintrc.js +55 -0
- package/.jsdoc +25 -0
- package/README.md +132 -0
- package/SECURITY.md +5 -0
- package/babel.config.js +16 -0
- package/dist/w-trade-solve.umd.js +19 -0
- package/dist/w-trade-solve.umd.js.map +1 -0
- package/docs/calcFitness.mjs.html +205 -0
- package/docs/calcLevelNumTrade.mjs.html +164 -0
- package/docs/cont.mjs.html +94 -0
- package/docs/estimComps.mjs.html +190 -0
- package/docs/estimFinder.mjs.html +197 -0
- package/docs/estimKeys.mjs.html +571 -0
- package/docs/estimPicks.mjs.html +200 -0
- package/docs/fonts/Montserrat/Montserrat-Bold.eot +0 -0
- package/docs/fonts/Montserrat/Montserrat-Bold.ttf +0 -0
- package/docs/fonts/Montserrat/Montserrat-Bold.woff +0 -0
- package/docs/fonts/Montserrat/Montserrat-Bold.woff2 +0 -0
- package/docs/fonts/Montserrat/Montserrat-Regular.eot +0 -0
- package/docs/fonts/Montserrat/Montserrat-Regular.ttf +0 -0
- package/docs/fonts/Montserrat/Montserrat-Regular.woff +0 -0
- package/docs/fonts/Montserrat/Montserrat-Regular.woff2 +0 -0
- package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.eot +0 -0
- package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.svg +978 -0
- package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.ttf +0 -0
- package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.woff +0 -0
- package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.woff2 +0 -0
- package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.eot +0 -0
- package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.svg +1049 -0
- package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.ttf +0 -0
- package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.woff +0 -0
- package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.woff2 +0 -0
- package/docs/genSid.mjs.html +125 -0
- package/docs/genStrategyFileName.mjs.html +131 -0
- package/docs/genTid.mjs.html +113 -0
- package/docs/global.html +4932 -0
- package/docs/index.html +84 -0
- package/docs/ott.mjs.html +137 -0
- package/docs/p2r.mjs.html +111 -0
- package/docs/readStrategies.mjs.html +203 -0
- package/docs/scripts/collapse.js +39 -0
- package/docs/scripts/commonNav.js +28 -0
- package/docs/scripts/linenumber.js +25 -0
- package/docs/scripts/nav.js +12 -0
- package/docs/scripts/polyfill.js +4 -0
- package/docs/scripts/prettify/Apache-License-2.0.txt +202 -0
- package/docs/scripts/prettify/lang-css.js +2 -0
- package/docs/scripts/prettify/prettify.js +28 -0
- package/docs/scripts/search.js +99 -0
- package/docs/styles/jsdoc.css +776 -0
- package/docs/styles/prettify.css +80 -0
- package/g.mjs +110 -0
- package/package.json +31 -0
- package/script.txt +19 -0
- package/src/WTradeSolve.mjs +29 -0
- package/src/calcFitness.mjs +133 -0
- package/src/calcLevelNumTrade.mjs +92 -0
- package/src/cont.mjs +22 -0
- package/src/estimComps.mjs +118 -0
- package/src/estimFinder.mjs +125 -0
- package/src/estimKeys.mjs +499 -0
- package/src/estimPicks.mjs +128 -0
- package/src/genSid.mjs +53 -0
- package/src/genStrategyFileName.mjs +59 -0
- package/src/genTid.mjs +41 -0
- package/src/ott.mjs +65 -0
- package/src/p2r.mjs +39 -0
- package/src/readStrategies.mjs +131 -0
- package/test/unit-WTradeSolve.test.mjs +83 -0
- package/test/unit-calcFitness.test.mjs +121 -0
- package/test/unit-calcLevelNumTrade.test.mjs +80 -0
- package/test/unit-estimComps.test.mjs +193 -0
- package/test/unit-estimFinder.test.mjs +184 -0
- package/test/unit-estimKeys.test.mjs +260 -0
- package/test/unit-estimPicks.test.mjs +241 -0
- package/test/unit-genSid.test.mjs +75 -0
- package/test/unit-genStrategyFileName.test.mjs +85 -0
- package/test/unit-genTid.test.mjs +72 -0
- package/test/unit-p2r.test.mjs +51 -0
- package/test/unit-readStrategies.test.mjs +258 -0
- package/test/unit-setup.mjs +119 -0
- package/toolg/addVersion.mjs +4 -0
- package/toolg/cleanFolder.mjs +5 -0
- package/toolg/gDistRollup.mjs +37 -0
- package/toolg/gDocsExams.mjs +48 -0
- package/toolg/modifyReadme.mjs +4 -0
package/docs/index.html
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
|
|
5
|
+
<meta charset="utf-8">
|
|
6
|
+
<title>Home - Documentation</title>
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
<script src="scripts/prettify/prettify.js"></script>
|
|
10
|
+
<script src="scripts/prettify/lang-css.js"></script>
|
|
11
|
+
<!--[if lt IE 9]>
|
|
12
|
+
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
|
|
13
|
+
<![endif]-->
|
|
14
|
+
<link type="text/css" rel="stylesheet" href="styles/prettify.css">
|
|
15
|
+
<link type="text/css" rel="stylesheet" href="styles/jsdoc.css">
|
|
16
|
+
<script src="scripts/nav.js" defer></script>
|
|
17
|
+
|
|
18
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
19
|
+
</head>
|
|
20
|
+
<body>
|
|
21
|
+
|
|
22
|
+
<input type="checkbox" id="nav-trigger" class="nav-trigger" />
|
|
23
|
+
<label for="nav-trigger" class="navicon-button x">
|
|
24
|
+
<div class="navicon"></div>
|
|
25
|
+
</label>
|
|
26
|
+
|
|
27
|
+
<label for="nav-trigger" class="overlay"></label>
|
|
28
|
+
|
|
29
|
+
<nav >
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
<h2><a href="index.html">Home</a></h2><h3>Global</h3><ul><li><a href="global.html#calcFitness">calcFitness</a></li><li><a href="global.html#calcLevelNumTrade">calcLevelNumTrade</a></li><li><a href="global.html#cont">cont</a></li><li><a href="global.html#estimComps">estimComps</a></li><li><a href="global.html#estimFinder">estimFinder</a></li><li><a href="global.html#estimKeys">estimKeys</a></li><li><a href="global.html#estimPicks">estimPicks</a></li><li><a href="global.html#genSid">genSid</a></li><li><a href="global.html#genStrategyFileName">genStrategyFileName</a></li><li><a href="global.html#genTid">genTid</a></li><li><a href="global.html#nowTpeStr">nowTpeStr</a></li><li><a href="global.html#nowTpeStrp">nowTpeStrp</a></li><li><a href="global.html#ott">ott</a></li><li><a href="global.html#p2r">p2r</a></li><li><a href="global.html#readStrategies">readStrategies</a></li></ul>
|
|
33
|
+
|
|
34
|
+
</nav>
|
|
35
|
+
|
|
36
|
+
<div id="main">
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
<section class="package">
|
|
47
|
+
<h3> </h3>
|
|
48
|
+
</section>
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
</div>
|
|
70
|
+
|
|
71
|
+
<br class="clear">
|
|
72
|
+
|
|
73
|
+
<footer>
|
|
74
|
+
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.5</a> on Tue Aug 04 2026 23:21:49 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
|
|
75
|
+
</footer>
|
|
76
|
+
|
|
77
|
+
<script>prettyPrint();</script>
|
|
78
|
+
<script src="scripts/polyfill.js"></script>
|
|
79
|
+
<script src="scripts/linenumber.js"></script>
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
</body>
|
|
84
|
+
</html>
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
|
|
5
|
+
<meta charset="utf-8">
|
|
6
|
+
<title>ott.mjs - Documentation</title>
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
<script src="scripts/prettify/prettify.js"></script>
|
|
10
|
+
<script src="scripts/prettify/lang-css.js"></script>
|
|
11
|
+
<!--[if lt IE 9]>
|
|
12
|
+
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
|
|
13
|
+
<![endif]-->
|
|
14
|
+
<link type="text/css" rel="stylesheet" href="styles/prettify.css">
|
|
15
|
+
<link type="text/css" rel="stylesheet" href="styles/jsdoc.css">
|
|
16
|
+
<script src="scripts/nav.js" defer></script>
|
|
17
|
+
|
|
18
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
19
|
+
</head>
|
|
20
|
+
<body>
|
|
21
|
+
|
|
22
|
+
<input type="checkbox" id="nav-trigger" class="nav-trigger" />
|
|
23
|
+
<label for="nav-trigger" class="navicon-button x">
|
|
24
|
+
<div class="navicon"></div>
|
|
25
|
+
</label>
|
|
26
|
+
|
|
27
|
+
<label for="nav-trigger" class="overlay"></label>
|
|
28
|
+
|
|
29
|
+
<nav >
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
<h2><a href="index.html">Home</a></h2><h3>Global</h3><ul><li><a href="global.html#calcFitness">calcFitness</a></li><li><a href="global.html#calcLevelNumTrade">calcLevelNumTrade</a></li><li><a href="global.html#cont">cont</a></li><li><a href="global.html#estimComps">estimComps</a></li><li><a href="global.html#estimFinder">estimFinder</a></li><li><a href="global.html#estimKeys">estimKeys</a></li><li><a href="global.html#estimPicks">estimPicks</a></li><li><a href="global.html#genSid">genSid</a></li><li><a href="global.html#genStrategyFileName">genStrategyFileName</a></li><li><a href="global.html#genTid">genTid</a></li><li><a href="global.html#nowTpeStr">nowTpeStr</a></li><li><a href="global.html#nowTpeStrp">nowTpeStrp</a></li><li><a href="global.html#ott">ott</a></li><li><a href="global.html#p2r">p2r</a></li><li><a href="global.html#readStrategies">readStrategies</a></li></ul>
|
|
33
|
+
|
|
34
|
+
</nav>
|
|
35
|
+
|
|
36
|
+
<div id="main">
|
|
37
|
+
|
|
38
|
+
<h1 class="page-title">ott.mjs</h1>
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
<section>
|
|
47
|
+
<article>
|
|
48
|
+
<pre class="prettyprint source linenums"><code>import ot from 'dayjs'
|
|
49
|
+
import utc from 'dayjs/plugin/utc.js'
|
|
50
|
+
import timezone from 'dayjs/plugin/timezone.js'
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
ot.extend(utc)
|
|
54
|
+
ot.extend(timezone)
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
let TZ = 'Asia/Taipei'
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* 產生台北時區(Asia/Taipei)之dayjs時間物件
|
|
62
|
+
*
|
|
63
|
+
* 供estimKeys與w-trade-backtest之runStrategy等函數使用,使各處時間換算基準一致
|
|
64
|
+
* 未給予input時回傳當下時間,給予input時以台北時區解析該時間
|
|
65
|
+
*
|
|
66
|
+
* @function
|
|
67
|
+
* @param {String|Number|Date} [input=null] 輸入時間字串、時間數值或時間物件,未給予時代表當下時間,預設null
|
|
68
|
+
* @returns {Object} 回傳台北時區之dayjs時間物件
|
|
69
|
+
* @example
|
|
70
|
+
*
|
|
71
|
+
* console.log(ott('2020-01-01T00:00:00').format('YYYY-MM-DDTHH:mm:ssZ'))
|
|
72
|
+
* // => '2020-01-01T00:00:00+08:00'
|
|
73
|
+
*
|
|
74
|
+
*/
|
|
75
|
+
let ott = (input) => {
|
|
76
|
+
if (input === undefined || input === null) {
|
|
77
|
+
return ot().tz(TZ)
|
|
78
|
+
}
|
|
79
|
+
return ot.tz(input, TZ)
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* 取得當下台北時間字串,格式'YYYY-MM-DDTHH:mm:ssZ'
|
|
85
|
+
*
|
|
86
|
+
* @function
|
|
87
|
+
* @returns {String} 回傳當下台北時間字串
|
|
88
|
+
* @example
|
|
89
|
+
*
|
|
90
|
+
* console.log(nowTpeStr())
|
|
91
|
+
* // => '2026-08-04T22:08:31+08:00'
|
|
92
|
+
*
|
|
93
|
+
*/
|
|
94
|
+
let nowTpeStr = () => ott().format('YYYY-MM-DDTHH:mm:ssZ')
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* 取得當下台北時間字串,格式'YYYYMMDDHHmmss'
|
|
99
|
+
*
|
|
100
|
+
* @function
|
|
101
|
+
* @returns {String} 回傳當下台北時間字串
|
|
102
|
+
* @example
|
|
103
|
+
*
|
|
104
|
+
* console.log(nowTpeStrp())
|
|
105
|
+
* // => '20260804220831'
|
|
106
|
+
*
|
|
107
|
+
*/
|
|
108
|
+
let nowTpeStrp = () => ott().format('YYYYMMDDHHmmss')
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
export default ott
|
|
112
|
+
export { ott, nowTpeStr, nowTpeStrp }
|
|
113
|
+
</code></pre>
|
|
114
|
+
</article>
|
|
115
|
+
</section>
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
</div>
|
|
123
|
+
|
|
124
|
+
<br class="clear">
|
|
125
|
+
|
|
126
|
+
<footer>
|
|
127
|
+
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.5</a> on Tue Aug 04 2026 23:21:49 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
|
|
128
|
+
</footer>
|
|
129
|
+
|
|
130
|
+
<script>prettyPrint();</script>
|
|
131
|
+
<script src="scripts/polyfill.js"></script>
|
|
132
|
+
<script src="scripts/linenumber.js"></script>
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
</body>
|
|
137
|
+
</html>
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
|
|
5
|
+
<meta charset="utf-8">
|
|
6
|
+
<title>p2r.mjs - Documentation</title>
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
<script src="scripts/prettify/prettify.js"></script>
|
|
10
|
+
<script src="scripts/prettify/lang-css.js"></script>
|
|
11
|
+
<!--[if lt IE 9]>
|
|
12
|
+
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
|
|
13
|
+
<![endif]-->
|
|
14
|
+
<link type="text/css" rel="stylesheet" href="styles/prettify.css">
|
|
15
|
+
<link type="text/css" rel="stylesheet" href="styles/jsdoc.css">
|
|
16
|
+
<script src="scripts/nav.js" defer></script>
|
|
17
|
+
|
|
18
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
19
|
+
</head>
|
|
20
|
+
<body>
|
|
21
|
+
|
|
22
|
+
<input type="checkbox" id="nav-trigger" class="nav-trigger" />
|
|
23
|
+
<label for="nav-trigger" class="navicon-button x">
|
|
24
|
+
<div class="navicon"></div>
|
|
25
|
+
</label>
|
|
26
|
+
|
|
27
|
+
<label for="nav-trigger" class="overlay"></label>
|
|
28
|
+
|
|
29
|
+
<nav >
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
<h2><a href="index.html">Home</a></h2><h3>Global</h3><ul><li><a href="global.html#calcFitness">calcFitness</a></li><li><a href="global.html#calcLevelNumTrade">calcLevelNumTrade</a></li><li><a href="global.html#cont">cont</a></li><li><a href="global.html#estimComps">estimComps</a></li><li><a href="global.html#estimFinder">estimFinder</a></li><li><a href="global.html#estimKeys">estimKeys</a></li><li><a href="global.html#estimPicks">estimPicks</a></li><li><a href="global.html#genSid">genSid</a></li><li><a href="global.html#genStrategyFileName">genStrategyFileName</a></li><li><a href="global.html#genTid">genTid</a></li><li><a href="global.html#nowTpeStr">nowTpeStr</a></li><li><a href="global.html#nowTpeStrp">nowTpeStrp</a></li><li><a href="global.html#ott">ott</a></li><li><a href="global.html#p2r">p2r</a></li><li><a href="global.html#readStrategies">readStrategies</a></li></ul>
|
|
33
|
+
|
|
34
|
+
</nav>
|
|
35
|
+
|
|
36
|
+
<div id="main">
|
|
37
|
+
|
|
38
|
+
<h1 class="page-title">p2r.mjs</h1>
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
<section>
|
|
47
|
+
<article>
|
|
48
|
+
<pre class="prettyprint source linenums"><code>import cstr from 'wsemi/src/cstr.mjs'
|
|
49
|
+
import cdbl from 'wsemi/src/cdbl.mjs'
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* 轉換百分比字串為比例數值
|
|
54
|
+
*
|
|
55
|
+
* 輸入須為含'%'之字串(例如w-trade-backtest之summary內各比例欄位),剔除'%'後除以100為比例值
|
|
56
|
+
* 未含'%'時回傳0,故無任何交易之空字串亦回傳0
|
|
57
|
+
*
|
|
58
|
+
* Unit Test: {@link https://github.com/yuda-lyu/w-trade-solve/blob/master/test/unit-p2r.test.mjs Github}
|
|
59
|
+
* @function
|
|
60
|
+
* @param {String} p 輸入百分比字串,例如'31.25%'
|
|
61
|
+
* @returns {Number} 回傳比例數值
|
|
62
|
+
* @example
|
|
63
|
+
*
|
|
64
|
+
* console.log(p2r('31.25%'))
|
|
65
|
+
* // => 0.3125
|
|
66
|
+
*
|
|
67
|
+
* console.log(p2r('-5%'))
|
|
68
|
+
* // => -0.05
|
|
69
|
+
*
|
|
70
|
+
* console.log(p2r(''))
|
|
71
|
+
* // => 0
|
|
72
|
+
*
|
|
73
|
+
*/
|
|
74
|
+
let p2r = (p) => {
|
|
75
|
+
p = cstr(p)
|
|
76
|
+
if (p.indexOf('%') < 0) {
|
|
77
|
+
return 0 //未有任何交易時會傳入空字串
|
|
78
|
+
}
|
|
79
|
+
p = p.replace('%', '')
|
|
80
|
+
p = cdbl(p)
|
|
81
|
+
p /= 100
|
|
82
|
+
return p
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
export default p2r
|
|
87
|
+
</code></pre>
|
|
88
|
+
</article>
|
|
89
|
+
</section>
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
</div>
|
|
97
|
+
|
|
98
|
+
<br class="clear">
|
|
99
|
+
|
|
100
|
+
<footer>
|
|
101
|
+
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.5</a> on Tue Aug 04 2026 23:21:49 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
|
|
102
|
+
</footer>
|
|
103
|
+
|
|
104
|
+
<script>prettyPrint();</script>
|
|
105
|
+
<script src="scripts/polyfill.js"></script>
|
|
106
|
+
<script src="scripts/linenumber.js"></script>
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
</body>
|
|
111
|
+
</html>
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
|
|
5
|
+
<meta charset="utf-8">
|
|
6
|
+
<title>readStrategies.mjs - Documentation</title>
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
<script src="scripts/prettify/prettify.js"></script>
|
|
10
|
+
<script src="scripts/prettify/lang-css.js"></script>
|
|
11
|
+
<!--[if lt IE 9]>
|
|
12
|
+
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
|
|
13
|
+
<![endif]-->
|
|
14
|
+
<link type="text/css" rel="stylesheet" href="styles/prettify.css">
|
|
15
|
+
<link type="text/css" rel="stylesheet" href="styles/jsdoc.css">
|
|
16
|
+
<script src="scripts/nav.js" defer></script>
|
|
17
|
+
|
|
18
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
19
|
+
</head>
|
|
20
|
+
<body>
|
|
21
|
+
|
|
22
|
+
<input type="checkbox" id="nav-trigger" class="nav-trigger" />
|
|
23
|
+
<label for="nav-trigger" class="navicon-button x">
|
|
24
|
+
<div class="navicon"></div>
|
|
25
|
+
</label>
|
|
26
|
+
|
|
27
|
+
<label for="nav-trigger" class="overlay"></label>
|
|
28
|
+
|
|
29
|
+
<nav >
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
<h2><a href="index.html">Home</a></h2><h3>Global</h3><ul><li><a href="global.html#calcFitness">calcFitness</a></li><li><a href="global.html#calcLevelNumTrade">calcLevelNumTrade</a></li><li><a href="global.html#cont">cont</a></li><li><a href="global.html#estimComps">estimComps</a></li><li><a href="global.html#estimFinder">estimFinder</a></li><li><a href="global.html#estimKeys">estimKeys</a></li><li><a href="global.html#estimPicks">estimPicks</a></li><li><a href="global.html#genSid">genSid</a></li><li><a href="global.html#genStrategyFileName">genStrategyFileName</a></li><li><a href="global.html#genTid">genTid</a></li><li><a href="global.html#nowTpeStr">nowTpeStr</a></li><li><a href="global.html#nowTpeStrp">nowTpeStrp</a></li><li><a href="global.html#ott">ott</a></li><li><a href="global.html#p2r">p2r</a></li><li><a href="global.html#readStrategies">readStrategies</a></li></ul>
|
|
33
|
+
|
|
34
|
+
</nav>
|
|
35
|
+
|
|
36
|
+
<div id="main">
|
|
37
|
+
|
|
38
|
+
<h1 class="page-title">readStrategies.mjs</h1>
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
<section>
|
|
47
|
+
<article>
|
|
48
|
+
<pre class="prettyprint source linenums"><code>import drop from 'lodash-es/drop.js'
|
|
49
|
+
import each from 'lodash-es/each.js'
|
|
50
|
+
import filter from 'lodash-es/filter.js'
|
|
51
|
+
import get from 'lodash-es/get.js'
|
|
52
|
+
import size from 'lodash-es/size.js'
|
|
53
|
+
import fsIsFolder from 'wsemi/src/fsIsFolder.mjs'
|
|
54
|
+
import fsReadJson from 'wsemi/src/fsReadJson.mjs'
|
|
55
|
+
import fsTreeFolder from 'wsemi/src/fsTreeFolder.mjs'
|
|
56
|
+
import isestr from 'wsemi/src/isestr.mjs'
|
|
57
|
+
import replace from 'wsemi/src/replace.mjs'
|
|
58
|
+
import sep from 'wsemi/src/sep.mjs'
|
|
59
|
+
import cont from './cont.mjs'
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* 讀取儲存策略資料夾內各策略檔資訊
|
|
64
|
+
*
|
|
65
|
+
* 僅列舉fd第1層之檔案,資料夾不列入,fd非資料夾或無任何檔案時回傳空陣列
|
|
66
|
+
* 各檔以主檔名(剔除'.json')依cont.dlmPkgs切段,依序為tid、levelNumTrade與rEquivalentCumuProfitOrLossFinalNormYear,即genStrategyFileName所產生之檔名,切不出tid者予以略過
|
|
67
|
+
* tid再依cont.dlmSeps切段,首段為mode,其餘為各key所組成之ps
|
|
68
|
+
* tkid為`${tid}:${levelNumTrade}`,與estimKeys內用於判斷同組keys與同交易次數級距之組合方式一致
|
|
69
|
+
*
|
|
70
|
+
* Unit Test: {@link https://github.com/yuda-lyu/w-trade-solve/blob/master/test/unit-readStrategies.test.mjs Github}
|
|
71
|
+
* @function
|
|
72
|
+
* @param {String} fd 輸入儲存策略資料夾字串
|
|
73
|
+
* @param {Object} [opt={}] 輸入設定物件,預設{}
|
|
74
|
+
* @param {Boolean} [opt.readContent=false] 輸入是否讀取策略檔內容布林值,為true時各元素額外提供data欄位,內容非合法json時data為null,預設false
|
|
75
|
+
* @returns {Array} 回傳策略資訊陣列,各元素為{path,name,tkid,tid,levelNumTrade,rEquivalentCumuProfitOrLossFinalNormYear,mode,ps},opt.readContent為true時額外提供data
|
|
76
|
+
* @example
|
|
77
|
+
*
|
|
78
|
+
* import fs from 'fs'
|
|
79
|
+
* import cont from './src/cont.mjs'
|
|
80
|
+
*
|
|
81
|
+
* let fd = './tmp/data-strategy'
|
|
82
|
+
* fs.mkdirSync(fd, { recursive: true })
|
|
83
|
+
*
|
|
84
|
+
* //以genStrategyFileName之檔名規則儲存策略檔
|
|
85
|
+
* let fn = `long${cont.dlmSeps}ma_1day${cont.dlmPkgs}12${cont.dlmPkgs}31.25%.json`
|
|
86
|
+
* fs.writeFileSync(`${fd}/${fn}`, JSON.stringify({ mode: 'long' }), 'utf8')
|
|
87
|
+
*
|
|
88
|
+
* console.log(readStrategies(fd))
|
|
89
|
+
* // => [
|
|
90
|
+
* // {
|
|
91
|
+
* // path: './tmp/data-strategy/long ║ ma_1day ⊙ 12 ⊙ 31.25%.json',
|
|
92
|
+
* // name: 'long ║ ma_1day ⊙ 12 ⊙ 31.25%.json',
|
|
93
|
+
* // tkid: 'long ║ ma_1day:12',
|
|
94
|
+
* // tid: 'long ║ ma_1day',
|
|
95
|
+
* // levelNumTrade: '12',
|
|
96
|
+
* // rEquivalentCumuProfitOrLossFinalNormYear: '31.25%',
|
|
97
|
+
* // mode: 'long',
|
|
98
|
+
* // ps: [ 'ma_1day' ]
|
|
99
|
+
* // }
|
|
100
|
+
* // ]
|
|
101
|
+
*
|
|
102
|
+
*/
|
|
103
|
+
let readStrategies = (fd, opt = {}) => {
|
|
104
|
+
|
|
105
|
+
//readContent
|
|
106
|
+
let readContent = get(opt, 'readContent', false)
|
|
107
|
+
|
|
108
|
+
//check
|
|
109
|
+
if (!fsIsFolder(fd)) {
|
|
110
|
+
console.log(`invalid fd[${fd}]`)
|
|
111
|
+
return []
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
//vfps
|
|
115
|
+
let vfps = fsTreeFolder(fd)
|
|
116
|
+
vfps = filter(vfps, { isFolder: false })
|
|
117
|
+
// console.log('vfps', vfps)
|
|
118
|
+
|
|
119
|
+
//check
|
|
120
|
+
if (size(vfps) === 0) {
|
|
121
|
+
console.log(`fd[${fd}] no files`)
|
|
122
|
+
return []
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
//ss
|
|
126
|
+
let ss = []
|
|
127
|
+
each(vfps, (v) => {
|
|
128
|
+
|
|
129
|
+
//qs
|
|
130
|
+
let name = replace(v.name, '.json', '')
|
|
131
|
+
let qs = sep(name, cont.dlmPkgs)
|
|
132
|
+
|
|
133
|
+
//tid
|
|
134
|
+
let tid = get(qs, 0, '')
|
|
135
|
+
|
|
136
|
+
//check
|
|
137
|
+
if (!isestr(tid)) {
|
|
138
|
+
return true //跳出換下一個
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
//levelNumTrade, rEquivalentCumuProfitOrLossFinalNormYear, ps, mode
|
|
142
|
+
let levelNumTrade = get(qs, 1, '')
|
|
143
|
+
let rEquivalentCumuProfitOrLossFinalNormYear = get(qs, 2, '')
|
|
144
|
+
let ps = sep(tid, cont.dlmSeps)
|
|
145
|
+
let mode = get(ps, 0, '')
|
|
146
|
+
ps = drop(ps)
|
|
147
|
+
|
|
148
|
+
//tkid
|
|
149
|
+
let tkid = `${tid}:${levelNumTrade}`
|
|
150
|
+
|
|
151
|
+
//s
|
|
152
|
+
let s = {
|
|
153
|
+
path: v.path,
|
|
154
|
+
name: v.name,
|
|
155
|
+
tkid,
|
|
156
|
+
tid,
|
|
157
|
+
levelNumTrade,
|
|
158
|
+
rEquivalentCumuProfitOrLossFinalNormYear,
|
|
159
|
+
mode,
|
|
160
|
+
ps,
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
//readContent
|
|
164
|
+
if (readContent) {
|
|
165
|
+
let d = fsReadJson(v.path) //回傳{success}或{error}, 讀取或解析失敗時data為null
|
|
166
|
+
s.data = get(d, 'success', null)
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
//push
|
|
170
|
+
ss.push(s)
|
|
171
|
+
|
|
172
|
+
})
|
|
173
|
+
|
|
174
|
+
return ss
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
export default readStrategies
|
|
179
|
+
</code></pre>
|
|
180
|
+
</article>
|
|
181
|
+
</section>
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
</div>
|
|
189
|
+
|
|
190
|
+
<br class="clear">
|
|
191
|
+
|
|
192
|
+
<footer>
|
|
193
|
+
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.5</a> on Tue Aug 04 2026 23:21:49 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
|
|
194
|
+
</footer>
|
|
195
|
+
|
|
196
|
+
<script>prettyPrint();</script>
|
|
197
|
+
<script src="scripts/polyfill.js"></script>
|
|
198
|
+
<script src="scripts/linenumber.js"></script>
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
</body>
|
|
203
|
+
</html>
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
function hideAllButCurrent(){
|
|
2
|
+
//by default all submenut items are hidden
|
|
3
|
+
//but we need to rehide them for search
|
|
4
|
+
document.querySelectorAll("nav > ul").forEach(function(parent) {
|
|
5
|
+
if (parent.className.indexOf("collapse_top") !== -1) {
|
|
6
|
+
parent.style.display = "none";
|
|
7
|
+
}
|
|
8
|
+
});
|
|
9
|
+
document.querySelectorAll("nav > ul > li > ul li").forEach(function(parent) {
|
|
10
|
+
parent.style.display = "none";
|
|
11
|
+
});
|
|
12
|
+
document.querySelectorAll("nav > h3").forEach(function(section) {
|
|
13
|
+
if (section.className.indexOf("collapsed_header") !== -1) {
|
|
14
|
+
section.addEventListener("click", function(){
|
|
15
|
+
if (section.nextSibling.style.display === "none") {
|
|
16
|
+
section.nextSibling.style.display = "block";
|
|
17
|
+
} else {
|
|
18
|
+
section.nextSibling.style.display = "none";
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
//only current page (if it exists) should be opened
|
|
25
|
+
var file = window.location.pathname.split("/").pop().replace(/\.html/, '');
|
|
26
|
+
document.querySelectorAll("nav > ul > li > a").forEach(function(parent) {
|
|
27
|
+
var href = parent.attributes.href.value.replace(/\.html/, '');
|
|
28
|
+
if (file === href) {
|
|
29
|
+
if (parent.parentNode.parentNode.className.indexOf("collapse_top") !== -1) {
|
|
30
|
+
parent.parentNode.parentNode.style.display = "block";
|
|
31
|
+
}
|
|
32
|
+
parent.parentNode.querySelectorAll("ul li").forEach(function(elem) {
|
|
33
|
+
elem.style.display = "block";
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
hideAllButCurrent();
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
if (typeof fetch === 'function') {
|
|
2
|
+
const init = () => {
|
|
3
|
+
if (typeof scrollToNavItem !== 'function') return false
|
|
4
|
+
scrollToNavItem()
|
|
5
|
+
// hideAllButCurrent not always loaded
|
|
6
|
+
if (typeof hideAllButCurrent === 'function') hideAllButCurrent()
|
|
7
|
+
return true
|
|
8
|
+
}
|
|
9
|
+
fetch('./nav.inc.html')
|
|
10
|
+
.then(response => response.ok ? response.text() : `${response.url} => ${response.status} ${response.statusText}`)
|
|
11
|
+
.then(body => {
|
|
12
|
+
document.querySelector('nav').innerHTML += body
|
|
13
|
+
// nav.js should be quicker to load than nav.inc.html, a fallback just in case
|
|
14
|
+
return init()
|
|
15
|
+
})
|
|
16
|
+
.then(done => {
|
|
17
|
+
if (done) return
|
|
18
|
+
let i = 0
|
|
19
|
+
;(function waitUntilNavJs () {
|
|
20
|
+
if (init()) return
|
|
21
|
+
if (i++ < 100) return setTimeout(waitUntilNavJs, 300)
|
|
22
|
+
console.error(Error('nav.js not loaded after 30s waiting for it'))
|
|
23
|
+
})()
|
|
24
|
+
})
|
|
25
|
+
.catch(error => console.error(error))
|
|
26
|
+
} else {
|
|
27
|
+
console.error(Error('Browser too old to display commonNav (remove commonNav docdash option)'))
|
|
28
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/*global document */
|
|
2
|
+
(function() {
|
|
3
|
+
var source = document.getElementsByClassName('prettyprint source linenums');
|
|
4
|
+
var i = 0;
|
|
5
|
+
var lineNumber = 0;
|
|
6
|
+
var lineId;
|
|
7
|
+
var lines;
|
|
8
|
+
var totalLines;
|
|
9
|
+
var anchorHash;
|
|
10
|
+
|
|
11
|
+
if (source && source[0]) {
|
|
12
|
+
anchorHash = document.location.hash.substring(1);
|
|
13
|
+
lines = source[0].getElementsByTagName('li');
|
|
14
|
+
totalLines = lines.length;
|
|
15
|
+
|
|
16
|
+
for (; i < totalLines; i++) {
|
|
17
|
+
lineNumber++;
|
|
18
|
+
lineId = 'line' + lineNumber;
|
|
19
|
+
lines[i].id = lineId;
|
|
20
|
+
if (lineId === anchorHash) {
|
|
21
|
+
lines[i].className += ' selected';
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
})();
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
function scrollToNavItem() {
|
|
2
|
+
var path = window.location.href.split('/').pop().replace(/\.html/, '');
|
|
3
|
+
document.querySelectorAll('nav a').forEach(function(link) {
|
|
4
|
+
var href = link.attributes.href.value.replace(/\.html/, '');
|
|
5
|
+
if (path === href) {
|
|
6
|
+
link.scrollIntoView({block: 'center'});
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
})
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
scrollToNavItem();
|