如何計算ETF的PE ratio — QQQ?

閱讀時間約 3 分鐘
  • 文內如有投資理財相關經驗、知識、資訊等內容,皆為創作者個人分享行為。
  • 有價證券、指數與衍生性商品之數據資料,僅供輔助說明之用,不代表創作者投資決策之推介及建議。
  • 閱讀同時,請審慎思考自身條件及自我決策,並應有為決策負責之事前認知。
  • 方格子希望您能從這些分享內容汲取投資養份,養成獨立思考的能力、判斷、行動,成就最適合您的投資理財模式。

之前在如何計算ETF的PE ratio — 00878?中討論到如何使用計算00878的PE以進行對於此ETF的估值,我們發現關鍵在於如何有效撈取一檔ETF的成分和持有股數和其市值(或發行股數),此篇我們繼續探討如何撈取計算Invesco納斯達克100指數ETF-QQQ的本益比。關於QQQ的介紹,可以參考此連結

You can check this for the English version!

raw-image

以下為建議步驟:

步驟1: 安裝相關套件。

!pip install pandas
!pip install yfinance

步驟2: 根據此官方連結獲取QQQ的基本資訊,包含持倉、每檔持有股數、市值等。

import pandas as pd
df = pd.read_csv('https://www.invesco.com/us/financial-products/etfs/holdings/main/holdings/0?audienceType=Investor&action=download&ticker=QQQ')
raw-image

步驟3: 我們唯一無法在上述檔案獲取的資訊是每當持倉獲利情況,也就是EPS。

  • 定義撈取EPS的函式。
  • 將持倉代碼(Ticker)丟進函式撈取EPS。
def get_info(tickers):
try:

details = yf.Tickers(tickers)
forwardEps = details.tickers[tickers].info.get('forwardEps')

except:
# print(error)
pass

return forwardEps
for row in df.to_records(index=False):
ticker = str(row[2]).strip()
eps = get_info(ticker)
print(eps)
filt = df['Holding Ticker'] == str(row[2])
df.loc[filt, 'eps'] = eps
raw-image

步驟4: 計算總盈餘和總市值,並利用此數字算出本益比。

df['Earning'] = df['Shares/Par Value'].str.replace(',', '', regex=True).astype(float) * df['eps'].astype(float)
Earning_QQQ = df['Earning'].sum()

MarketValues_QQQ = df['MarketValue'].str.replace(',', '', regex=True).astype(float).sum()

MarketValues_QQQ / Earning_QQQ
raw-image

Thank you and more to come! We will talk about this topic for more ETFs, approaches, matrices, etc. Enjoy it :)

If you want to support Informula, you can buy us a coffee here :)

𝗕𝘂𝘆 𝗺𝗲 𝗮 𝗰𝗼𝗳𝗳𝗲𝗲


6會員
17內容數
Informula 作為上班族的臨時急救包,介紹一些簡單的程式工具、資料處理、數據分析、網路爬蟲應用等。
留言0
查看全部
發表第一個留言支持創作者!