<?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/%E8%B3%87%E6%96%99%E8%99%95%E7%90%86/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.finlab.tw</link>
	<description>深入淺出的量化投資，讓你在在茫茫股海中，找到專屬於自己的投資方法</description>
	<lastBuildDate>Thu, 22 Dec 2022 07:29:01 +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>產業資料庫的基礎應用</title>
		<link>https://www.finlab.tw/industry_themes_database_basic_application/</link>
					<comments>https://www.finlab.tw/industry_themes_database_basic_application/#respond</comments>
		
		<dc:creator><![CDATA[Ben]]></dc:creator>
		<pubDate>Tue, 20 Dec 2022 06:35:19 +0000</pubDate>
				<category><![CDATA[FinLab 量化平台]]></category>
		<category><![CDATA[Python新手教學]]></category>
		<category><![CDATA[基本面分析]]></category>
		<category><![CDATA[生產力]]></category>
		<category><![CDATA[pandas]]></category>
		<category><![CDATA[台股]]></category>
		<category><![CDATA[產業分析]]></category>
		<category><![CDATA[資料處理]]></category>
		<guid isPermaLink="false">https://www.finlab.tw/?p=4971</guid>

					<description><![CDATA[這篇教學文章將說明FinLab的「產業題材資料庫」的簡單應用，並教你如何用 Python 與 Pandas 基礎語法去「客製化」自己的產業分類，讓產業資料庫更豐富]]></description>
										<content:encoded><![CDATA[
<p class="has-medium-font-size">產業資料庫重要嗎？如果你想讓選股技巧更上一層樓，勢必會進階到產業分析。<br>投資標的的優劣評價，除了自己跟自己比，例如近期財報是否較過去改善，另一個判斷企業競爭力的評價方式，就是跟同業比，好壞都是比較而來的，選對比較基準才讓評價有意義。<br>除了同業個股比較，產業資料庫的另一個主要應用在找出族群趨勢，如果一個產業的企業的營收或股價趨勢都向上，那代表該產業蒸蒸日上，有產業景氣良好的基本面護體，更能增加投資判斷把握度與可解釋性，排除單一個股炒作的個別性，更進階的應用甚至可延伸到概念股落後補漲效應。<br>這一切的應用的基礎都建構在「產業資料庫」的分類，這篇教學文章將說明FinLab的「<a href="https://ai.finlab.tw/database#security_industry_themes" target="_blank" rel="noopener">產業題材資料庫</a>」的簡單應用，並教你如何用 Python 與 Pandas 基礎語法去「客製化」自己的產業分類，讓產業資料庫更豐富。</p>



<h2>產業資料</h2>



<p class="has-medium-font-size">FinLab 的細產業主題資料來源主要取自「<a href="https://ic.tpex.org.tw/" target="_blank" rel="noreferrer noopener">產業價值鍊資訊平台</a>」，少部分為自定義分類。從&nbsp;<a href="https://ai.finlab.tw/database#security_industry_themes" target="_blank" rel="noreferrer noopener">FinLab資料庫</a>&nbsp;只要一行程式碼就能下載全部的細產業資訊，讓你輕鬆以此基礎做後續應用。要注意的是此份資料僅限&nbsp;<a href="https://ai.finlab.tw/pricing" target="_blank" rel="noreferrer noopener">VIP</a>&nbsp;使用。<br><a href="https://ic.tpex.org.tw/" target="_blank" rel="noreferrer noopener">產業價值鍊資訊平台</a>&nbsp;會將主產業再分拆上下游的細產業，讓你更精細的去比較，否則證交所一般分類光半導體就近百檔，比較效果相對籠統。</p>



<figure class="wp-block-image"><img src="https://www.finlab.tw/wp-content/uploads/2022/11/%E6%88%AA%E5%9C%96-2022-11-02-%E4%B8%8A%E5%8D%887.30.52-1024x404.png" alt="截圖 2022 11 02 上午7.30.52" class="wp-image-4756" title="產業面選股策略｜同業本益比比較法 1"/><figcaption>資料庫欄位</figcaption></figure>



<p class="has-medium-font-size">每家公司所屬產業的資訊放在 catergory 內，category 欄位的型態是文字格式，所有產業分類會放入 List 後再包成文字型態，從該資料得知公司分別有哪些產業的標籤。<br>例如1101台泥的產業序列裡有主產業的水泥，也有細產業「水泥:水泥成品」、「水泥:水泥熟料」(格式為「主產業:細產業 or 主產業」)。</p>



<figure class="wp-block-image"><img src="https://www.finlab.tw/wp-content/uploads/2022/11/%E6%88%AA%E5%9C%96-2022-11-02-%E4%B8%8A%E5%8D%887.35.04-1024x810.png" alt="截圖 2022 11 02 上午7.35.04" class="wp-image-4757" title="產業面選股策略｜同業本益比比較法 2"/></figure>



<h2>簡單查詢應用</h2>



<p class="has-medium-font-size">如果我們想查詢哪些公司屬於水泥產業？我們可以運用pandas內的 <a href="https://pandas.pydata.org/docs/reference/api/pandas.Series.str.contains.html" target="_blank" rel="noopener">Series.str.contains</a>，讓我們快速分類出產業名單，如下範例，只要「category」欄位內含「水泥」兩字，就會被納入範圍。</p>



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

# 取出產業題材
themes = data.get('security_industry_themes')

# 選出產業包含「水泥」的公司
ind1 = themes[themes['category'].str.contains('水泥')]
</code></pre>



<figure class="wp-block-image size-large"><img loading="lazy" width="1024" height="513" src="https://www.finlab.tw/wp-content/uploads/2022/12/截圖-2022-12-20-下午12.36.55-1024x513.png" alt="截圖 2022 12 20 下午12.36.55" class="wp-image-4972" srcset="https://www.finlab.tw/wp-content/uploads/2022/12/截圖-2022-12-20-下午12.36.55-1024x513.png 1024w, https://www.finlab.tw/wp-content/uploads/2022/12/截圖-2022-12-20-下午12.36.55-300x150.png 300w, https://www.finlab.tw/wp-content/uploads/2022/12/截圖-2022-12-20-下午12.36.55-768x384.png 768w, https://www.finlab.tw/wp-content/uploads/2022/12/截圖-2022-12-20-下午12.36.55-1536x769.png 1536w, https://www.finlab.tw/wp-content/uploads/2022/12/截圖-2022-12-20-下午12.36.55.png 1894w" sizes="(max-width: 1024px) 100vw, 1024px" title="產業資料庫的基礎應用 1"></figure>



<p class="has-medium-font-size">contains 語法支援 or 的運用，如果我們今天想選出產業包含「水泥」或「建材營造」的公司，可以使用以下語句，使用&#8217;|&#8217;的符號做邏輯運算串連：</p>



<p class="has-medium-font-size"> <code>ind2 = themes[themes['category'].str.contains('水泥|建材營造')]</code> </p>



<figure class="wp-block-image size-large"><img loading="lazy" width="1024" height="532" src="https://www.finlab.tw/wp-content/uploads/2022/12/截圖-2022-12-20-下午12.37.48-1024x532.png" alt="截圖 2022 12 20 下午12.37.48" class="wp-image-4973" srcset="https://www.finlab.tw/wp-content/uploads/2022/12/截圖-2022-12-20-下午12.37.48-1024x532.png 1024w, https://www.finlab.tw/wp-content/uploads/2022/12/截圖-2022-12-20-下午12.37.48-300x156.png 300w, https://www.finlab.tw/wp-content/uploads/2022/12/截圖-2022-12-20-下午12.37.48-768x399.png 768w, https://www.finlab.tw/wp-content/uploads/2022/12/截圖-2022-12-20-下午12.37.48-1536x799.png 1536w, https://www.finlab.tw/wp-content/uploads/2022/12/截圖-2022-12-20-下午12.37.48-2048x1065.png 2048w" sizes="(max-width: 1024px) 100vw, 1024px" title="產業資料庫的基礎應用 2"></figure>



<h2>簡單回測範例</h2>



<p class="has-medium-font-size">「想挑出水泥產業中，本益比低於水泥產業本益比中位數之個股當投資組合」</p>



<p class="has-medium-font-size">實作很簡單，用前述contains篩選的stock_id，套入本益比資料做欄位圈選，就能限定資料範圍，再運用 <code>median(axis=1)</code>，計算每日產業本益比中位數，axis=1的用途在取每一期(橫列)的中位數。</p>



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

# 取出產業題材
themes = data.get('security_industry_themes')

# 選出產業包含「水泥」公司
ind = themes[themes['category'].str.contains('水泥')]
pe = data.get('price_earning_ratio:本益比')
ind_pe = pe[list(ind['stock_id'])]

# 計算每日產業本益比中位數,axis=1的用途在取每一期(橫列)的中位數
ind_pe_med = ind_pe.median(axis=1)

# 選出本益比小於同業本益比中位數且本益比小於25的公司
position = (ind_pe &lt; ind_pe_med) &amp; (ind_pe &lt; 25)

# 回測
report = sim(position, upload=False)
report.display()</code></pre>



<figure class="wp-block-image"><img loading="lazy" width="800" height="600" src="https://www.finlab.tw/wp-content/uploads/2022/11/newplot-2.png" alt="newplot 2" class="wp-image-4758" title="產業面選股策略｜同業本益比比較法 3" srcset="https://www.finlab.tw/wp-content/uploads/2022/11/newplot-2.png 800w, https://www.finlab.tw/wp-content/uploads/2022/11/newplot-2-300x225.png 300w, https://www.finlab.tw/wp-content/uploads/2022/11/newplot-2-768x576.png 768w" sizes="(max-width: 800px) 100vw, 800px" /></figure>



<h2>自定義產業分類</h2>



<p class="has-medium-font-size">有時我們發現產業價值鏈資訊平台的分類仍不能滿足需求，像是他缺少概念股的標籤資料，學會Python 的好處在我們可以任意擴展資料，去自定義新增的分類。<br>使用開發好的 create_new_industry_themes 的函式去創建新的產業分類，其中 additional_themes 變數控制新增標籤，格式為<code>[([目標群],[標籤群]),...]</code>。<br><br>例如以下範例對&#8217;6684&#8242;, &#8216;6756&#8217;, &#8216;3014&#8217; 新增 &#8216;元宇宙:祖克柏概念股&#8217; 的標籤，對&#8217;1342&#8242;, &#8216;1584&#8217;新增&#8217;航太週邊:空中巴士概念股&#8217;的標籤，對&#8217;2342&#8242;, &#8216;3317&#8217;, &#8216;4923&#8217;, &#8216;5299&#8217;, &#8216;6287&#8217; 增加兩個標籤&#8217;半導體:基礎元件&#8217;, &#8216;通訊產業:通訊元件&#8217;。</p>



<pre class="wp-block-code"><code lang="python" class="language-python">def add_sub_group(dataframe, stock_list: list, theme_list: list):
    try:
        dataframe.loc[stock_list]['category'] = dataframe.loc[stock_list]['category'].apply(
            lambda s: s.extend(theme_list))
    except KeyError:
        print('stock_list not in index.')
    return dataframe


def process_sub_group_list(sub_group_list):
    sub_group_list.extend(list(set({i[:i.index(':')] for i in sub_group_list if ':' in i})))
    return sorted(list(set(sub_group_list)))


def create_new_industry_themes(additional_themes):

    df = data.get('security_industry_themes')
    df = df.set_index(['stock_id', 'name'])
    df['category'] = df['category'].apply(lambda s: eval(s))

    if additional_themes:
        for stock_list, theme_list in additional_themes:
            df = add_sub_group(df, stock_list, theme_list)

    df['category'] = df['category'].apply(lambda s: process_sub_group_list(s))
    df = df.astype(str)
    df = df.reset_index()
    return df


additional_themes = [
    (['6684', '6756', '3014'], ['元宇宙:祖克柏概念股']),
    (['1342', '1584'], ['航太週邊:空中巴士概念股']),
    (['2342', '3317', '4923', '5299', '6287'], ['半導體:基礎元件', '通訊產業:通訊元件']),
]


new_themes = create_new_industry_themes(additional_themes)
# 檢查6684 是否成功新增標籤
new_themes[new_themes['stock_id']=='6684']['category'].values</code></pre>



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



<figure class="wp-block-image size-large"><img loading="lazy" width="1024" height="699" src="https://www.finlab.tw/wp-content/uploads/2022/12/截圖-2022-12-20-下午2.02.42-1024x699.png" alt="截圖 2022 12 20 下午2.02.42" class="wp-image-4974" srcset="https://www.finlab.tw/wp-content/uploads/2022/12/截圖-2022-12-20-下午2.02.42-1024x699.png 1024w, https://www.finlab.tw/wp-content/uploads/2022/12/截圖-2022-12-20-下午2.02.42-300x205.png 300w, https://www.finlab.tw/wp-content/uploads/2022/12/截圖-2022-12-20-下午2.02.42-768x524.png 768w, https://www.finlab.tw/wp-content/uploads/2022/12/截圖-2022-12-20-下午2.02.42-1536x1049.png 1536w, https://www.finlab.tw/wp-content/uploads/2022/12/截圖-2022-12-20-下午2.02.42.png 1797w" sizes="(max-width: 1024px) 100vw, 1024px" title="產業資料庫的基礎應用 3"></figure>



<p class="has-medium-font-size">執行完含式後，會發現 new_themes 已有新增資料～之後就可以用自定義後的 new_themes  做產業分析囉！</p>



<h2>小結</h2>



<p class="has-medium-font-size"><a href="https://colab.research.google.com/drive/15PQ_W_6xUZ1lHlDWaNZtZgsUPZPMiove?usp=sharing" target="_blank" rel="noopener">colab程式範例</a><br><br>學會基礎的產業資料的資料處理技巧後，就可以進行許多分析與策略開發，像是「<a href="https://www.finlab.tw/industry_pe_strategy/">產業面選股策略｜同業本益比比較法</a>」就是延伸的應用喔！<br>如果有自己的產業分類標籤可以加入，那就會進化成個人獨有的資料，可能創造出不易被模仿的策略或產業觀察指標。</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.finlab.tw/industry_themes_database_basic_application/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">4971</post-id>	</item>
		<item>
		<title>台股財報資料豆知識 ｜ 時序索引操作</title>
		<link>https://www.finlab.tw/tw_stock_financial_statement_time_series_knowledge/</link>
					<comments>https://www.finlab.tw/tw_stock_financial_statement_time_series_knowledge/#respond</comments>
		
		<dc:creator><![CDATA[Ben]]></dc:creator>
		<pubDate>Fri, 28 Oct 2022 10:31:13 +0000</pubDate>
				<category><![CDATA[Python新手教學]]></category>
		<category><![CDATA[FinLab 量化平台]]></category>
		<category><![CDATA[生產力]]></category>
		<category><![CDATA[FinlabDataframe]]></category>
		<category><![CDATA[台股]]></category>
		<category><![CDATA[策略開發豆知識]]></category>
		<category><![CDATA[財報]]></category>
		<category><![CDATA[資料處理]]></category>
		<guid isPermaLink="false">https://www.finlab.tw/?p=4720</guid>

					<description><![CDATA[目前正逢財報季，有些公司已經上傳第三季財報，許多已基本面為選股主軸的用戶都開始緊盯自己的程式是否跑出新的指引？許多新手用戶對財報資料的發佈時間和資料操作不熟悉，這篇文章將娓娓道來台股財報資料的時序細節，花幾分鐘，你會了解財報「發布日、截止日、FinlabDataFrame的資料索引轉換方法，讓你上手財報資料選股策略。]]></description>
										<content:encoded><![CDATA[
<p class="has-medium-font-size">目前正逢財報季，有些公司已經上傳第三季財報，許多已基本面為選股主軸的用戶都開始緊盯自己的程式是否跑出新的指引？藉於新手用戶對財報資料的發佈時間和資料操作不熟悉，這篇文章將娓娓道來台股財報資料的時序細節，花幾分鐘，你會了解財報「發布日、截止日、FinlabDataFrame的資料索引轉換方法，讓你上手財報資料選股策略的前處理。</p>



<h2>財報發布日定義</h2>



<p class="has-medium-font-size">FinLab 資料庫系統會每天更新、檢查財報資料，財報發布日以<a href="https://doc.twse.com.tw/server-java/t57sb01?step=1&amp;colorchg=1&amp;co_id=1101&amp;year=&amp;seamon=&amp;mtype=A&amp;" target="_blank" rel="noopener">財報電子檔</a>內的資料上傳日當基準資料。你可能疑惑怎麼在新聞或公司重訊已看到 EPS 多少了，但抓下的財報或財報電子檔卻沒有當季資料？那是因為有些公司的財報電子檔上傳日會比董事會重訊發布晚個幾天，通常是因為公司內部或會計作業問題，某些會計項目可能還會再校對或微調等等，實際數字以公司財報完整電子檔上傳才是比較穩當的做法。 大部分的公司會在財報截止日前一週內才上傳完畢。</p>



<h2>財報截止日定義</h2>



<p class="has-medium-font-size">所有公司都必須在每季財報截止日前上傳財報電子書，若沒有即時上傳，通常代表財務狀況出問題、會計師審核上出狀況&#8230;若沒在規定期限內補正，後續面臨暫停交易或下市風險。<br>台股上市櫃公司一年要上傳4次財報，興櫃只要上傳第二季和第四季財報，監理強度不同。各產業截止日細節如下列供參：</p>



<h3>上市櫃一般公司</h3>



<p class="has-medium-font-size">季別/財報截止日對應為下列對應，遇假日則遞延到次一個交易日。</p>



<ul class="has-medium-font-size"><li>Q1：當年5/15</li><li>Q2：當年8/14。若為2021年後的KY股，因監管法規改變，改成8/31。</li><li>Q3：當年11/14</li><li>Q4：次年3/31</li></ul>



<h3>保險業</h3>



<p class="has-medium-font-size">季別/財報截止日對應為下列對應，遇假日則遞延到次一個交易日。</p>



<ul class="has-medium-font-size"><li>Q1：當年4/30</li><li>Q2：當年8/31</li><li>Q3：當年10/30</li><li>Q4：次年3/31</li></ul>



<h3>金融業</h3>



<p class="has-medium-font-size">這邊指的是非保險的金融業，如銀行、證券、票券、金控業者。季別/財報截止日對應為下列對應，遇假日則遞延到次一個交易日。</p>



<ul class="has-medium-font-size"><li>Q1：當年5/15</li><li>Q2：當年8/31</li><li>Q3：當年11/14</li><li>Q4：次年3/31</li></ul>



<h2>量化平台財報資料操作</h2>



<h3>取得資料</h3>



<p class="has-medium-font-size">至<a href="https://ai.finlab.tw/database/#financial_statement" target="_blank" rel="noopener">財報資料庫</a>複製財報項目的使用方法，即可取得財報資料。<br>欄位是每家公司的股號，包含所有公開發行公司，索引則是每季的季別，ex : 2013Q1。<br>新手會疑惑為什麼看到一堆NaN ?不要緊張，不是資料出問題，而是這些公司當時未上市櫃或按規定不用發布財報。</p>



<figure class="wp-block-image size-large"><img loading="lazy" width="1024" height="565" src="https://www.finlab.tw/wp-content/uploads/2022/10/截圖-2022-10-28-下午5.25.31-1024x565.png" alt="截圖 2022 10 28 下午5.25.31" class="wp-image-4721" srcset="https://www.finlab.tw/wp-content/uploads/2022/10/截圖-2022-10-28-下午5.25.31-1024x565.png 1024w, https://www.finlab.tw/wp-content/uploads/2022/10/截圖-2022-10-28-下午5.25.31-300x166.png 300w, https://www.finlab.tw/wp-content/uploads/2022/10/截圖-2022-10-28-下午5.25.31-768x424.png 768w, https://www.finlab.tw/wp-content/uploads/2022/10/截圖-2022-10-28-下午5.25.31-1536x848.png 1536w, https://www.finlab.tw/wp-content/uploads/2022/10/截圖-2022-10-28-下午5.25.31-2048x1130.png 2048w" sizes="(max-width: 1024px) 100vw, 1024px" title="台股財報資料豆知識 ｜ 時序索引操作 4"></figure>



<p class="has-medium-font-size">另外提一個小技巧，如果你想要拿掉未上市櫃公司來方便觀察資料，可以使用pandas的<a href="https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.dropna.html" target="_blank" rel="noopener">dropna</a>進行操作。下面的例子會排除掉每一欄位沒有20格有數值的欄位，篩出上市櫃有較久歷史的公司，就可以顯示中間部分的資料，像是1101台泥等等。</p>



<figure class="wp-block-image size-large"><img loading="lazy" width="1024" height="534" src="https://www.finlab.tw/wp-content/uploads/2022/10/截圖-2022-10-28-下午5.34.53-1024x534.png" alt="截圖 2022 10 28 下午5.34.53" class="wp-image-4722" srcset="https://www.finlab.tw/wp-content/uploads/2022/10/截圖-2022-10-28-下午5.34.53-1024x534.png 1024w, https://www.finlab.tw/wp-content/uploads/2022/10/截圖-2022-10-28-下午5.34.53-300x157.png 300w, https://www.finlab.tw/wp-content/uploads/2022/10/截圖-2022-10-28-下午5.34.53-768x401.png 768w, https://www.finlab.tw/wp-content/uploads/2022/10/截圖-2022-10-28-下午5.34.53-1536x802.png 1536w, https://www.finlab.tw/wp-content/uploads/2022/10/截圖-2022-10-28-下午5.34.53-2048x1069.png 2048w" sizes="(max-width: 1024px) 100vw, 1024px" title="台股財報資料豆知識 ｜ 時序索引操作 5"></figure>



<h3>時序轉換</h3>



<p class="has-medium-font-size">上面原始財報數據的日期索引是如「2022-Q1」這類的文字格式，雖然回測將不同尺度的資料取交集時會自動將時序轉成財報發布日的datetime格式，但若有其他用途，想將時序索引從文字轉換成財報發布日的datetime格式，該如何做呢？</p>



<h4>季別文字轉財報發佈日</h4>



<p class="has-medium-font-size">轉非常的簡單，只要加上 <code>index_str_to_date()</code> ，就能將資料轉換，這是<a href="https://doc.finlab.tw/reference/dataframe/#finlab.dataframe.FinlabDataFrame.index_str_to_date" target="_blank" rel="noopener">FinlabDataFrame</a>類別內建的方法。<br>從下圖所示，可以看到加完 <code>index_str_to_date()</code>後，索引改變了。<br>要注意的是，如果公司還沒有正式上傳「<a href="https://doc.twse.com.tw/server-java/t57sb01?step=1&amp;colorchg=1&amp;co_id=1101&amp;year=&amp;seamon=&amp;mtype=A&amp;" target="_blank" rel="noopener">財報電子書</a>」，雖然<a href="https://mops.twse.com.tw/mops/web/t203sb02" target="_blank" rel="noopener">XBRL資訊平台</a>已經有數值可下載，但由於財報電子書上傳日資料未定，資料仍會被歸到截止日的欄位。<br>現在正臨2022-Q3財報季，沒有財報電子書上傳日的數值都會放到最後兩欄的財報截止日，2022-10-31是保險業Q3截止日、2022-11-14則是一般上市櫃公司的Q3截止日，不用擔心回測會用到未來資料，回測會再去與收盤價的交易日索引做對應，遇假日會遞延到下一個交易日。<br>你可能會好奇，公司每季只會發布一次財報，為何日期會那麼多天？那是因為只要A日有任一家公司有上傳紀錄，為方便回測，索引都會加入發布日，如果其他公司在A日沒發布財報，其他公司則會套用近一期數值做填充。</p>



<figure class="wp-block-image size-large"><img loading="lazy" width="1024" height="486" src="https://www.finlab.tw/wp-content/uploads/2022/10/截圖-2022-10-28-下午5.48.13-1024x486.png" alt="截圖 2022 10 28 下午5.48.13" class="wp-image-4723" srcset="https://www.finlab.tw/wp-content/uploads/2022/10/截圖-2022-10-28-下午5.48.13-1024x486.png 1024w, https://www.finlab.tw/wp-content/uploads/2022/10/截圖-2022-10-28-下午5.48.13-300x142.png 300w, https://www.finlab.tw/wp-content/uploads/2022/10/截圖-2022-10-28-下午5.48.13-768x364.png 768w, https://www.finlab.tw/wp-content/uploads/2022/10/截圖-2022-10-28-下午5.48.13-1536x728.png 1536w, https://www.finlab.tw/wp-content/uploads/2022/10/截圖-2022-10-28-下午5.48.13-2048x971.png 2048w" sizes="(max-width: 1024px) 100vw, 1024px" title="台股財報資料豆知識 ｜ 時序索引操作 6"></figure>



<h4>季別文字轉財報截止日</h4>



<p class="has-medium-font-size">若想使用財報截止日做回測與選股，可以使用 <code>deadline()</code> ，就能將資料轉換，這是<a href="https://doc.finlab.tw/reference/dataframe/#finlab.dataframe.FinlabDataFrame.deadline" target="_blank" rel="noopener">FinlabDataFrame</a> 類別內建的方法。注意財報資料與其他時間尺度的資料做交集時，預設是使用財報發布日，所以若要使用截止日當條件，一定要加上 <code>deadline()</code>，使用範例如下。</p>



<figure class="wp-block-image size-large"><img loading="lazy" width="1024" height="366" src="https://www.finlab.tw/wp-content/uploads/2022/10/截圖-2022-10-28-下午6.06.38-1024x366.png" alt="截圖 2022 10 28 下午6.06.38" class="wp-image-4724" srcset="https://www.finlab.tw/wp-content/uploads/2022/10/截圖-2022-10-28-下午6.06.38-1024x366.png 1024w, https://www.finlab.tw/wp-content/uploads/2022/10/截圖-2022-10-28-下午6.06.38-300x107.png 300w, https://www.finlab.tw/wp-content/uploads/2022/10/截圖-2022-10-28-下午6.06.38-768x274.png 768w, https://www.finlab.tw/wp-content/uploads/2022/10/截圖-2022-10-28-下午6.06.38-1536x548.png 1536w, https://www.finlab.tw/wp-content/uploads/2022/10/截圖-2022-10-28-下午6.06.38-2048x731.png 2048w" sizes="(max-width: 1024px) 100vw, 1024px" title="台股財報資料豆知識 ｜ 時序索引操作 7"></figure>



<p class="has-medium-font-size">截止日日期索引包括一般公司、保險業、金融業的規定日期，若當日沒數值，則會拿近一筆數值來補，以方便回測。</p>



<h2>結論</h2>



<p class="has-medium-font-size">經過上述說明，是不是對 FinLab 量化平台的財報資料操作與原理更為熟悉了呢？<br>如果想進一步學習用財報來選股，可參考這篇<a href="https://www.finlab.tw/basic_score_strategy/">財務指標計分法的教學</a>～<br>如果還有其他相關問題，歡迎隨時與我們討論喔！</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.finlab.tw/tw_stock_financial_statement_time_series_knowledge/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">4720</post-id>	</item>
	</channel>
</rss>
