w-trade-solve 1.0.2 → 1.0.3

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.
@@ -192,7 +192,7 @@ export default calcFitness
192
192
  <br class="clear">
193
193
 
194
194
  <footer>
195
- Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.5</a> on Wed Aug 05 2026 10:37:47 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
195
+ Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.5</a> on Wed Aug 05 2026 14:58:22 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
196
196
  </footer>
197
197
 
198
198
  <script>prettyPrint();</script>
@@ -151,7 +151,7 @@ export default calcLevelNumTrade
151
151
  <br class="clear">
152
152
 
153
153
  <footer>
154
- Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.5</a> on Wed Aug 05 2026 10:37:47 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
154
+ Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.5</a> on Wed Aug 05 2026 14:58:22 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
155
155
  </footer>
156
156
 
157
157
  <script>prettyPrint();</script>
@@ -81,7 +81,7 @@ export default r
81
81
  <br class="clear">
82
82
 
83
83
  <footer>
84
- Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.5</a> on Wed Aug 05 2026 10:37:47 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
84
+ Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.5</a> on Wed Aug 05 2026 14:58:22 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
85
85
  </footer>
86
86
 
87
87
  <script>prettyPrint();</script>
@@ -65,7 +65,9 @@ import estimPicks from './estimPicks.mjs'
65
65
  * Unit Test: {@link https://github.com/yuda-lyu/w-trade-solve/blob/master/test/unit-estimComps.test.mjs Github}
66
66
  * @function
67
67
  * @param {Function} ott 輸入時區時間函數,傳入時間字串回傳dayjs時間物件,可用src/ott.mjs
68
- * @param {Object} st 輸入設定物件,需可由opt.keySettings取得name、symbol與interval欄位
68
+ * @param {String} name 輸入幣種名稱字串,例如'btc'
69
+ * @param {String} symbol 輸入交易對名稱字串,例如'BTCUSDT'
70
+ * @param {String} interval 輸入K線週期字串,例如'4hr'
69
71
  * @param {String} fdOhlc 輸入儲存K線(ohlc)序列資料夾字串
70
72
  * @param {String} fdParam 輸入儲存指標參數序列資料夾字串
71
73
  * @param {String} timeStart 輸入回測起始時間字串,格式'YYYY-MM-DDTHH:mm:ss'
@@ -79,18 +81,21 @@ import estimPicks from './estimPicks.mjs'
79
81
  *
80
82
  * import ott from './src/ott.mjs'
81
83
  *
82
- * let st = {
83
- * btc4hr: { name: 'btc', symbol: 'BTCUSDT', interval: '4hr' },
84
- * }
85
- *
86
84
  * //comps='2,1,0', 挑2種一般類、1種指數類與0種成交量類
87
- * await estimComps(ott, st, './data/ohlc', './data/param', '2022-07-01T00:00:00', '2025-04-08T00:00:00', 'long', '2,1,0', './data/strategy', {
88
- * keySettings: 'btc4hr',
89
- * })
85
+ * await estimComps(ott, 'btc', 'BTCUSDT', '4hr', './data/ohlc', './data/param', '2022-07-01T00:00:00', '2025-04-08T00:00:00', 'long', '2,1,0', './data/strategy', {})
90
86
  *
91
87
  */
92
- let estimComps = async (ott, st, fdOhlc, fdParam, timeStart, timeEnd, mode, comps, fdData, opt = {}) => {
88
+ let estimComps = async (ott, name, symbol, interval, fdOhlc, fdParam, timeStart, timeEnd, mode, comps, fdData, opt = {}) => {
93
89
 
90
+ if (!isestr(name)) {
91
+ throw new Error(`invalid name[${name}]`)
92
+ }
93
+ if (!isestr(symbol)) {
94
+ throw new Error(`invalid symbol[${symbol}]`)
95
+ }
96
+ if (!isestr(interval)) {
97
+ throw new Error(`invalid interval[${interval}]`)
98
+ }
94
99
  if (!isestr(fdOhlc)) {
95
100
  throw new Error(`invalid fdOhlc[${fdOhlc}]`)
96
101
  }
@@ -157,7 +162,7 @@ let estimComps = async (ott, st, fdOhlc, fdParam, timeStart, timeEnd, mode, comp
157
162
  }
158
163
 
159
164
  //estimPicks
160
- await estimPicks(ott, st, fdOhlc, fdParam, timeStart, timeEnd, mode, funPickKeys, fdData, opt)
165
+ await estimPicks(ott, name, symbol, interval, fdOhlc, fdParam, timeStart, timeEnd, mode, funPickKeys, fdData, opt)
161
166
 
162
167
  }
163
168
 
@@ -177,7 +182,7 @@ export default estimComps
177
182
  <br class="clear">
178
183
 
179
184
  <footer>
180
- Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.5</a> on Wed Aug 05 2026 10:37:47 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
185
+ Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.5</a> on Wed Aug 05 2026 14:58:22 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
181
186
  </footer>
182
187
 
183
188
  <script>prettyPrint();</script>
@@ -56,12 +56,14 @@ import estimComps from './estimComps.mjs'
56
56
  *
57
57
  * 供批次探索用之進入點,未指定時mode由'long'與'short'隨機取一,comps由18種預設組成隨機取一,故重複呼叫即可隨機探索各種策略
58
58
  * 未指定時timeStart預設為'2022-07-01T00:00:00',timeEnd則依mode給予不同值: 做多為'2025-04-08T00:00:00'(須涵蓋暴跌數據),做空為'2025-10-06T00:00:00'(須涵蓋暴漲數據),藉此提高率定難度
59
- * fdOhlc、fdParam與fdData無效時throw
59
+ * name、symbol、interval、fdOhlc、fdParam與fdData無效時throw
60
60
  *
61
61
  * Unit Test: {@link https://github.com/yuda-lyu/w-trade-solve/blob/master/test/unit-estimFinder.test.mjs Github}
62
62
  * @function
63
63
  * @param {Function} ott 輸入時區時間函數,傳入時間字串回傳dayjs時間物件,可用src/ott.mjs
64
- * @param {Object} st 輸入設定物件,需可由opt.keySettings取得name、symbol與interval欄位
64
+ * @param {String} name 輸入幣種名稱字串,例如'btc'
65
+ * @param {String} symbol 輸入交易對名稱字串,例如'BTCUSDT'
66
+ * @param {String} interval 輸入K線週期字串,例如'4hr'
65
67
  * @param {String} fdOhlc 輸入儲存K線(ohlc)序列資料夾字串
66
68
  * @param {String} fdParam 輸入儲存指標參數序列資料夾字串
67
69
  * @param {String} fdData 輸入儲存策略資料夾字串,不存在時自動建立
@@ -75,18 +77,21 @@ import estimComps from './estimComps.mjs'
75
77
  *
76
78
  * import ott from './src/ott.mjs'
77
79
  *
78
- * let st = {
79
- * btc4hr: { name: 'btc', symbol: 'BTCUSDT', interval: '4hr' },
80
- * }
81
- *
82
80
  * //mode與comps皆隨機, 適合以迴圈重複呼叫批次探索
83
- * await estimFinder(ott, st, './data/ohlc', './data/param', './data/strategy', {
84
- * keySettings: 'btc4hr',
85
- * })
81
+ * await estimFinder(ott, 'btc', 'BTCUSDT', '4hr', './data/ohlc', './data/param', './data/strategy', {})
86
82
  *
87
83
  */
88
- let estimFinder = async (ott, st, fdOhlc, fdParam, fdData, opt = {}) => {
84
+ let estimFinder = async (ott, name, symbol, interval, fdOhlc, fdParam, fdData, opt = {}) => {
89
85
 
86
+ if (!isestr(name)) {
87
+ throw new Error(`invalid name[${name}]`)
88
+ }
89
+ if (!isestr(symbol)) {
90
+ throw new Error(`invalid symbol[${symbol}]`)
91
+ }
92
+ if (!isestr(interval)) {
93
+ throw new Error(`invalid interval[${interval}]`)
94
+ }
90
95
  if (!isestr(fdOhlc)) {
91
96
  throw new Error(`invalid fdOhlc[${fdOhlc}]`)
92
97
  }
@@ -164,7 +169,7 @@ let estimFinder = async (ott, st, fdOhlc, fdParam, fdData, opt = {}) => {
164
169
  }
165
170
 
166
171
  //estimComps
167
- await estimComps(ott, st, fdOhlc, fdParam, timeStart, timeEnd, mode, comps, fdData, opt)
172
+ await estimComps(ott, name, symbol, interval, fdOhlc, fdParam, timeStart, timeEnd, mode, comps, fdData, opt)
168
173
 
169
174
  }
170
175
 
@@ -184,7 +189,7 @@ export default estimFinder
184
189
  <br class="clear">
185
190
 
186
191
  <footer>
187
- Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.5</a> on Wed Aug 05 2026 10:37:47 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
192
+ Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.5</a> on Wed Aug 05 2026 14:58:22 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
188
193
  </footer>
189
194
 
190
195
  <script>prettyPrint();</script>
@@ -63,7 +63,11 @@ import isestr from 'wsemi/src/isestr.mjs'
63
63
  import isnum from 'wsemi/src/isnum.mjs'
64
64
  import rang from 'wsemi/src/rang.mjs'
65
65
  import wround from 'wsemi/src/round.mjs'
66
+ import omlRGA from 'w-optimization/src/omlRGA.mjs'
67
+ import omlDE from 'w-optimization/src/omlDE.mjs'
68
+ import omlHS from 'w-optimization/src/omlHS.mjs'
66
69
  import omlPSO from 'w-optimization/src/omlPSO.mjs'
70
+ import omlACO from 'w-optimization/src/omlACO.mjs'
67
71
  import dataProvide from 'w-data-tdprovide'
68
72
  import runStrategy from 'w-trade-backtest/src/runStrategy.mjs'
69
73
  import readStrategies from './readStrategies.mjs'
@@ -80,16 +84,19 @@ import genStrategyFileName from './genStrategyFileName.mjs'
80
84
  *
81
85
  * 設計變數為[止損比例, 止盈比例, ...各key之門檻],止損與止盈由opt.thsSl與opt.thsTp給予之百分比清單離散取值
82
86
  * 各key門檻取值範圍為[-thLim,thLim]切為thLim*20段,並各自平移+vdir與-vdir(vdir=thLim*5)為兩組,使解值恆大於0代表'>'條件、恆小於0代表'&lt;'條件,還原時再扣除平移值,故單一設計變數即同時涵蓋大於與小於兩種條件
83
- * 以omlPSO粒子群最佳化求解,各次計算皆以w-trade-backtest之runStrategy回測並經calcFitness計算適應值
87
+ * 以w-optimization之最佳化函數求解,由opt.methodOml指定演算法,各次計算皆以w-trade-backtest之runStrategy回測並經calcFitness計算適應值
84
88
  * 各次計算結果若同時滿足交易次數、勝率與最終等效年化盈虧三門檻,則以genStrategyFileName產生檔名存入fdData;同tid且同交易次數級距(tkid)已有策略時,僅於最終等效年化盈虧更佳時抽換,並刪除較差者
85
- * opt除下列各欄位外,其餘欄位皆原樣傳遞至omlPSO,兩者欄位名稱無重疊,故可一併給予omlPSO之求解設定,包含Nl(最大總迴圈數,預設10000)、Np(粒子數,預設40)、NContiguous(最佳解連續未更新次數上限,預設100)、NRepeat、NCore、ModeOutLimit、UseRepeat、UseImmigration、LocalSearchMethod、funGetBetter、funEndLoop、funGenerationBefore、funGenerationAfter與psoBeta、psoGamma、psoInertiaMin、psoC1Start、psoC1End、psoC1Dynamic、psoC2Start、psoC2End、psoC2Dynamic
86
- * omlPSO預設之求解量甚大(單一key約需1萬7千次回測),僅需快速試算時可調小Np與NContiguous
87
- * fdOhlc、fdParam、timeStart、timeEnd、keys、fdData無效或mode非'long'或'short'時throw
89
+ * opt除下列各欄位外,其餘欄位皆原樣傳遞至所選之最佳化函數,兩者欄位名稱無重疊,故可一併給予求解設定
90
+ * 各演算法共通之設定為NContiguous(最佳解連續未更新次數上限,預設100)、NRepeat、NCore、ModeOutLimit、UseRepeat、UseImmigration、LocalSearchMethod與funGetBetter、funGenerationBefore、funGenerationAfter三接口;族群數與迴圈數之欄位名稱各演算法不同,RGA與DE為Np與Ng、PSO為Np與Nl、HS為Ns與Ni、ACO為Na與Nl;另各演算法有其專屬超參數,如PSO之psoC1Start、RGA之rgaCrossover、DE之deF、HS之hsHMCR與ACO之acoAlphaStart等
91
+ * 預設之求解量甚大(單一key約需1萬7千次回測),僅需快速試算時可調小族群數與NContiguous
92
+ * name、symbol、interval、fdOhlc、fdParam、timeStart、timeEnd、keys、fdData無效或mode非'long'或'short'時throw
88
93
  *
89
94
  * Unit Test: {@link https://github.com/yuda-lyu/w-trade-solve/blob/master/test/unit-estimKeys.test.mjs Github}
90
95
  * @function
91
96
  * @param {Function} ott 輸入時區時間函數,傳入時間字串回傳dayjs時間物件,可用src/ott.mjs
92
- * @param {Object} st 輸入設定物件,需可由opt.keySettings取得name、symbol與interval欄位
97
+ * @param {String} name 輸入幣種名稱字串,例如'btc',用於組出K線序列key(`${name}_price_${interval}`)與縮寫tid
98
+ * @param {String} symbol 輸入交易對名稱字串,例如'BTCUSDT',僅儲存至策略內供辨識
99
+ * @param {String} interval 輸入K線週期字串,例如'4hr'
93
100
  * @param {String} fdOhlc 輸入儲存K線(ohlc)序列資料夾字串
94
101
  * @param {String} fdParam 輸入儲存指標參數序列資料夾字串
95
102
  * @param {String} timeStart 輸入回測起始時間字串,格式'YYYY-MM-DDTHH:mm:ss'
@@ -97,33 +104,23 @@ import genStrategyFileName from './genStrategyFileName.mjs'
97
104
  * @param {String} mode 輸入交易方向字串,可選'long'或'short'
98
105
  * @param {Array} keys 輸入待率定門檻之指標key字串陣列
99
106
  * @param {String} fdData 輸入儲存策略資料夾字串,不存在時自動建立
100
- * @param {Object} [opt={}] 輸入設定物件,預設{},全部欄位皆傳遞至omlPSO,故可另給Nl、Np、NContiguous等omlPSO之設定
101
- * @param {String} opt.keySettings 輸入取用st內設定之鍵字串,例如'btc4hr'代表取用st.btc4hr.name、st.btc4hr.symbol與st.btc4hr.interval
107
+ * @param {Object} [opt={}] 輸入設定物件,預設{},除下列欄位外皆傳遞至所選之最佳化函數,故可另給NContiguous等求解設定
108
+ * @param {String} [opt.methodOml='PSO'] 輸入最佳化演算法字串,可選'RGA'(實數型基因演算法)、'DE'(差分進化法)、'HS'(和聲搜尋法)、'PSO'(粒子群最佳化)與'ACO'(蟻群最佳化),給予其他值時亦採'PSO',預設'PSO'
102
109
  * @param {Array} [opt.thsTp=[1,2,3,4,5,6,7,8,9,10]] 輸入止盈門檻百分比數值陣列,預設[1,2,3,4,5,6,7,8,9,10]
103
110
  * @param {Array} [opt.thsSl=[1,2,3,4,5,6,7,8,9,10]] 輸入止損門檻百分比數值陣列,預設[1,2,3,4,5,6,7,8,9,10]
104
111
  * @param {Number} [opt.thNumTrade=1] 輸入策略須儲存之最少交易次數數值,預設1
105
112
  * @param {Number} [opt.thRWin=0.5] 輸入策略須儲存之最低勝率比例數值,預設0.5
106
113
  * @param {Number} [opt.thREquivalentCumuProfitOrLossFinalNormYear=0.15] 輸入策略須儲存之最低最終等效年化盈虧比例數值,預設0.15
107
114
  * @param {Boolean} [opt.useShowLog=false] 輸入是否顯示求解過程log布林值,預設false
108
- * @returns {Promise} 回傳Promise,resolve為omlPSO之求解結果物件,含bestSolution(最佳解,內有ps設計變數陣列與fitness適應值)、stopMode(觸發停止之機制字串)、stopIteration(停止時之迴圈數)與stopExecutions(停止時之核心分析次數)等欄位
115
+ * @returns {Promise} 回傳Promise,resolve為求解結果物件,含bestSolution(最佳解,內有ps設計變數陣列與fitness適應值)、stopMode(觸發停止之機制字串)、stopIteration(停止時之迴圈數)與stopExecutions(停止時之核心分析次數)等欄位
109
116
  * @example
110
117
  *
111
118
  * import ott from './src/ott.mjs'
112
119
  *
113
- * //st, 各設定以keySettings為鍵儲存
114
- * let st = {
115
- * btc4hr: {
116
- * name: 'btc',
117
- * symbol: 'BTCUSDT',
118
- * interval: '4hr',
119
- * },
120
- * }
121
- *
122
120
  * //keys, 待率定門檻之指標key, 各key於fdParam內須有對應之`${key}.json`
123
121
  * let keys = ['btc_price_4hr_ma_1day']
124
122
  *
125
- * let m = await estimKeys(ott, st, './data/ohlc', './data/param', '2022-07-01T00:00:00', '2025-04-08T00:00:00', 'long', keys, './data/strategy', {
126
- * keySettings: 'btc4hr',
123
+ * let m = await estimKeys(ott, 'btc', 'BTCUSDT', '4hr', './data/ohlc', './data/param', '2022-07-01T00:00:00', '2025-04-08T00:00:00', 'long', keys, './data/strategy', {
127
124
  * thsTp: [1, 2, 3],
128
125
  * thsSl: [1, 2, 3],
129
126
  * useShowLog: true,
@@ -131,12 +128,12 @@ import genStrategyFileName from './genStrategyFileName.mjs'
131
128
  * console.log(m.bestSolution.fitness)
132
129
  * // => 1.0325
133
130
  *
134
- * //可一併給予omlPSO之求解設定, 縮小Np與NContiguous即可快速試算
135
- * let mQuick = await estimKeys(ott, st, './data/ohlc', './data/param', '2022-07-01T00:00:00', '2025-04-08T00:00:00', 'long', keys, './data/strategy', {
136
- * keySettings: 'btc4hr',
131
+ * //可指定演算法並一併給予其求解設定, 縮小族群數與NContiguous即可快速試算
132
+ * let mQuick = await estimKeys(ott, 'btc', 'BTCUSDT', '4hr', './data/ohlc', './data/param', '2022-07-01T00:00:00', '2025-04-08T00:00:00', 'long', keys, './data/strategy', {
137
133
  * thsTp: [1, 2, 3],
138
134
  * thsSl: [1, 2, 3],
139
- * Np: 8, //粒子數, 預設40
135
+ * methodOml: 'PSO',
136
+ * Np: 8, //PSO之粒子數, 預設40
140
137
  * NContiguous: 5, //最佳解連續未更新次數上限, 預設100
141
138
  * })
142
139
  * console.log(mQuick.stopMode)
@@ -145,8 +142,17 @@ import genStrategyFileName from './genStrategyFileName.mjs'
145
142
  * // => 357
146
143
  *
147
144
  */
148
- let estimKeys = async (ott, st, fdOhlc, fdParam, timeStart, timeEnd, mode, keys, fdData, opt = {}) => {
145
+ let estimKeys = async (ott, name, symbol, interval, fdOhlc, fdParam, timeStart, timeEnd, mode, keys, fdData, opt = {}) => {
149
146
 
147
+ if (!isestr(name)) {
148
+ throw new Error(`invalid name[${name}]`)
149
+ }
150
+ if (!isestr(symbol)) {
151
+ throw new Error(`invalid symbol[${symbol}]`)
152
+ }
153
+ if (!isestr(interval)) {
154
+ throw new Error(`invalid interval[${interval}]`)
155
+ }
150
156
  if (!isestr(fdOhlc)) {
151
157
  throw new Error(`invalid fdOhlc[${fdOhlc}]`)
152
158
  }
@@ -169,9 +175,9 @@ let estimKeys = async (ott, st, fdOhlc, fdParam, timeStart, timeEnd, mode, keys,
169
175
  throw new Error(`invalid fdData[${fdData}]`)
170
176
  }
171
177
 
172
- let keySettings = get(opt, 'keySettings', '')
173
- if (!isestr(keySettings)) {
174
- throw new Error(`invalid opt.keySettings[${keySettings}]`)
178
+ let methodOml = get(opt, 'methodOml', '')
179
+ if (!isestr(methodOml)) {
180
+ methodOml = 'PSO'
175
181
  }
176
182
  let thsTp = get(opt, 'thsTp', null)
177
183
  if (!isearr(thsTp)) {
@@ -198,11 +204,6 @@ let estimKeys = async (ott, st, fdOhlc, fdParam, timeStart, timeEnd, mode, keys,
198
204
  //provideData
199
205
  let provideData = dataProvide(fdOhlc, fdParam)
200
206
 
201
- //st
202
- let name = get(st, `${keySettings}.name`, '')
203
- let symbol = get(st, `${keySettings}.symbol`, '')
204
- let interval = get(st, `${keySettings}.interval`, '')
205
-
206
207
  //fdData, 儲存策略資料夾, 由呼叫端指定, 不存在則建立
207
208
  if (!fsIsFolder(fdData)) {
208
209
  fsCreateFolder(fdData)
@@ -540,8 +541,26 @@ let estimKeys = async (ott, st, fdOhlc, fdParam, timeStart, timeEnd, mode, keys,
540
541
  return fitness
541
542
  }
542
543
 
544
+ //oml
545
+ let oml = omlPSO
546
+ if (methodOml === 'RGA') {
547
+ oml = omlRGA
548
+ }
549
+ else if (methodOml === 'DE') {
550
+ oml = omlDE
551
+ }
552
+ else if (methodOml === 'HS') {
553
+ oml = omlHS
554
+ }
555
+ else if (methodOml === 'PSO') {
556
+ oml = omlPSO
557
+ }
558
+ else if (methodOml === 'ACO') {
559
+ oml = omlACO
560
+ }
561
+
543
562
  //m
544
- let m = await omlPSO(dps, fun, {
563
+ let m = await oml(dps, fun, {
545
564
  // funGenerationBefore,
546
565
  // funGenerationAfter,
547
566
  // funGetBetter,
@@ -574,7 +593,7 @@ export default estimKeys
574
593
  <br class="clear">
575
594
 
576
595
  <footer>
577
- Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.5</a> on Wed Aug 05 2026 10:37:47 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
596
+ Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.5</a> on Wed Aug 05 2026 14:58:22 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
578
597
  </footer>
579
598
 
580
599
  <script>prettyPrint();</script>
@@ -58,12 +58,14 @@ import estimKeys from './estimKeys.mjs'
58
58
  *
59
59
  * 先由fdParam列舉全部指標key,並依名稱分為3類: 開頭為'index_'者為keysIndex(指數類)、含'_vbs_'者為keysVolumn(成交量類)、其餘為keysNorm(一般類)
60
60
  * 分類後各類可經opt內對應之過濾函數再行篩選,接著呼叫funPickKeys由3類挑出待率定之keys,最後交由estimKeys求解
61
- * fdOhlc、fdParam、timeStart、timeEnd、fdData無效或mode非'long'或'short'或funPickKeys非函數時throw
61
+ * name、symbol、interval、fdOhlc、fdParam、timeStart、timeEnd、fdData無效或mode非'long'或'short'或funPickKeys非函數時throw
62
62
  *
63
63
  * Unit Test: {@link https://github.com/yuda-lyu/w-trade-solve/blob/master/test/unit-estimPicks.test.mjs Github}
64
64
  * @function
65
65
  * @param {Function} ott 輸入時區時間函數,傳入時間字串回傳dayjs時間物件,可用src/ott.mjs
66
- * @param {Object} st 輸入設定物件,需可由opt.keySettings取得name、symbol與interval欄位
66
+ * @param {String} name 輸入幣種名稱字串,例如'btc'
67
+ * @param {String} symbol 輸入交易對名稱字串,例如'BTCUSDT'
68
+ * @param {String} interval 輸入K線週期字串,例如'4hr'
67
69
  * @param {String} fdOhlc 輸入儲存K線(ohlc)序列資料夾字串
68
70
  * @param {String} fdParam 輸入儲存指標參數序列資料夾字串
69
71
  * @param {String} timeStart 輸入回測起始時間字串,格式'YYYY-MM-DDTHH:mm:ss'
@@ -80,22 +82,25 @@ import estimKeys from './estimKeys.mjs'
80
82
  *
81
83
  * import ott from './src/ott.mjs'
82
84
  *
83
- * let st = {
84
- * btc4hr: { name: 'btc', symbol: 'BTCUSDT', interval: '4hr' },
85
- * }
86
- *
87
85
  * //funPickKeys, 由一般類挑第1個key為待率定key
88
86
  * let funPickKeys = ({ keysNorm, keysIndex, keysVolumn }) => {
89
87
  * return [keysNorm[0]]
90
88
  * }
91
89
  *
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
- * })
90
+ * await estimPicks(ott, 'btc', 'BTCUSDT', '4hr', './data/ohlc', './data/param', '2022-07-01T00:00:00', '2025-04-08T00:00:00', 'long', funPickKeys, './data/strategy', {})
95
91
  *
96
92
  */
97
- let estimPicks = async (ott, st, fdOhlc, fdParam, timeStart, timeEnd, mode, funPickKeys, fdData, opt = {}) => {
93
+ let estimPicks = async (ott, name, symbol, interval, fdOhlc, fdParam, timeStart, timeEnd, mode, funPickKeys, fdData, opt = {}) => {
98
94
 
95
+ if (!isestr(name)) {
96
+ throw new Error(`invalid name[${name}]`)
97
+ }
98
+ if (!isestr(symbol)) {
99
+ throw new Error(`invalid symbol[${symbol}]`)
100
+ }
101
+ if (!isestr(interval)) {
102
+ throw new Error(`invalid interval[${interval}]`)
103
+ }
99
104
  if (!isestr(fdOhlc)) {
100
105
  throw new Error(`invalid fdOhlc[${fdOhlc}]`)
101
106
  }
@@ -167,7 +172,7 @@ let estimPicks = async (ott, st, fdOhlc, fdParam, timeStart, timeEnd, mode, funP
167
172
  // console.log('keys', keys)
168
173
 
169
174
  //estimKeys
170
- await estimKeys(ott, st, fdOhlc, fdParam, timeStart, timeEnd, mode, keys, fdData, opt)
175
+ await estimKeys(ott, name, symbol, interval, fdOhlc, fdParam, timeStart, timeEnd, mode, keys, fdData, opt)
171
176
 
172
177
  }
173
178
 
@@ -187,7 +192,7 @@ export default estimPicks
187
192
  <br class="clear">
188
193
 
189
194
  <footer>
190
- Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.5</a> on Wed Aug 05 2026 10:37:47 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
195
+ Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.5</a> on Wed Aug 05 2026 14:58:22 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
191
196
  </footer>
192
197
 
193
198
  <script>prettyPrint();</script>
@@ -112,7 +112,7 @@ export default genSid
112
112
  <br class="clear">
113
113
 
114
114
  <footer>
115
- Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.5</a> on Wed Aug 05 2026 10:37:47 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
115
+ Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.5</a> on Wed Aug 05 2026 14:58:22 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
116
116
  </footer>
117
117
 
118
118
  <script>prettyPrint();</script>
@@ -118,7 +118,7 @@ export default genStrategyFileName
118
118
  <br class="clear">
119
119
 
120
120
  <footer>
121
- Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.5</a> on Wed Aug 05 2026 10:37:47 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
121
+ Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.5</a> on Wed Aug 05 2026 14:58:22 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
122
122
  </footer>
123
123
 
124
124
  <script>prettyPrint();</script>
@@ -100,7 +100,7 @@ export default genTid
100
100
  <br class="clear">
101
101
 
102
102
  <footer>
103
- Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.5</a> on Wed Aug 05 2026 10:37:47 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
103
+ Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.5</a> on Wed Aug 05 2026 14:58:22 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
104
104
  </footer>
105
105
 
106
106
  <script>prettyPrint();</script>