系統識別號 | U0002-2407202419343900 |
---|---|
DOI | 10.6846/tku202400566 |
論文名稱(中文) | 程式交易策略之開發優化與避免過度最佳化之研究 |
論文名稱(英文) | Research on the Development and Optimization of Program Trading Strategies and the Avoidance of Overfitting |
第三語言論文名稱 | |
校院名稱 | 淡江大學 |
系所名稱(中文) | 資訊工程學系碩士在職專班 |
系所名稱(英文) | Department of Computer Science and Information Engineering |
外國學位學校名稱 | |
外國學位學院名稱 | |
外國學位研究所名稱 | |
學年度 | 112 |
學期 | 2 |
出版年 | 113 |
研究生(中文) | 簡大詠 |
研究生(英文) | Da-Yong Jian |
學號 | 711410075 |
學位類別 | 碩士 |
語言別 | 繁體中文 |
第二語言別 | |
口試日期 | 2024-07-15 |
論文頁數 | 126頁 |
口試委員 |
指導教授
-
陳世興(shchen@mail.tku.edu.tw)
口試委員 - 陳宜惠(cyh@mail.cgu.edu.tw) 口試委員 - 陳瑞發(alpha@mail.tku.edu.tw) 口試委員 - 張峯誠(135170@mail.tku.edu.tw) |
關鍵字(中) |
程式交易 交易策略 過度最佳化 |
關鍵字(英) |
Algorithmic trading trading strategies overfitting |
第三語言關鍵字 | |
學科別分類 | |
中文摘要 |
隨著資訊科技的蓬勃發展,程式交易越來越廣泛應用於金融市場,相比於手動交 易,程式交易除了能克服人性追漲殺跌、不守紀律的弱點,還能夠透過回測手段 驗證交易策略的可行性,但在回測的過程中常因為訓練資料不足、過度訓練等原 因,造成過度最佳化的問題。本論文以雙均線交叉、M型態、W型態、盤整突破策 略、均線加布林通道策略,對外匯市場2015年到2022年黃金價格走勢進行績效回 測分析並使用型態組合、加入技術指標、下單量動態控制優化交易策略、提升回 測績效表現。為解決交易策略過度最佳化的問題,本研究使用調控樣本訓練週 期、調控 K 棒週期、減少移動窗格法之參數密度、非最佳化之參數組合、交易 策略參數使用隨機亂數、尋找參數高原這6種方法搭配移動窗格法(walk-forward optimization) 找出程式交易過度最佳化解決之道。本論文所使用的交易策略 在型態策略方面,W型態加上ADX指標總報酬率增加15.53%,但ADX指標對於M型 態則沒有明顯的提升效果。M型態加上ATR指標總報酬率增加0.72%,但 ATR 指標 對於W型態則沒有獲利提升效果,如果結合WM型態與ADX、ATR在相同條件下報酬 率會比只有單純的WM型態增加5.42%,並且營利因子增加38%。在雙均線交叉策 略方面,加入ADX指標的報酬率增加6.5%。同時為了增加營利減少虧損,本研究 加入動態下單量控制,透過偵測帳戶餘額以及止損價差去動態調整每一筆交易 的下單量。由實驗可以發現加上動態下單量控制,WM型態策略報酬率增加37%, 盤整突破策略報酬率增加54%,雙均線交叉策略報酬率增加8.3%。 |
英文摘要 |
With the rapid development of information technology, algorithmic trading is becoming increasingly prevalent in financial markets. Compared to manual trading, algorithmic trading overcomes human weaknesses such as emotional trading and lack of discipline, and can verify the feasibility of trading strategies through backtesting. However, backtesting can lead to overfitting due to insufficient training data or too many adjustable parameters. This thesis conducts performance backtesting on Forex market gold price trends from 2015 to 2022 using strategies like double moving average crossover, M pattern, W pattern, range breakout, and moving average combined with Bollinger Bands. It proposes optimizing trading strategies through pattern combinations, additional technical indicators, and dynamic order quantity control to enhance performance. To address overfitting, six methods are employed: adjusting the sample training period, changing the candlestick period, reducing optimization parameter density, using non-optimized parameter combinations, employing random numbers, and searching for parameter plateaus, combined with walk-forward optimization. For the WM pattern, adding the ADX indicator increased the return rate by 15.53%, while the ATR indicator increased the M pattern's return by 0.72%. Combining these improved the return rate by 5.42% and the profit factor by 38%. The double moving average strategy saw a 6.5% increase in return rate with the ADX indicator. The experiments showed that adding dynamic order quantity control increased the return rate of the WM pattern strategy by 37%, the range breakout strategy by 54%, and the double moving average crossover strategy by 8.3%. |
第三語言摘要 | |
論文目次 |
致謝 摘要 i Abstract iii 目錄 vi 圖目錄 ix 表目錄 xii 第一章 緒論 1 1.1 研究背景 . ................................1 1.2 研究動機 . ................................2 1.3 研究目的 . ................................3 1.4 論文架構 . ................................4 第二章 文獻探討 5 2.1 交易策略之探討 . ............................5 2.2 評估指標 . ................................12 2.3 過度最佳化 . ...............................15 第三章 研究方法設計 19 3.1 W 型態交易策略 . ............................21 3.2 M 型態交易策略 . ............................24 3.3 ADX 與 ATR 指標納入 M、W 型態之策略優化 . ...........28 3.4 雙均線交叉策略 . ............................35 3.5 針形 K 棒與 ADX 納入雙均線交叉策略之優化 . ...........35 3.6 盤整突破策略 . .............................38 3.7 布林通道結合 MA 突破策略 . .....................41 3.8 下單量加入倉位風險管控 . .......................42 3.9 移動窗格法找出最佳參數組合 . ....................44 3.10 過度最佳化之解決之道 . ........................50 第四章 研究結果與呈現 60 4.1 W 型態、M 型態策略回測結果分析 . .................61 4.2 ADX 與 ATR 指標納入 W、M 型態之交易回測分析 . ........66 4.3 針型 K 棒與 ADX 納入雙均線交叉策略回測分析 . ..........72 4.4 盤整突破策略回測分析 . ........................73 4.5 布林通道結合 MA 突破策略回測分析 . ................74 4.6 下單量風險控管納入交易策略 . ....................74 4.7 移動窗格法找尋交易策略最佳化參數 . ................77 4.8 交易策略過度最佳化之解決之道 . ...................84 4.9 績效比對 . ................................102 第五章 結論與未來展望 108 5.1 結論 . ...................................108 5.2 未來展望 . ................................109 參考文獻 111 附錄 1 — 移動窗格法之亂數回測 116 附錄 2 — 最佳化與回測階段排名之差異比較之詳細結果 121 圖目錄 2.1 SMA 策略示意圖 (紅線 20 日,黃線 50 日) . ..............6 2.2 MACD 策略示意圖 . ...........................9 2.3 M 與 W 型態示意圖 . ...........................10 2.4 RSI 策略示意圖 . .............................11 2.5 支撐阻力策略示意圖 . ..........................11 2.6 布林通道策略示意圖 . ..........................12 3.1 W 型態示意圖 . ..............................21 3.2 W 市價買入策略示意圖 . .........................22 3.3 W 市價做多策略流程圖 . .........................23 3.4 W 限價做多示意圖 . ............................24 3.5 M 型態示意圖 . ..............................25 3.6 M 市價做空策略示意圖 . .........................26 3.7 M 市價做空策略流程圖 . .........................27 3.8 M 限價做空策略示意圖 . .........................28 3.9 W、M 限價交易 +ATR 策略流程圖 . ..................33 3.10 W、M 限價交易 +ADX 策略流程圖 . ..................34 3.11 雙均線金叉死叉交易策略流程圖 . ....................35 3.12 UPpinbar 與 Downpinbar 示意圖 . ....................37 3.13 channelbreakout 策略流程圖 . ......................39 3.14 布林通道結合 MA 突破策略做多 . ....................42 3.15 布林通道結合 MA 突破策略做空 . ....................42 3.16 MT5 的可視覺化界面可以看出下單量隨著總資產增減而有所變化 . .44 3.17 Walk-ForwardOptimization 示意圖 . ...................45 3.18 損益平衡的情況下勝率與盈虧比之關係 . . . . . . . . . . . . . . . . 48 3.19 使用 MT5 進行快速遺傳學演算法回測 . ................49 3.20 設定欲優化的參數值,start: 起始值,stop: 終止值,step: 等差值 . ..50 3.21 績效由高到低排列出所有組合的盈利表現 . ..............50 3.22 美林時鐘景氣循環圖 . ..........................53 3.23 移動窗格法 3 年 +1 年 . ..........................54 3.24 移動窗格法 4 年 +1 年 . ..........................55 3.25 MT5 介面,選擇不同的 K 棒週期 . ...................56 3.26 MT5 之快速遺傳演算法 . .........................57 4.1 W 市價做多回測 (止損 zigzag[1]),2015 -2022,GOLD,H4 週期 . .61 4.2 W 市價做多回測 (止損 zigzag[3]),2015 -2022,GOLD,H4 週期 . .61 4.3 W 限價做多回測 (止損 zigzag[1]),2015 -2022,GOLD,H4 週期 . .62 4.4 W 限價做多回測 (止損 zigzag[3]),2015 -2022,GOLD,H4 週期 . .62 4.5 M 市價做空回測 (止損 zigzag[1]),2015 -2022,GOLD,H4 週期 . .63 4.6 M 市價做空回測 (止損 zigzag[3]),2015 -2022,GOLD,H4 週期 . .64 4.7 M 市價做空回測 (止損 zigzag[1]),2015 -2022,GOLD,H4 週期 . .65 4.8 M 限價做空回測 (止損設為 zigzag[3]),2015 -2022,GOLD,H4 週期 65 4.9 M 限價賣空 +ADX 指標,2015 -2022,GOLD,H4 週期 . ......68 4.10 W、M 限價買入 +ADX 指標,2015 -2022,GOLD,H4 週期 . ...68 4.11W 限價買入 +ATR 指標,2015 -2022,GOLD,H4 週期 . ......69 4.12 M 限價做空入 +ATR 指標,2015 -2022,GOLD,H4 週期 . .....69 4.13 雙均線 +pinbar+ADX 回測,2015 -2022,GOLD,H4 週期 . .....73 4.14 盤整突破策略回測,2015 -2022,GOLD,H4 週期 . .........73 4.15 布林通道突破結合 MA 策略回測,2015-2022,黃金,H4 週期 . ...74 4.16 W、M 限價單 +ATR+ 倉位風險控管,2015-2022,GOLD,H4 週期 . 75 4.17 雙均線 +pinbar+ADX+ 倉位風險控管,2015-2022,GOLD,H4 週期 76 4.18 盤整突破策略 + 倉位風險控管,2015 -2022,GOLD,H4 週期 . ..76 4.19 布林通道 +MA+ 倉位風險控管,2015-2022,GOLD,H4 週期 . ...77 4.20 參數密度對於程式交易過度最佳化之影響 . ..............92 4.21 移動窗格法示意圖 . ............................94 4.22 X 軸布林通道週期,Y 軸移動平均線,Z 軸營利結果 . ........97 4.23 X 軸布林通道標準差,Y 軸移動平均線,Z 軸營利結果 . .......98 4.24 X 軸布林通道標準差,Y 軸停損範圍,Z 軸營利結果 . ........98 4.25 X 軸布林通道標準差,Y 軸停利範圍,Z 軸營利結果 . ........98 4.26 X 軸移動平均線參數,Y 軸停損範圍,Z 軸營利結果 . ........98 4.27 X 軸移動平均線參數,Y 軸停利範圍,Z 軸營利結果 . ........99 4.30 X 軸停損範圍,Y 軸停利範圍,Z 軸營利結果 . ............101 表目錄 3.1 A 時期,最佳化參數: shortMA:25,long MA:195 . ..........51 3.2 B 時期,最佳化參數:short MA:15,long MA:120 . ...........51 3.3 C 時期,最佳化參數:short MA:20,long MA:85 . ...........51 3.4 D 時期,最佳化參數: shortMA:5,long MA:125 . ...........51 3.5 技術指標的參數設定 . ..........................58 4.1 W 市價做多策略回測報表重點 (止損 zigzag[1]) . ............61 4.2 W 市價做多策略回測報表重點 (止損 zigzag[3]) . ............61 4.3 W 限價做空策略回測報表重點止損 (zigzag[1]) . ............63 4.4 W 限價做空策略回測報表重點 (止損 zigzag[3]) . ............63 4.5 M 市價做空回測報表重點止損 (zigzag[1]) . ...............64 4.6 M 市價做空回測報表重點止損 (zigzag[3]) . ...............64 4.7 M 市價做空回測報表重點止損 (zigzag[1]) . ...............65 4.8 M 限價做空回測報表重點 (止損設為 zigzag[3]) . ............65 4.9 W 市價、限價,M 市價、限價回測總攬 . ...............66 4.10 W 限價買入 +ATR 回測重點 . ......................67 4.11W 限價買入 +ATR 回測重點 . ......................68 4.12 W、M 限價 +ADX 回測重點 . ......................68 4.13 W 限價買入 +ATR 回測重點 . ......................69 4.14 M 限價做空 +ATR 指標回測重點 . ....................70 4.15 W 限價、M 限價 +ATR 回測重點 . ...................70 4.16 W 限價、M 限價 +ATR+ADX 回測重點 . ................71 4.17 WM 型態策略分別加上 ADX、ATR 的回測比較 . ...........72 4.18 雙均線交叉加上 pinbar 與否之績效回測比較 . .............73 4.19 盤整突破策略回測報表重點 . ......................74 4.20 布林通道突破結合 MA 策略回測報表重點 . ..............74 4.21 W、M 限價買入 +ATR 指標比較加上倉位風險控管之差異 . .....75 4.22 雙均線交叉加上 pinbar 與否之績效回測比較 . .............76 4.23 盤整突破策略 + 倉位風險控管與否之績效回測比較 . .........76 4.24 布林通道 +MA 策略倉位風險控管與否之績效比較 . ..........77 4.25 加上下單量風險控管總報酬率都有所提升 . ..............77 4.26 A 時期,最佳化參數: shortMA:25,long MA:195 . ..........78 4.27 B 時期,最佳化參數:short MA:15,long MA:120 . ...........78 4.28 C 時期,最佳化參數:short MA:20,long MA:85 . ...........78 4.29 D 時期,最佳化參數: shortMA:5,long MA:125 . ...........79 4.30 A 時期,最佳化參數:msl =300;mtp=1.5 . ...............80 4.31 B 時期,最佳化參數::msl =150;mtp=1.0 . ...............80 4.32 C 時期,最佳化參數: msl=150;mtp=5.0 . ...............80 4.33 D 時期,最佳化參數:msl =300;mtp=5.0 . ...............80 4.34 A 時期,最佳化參數: 盤整 K 棒數量:5,MA: 9 . ............81 4.35 B 時期,最佳化參數: 盤整 K 棒數量:5,MA: 28 . ...........81 4.36 C 時期,最佳化參數: 盤整 K 棒數量:13,MA: 5 . ...........81 4.37 D 時期,最佳化參數: 盤整 K 棒數量:5,MA: 9 . ...........81 4.38 A 時期,最佳化參數:BBP:25,BBd:3,MA: 20,ATR:2 . ........83 4.39 B 時期,最佳化參數:BBP:5,BBd:4,MA: 5,ATR:2 . ..........83 4.40 C 時期,最佳化參數:BBP:20,BBd:4,MA: 10,ATR:0.5 . .......83 4.41 D 時期,最佳化參數:BBP:10,BBd:4,MA:30,ATR:2 . .........84 4.42 最佳化時期與回測時期之比例 (WM+ATR+ADX 策略) . ........85 4.43 最佳化時期與回測時期之比例 (雙均線 +pinbar+ADX) . ........86 4.44 最佳化時期與回測時期之比例 (布林通道 +MA) . ...........87 4.45 雙均線交叉策略使用 H1 週期透過移動窗格法找尋最佳化參數 . ...89 4.46 雙均線交叉策略使用 H4 週期透過移動窗格法找尋最佳化參數 . ...89 4.47 WM 限價 +ATR 使用 H1 週期透過移動窗格法找尋最佳化參數 . ...90 4.48 WM 限價 +ATR 使用 H4 週期透過移動窗格法找尋最佳化參數 . ...91 4.49 技術指標的參數設定 . . .........................93 4.50 MA+ 布林通道策略亂數加入與否之最佳化與回測之盈餘差異 . ...94 4.51 MA+ 布林通道策略亂數加入與否之最佳化與回測之盈餘排名差異 . .95 4.52 WM+ATR+ADX 策略亂數加入與否之最佳化與回測之盈餘差異 . ..95 4.53 WM+ATR+ADX 策略亂數加入與否之最佳化與回測之盈餘排名差異 95 4.54 布林通道 +MA 策略原始參數範圍 . ...................97 4.55 布林通道 +MA 策略參數高原之參數範圍 . ...............99 4.56 雙均線交叉 +pinbar+ADX 策略原始參數範圍 . .............99 4.57 雙均線交叉 +pinbar+ADX 策略參數高原之參數範圍 . .........100 4.58 WM+ADX+ATR 策略原始參數範圍 . ..................101 4.62 葉佳霖使用的移動窗格法週期 . .....................103 4.63 葉佳霖的實驗數據 . ............................103 4.64 本論文 W+M+ATR+ADX 策略 . .....................104 4.65 本論文布林通道 +MA 策略 . .......................104 4.66 本論文雙均線交叉 +Pinbar+ADX 策略 . .................105 4.67 張天禹的實驗數據 . ............................105 4.71 本研究與張天禹之實驗結果比對 . ....................106 |
參考文獻 |
[1] Kendall Kim and J. Kaljuvee. The growth of program and algorithmic trading. Journal of Trading Strategies, pages 29–38, 2007. [2] Woo–baik Lee, J. Park, and S. Jordan. Scalpel or hatchet? program trade regulation. ERN: Financial Markets (Topic), 2009. [3] 林泓志. 多商品相關性獲利穩定度分析與比較. Master’s thesis, 國立中央大學, 2020. 臺灣博碩士論文知識加值系統. [4] W. Brock, J. Lakonishok, and B. LeBaron. 簡單技術交易規則與股票回報的隨機 特性. 金融學期刊, 47(5):1731–1764, 1992. [5] R. A. Kiehl and V. A. Alexandria. 技術指標的開發與應用. 投資組合管理期刊, 21(4):45–52, 1995. [6] J. Bollinger. 布林通道. McGraw Hill 專業出版, 2002. [7] Christopher J. Neely, David E. Rapach, Jun Tu, and Guofu Zhou. Forecasting the equity risk premium: The role of technical indicators. Management Science, 60(7):1772–1791, 2014. [8] 許嘉恩. 利用移動窗格法驗證程式交易策略樣本內外穩健性的自動化平台設計研究. Master’s thesis, 國立中央大學, 臺灣, 2018. 臺灣博碩士論文知識加值系統. [9] L. Trujillo, S. Silva, P. Legrand, and L. Vanneschi. An empirical study of functional complexity as an indicator of overfitting in genetic programming. In Proceedings of the ..., 2011. [10] T. Mills. Business cycle asymmetry and duration dependence: An international perspective. Journal of Applied Statistics, 28:713 – 724, 2001. [11] J. James. Robustness of simple trend-following strategies. Quantitative Finance, 3:C114–C116, 2003. [12] Yufeng Han, Ke Yang, and Guofu Zhou. A new anomaly: The cross-sectional profitability of technical analysis. Journal of Financial and Quantitative Analysis, 2011. [13] Curtis Faith. Trend following trading strategies and systems. Quantified Strategies, 2006. [14] Pat Tong Chio. A comparative study of the macd-based trading strategies: Evidence from the us stock market. arXiv preprint arXiv:2206.12282, 2022. [15] P. E. Swanson and A. Y. Lin. Trading behavior and investment performance of u.s. investors in global equity markets. Journal of Multinational Financial Management, 15:99–115, 2005. [16] Louis K. C. Chan, Narasimhan Jegadeesh, and Josef Lakonishok. The profitability of momentum strategies. Financial Analyst, 1999. [17] Gil Cohen and Elinor Cabiri. Can technical oscillators outperform the buy and hold strategy? Applied Economics, 2015 [18] T. Chong and W. Ng. Technical analysis and the london stock exchange: testing the macd and rsi rules using the ft30. Applied Economics Letters, 2008. [19] M. Dempster and C. M. Jones. Can channel pattern trading be profitably automated? The European Journal of Finance, 8:275–301, 2002. [20] R. Yan, Z. Pei, and C. Myers. Do channel members value the multiple-cooperation strategy? Journal of Retailing and Consumer Services, 30:84–95, 2016. [21] J. M. Leung and T. Chong. An empirical comparison of moving average envelopes and bollinger bands. Applied Economics Letters, 10:339–341, 2003. [22] Xiaohua Han, Yingtao Shen, and Yiwen Bian. Optimal recovery strategy of manufacturers: Remanufacturing products or recycling materials? Annals of Operations Research, 290:463–489, 2018. [23] Wesley Gray and Jack R. Vogel. Using maximum drawdowns to capture tail risk. Capital Markets: Asset Pricing & Valuation eJournal, 2013. [24] 蘇育樟. 樣式探勘方法應用於台指期貨當沖交易之研究. Master’s thesis, 國立 中興大學, 2015. 臺灣博碩士論文知識加值系統. [25] M. Dempster, T. W. Payne, Yazann S. Romahi, and G. Thompson. Title of the article. Journal Name, Volume Number(Issue Number):Page Range, 2001. Additional Information. [26] Jianwen Fang. A critical review of five machine learning-based algorithms for predicting protein stability changes upon mutation. Briefings in bioinformatics, 2019. [27] J. Subramanian and R. Simon. Overfitting in prediction models - is it a problem only in high dimensions? Contemporary clinical trials, 2013. [28] John Rust, John H. Miller, and R. Palmer. Characterizing effective trading strategies: Insights from a computerized double auction tournament. Journal of Economic Dynamics and Control, 18:61–96, 1994. [29] David H. Bailey, Jonathan M. Borwein, Marcos López de Prado, and Qiji Jim Zhu. The probability of backtest overfitting. Journal of Computational Finance, 18(2):19– 39, 2014. [30] Ryan Sullivan, Allan Timmermann, and Halbert White. Data-snooping, technical trading rule performance, and the bootstrap. Journal of Finance, 54(5):1647–1691, 1999. [31] 潘靜怡. 以技術分析 w 底型態建構台指期交易策略之實證研究. Master’s thesis, 朝陽科技大學, 臺灣, 2011. 臺灣博碩士論文知識加值系統. [32] J. Welles Wilder. New Concepts in Technical Trading Systems. Trend Research, 1978. [33] The Forex Geek. Pin bar candlestick pattern. The Forex Geek, 2024. [34] Shing yang Hu. A simple estimate of noise and its determinant in a call auction market. Capital Markets: Market Efficiency, 2004. [35] J. Danthine and Serge Moresi. Volatility, information and noise trading. European Economic Review, 37:961–982, 1993. [36] R. Mestel, Michael Murg, and E. Theissen. Algorithmic trading and liquidity: Long term evidence from austria. Finance Research Letters, 2018. [37] Si Ying Lim, Zi Kai Soh, and Xiang Zhou. A study of trading strategies: average true range. Journal of Financial Markets, 2012. [38] 葉佳霖. 應用平滑支撐向量機於黃金現貨的投資策略與績效評比. Master’s thesis, 國立臺灣科技大學, 2012. 臺灣博碩士論文知識加值系統. [39] 張天禹. 技術分析應用於外匯交易之研究. Master’s thesis, 東吳大學, 2015. 碩 士論文. |
論文全文使用權限 |
如有問題,歡迎洽詢!
圖書館數位資訊組 (02)2621-5656 轉 2487 或 來信