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.
Files changed (88) hide show
  1. package/.editorconfig +9 -0
  2. package/.eslintignore +3 -0
  3. package/.eslintrc.js +55 -0
  4. package/.jsdoc +25 -0
  5. package/README.md +132 -0
  6. package/SECURITY.md +5 -0
  7. package/babel.config.js +16 -0
  8. package/dist/w-trade-solve.umd.js +19 -0
  9. package/dist/w-trade-solve.umd.js.map +1 -0
  10. package/docs/calcFitness.mjs.html +205 -0
  11. package/docs/calcLevelNumTrade.mjs.html +164 -0
  12. package/docs/cont.mjs.html +94 -0
  13. package/docs/estimComps.mjs.html +190 -0
  14. package/docs/estimFinder.mjs.html +197 -0
  15. package/docs/estimKeys.mjs.html +571 -0
  16. package/docs/estimPicks.mjs.html +200 -0
  17. package/docs/fonts/Montserrat/Montserrat-Bold.eot +0 -0
  18. package/docs/fonts/Montserrat/Montserrat-Bold.ttf +0 -0
  19. package/docs/fonts/Montserrat/Montserrat-Bold.woff +0 -0
  20. package/docs/fonts/Montserrat/Montserrat-Bold.woff2 +0 -0
  21. package/docs/fonts/Montserrat/Montserrat-Regular.eot +0 -0
  22. package/docs/fonts/Montserrat/Montserrat-Regular.ttf +0 -0
  23. package/docs/fonts/Montserrat/Montserrat-Regular.woff +0 -0
  24. package/docs/fonts/Montserrat/Montserrat-Regular.woff2 +0 -0
  25. package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.eot +0 -0
  26. package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.svg +978 -0
  27. package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.ttf +0 -0
  28. package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.woff +0 -0
  29. package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.woff2 +0 -0
  30. package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.eot +0 -0
  31. package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.svg +1049 -0
  32. package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.ttf +0 -0
  33. package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.woff +0 -0
  34. package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.woff2 +0 -0
  35. package/docs/genSid.mjs.html +125 -0
  36. package/docs/genStrategyFileName.mjs.html +131 -0
  37. package/docs/genTid.mjs.html +113 -0
  38. package/docs/global.html +4932 -0
  39. package/docs/index.html +84 -0
  40. package/docs/ott.mjs.html +137 -0
  41. package/docs/p2r.mjs.html +111 -0
  42. package/docs/readStrategies.mjs.html +203 -0
  43. package/docs/scripts/collapse.js +39 -0
  44. package/docs/scripts/commonNav.js +28 -0
  45. package/docs/scripts/linenumber.js +25 -0
  46. package/docs/scripts/nav.js +12 -0
  47. package/docs/scripts/polyfill.js +4 -0
  48. package/docs/scripts/prettify/Apache-License-2.0.txt +202 -0
  49. package/docs/scripts/prettify/lang-css.js +2 -0
  50. package/docs/scripts/prettify/prettify.js +28 -0
  51. package/docs/scripts/search.js +99 -0
  52. package/docs/styles/jsdoc.css +776 -0
  53. package/docs/styles/prettify.css +80 -0
  54. package/g.mjs +110 -0
  55. package/package.json +31 -0
  56. package/script.txt +19 -0
  57. package/src/WTradeSolve.mjs +29 -0
  58. package/src/calcFitness.mjs +133 -0
  59. package/src/calcLevelNumTrade.mjs +92 -0
  60. package/src/cont.mjs +22 -0
  61. package/src/estimComps.mjs +118 -0
  62. package/src/estimFinder.mjs +125 -0
  63. package/src/estimKeys.mjs +499 -0
  64. package/src/estimPicks.mjs +128 -0
  65. package/src/genSid.mjs +53 -0
  66. package/src/genStrategyFileName.mjs +59 -0
  67. package/src/genTid.mjs +41 -0
  68. package/src/ott.mjs +65 -0
  69. package/src/p2r.mjs +39 -0
  70. package/src/readStrategies.mjs +131 -0
  71. package/test/unit-WTradeSolve.test.mjs +83 -0
  72. package/test/unit-calcFitness.test.mjs +121 -0
  73. package/test/unit-calcLevelNumTrade.test.mjs +80 -0
  74. package/test/unit-estimComps.test.mjs +193 -0
  75. package/test/unit-estimFinder.test.mjs +184 -0
  76. package/test/unit-estimKeys.test.mjs +260 -0
  77. package/test/unit-estimPicks.test.mjs +241 -0
  78. package/test/unit-genSid.test.mjs +75 -0
  79. package/test/unit-genStrategyFileName.test.mjs +85 -0
  80. package/test/unit-genTid.test.mjs +72 -0
  81. package/test/unit-p2r.test.mjs +51 -0
  82. package/test/unit-readStrategies.test.mjs +258 -0
  83. package/test/unit-setup.mjs +119 -0
  84. package/toolg/addVersion.mjs +4 -0
  85. package/toolg/cleanFolder.mjs +5 -0
  86. package/toolg/gDistRollup.mjs +37 -0
  87. package/toolg/gDocsExams.mjs +48 -0
  88. package/toolg/modifyReadme.mjs +4 -0
@@ -0,0 +1,4932 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+
5
+ <meta charset="utf-8">
6
+ <title>Global - 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">Global</h1>
39
+
40
+
41
+
42
+
43
+
44
+
45
+
46
+ <section>
47
+
48
+ <header>
49
+
50
+ <h2>
51
+
52
+
53
+
54
+ </h2>
55
+
56
+
57
+ </header>
58
+
59
+ <article>
60
+
61
+ <div class="container-overview">
62
+
63
+
64
+
65
+ <dl class="details">
66
+
67
+
68
+
69
+
70
+
71
+
72
+
73
+
74
+
75
+
76
+
77
+
78
+
79
+
80
+
81
+
82
+
83
+
84
+
85
+
86
+
87
+
88
+
89
+
90
+
91
+
92
+
93
+
94
+
95
+
96
+
97
+
98
+
99
+ </dl>
100
+
101
+
102
+
103
+
104
+
105
+
106
+
107
+
108
+ </div>
109
+
110
+
111
+
112
+
113
+
114
+
115
+
116
+
117
+
118
+
119
+
120
+
121
+
122
+
123
+
124
+ <h3 class="subsection-title">Members</h3>
125
+
126
+
127
+
128
+ <h4 class="name" id="cont"><span class="type-signature type-signature-constant">(constant) </span>cont<span class="type-signature"> :Object</span></h4>
129
+
130
+
131
+
132
+
133
+
134
+ <dl class="details">
135
+
136
+ <dt class="tag-description">Description:</dt>
137
+ <dd class="tag-description"><ul class="dummy"><li><p>共用常數</p>
138
+ <p>dlmSeps為tid與sid內各段(mode與各key或各cond)之分隔字串
139
+ dlmPkgs為策略檔名內各段(tid、levelNumTrade、rEquivalentCumuProfitOrLossFinalNormYear)之分隔字串</p></li></ul></dd>
140
+
141
+
142
+
143
+ <dt class="tag-source">Source:</dt>
144
+ <dd class="tag-source"><ul class="dummy"><li>
145
+ <a href="cont.mjs.html">cont.mjs</a>, <a href="cont.mjs.html#line1">line 1</a>
146
+ </li></ul></dd>
147
+
148
+
149
+
150
+
151
+
152
+
153
+
154
+
155
+
156
+
157
+
158
+
159
+
160
+
161
+
162
+
163
+
164
+
165
+
166
+
167
+
168
+
169
+
170
+
171
+
172
+
173
+
174
+
175
+
176
+
177
+
178
+ </dl>
179
+
180
+
181
+
182
+
183
+
184
+ <div class="description usertext">
185
+ <p>共用常數</p>
186
+ <p>dlmSeps為tid與sid內各段(mode與各key或各cond)之分隔字串
187
+ dlmPkgs為策略檔名內各段(tid、levelNumTrade、rEquivalentCumuProfitOrLossFinalNormYear)之分隔字串</p>
188
+ </div>
189
+
190
+
191
+
192
+ <h5 class="h5-types">Type:</h5>
193
+ <ul>
194
+ <li>
195
+
196
+ <span class="param-type">Object</span>
197
+
198
+
199
+
200
+ </li>
201
+ </ul>
202
+
203
+
204
+
205
+
206
+
207
+ <h5 class="h5-examples">Example</h5>
208
+
209
+ <pre class="prettyprint"><code>console.log(cont)
210
+ // => { dlmSeps: ' ║ ', dlmPkgs: ' ⊙ ' }</code></pre>
211
+
212
+
213
+
214
+
215
+
216
+
217
+
218
+ <h3 class="subsection-title">Methods</h3>
219
+
220
+
221
+
222
+
223
+
224
+
225
+ <h4 class="name" id="calcFitness"><span class="type-signature"></span>calcFitness<span class="signature">(settings, summary)</span><span class="type-signature"> &rarr; {Number}</span></h4>
226
+
227
+
228
+
229
+
230
+
231
+
232
+ <dl class="details">
233
+
234
+ <dt class="tag-description">Description:</dt>
235
+ <dd class="tag-description"><ul class="dummy"><li><p>計算策略適應值fitness</p>
236
+ <p>供最佳化求解使用之目標函數值,數值越小代表策略越佳
237
+ 由勝率與最終等效年化盈虧兩者組成: 勝率rWin限縮至[0,1],等效年化盈虧rEquivalentCumuProfitOrLossFinalNormYear限縮至[0,0.5]再正規化至[0,1],兩者皆轉為越小越好後,以權重2與1加權求和,故無懲罰時fitness落於[0,3]
238
+ 交易次數為0時加上懲罰值1000000,最終累計盈虧金額(summary.uEquityFinal-settings.uIni)小於等於0時再加上懲罰值1000000,故兩者皆觸發時可達2000000以上</p>
239
+ <p>Unit Test: <a href="https://github.com/yuda-lyu/w-trade-solve/blob/master/test/unit-calcFitness.test.mjs">Github</a></p></li></ul></dd>
240
+
241
+
242
+
243
+ <dt class="tag-source">Source:</dt>
244
+ <dd class="tag-source"><ul class="dummy"><li>
245
+ <a href="calcFitness.mjs.html">calcFitness.mjs</a>, <a href="calcFitness.mjs.html#line42">line 42</a>
246
+ </li></ul></dd>
247
+
248
+
249
+
250
+
251
+
252
+
253
+
254
+
255
+
256
+
257
+
258
+
259
+
260
+
261
+
262
+
263
+
264
+
265
+
266
+
267
+
268
+
269
+
270
+
271
+
272
+
273
+
274
+
275
+
276
+
277
+
278
+ </dl>
279
+
280
+
281
+
282
+
283
+
284
+
285
+
286
+
287
+
288
+
289
+
290
+ <h5 class="h5-examples">Example</h5>
291
+
292
+ <pre class="prettyprint"><code>let settings = { uIni: 1000 }
293
+
294
+ //勝率60%, 等效年化盈虧25%(正規化後0.5), fitness = 2*(1-0.6) + 1*(1-0.5) = 1.3
295
+ let summary = {
296
+ numTrade: 30,
297
+ uEquityFinal: 1200,
298
+ rWin: '60%',
299
+ rEquivalentCumuProfitOrLossFinalNormYear: '25%',
300
+ }
301
+ console.log(calcFitness(settings, summary))
302
+ // => 1.3
303
+
304
+ //無交易且無獲利時, 兩懲罰值皆觸發
305
+ let summaryNone = {
306
+ numTrade: 0,
307
+ uEquityFinal: 1000,
308
+ rWin: '',
309
+ rEquivalentCumuProfitOrLossFinalNormYear: '',
310
+ }
311
+ console.log(calcFitness(settings, summaryNone))
312
+ // => 2000003</code></pre>
313
+
314
+
315
+
316
+
317
+ <h5 class="h5-parameters">Parameters:</h5>
318
+
319
+
320
+ <table class="params">
321
+ <thead>
322
+ <tr>
323
+
324
+ <th>Name</th>
325
+
326
+
327
+ <th>Type</th>
328
+
329
+
330
+
331
+
332
+
333
+ <th class="last">Description</th>
334
+ </tr>
335
+ </thead>
336
+
337
+ <tbody>
338
+
339
+
340
+ <tr>
341
+
342
+ <td class="name"><code>settings</code></td>
343
+
344
+
345
+ <td class="type">
346
+
347
+
348
+ <span class="param-type">Object</span>
349
+
350
+
351
+
352
+
353
+ </td>
354
+
355
+
356
+
357
+
358
+
359
+ <td class="description last"><p>輸入策略設定物件,需含uIni(初始資金)欄位</p></td>
360
+ </tr>
361
+
362
+
363
+
364
+ <tr>
365
+
366
+ <td class="name"><code>summary</code></td>
367
+
368
+
369
+ <td class="type">
370
+
371
+
372
+ <span class="param-type">Object</span>
373
+
374
+
375
+
376
+
377
+ </td>
378
+
379
+
380
+
381
+
382
+
383
+ <td class="description last"><p>輸入回測統計摘要物件,需含numTrade(交易次數)、uEquityFinal(最終權益金額)、rWin(勝率百分比字串)、rEquivalentCumuProfitOrLossFinalNormYear(最終等效年化盈虧百分比字串)欄位</p></td>
384
+ </tr>
385
+
386
+
387
+ </tbody>
388
+ </table>
389
+
390
+
391
+
392
+
393
+
394
+
395
+
396
+
397
+
398
+
399
+
400
+
401
+
402
+
403
+
404
+
405
+ <h5 class="h5-returns">Returns:</h5>
406
+
407
+
408
+ <div class="param-desc">
409
+ <p>回傳適應值數值,越小代表策略越佳</p>
410
+ </div>
411
+
412
+
413
+
414
+ <dl class="param-type">
415
+ <dt>
416
+ Type
417
+ </dt>
418
+ <dd>
419
+
420
+ <span class="param-type">Number</span>
421
+
422
+
423
+
424
+ </dd>
425
+ </dl>
426
+
427
+
428
+
429
+
430
+
431
+
432
+
433
+
434
+
435
+
436
+ <h4 class="name" id="calcLevelNumTrade"><span class="type-signature"></span>calcLevelNumTrade<span class="signature">(numTrade)</span><span class="type-signature"> &rarr; {Number}</span></h4>
437
+
438
+
439
+
440
+
441
+
442
+
443
+ <dl class="details">
444
+
445
+ <dt class="tag-description">Description:</dt>
446
+ <dd class="tag-description"><ul class="dummy"><li><p>計算交易次數所屬級距代碼levelNumTrade</p>
447
+ <p>交易次數過少之策略統計意義不足,過多則屬高頻,故以級距分群,使不同交易次數規模之策略各自保留最佳者
448
+ 級距對應為: &lt;=0為0,1-5為1,6-9為2,10-24為11,25-49為12,50-74為13,75-99為14,100-249為101,250-499為102,500-749為103,750-999為104,1000-1999為1001,2000-2999為1002,3000-3999為1003,4000-4999為1004,&gt;=5000為100
449
+ numTrade非數值時throw</p>
450
+ <p>Unit Test: <a href="https://github.com/yuda-lyu/w-trade-solve/blob/master/test/unit-calcLevelNumTrade.test.mjs">Github</a></p></li></ul></dd>
451
+
452
+
453
+
454
+ <dt class="tag-source">Source:</dt>
455
+ <dd class="tag-source"><ul class="dummy"><li>
456
+ <a href="calcLevelNumTrade.mjs.html">calcLevelNumTrade.mjs</a>, <a href="calcLevelNumTrade.mjs.html#line31">line 31</a>
457
+ </li></ul></dd>
458
+
459
+
460
+
461
+
462
+
463
+
464
+
465
+
466
+
467
+
468
+
469
+
470
+
471
+
472
+
473
+
474
+
475
+
476
+
477
+
478
+
479
+
480
+
481
+
482
+
483
+
484
+
485
+
486
+
487
+
488
+
489
+ </dl>
490
+
491
+
492
+
493
+
494
+
495
+
496
+
497
+
498
+
499
+
500
+
501
+ <h5 class="h5-examples">Example</h5>
502
+
503
+ <pre class="prettyprint"><code>console.log(calcLevelNumTrade(0))
504
+ // => 0
505
+
506
+ console.log(calcLevelNumTrade(3))
507
+ // => 1
508
+
509
+ console.log(calcLevelNumTrade(30))
510
+ // => 12
511
+
512
+ console.log(calcLevelNumTrade(8000))
513
+ // => 100</code></pre>
514
+
515
+
516
+
517
+
518
+ <h5 class="h5-parameters">Parameters:</h5>
519
+
520
+
521
+ <table class="params">
522
+ <thead>
523
+ <tr>
524
+
525
+ <th>Name</th>
526
+
527
+
528
+ <th>Type</th>
529
+
530
+
531
+
532
+
533
+
534
+ <th class="last">Description</th>
535
+ </tr>
536
+ </thead>
537
+
538
+ <tbody>
539
+
540
+
541
+ <tr>
542
+
543
+ <td class="name"><code>numTrade</code></td>
544
+
545
+
546
+ <td class="type">
547
+
548
+
549
+ <span class="param-type">Number</span>
550
+
551
+
552
+
553
+
554
+ </td>
555
+
556
+
557
+
558
+
559
+
560
+ <td class="description last"><p>輸入交易次數數值</p></td>
561
+ </tr>
562
+
563
+
564
+ </tbody>
565
+ </table>
566
+
567
+
568
+
569
+
570
+
571
+
572
+
573
+
574
+
575
+
576
+
577
+
578
+
579
+
580
+
581
+
582
+ <h5 class="h5-returns">Returns:</h5>
583
+
584
+
585
+ <div class="param-desc">
586
+ <p>回傳級距代碼數值</p>
587
+ </div>
588
+
589
+
590
+
591
+ <dl class="param-type">
592
+ <dt>
593
+ Type
594
+ </dt>
595
+ <dd>
596
+
597
+ <span class="param-type">Number</span>
598
+
599
+
600
+
601
+ </dd>
602
+ </dl>
603
+
604
+
605
+
606
+
607
+
608
+
609
+
610
+
611
+
612
+
613
+ <h4 class="name" id="estimComps"><span class="type-signature type-signature-async">(async) </span>estimComps<span class="signature">(ott, st, fdOhlc, fdParam, timeStart, timeEnd, mode, comps, fdData, opt<span class="signature-attributes">opt</span>)</span><span class="type-signature"> &rarr; {Promise}</span></h4>
614
+
615
+
616
+
617
+
618
+
619
+
620
+ <dl class="details">
621
+
622
+ <dt class="tag-description">Description:</dt>
623
+ <dd class="tag-description"><ul class="dummy"><li><p>依指標組成comps隨機挑選keys,再率定各key之門檻與止盈止損,求解最佳策略</p>
624
+ <p>comps為以逗號分隔之3個數字字串,依序代表由一般類(keysNorm)、指數類(keysIndex)與成交量類(keysVolumn)各隨機挑選之key個數,例如'2,1,0'代表挑2個一般類、1個指數類與0個成交量類
625
+ 各類皆以randomIntsNdpRange不重複隨機取樣,故同一comps每次執行所挑之keys不同
626
+ comps非3段時throw,其餘檢核與分類邏輯同estimPicks</p>
627
+ <p>Unit Test: <a href="https://github.com/yuda-lyu/w-trade-solve/blob/master/test/unit-estimComps.test.mjs">Github</a></p></li></ul></dd>
628
+
629
+
630
+
631
+ <dt class="tag-source">Source:</dt>
632
+ <dd class="tag-source"><ul class="dummy"><li>
633
+ <a href="estimComps.mjs.html">estimComps.mjs</a>, <a href="estimComps.mjs.html#line45">line 45</a>
634
+ </li></ul></dd>
635
+
636
+
637
+
638
+
639
+
640
+
641
+
642
+
643
+
644
+
645
+
646
+
647
+
648
+
649
+
650
+
651
+
652
+
653
+
654
+
655
+
656
+
657
+
658
+
659
+
660
+
661
+
662
+
663
+
664
+
665
+
666
+ </dl>
667
+
668
+
669
+
670
+
671
+
672
+
673
+
674
+
675
+
676
+
677
+
678
+ <h5 class="h5-examples">Example</h5>
679
+
680
+ <pre class="prettyprint"><code>import ott from './src/ott.mjs'
681
+
682
+ let st = {
683
+ btc4hr: { name: 'btc', symbol: 'BTCUSDT', interval: '4hr' },
684
+ }
685
+
686
+ //comps='2,1,0', 挑2種一般類、1種指數類與0種成交量類
687
+ await estimComps(ott, st, './data/ohlc', './data/param', '2022-07-01T00:00:00', '2025-04-08T00:00:00', 'long', '2,1,0', './data/strategy', {
688
+ keySettings: 'btc4hr',
689
+ })</code></pre>
690
+
691
+
692
+
693
+
694
+ <h5 class="h5-parameters">Parameters:</h5>
695
+
696
+
697
+ <table class="params">
698
+ <thead>
699
+ <tr>
700
+
701
+ <th>Name</th>
702
+
703
+
704
+ <th>Type</th>
705
+
706
+
707
+ <th>Attributes</th>
708
+
709
+
710
+
711
+ <th>Default</th>
712
+
713
+
714
+ <th class="last">Description</th>
715
+ </tr>
716
+ </thead>
717
+
718
+ <tbody>
719
+
720
+
721
+ <tr>
722
+
723
+ <td class="name"><code>ott</code></td>
724
+
725
+
726
+ <td class="type">
727
+
728
+
729
+ <span class="param-type">function</span>
730
+
731
+
732
+
733
+
734
+ </td>
735
+
736
+
737
+ <td class="attributes">
738
+
739
+
740
+
741
+
742
+
743
+ </td>
744
+
745
+
746
+
747
+ <td class="default">
748
+
749
+ </td>
750
+
751
+
752
+ <td class="description last"><p>輸入時區時間函數,傳入時間字串回傳dayjs時間物件,可用src/ott.mjs</p></td>
753
+ </tr>
754
+
755
+
756
+
757
+ <tr>
758
+
759
+ <td class="name"><code>st</code></td>
760
+
761
+
762
+ <td class="type">
763
+
764
+
765
+ <span class="param-type">Object</span>
766
+
767
+
768
+
769
+
770
+ </td>
771
+
772
+
773
+ <td class="attributes">
774
+
775
+
776
+
777
+
778
+
779
+ </td>
780
+
781
+
782
+
783
+ <td class="default">
784
+
785
+ </td>
786
+
787
+
788
+ <td class="description last"><p>輸入設定物件,需可由opt.keySettings取得name、symbol與interval欄位</p></td>
789
+ </tr>
790
+
791
+
792
+
793
+ <tr>
794
+
795
+ <td class="name"><code>fdOhlc</code></td>
796
+
797
+
798
+ <td class="type">
799
+
800
+
801
+ <span class="param-type">String</span>
802
+
803
+
804
+
805
+
806
+ </td>
807
+
808
+
809
+ <td class="attributes">
810
+
811
+
812
+
813
+
814
+
815
+ </td>
816
+
817
+
818
+
819
+ <td class="default">
820
+
821
+ </td>
822
+
823
+
824
+ <td class="description last"><p>輸入儲存K線(ohlc)序列資料夾字串</p></td>
825
+ </tr>
826
+
827
+
828
+
829
+ <tr>
830
+
831
+ <td class="name"><code>fdParam</code></td>
832
+
833
+
834
+ <td class="type">
835
+
836
+
837
+ <span class="param-type">String</span>
838
+
839
+
840
+
841
+
842
+ </td>
843
+
844
+
845
+ <td class="attributes">
846
+
847
+
848
+
849
+
850
+
851
+ </td>
852
+
853
+
854
+
855
+ <td class="default">
856
+
857
+ </td>
858
+
859
+
860
+ <td class="description last"><p>輸入儲存指標參數序列資料夾字串</p></td>
861
+ </tr>
862
+
863
+
864
+
865
+ <tr>
866
+
867
+ <td class="name"><code>timeStart</code></td>
868
+
869
+
870
+ <td class="type">
871
+
872
+
873
+ <span class="param-type">String</span>
874
+
875
+
876
+
877
+
878
+ </td>
879
+
880
+
881
+ <td class="attributes">
882
+
883
+
884
+
885
+
886
+
887
+ </td>
888
+
889
+
890
+
891
+ <td class="default">
892
+
893
+ </td>
894
+
895
+
896
+ <td class="description last"><p>輸入回測起始時間字串,格式'YYYY-MM-DDTHH:mm:ss'</p></td>
897
+ </tr>
898
+
899
+
900
+
901
+ <tr>
902
+
903
+ <td class="name"><code>timeEnd</code></td>
904
+
905
+
906
+ <td class="type">
907
+
908
+
909
+ <span class="param-type">String</span>
910
+
911
+
912
+
913
+
914
+ </td>
915
+
916
+
917
+ <td class="attributes">
918
+
919
+
920
+
921
+
922
+
923
+ </td>
924
+
925
+
926
+
927
+ <td class="default">
928
+
929
+ </td>
930
+
931
+
932
+ <td class="description last"><p>輸入回測結束時間字串,格式'YYYY-MM-DDTHH:mm:ss'</p></td>
933
+ </tr>
934
+
935
+
936
+
937
+ <tr>
938
+
939
+ <td class="name"><code>mode</code></td>
940
+
941
+
942
+ <td class="type">
943
+
944
+
945
+ <span class="param-type">String</span>
946
+
947
+
948
+
949
+
950
+ </td>
951
+
952
+
953
+ <td class="attributes">
954
+
955
+
956
+
957
+
958
+
959
+ </td>
960
+
961
+
962
+
963
+ <td class="default">
964
+
965
+ </td>
966
+
967
+
968
+ <td class="description last"><p>輸入交易方向字串,可選'long'或'short'</p></td>
969
+ </tr>
970
+
971
+
972
+
973
+ <tr>
974
+
975
+ <td class="name"><code>comps</code></td>
976
+
977
+
978
+ <td class="type">
979
+
980
+
981
+ <span class="param-type">String</span>
982
+
983
+
984
+
985
+
986
+ </td>
987
+
988
+
989
+ <td class="attributes">
990
+
991
+
992
+
993
+
994
+
995
+ </td>
996
+
997
+
998
+
999
+ <td class="default">
1000
+
1001
+ </td>
1002
+
1003
+
1004
+ <td class="description last"><p>輸入指標組成字串,為逗號分隔之3個數字,例如'2,1,0'</p></td>
1005
+ </tr>
1006
+
1007
+
1008
+
1009
+ <tr>
1010
+
1011
+ <td class="name"><code>fdData</code></td>
1012
+
1013
+
1014
+ <td class="type">
1015
+
1016
+
1017
+ <span class="param-type">String</span>
1018
+
1019
+
1020
+
1021
+
1022
+ </td>
1023
+
1024
+
1025
+ <td class="attributes">
1026
+
1027
+
1028
+
1029
+
1030
+
1031
+ </td>
1032
+
1033
+
1034
+
1035
+ <td class="default">
1036
+
1037
+ </td>
1038
+
1039
+
1040
+ <td class="description last"><p>輸入儲存策略資料夾字串,不存在時自動建立</p></td>
1041
+ </tr>
1042
+
1043
+
1044
+
1045
+ <tr>
1046
+
1047
+ <td class="name"><code>opt</code></td>
1048
+
1049
+
1050
+ <td class="type">
1051
+
1052
+
1053
+ <span class="param-type">Object</span>
1054
+
1055
+
1056
+
1057
+
1058
+ </td>
1059
+
1060
+
1061
+ <td class="attributes">
1062
+
1063
+ &lt;optional><br>
1064
+
1065
+
1066
+
1067
+
1068
+
1069
+ </td>
1070
+
1071
+
1072
+
1073
+ <td class="default">
1074
+
1075
+ <code>{}</code>
1076
+
1077
+ </td>
1078
+
1079
+
1080
+ <td class="description last"><p>輸入設定物件,預設{},全部欄位皆傳遞至estimPicks</p></td>
1081
+ </tr>
1082
+
1083
+
1084
+ </tbody>
1085
+ </table>
1086
+
1087
+
1088
+
1089
+
1090
+
1091
+
1092
+
1093
+
1094
+
1095
+
1096
+
1097
+
1098
+
1099
+
1100
+
1101
+
1102
+ <h5 class="h5-returns">Returns:</h5>
1103
+
1104
+
1105
+ <div class="param-desc">
1106
+ <p>回傳Promise,resolve為undefined</p>
1107
+ </div>
1108
+
1109
+
1110
+
1111
+ <dl class="param-type">
1112
+ <dt>
1113
+ Type
1114
+ </dt>
1115
+ <dd>
1116
+
1117
+ <span class="param-type">Promise</span>
1118
+
1119
+
1120
+
1121
+ </dd>
1122
+ </dl>
1123
+
1124
+
1125
+
1126
+
1127
+
1128
+
1129
+
1130
+
1131
+
1132
+
1133
+ <h4 class="name" id="estimFinder"><span class="type-signature type-signature-async">(async) </span>estimFinder<span class="signature">(ott, st, fdOhlc, fdParam, fdData, opt<span class="signature-attributes">opt</span>)</span><span class="type-signature"> &rarr; {Promise}</span></h4>
1134
+
1135
+
1136
+
1137
+
1138
+
1139
+
1140
+ <dl class="details">
1141
+
1142
+ <dt class="tag-description">Description:</dt>
1143
+ <dd class="tag-description"><ul class="dummy"><li><p>以隨機之交易方向與指標組成求解最佳策略</p>
1144
+ <p>供批次探索用之進入點,未指定時mode由'long'與'short'隨機取一,comps由18種預設組成隨機取一,故重複呼叫即可隨機探索各種策略
1145
+ 未指定時timeStart預設為'2022-07-01T00:00:00',timeEnd則依mode給予不同值: 做多為'2025-04-08T00:00:00'(須涵蓋暴跌數據),做空為'2025-10-06T00:00:00'(須涵蓋暴漲數據),藉此提高率定難度
1146
+ fdOhlc、fdParam與fdData無效時throw</p>
1147
+ <p>Unit Test: <a href="https://github.com/yuda-lyu/w-trade-solve/blob/master/test/unit-estimFinder.test.mjs">Github</a></p></li></ul></dd>
1148
+
1149
+
1150
+
1151
+ <dt class="tag-source">Source:</dt>
1152
+ <dd class="tag-source"><ul class="dummy"><li>
1153
+ <a href="estimFinder.mjs.html">estimFinder.mjs</a>, <a href="estimFinder.mjs.html#line41">line 41</a>
1154
+ </li></ul></dd>
1155
+
1156
+
1157
+
1158
+
1159
+
1160
+
1161
+
1162
+
1163
+
1164
+
1165
+
1166
+
1167
+
1168
+
1169
+
1170
+
1171
+
1172
+
1173
+
1174
+
1175
+
1176
+
1177
+
1178
+
1179
+
1180
+
1181
+
1182
+
1183
+
1184
+
1185
+
1186
+ </dl>
1187
+
1188
+
1189
+
1190
+
1191
+
1192
+
1193
+
1194
+
1195
+
1196
+
1197
+
1198
+ <h5 class="h5-examples">Example</h5>
1199
+
1200
+ <pre class="prettyprint"><code>import ott from './src/ott.mjs'
1201
+
1202
+ let st = {
1203
+ btc4hr: { name: 'btc', symbol: 'BTCUSDT', interval: '4hr' },
1204
+ }
1205
+
1206
+ //mode與comps皆隨機, 適合以迴圈重複呼叫批次探索
1207
+ await estimFinder(ott, st, './data/ohlc', './data/param', './data/strategy', {
1208
+ keySettings: 'btc4hr',
1209
+ })</code></pre>
1210
+
1211
+
1212
+
1213
+
1214
+ <h5 class="h5-parameters">Parameters:</h5>
1215
+
1216
+
1217
+ <table class="params">
1218
+ <thead>
1219
+ <tr>
1220
+
1221
+ <th>Name</th>
1222
+
1223
+
1224
+ <th>Type</th>
1225
+
1226
+
1227
+ <th>Attributes</th>
1228
+
1229
+
1230
+
1231
+ <th>Default</th>
1232
+
1233
+
1234
+ <th class="last">Description</th>
1235
+ </tr>
1236
+ </thead>
1237
+
1238
+ <tbody>
1239
+
1240
+
1241
+ <tr>
1242
+
1243
+ <td class="name"><code>ott</code></td>
1244
+
1245
+
1246
+ <td class="type">
1247
+
1248
+
1249
+ <span class="param-type">function</span>
1250
+
1251
+
1252
+
1253
+
1254
+ </td>
1255
+
1256
+
1257
+ <td class="attributes">
1258
+
1259
+
1260
+
1261
+
1262
+
1263
+ </td>
1264
+
1265
+
1266
+
1267
+ <td class="default">
1268
+
1269
+ </td>
1270
+
1271
+
1272
+ <td class="description last"><p>輸入時區時間函數,傳入時間字串回傳dayjs時間物件,可用src/ott.mjs</p></td>
1273
+ </tr>
1274
+
1275
+
1276
+
1277
+ <tr>
1278
+
1279
+ <td class="name"><code>st</code></td>
1280
+
1281
+
1282
+ <td class="type">
1283
+
1284
+
1285
+ <span class="param-type">Object</span>
1286
+
1287
+
1288
+
1289
+
1290
+ </td>
1291
+
1292
+
1293
+ <td class="attributes">
1294
+
1295
+
1296
+
1297
+
1298
+
1299
+ </td>
1300
+
1301
+
1302
+
1303
+ <td class="default">
1304
+
1305
+ </td>
1306
+
1307
+
1308
+ <td class="description last"><p>輸入設定物件,需可由opt.keySettings取得name、symbol與interval欄位</p></td>
1309
+ </tr>
1310
+
1311
+
1312
+
1313
+ <tr>
1314
+
1315
+ <td class="name"><code>fdOhlc</code></td>
1316
+
1317
+
1318
+ <td class="type">
1319
+
1320
+
1321
+ <span class="param-type">String</span>
1322
+
1323
+
1324
+
1325
+
1326
+ </td>
1327
+
1328
+
1329
+ <td class="attributes">
1330
+
1331
+
1332
+
1333
+
1334
+
1335
+ </td>
1336
+
1337
+
1338
+
1339
+ <td class="default">
1340
+
1341
+ </td>
1342
+
1343
+
1344
+ <td class="description last"><p>輸入儲存K線(ohlc)序列資料夾字串</p></td>
1345
+ </tr>
1346
+
1347
+
1348
+
1349
+ <tr>
1350
+
1351
+ <td class="name"><code>fdParam</code></td>
1352
+
1353
+
1354
+ <td class="type">
1355
+
1356
+
1357
+ <span class="param-type">String</span>
1358
+
1359
+
1360
+
1361
+
1362
+ </td>
1363
+
1364
+
1365
+ <td class="attributes">
1366
+
1367
+
1368
+
1369
+
1370
+
1371
+ </td>
1372
+
1373
+
1374
+
1375
+ <td class="default">
1376
+
1377
+ </td>
1378
+
1379
+
1380
+ <td class="description last"><p>輸入儲存指標參數序列資料夾字串</p></td>
1381
+ </tr>
1382
+
1383
+
1384
+
1385
+ <tr>
1386
+
1387
+ <td class="name"><code>fdData</code></td>
1388
+
1389
+
1390
+ <td class="type">
1391
+
1392
+
1393
+ <span class="param-type">String</span>
1394
+
1395
+
1396
+
1397
+
1398
+ </td>
1399
+
1400
+
1401
+ <td class="attributes">
1402
+
1403
+
1404
+
1405
+
1406
+
1407
+ </td>
1408
+
1409
+
1410
+
1411
+ <td class="default">
1412
+
1413
+ </td>
1414
+
1415
+
1416
+ <td class="description last"><p>輸入儲存策略資料夾字串,不存在時自動建立</p></td>
1417
+ </tr>
1418
+
1419
+
1420
+
1421
+ <tr>
1422
+
1423
+ <td class="name"><code>opt</code></td>
1424
+
1425
+
1426
+ <td class="type">
1427
+
1428
+
1429
+ <span class="param-type">Object</span>
1430
+
1431
+
1432
+
1433
+
1434
+ </td>
1435
+
1436
+
1437
+ <td class="attributes">
1438
+
1439
+ &lt;optional><br>
1440
+
1441
+
1442
+
1443
+
1444
+
1445
+ </td>
1446
+
1447
+
1448
+
1449
+ <td class="default">
1450
+
1451
+ <code>{}</code>
1452
+
1453
+ </td>
1454
+
1455
+
1456
+ <td class="description last"><p>輸入設定物件,預設{},全部欄位皆傳遞至estimComps</p>
1457
+ <h6>Properties</h6>
1458
+
1459
+
1460
+ <table class="params">
1461
+ <thead>
1462
+ <tr>
1463
+
1464
+ <th>Name</th>
1465
+
1466
+
1467
+ <th>Type</th>
1468
+
1469
+
1470
+ <th>Attributes</th>
1471
+
1472
+
1473
+
1474
+ <th>Default</th>
1475
+
1476
+
1477
+ <th class="last">Description</th>
1478
+ </tr>
1479
+ </thead>
1480
+
1481
+ <tbody>
1482
+
1483
+
1484
+ <tr>
1485
+
1486
+ <td class="name"><code>mode</code></td>
1487
+
1488
+
1489
+ <td class="type">
1490
+
1491
+
1492
+ <span class="param-type">String</span>
1493
+
1494
+
1495
+
1496
+
1497
+ </td>
1498
+
1499
+
1500
+ <td class="attributes">
1501
+
1502
+ &lt;optional><br>
1503
+
1504
+
1505
+
1506
+
1507
+
1508
+ </td>
1509
+
1510
+
1511
+
1512
+ <td class="default">
1513
+
1514
+ <code>''</code>
1515
+
1516
+ </td>
1517
+
1518
+
1519
+ <td class="description last"><p>輸入交易方向字串,可選'long'或'short',未給予時隨機取一,預設''</p></td>
1520
+ </tr>
1521
+
1522
+
1523
+
1524
+ <tr>
1525
+
1526
+ <td class="name"><code>timeStart</code></td>
1527
+
1528
+
1529
+ <td class="type">
1530
+
1531
+
1532
+ <span class="param-type">String</span>
1533
+
1534
+
1535
+
1536
+
1537
+ </td>
1538
+
1539
+
1540
+ <td class="attributes">
1541
+
1542
+ &lt;optional><br>
1543
+
1544
+
1545
+
1546
+
1547
+
1548
+ </td>
1549
+
1550
+
1551
+
1552
+ <td class="default">
1553
+
1554
+ <code>'2022-07-01T00:00:00'</code>
1555
+
1556
+ </td>
1557
+
1558
+
1559
+ <td class="description last"><p>輸入回測起始時間字串,預設'2022-07-01T00:00:00'</p></td>
1560
+ </tr>
1561
+
1562
+
1563
+
1564
+ <tr>
1565
+
1566
+ <td class="name"><code>timeEnd</code></td>
1567
+
1568
+
1569
+ <td class="type">
1570
+
1571
+
1572
+ <span class="param-type">String</span>
1573
+
1574
+
1575
+
1576
+
1577
+ </td>
1578
+
1579
+
1580
+ <td class="attributes">
1581
+
1582
+ &lt;optional><br>
1583
+
1584
+
1585
+
1586
+
1587
+
1588
+ </td>
1589
+
1590
+
1591
+
1592
+ <td class="default">
1593
+
1594
+ <code>''</code>
1595
+
1596
+ </td>
1597
+
1598
+
1599
+ <td class="description last"><p>輸入回測結束時間字串,未給予時做多為'2025-04-08T00:00:00'、做空為'2025-10-06T00:00:00',預設''</p></td>
1600
+ </tr>
1601
+
1602
+
1603
+
1604
+ <tr>
1605
+
1606
+ <td class="name"><code>comps</code></td>
1607
+
1608
+
1609
+ <td class="type">
1610
+
1611
+
1612
+ <span class="param-type">String</span>
1613
+
1614
+
1615
+
1616
+
1617
+ </td>
1618
+
1619
+
1620
+ <td class="attributes">
1621
+
1622
+ &lt;optional><br>
1623
+
1624
+
1625
+
1626
+
1627
+
1628
+ </td>
1629
+
1630
+
1631
+
1632
+ <td class="default">
1633
+
1634
+ <code>''</code>
1635
+
1636
+ </td>
1637
+
1638
+
1639
+ <td class="description last"><p>輸入指標組成字串,例如'2,1,0',未給予時由18種預設組成隨機取一,預設''</p></td>
1640
+ </tr>
1641
+
1642
+
1643
+ </tbody>
1644
+ </table>
1645
+
1646
+ </td>
1647
+ </tr>
1648
+
1649
+
1650
+ </tbody>
1651
+ </table>
1652
+
1653
+
1654
+
1655
+
1656
+
1657
+
1658
+
1659
+
1660
+
1661
+
1662
+
1663
+
1664
+
1665
+
1666
+
1667
+
1668
+ <h5 class="h5-returns">Returns:</h5>
1669
+
1670
+
1671
+ <div class="param-desc">
1672
+ <p>回傳Promise,resolve為undefined</p>
1673
+ </div>
1674
+
1675
+
1676
+
1677
+ <dl class="param-type">
1678
+ <dt>
1679
+ Type
1680
+ </dt>
1681
+ <dd>
1682
+
1683
+ <span class="param-type">Promise</span>
1684
+
1685
+
1686
+
1687
+ </dd>
1688
+ </dl>
1689
+
1690
+
1691
+
1692
+
1693
+
1694
+
1695
+
1696
+
1697
+
1698
+
1699
+ <h4 class="name" id="estimKeys"><span class="type-signature type-signature-async">(async) </span>estimKeys<span class="signature">(ott, st, fdOhlc, fdParam, timeStart, timeEnd, mode, keys, fdData, opt<span class="signature-attributes">opt</span>)</span><span class="type-signature"> &rarr; {Promise}</span></h4>
1700
+
1701
+
1702
+
1703
+
1704
+
1705
+
1706
+ <dl class="details">
1707
+
1708
+ <dt class="tag-description">Description:</dt>
1709
+ <dd class="tag-description"><ul class="dummy"><li><p>針對指定keys率定各key之門檻與止盈止損,求解最佳策略</p>
1710
+ <p>設計變數為[止損比例, 止盈比例, ...各key之門檻],止損與止盈由opt.thsSl與opt.thsTp給予之百分比清單離散取值
1711
+ 各key門檻取值範圍為[-thLim,thLim]切為thLim<em>20段,並各自平移+vdir與-vdir(vdir=thLim</em>5)為兩組,使解值恆大於0代表'&gt;'條件、恆小於0代表'&lt;'條件,還原時再扣除平移值,故單一設計變數即同時涵蓋大於與小於兩種條件
1712
+ 以omlPSO粒子群最佳化求解,各次計算皆以w-trade-backtest之runStrategy回測並經calcFitness計算適應值
1713
+ 各次計算結果若同時滿足交易次數、勝率與最終等效年化盈虧三門檻,則以genStrategyFileName產生檔名存入fdData;同tid且同交易次數級距(tkid)已有策略時,僅於最終等效年化盈虧更佳時抽換,並刪除較差者
1714
+ fdOhlc、fdParam、timeStart、timeEnd、keys、fdData無效或mode非'long'或'short'時throw</p>
1715
+ <p>Unit Test: <a href="https://github.com/yuda-lyu/w-trade-solve/blob/master/test/unit-estimKeys.test.mjs">Github</a></p></li></ul></dd>
1716
+
1717
+
1718
+
1719
+ <dt class="tag-source">Source:</dt>
1720
+ <dd class="tag-source"><ul class="dummy"><li>
1721
+ <a href="estimKeys.mjs.html">estimKeys.mjs</a>, <a href="estimKeys.mjs.html#line86">line 86</a>
1722
+ </li></ul></dd>
1723
+
1724
+
1725
+
1726
+
1727
+
1728
+
1729
+
1730
+
1731
+
1732
+
1733
+
1734
+
1735
+
1736
+
1737
+
1738
+
1739
+
1740
+
1741
+
1742
+
1743
+
1744
+
1745
+
1746
+
1747
+
1748
+
1749
+
1750
+
1751
+
1752
+
1753
+
1754
+ </dl>
1755
+
1756
+
1757
+
1758
+
1759
+
1760
+
1761
+
1762
+
1763
+
1764
+
1765
+
1766
+ <h5 class="h5-examples">Example</h5>
1767
+
1768
+ <pre class="prettyprint"><code>import ott from './src/ott.mjs'
1769
+
1770
+ //st, 各設定以keySettings為鍵儲存
1771
+ let st = {
1772
+ btc4hr: {
1773
+ name: 'btc',
1774
+ symbol: 'BTCUSDT',
1775
+ interval: '4hr',
1776
+ },
1777
+ }
1778
+
1779
+ //keys, 待率定門檻之指標key, 各key於fdParam內須有對應之`${key}.json`
1780
+ let keys = ['btc_price_4hr_ma_1day']
1781
+
1782
+ let m = await estimKeys(ott, st, './data/ohlc', './data/param', '2022-07-01T00:00:00', '2025-04-08T00:00:00', 'long', keys, './data/strategy', {
1783
+ keySettings: 'btc4hr',
1784
+ thsTp: [1, 2, 3],
1785
+ thsSl: [1, 2, 3],
1786
+ useShowLog: true,
1787
+ })
1788
+ console.log(m.bestSolution.fitness)
1789
+ // => 1.0325</code></pre>
1790
+
1791
+
1792
+
1793
+
1794
+ <h5 class="h5-parameters">Parameters:</h5>
1795
+
1796
+
1797
+ <table class="params">
1798
+ <thead>
1799
+ <tr>
1800
+
1801
+ <th>Name</th>
1802
+
1803
+
1804
+ <th>Type</th>
1805
+
1806
+
1807
+ <th>Attributes</th>
1808
+
1809
+
1810
+
1811
+ <th>Default</th>
1812
+
1813
+
1814
+ <th class="last">Description</th>
1815
+ </tr>
1816
+ </thead>
1817
+
1818
+ <tbody>
1819
+
1820
+
1821
+ <tr>
1822
+
1823
+ <td class="name"><code>ott</code></td>
1824
+
1825
+
1826
+ <td class="type">
1827
+
1828
+
1829
+ <span class="param-type">function</span>
1830
+
1831
+
1832
+
1833
+
1834
+ </td>
1835
+
1836
+
1837
+ <td class="attributes">
1838
+
1839
+
1840
+
1841
+
1842
+
1843
+ </td>
1844
+
1845
+
1846
+
1847
+ <td class="default">
1848
+
1849
+ </td>
1850
+
1851
+
1852
+ <td class="description last"><p>輸入時區時間函數,傳入時間字串回傳dayjs時間物件,可用src/ott.mjs</p></td>
1853
+ </tr>
1854
+
1855
+
1856
+
1857
+ <tr>
1858
+
1859
+ <td class="name"><code>st</code></td>
1860
+
1861
+
1862
+ <td class="type">
1863
+
1864
+
1865
+ <span class="param-type">Object</span>
1866
+
1867
+
1868
+
1869
+
1870
+ </td>
1871
+
1872
+
1873
+ <td class="attributes">
1874
+
1875
+
1876
+
1877
+
1878
+
1879
+ </td>
1880
+
1881
+
1882
+
1883
+ <td class="default">
1884
+
1885
+ </td>
1886
+
1887
+
1888
+ <td class="description last"><p>輸入設定物件,需可由opt.keySettings取得name、symbol與interval欄位</p></td>
1889
+ </tr>
1890
+
1891
+
1892
+
1893
+ <tr>
1894
+
1895
+ <td class="name"><code>fdOhlc</code></td>
1896
+
1897
+
1898
+ <td class="type">
1899
+
1900
+
1901
+ <span class="param-type">String</span>
1902
+
1903
+
1904
+
1905
+
1906
+ </td>
1907
+
1908
+
1909
+ <td class="attributes">
1910
+
1911
+
1912
+
1913
+
1914
+
1915
+ </td>
1916
+
1917
+
1918
+
1919
+ <td class="default">
1920
+
1921
+ </td>
1922
+
1923
+
1924
+ <td class="description last"><p>輸入儲存K線(ohlc)序列資料夾字串</p></td>
1925
+ </tr>
1926
+
1927
+
1928
+
1929
+ <tr>
1930
+
1931
+ <td class="name"><code>fdParam</code></td>
1932
+
1933
+
1934
+ <td class="type">
1935
+
1936
+
1937
+ <span class="param-type">String</span>
1938
+
1939
+
1940
+
1941
+
1942
+ </td>
1943
+
1944
+
1945
+ <td class="attributes">
1946
+
1947
+
1948
+
1949
+
1950
+
1951
+ </td>
1952
+
1953
+
1954
+
1955
+ <td class="default">
1956
+
1957
+ </td>
1958
+
1959
+
1960
+ <td class="description last"><p>輸入儲存指標參數序列資料夾字串</p></td>
1961
+ </tr>
1962
+
1963
+
1964
+
1965
+ <tr>
1966
+
1967
+ <td class="name"><code>timeStart</code></td>
1968
+
1969
+
1970
+ <td class="type">
1971
+
1972
+
1973
+ <span class="param-type">String</span>
1974
+
1975
+
1976
+
1977
+
1978
+ </td>
1979
+
1980
+
1981
+ <td class="attributes">
1982
+
1983
+
1984
+
1985
+
1986
+
1987
+ </td>
1988
+
1989
+
1990
+
1991
+ <td class="default">
1992
+
1993
+ </td>
1994
+
1995
+
1996
+ <td class="description last"><p>輸入回測起始時間字串,格式'YYYY-MM-DDTHH:mm:ss'</p></td>
1997
+ </tr>
1998
+
1999
+
2000
+
2001
+ <tr>
2002
+
2003
+ <td class="name"><code>timeEnd</code></td>
2004
+
2005
+
2006
+ <td class="type">
2007
+
2008
+
2009
+ <span class="param-type">String</span>
2010
+
2011
+
2012
+
2013
+
2014
+ </td>
2015
+
2016
+
2017
+ <td class="attributes">
2018
+
2019
+
2020
+
2021
+
2022
+
2023
+ </td>
2024
+
2025
+
2026
+
2027
+ <td class="default">
2028
+
2029
+ </td>
2030
+
2031
+
2032
+ <td class="description last"><p>輸入回測結束時間字串,格式'YYYY-MM-DDTHH:mm:ss'</p></td>
2033
+ </tr>
2034
+
2035
+
2036
+
2037
+ <tr>
2038
+
2039
+ <td class="name"><code>mode</code></td>
2040
+
2041
+
2042
+ <td class="type">
2043
+
2044
+
2045
+ <span class="param-type">String</span>
2046
+
2047
+
2048
+
2049
+
2050
+ </td>
2051
+
2052
+
2053
+ <td class="attributes">
2054
+
2055
+
2056
+
2057
+
2058
+
2059
+ </td>
2060
+
2061
+
2062
+
2063
+ <td class="default">
2064
+
2065
+ </td>
2066
+
2067
+
2068
+ <td class="description last"><p>輸入交易方向字串,可選'long'或'short'</p></td>
2069
+ </tr>
2070
+
2071
+
2072
+
2073
+ <tr>
2074
+
2075
+ <td class="name"><code>keys</code></td>
2076
+
2077
+
2078
+ <td class="type">
2079
+
2080
+
2081
+ <span class="param-type">Array</span>
2082
+
2083
+
2084
+
2085
+
2086
+ </td>
2087
+
2088
+
2089
+ <td class="attributes">
2090
+
2091
+
2092
+
2093
+
2094
+
2095
+ </td>
2096
+
2097
+
2098
+
2099
+ <td class="default">
2100
+
2101
+ </td>
2102
+
2103
+
2104
+ <td class="description last"><p>輸入待率定門檻之指標key字串陣列</p></td>
2105
+ </tr>
2106
+
2107
+
2108
+
2109
+ <tr>
2110
+
2111
+ <td class="name"><code>fdData</code></td>
2112
+
2113
+
2114
+ <td class="type">
2115
+
2116
+
2117
+ <span class="param-type">String</span>
2118
+
2119
+
2120
+
2121
+
2122
+ </td>
2123
+
2124
+
2125
+ <td class="attributes">
2126
+
2127
+
2128
+
2129
+
2130
+
2131
+ </td>
2132
+
2133
+
2134
+
2135
+ <td class="default">
2136
+
2137
+ </td>
2138
+
2139
+
2140
+ <td class="description last"><p>輸入儲存策略資料夾字串,不存在時自動建立</p></td>
2141
+ </tr>
2142
+
2143
+
2144
+
2145
+ <tr>
2146
+
2147
+ <td class="name"><code>opt</code></td>
2148
+
2149
+
2150
+ <td class="type">
2151
+
2152
+
2153
+ <span class="param-type">Object</span>
2154
+
2155
+
2156
+
2157
+
2158
+ </td>
2159
+
2160
+
2161
+ <td class="attributes">
2162
+
2163
+ &lt;optional><br>
2164
+
2165
+
2166
+
2167
+
2168
+
2169
+ </td>
2170
+
2171
+
2172
+
2173
+ <td class="default">
2174
+
2175
+ <code>{}</code>
2176
+
2177
+ </td>
2178
+
2179
+
2180
+ <td class="description last"><p>輸入設定物件,預設{}</p>
2181
+ <h6>Properties</h6>
2182
+
2183
+
2184
+ <table class="params">
2185
+ <thead>
2186
+ <tr>
2187
+
2188
+ <th>Name</th>
2189
+
2190
+
2191
+ <th>Type</th>
2192
+
2193
+
2194
+ <th>Attributes</th>
2195
+
2196
+
2197
+
2198
+ <th>Default</th>
2199
+
2200
+
2201
+ <th class="last">Description</th>
2202
+ </tr>
2203
+ </thead>
2204
+
2205
+ <tbody>
2206
+
2207
+
2208
+ <tr>
2209
+
2210
+ <td class="name"><code>keySettings</code></td>
2211
+
2212
+
2213
+ <td class="type">
2214
+
2215
+
2216
+ <span class="param-type">String</span>
2217
+
2218
+
2219
+
2220
+
2221
+ </td>
2222
+
2223
+
2224
+ <td class="attributes">
2225
+
2226
+
2227
+
2228
+
2229
+
2230
+ </td>
2231
+
2232
+
2233
+
2234
+ <td class="default">
2235
+
2236
+ </td>
2237
+
2238
+
2239
+ <td class="description last"><p>輸入取用st內設定之鍵字串,例如'btc4hr'代表取用st.btc4hr.name、st.btc4hr.symbol與st.btc4hr.interval</p></td>
2240
+ </tr>
2241
+
2242
+
2243
+
2244
+ <tr>
2245
+
2246
+ <td class="name"><code>thsTp</code></td>
2247
+
2248
+
2249
+ <td class="type">
2250
+
2251
+
2252
+ <span class="param-type">Array</span>
2253
+
2254
+
2255
+
2256
+
2257
+ </td>
2258
+
2259
+
2260
+ <td class="attributes">
2261
+
2262
+ &lt;optional><br>
2263
+
2264
+
2265
+
2266
+
2267
+
2268
+ </td>
2269
+
2270
+
2271
+
2272
+ <td class="default">
2273
+
2274
+ <code>[1,2,3,4,5,6,7,8,9,10]</code>
2275
+
2276
+ </td>
2277
+
2278
+
2279
+ <td class="description last"><p>輸入止盈門檻百分比數值陣列,預設[1,2,3,4,5,6,7,8,9,10]</p></td>
2280
+ </tr>
2281
+
2282
+
2283
+
2284
+ <tr>
2285
+
2286
+ <td class="name"><code>thsSl</code></td>
2287
+
2288
+
2289
+ <td class="type">
2290
+
2291
+
2292
+ <span class="param-type">Array</span>
2293
+
2294
+
2295
+
2296
+
2297
+ </td>
2298
+
2299
+
2300
+ <td class="attributes">
2301
+
2302
+ &lt;optional><br>
2303
+
2304
+
2305
+
2306
+
2307
+
2308
+ </td>
2309
+
2310
+
2311
+
2312
+ <td class="default">
2313
+
2314
+ <code>[1,2,3,4,5,6,7,8,9,10]</code>
2315
+
2316
+ </td>
2317
+
2318
+
2319
+ <td class="description last"><p>輸入止損門檻百分比數值陣列,預設[1,2,3,4,5,6,7,8,9,10]</p></td>
2320
+ </tr>
2321
+
2322
+
2323
+
2324
+ <tr>
2325
+
2326
+ <td class="name"><code>thNumTrade</code></td>
2327
+
2328
+
2329
+ <td class="type">
2330
+
2331
+
2332
+ <span class="param-type">Number</span>
2333
+
2334
+
2335
+
2336
+
2337
+ </td>
2338
+
2339
+
2340
+ <td class="attributes">
2341
+
2342
+ &lt;optional><br>
2343
+
2344
+
2345
+
2346
+
2347
+
2348
+ </td>
2349
+
2350
+
2351
+
2352
+ <td class="default">
2353
+
2354
+ <code>1</code>
2355
+
2356
+ </td>
2357
+
2358
+
2359
+ <td class="description last"><p>輸入策略須儲存之最少交易次數數值,預設1</p></td>
2360
+ </tr>
2361
+
2362
+
2363
+
2364
+ <tr>
2365
+
2366
+ <td class="name"><code>thRWin</code></td>
2367
+
2368
+
2369
+ <td class="type">
2370
+
2371
+
2372
+ <span class="param-type">Number</span>
2373
+
2374
+
2375
+
2376
+
2377
+ </td>
2378
+
2379
+
2380
+ <td class="attributes">
2381
+
2382
+ &lt;optional><br>
2383
+
2384
+
2385
+
2386
+
2387
+
2388
+ </td>
2389
+
2390
+
2391
+
2392
+ <td class="default">
2393
+
2394
+ <code>0.5</code>
2395
+
2396
+ </td>
2397
+
2398
+
2399
+ <td class="description last"><p>輸入策略須儲存之最低勝率比例數值,預設0.5</p></td>
2400
+ </tr>
2401
+
2402
+
2403
+
2404
+ <tr>
2405
+
2406
+ <td class="name"><code>thREquivalentCumuProfitOrLossFinalNormYear</code></td>
2407
+
2408
+
2409
+ <td class="type">
2410
+
2411
+
2412
+ <span class="param-type">Number</span>
2413
+
2414
+
2415
+
2416
+
2417
+ </td>
2418
+
2419
+
2420
+ <td class="attributes">
2421
+
2422
+ &lt;optional><br>
2423
+
2424
+
2425
+
2426
+
2427
+
2428
+ </td>
2429
+
2430
+
2431
+
2432
+ <td class="default">
2433
+
2434
+ <code>0.15</code>
2435
+
2436
+ </td>
2437
+
2438
+
2439
+ <td class="description last"><p>輸入策略須儲存之最低最終等效年化盈虧比例數值,預設0.15</p></td>
2440
+ </tr>
2441
+
2442
+
2443
+
2444
+ <tr>
2445
+
2446
+ <td class="name"><code>useShowLog</code></td>
2447
+
2448
+
2449
+ <td class="type">
2450
+
2451
+
2452
+ <span class="param-type">Boolean</span>
2453
+
2454
+
2455
+
2456
+
2457
+ </td>
2458
+
2459
+
2460
+ <td class="attributes">
2461
+
2462
+ &lt;optional><br>
2463
+
2464
+
2465
+
2466
+
2467
+
2468
+ </td>
2469
+
2470
+
2471
+
2472
+ <td class="default">
2473
+
2474
+ <code>false</code>
2475
+
2476
+ </td>
2477
+
2478
+
2479
+ <td class="description last"><p>輸入是否顯示求解過程log布林值,預設false</p></td>
2480
+ </tr>
2481
+
2482
+
2483
+ </tbody>
2484
+ </table>
2485
+
2486
+ </td>
2487
+ </tr>
2488
+
2489
+
2490
+ </tbody>
2491
+ </table>
2492
+
2493
+
2494
+
2495
+
2496
+
2497
+
2498
+
2499
+
2500
+
2501
+
2502
+
2503
+
2504
+
2505
+
2506
+
2507
+
2508
+ <h5 class="h5-returns">Returns:</h5>
2509
+
2510
+
2511
+ <div class="param-desc">
2512
+ <p>回傳Promise,resolve為omlPSO之求解結果物件,含bestSolution、stopMode、stopIteration與stopExecutions等欄位</p>
2513
+ </div>
2514
+
2515
+
2516
+
2517
+ <dl class="param-type">
2518
+ <dt>
2519
+ Type
2520
+ </dt>
2521
+ <dd>
2522
+
2523
+ <span class="param-type">Promise</span>
2524
+
2525
+
2526
+
2527
+ </dd>
2528
+ </dl>
2529
+
2530
+
2531
+
2532
+
2533
+
2534
+
2535
+
2536
+
2537
+
2538
+
2539
+ <h4 class="name" id="estimPicks"><span class="type-signature type-signature-async">(async) </span>estimPicks<span class="signature">(ott, st, fdOhlc, fdParam, timeStart, timeEnd, mode, funPickKeys, fdData, opt<span class="signature-attributes">opt</span>)</span><span class="type-signature"> &rarr; {Promise}</span></h4>
2540
+
2541
+
2542
+
2543
+
2544
+
2545
+
2546
+ <dl class="details">
2547
+
2548
+ <dt class="tag-description">Description:</dt>
2549
+ <dd class="tag-description"><ul class="dummy"><li><p>由fdParam內全部指標key分類後挑選keys,再率定各key之門檻與止盈止損,求解最佳策略</p>
2550
+ <p>先由fdParam列舉全部指標key,並依名稱分為3類: 開頭為'index_'者為keysIndex(指數類)、含'<em>vbs</em>'者為keysVolumn(成交量類)、其餘為keysNorm(一般類)
2551
+ 分類後各類可經opt內對應之過濾函數再行篩選,接著呼叫funPickKeys由3類挑出待率定之keys,最後交由estimKeys求解
2552
+ fdOhlc、fdParam、timeStart、timeEnd、fdData無效或mode非'long'或'short'或funPickKeys非函數時throw</p>
2553
+ <p>Unit Test: <a href="https://github.com/yuda-lyu/w-trade-solve/blob/master/test/unit-estimPicks.test.mjs">Github</a></p></li></ul></dd>
2554
+
2555
+
2556
+
2557
+ <dt class="tag-source">Source:</dt>
2558
+ <dd class="tag-source"><ul class="dummy"><li>
2559
+ <a href="estimPicks.mjs.html">estimPicks.mjs</a>, <a href="estimPicks.mjs.html#line50">line 50</a>
2560
+ </li></ul></dd>
2561
+
2562
+
2563
+
2564
+
2565
+
2566
+
2567
+
2568
+
2569
+
2570
+
2571
+
2572
+
2573
+
2574
+
2575
+
2576
+
2577
+
2578
+
2579
+
2580
+
2581
+
2582
+
2583
+
2584
+
2585
+
2586
+
2587
+
2588
+
2589
+
2590
+
2591
+
2592
+ </dl>
2593
+
2594
+
2595
+
2596
+
2597
+
2598
+
2599
+
2600
+
2601
+
2602
+
2603
+
2604
+ <h5 class="h5-examples">Example</h5>
2605
+
2606
+ <pre class="prettyprint"><code>import ott from './src/ott.mjs'
2607
+
2608
+ let st = {
2609
+ btc4hr: { name: 'btc', symbol: 'BTCUSDT', interval: '4hr' },
2610
+ }
2611
+
2612
+ //funPickKeys, 由一般類挑第1個key為待率定key
2613
+ let funPickKeys = ({ keysNorm, keysIndex, keysVolumn }) => {
2614
+ return [keysNorm[0]]
2615
+ }
2616
+
2617
+ await estimPicks(ott, st, './data/ohlc', './data/param', '2022-07-01T00:00:00', '2025-04-08T00:00:00', 'long', funPickKeys, './data/strategy', {
2618
+ keySettings: 'btc4hr',
2619
+ })</code></pre>
2620
+
2621
+
2622
+
2623
+
2624
+ <h5 class="h5-parameters">Parameters:</h5>
2625
+
2626
+
2627
+ <table class="params">
2628
+ <thead>
2629
+ <tr>
2630
+
2631
+ <th>Name</th>
2632
+
2633
+
2634
+ <th>Type</th>
2635
+
2636
+
2637
+ <th>Attributes</th>
2638
+
2639
+
2640
+
2641
+ <th>Default</th>
2642
+
2643
+
2644
+ <th class="last">Description</th>
2645
+ </tr>
2646
+ </thead>
2647
+
2648
+ <tbody>
2649
+
2650
+
2651
+ <tr>
2652
+
2653
+ <td class="name"><code>ott</code></td>
2654
+
2655
+
2656
+ <td class="type">
2657
+
2658
+
2659
+ <span class="param-type">function</span>
2660
+
2661
+
2662
+
2663
+
2664
+ </td>
2665
+
2666
+
2667
+ <td class="attributes">
2668
+
2669
+
2670
+
2671
+
2672
+
2673
+ </td>
2674
+
2675
+
2676
+
2677
+ <td class="default">
2678
+
2679
+ </td>
2680
+
2681
+
2682
+ <td class="description last"><p>輸入時區時間函數,傳入時間字串回傳dayjs時間物件,可用src/ott.mjs</p></td>
2683
+ </tr>
2684
+
2685
+
2686
+
2687
+ <tr>
2688
+
2689
+ <td class="name"><code>st</code></td>
2690
+
2691
+
2692
+ <td class="type">
2693
+
2694
+
2695
+ <span class="param-type">Object</span>
2696
+
2697
+
2698
+
2699
+
2700
+ </td>
2701
+
2702
+
2703
+ <td class="attributes">
2704
+
2705
+
2706
+
2707
+
2708
+
2709
+ </td>
2710
+
2711
+
2712
+
2713
+ <td class="default">
2714
+
2715
+ </td>
2716
+
2717
+
2718
+ <td class="description last"><p>輸入設定物件,需可由opt.keySettings取得name、symbol與interval欄位</p></td>
2719
+ </tr>
2720
+
2721
+
2722
+
2723
+ <tr>
2724
+
2725
+ <td class="name"><code>fdOhlc</code></td>
2726
+
2727
+
2728
+ <td class="type">
2729
+
2730
+
2731
+ <span class="param-type">String</span>
2732
+
2733
+
2734
+
2735
+
2736
+ </td>
2737
+
2738
+
2739
+ <td class="attributes">
2740
+
2741
+
2742
+
2743
+
2744
+
2745
+ </td>
2746
+
2747
+
2748
+
2749
+ <td class="default">
2750
+
2751
+ </td>
2752
+
2753
+
2754
+ <td class="description last"><p>輸入儲存K線(ohlc)序列資料夾字串</p></td>
2755
+ </tr>
2756
+
2757
+
2758
+
2759
+ <tr>
2760
+
2761
+ <td class="name"><code>fdParam</code></td>
2762
+
2763
+
2764
+ <td class="type">
2765
+
2766
+
2767
+ <span class="param-type">String</span>
2768
+
2769
+
2770
+
2771
+
2772
+ </td>
2773
+
2774
+
2775
+ <td class="attributes">
2776
+
2777
+
2778
+
2779
+
2780
+
2781
+ </td>
2782
+
2783
+
2784
+
2785
+ <td class="default">
2786
+
2787
+ </td>
2788
+
2789
+
2790
+ <td class="description last"><p>輸入儲存指標參數序列資料夾字串</p></td>
2791
+ </tr>
2792
+
2793
+
2794
+
2795
+ <tr>
2796
+
2797
+ <td class="name"><code>timeStart</code></td>
2798
+
2799
+
2800
+ <td class="type">
2801
+
2802
+
2803
+ <span class="param-type">String</span>
2804
+
2805
+
2806
+
2807
+
2808
+ </td>
2809
+
2810
+
2811
+ <td class="attributes">
2812
+
2813
+
2814
+
2815
+
2816
+
2817
+ </td>
2818
+
2819
+
2820
+
2821
+ <td class="default">
2822
+
2823
+ </td>
2824
+
2825
+
2826
+ <td class="description last"><p>輸入回測起始時間字串,格式'YYYY-MM-DDTHH:mm:ss'</p></td>
2827
+ </tr>
2828
+
2829
+
2830
+
2831
+ <tr>
2832
+
2833
+ <td class="name"><code>timeEnd</code></td>
2834
+
2835
+
2836
+ <td class="type">
2837
+
2838
+
2839
+ <span class="param-type">String</span>
2840
+
2841
+
2842
+
2843
+
2844
+ </td>
2845
+
2846
+
2847
+ <td class="attributes">
2848
+
2849
+
2850
+
2851
+
2852
+
2853
+ </td>
2854
+
2855
+
2856
+
2857
+ <td class="default">
2858
+
2859
+ </td>
2860
+
2861
+
2862
+ <td class="description last"><p>輸入回測結束時間字串,格式'YYYY-MM-DDTHH:mm:ss'</p></td>
2863
+ </tr>
2864
+
2865
+
2866
+
2867
+ <tr>
2868
+
2869
+ <td class="name"><code>mode</code></td>
2870
+
2871
+
2872
+ <td class="type">
2873
+
2874
+
2875
+ <span class="param-type">String</span>
2876
+
2877
+
2878
+
2879
+
2880
+ </td>
2881
+
2882
+
2883
+ <td class="attributes">
2884
+
2885
+
2886
+
2887
+
2888
+
2889
+ </td>
2890
+
2891
+
2892
+
2893
+ <td class="default">
2894
+
2895
+ </td>
2896
+
2897
+
2898
+ <td class="description last"><p>輸入交易方向字串,可選'long'或'short'</p></td>
2899
+ </tr>
2900
+
2901
+
2902
+
2903
+ <tr>
2904
+
2905
+ <td class="name"><code>funPickKeys</code></td>
2906
+
2907
+
2908
+ <td class="type">
2909
+
2910
+
2911
+ <span class="param-type">function</span>
2912
+
2913
+
2914
+
2915
+
2916
+ </td>
2917
+
2918
+
2919
+ <td class="attributes">
2920
+
2921
+
2922
+
2923
+
2924
+
2925
+ </td>
2926
+
2927
+
2928
+
2929
+ <td class="default">
2930
+
2931
+ </td>
2932
+
2933
+
2934
+ <td class="description last"><p>輸入挑選keys函數,傳入{keysNorm,keysIndex,keysVolumn}物件,回傳待率定之指標key字串陣列</p></td>
2935
+ </tr>
2936
+
2937
+
2938
+
2939
+ <tr>
2940
+
2941
+ <td class="name"><code>fdData</code></td>
2942
+
2943
+
2944
+ <td class="type">
2945
+
2946
+
2947
+ <span class="param-type">String</span>
2948
+
2949
+
2950
+
2951
+
2952
+ </td>
2953
+
2954
+
2955
+ <td class="attributes">
2956
+
2957
+
2958
+
2959
+
2960
+
2961
+ </td>
2962
+
2963
+
2964
+
2965
+ <td class="default">
2966
+
2967
+ </td>
2968
+
2969
+
2970
+ <td class="description last"><p>輸入儲存策略資料夾字串,不存在時自動建立</p></td>
2971
+ </tr>
2972
+
2973
+
2974
+
2975
+ <tr>
2976
+
2977
+ <td class="name"><code>opt</code></td>
2978
+
2979
+
2980
+ <td class="type">
2981
+
2982
+
2983
+ <span class="param-type">Object</span>
2984
+
2985
+
2986
+
2987
+
2988
+ </td>
2989
+
2990
+
2991
+ <td class="attributes">
2992
+
2993
+ &lt;optional><br>
2994
+
2995
+
2996
+
2997
+
2998
+
2999
+ </td>
3000
+
3001
+
3002
+
3003
+ <td class="default">
3004
+
3005
+ <code>{}</code>
3006
+
3007
+ </td>
3008
+
3009
+
3010
+ <td class="description last"><p>輸入設定物件,預設{},其餘欄位皆傳遞至estimKeys</p>
3011
+ <h6>Properties</h6>
3012
+
3013
+
3014
+ <table class="params">
3015
+ <thead>
3016
+ <tr>
3017
+
3018
+ <th>Name</th>
3019
+
3020
+
3021
+ <th>Type</th>
3022
+
3023
+
3024
+ <th>Attributes</th>
3025
+
3026
+
3027
+
3028
+ <th>Default</th>
3029
+
3030
+
3031
+ <th class="last">Description</th>
3032
+ </tr>
3033
+ </thead>
3034
+
3035
+ <tbody>
3036
+
3037
+
3038
+ <tr>
3039
+
3040
+ <td class="name"><code>funFilterKeysNorm</code></td>
3041
+
3042
+
3043
+ <td class="type">
3044
+
3045
+
3046
+ <span class="param-type">function</span>
3047
+
3048
+
3049
+
3050
+
3051
+ </td>
3052
+
3053
+
3054
+ <td class="attributes">
3055
+
3056
+ &lt;optional><br>
3057
+
3058
+
3059
+
3060
+
3061
+
3062
+ </td>
3063
+
3064
+
3065
+
3066
+ <td class="default">
3067
+
3068
+ <code>null</code>
3069
+
3070
+ </td>
3071
+
3072
+
3073
+ <td class="description last"><p>輸入過濾一般類key之async函數,傳入keysNorm陣列回傳過濾後陣列,預設null</p></td>
3074
+ </tr>
3075
+
3076
+
3077
+
3078
+ <tr>
3079
+
3080
+ <td class="name"><code>funFilterKeysIndex</code></td>
3081
+
3082
+
3083
+ <td class="type">
3084
+
3085
+
3086
+ <span class="param-type">function</span>
3087
+
3088
+
3089
+
3090
+
3091
+ </td>
3092
+
3093
+
3094
+ <td class="attributes">
3095
+
3096
+ &lt;optional><br>
3097
+
3098
+
3099
+
3100
+
3101
+
3102
+ </td>
3103
+
3104
+
3105
+
3106
+ <td class="default">
3107
+
3108
+ <code>null</code>
3109
+
3110
+ </td>
3111
+
3112
+
3113
+ <td class="description last"><p>輸入過濾指數類key之async函數,傳入keysIndex陣列回傳過濾後陣列,預設null</p></td>
3114
+ </tr>
3115
+
3116
+
3117
+
3118
+ <tr>
3119
+
3120
+ <td class="name"><code>funFilterKeysVolumn</code></td>
3121
+
3122
+
3123
+ <td class="type">
3124
+
3125
+
3126
+ <span class="param-type">function</span>
3127
+
3128
+
3129
+
3130
+
3131
+ </td>
3132
+
3133
+
3134
+ <td class="attributes">
3135
+
3136
+ &lt;optional><br>
3137
+
3138
+
3139
+
3140
+
3141
+
3142
+ </td>
3143
+
3144
+
3145
+
3146
+ <td class="default">
3147
+
3148
+ <code>null</code>
3149
+
3150
+ </td>
3151
+
3152
+
3153
+ <td class="description last"><p>輸入過濾成交量類key之async函數,傳入keysVolumn陣列回傳過濾後陣列,預設null</p></td>
3154
+ </tr>
3155
+
3156
+
3157
+ </tbody>
3158
+ </table>
3159
+
3160
+ </td>
3161
+ </tr>
3162
+
3163
+
3164
+ </tbody>
3165
+ </table>
3166
+
3167
+
3168
+
3169
+
3170
+
3171
+
3172
+
3173
+
3174
+
3175
+
3176
+
3177
+
3178
+
3179
+
3180
+
3181
+
3182
+ <h5 class="h5-returns">Returns:</h5>
3183
+
3184
+
3185
+ <div class="param-desc">
3186
+ <p>回傳Promise,resolve為undefined</p>
3187
+ </div>
3188
+
3189
+
3190
+
3191
+ <dl class="param-type">
3192
+ <dt>
3193
+ Type
3194
+ </dt>
3195
+ <dd>
3196
+
3197
+ <span class="param-type">Promise</span>
3198
+
3199
+
3200
+
3201
+ </dd>
3202
+ </dl>
3203
+
3204
+
3205
+
3206
+
3207
+
3208
+
3209
+
3210
+
3211
+
3212
+
3213
+ <h4 class="name" id="genSid"><span class="type-signature"></span>genSid<span class="signature">(coin, interval, mode, conds)</span><span class="type-signature"> &rarr; {String}</span></h4>
3214
+
3215
+
3216
+
3217
+
3218
+
3219
+
3220
+ <dl class="details">
3221
+
3222
+ <dt class="tag-description">Description:</dt>
3223
+ <dd class="tag-description"><ul class="dummy"><li><p>產生策略識別碼sid</p>
3224
+ <p>各cond先組為<code>${key}${sym}${th}</code>,再以cont.dlmSeps串接mode與各cond為識別字串,最後進行與genTid相同之縮寫替換
3225
+ 縮寫替換依序為: 剔除<code>${coin}_</code>、剔除<code>${interval}_</code>、'price_'轉'p_'、'index_'轉'i_'、'Ohlc_'轉'o_'、'Close_'轉'c_'、'Volumn_'轉'v_'
3226
+ 因替換係以<code>${coin}_</code>與<code>${interval}_</code>為樣式,故coin與interval須給予有效字串,否則將剔除全部底線
3227
+ sid已含各cond之門檻,故同組keys之不同門檻組合對應不同sid,可與僅由keys決定之tid區別</p>
3228
+ <p>Unit Test: <a href="https://github.com/yuda-lyu/w-trade-solve/blob/master/test/unit-genSid.test.mjs">Github</a></p></li></ul></dd>
3229
+
3230
+
3231
+
3232
+ <dt class="tag-source">Source:</dt>
3233
+ <dd class="tag-source"><ul class="dummy"><li>
3234
+ <a href="genSid.mjs.html">genSid.mjs</a>, <a href="genSid.mjs.html#line33">line 33</a>
3235
+ </li></ul></dd>
3236
+
3237
+
3238
+
3239
+
3240
+
3241
+
3242
+
3243
+
3244
+
3245
+
3246
+
3247
+
3248
+
3249
+
3250
+
3251
+
3252
+
3253
+
3254
+
3255
+
3256
+
3257
+
3258
+
3259
+
3260
+
3261
+
3262
+
3263
+
3264
+
3265
+
3266
+
3267
+ </dl>
3268
+
3269
+
3270
+
3271
+
3272
+
3273
+
3274
+
3275
+
3276
+
3277
+
3278
+
3279
+ <h5 class="h5-examples">Example</h5>
3280
+
3281
+ <pre class="prettyprint"><code>let conds = [
3282
+ { key: 'btc_price_4hr_ma_1day', sym: '>', th: 0.05 },
3283
+ { key: 'btc_index_rsi_4hr', sym: '&lt;', th: -0.2 },
3284
+ ]
3285
+
3286
+ let sid = genSid('btc', '4hr', 'long', conds)
3287
+ console.log(sid)
3288
+ // => 'long ║ p_ma_1day>0.05 ║ i_rsi_4hr&lt;-0.2'</code></pre>
3289
+
3290
+
3291
+
3292
+
3293
+ <h5 class="h5-parameters">Parameters:</h5>
3294
+
3295
+
3296
+ <table class="params">
3297
+ <thead>
3298
+ <tr>
3299
+
3300
+ <th>Name</th>
3301
+
3302
+
3303
+ <th>Type</th>
3304
+
3305
+
3306
+
3307
+
3308
+
3309
+ <th class="last">Description</th>
3310
+ </tr>
3311
+ </thead>
3312
+
3313
+ <tbody>
3314
+
3315
+
3316
+ <tr>
3317
+
3318
+ <td class="name"><code>coin</code></td>
3319
+
3320
+
3321
+ <td class="type">
3322
+
3323
+
3324
+ <span class="param-type">String</span>
3325
+
3326
+
3327
+
3328
+
3329
+ </td>
3330
+
3331
+
3332
+
3333
+
3334
+
3335
+ <td class="description last"><p>輸入幣種名稱字串,例如'btc'</p></td>
3336
+ </tr>
3337
+
3338
+
3339
+
3340
+ <tr>
3341
+
3342
+ <td class="name"><code>interval</code></td>
3343
+
3344
+
3345
+ <td class="type">
3346
+
3347
+
3348
+ <span class="param-type">String</span>
3349
+
3350
+
3351
+
3352
+
3353
+ </td>
3354
+
3355
+
3356
+
3357
+
3358
+
3359
+ <td class="description last"><p>輸入K線週期字串,例如'4hr'</p></td>
3360
+ </tr>
3361
+
3362
+
3363
+
3364
+ <tr>
3365
+
3366
+ <td class="name"><code>mode</code></td>
3367
+
3368
+
3369
+ <td class="type">
3370
+
3371
+
3372
+ <span class="param-type">String</span>
3373
+
3374
+
3375
+
3376
+
3377
+ </td>
3378
+
3379
+
3380
+
3381
+
3382
+
3383
+ <td class="description last"><p>輸入交易方向字串,可選'long'或'short'</p></td>
3384
+ </tr>
3385
+
3386
+
3387
+
3388
+ <tr>
3389
+
3390
+ <td class="name"><code>conds</code></td>
3391
+
3392
+
3393
+ <td class="type">
3394
+
3395
+
3396
+ <span class="param-type">Array</span>
3397
+
3398
+
3399
+
3400
+
3401
+ </td>
3402
+
3403
+
3404
+
3405
+
3406
+
3407
+ <td class="description last"><p>輸入條件物件陣列,各元素為{key,sym,th},key為指標key字串,sym為'&gt;'或'&lt;',th為門檻數值</p></td>
3408
+ </tr>
3409
+
3410
+
3411
+ </tbody>
3412
+ </table>
3413
+
3414
+
3415
+
3416
+
3417
+
3418
+
3419
+
3420
+
3421
+
3422
+
3423
+
3424
+
3425
+
3426
+
3427
+
3428
+
3429
+ <h5 class="h5-returns">Returns:</h5>
3430
+
3431
+
3432
+ <div class="param-desc">
3433
+ <p>回傳策略識別碼sid字串</p>
3434
+ </div>
3435
+
3436
+
3437
+
3438
+ <dl class="param-type">
3439
+ <dt>
3440
+ Type
3441
+ </dt>
3442
+ <dd>
3443
+
3444
+ <span class="param-type">String</span>
3445
+
3446
+
3447
+
3448
+ </dd>
3449
+ </dl>
3450
+
3451
+
3452
+
3453
+
3454
+
3455
+
3456
+
3457
+
3458
+
3459
+
3460
+ <h4 class="name" id="genStrategyFileName"><span class="type-signature"></span>genStrategyFileName<span class="signature">(coin, interval, mode, keys, settings, summary)</span><span class="type-signature"> &rarr; {String}</span></h4>
3461
+
3462
+
3463
+
3464
+
3465
+
3466
+
3467
+ <dl class="details">
3468
+
3469
+ <dt class="tag-description">Description:</dt>
3470
+ <dd class="tag-description"><ul class="dummy"><li><p>產生策略儲存檔名</p>
3471
+ <p>檔名為<code>${tid}${cont.dlmPkgs}${levelNumTrade}${cont.dlmPkgs}${rEquivalentCumuProfitOrLossFinalNormYear}.json</code>
3472
+ tid由genTid以coin、interval、mode與keys產生,levelNumTrade由calcLevelNumTrade以summary.numTrade產生
3473
+ 因tid與levelNumTrade皆入檔名,故可由檔名反解出同組keys與同交易次數級距之既有策略,供readStrategies列舉比較
3474
+ settings目前未參與檔名組成</p>
3475
+ <p>Unit Test: <a href="https://github.com/yuda-lyu/w-trade-solve/blob/master/test/unit-genStrategyFileName.test.mjs">Github</a></p></li></ul></dd>
3476
+
3477
+
3478
+
3479
+ <dt class="tag-source">Source:</dt>
3480
+ <dd class="tag-source"><ul class="dummy"><li>
3481
+ <a href="genStrategyFileName.mjs.html">genStrategyFileName.mjs</a>, <a href="genStrategyFileName.mjs.html#line37">line 37</a>
3482
+ </li></ul></dd>
3483
+
3484
+
3485
+
3486
+
3487
+
3488
+
3489
+
3490
+
3491
+
3492
+
3493
+
3494
+
3495
+
3496
+
3497
+
3498
+
3499
+
3500
+
3501
+
3502
+
3503
+
3504
+
3505
+
3506
+
3507
+
3508
+
3509
+
3510
+
3511
+
3512
+
3513
+
3514
+ </dl>
3515
+
3516
+
3517
+
3518
+
3519
+
3520
+
3521
+
3522
+
3523
+
3524
+
3525
+
3526
+ <h5 class="h5-examples">Example</h5>
3527
+
3528
+ <pre class="prettyprint"><code>let keys = ['btc_price_4hr_ma_1day']
3529
+
3530
+ let settings = { uIni: 1000, uTrade: 1, rTakeProfit: 0.05, rStopLoss: 0.03, rFee: 0.0005 }
3531
+
3532
+ let summary = { numTrade: 30, rEquivalentCumuProfitOrLossFinalNormYear: '31.25%' }
3533
+
3534
+ let fn = genStrategyFileName('btc', '4hr', 'long', keys, settings, summary)
3535
+ console.log(fn)
3536
+ // => 'long ║ p_ma_1day ⊙ 12 ⊙ 31.25%.json'</code></pre>
3537
+
3538
+
3539
+
3540
+
3541
+ <h5 class="h5-parameters">Parameters:</h5>
3542
+
3543
+
3544
+ <table class="params">
3545
+ <thead>
3546
+ <tr>
3547
+
3548
+ <th>Name</th>
3549
+
3550
+
3551
+ <th>Type</th>
3552
+
3553
+
3554
+
3555
+
3556
+
3557
+ <th class="last">Description</th>
3558
+ </tr>
3559
+ </thead>
3560
+
3561
+ <tbody>
3562
+
3563
+
3564
+ <tr>
3565
+
3566
+ <td class="name"><code>coin</code></td>
3567
+
3568
+
3569
+ <td class="type">
3570
+
3571
+
3572
+ <span class="param-type">String</span>
3573
+
3574
+
3575
+
3576
+
3577
+ </td>
3578
+
3579
+
3580
+
3581
+
3582
+
3583
+ <td class="description last"><p>輸入幣種名稱字串,例如'btc'</p></td>
3584
+ </tr>
3585
+
3586
+
3587
+
3588
+ <tr>
3589
+
3590
+ <td class="name"><code>interval</code></td>
3591
+
3592
+
3593
+ <td class="type">
3594
+
3595
+
3596
+ <span class="param-type">String</span>
3597
+
3598
+
3599
+
3600
+
3601
+ </td>
3602
+
3603
+
3604
+
3605
+
3606
+
3607
+ <td class="description last"><p>輸入K線週期字串,例如'4hr'</p></td>
3608
+ </tr>
3609
+
3610
+
3611
+
3612
+ <tr>
3613
+
3614
+ <td class="name"><code>mode</code></td>
3615
+
3616
+
3617
+ <td class="type">
3618
+
3619
+
3620
+ <span class="param-type">String</span>
3621
+
3622
+
3623
+
3624
+
3625
+ </td>
3626
+
3627
+
3628
+
3629
+
3630
+
3631
+ <td class="description last"><p>輸入交易方向字串,可選'long'或'short'</p></td>
3632
+ </tr>
3633
+
3634
+
3635
+
3636
+ <tr>
3637
+
3638
+ <td class="name"><code>keys</code></td>
3639
+
3640
+
3641
+ <td class="type">
3642
+
3643
+
3644
+ <span class="param-type">Array</span>
3645
+
3646
+
3647
+
3648
+
3649
+ </td>
3650
+
3651
+
3652
+
3653
+
3654
+
3655
+ <td class="description last"><p>輸入指標key字串陣列</p></td>
3656
+ </tr>
3657
+
3658
+
3659
+
3660
+ <tr>
3661
+
3662
+ <td class="name"><code>settings</code></td>
3663
+
3664
+
3665
+ <td class="type">
3666
+
3667
+
3668
+ <span class="param-type">Object</span>
3669
+
3670
+
3671
+
3672
+
3673
+ </td>
3674
+
3675
+
3676
+
3677
+
3678
+
3679
+ <td class="description last"><p>輸入策略設定物件</p></td>
3680
+ </tr>
3681
+
3682
+
3683
+
3684
+ <tr>
3685
+
3686
+ <td class="name"><code>summary</code></td>
3687
+
3688
+
3689
+ <td class="type">
3690
+
3691
+
3692
+ <span class="param-type">Object</span>
3693
+
3694
+
3695
+
3696
+
3697
+ </td>
3698
+
3699
+
3700
+
3701
+
3702
+
3703
+ <td class="description last"><p>輸入回測統計摘要物件,需含numTrade(交易次數)與rEquivalentCumuProfitOrLossFinalNormYear(最終等效年化盈虧百分比字串)欄位</p></td>
3704
+ </tr>
3705
+
3706
+
3707
+ </tbody>
3708
+ </table>
3709
+
3710
+
3711
+
3712
+
3713
+
3714
+
3715
+
3716
+
3717
+
3718
+
3719
+
3720
+
3721
+
3722
+
3723
+
3724
+
3725
+ <h5 class="h5-returns">Returns:</h5>
3726
+
3727
+
3728
+ <div class="param-desc">
3729
+ <p>回傳策略儲存檔名字串</p>
3730
+ </div>
3731
+
3732
+
3733
+
3734
+ <dl class="param-type">
3735
+ <dt>
3736
+ Type
3737
+ </dt>
3738
+ <dd>
3739
+
3740
+ <span class="param-type">String</span>
3741
+
3742
+
3743
+
3744
+ </dd>
3745
+ </dl>
3746
+
3747
+
3748
+
3749
+
3750
+
3751
+
3752
+
3753
+
3754
+
3755
+
3756
+ <h4 class="name" id="genTid"><span class="type-signature"></span>genTid<span class="signature">(coin, interval, mode, keys)</span><span class="type-signature"> &rarr; {String}</span></h4>
3757
+
3758
+
3759
+
3760
+
3761
+
3762
+
3763
+ <dl class="details">
3764
+
3765
+ <dt class="tag-description">Description:</dt>
3766
+ <dd class="tag-description"><ul class="dummy"><li><p>產生策略種類識別碼tid</p>
3767
+ <p>以cont.dlmSeps串接mode與各key為識別字串,再進行縮寫替換以縮短長度
3768
+ 縮寫替換依序為: 剔除<code>${coin}_</code>、剔除<code>${interval}_</code>、'price_'轉'p_'、'index_'轉'i_'、'Ohlc_'轉'o_'、'Close_'轉'c_'、'Volumn_'轉'v_'
3769
+ 因替換係以<code>${coin}_</code>與<code>${interval}_</code>為樣式,故coin與interval須給予有效字串,否則將剔除全部底線
3770
+ tid僅由mode與keys決定,未含各key之門檻條件,故同組keys之各門檻組合皆對應同一tid</p>
3771
+ <p>Unit Test: <a href="https://github.com/yuda-lyu/w-trade-solve/blob/master/test/unit-genTid.test.mjs">Github</a></p></li></ul></dd>
3772
+
3773
+
3774
+
3775
+ <dt class="tag-source">Source:</dt>
3776
+ <dd class="tag-source"><ul class="dummy"><li>
3777
+ <a href="genTid.mjs.html">genTid.mjs</a>, <a href="genTid.mjs.html#line27">line 27</a>
3778
+ </li></ul></dd>
3779
+
3780
+
3781
+
3782
+
3783
+
3784
+
3785
+
3786
+
3787
+
3788
+
3789
+
3790
+
3791
+
3792
+
3793
+
3794
+
3795
+
3796
+
3797
+
3798
+
3799
+
3800
+
3801
+
3802
+
3803
+
3804
+
3805
+
3806
+
3807
+
3808
+
3809
+
3810
+ </dl>
3811
+
3812
+
3813
+
3814
+
3815
+
3816
+
3817
+
3818
+
3819
+
3820
+
3821
+
3822
+ <h5 class="h5-examples">Example</h5>
3823
+
3824
+ <pre class="prettyprint"><code>let tid = genTid('btc', '4hr', 'long', ['btc_price_4hr_ma_1day', 'btc_index_rsi_4hr'])
3825
+ console.log(tid)
3826
+ // => 'long ║ p_ma_1day ║ i_rsi_4hr'</code></pre>
3827
+
3828
+
3829
+
3830
+
3831
+ <h5 class="h5-parameters">Parameters:</h5>
3832
+
3833
+
3834
+ <table class="params">
3835
+ <thead>
3836
+ <tr>
3837
+
3838
+ <th>Name</th>
3839
+
3840
+
3841
+ <th>Type</th>
3842
+
3843
+
3844
+
3845
+
3846
+
3847
+ <th class="last">Description</th>
3848
+ </tr>
3849
+ </thead>
3850
+
3851
+ <tbody>
3852
+
3853
+
3854
+ <tr>
3855
+
3856
+ <td class="name"><code>coin</code></td>
3857
+
3858
+
3859
+ <td class="type">
3860
+
3861
+
3862
+ <span class="param-type">String</span>
3863
+
3864
+
3865
+
3866
+
3867
+ </td>
3868
+
3869
+
3870
+
3871
+
3872
+
3873
+ <td class="description last"><p>輸入幣種名稱字串,例如'btc'</p></td>
3874
+ </tr>
3875
+
3876
+
3877
+
3878
+ <tr>
3879
+
3880
+ <td class="name"><code>interval</code></td>
3881
+
3882
+
3883
+ <td class="type">
3884
+
3885
+
3886
+ <span class="param-type">String</span>
3887
+
3888
+
3889
+
3890
+
3891
+ </td>
3892
+
3893
+
3894
+
3895
+
3896
+
3897
+ <td class="description last"><p>輸入K線週期字串,例如'4hr'</p></td>
3898
+ </tr>
3899
+
3900
+
3901
+
3902
+ <tr>
3903
+
3904
+ <td class="name"><code>mode</code></td>
3905
+
3906
+
3907
+ <td class="type">
3908
+
3909
+
3910
+ <span class="param-type">String</span>
3911
+
3912
+
3913
+
3914
+
3915
+ </td>
3916
+
3917
+
3918
+
3919
+
3920
+
3921
+ <td class="description last"><p>輸入交易方向字串,可選'long'或'short'</p></td>
3922
+ </tr>
3923
+
3924
+
3925
+
3926
+ <tr>
3927
+
3928
+ <td class="name"><code>keys</code></td>
3929
+
3930
+
3931
+ <td class="type">
3932
+
3933
+
3934
+ <span class="param-type">Array</span>
3935
+
3936
+
3937
+
3938
+
3939
+ </td>
3940
+
3941
+
3942
+
3943
+
3944
+
3945
+ <td class="description last"><p>輸入指標key字串陣列</p></td>
3946
+ </tr>
3947
+
3948
+
3949
+ </tbody>
3950
+ </table>
3951
+
3952
+
3953
+
3954
+
3955
+
3956
+
3957
+
3958
+
3959
+
3960
+
3961
+
3962
+
3963
+
3964
+
3965
+
3966
+
3967
+ <h5 class="h5-returns">Returns:</h5>
3968
+
3969
+
3970
+ <div class="param-desc">
3971
+ <p>回傳策略種類識別碼tid字串</p>
3972
+ </div>
3973
+
3974
+
3975
+
3976
+ <dl class="param-type">
3977
+ <dt>
3978
+ Type
3979
+ </dt>
3980
+ <dd>
3981
+
3982
+ <span class="param-type">String</span>
3983
+
3984
+
3985
+
3986
+ </dd>
3987
+ </dl>
3988
+
3989
+
3990
+
3991
+
3992
+
3993
+
3994
+
3995
+
3996
+
3997
+
3998
+ <h4 class="name" id="nowTpeStr"><span class="type-signature"></span>nowTpeStr<span class="signature">()</span><span class="type-signature"> &rarr; {String}</span></h4>
3999
+
4000
+
4001
+
4002
+
4003
+
4004
+
4005
+ <dl class="details">
4006
+
4007
+ <dt class="tag-description">Description:</dt>
4008
+ <dd class="tag-description"><ul class="dummy"><li><p>取得當下台北時間字串,格式'YYYY-MM-DDTHH:mm:ssZ'</p></li></ul></dd>
4009
+
4010
+
4011
+
4012
+ <dt class="tag-source">Source:</dt>
4013
+ <dd class="tag-source"><ul class="dummy"><li>
4014
+ <a href="ott.mjs.html">ott.mjs</a>, <a href="ott.mjs.html#line47">line 47</a>
4015
+ </li></ul></dd>
4016
+
4017
+
4018
+
4019
+
4020
+
4021
+
4022
+
4023
+
4024
+
4025
+
4026
+
4027
+
4028
+
4029
+
4030
+
4031
+
4032
+
4033
+
4034
+
4035
+
4036
+
4037
+
4038
+
4039
+
4040
+
4041
+
4042
+
4043
+
4044
+
4045
+
4046
+
4047
+ </dl>
4048
+
4049
+
4050
+
4051
+
4052
+
4053
+
4054
+
4055
+
4056
+
4057
+
4058
+
4059
+ <h5 class="h5-examples">Example</h5>
4060
+
4061
+ <pre class="prettyprint"><code>console.log(nowTpeStr())
4062
+ // => '2026-08-04T22:08:31+08:00'</code></pre>
4063
+
4064
+
4065
+
4066
+
4067
+
4068
+
4069
+
4070
+
4071
+
4072
+
4073
+
4074
+
4075
+
4076
+
4077
+
4078
+
4079
+
4080
+
4081
+ <h5 class="h5-returns">Returns:</h5>
4082
+
4083
+
4084
+ <div class="param-desc">
4085
+ <p>回傳當下台北時間字串</p>
4086
+ </div>
4087
+
4088
+
4089
+
4090
+ <dl class="param-type">
4091
+ <dt>
4092
+ Type
4093
+ </dt>
4094
+ <dd>
4095
+
4096
+ <span class="param-type">String</span>
4097
+
4098
+
4099
+
4100
+ </dd>
4101
+ </dl>
4102
+
4103
+
4104
+
4105
+
4106
+
4107
+
4108
+
4109
+
4110
+
4111
+
4112
+ <h4 class="name" id="nowTpeStrp"><span class="type-signature"></span>nowTpeStrp<span class="signature">()</span><span class="type-signature"> &rarr; {String}</span></h4>
4113
+
4114
+
4115
+
4116
+
4117
+
4118
+
4119
+ <dl class="details">
4120
+
4121
+ <dt class="tag-description">Description:</dt>
4122
+ <dd class="tag-description"><ul class="dummy"><li><p>取得當下台北時間字串,格式'YYYYMMDDHHmmss'</p></li></ul></dd>
4123
+
4124
+
4125
+
4126
+ <dt class="tag-source">Source:</dt>
4127
+ <dd class="tag-source"><ul class="dummy"><li>
4128
+ <a href="ott.mjs.html">ott.mjs</a>, <a href="ott.mjs.html#line61">line 61</a>
4129
+ </li></ul></dd>
4130
+
4131
+
4132
+
4133
+
4134
+
4135
+
4136
+
4137
+
4138
+
4139
+
4140
+
4141
+
4142
+
4143
+
4144
+
4145
+
4146
+
4147
+
4148
+
4149
+
4150
+
4151
+
4152
+
4153
+
4154
+
4155
+
4156
+
4157
+
4158
+
4159
+
4160
+
4161
+ </dl>
4162
+
4163
+
4164
+
4165
+
4166
+
4167
+
4168
+
4169
+
4170
+
4171
+
4172
+
4173
+ <h5 class="h5-examples">Example</h5>
4174
+
4175
+ <pre class="prettyprint"><code>console.log(nowTpeStrp())
4176
+ // => '20260804220831'</code></pre>
4177
+
4178
+
4179
+
4180
+
4181
+
4182
+
4183
+
4184
+
4185
+
4186
+
4187
+
4188
+
4189
+
4190
+
4191
+
4192
+
4193
+
4194
+
4195
+ <h5 class="h5-returns">Returns:</h5>
4196
+
4197
+
4198
+ <div class="param-desc">
4199
+ <p>回傳當下台北時間字串</p>
4200
+ </div>
4201
+
4202
+
4203
+
4204
+ <dl class="param-type">
4205
+ <dt>
4206
+ Type
4207
+ </dt>
4208
+ <dd>
4209
+
4210
+ <span class="param-type">String</span>
4211
+
4212
+
4213
+
4214
+ </dd>
4215
+ </dl>
4216
+
4217
+
4218
+
4219
+
4220
+
4221
+
4222
+
4223
+
4224
+
4225
+
4226
+ <h4 class="name" id="ott"><span class="type-signature"></span>ott<span class="signature">(input<span class="signature-attributes">opt</span>)</span><span class="type-signature"> &rarr; {Object}</span></h4>
4227
+
4228
+
4229
+
4230
+
4231
+
4232
+
4233
+ <dl class="details">
4234
+
4235
+ <dt class="tag-description">Description:</dt>
4236
+ <dd class="tag-description"><ul class="dummy"><li><p>產生台北時區(Asia/Taipei)之dayjs時間物件</p>
4237
+ <p>供estimKeys與w-trade-backtest之runStrategy等函數使用,使各處時間換算基準一致
4238
+ 未給予input時回傳當下時間,給予input時以台北時區解析該時間</p></li></ul></dd>
4239
+
4240
+
4241
+
4242
+ <dt class="tag-source">Source:</dt>
4243
+ <dd class="tag-source"><ul class="dummy"><li>
4244
+ <a href="ott.mjs.html">ott.mjs</a>, <a href="ott.mjs.html#line28">line 28</a>
4245
+ </li></ul></dd>
4246
+
4247
+
4248
+
4249
+
4250
+
4251
+
4252
+
4253
+
4254
+
4255
+
4256
+
4257
+
4258
+
4259
+
4260
+
4261
+
4262
+
4263
+
4264
+
4265
+
4266
+
4267
+
4268
+
4269
+
4270
+
4271
+
4272
+
4273
+
4274
+
4275
+
4276
+
4277
+ </dl>
4278
+
4279
+
4280
+
4281
+
4282
+
4283
+
4284
+
4285
+
4286
+
4287
+
4288
+
4289
+ <h5 class="h5-examples">Example</h5>
4290
+
4291
+ <pre class="prettyprint"><code>console.log(ott('2020-01-01T00:00:00').format('YYYY-MM-DDTHH:mm:ssZ'))
4292
+ // => '2020-01-01T00:00:00+08:00'</code></pre>
4293
+
4294
+
4295
+
4296
+
4297
+ <h5 class="h5-parameters">Parameters:</h5>
4298
+
4299
+
4300
+ <table class="params">
4301
+ <thead>
4302
+ <tr>
4303
+
4304
+ <th>Name</th>
4305
+
4306
+
4307
+ <th>Type</th>
4308
+
4309
+
4310
+ <th>Attributes</th>
4311
+
4312
+
4313
+
4314
+ <th>Default</th>
4315
+
4316
+
4317
+ <th class="last">Description</th>
4318
+ </tr>
4319
+ </thead>
4320
+
4321
+ <tbody>
4322
+
4323
+
4324
+ <tr>
4325
+
4326
+ <td class="name"><code>input</code></td>
4327
+
4328
+
4329
+ <td class="type">
4330
+
4331
+
4332
+ <span class="param-type">String</span>
4333
+ |
4334
+
4335
+ <span class="param-type">Number</span>
4336
+ |
4337
+
4338
+ <span class="param-type">Date</span>
4339
+
4340
+
4341
+
4342
+
4343
+ </td>
4344
+
4345
+
4346
+ <td class="attributes">
4347
+
4348
+ &lt;optional><br>
4349
+
4350
+
4351
+
4352
+
4353
+
4354
+ </td>
4355
+
4356
+
4357
+
4358
+ <td class="default">
4359
+
4360
+ <code>null</code>
4361
+
4362
+ </td>
4363
+
4364
+
4365
+ <td class="description last"><p>輸入時間字串、時間數值或時間物件,未給予時代表當下時間,預設null</p></td>
4366
+ </tr>
4367
+
4368
+
4369
+ </tbody>
4370
+ </table>
4371
+
4372
+
4373
+
4374
+
4375
+
4376
+
4377
+
4378
+
4379
+
4380
+
4381
+
4382
+
4383
+
4384
+
4385
+
4386
+
4387
+ <h5 class="h5-returns">Returns:</h5>
4388
+
4389
+
4390
+ <div class="param-desc">
4391
+ <p>回傳台北時區之dayjs時間物件</p>
4392
+ </div>
4393
+
4394
+
4395
+
4396
+ <dl class="param-type">
4397
+ <dt>
4398
+ Type
4399
+ </dt>
4400
+ <dd>
4401
+
4402
+ <span class="param-type">Object</span>
4403
+
4404
+
4405
+
4406
+ </dd>
4407
+ </dl>
4408
+
4409
+
4410
+
4411
+
4412
+
4413
+
4414
+
4415
+
4416
+
4417
+
4418
+ <h4 class="name" id="p2r"><span class="type-signature"></span>p2r<span class="signature">(p)</span><span class="type-signature"> &rarr; {Number}</span></h4>
4419
+
4420
+
4421
+
4422
+
4423
+
4424
+
4425
+ <dl class="details">
4426
+
4427
+ <dt class="tag-description">Description:</dt>
4428
+ <dd class="tag-description"><ul class="dummy"><li><p>轉換百分比字串為比例數值</p>
4429
+ <p>輸入須為含'%'之字串(例如w-trade-backtest之summary內各比例欄位),剔除'%'後除以100為比例值
4430
+ 未含'%'時回傳0,故無任何交易之空字串亦回傳0</p>
4431
+ <p>Unit Test: <a href="https://github.com/yuda-lyu/w-trade-solve/blob/master/test/unit-p2r.test.mjs">Github</a></p></li></ul></dd>
4432
+
4433
+
4434
+
4435
+ <dt class="tag-source">Source:</dt>
4436
+ <dd class="tag-source"><ul class="dummy"><li>
4437
+ <a href="p2r.mjs.html">p2r.mjs</a>, <a href="p2r.mjs.html#line27">line 27</a>
4438
+ </li></ul></dd>
4439
+
4440
+
4441
+
4442
+
4443
+
4444
+
4445
+
4446
+
4447
+
4448
+
4449
+
4450
+
4451
+
4452
+
4453
+
4454
+
4455
+
4456
+
4457
+
4458
+
4459
+
4460
+
4461
+
4462
+
4463
+
4464
+
4465
+
4466
+
4467
+
4468
+
4469
+
4470
+ </dl>
4471
+
4472
+
4473
+
4474
+
4475
+
4476
+
4477
+
4478
+
4479
+
4480
+
4481
+
4482
+ <h5 class="h5-examples">Example</h5>
4483
+
4484
+ <pre class="prettyprint"><code>console.log(p2r('31.25%'))
4485
+ // => 0.3125
4486
+
4487
+ console.log(p2r('-5%'))
4488
+ // => -0.05
4489
+
4490
+ console.log(p2r(''))
4491
+ // => 0</code></pre>
4492
+
4493
+
4494
+
4495
+
4496
+ <h5 class="h5-parameters">Parameters:</h5>
4497
+
4498
+
4499
+ <table class="params">
4500
+ <thead>
4501
+ <tr>
4502
+
4503
+ <th>Name</th>
4504
+
4505
+
4506
+ <th>Type</th>
4507
+
4508
+
4509
+
4510
+
4511
+
4512
+ <th class="last">Description</th>
4513
+ </tr>
4514
+ </thead>
4515
+
4516
+ <tbody>
4517
+
4518
+
4519
+ <tr>
4520
+
4521
+ <td class="name"><code>p</code></td>
4522
+
4523
+
4524
+ <td class="type">
4525
+
4526
+
4527
+ <span class="param-type">String</span>
4528
+
4529
+
4530
+
4531
+
4532
+ </td>
4533
+
4534
+
4535
+
4536
+
4537
+
4538
+ <td class="description last"><p>輸入百分比字串,例如'31.25%'</p></td>
4539
+ </tr>
4540
+
4541
+
4542
+ </tbody>
4543
+ </table>
4544
+
4545
+
4546
+
4547
+
4548
+
4549
+
4550
+
4551
+
4552
+
4553
+
4554
+
4555
+
4556
+
4557
+
4558
+
4559
+
4560
+ <h5 class="h5-returns">Returns:</h5>
4561
+
4562
+
4563
+ <div class="param-desc">
4564
+ <p>回傳比例數值</p>
4565
+ </div>
4566
+
4567
+
4568
+
4569
+ <dl class="param-type">
4570
+ <dt>
4571
+ Type
4572
+ </dt>
4573
+ <dd>
4574
+
4575
+ <span class="param-type">Number</span>
4576
+
4577
+
4578
+
4579
+ </dd>
4580
+ </dl>
4581
+
4582
+
4583
+
4584
+
4585
+
4586
+
4587
+
4588
+
4589
+
4590
+
4591
+ <h4 class="name" id="readStrategies"><span class="type-signature"></span>readStrategies<span class="signature">(fd, opt<span class="signature-attributes">opt</span>)</span><span class="type-signature"> &rarr; {Array}</span></h4>
4592
+
4593
+
4594
+
4595
+
4596
+
4597
+
4598
+ <dl class="details">
4599
+
4600
+ <dt class="tag-description">Description:</dt>
4601
+ <dd class="tag-description"><ul class="dummy"><li><p>讀取儲存策略資料夾內各策略檔資訊</p>
4602
+ <p>僅列舉fd第1層之檔案,資料夾不列入,fd非資料夾或無任何檔案時回傳空陣列
4603
+ 各檔以主檔名(剔除'.json')依cont.dlmPkgs切段,依序為tid、levelNumTrade與rEquivalentCumuProfitOrLossFinalNormYear,即genStrategyFileName所產生之檔名,切不出tid者予以略過
4604
+ tid再依cont.dlmSeps切段,首段為mode,其餘為各key所組成之ps
4605
+ tkid為<code>${tid}:${levelNumTrade}</code>,與estimKeys內用於判斷同組keys與同交易次數級距之組合方式一致</p>
4606
+ <p>Unit Test: <a href="https://github.com/yuda-lyu/w-trade-solve/blob/master/test/unit-readStrategies.test.mjs">Github</a></p></li></ul></dd>
4607
+
4608
+
4609
+
4610
+ <dt class="tag-source">Source:</dt>
4611
+ <dd class="tag-source"><ul class="dummy"><li>
4612
+ <a href="readStrategies.mjs.html">readStrategies.mjs</a>, <a href="readStrategies.mjs.html#line56">line 56</a>
4613
+ </li></ul></dd>
4614
+
4615
+
4616
+
4617
+
4618
+
4619
+
4620
+
4621
+
4622
+
4623
+
4624
+
4625
+
4626
+
4627
+
4628
+
4629
+
4630
+
4631
+
4632
+
4633
+
4634
+
4635
+
4636
+
4637
+
4638
+
4639
+
4640
+
4641
+
4642
+
4643
+
4644
+
4645
+ </dl>
4646
+
4647
+
4648
+
4649
+
4650
+
4651
+
4652
+
4653
+
4654
+
4655
+
4656
+
4657
+ <h5 class="h5-examples">Example</h5>
4658
+
4659
+ <pre class="prettyprint"><code>import fs from 'fs'
4660
+ import cont from './src/cont.mjs'
4661
+
4662
+ let fd = './tmp/data-strategy'
4663
+ fs.mkdirSync(fd, { recursive: true })
4664
+
4665
+ //以genStrategyFileName之檔名規則儲存策略檔
4666
+ let fn = `long${cont.dlmSeps}ma_1day${cont.dlmPkgs}12${cont.dlmPkgs}31.25%.json`
4667
+ fs.writeFileSync(`${fd}/${fn}`, JSON.stringify({ mode: 'long' }), 'utf8')
4668
+
4669
+ console.log(readStrategies(fd))
4670
+ // => [
4671
+ // {
4672
+ // path: './tmp/data-strategy/long ║ ma_1day ⊙ 12 ⊙ 31.25%.json',
4673
+ // name: 'long ║ ma_1day ⊙ 12 ⊙ 31.25%.json',
4674
+ // tkid: 'long ║ ma_1day:12',
4675
+ // tid: 'long ║ ma_1day',
4676
+ // levelNumTrade: '12',
4677
+ // rEquivalentCumuProfitOrLossFinalNormYear: '31.25%',
4678
+ // mode: 'long',
4679
+ // ps: [ 'ma_1day' ]
4680
+ // }
4681
+ // ]</code></pre>
4682
+
4683
+
4684
+
4685
+
4686
+ <h5 class="h5-parameters">Parameters:</h5>
4687
+
4688
+
4689
+ <table class="params">
4690
+ <thead>
4691
+ <tr>
4692
+
4693
+ <th>Name</th>
4694
+
4695
+
4696
+ <th>Type</th>
4697
+
4698
+
4699
+ <th>Attributes</th>
4700
+
4701
+
4702
+
4703
+ <th>Default</th>
4704
+
4705
+
4706
+ <th class="last">Description</th>
4707
+ </tr>
4708
+ </thead>
4709
+
4710
+ <tbody>
4711
+
4712
+
4713
+ <tr>
4714
+
4715
+ <td class="name"><code>fd</code></td>
4716
+
4717
+
4718
+ <td class="type">
4719
+
4720
+
4721
+ <span class="param-type">String</span>
4722
+
4723
+
4724
+
4725
+
4726
+ </td>
4727
+
4728
+
4729
+ <td class="attributes">
4730
+
4731
+
4732
+
4733
+
4734
+
4735
+ </td>
4736
+
4737
+
4738
+
4739
+ <td class="default">
4740
+
4741
+ </td>
4742
+
4743
+
4744
+ <td class="description last"><p>輸入儲存策略資料夾字串</p></td>
4745
+ </tr>
4746
+
4747
+
4748
+
4749
+ <tr>
4750
+
4751
+ <td class="name"><code>opt</code></td>
4752
+
4753
+
4754
+ <td class="type">
4755
+
4756
+
4757
+ <span class="param-type">Object</span>
4758
+
4759
+
4760
+
4761
+
4762
+ </td>
4763
+
4764
+
4765
+ <td class="attributes">
4766
+
4767
+ &lt;optional><br>
4768
+
4769
+
4770
+
4771
+
4772
+
4773
+ </td>
4774
+
4775
+
4776
+
4777
+ <td class="default">
4778
+
4779
+ <code>{}</code>
4780
+
4781
+ </td>
4782
+
4783
+
4784
+ <td class="description last"><p>輸入設定物件,預設{}</p>
4785
+ <h6>Properties</h6>
4786
+
4787
+
4788
+ <table class="params">
4789
+ <thead>
4790
+ <tr>
4791
+
4792
+ <th>Name</th>
4793
+
4794
+
4795
+ <th>Type</th>
4796
+
4797
+
4798
+ <th>Attributes</th>
4799
+
4800
+
4801
+
4802
+ <th>Default</th>
4803
+
4804
+
4805
+ <th class="last">Description</th>
4806
+ </tr>
4807
+ </thead>
4808
+
4809
+ <tbody>
4810
+
4811
+
4812
+ <tr>
4813
+
4814
+ <td class="name"><code>readContent</code></td>
4815
+
4816
+
4817
+ <td class="type">
4818
+
4819
+
4820
+ <span class="param-type">Boolean</span>
4821
+
4822
+
4823
+
4824
+
4825
+ </td>
4826
+
4827
+
4828
+ <td class="attributes">
4829
+
4830
+ &lt;optional><br>
4831
+
4832
+
4833
+
4834
+
4835
+
4836
+ </td>
4837
+
4838
+
4839
+
4840
+ <td class="default">
4841
+
4842
+ <code>false</code>
4843
+
4844
+ </td>
4845
+
4846
+
4847
+ <td class="description last"><p>輸入是否讀取策略檔內容布林值,為true時各元素額外提供data欄位,內容非合法json時data為null,預設false</p></td>
4848
+ </tr>
4849
+
4850
+
4851
+ </tbody>
4852
+ </table>
4853
+
4854
+ </td>
4855
+ </tr>
4856
+
4857
+
4858
+ </tbody>
4859
+ </table>
4860
+
4861
+
4862
+
4863
+
4864
+
4865
+
4866
+
4867
+
4868
+
4869
+
4870
+
4871
+
4872
+
4873
+
4874
+
4875
+
4876
+ <h5 class="h5-returns">Returns:</h5>
4877
+
4878
+
4879
+ <div class="param-desc">
4880
+ <p>回傳策略資訊陣列,各元素為{path,name,tkid,tid,levelNumTrade,rEquivalentCumuProfitOrLossFinalNormYear,mode,ps},opt.readContent為true時額外提供data</p>
4881
+ </div>
4882
+
4883
+
4884
+
4885
+ <dl class="param-type">
4886
+ <dt>
4887
+ Type
4888
+ </dt>
4889
+ <dd>
4890
+
4891
+ <span class="param-type">Array</span>
4892
+
4893
+
4894
+
4895
+ </dd>
4896
+ </dl>
4897
+
4898
+
4899
+
4900
+
4901
+
4902
+
4903
+
4904
+
4905
+
4906
+
4907
+
4908
+ </article>
4909
+
4910
+ </section>
4911
+
4912
+
4913
+
4914
+
4915
+
4916
+
4917
+ </div>
4918
+
4919
+ <br class="clear">
4920
+
4921
+ <footer>
4922
+ 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.
4923
+ </footer>
4924
+
4925
+ <script>prettyPrint();</script>
4926
+ <script src="scripts/polyfill.js"></script>
4927
+ <script src="scripts/linenumber.js"></script>
4928
+
4929
+
4930
+
4931
+ </body>
4932
+ </html>