Informula

Informula

Share this post

Informula
Informula
How to Calculate PE ratio for ETFs via Python in Colab - QQQ

How to Calculate PE ratio for ETFs via Python in Colab - QQQ

Informula's avatar
Informula
Sep 13, 2023
∙ Paid

Share this post

Informula
Informula
How to Calculate PE ratio for ETFs via Python in Colab - QQQ
Share

ETFs are becoming more and more popular options for investors recently to not only participate the markets but enjoy some level of diversification compared to owning an individual ticket (especially for passive ETFs and indexing funds).

Some large ETFs passively track stock market indices enable investors to invest a basket of equities. However, does it mean that we don’t need to evaluate an equity ETF is expensive?

PE ratio plays crucial role when we gauge if a stock symbol is at a proper price. This information is quite common for individual stocks across the platforms and brokers, but I only see few places report this number for ETFs.

In this series of articles, we are going to show you how to calculate PE ratio for ETFs so that you can evaluate the values by yourself and rebalance your portfolio independently and agilely.

Let’s first put everything together for Invesco QQQ.

Step 0

  • We first need to know the definition of PE ratio.

The price-to-earnings (P/E) ratio relates a company’s share price to its earnings per share. A high P/E ratio could mean that a company’s stock is overvalued, or that investors are expecting high growth rates in the future.

  • Install all required packages.

!pip install pandas
!pip install yfinance

Step 1

  • Get the previous close price for QQQ.

import yfinance as yf

tickers = yf.Tickers('QQQ')

previousClose_QQQ = tickers.tickers['QQQ'].info.get('previousClose')

previousClose_QQQ

Keep reading with a 7-day free trial

Subscribe to Informula to keep reading this post and get 7 days of free access to the full post archives.

Already a paid subscriber? Sign in
© 2025 Informula
Privacy ∙ Terms ∙ Collection notice
Start writingGet the app
Substack is the home for great culture

Share