è¿å¹´è¡å¸ççç±ï¼å°è´æ¼è¨±å¤æ²æåæè³çæååé½æ³ä¾è¡å¸åä¸æ¯ç¾¹ï¼è身çºç¡é è¼è çä»åï¼é½æé¸ææå¿«çæ¶äººå ï¼å¤è½å¹¾åYoutuberãPodcasterç建è°ï¼ä¸çæ¨èªªï¼é好åçæ¯åä¸é¯çæ¹æ³ï¼ãæå¾é群ç¡é è¼è ççµè«é½æ¯ãå®åETFææ¸è¡ãã é樣ççµè«è³å°ç¢ºå®ï¼è½YoutuberãPodcasterç建è°æ¯é£äºæ顧å師好å¾å¤ï¼è³å°ç¸è¼ä¹ä¸ï¼èä½æåä½å¼å°éèåæ¥ç¤çæ©çå°å¾å¤ï¼éåå §å¹ææ©æå¨å享ï¼ãèæ¥ä¸ä¾é群æåå°±éå§åæãéæä»éº¼è¡ç¥¨ETFé¡ä¼¼0050ï¼ãããä½ èå¸ç¨åªä¸å®¶ï¼ãããéæç麼風éªï¼ã
å ççï¼ä½ ç¾å¨ETFè²·ä¸å»ï¼å¹³å7~15å¹´ææè³ºä½ ç¥éåï¼
å¨æ¬æä¸é¤äºå享æ¯æ°£çèèè¡å¸å¤§ç¤çéä¿ï¼æ¹ä¾¿æ¨é¸ææè³ETFçææ©å¤ï¼æ´å©ç¨Python繪製åºè¦è¦ºåçã大ç¤èæ¯æ°£çèéä¿æ²ç·ãï¼è®æåè½å¤ æ´è¼é¬çå¤æ·ç¾å¨ç趨å¢æ¯å¦æåä¸æé·ï¼æçºéå§ç´¯ç©ETFç好ææ©ã
è¦åï¼æ¬æç« å §å®¹å ä½çºç¨å¼å享èç¯ä¾ï¼ä¸¦éæè³å»ºè°ï¼åºæ¼æç« ä¹ä»»ä½äº¤æææè³æ±ºå®ï¼ä½¿ç¨è é èªè² 風éªåçè§ï¼æ¬æç« èç¨å¼äº¦ä¸è² ä»»ä½è²¬ä»»
éååå å ¶å¯¦å¾å¥½ç解ï¼å¦ææ²æè¨ç«æ§æè³ï¼é£æåå¨æè³ETFé常é½æ¯å®æå®é¡æè³ï¼é£æ¨çæè³ææ¬å°±æ¯æ¯æ¬¡æè³éé¡çå¹³åãè¥ä¸å¹¸çï¼æ¨æè³çæéå好æ¯å¤§ç¤çé«é»é£ä¹å¾å¾å¤§ç¤ä¸åæªï¼å¨çä»æ¼²åä¾çæéï¼å·®ä¸å¤å°±æ¯ä¸åç¶æ¿å¾ªç°ï¼7~15å¹´ï¼ï¼å æ¤æè³ææ¸åETF風éªç確å£å¾å¾ä½äºï¼ä½è²·é»ææ¯éé æè³ä¸å¾éè¦çå ç´ ã
ç¨æ¯è¼å¸è¡çåæ³æ¯ï¼å¸å ´ä¸æé 測大ç¤è¡å¸çãé å ææ¨ãåï¼æ¯æçï¼èä¸ä½ æ©å°±è½éäºãç¸ä¿¡æ¨ç¥éãæ¯æ°£çèãéåæ¿åºæä¾çææ¨ï¼ç¨ä¾æ¨æ並ååç¾å¨å家çç¶æ¿ç±åº¦ï¼éåç¶æ¿èª²æ¬ä¸ççè«ç¥èï¼è·å¤§ç¤æç麼éä¿ï¼çæ¡æ¯æ¯æ¯ç¸éã
é裡æåå ççµæãå¯ä»¥ç¼ç¾æ¯æ¬¡æ¯æ°£çèçæ¸å¼éå§ä¸éå¾æ²å¤ä¹ ï¼å¤§ç¤ä¹è·èéå§ä¸æ»ï¼éç¶ä¸éçééçèµ·ä¾å¾çï¼ä½å ¶å¯¦æå°ä¹ç¸å·®1~3åæä¹ä¹ ãä¹å°±æ¯èªªï¼ç¶æ¯æ°£çèéå§åè½ä¹å¾ï¼å¨åå¹´å §å¤§ç¤å¿ å®ä¹æè·èä¸æ»ï¼éæ¯æåå¾çµæä¸è§å¯å¾ç¥çã
å¾ç¶æ¿å¸çè§åº¦ä¹ä¸é£ç解ï¼æ¯æ°£çèè大ç¤åæé½æ¯åæ ä¸åå家çç¶æ¿çæ³ï¼è大ç¤ççæè®åå¤åä¾èªæ¼æ´é«æè³äººç測çæ¹åï¼é¤éæéé«ææ ç¢ç(å¦éèæµ·å¯)ï¼å¦åç測æ¨æºä¹ä¾èªæ¼ãå°ç®åç¶æ¿å¸å ´çé«é©ãï¼è¬å¦æè¿ç©å¹å¦ãæ¿è²¸è»è²¸å©çãå ¬å¸å«ææ æ³ï¼èéäºåæ¸ï¼å ¶å¯¦é½è¢«å å«å¨æ¯æ°£çèå §ä½çºç¢åºå åï¼å æ¤æ¯æ°£çèè½æçºå¤§ç¤çé å ææ¨ä¹æ¯åæ åççã
å¨æ¬æ¬¡ç實ä½ä¸ï¼ä»ç¶æç¨å°pandas_datareaderä¾åå¾å¤§ç¤çèµ°å¢ï¼å æ¤ä¹éè¦å°æ¤å¥ä»¶å å¼å ¥ã
import datetime
import matplotlib
matplotlib.use('TkAgg')
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
from pandas_datareader import data
# éè¦ç¨æ¤å¥å»ºè¼å
¥yahooçAPIï¼å¦åç¡æ³åå¾è³è¨
import yfinance as yf
yf.pdr_override()
å¨pandas_datareaderå¥ä»¶ä¸çå°ç£ææ¸ä»£èçºã^TWIIããé次æåå¾é·æçè§åº¦ä¾å¯¦èéåè«è¿°ï¼å æ¤å¾2001å¹´éå§æåæ¯æ°£çèï¼å ¶ä¸å°±ç¶æ·äº2008å¹´éèæµ·å¯ï¼çå®ä¸æ´åå®æ´çç¶æ¿å¾ªç°æè½é«ç¾ä¸åçè«ç實è¸ã
#--- æå大ç¤çè¡å¹è®å
# å
è¨å®è¦ç¬çæé
start = datetime.datetime.strptime('20010101',"%Y%m%d")
end = datetime.datetime.strptime('20221231',"%Y%m%d")
# åå¾å
¨å°ç£ææçè¡ç¥¨ï¼æ¯å¤©ç交æè³è¨
df_stock = data.get_data_yahoo('^TWII', start, end)
ç±æ¼æ¯æ°£çèçå®ä½æ¯ãæãï¼å æ¤å°æçç·åä¹å¿ é 以æç·åç¾ï¼é樣æè½å¨åä¸ååºæºä¸åæ¯è¼ãå æ¤é裡éè¦åä¾ç §å¹´ææåºè³æ並å併平åã
# æ´çåºæ¥ææ¬ä½ï¼è¨ç®ææ¸çæå¹³åç·
df_stock['æ¥æ'] = df_stock.index
df_stock['å¹´æ'] = df_stock['æ¥æ'].dt.strftime('%Y-%m')
M_index = df_stock[['å¹´æ','Close']].groupby('å¹´æ').mean()
M_index['æ¥æ'] = pd.to_datetime(M_index.index)
æ³è¦åå¾æ¯æ°£çèçè³æå ¶å¯¦é常簡å®ï¼åç¼æå°±ææä¾ä¸è¼ç管éï¼æ·å²æ¯æ°£çèé½å¯ä»¥ä¸è¼ï¼å æ¤åªéè¦å°é裡é¸ææ³è¦çæéåéé²è¡ä¸è¼å°±å¯ä»¥äºã
#--- å¼å
¥å家æ¯æ°£çèè³æ
monitoring_indicator = pd.read_excel('精氣çè.xls')
monitoring_indicator.columns = ['æ¥æ','æ¯æ°£å°çä¿¡è(çè)','æ¯æ°£å°çä¿¡è(å)']
monitoring_indicator['æ¥æ'] = pd.to_datetime(monitoring_indicator['æ¥æ'])
ç±æ¼éå¼µåéè¦åæå å ¥å¤§ç¤æç·ãæ¯æ°£çèãæéä¸ååæ¸ï¼å æ¤å¿ é è¦ä½¿ç¨éY軸ç繪製æ¹å¼ãå¨matplotlib繪ååï¼å¿ çºéå å°ç«å¸åå²æå ©åä¾é²è¡ç¹ªåã
#--- éå§ç¹ªè£½ã大ç¤èæ¯æ°£çèéä¿æ²ç·ã
fig, ax1 = plt.subplots()
plt.title('大ç¤èæ¯æ°£çèéä¿æ²ç·')
plt.xlabel('æ¥æ')
ax2 = ax1.twinx()
ax1.set_ylabel('å°ç£ææ¸', color='#5d82bb')
ax1.plot(
M_index['æ¥æ'],
M_index['Close'],
color='#5d82bb',
alpha=0.5)
ax1.tick_params(axis='y', labelcolor='tab:blue')
ax2.set_ylabel('æ¯æ°£çè', color='#bb965d')
ax2.plot(
monitoring_indicator['æ¥æ'],
monitoring_indicator['æ¯æ°£å°çä¿¡è(å)'],
color='#bb965d',
alpha=0.5)
ax2.tick_params(axis='y', labelcolor='black')
fig.tight_layout()
plt.show()
è¦åï¼æ¬æç« å §å®¹å ä½çºç¨å¼å享èç¯ä¾ï¼ä¸¦éæè³å»ºè°ï¼åºæ¼æç« ä¹ä»»ä½äº¤æææè³æ±ºå®ï¼ä½¿ç¨è é èªè² 風éªåçè§ï¼æ¬æç« èç¨å¼äº¦ä¸è² ä»»ä½è²¬ä»»
å°æ¼é·ææè³ãå®æå®é¡çæè³äººä¾èªªï¼æ¯æ°£çèçµå°æ¯å¿ é å å ¥åèçè¦ä»¶ï¼é¸å°æéå ¥å ´ï¼è½è®è³éç¼ææ大çæç¨ãä½è æ¬èº«ä¹æ¯å好é·ææè³ç人ï¼èæå ¶å¯¦ä¹æ¯ä½¿ç¨éå¥æ¹æ³ä¾è©ä¼°å ¥å ´æéï¼å æ¤ä¹å享給æç·£è®å°æ¤ç¯æç« çæ¨ã
作者:楊超霆 行銷搬進大程式 創辦人