Skip to content

Algo Trading

Fetching PE, PB Ratios, and Dividend Yields from NSE Using Python

18 March 20253 min readAlgo Trading
FabTrader author portrait

FabTrader

Article overview

For algo traders and investors, keeping track of fundamental index metrics like Price-to-Earnings (PE) Ratio, Price-to-Book (PB) Ratio, and Dividend Yield is crucial for making informed decisions. If you're looking for a way to automate the retrieval of these metrics for all indices listed on the National Stock...

For algo traders and investors, keeping track of fundamental index metrics like Price-to-Earnings (PE) Ratio, Price-to-Book (PB) Ratio, and Dividend Yield is crucial for making informed decisions. If you're looking for a way to automate the retrieval of these metrics for all indices listed on the National Stock Exchange (NSE) of India, this Python utility will come in handy.

Why Track PE, PB, and Dividend Yield?

  • PE Ratio: Indicates how expensive or cheap an index is compared to its earnings.
  • PB Ratio: Helps assess whether an index is overvalued or undervalued based on book value.
  • Dividend Yield: A key metric for income-seeking investors to evaluate returns from dividends.

Automating Data Retrieval

Rather than manually checking the NSE website for these values, I have developed a Python utility that fetches and structures the data into a pandas DataFrame. This makes it easier to integrate into trading algorithms, financial dashboards, and custom analysis tools.

How It Works

The utility uses NseUtility, a Python module that I have built earlier, to pull the latest data for all indices. With just a few lines of code, you can fetch and display the PE, PB, and Dividend Yield for all indices on the NSE.

Here's how you can use it:

Copy the main NseUtility Python Class from my main blog article >> HERE and include / import it into your code as explained the video.

import NseUtility

# Create an instance of NseUtility
nse = NseUtility.NseUtils()

# Fetch PE, PB, and Dividend Yield data
print(nse.get_index_pe_ratio().head())
print(nse.get_index_pb_ratio().head())
print(nse.get_index_div_yield().head())


Applications for Algo Traders
  1. Market Valuation Checks: Use PE and PB ratios to determine market conditions before executing trades.
  2. Index Comparison: Compare fundamental metrics of different indices to spot investment opportunities.
  3. Portfolio Rebalancing: Incorporate dividend yield data to optimize a dividend-focused strategy.
Where to Get the Utility?

This utility is part of a broader Python package that I created to fetch live data from NSE India. You can read more about it and how to set it up in my previous article: A Python Utility to Fetch Live Data from NSE India.

Final Thoughts

If you're an algo trader, financial analyst, or investor, automating the retrieval of fundamental index data can significantly enhance your decision-making process. Feel free to integrate this utility into your workflows and let me know how it helps!

For more trading tools, insights, and Python-based finance utilities, stay tuned to FabTrader!


Support this community : FabTrader.in is a one-person initiative dedicated to helping individuals on their F.I.R.E. journey. Running and maintaining this community takes time, effort, and resources. If you’ve found value in the content, consider making a donation to support this mission.

More from Algo Trading