w-trade-solve 1.0.2 → 1.0.4
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/README.md +15 -11
- package/dist/w-trade-solve.umd.js +5 -5
- package/dist/w-trade-solve.umd.js.map +1 -1
- package/docs/calcFitness.mjs.html +1 -1
- package/docs/calcLevelNumTrade.mjs.html +1 -1
- package/docs/cont.mjs.html +1 -1
- package/docs/estimComps.mjs.html +16 -11
- package/docs/estimFinder.mjs.html +17 -12
- package/docs/estimKeys.mjs.html +53 -34
- package/docs/estimPicks.mjs.html +17 -12
- package/docs/genSid.mjs.html +1 -1
- package/docs/genStrategyFileName.mjs.html +1 -1
- package/docs/genTid.mjs.html +1 -1
- package/docs/global.html +332 -67
- package/docs/index.html +1 -1
- package/docs/ott.mjs.html +1 -1
- package/docs/p2r.mjs.html +1 -1
- package/docs/readStrategies.mjs.html +1 -1
- package/g.mjs +14 -11
- package/package.json +5 -6
- package/src/estimComps.mjs +15 -10
- package/src/estimFinder.mjs +16 -11
- package/src/estimKeys.mjs +52 -33
- package/src/estimPicks.mjs +16 -11
- package/test/unit-estimComps.test.mjs +34 -18
- package/test/unit-estimFinder.test.mjs +33 -20
- package/test/unit-estimKeys.test.mjs +115 -17
- package/test/unit-estimPicks.test.mjs +27 -17
- package/test/unit-setup.mjs +8 -14
package/README.md
CHANGED
|
@@ -38,15 +38,11 @@ async function test() {
|
|
|
38
38
|
fs.mkdirSync(fdOhlc, { recursive: true })
|
|
39
39
|
fs.mkdirSync(fdParam, { recursive: true })
|
|
40
40
|
|
|
41
|
-
//
|
|
41
|
+
//name, symbol, interval, 幣種設定
|
|
42
42
|
// name 與 interval 用於組出 K 線序列 key(`${name}_price_${interval}`)與縮寫 tid
|
|
43
|
-
let
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
symbol: 'BTCUSDT',
|
|
47
|
-
interval: '4hr',
|
|
48
|
-
},
|
|
49
|
-
}
|
|
43
|
+
let name = 'btc'
|
|
44
|
+
let symbol = 'BTCUSDT'
|
|
45
|
+
let interval = '4hr'
|
|
50
46
|
|
|
51
47
|
//arrOhlc 與 arrParam, 20 根 4hr K 線與對應之指標序列(以 sin/cos 合成之示範資料)
|
|
52
48
|
let arrOhlc = []
|
|
@@ -65,17 +61,24 @@ async function test() {
|
|
|
65
61
|
//keys, 待率定門檻之指標 key, 各 key 於 fdParam 內須有對應之 `${key}.json`
|
|
66
62
|
let keys = ['btc_4hr_ma_1day']
|
|
67
63
|
|
|
68
|
-
//estimKeys,
|
|
64
|
+
//estimKeys, 以最佳化演算法率定[止損, 止盈, 各 key 門檻], 逐次以 runStrategy 回測並取 fitness 最小者
|
|
69
65
|
// 滿足 thNumTrade / thRWin / thREquivalentCumuProfitOrLossFinalNormYear 三門檻之參數組會存入 fdData
|
|
70
|
-
|
|
71
|
-
|
|
66
|
+
// opt 除下列各欄位外皆傳遞至演算法, 故可一併給 Np / NContiguous 等求解設定
|
|
67
|
+
let m = await wts.estimKeys(ott, name, symbol, interval, fdOhlc, fdParam, arrOhlc[0].time, arrOhlc[19].time, 'long', keys, fdData, {
|
|
72
68
|
thsTp: [3], //止盈候選(%), 僅給 1 點使示範較快收斂
|
|
73
69
|
thsSl: [2], //止損候選(%)
|
|
74
70
|
thNumTrade: 5, //至少 5 筆交易才存檔
|
|
75
71
|
thRWin: 0.5, //勝率至少 50% 才存檔
|
|
76
72
|
thREquivalentCumuProfitOrLossFinalNormYear: 0, //等效年化盈虧至少 0 才存檔
|
|
73
|
+
methodOml: 'PSO', //可選 'RGA' / 'DE' / 'HS' / 'PSO' / 'ACO', 預設 'PSO'
|
|
74
|
+
Np: 8, //PSO 之粒子數, 預設 40
|
|
75
|
+
NContiguous: 5, //最佳解連續未更新次數上限, 預設 100
|
|
77
76
|
})
|
|
78
77
|
|
|
78
|
+
//停止機制, 由所選演算法之設定決定, 此處為 NContiguous 達 5 而停止
|
|
79
|
+
console.log(m.stopMode)
|
|
80
|
+
// => 'stop by iContinue[5] >= NContiguous[5]'
|
|
81
|
+
|
|
79
82
|
//設計變數為[止損, 止盈, 各 key 門檻], 故個數為 2 + keys 個數
|
|
80
83
|
// 各 key 門檻之解值帶有平移量 10, 大於 0 代表'>'條件、小於 0 代表'<'條件, 還原時扣除平移量
|
|
81
84
|
// estimKeys 為隨機求解, 故以下各數值每次執行皆不同, 僅結構固定
|
|
@@ -129,4 +132,5 @@ test()
|
|
|
129
132
|
console.log('catch', err)
|
|
130
133
|
})
|
|
131
134
|
|
|
135
|
+
|
|
132
136
|
```
|