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
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
|
|
5
|
+
<meta charset="utf-8">
|
|
6
|
+
<title>estimPicks.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">estimPicks.mjs</h1>
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
<section>
|
|
47
|
+
<article>
|
|
48
|
+
<pre class="prettyprint source linenums"><code>import each from 'lodash-es/each.js'
|
|
49
|
+
import get from 'lodash-es/get.js'
|
|
50
|
+
import isestr from 'wsemi/src/isestr.mjs'
|
|
51
|
+
import isfun from 'wsemi/src/isfun.mjs'
|
|
52
|
+
import dataProvide from 'w-data-tdprovide'
|
|
53
|
+
import estimKeys from './estimKeys.mjs'
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* 由fdParam內全部指標key分類後挑選keys,再率定各key之門檻與止盈止損,求解最佳策略
|
|
58
|
+
*
|
|
59
|
+
* 先由fdParam列舉全部指標key,並依名稱分為3類: 開頭為'index_'者為keysIndex(指數類)、含'_vbs_'者為keysVolumn(成交量類)、其餘為keysNorm(一般類)
|
|
60
|
+
* 分類後各類可經opt內對應之過濾函數再行篩選,接著呼叫funPickKeys由3類挑出待率定之keys,最後交由estimKeys求解
|
|
61
|
+
* fdOhlc、fdParam、timeStart、timeEnd、fdData無效或mode非'long'或'short'或funPickKeys非函數時throw
|
|
62
|
+
*
|
|
63
|
+
* Unit Test: {@link https://github.com/yuda-lyu/w-trade-solve/blob/master/test/unit-estimPicks.test.mjs Github}
|
|
64
|
+
* @function
|
|
65
|
+
* @param {Function} ott 輸入時區時間函數,傳入時間字串回傳dayjs時間物件,可用src/ott.mjs
|
|
66
|
+
* @param {Object} st 輸入設定物件,需可由opt.keySettings取得name、symbol與interval欄位
|
|
67
|
+
* @param {String} fdOhlc 輸入儲存K線(ohlc)序列資料夾字串
|
|
68
|
+
* @param {String} fdParam 輸入儲存指標參數序列資料夾字串
|
|
69
|
+
* @param {String} timeStart 輸入回測起始時間字串,格式'YYYY-MM-DDTHH:mm:ss'
|
|
70
|
+
* @param {String} timeEnd 輸入回測結束時間字串,格式'YYYY-MM-DDTHH:mm:ss'
|
|
71
|
+
* @param {String} mode 輸入交易方向字串,可選'long'或'short'
|
|
72
|
+
* @param {Function} funPickKeys 輸入挑選keys函數,傳入{keysNorm,keysIndex,keysVolumn}物件,回傳待率定之指標key字串陣列
|
|
73
|
+
* @param {String} fdData 輸入儲存策略資料夾字串,不存在時自動建立
|
|
74
|
+
* @param {Object} [opt={}] 輸入設定物件,預設{},其餘欄位皆傳遞至estimKeys
|
|
75
|
+
* @param {Function} [opt.funFilterKeysNorm=null] 輸入過濾一般類key之async函數,傳入keysNorm陣列回傳過濾後陣列,預設null
|
|
76
|
+
* @param {Function} [opt.funFilterKeysIndex=null] 輸入過濾指數類key之async函數,傳入keysIndex陣列回傳過濾後陣列,預設null
|
|
77
|
+
* @param {Function} [opt.funFilterKeysVolumn=null] 輸入過濾成交量類key之async函數,傳入keysVolumn陣列回傳過濾後陣列,預設null
|
|
78
|
+
* @returns {Promise} 回傳Promise,resolve為undefined
|
|
79
|
+
* @example
|
|
80
|
+
*
|
|
81
|
+
* import ott from './src/ott.mjs'
|
|
82
|
+
*
|
|
83
|
+
* let st = {
|
|
84
|
+
* btc4hr: { name: 'btc', symbol: 'BTCUSDT', interval: '4hr' },
|
|
85
|
+
* }
|
|
86
|
+
*
|
|
87
|
+
* //funPickKeys, 由一般類挑第1個key為待率定key
|
|
88
|
+
* let funPickKeys = ({ keysNorm, keysIndex, keysVolumn }) => {
|
|
89
|
+
* return [keysNorm[0]]
|
|
90
|
+
* }
|
|
91
|
+
*
|
|
92
|
+
* await estimPicks(ott, st, './data/ohlc', './data/param', '2022-07-01T00:00:00', '2025-04-08T00:00:00', 'long', funPickKeys, './data/strategy', {
|
|
93
|
+
* keySettings: 'btc4hr',
|
|
94
|
+
* })
|
|
95
|
+
*
|
|
96
|
+
*/
|
|
97
|
+
let estimPicks = async (ott, st, fdOhlc, fdParam, timeStart, timeEnd, mode, funPickKeys, fdData, opt = {}) => {
|
|
98
|
+
|
|
99
|
+
if (!isestr(fdOhlc)) {
|
|
100
|
+
throw new Error(`invalid fdOhlc[${fdOhlc}]`)
|
|
101
|
+
}
|
|
102
|
+
if (!isestr(fdParam)) {
|
|
103
|
+
throw new Error(`invalid fdParam[${fdParam}]`)
|
|
104
|
+
}
|
|
105
|
+
if (!isestr(timeStart)) {
|
|
106
|
+
throw new Error(`invalid timeStart[${timeStart}]`)
|
|
107
|
+
}
|
|
108
|
+
if (!isestr(timeEnd)) {
|
|
109
|
+
throw new Error(`invalid timeEnd[${timeEnd}]`)
|
|
110
|
+
}
|
|
111
|
+
if (mode !== 'long' && mode !== 'short') {
|
|
112
|
+
throw new Error(`invalid mode[${mode}]`)
|
|
113
|
+
}
|
|
114
|
+
if (!isfun(funPickKeys)) {
|
|
115
|
+
throw new Error(`funPickKeys is not a function`)
|
|
116
|
+
}
|
|
117
|
+
if (!isestr(fdData)) {
|
|
118
|
+
throw new Error(`invalid fdData[${fdData}]`)
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
let funFilterKeysNorm = get(opt, 'funFilterKeysNorm', null)
|
|
122
|
+
let funFilterKeysIndex = get(opt, 'funFilterKeysIndex', null)
|
|
123
|
+
let funFilterKeysVolumn = get(opt, 'funFilterKeysVolumn', null)
|
|
124
|
+
|
|
125
|
+
//provideData
|
|
126
|
+
let provideData = dataProvide(fdOhlc, fdParam)
|
|
127
|
+
|
|
128
|
+
//keysParam
|
|
129
|
+
let keysParam = provideData.getKeysParam()
|
|
130
|
+
// console.log('keysParam', keysParam)
|
|
131
|
+
|
|
132
|
+
//keysIndex, keysVolumn, keysNorm
|
|
133
|
+
let keysIndex = []
|
|
134
|
+
let keysVolumn = []
|
|
135
|
+
let keysNorm = []
|
|
136
|
+
each(keysParam, (v) => {
|
|
137
|
+
let b1 = v.indexOf('index_') === 0
|
|
138
|
+
let b2 = v.indexOf('_vbs_') >= 0
|
|
139
|
+
let b3 = !(b1 || b2)
|
|
140
|
+
if (b1) {
|
|
141
|
+
keysIndex.push(v)
|
|
142
|
+
}
|
|
143
|
+
else if (b2) {
|
|
144
|
+
keysVolumn.push(v)
|
|
145
|
+
}
|
|
146
|
+
else if (b3) {
|
|
147
|
+
keysNorm.push(v)
|
|
148
|
+
}
|
|
149
|
+
})
|
|
150
|
+
// console.log('keysIndex', keysIndex)
|
|
151
|
+
// console.log('keysVolumn', keysVolumn)
|
|
152
|
+
// console.log('keysNorm', keysNorm)
|
|
153
|
+
// console.log(size(keysIndex) + size(keysVolumn) + size(keysNorm))
|
|
154
|
+
|
|
155
|
+
if (isfun(funFilterKeysNorm)) {
|
|
156
|
+
keysNorm = await funFilterKeysNorm(keysNorm)
|
|
157
|
+
}
|
|
158
|
+
if (isfun(funFilterKeysIndex)) {
|
|
159
|
+
keysIndex = await funFilterKeysIndex(keysIndex)
|
|
160
|
+
}
|
|
161
|
+
if (isfun(funFilterKeysVolumn)) {
|
|
162
|
+
keysVolumn = await funFilterKeysVolumn(keysVolumn)
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
//keys
|
|
166
|
+
let keys = funPickKeys({ keysNorm, keysIndex, keysVolumn })
|
|
167
|
+
// console.log('keys', keys)
|
|
168
|
+
|
|
169
|
+
//estimKeys
|
|
170
|
+
await estimKeys(ott, st, fdOhlc, fdParam, timeStart, timeEnd, mode, keys, fdData, opt)
|
|
171
|
+
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
export default estimPicks
|
|
176
|
+
</code></pre>
|
|
177
|
+
</article>
|
|
178
|
+
</section>
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
</div>
|
|
186
|
+
|
|
187
|
+
<br class="clear">
|
|
188
|
+
|
|
189
|
+
<footer>
|
|
190
|
+
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.
|
|
191
|
+
</footer>
|
|
192
|
+
|
|
193
|
+
<script>prettyPrint();</script>
|
|
194
|
+
<script src="scripts/polyfill.js"></script>
|
|
195
|
+
<script src="scripts/linenumber.js"></script>
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
</body>
|
|
200
|
+
</html>
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|