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

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
- Market Valuation Checks: Use PE and PB ratios to determine market conditions before executing trades.
- Index Comparison: Compare fundamental metrics of different indices to spot investment opportunities.
- 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
Algo Trading Cost in India: How I Built a Reliable Setup for ₹150/Month
Wondering how much algo trading costs in India? In this article, I break down the real expenses involved in running an algorithmic...
When Your Job Feels Shaky: Can Trading Become an Alternate Income Stream?
Can trading become a stable source of income in India? While many consider it during times of job uncertainty, the reality is...
How Much Capital Do You Really Need for Sustainable Trading Income in India?
How much capital is needed for sustainable trading income in India? This in-depth guide explores the realistic returns traders can expect, the...
