<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	
	xmlns:georss="http://www.georss.org/georss"
	xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#"
	>

<channel>
	<title>徵稿作品 &#8211; FinLab</title>
	<atom:link href="https://www.finlab.tw/tag/%E5%BE%B5%E7%A8%BF%E4%BD%9C%E5%93%81/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.finlab.tw</link>
	<description>深入淺出的量化投資，讓你在在茫茫股海中，找到專屬於自己的投資方法</description>
	<lastBuildDate>Wed, 25 May 2022 07:46:20 +0000</lastBuildDate>
	<language>zh-TW</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.0.9</generator>

<image>
	<url>https://www.finlab.tw/wp-content/uploads/2020/07/favicon.png</url>
	<title>徵稿作品 &#8211; FinLab</title>
	<link>https://www.finlab.tw</link>
	<width>32</width>
	<height>32</height>
</image> 
<site xmlns="com-wordpress:feed-additions:1">179699571</site>	<item>
		<title>Finlab 量化平台徵稿活動得獎作品 集技術面和籌碼面於一身的的AI選股策略-陳士謀</title>
		<link>https://www.finlab.tw/finlab_submit1/</link>
					<comments>https://www.finlab.tw/finlab_submit1/#respond</comments>
		
		<dc:creator><![CDATA[陳 士謀]]></dc:creator>
		<pubDate>Wed, 09 Feb 2022 12:58:00 +0000</pubDate>
				<category><![CDATA[AI看股票]]></category>
		<category><![CDATA[徵稿作品]]></category>
		<guid isPermaLink="false">https://www.finlab.tw/?p=3270</guid>

					<description><![CDATA[AI選股策略介紹 機器學習是現今人工智慧(AI)浪潮下的代表性技術，將機器學習演算法應用至股市交易是本次研究著 [&#8230;]]]></description>
										<content:encoded><![CDATA[
<h1>AI選股策略介紹</h1>



<p>機器學習是現今人工智慧(AI)浪潮下的代表性技術，將機器學習演算法應用至股市交易是本次研究著重的重點，目的是探討在台灣股市中同時使用技術面和籌碼面的資料來訓練機器學習模型並預測交易訊號會有怎樣的表現，希望能找出籌碼面資料與技術面資料哪一個更為重要的答案。</p>



<p>本次機器學習模型的任務是迴歸，迴歸各標的未來一周的報酬率分布，由於各標的報酬率範圍落差極大，所以在製作標籤時對周報酬率採取了排名運算，並將其縮放至0～1，因此模型預測出來的數值也會介於0～1之間，若數值偏向0表示未來ㄧ周模型認為該標的上漲機會低；反之，若數值偏向1表示未來一周模型認為該標的上漲機會高。</p>



<p>因此，交易策略的使用方式便是每周從數百檔標的中取出預測值最高的一檔做為買入訊號，每次買入後持有時間固定為一周，若本周最高的一檔和上周的相同則不做任何操作，若不同則先將上周的標的清倉，再買入本周預測數值最高的標的。</p>



<h1>資料</h1>



<h2>標的池</h2>



<p>從Finlab獲取所有台灣股市標的（含股票、ETF等），並限定標的需要在2013/01/05以前就有價格資料，再扣除一些價格有缺失值的標的後，剩下標的池近700檔。</p>



<h2>訓練、驗證、測試資料切分<br></h2>



<p>從Finlab獲取上述標的池的股價資料，從2013/01年至2021/12年，由於2013-2014年的資料在計算特徵時使用了移動窗格，會出現缺失值，因此在計算完特徵後將前面的缺失值刪除，留下了2014年至2019年近六年的資料做為訓練資料；此外，2020一整年做為驗證資料、2021年至今做為測試資料。<br></p>



<h2>技術面特徵</h2>



<p>技術面特徵泛指各種使用開高低收量其中一種以上的數據計算而成的特徵。</p>



<p>首先，從Finlab獲取上述標的池的開高低收價格資料，再用這些資料作為材料計算各種技術面特徵。其中包含一日報酬率取對數、年化波動率、GitHub 上著名計算技術指標套件Ta-Lib裡的大多數技術指標，裡面包含MACD、RSI、K線型態等共100多個技術指標欄位，由於程式碼繁雜、篇幅過長，故不在此詳列。</p>



<figure class="wp-block-image size-full"><img width="602" height="193" src="https://www.finlab.tw/wp-content/uploads/2022/02/圖片.png" alt="圖片" class="wp-image-3273" srcset="https://www.finlab.tw/wp-content/uploads/2022/02/圖片.png 602w, https://www.finlab.tw/wp-content/uploads/2022/02/圖片-300x96.png 300w" sizes="(max-width: 602px) 100vw, 602px" title="Finlab 量化平台徵稿活動得獎作品 集技術面和籌碼面於一身的的AI選股策略-陳士謀 1"></figure>



<h2>籌碼面特徵</h2>



<p>資料源為Finlab，包含三大法人進出、上市櫃合計、上市櫃外資、上市櫃外資及陸資、上市櫃外資自營商、上市櫃投信、上市櫃自營商自行買賣、避險、上櫃三大法人合計等數據。以下幾個買賣超數據由於各標的分布落差極大，所以特別使用rank將原數值轉換至0～1的數值放以便於模型學習。</p>



<p>資料源為Finlab，包含三大法人進出、上市櫃合計、上市櫃外資、上市櫃外資及陸資、上市櫃外資自營商、上市櫃投信、上市櫃自營商自行買賣、避險、上櫃三大法人合計等數據。以下幾個買賣超數據由於各標的分布落差極大，所以特別使用rank將原數值轉換至0～1的數值放以便於模型學習。</p>



<pre class="wp-block-code"><code lang="python" class="language-python">data.get('institutional_investors_trading_all_market_summary:買賣超').rank(pct=True, axis=1)
data.get('institutional_investors_trading_summary:外陸資買賣超股數(不含外資自營商)').rank(pct=True, axis=1)
data.get('institutional_investors_trading_summary:外資自營商買賣超股數').rank(pct=True, axis=1)
data.get('institutional_investors_trading_summary:投信買賣超股數').rank(pct=True, axis=1)
data.get('institutional_investors_trading_summary:自營商買賣超股數(自行買賣)').rank(pct=True, axis=1)
data.get('institutional_investors_trading_summary:自營商買賣超股數(避險)').rank(pct=True, axis=1)
</code></pre>



<figure class="wp-block-image size-full"><img loading="lazy" width="602" height="193" src="https://www.finlab.tw/wp-content/uploads/2022/02/圖片-1.png" alt="圖片 1" class="wp-image-3274" srcset="https://www.finlab.tw/wp-content/uploads/2022/02/圖片-1.png 602w, https://www.finlab.tw/wp-content/uploads/2022/02/圖片-1-300x96.png 300w" sizes="(max-width: 602px) 100vw, 602px" title="Finlab 量化平台徵稿活動得獎作品 集技術面和籌碼面於一身的的AI選股策略-陳士謀 2"></figure>



<h2>預測標籤</h2>



<p>模型預測的數值為未來一周報酬率的分布。標籤計算方式為先計算每周報酬率，再平移一周變成未來一周報酬率，最後將各標的報酬率做排名，並縮放至0~1，此數值可以做為區分未來一周報酬率的分布情形，若有一檔標的數值偏向0表示未來一周該標的有偏低的報酬率；若有一檔標的數值偏向1表示未來一周該標的有偏高的報酬率。</p>



<figure class="wp-block-image size-full"><img loading="lazy" width="84" height="384" src="https://www.finlab.tw/wp-content/uploads/2022/02/圖片-2.png" alt="圖片 2" class="wp-image-3278" title="Finlab 量化平台徵稿活動得獎作品 集技術面和籌碼面於一身的的AI選股策略-陳士謀 3"></figure>



<h2>資料處理</h2>



<p>將上述所有資料計算完成後，使用date日期或是ticker股票代號做為鍵來merge各種資料，並將X和y整合進一個大DataFrame。最終，缺失值統一以0填補。</p>



<h1>模型</h1>



<h2>模型訓練</h2>



<p>本次使用的模型為CatBoost Regressor，CatBoost與XGBoost、LightGBM齊名三大決策樹巨頭模型，特色在於對多維度的類別特徵能做更有效的提取。使用CPU訓練1000回合並使用驗證資料衡量訓練的優劣後，RMSE從0.2838迅速下降至0.2627，並在第九十六回合就達到了最低的RMSE。</p>



<p></p>



<figure class="wp-block-image size-full"><img loading="lazy" width="602" height="85" src="https://www.finlab.tw/wp-content/uploads/2022/02/圖片-3.png" alt="圖片 3" class="wp-image-3279" srcset="https://www.finlab.tw/wp-content/uploads/2022/02/圖片-3.png 602w, https://www.finlab.tw/wp-content/uploads/2022/02/圖片-3-300x42.png 300w" sizes="(max-width: 602px) 100vw, 602px" title="Finlab 量化平台徵稿活動得獎作品 集技術面和籌碼面於一身的的AI選股策略-陳士謀 4"></figure>



<figure class="wp-block-image size-full"><img loading="lazy" width="602" height="128" src="https://www.finlab.tw/wp-content/uploads/2022/02/圖片-4.png" alt="圖片 4" class="wp-image-3280" srcset="https://www.finlab.tw/wp-content/uploads/2022/02/圖片-4.png 602w, https://www.finlab.tw/wp-content/uploads/2022/02/圖片-4-300x64.png 300w" sizes="(max-width: 602px) 100vw, 602px" title="Finlab 量化平台徵稿活動得獎作品 集技術面和籌碼面於一身的的AI選股策略-陳士謀 5"></figure>



<h2>特徵重要性</h2>



<p>由模型的特徵重要性圖表可以看到，BOP、DIV、K線型態、上櫃自營商，這幾種指標是模型認為滿重要的指標。雖然技術面指標佔據了模型重要性的前幾名，但根據圖表也能發現有不少關於籌碼面的欄位在模型學習上起到了不小的作用，表明籌碼面的數據確實可以互補眾多技術指標無法捕捉到的角度，也再次印證了機器學習流程中，特徵工程扮演著極為重要的角色。</p>



<figure class="wp-block-image size-full"><img loading="lazy" width="484" height="650" src="https://www.finlab.tw/wp-content/uploads/2022/02/圖片-5.png" alt="圖片 5" class="wp-image-3281" srcset="https://www.finlab.tw/wp-content/uploads/2022/02/圖片-5.png 484w, https://www.finlab.tw/wp-content/uploads/2022/02/圖片-5-223x300.png 223w" sizes="(max-width: 484px) 100vw, 484px" title="Finlab 量化平台徵稿活動得獎作品 集技術面和籌碼面於一身的的AI選股策略-陳士謀 6"></figure>



<h1>績效</h1>



<p>這裡將每周模型預測出來的數值分成4組分別進行回測，第一組為每周只購買模型預測數值最高的一檔，第二組為每周只購買模型預測數值最高的前兩檔，依此類推。</p>



<h2>AI 第一名 策略</h2>



<p>由下圖可以看到，2021年ㄧ年的表現可說是如過山車ㄧ般，從最高的近250%高點一路回撤至近期12月的86%左右，即使報酬雖然從高點到最後被腰斬，但整體大部分時間仍勝過大盤。</p>



<p>總體來說，這個策略報酬率雖然看似不錯，但風險與獲利穩定性不佳，推測其原因可能在於只買一檔，容錯性太低，模型若稍有錯誤該周就完全沒機會了，因此下面我們來看如果增加檔數會有怎樣的結果。</p>



<figure class="wp-block-image size-full"><img loading="lazy" width="602" height="184" src="https://www.finlab.tw/wp-content/uploads/2022/02/圖片-6.png" alt="圖片 6" class="wp-image-3282" srcset="https://www.finlab.tw/wp-content/uploads/2022/02/圖片-6.png 602w, https://www.finlab.tw/wp-content/uploads/2022/02/圖片-6-300x92.png 300w" sizes="(max-width: 602px) 100vw, 602px" title="Finlab 量化平台徵稿活動得獎作品 集技術面和籌碼面於一身的的AI選股策略-陳士謀 7"></figure>



<figure class="wp-block-image size-full"><img loading="lazy" width="602" height="336" src="https://www.finlab.tw/wp-content/uploads/2022/02/圖片-7.png" alt="圖片 7" class="wp-image-3283" srcset="https://www.finlab.tw/wp-content/uploads/2022/02/圖片-7.png 602w, https://www.finlab.tw/wp-content/uploads/2022/02/圖片-7-300x167.png 300w" sizes="(max-width: 602px) 100vw, 602px" title="Finlab 量化平台徵稿活動得獎作品 集技術面和籌碼面於一身的的AI選股策略-陳士謀 8"></figure>



<figure class="wp-block-image size-full"><img loading="lazy" width="602" height="445" src="https://www.finlab.tw/wp-content/uploads/2022/02/圖片-8.png" alt="圖片 8" class="wp-image-3284" srcset="https://www.finlab.tw/wp-content/uploads/2022/02/圖片-8.png 602w, https://www.finlab.tw/wp-content/uploads/2022/02/圖片-8-300x222.png 300w" sizes="(max-width: 602px) 100vw, 602px" title="Finlab 量化平台徵稿活動得獎作品 集技術面和籌碼面於一身的的AI選股策略-陳士謀 9"></figure>



<h2>AI 前兩名 策略</h2>



<p>加入第二名後，可以發現最大回撤從原本的60%下降至40%左右，雖然報酬率也有小幅下降，但整體Sharpe Ratio還是1.3，印證增加至前兩名確實可以達到分散風險的效果。</p>



<figure class="wp-block-image size-full"><img loading="lazy" width="602" height="184" src="https://www.finlab.tw/wp-content/uploads/2022/02/圖片-9.png" alt="圖片 9" class="wp-image-3285" srcset="https://www.finlab.tw/wp-content/uploads/2022/02/圖片-9.png 602w, https://www.finlab.tw/wp-content/uploads/2022/02/圖片-9-300x92.png 300w" sizes="(max-width: 602px) 100vw, 602px" title="Finlab 量化平台徵稿活動得獎作品 集技術面和籌碼面於一身的的AI選股策略-陳士謀 10"></figure>



<figure class="wp-block-image size-full"><img loading="lazy" width="602" height="336" src="https://www.finlab.tw/wp-content/uploads/2022/02/圖片-10.png" alt="圖片 10" class="wp-image-3286" srcset="https://www.finlab.tw/wp-content/uploads/2022/02/圖片-10.png 602w, https://www.finlab.tw/wp-content/uploads/2022/02/圖片-10-300x167.png 300w" sizes="(max-width: 602px) 100vw, 602px" title="Finlab 量化平台徵稿活動得獎作品 集技術面和籌碼面於一身的的AI選股策略-陳士謀 11"></figure>



<figure class="wp-block-image size-full"><img loading="lazy" width="602" height="448" src="https://www.finlab.tw/wp-content/uploads/2022/02/圖片-11.png" alt="圖片 11" class="wp-image-3287" srcset="https://www.finlab.tw/wp-content/uploads/2022/02/圖片-11.png 602w, https://www.finlab.tw/wp-content/uploads/2022/02/圖片-11-300x223.png 300w" sizes="(max-width: 602px) 100vw, 602px" title="Finlab 量化平台徵稿活動得獎作品 集技術面和籌碼面於一身的的AI選股策略-陳士謀 12"></figure>



<h2>AI 前四名 策略</h2>



<p>加入第二名有效，那再加一些呢？如果換成前四名，可以看到最大回撤更是進一步地降低至20%左右，雖然報酬率再次下降，但整體穩定度提升了許多，不再發生獲利大回吐的情況，Sharpe Ratio也增加至1.4，為目前最優的一個策略。</p>



<figure class="wp-block-image size-full"><img loading="lazy" width="602" height="184" src="https://www.finlab.tw/wp-content/uploads/2022/02/圖片-12.png" alt="圖片 12" class="wp-image-3288" srcset="https://www.finlab.tw/wp-content/uploads/2022/02/圖片-12.png 602w, https://www.finlab.tw/wp-content/uploads/2022/02/圖片-12-300x92.png 300w" sizes="(max-width: 602px) 100vw, 602px" title="Finlab 量化平台徵稿活動得獎作品 集技術面和籌碼面於一身的的AI選股策略-陳士謀 13"></figure>



<figure class="wp-block-image size-full"><img loading="lazy" width="602" height="333" src="https://www.finlab.tw/wp-content/uploads/2022/02/圖片-13.png" alt="圖片 13" class="wp-image-3289" srcset="https://www.finlab.tw/wp-content/uploads/2022/02/圖片-13.png 602w, https://www.finlab.tw/wp-content/uploads/2022/02/圖片-13-300x166.png 300w" sizes="(max-width: 602px) 100vw, 602px" title="Finlab 量化平台徵稿活動得獎作品 集技術面和籌碼面於一身的的AI選股策略-陳士謀 14"></figure>



<figure class="wp-block-image size-full"><img loading="lazy" width="602" height="452" src="https://www.finlab.tw/wp-content/uploads/2022/02/圖片-14.png" alt="圖片 14" class="wp-image-3290" srcset="https://www.finlab.tw/wp-content/uploads/2022/02/圖片-14.png 602w, https://www.finlab.tw/wp-content/uploads/2022/02/圖片-14-300x225.png 300w" sizes="(max-width: 602px) 100vw, 602px" title="Finlab 量化平台徵稿活動得獎作品 集技術面和籌碼面於一身的的AI選股策略-陳士謀 15"></figure>



<h1>結論與未來展望</h1>



<p>本研究比較了籌碼面資料對於選股策略的有效性，也從機器學習模型中了解到演算法認為究竟是哪些技術面或籌碼面的資料對未來一週的報酬率分布更有預測能力。因此，本研究認為對於台股而言，除了技術面指標以外，籌碼面也是一個很重要的因素。在機器學習策略的實驗可以發現，對於特徵工程而言，大量使用技術面和籌碼面做為模型學習的特徵近200個欄位能讓模型從多個角度學習如何更有效地預測台股未來一週報酬率的分布情形；對於模型訓練而言，加入籌碼面的資料也確實可以提升模型的學習成效，降低損失函數RMSE。若未來有機會再將此專題改進，例如使用其他決策樹模型如XGBoost、LightGBM或是深度學習模型、甚至示把多種不同的模型做集成學習或是提高模型重新訓練頻率等其他方面再做得更細緻一些，相信模型績效還有再進步的空間。</p>



<h1>參考連結</h1>



<ol><li><a href="https://mrjbq7.github.io/ta-lib/funcs.html" class="rank-math-link" target="_blank" rel="noopener">talib</a></li><li><a href="https://ai.finlab.tw/database" class="rank-math-link" target="_blank" rel="noopener">finlab</a></li></ol>
]]></content:encoded>
					
					<wfw:commentRss>https://www.finlab.tw/finlab_submit1/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">3270</post-id>	</item>
	</channel>
</rss>
