What it does

Screener websites show the fundamentals of one company at a time. This script builds a spreadsheet of them for every stock in a list: valuation ratios, margins, returns, debt, dividends and recent price movement, one row per company. You give it an Excel file of NSE symbols, and it writes stock_data_fundamentals.xlsx with three sheets: Technical Data (prices and recent changes), Financial Metrics (the key ratios at a glance) and All Data (every column), ready to sort and filter.

Where the data comes from

The input is NSE's own list of listed equities (EQUITY_L, downloadable from the NSE website), whose first column is the trading symbol. The data comes from Yahoo Finance through the yfinance library. Yahoo identifies NSE stocks with a .NS suffix (BSE stocks use .BO), so each symbol is cleaned up first:

def clean_symbol(symbol):
    symbol = symbol.strip().replace(' ', '')
    return f"{symbol}.NS"

For each symbol the script makes two requests: Ticker.info for the company profile and financial ratios, and Ticker.history() for the last 30 days of daily prices. A symbol that fails, because it was delisted or Yahoo has no data, is logged and skipped, so one bad row doesn't stop a run over hundreds of companies.

What ends up in the spreadsheet

GroupColumns
CompanyName, sector, industry, market cap
ValuationP/E, forward P/E, PEG, price to book, EV/EBITDA
ProfitabilityProfit and operating margin, ROE, ROA, revenue, EBITDA, net income, EPS, quarterly revenue and earnings growth
Balance sheetTotal cash, total debt, debt to equity, current ratio, book value, free cash flow
DividendsDividend rate, yield, payout ratio
PriceLatest OHLC and volume, beta, 52-week high/low, 50- and 200-day averages, daily/weekly/monthly change

Any field Yahoo doesn't have for a company comes out as N/A. That's common for smaller companies, where forward P/E, PEG and growth figures are often missing, so check how many rows actually have a value before screening on a column.

Things I learned building it

Formatting for people breaks the data for machines

To make the sheet easier to read, every number goes through format_value, which turns 11,545,743,360 into "11.55B" and 0.07219 into "0.07". That has two costs. First, the values become text, so Excel sorts them alphabetically: "1.36B", "11.55B", "950.00M", which puts a ₹950 million company after an ₹11.5 billion one. Second, two decimal places is far too coarse for ratios. A 7.2% profit margin becomes "0.07", and 7.2% and 6.5% both round to the same value. The better design is to keep raw numbers in the data and apply number formats in Excel, or in a separate presentation copy.

Indian investors think in crores, not billions

B and M suffixes are a Western convention. Market caps in Indian filings and news are quoted in crores (1 crore = 10 million), so ₹11.55B reads more naturally as ₹1,154.6 crore. If the sheet is for an Indian audience, converting to crore makes it much easier to read alongside annual reports.

The "VWAP" column isn't VWAP

The column labelled VWAP is calculated as (High + Low + Close) / 3. That's the typical price, a useful number but a different one. Real VWAP (volume-weighted average price) weights every trade's price by its volume across the day, which needs intraday data, not one daily bar. With only daily data, "Typical Price" is the honest label.

Counting trading days, not calendar days

Price changes are computed from positions in the 30-day history. The weekly change compares the latest close with Close[-5], which is four trading sessions earlier, not five (Close[-1] is today, so five sessions back is Close[-6]). The monthly change uses the first close in the 30-calendar-day window, which is usually around 20 to 22 sessions, depending on weekends and market holidays. These are small differences, but they're the kind that make your numbers disagree with a screener's and leave you wondering which one is wrong.

Be gentle with the data source

yfinance is an unofficial wrapper around Yahoo's public endpoints, not a paid API with guarantees. Running it over the whole NSE list in a tight loop means thousands of requests, and Yahoo may start rate-limiting or returning errors. A short pause between symbols, saving progress as you go so a failed run can resume, and running it once a day after market close keep it reliable. Field names in .info also change from time to time, which is why every field is read with info.get(..., 'N/A') rather than info[...].

Running it

pip install yfinance pandas openpyxl numpy

Download EQUITY_L from NSE (or make an Excel file with your own watchlist symbols in the first column), set file_path in main() to point to it, and run the notebook. For a first try, use a watchlist of 20 to 30 stocks: the full NSE list takes a long time and is where rate limits start to show.

The figures come from a free third-party source and may be delayed or incomplete. Use the sheet to shortlist companies, then confirm the numbers in their annual reports and exchange filings before making any investment decision.