<?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%89%B5%E6%96%B0%E9%AB%98/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.finlab.tw</link>
	<description>深入淺出的量化投資，讓你在在茫茫股海中，找到專屬於自己的投資方法</description>
	<lastBuildDate>Mon, 28 Nov 2022 09:53:10 +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>選股回測系統豆知識 (2)｜持股比例上限設定</title>
		<link>https://www.finlab.tw/backtest_system_position_limit/</link>
					<comments>https://www.finlab.tw/backtest_system_position_limit/#respond</comments>
		
		<dc:creator><![CDATA[Ben]]></dc:creator>
		<pubDate>Mon, 28 Nov 2022 09:43:14 +0000</pubDate>
				<category><![CDATA[Python新手教學]]></category>
		<category><![CDATA[FinLab 量化平台]]></category>
		<category><![CDATA[選股策略]]></category>
		<category><![CDATA[創新高]]></category>
		<category><![CDATA[回測]]></category>
		<category><![CDATA[快樂表]]></category>
		<guid isPermaLink="false">https://www.finlab.tw/?p=4940</guid>

					<description><![CDATA[策略回測最怕測到快樂表，什麼是快樂表？簡而言之就是紙上談兵的表現嚇嚇叫，但實際操作時卻很難貼合回測，通常這類情況多是流動性風險問題，而另一種快樂表就是回測數據的解讀錯誤，像是看到超高年化報酬率就很嗨，卻沒注意到在勝率普通的情況下，高報酬是不是剛好靠幾檔交易重壓而生成？若真是如此，那運氣成分可能佔比很大。
本文會利用一些簡單的技巧去避免統計的陷阱，讓你注意到策略中因持股重壓導致的失真問題。]]></description>
										<content:encoded><![CDATA[
<p class="has-medium-font-size">策略回測最怕測到快樂表，什麼是快樂表？簡而言之就是紙上談兵的表現嚇嚇叫，但實際操作時卻很難貼合回測，通常這類情況多是<a href="https://www.finlab.tw/customized_liquidityanalysis/">流動性風險</a>問題，而另一種快樂表就是回測數據的解讀錯誤，像是看到超高年化報酬率就很嗨，卻沒注意到在勝率普通的情況下，高報酬是不是剛好靠幾檔交易重壓而生成？若真是如此，那運氣成分可能佔比很大。<br>本文會利用一些簡單的技巧去避免統計的陷阱，讓你注意到策略中因持股重壓導致的失真問題。</p>



<h2>持股檔數設定</h2>



<p class="has-medium-font-size">小資族的資金少，選股策略在初步開發完後第一個問題是選到檔數太多，以之前介紹過的創新高延續動能策略為例，可能某幾期選股在大牛市高達百檔，但實務上根本不可能買那麼多。</p>



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

with data.universe(market='TSE_OTC'):
    close = data.get("price:收盤價")
    # 近5日內有3日以上的股價創前200日新高
    position = (close == close.rolling(200).max()).sustain(5,3)
    report = sim(position, resample="2W", stop_loss=0.2, name="創新高延續動能策略", upload=False)
    report.display()</code></pre>



<figure class="wp-block-image size-full"><img width="800" height="600" src="https://www.finlab.tw/wp-content/uploads/2022/11/newplot-40.png" alt="newplot 40" class="wp-image-4941" srcset="https://www.finlab.tw/wp-content/uploads/2022/11/newplot-40.png 800w, https://www.finlab.tw/wp-content/uploads/2022/11/newplot-40-300x225.png 300w, https://www.finlab.tw/wp-content/uploads/2022/11/newplot-40-768x576.png 768w" sizes="(max-width: 800px) 100vw, 800px" title="選股回測系統豆知識 (2)｜持股比例上限設定 1"><figcaption>創新高延續動能策略原型</figcaption></figure>



<p class="has-medium-font-size">此時我們可以針對小資族去客製化務實的條件，每期選股價前10低的標的來當持股組合。回測結果發現報酬率降低一些，但持股檔數上限控制在10檔以內，且低價的優先，讓小資族更能參與整張現股的操作，避免零股交易較高的滑價風險，讓回測更貼近現實交易貼合的可能性。</p>



<pre class="wp-block-code"><code lang="python" class="language-python">with data.universe(market='TSE_OTC'):
    close = data.get("price:收盤價")
    # 近5日內有3日以上的股價創前200日新高
    position = (close == close.rolling(200).max()).sustain(5,3)
    position *= close
    position = position[position &gt; 0].is_smallest(10)
    report = sim(position, resample="2W", name="創新高延續動能策略", upload=False)
    report.display()</code></pre>



<figure class="wp-block-image size-full"><img loading="lazy" width="800" height="600" src="https://www.finlab.tw/wp-content/uploads/2022/11/newplot-42.png" alt="newplot 42" class="wp-image-4942" srcset="https://www.finlab.tw/wp-content/uploads/2022/11/newplot-42.png 800w, https://www.finlab.tw/wp-content/uploads/2022/11/newplot-42-300x225.png 300w, https://www.finlab.tw/wp-content/uploads/2022/11/newplot-42-768x576.png 768w" sizes="(max-width: 800px) 100vw, 800px" title="選股回測系統豆知識 (2)｜持股比例上限設定 2"><figcaption>低價股優先測定持股檔數上限</figcaption></figure>



<h2>單檔持股比例上限</h2>



<p class="has-medium-font-size">以為這樣就沒問題了嗎？你若仔細看上面「低價股優先測定持股檔數上限」的策略，會發現每期的標的數量仍參差不定，牛市有時候10檔，熊市有時候1檔，由於 position 預設分配持股比例是用檔數做平均，因此若當期只選到一隻，而沒在 <a href="https://doc.finlab.tw/reference/backtest/#finlab.backtest.sim" target="_blank" rel="noopener">sim 回測函數</a> 內特別設定 position_limit，那就是100%重壓一檔！如下圖示對整體策略波動會造成很大的風險：</p>



<figure class="wp-block-image size-full"><img loading="lazy" width="800" height="600" src="https://www.finlab.tw/wp-content/uploads/2022/11/newplot-41.png" alt="newplot 41" class="wp-image-4943" srcset="https://www.finlab.tw/wp-content/uploads/2022/11/newplot-41.png 800w, https://www.finlab.tw/wp-content/uploads/2022/11/newplot-41-300x225.png 300w, https://www.finlab.tw/wp-content/uploads/2022/11/newplot-41-768x576.png 768w" sizes="(max-width: 800px) 100vw, 800px" title="選股回測系統豆知識 (2)｜持股比例上限設定 3"></figure>



<p class="has-medium-font-size">如何解決此問題呢？<a href="https://doc.finlab.tw/reference/backtest/#finlab.backtest.sim" target="_blank" rel="noopener">sim 回測函數</a> 內設定 position_limit 當單檔標的持股比例上限，控制倉位風險。預設為None，也就是不設上限。範例：0.1，代表單檔標的最多持有 10 % 部位，若加上持股檔數上限10檔，當只選到8檔時，總持股上限則為80%，剩下 20% 為現金，在選到檔數較少的時候，自然產生空手避險的效果，而不重壓標地。<br>position_limit 越高一般來說波動越大 ; position_limit  越低則波動低，報酬率與最大回撤普遍都會縮小，站在風控角度，一般建議都要設 position_limit &lt; 0.2，避免個股非系統性風險影響整體策略。<br>「<a href="https://www.finlab.tw/breakthrough_stock_picking_strategies/">創新高延續動能策略</a>」的 position_limit 要用多少比較好？我們可以用 ReportCollection 來檢測不同數值的回測效果，程式如下：</p>



<pre class="wp-block-code"><code lang="python" class="language-python">def run_strategy(position_limit):
    with data.universe(market='TSE_OTC'):
        close = data.get("price:收盤價")
        # 近5日內有3日以上的股價創前200日新高
        position = (close == close.rolling(200).max()).sustain(5,3)
        report = sim(position, resample="2W", position_limit=position_limit, stop_loss=0.2, name="創新高延續動能策略", upload=False)
        return report


# # 產生回測組合
reports = {ind/10: run_strategy(ind/10) for ind in range(1,11)}
# 放入回測報告組合比較器
collection = ReportCollection(reports)
# 產生回測數據分群柱狀圖
collection.plot_creturns().show()

import plotly.graph_objects as go

def show_index_bar(collection, item = 'max_drawdown'):
    stats = collection.get_stats()
    df = round(stats.loc[item],2).sort_values()
    fig = go.Figure([go.Bar(x=df.index, y=df.values, text=df.values, textposition='auto',)])
    fig.update_layout(title_text=item)
    return fig

# 年化報酬
show_index_bar(collection, item = 'daily_mean').show()
show_index_bar(collection, item = 'max_drawdown').show()
show_index_bar(collection, item = 'daily_sharpe').show()</code></pre>



<h2>回測分析</h2>



<p class="has-medium-font-size">可以發現 position_limit  = 0.2 時 的年化報酬率、夏普率、MDD (最大回撤) 表現最好，能有效降低重壓波動風險。如果做出來發現 position_limit  = 1 的數據最好，那就要留意快樂表的可能性，可能好績效靠是重壓導致的，這時最好考慮低 position_limit 的情況</p>



<figure class="wp-block-image size-large"><img loading="lazy" width="1024" height="271" src="https://www.finlab.tw/wp-content/uploads/2022/11/newplot-43-1024x271.png" alt="newplot 43" class="wp-image-4945" srcset="https://www.finlab.tw/wp-content/uploads/2022/11/newplot-43-1024x271.png 1024w, https://www.finlab.tw/wp-content/uploads/2022/11/newplot-43-300x79.png 300w, https://www.finlab.tw/wp-content/uploads/2022/11/newplot-43-768x203.png 768w, https://www.finlab.tw/wp-content/uploads/2022/11/newplot-43-1536x407.png 1536w, https://www.finlab.tw/wp-content/uploads/2022/11/newplot-43.png 1982w" sizes="(max-width: 1024px) 100vw, 1024px" title="選股回測系統豆知識 (2)｜持股比例上限設定 4"></figure>



<figure class="wp-block-image size-large"><img loading="lazy" width="1024" height="271" src="https://www.finlab.tw/wp-content/uploads/2022/11/newplot-44-1024x271.png" alt="newplot 44" class="wp-image-4948" srcset="https://www.finlab.tw/wp-content/uploads/2022/11/newplot-44-1024x271.png 1024w, https://www.finlab.tw/wp-content/uploads/2022/11/newplot-44-300x79.png 300w, https://www.finlab.tw/wp-content/uploads/2022/11/newplot-44-768x203.png 768w, https://www.finlab.tw/wp-content/uploads/2022/11/newplot-44-1536x407.png 1536w, https://www.finlab.tw/wp-content/uploads/2022/11/newplot-44.png 1982w" sizes="(max-width: 1024px) 100vw, 1024px" title="選股回測系統豆知識 (2)｜持股比例上限設定 5"></figure>



<figure class="wp-block-image size-large"><img loading="lazy" width="1024" height="271" src="https://www.finlab.tw/wp-content/uploads/2022/11/newplot-46-1024x271.png" alt="newplot 46" class="wp-image-4947" srcset="https://www.finlab.tw/wp-content/uploads/2022/11/newplot-46-1024x271.png 1024w, https://www.finlab.tw/wp-content/uploads/2022/11/newplot-46-300x79.png 300w, https://www.finlab.tw/wp-content/uploads/2022/11/newplot-46-768x203.png 768w, https://www.finlab.tw/wp-content/uploads/2022/11/newplot-46-1536x407.png 1536w, https://www.finlab.tw/wp-content/uploads/2022/11/newplot-46.png 1982w" sizes="(max-width: 1024px) 100vw, 1024px" title="選股回測系統豆知識 (2)｜持股比例上限設定 6"></figure>



<figure class="wp-block-image size-large"><img loading="lazy" width="1024" height="271" src="https://www.finlab.tw/wp-content/uploads/2022/11/newplot-45-1-1024x271.png" alt="newplot 45 1" class="wp-image-4950" srcset="https://www.finlab.tw/wp-content/uploads/2022/11/newplot-45-1-1024x271.png 1024w, https://www.finlab.tw/wp-content/uploads/2022/11/newplot-45-1-300x79.png 300w, https://www.finlab.tw/wp-content/uploads/2022/11/newplot-45-1-768x203.png 768w, https://www.finlab.tw/wp-content/uploads/2022/11/newplot-45-1-1536x407.png 1536w, https://www.finlab.tw/wp-content/uploads/2022/11/newplot-45-1.png 1982w" sizes="(max-width: 1024px) 100vw, 1024px" title="選股回測系統豆知識 (2)｜持股比例上限設定 7"></figure>



<figure class="wp-block-image size-full"><img loading="lazy" width="800" height="600" src="https://www.finlab.tw/wp-content/uploads/2022/11/newplot-48.png" alt="newplot 48" class="wp-image-4953" srcset="https://www.finlab.tw/wp-content/uploads/2022/11/newplot-48.png 800w, https://www.finlab.tw/wp-content/uploads/2022/11/newplot-48-300x225.png 300w, https://www.finlab.tw/wp-content/uploads/2022/11/newplot-48-768x576.png 768w" sizes="(max-width: 800px) 100vw, 800px" title="選股回測系統豆知識 (2)｜持股比例上限設定 8"><figcaption>position_limit = 0.2 的回測情況 </figcaption></figure>



<h2>結論</h2>



<p class="has-medium-font-size"><a href="https://colab.research.google.com/drive/11xHowJGeHmhpNCbCjOPfcsBI5yT6ZsOq?usp=sharing" target="_blank" rel="noopener">colab 範例檔</a><br>你的策略有驗證過持股檔數與單檔持股上限的問題嗎？<br>調整一個  position_limit  參數 就能降低快樂表和大波動的風險，可說是新手必學的參數設定啊！</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.finlab.tw/backtest_system_position_limit/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">4940</post-id>	</item>
		<item>
		<title>月營收選股｜股價創新高｜新手必學的雙動能策略</title>
		<link>https://www.finlab.tw/revenue_and_price_engine_strategy/</link>
					<comments>https://www.finlab.tw/revenue_and_price_engine_strategy/#respond</comments>
		
		<dc:creator><![CDATA[Ben]]></dc:creator>
		<pubDate>Wed, 16 Nov 2022 06:55:47 +0000</pubDate>
				<category><![CDATA[Python新手教學]]></category>
		<category><![CDATA[FinLab 量化平台]]></category>
		<category><![CDATA[VIP文章]]></category>
		<category><![CDATA[基本面分析]]></category>
		<category><![CDATA[技術面]]></category>
		<category><![CDATA[投資新手]]></category>
		<category><![CDATA[財經PYTHON教學]]></category>
		<category><![CDATA[VIP限定]]></category>
		<category><![CDATA[創新高]]></category>
		<category><![CDATA[動能]]></category>
		<category><![CDATA[月營收]]></category>
		<guid isPermaLink="false">https://www.finlab.tw/?p=4884</guid>

					<description><![CDATA[月營收是台股獨特的基本面因子，操作台股的玩家，都知道月營收的影響性，常可先預判季財報，究竟月營收選股條件要怎麼寫？這篇就用超簡單的語法，結合「突破策略豆知識」技巧寫出15年來年化報酬37%的高報酬率策略，讓你迅速上手月營收突破這個台股經典的策略。]]></description>
										<content:encoded><![CDATA[
<p class="has-medium-font-size">月營收是台股獨特的基本面因子，操作台股的玩家，都知道月營收的影響性，常可先預判季財報，究竟月營收選股條件要怎麼寫？這篇就用超簡單的語法，結合「<a href="https://www.finlab.tw/breakthrough_stock_picking_strategies/">突破策略豆知識</a>」技巧寫出15年來年化報酬37%的高報酬率策略，讓你迅速上手月營收突破這個台股經典的策略。</p>



<figure class="wp-block-image size-large"><img loading="lazy" width="1024" height="654" src="https://www.finlab.tw/wp-content/uploads/2022/11/截圖-2022-11-16-下午12.47.28-e1668593619128-1024x654.png" alt="截圖 2022 11 16 下午12.47.28 e1668593619128" class="wp-image-4885" srcset="https://www.finlab.tw/wp-content/uploads/2022/11/截圖-2022-11-16-下午12.47.28-e1668593619128-1024x654.png 1024w, https://www.finlab.tw/wp-content/uploads/2022/11/截圖-2022-11-16-下午12.47.28-e1668593619128-300x192.png 300w, https://www.finlab.tw/wp-content/uploads/2022/11/截圖-2022-11-16-下午12.47.28-e1668593619128-768x491.png 768w, https://www.finlab.tw/wp-content/uploads/2022/11/截圖-2022-11-16-下午12.47.28-e1668593619128.png 1396w" sizes="(max-width: 1024px) 100vw, 1024px" title="月營收選股｜股價創新高｜新手必學的雙動能策略 9"></figure>



<h2>月營收選股策略 &#8211; 創高基礎型態</h2>



<h3>程式範例</h3>



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

rev = data.get('monthly_revenue:當月營收')
rev_yoy_growth = data.get('monthly_revenue:去年同月增減(%)')

# 近2月平均營收
rev_ma = rev.average(2)

# 近2月平均營收創12個月來新高
condition = rev_ma == rev_ma.rolling(12, min_periods=6).max()

# 單月營收年增率與訊號相乘，若訊號為False，相乘結果為0
position= rev_yoy_growth*condition

# 符合選股條件的名單中，再選出單月營收年增率前10強，並在營收公告截止日換股。
position=position[position&gt;0].is_largest(10)

report=sim(position ,name="營收動能",upload=False)
report.display()</code></pre>



<p class="has-medium-font-size">程式非常簡單，只有10來行。說明幾個關鍵處。<br>月營收有個關鍵在要注意過年效應，有時候年假在1月、有時在2月中旬前，由於台股多數企業的營運區域都在華人地區，年假通常會停工或減班，如果是在1月過年，訂單常遞延到2月。因此在比較營收時，為了平滑過年效應，我會習慣取近2月平均營收來取代單月營收，不然1、2月若碰到年假，單月營收要創近12月新高的可能性實在太低。</p>



<p class="has-medium-font-size"><br>如果策略要實戰，縮減檔數是必須的，因為多數人沒那麼多資金全買，所以範例簡單用單月月營收來選最後10強。你可能會疑惑為何要寫<code>position[position&gt;0].is_largest(10)</code>，而不是<code>position.is_largest(10)</code>就好？那是因為<code>is_largest(10)</code>會選數值前10高的，若沒有排除不符合營收創高的標的，前10高的數值可能會選到不合條件的，會從股號小的標的開始補到10檔為止。</p>



<p class="has-medium-font-size">此策略的換股週期是用月營收索引，也就是月營收公告截止日，好處是貼近營收因子發酵期。<br>來看看策略的表現，非常不錯，15年來，年化高達 26% ! <br>你以為這樣就結束了嗎？其實還可以優化，繼續看下去。</p>



<figure class="wp-block-image size-full"><img loading="lazy" width="800" height="600" src="https://www.finlab.tw/wp-content/uploads/2022/11/newplot-36.png" alt="newplot 36" class="wp-image-4886" srcset="https://www.finlab.tw/wp-content/uploads/2022/11/newplot-36.png 800w, https://www.finlab.tw/wp-content/uploads/2022/11/newplot-36-300x225.png 300w, https://www.finlab.tw/wp-content/uploads/2022/11/newplot-36-768x576.png 768w" sizes="(max-width: 800px) 100vw, 800px" title="月營收選股｜股價創新高｜新手必學的雙動能策略 10"></figure>



<h2>營收股價雙創高的渦輪效應</h2>



<h3>股價創新高動能</h3>



<p class="has-medium-font-size">營收利多，最怕利多不漲，那很可能是市場早就反應，因此我們的目標是股價與營收連動，一同創高，代表股價的動能和營收創新高的關聯較大，如何寫出好棒棒的股價創新高動能策略，可以看先前的文章「<a href="https://www.finlab.tw/breakthrough_stock_picking_strategies/">突破策略豆知識</a>」，運用FinlabDataframe好用的sustiain方法確認突破強度。<br>程式與回測結果如下：</p>



<pre class="wp-block-code"><code lang="python" class="language-python">from finlab.backtest import sim
from finlab import data
with data.universe(market='TSE_OTC'):
    close = data.get("price:收盤價")
    # 近5日內有3日以上的股價創前200日新高
    position = (close == close.rolling(200).max()).sustain(5,2)
    report = sim(position, resample="M", name="創新高延續動能策略", upload=False)
    report.display()</code></pre>



<figure class="wp-block-image size-full"><img loading="lazy" width="800" height="600" src="https://www.finlab.tw/wp-content/uploads/2022/11/newplot-38.png" alt="newplot 38" class="wp-image-4887" srcset="https://www.finlab.tw/wp-content/uploads/2022/11/newplot-38.png 800w, https://www.finlab.tw/wp-content/uploads/2022/11/newplot-38-300x225.png 300w, https://www.finlab.tw/wp-content/uploads/2022/11/newplot-38-768x576.png 768w" sizes="(max-width: 800px) 100vw, 800px" title="月營收選股｜股價創新高｜新手必學的雙動能策略 11"></figure>



<h3>雙渦輪</h3>



<p class="has-medium-font-size">如果把營收創新高和股價創新高的程式做結合，會發生什麼事？</p>



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

close = data.get('price:收盤價')
vol = data.get('price:成交股數')
rev = data.get('monthly_revenue:當月營收')
rev_yoy_growth = data.get('monthly_revenue:去年同月增減(%)')

# 近2月平均營收
rev_ma = rev.average(2)

# 近2月平均營收創12個月來新高
condition1 = rev_ma == rev_ma.rolling(12, min_periods=6).max()
# 近5日內有2日股價創新高
condition2 = (close == close.rolling(200).max()).sustain(5,2)
# 近五日成交均量大於500張
condition3 = vol.average(5) &gt; 500*1000
conditions = condition1 &amp; condition2 &amp; condition3

# 符合選股條件的名單中，再選出單月營收年增率前10強，並在營收公告截止日換股。
position= rev_yoy_growth*conditions

position=position[position&gt;0].is_largest(10).reindex(rev.index_str_to_date().index, method='ffill')

# 設定position_limit避免重壓
report = sim(position=position,stop_loss=0.2,take_profit=0.8, position_limit=0.25, fee_ratio=1.425/1000*0.3,name="營收股價雙渦輪",upload=False)
report.display()</code></pre>



<p class="has-medium-font-size">上面程式要注意的小地方是有加上流動性條件，只買近五日成交均量大於500張的標的，避免太冷門的標的很難入手。由於月營收創高和股價創高的條件交集後，會轉成日週期索引，若要使用月營收截止日換股，必須要做reindex的動作，<code>rev.index_str_to_date</code> 會將月營收文字格式日期轉成月營收公告截止日，例如 2022-M10 變成 2022-11-11。<br><br>最後為避免重壓標地，設定position_limit=0.25，代表單擋持股上限為25%，避免只選到1-2檔全壓的大波動狀況。如果偏好降低波動，也可調成0.1，如此一來若只選到4檔標的，總持股比例只會有40%，在熊市時由於創新高標的本來就少，因此持股比例自然降低，具自然避險躲空頭的效果。<br><br>停損不建議設定小，此策略波動較大，設太小容易被洗掉。最後來看看加乘的效果吧！<br>15年來年化報酬37%！夏普率1.3，幾乎每一年都獲利，比前述單因子選股的表現優異許多，熊市年 2022 竟然還有16%正報酬，以條件這麼簡單的策略來說，算是很神的成績！</p>



<figure class="wp-block-image size-full"><img loading="lazy" width="800" height="600" src="https://www.finlab.tw/wp-content/uploads/2022/11/newplot-39.png" alt="newplot 39" class="wp-image-4888" srcset="https://www.finlab.tw/wp-content/uploads/2022/11/newplot-39.png 800w, https://www.finlab.tw/wp-content/uploads/2022/11/newplot-39-300x225.png 300w, https://www.finlab.tw/wp-content/uploads/2022/11/newplot-39-768x576.png 768w" sizes="(max-width: 800px) 100vw, 800px" title="月營收選股｜股價創新高｜新手必學的雙動能策略 12"></figure>



<figure class="wp-block-image size-large"><img loading="lazy" width="1024" height="654" src="https://www.finlab.tw/wp-content/uploads/2022/11/截圖-2022-11-16-下午12.47.28-e1668593619128-1024x654.png" alt="截圖 2022 11 16 下午12.47.28 e1668593619128" class="wp-image-4885" srcset="https://www.finlab.tw/wp-content/uploads/2022/11/截圖-2022-11-16-下午12.47.28-e1668593619128-1024x654.png 1024w, https://www.finlab.tw/wp-content/uploads/2022/11/截圖-2022-11-16-下午12.47.28-e1668593619128-300x192.png 300w, https://www.finlab.tw/wp-content/uploads/2022/11/截圖-2022-11-16-下午12.47.28-e1668593619128-768x491.png 768w, https://www.finlab.tw/wp-content/uploads/2022/11/截圖-2022-11-16-下午12.47.28-e1668593619128.png 1396w" sizes="(max-width: 1024px) 100vw, 1024px" title="月營收選股｜股價創新高｜新手必學的雙動能策略 9"></figure>



<h2>結論</h2>



<p class="has-medium-font-size"><a href="https://colab.research.google.com/drive/1qp-5ZPtJXFIc6x4EkCJezzMcwpFdc5jY?usp=sharing" target="_blank" rel="noopener">colab 範例</a><br><a href="https://ai.finlab.tw/strategyview/?uid=TJN4FDuqrwU8DML7DAjUYFIMutp2&amp;sid=%E7%87%9F%E6%94%B6%E8%82%A1%E5%83%B9%E9%9B%99%E6%B8%A6%E8%BC%AA" target="_blank" rel="noopener">量化平台部署範例</a><br>簡單卻很有實戰性，這就是FinLab與其他地方不同之處，不走太學術的路線，考慮實戰面，除了完整公開程式碼，還跟你講策略背後的思維。<br>此策略當然還有優化的空間～但這就是大家各自的功課了，Ben 把最核心的條件交給你了，一起去找股海的大秘寶吧！</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.finlab.tw/revenue_and_price_engine_strategy/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">4884</post-id>	</item>
		<item>
		<title>突破策略豆知識 &#124; 如何避免假突破?</title>
		<link>https://www.finlab.tw/breakthrough_stock_picking_strategies/</link>
					<comments>https://www.finlab.tw/breakthrough_stock_picking_strategies/#respond</comments>
		
		<dc:creator><![CDATA[Ben]]></dc:creator>
		<pubDate>Thu, 22 Sep 2022 05:13:35 +0000</pubDate>
				<category><![CDATA[技術面]]></category>
		<category><![CDATA[FinLab 量化平台]]></category>
		<category><![CDATA[VIP文章]]></category>
		<category><![CDATA[投資新手]]></category>
		<category><![CDATA[股票策略]]></category>
		<category><![CDATA[選股策略]]></category>
		<category><![CDATA[FinlabDataframe]]></category>
		<category><![CDATA[創新高]]></category>
		<category><![CDATA[動能]]></category>
		<category><![CDATA[策略開發豆知識]]></category>
		<guid isPermaLink="false">https://www.finlab.tw/?p=4452</guid>

					<description><![CDATA[動能策略很常用到「股價創新高」這個條件，所謂的動能策略簡單說就是追突破，通說認為創新高的股票比較少套牢壓力，上 [&#8230;]]]></description>
										<content:encoded><![CDATA[
<p class="has-medium-font-size">動能策略很常用到「股價創新高」這個條件，所謂的動能策略簡單說就是追突破，通說認為創新高的股票比較少套牢壓力，上漲的延續性較高。反之股價無創新高的股票，可能在上漲過程跌跌撞撞，一漲上去可能就被套牢賣壓打下來。<br>但股價創新高這麼廣為人知的突破策略真的有用嗎？趕緊來回測驗證一下</p>



<h2>股價創新高策略範例</h2>



<h3>程式碼</h3>



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

# 標的範圍為上市櫃普通股
with data.universe(market='TSE_OTC'):
    # 取得收盤價
    close = data.get("price:收盤價")
    # 股價創近200日新高
    position = (close == close.rolling(200).max())
    # 每兩週再平衡，單檔最大持股比例限制20%，停損20%
    report = sim(position, resample="2W", position_limit=0.2, stop_loss=0.2, name="股價創新高策略")
    report.display()</code></pre>



<h3>選股條件</h3>



<p class="has-medium-font-size">程式很簡單，這是一個偏短線的技術面策略，不用幾行就可以開發完成，只有了一個股價創新高條件和一些回測基本設定。<br>主要條件為:</p>



<ul class="has-medium-font-size"><li>標的範圍為上市櫃普通股</li><li>股價創近200日新高，天數越高，則壓力越小</li><li>每兩週再平衡</li><li>單檔最大持股比例限制20%，避免個股單壓的非系統性風險</li><li>停損20%</li></ul>



<h3>回測結果</h3>



<figure class="wp-block-image size-large"><img loading="lazy" width="1024" height="747" src="https://www.finlab.tw/wp-content/uploads/2022/09/截圖-2022-09-22-下午12.43.29-1024x747.png" alt="截圖 2022 09 22 下午12.43.29" class="wp-image-4456" srcset="https://www.finlab.tw/wp-content/uploads/2022/09/截圖-2022-09-22-下午12.43.29-1024x747.png 1024w, https://www.finlab.tw/wp-content/uploads/2022/09/截圖-2022-09-22-下午12.43.29-300x219.png 300w, https://www.finlab.tw/wp-content/uploads/2022/09/截圖-2022-09-22-下午12.43.29-768x560.png 768w, https://www.finlab.tw/wp-content/uploads/2022/09/截圖-2022-09-22-下午12.43.29-1536x1120.png 1536w, https://www.finlab.tw/wp-content/uploads/2022/09/截圖-2022-09-22-下午12.43.29.png 1890w" sizes="(max-width: 1024px) 100vw, 1024px" title="突破策略豆知識 | 如何避免假突破? 14"></figure>



<figure class="wp-block-image size-large"><img loading="lazy" width="1024" height="841" src="https://www.finlab.tw/wp-content/uploads/2022/09/截圖-2022-09-22-下午12.39.15-1024x841.png" alt="截圖 2022 09 22 下午12.39.15" class="wp-image-4455" srcset="https://www.finlab.tw/wp-content/uploads/2022/09/截圖-2022-09-22-下午12.39.15-1024x841.png 1024w, https://www.finlab.tw/wp-content/uploads/2022/09/截圖-2022-09-22-下午12.39.15-300x246.png 300w, https://www.finlab.tw/wp-content/uploads/2022/09/截圖-2022-09-22-下午12.39.15-768x631.png 768w, https://www.finlab.tw/wp-content/uploads/2022/09/截圖-2022-09-22-下午12.39.15.png 1394w" sizes="(max-width: 1024px) 100vw, 1024px" title="突破策略豆知識 | 如何避免假突破? 15"></figure>



<p class="has-medium-font-size">年化報酬率為17.7%，幾乎每年都獲利，至今只有兩個年份虧損，困難年份2008、2018、2022年的表現優於大盤，但困難年份 2011 表現不好。以報酬率表現來說，該因子表現不錯。<br>但夏普率和最大下跌和大盤風險差不多，並無明顯優勢。</p>



<h2>策略優化</h2>



<p class="has-medium-font-size">上述策略的缺點在只有近一天突破就買，你可能會「買到假突破的標的」、「錯過前幾天突破小拉回的好標地」。<br>一個動能夠強的標的，短期不會只有一天創新高，而是「<strong>連續挑戰新高</strong>」，創新高越多次，代表動能越強，這樣的訊號除了確認訊號強度，也可把前幾天有突破，近期小回檔的強勢股納進來，將時間條件更有彈性，比較不會錯過飆股，你時間定的越死，會很吃選股日當日訊號的運氣。</p>



<p class="has-medium-font-size">為了更確認訊號及囊括近期強勢標的，我會使用<a href="https://doc.finlab.tw/reference/dataframe/#finlab.dataframe.FinlabDataFrame.sustain" data-type="URL" data-id="https://doc.finlab.tw/reference/dataframe/#finlab.dataframe.FinlabDataFrame.sustain" target="_blank" rel="noopener">FinlabDataFrame的語法糖 sustain</a> 去判斷訊號強度延續性。</p>



<h3>程式範例</h3>



<pre class="wp-block-code"><code lang="python" class="language-python">from finlab.backtest import sim
from finlab import data
with data.universe(market='TSE_OTC'):
    close = data.get("price:收盤價")
    # 近5日內有3日以上的股價創前200日新高
    position = (close == close.rolling(200).max()).sustain(5,3)
    report = sim(position, resample="2W", position_limit=0.2, stop_loss=0.2, name="創新高延續動能策略")
    report.display()</code></pre>



<p class="has-medium-font-size"><br></p>



<h3>選股條件</h3>



<p class="has-medium-font-size">只將創新高條件加入強度延續性判斷，為公平比較，其餘條件相同。</p>



<ul class="has-medium-font-size"><li>標的範圍為上市櫃普通股</li><li>近5日內有3日以上（含）的股價創前200日新高。</li><li>每兩週再平衡</li><li>單檔最大持股比例限制20%，避免個股單壓的非系統性風險</li><li>停損20%</li></ul>



<h3>回測結果</h3>



<figure class="wp-block-image size-large"><img loading="lazy" width="1024" height="705" src="https://www.finlab.tw/wp-content/uploads/2022/09/截圖-2022-09-22-下午12.59.07-1024x705.png" alt="截圖 2022 09 22 下午12.59.07" class="wp-image-4457" srcset="https://www.finlab.tw/wp-content/uploads/2022/09/截圖-2022-09-22-下午12.59.07-1024x705.png 1024w, https://www.finlab.tw/wp-content/uploads/2022/09/截圖-2022-09-22-下午12.59.07-300x206.png 300w, https://www.finlab.tw/wp-content/uploads/2022/09/截圖-2022-09-22-下午12.59.07-768x529.png 768w, https://www.finlab.tw/wp-content/uploads/2022/09/截圖-2022-09-22-下午12.59.07-1536x1057.png 1536w, https://www.finlab.tw/wp-content/uploads/2022/09/截圖-2022-09-22-下午12.59.07.png 1601w" sizes="(max-width: 1024px) 100vw, 1024px" title="突破策略豆知識 | 如何避免假突破? 16"></figure>



<figure class="wp-block-image size-large"><img loading="lazy" width="1024" height="791" src="https://www.finlab.tw/wp-content/uploads/2022/09/截圖-2022-09-22-下午12.59.49-1024x791.png" alt="截圖 2022 09 22 下午12.59.49" class="wp-image-4458" srcset="https://www.finlab.tw/wp-content/uploads/2022/09/截圖-2022-09-22-下午12.59.49-1024x791.png 1024w, https://www.finlab.tw/wp-content/uploads/2022/09/截圖-2022-09-22-下午12.59.49-300x232.png 300w, https://www.finlab.tw/wp-content/uploads/2022/09/截圖-2022-09-22-下午12.59.49-768x593.png 768w, https://www.finlab.tw/wp-content/uploads/2022/09/截圖-2022-09-22-下午12.59.49.png 1391w" sizes="(max-width: 1024px) 100vw, 1024px" title="突破策略豆知識 | 如何避免假突破? 17"></figure>



<p class="has-medium-font-size">年化報酬率為25.9%，比原先的17.7%大幅上升，幾乎每年都獲利，困難年份2008、2011、2018、2022年的表現優於大盤。<br>夏普率明顯提升到1.1，最大下跌和下跌幅度曲線比原先收斂不少，長時間都能比大盤有更小的回檔風險。</p>



<h2>結論</h2>



<p class="has-medium-font-size">經過小小的觀念和語法調整，卻能讓策略大幅優化！是不是很神奇呢？<br>如果你的策略也有用到「股價創新高的條件」之類的突破策略，可以試試加入 sustain 語法，看看會不會有優化的效果。甚至將 sustain 語法應用到其他條件。<br></p>



<h3>相關資料</h3>



<ul class="has-medium-font-size"><li><a href="https://colab.research.google.com/drive/1M0XxnAMZoqoOrJQP9dyJVer5Q7YyRFOA?usp=sharing" target="_blank" rel="noopener">colab 程式範例檔</a></li></ul>
]]></content:encoded>
					
					<wfw:commentRss>https://www.finlab.tw/breakthrough_stock_picking_strategies/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">4452</post-id>	</item>
	</channel>
</rss>
