How the NSE India Stock Dataset Was Built

Behind the NSE India stock dataset: where the data comes from, the strange ways public sources fail, and the checks that run before anything is published.
Data Engineering
Finance
Author
Published

October 14, 2026

This is the behind-the-scenes companion to Ten Years of Indian Stock Market Data, and Why Raw Prices Lie. That post covers what the dataset is and why raw prices can’t be trusted. This one covers how it’s put together, from the first download to the file on Kaggle.

The big picture

Everything runs as a set of small Python scripts. Each one does one job, and they run in order:

flowchart LR
  A[Download<br/>raw files] --> B[Parse into<br/>tables]
  B --> C[Fix prices<br/>and dates]
  C --> D{Checks<br/>pass?}
  D -- yes --> E[Features<br/>and Kaggle]
  D -- no --> F[Stop]

Raw files are always kept. If a parsing rule turns out to be wrong, the tables can be rebuilt in minutes without downloading anything again.

Step 1: Collect

The data comes from four public sources:

Source What it gives
NSE Daily prices for every stock, corporate actions, quarterly results, insider trades, bulk deals, F&O positions
NSDL Daily foreign investor flows
BSE Bulk and block deals
Yahoo Finance Global indices, oil, gold, currency

Downloading ten years of this sounds simple. In practice the sources fail in odd ways, and most of the collection code exists to handle them.

“Not Found” doesn’t always mean not found. NSE sometimes says a file doesn’t exist when it does. In the first full run about 10% of trading days came back missing. Asked again, 5 out of 8 of them downloaded fine. So a missing file is retried on later runs, and only counts as truly missing after three tries.

Holidays get yesterday’s file. Ask NSE for a holiday and it can hand back the previous day’s file, renamed to the date you asked for. Every file’s date is now checked against what’s written inside it.

Files aren’t always what they claim. One day’s “CSV” was really an Excel workbook. Some zip files contain more zip files. Some put the CSV inside a folder named like a CSV.

Some APIs quietly cut results short. NSE’s bulk deals API returns at most 70 rows as JSON, but the full month as CSV. Another endpoint once reported 0 results on one page, and a month came back with 100 of its 3,075 filings. Counts are now checked, and a short month stops the run.

Formats change. NSE replaced its daily price file in July 2024, moved quarterly results to a new system in 2025, and changed insider disclosures in May 2026. Old and new formats are merged into one table. For prices, both versions were compared on days where both exist, and every column matched.

Some data only exists if you save it that day. BSE’s deals and NSE’s daily FII/DII figures only show the latest day, with no archive. A day that’s missed is gone for good.

The downloads are built to be restarted. Each finished file gets a small marker, so a rerun skips what’s done and fills any gaps. The biggest job, about 123,000 quarterly results documents, took around 60 hours.

Step 2: Turn files into tables

Raw files become one clean table per topic. Most of the work is small rules, each with a reason:

  • Quarterly results: read the quarter’s own numbers, not the year-to-date totals that sit next to them in the same filing.
  • Insider trades: the same trade is often filed more than once, so 14,680 duplicates were removed. When a reported trade value didn’t match quantity × price, it was corrected (1,802 rows).
  • Insider categories: 142 different spellings of “promoter”, “director” and so on were mapped to six groups.

One parsing bug is worth sharing. The 2017 results pages had table rows that were never closed in the HTML, so each row contained the rest of the table inside it. The parser read the next row’s label as this row’s value, and quietly lost EPS for most of 2017. It was only caught by looking at how many EPS values each year had.

Step 3: Fix prices and dates

The price fixes (splits, bonuses, demergers) are covered in the first post.

The date fix is simpler but just as important. Every filing gets an EVENT_DATE: the first trading session that could react to it. Most results come out after the market closes:

Hour of day when quarterly results are published (Indian time). Most arrive in the evening, after the 3:30 pm close.

The rule is: anything published after 3:15 pm, or on a holiday, counts for the next session. Using the quarter-end date or the trade date instead would let a backtest act on news before it was public.

Step 4: Check before publishing

Every build ends with a check script. If it fails, nothing downstream runs, and nothing gets published.

Check What it looks for Result
Look-ahead Rebuild everything as if it were 1 Jan 2024. Does any past row change? 0 of 3.37 million rows changed
Hidden splits Any large one-day fall on a liquid stock that isn’t a known event None beyond −29%
Market sanity Does an equal-weight basket of the liquid stocks behave like the real market? Tracks NIFTY with a correlation of 0.80

The last check is a good smell test. If splits weren’t fixed, the basket would be full of fake crashes. Instead it shows the market history you’d expect, including the 2018–19 small-cap slump and the March 2020 COVID crash:

An equal-weight basket of all liquid stocks, dividends included (top), and how far it was below its previous peak (bottom).

Step 5: Keep it fresh

One command runs the whole pipeline every evening after NSE publishes the day’s files. It takes about 15 to 20 minutes.

The rule for failures is simple:

  • A failed download is logged and the run carries on. One late source shouldn’t stop the day.
  • A failed build or check stops everything. Bad data is worse than no data.

For the Kaggle release, the tables are split into one file per year, so you can load just the years you need.

What made the biggest difference

  1. Keep the raw files. Most bugs were in parsing, not downloading. Re-parsing takes minutes, re-downloading takes days.
  2. Never trust a single “missing”. Public APIs fail randomly. Retry on another day before giving up.
  3. Check the date inside the file, not the date in its name.
  4. Count things. Rows per month, values per year. Most silent bugs show up as a dip in a simple count.
  5. Make the checks a gate, not a report. A check that only prints a warning gets ignored.

Dataset: NSE India Stocks 2016–2026: Adjusted Panel