<?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/%E6%99%AF%E6%B0%A3%E7%87%88%E8%99%9F/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.finlab.tw</link>
	<description>深入淺出的量化投資，讓你在在茫茫股海中，找到專屬於自己的投資方法</description>
	<lastBuildDate>Thu, 29 Dec 2022 12:01:30 +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>用Python回測總經指標(3)｜台灣景氣燈號｜加減碼策略</title>
		<link>https://www.finlab.tw/tw_business_indicator_changed_weight_strategy/</link>
					<comments>https://www.finlab.tw/tw_business_indicator_changed_weight_strategy/#respond</comments>
		
		<dc:creator><![CDATA[Ben]]></dc:creator>
		<pubDate>Thu, 29 Dec 2022 11:26:10 +0000</pubDate>
				<category><![CDATA[FinLab 量化平台]]></category>
		<category><![CDATA[VIP文章]]></category>
		<category><![CDATA[總體經濟]]></category>
		<category><![CDATA[選股策略]]></category>
		<category><![CDATA[0050]]></category>
		<category><![CDATA[加減碼]]></category>
		<category><![CDATA[景氣燈號]]></category>
		<category><![CDATA[總經]]></category>
		<guid isPermaLink="false">https://www.finlab.tw/?p=5072</guid>

					<description><![CDATA[國發會在12月底發布了上月景氣燈號數據，這個指標可以視為台灣總經的風向球。現進入低迷的藍燈，數值非常低，剩下1 [&#8230;]]]></description>
										<content:encoded><![CDATA[
<p class="has-medium-font-size">國發會在12月底發布了上月景氣燈號數據，這個指標可以視為台灣總經的風向球。現進入低迷的藍燈，數值非常低，剩下12分，很久沒有這麼慘了。</p>



<figure class="wp-block-image size-large"><img width="1024" height="717" src="https://www.finlab.tw/wp-content/uploads/2022/12/截圖-2022-12-29-下午6.04.34-1024x717.png" alt="截圖 2022 12 29 下午6.04.34" class="wp-image-5073" srcset="https://www.finlab.tw/wp-content/uploads/2022/12/截圖-2022-12-29-下午6.04.34-1024x717.png 1024w, https://www.finlab.tw/wp-content/uploads/2022/12/截圖-2022-12-29-下午6.04.34-300x210.png 300w, https://www.finlab.tw/wp-content/uploads/2022/12/截圖-2022-12-29-下午6.04.34-768x537.png 768w, https://www.finlab.tw/wp-content/uploads/2022/12/截圖-2022-12-29-下午6.04.34-1536x1075.png 1536w, https://www.finlab.tw/wp-content/uploads/2022/12/截圖-2022-12-29-下午6.04.34-2048x1433.png 2048w" sizes="(max-width: 1024px) 100vw, 1024px" title="用Python回測總經指標(3)｜台灣景氣燈號｜加減碼策略 1"><figcaption><a href="https://index.ndc.gov.tw/n/zh_tw" target="_blank" rel="noopener">取自國發會</a></figcaption></figure>



<figure class="wp-block-image size-large"><img loading="lazy" width="825" height="1024" src="https://www.finlab.tw/wp-content/uploads/2022/12/截圖-2022-12-29-下午6.14.43-825x1024.png" alt="截圖 2022 12 29 下午6.14.43" class="wp-image-5075" srcset="https://www.finlab.tw/wp-content/uploads/2022/12/截圖-2022-12-29-下午6.14.43-825x1024.png 825w, https://www.finlab.tw/wp-content/uploads/2022/12/截圖-2022-12-29-下午6.14.43-242x300.png 242w, https://www.finlab.tw/wp-content/uploads/2022/12/截圖-2022-12-29-下午6.14.43-768x953.png 768w, https://www.finlab.tw/wp-content/uploads/2022/12/截圖-2022-12-29-下午6.14.43.png 1036w" sizes="(max-width: 825px) 100vw, 825px" title="用Python回測總經指標(3)｜台灣景氣燈號｜加減碼策略 2"><figcaption>取自<a href="https://www.facebook.com/macromicro.me/posts/pfbid02S2hEbWiLi7Wt3c5My2qmvHPuHJPhXqzaacLM1mkgBMPvx7xoK4YE5seyvN8LfXnMl" target="_blank" rel="noopener">財經M平方臉書粉絲團</a></figcaption></figure>



<p class="has-medium-font-size">然而今年股市也回檔了超過20%，如果在景氣熱絡時進場，像是去年底，那你今年肯定很難過，現在你看到藍燈，是不是認為為總經環境差，要趕緊脫出股票？<br>市場老手「麥克風」則有不一樣的看法，認為「藍燈」反而是末跌段買點，只是要分批進場會比較安全。我的看法也是如此，通常進入藍燈時，股市早就反映一大段了，當未來爛無可爛，反而容易出現轉機，市場經常領先經濟數據。</p>



<figure class="wp-block-image size-large"><img loading="lazy" width="1024" height="933" src="https://www.finlab.tw/wp-content/uploads/2022/12/截圖-2022-12-29-下午6.12.42-1024x933.png" alt="截圖 2022 12 29 下午6.12.42" class="wp-image-5074" srcset="https://www.finlab.tw/wp-content/uploads/2022/12/截圖-2022-12-29-下午6.12.42-1024x933.png 1024w, https://www.finlab.tw/wp-content/uploads/2022/12/截圖-2022-12-29-下午6.12.42-300x273.png 300w, https://www.finlab.tw/wp-content/uploads/2022/12/截圖-2022-12-29-下午6.12.42-768x700.png 768w, https://www.finlab.tw/wp-content/uploads/2022/12/截圖-2022-12-29-下午6.12.42-1536x1400.png 1536w, https://www.finlab.tw/wp-content/uploads/2022/12/截圖-2022-12-29-下午6.12.42.png 1545w" sizes="(max-width: 1024px) 100vw, 1024px" title="用Python回測總經指標(3)｜台灣景氣燈號｜加減碼策略 3"><figcaption>取自<a href="https://www.facebook.com/mktsurvivalkit/posts/pfbid0Y3czh2MLSYZxG6Utjr6povtP1R2Cq2vmAfncyiTMnuqGBJ1kSLmVU7p4rVnWn9Lrl" target="_blank" rel="noopener">麥克風臉書粉絲團</a></figcaption></figure>



<h2>景氣燈號如何撰寫加減碼？</h2>



<p class="has-medium-font-size">重點來了，許多人都知道要在藍燈分批買進，但分批加減碼究竟要如何撰寫？<br>通常寫策略都是一布林訊號通到底，100%持有。這就是FinLab量化平台的優勢，可以自動調控加減碼，可以自動調控加減碼，不限於固定部位，可靈活運用總經數據，把策略都自動化起來，比起外面的總經課程，更貼近實戰。<br><br><a href="https://doc.finlab.tw/reference/backtest/#finlab.backtest.sim" target="_blank" rel="noopener">回測函數</a> 當position 的數值除了可為布林訊號，也可以填入數值當持有部位調控，例如 0.2 為持有20%。</p>



<p class="has-medium-font-size">示範的景氣燈號加減碼策略邏輯為分5批進場。<br>只要近12個月內每一月景氣指標分數小於等於18時，分批買進20%部位。若景氣指標分數大於等於40時則全數賣出。舉例：若近12月內有3個月滿足條件，則持有60%，若近12月內有5個月以上滿足條件，則持有100%。<br>這個策略設計的背後思維在如果近12月內景氣燈號低於18分的月份越少，代表脫離藍燈谷底越遠，若近12月內景氣燈號低於18分的月份越多，則代表貼近景氣谷底，利用訊號數量去加乘持股部位。<br>另一個小重點在為何指標是用18與40分，而不是官方藍紅燈上下限的16分與38分？原因在策略若想要比人早一步，就要微調數值，且進入紅燈的熱絡階段，往往有所謂邪惡第五波，延遲出場有機會獲得更高報酬，而若用官方的16分當衰退指標，會發現低於16分的情況不多，所以往上微調，以增加訊號數。</p>



<pre class="wp-block-code"><code lang="python" class="language-python">from finlab import data
import pandas as pd
import numpy as np

df = data.get('tw_business_indicators:景氣對策信號(分)')
df = df[list(df['tw_business_indicators'] &gt; 0)]

# 只要近12個月內每一月景氣指標分數小於等於18時，分批買進20%部位。舉例：若近12月內有3個月滿足條件，則持有60%，若近12月內有5個月滿足條件，則持有100%。若景氣指標分數大於等於40時則全數賣出
batches = 5
ind = df['tw_business_indicators']
sig = pd.Series([True if i &lt;= 18 else False if i &gt;= 40 else np.nan for i in ind], index=ind.index)
position = (((sig / batches).rolling(12,min_periods=1).sum()) * sig).ffill().clip(0,1)
position.astype(float).plot()</code></pre>



<h2>景氣燈號加減碼訊號曲線變化</h2>



<p class="has-medium-font-size">可以發現加減碼曲線控制在 0%到100%，隨著時間不同而有不同持股部位變化。</p>



<figure class="wp-block-image size-large"><img loading="lazy" width="1024" height="703" src="https://www.finlab.tw/wp-content/uploads/2022/12/截圖-2022-12-29-下午6.33.30-1024x703.png" alt="截圖 2022 12 29 下午6.33.30" class="wp-image-5076" srcset="https://www.finlab.tw/wp-content/uploads/2022/12/截圖-2022-12-29-下午6.33.30-1024x703.png 1024w, https://www.finlab.tw/wp-content/uploads/2022/12/截圖-2022-12-29-下午6.33.30-300x206.png 300w, https://www.finlab.tw/wp-content/uploads/2022/12/截圖-2022-12-29-下午6.33.30-768x527.png 768w, https://www.finlab.tw/wp-content/uploads/2022/12/截圖-2022-12-29-下午6.33.30.png 1420w" sizes="(max-width: 1024px) 100vw, 1024px" title="用Python回測總經指標(3)｜台灣景氣燈號｜加減碼策略 4"></figure>



<h2>回測程式</h2>



<p class="has-medium-font-size"><a href="https://colab.research.google.com/drive/1NbxeJydvdSyD_3zxYulvPJiJfb7UpOOw?usp=sharing" target="_blank" rel="noopener">colab 範例檔</a><br>回測程式很簡單，我們以 0050 元大台灣50 當操作台灣總經策略的標地，將上述的景氣燈號加減碼訊號傳入 0050 的 DataFrame，就會以該加減碼訊號靈活操作 0050 ，在景氣低迷時逐步入手，在景氣熱絡時拖出。<br>小細節是帶入回測時把交易稅率調成 ETF 適用的 1/1000。</p>



<pre class="wp-block-code"><code lang="python" class="language-python">from finlab.backtest import sim

# 將持有部位帶進0050
close = data.get('price:收盤價')
buy = pd.DataFrame({'0050':position})
buy = buy.reindex(close.index, method='ffill')
report = sim(buy, upload=False, tax_ratio=1/1000)
report.display()</code></pre>



<p class="has-medium-font-size">回測結果發現該策略可以取得比長期持有0050還好的績效，熊市時期的2007與2022回檔幅度較小，波動曲線更為漂亮。</p>



<figure class="wp-block-image size-full"><img loading="lazy" width="800" height="600" src="https://www.finlab.tw/wp-content/uploads/2022/12/newplot-49.png" alt="newplot 49" class="wp-image-5077" srcset="https://www.finlab.tw/wp-content/uploads/2022/12/newplot-49.png 800w, https://www.finlab.tw/wp-content/uploads/2022/12/newplot-49-300x225.png 300w, https://www.finlab.tw/wp-content/uploads/2022/12/newplot-49-768x576.png 768w" sizes="(max-width: 800px) 100vw, 800px" title="用Python回測總經指標(3)｜台灣景氣燈號｜加減碼策略 5"></figure>
]]></content:encoded>
					
					<wfw:commentRss>https://www.finlab.tw/tw_business_indicator_changed_weight_strategy/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">5072</post-id>	</item>
	</channel>
</rss>
