Getting and cleaning market data
Bad data gives confident wrong answers. Where to get Indian market data, from exchange downloads to free libraries; why prices must be adjusted for splits, bonuses and dividends, worked step by step with a calculator and shown by Reliance's 1:1 bonus in October 2024; a cleaning checklist with pandas checks; and the survivorship and look-ahead biases, seen in Satyam's and Yes Bank's exits from the Nifty, that make backtests look better than reality.
Facts reviewed Oct 2026
Every analysis is only as good as its data. And market data has traps that aren’t obvious:
- a share split looks like a 50% crash;
- a missing week looks like a calm market;
- a list of today’s index members hides all the companies that failed.
This lesson covers where to get data, and how to clean it before trusting any result.
Where to get data
- Exchanges. NSE and BSE publish historical prices for shares and indices, daily bhavcopy files of all trades, and company announcements.
- Index providers. NSE Indices (Nifty) and Asia Index (Sensex) publish index levels and total-return indices.
- AMFI. Daily NAVs for every mutual fund scheme.
- The RBI’s Database on Indian Economy (DBIE). Interest rates, exchange rates, money supply and much more.
- Free libraries. The open-source yfinance package downloads Yahoo Finance data, including Indian shares (tickers ending
.NSfor NSE) and indices such as the Nifty 50 (^NSEI). It’s convenient but unofficial: check its numbers against exchange data before relying on them. - Broker APIs and paid vendors, for intraday and professional data. (Algorithmic & Systematic Trading describes them.)
A first download in Python:
import yfinance as yf
nifty = yf.download("^NSEI", start="2015-01-01", auto_adjust=True, multi_level_index=False)
nifty[["Close"]].tail()
Adjusting for corporate actions
When a company splits its shares 1:2, or issues a 1:1 bonus, the share price halves overnight. But shareholders lose nothing: they now own twice as many shares. Dividends also lower the price on the ex-dividend date. (Stock Market Basics explains why.)
So unadjusted prices show false crashes. Adjusted prices rescale history, so returns reflect what an investor actually earned. A total-return series also adds back dividends.
Worked example. A share closes at ₹1,000. Then it splits 1:2 (each share becomes two). Later it pays a ₹10 dividend on each new share, and ends at ₹520.
- Raw price change: ₹520 ÷ ₹1,000 − 1 = −48%. That’s what unadjusted data shows.
- Your holding after the split: 2 shares × ₹520 = ₹1,040. Split-adjusted return: +4%.
- Plus dividends: 2 shares × ₹10 = ₹20.
- Total return: (₹1,040 + ₹20) ÷ ₹1,000 − 1 = +6%.
A −48% “crash” was actually a 6% gain.
The defaults: the raw price falls 48%, but the split-adjusted return is +4% and the total return +6%. Analyses built on unadjusted prices would record a crash that never happened.
A real case: Reliance’s 1:1 bonus, October 2024
In October 2024, Reliance Industries issued a 1:1 bonus: one free share for every share held. On the day the shares began trading without the bonus, the price roughly halved.
Holders lost nothing. Someone with 100 shares now had 200, each worth about half as much. But an unadjusted price chart showed a near-50% fall in one day, in India’s largest company. Any backtest, volatility estimate or “biggest fallers” screen built on raw prices would have been badly wrong.
A backtest shows a share 'crashing' 80% in one day, with no news. What's the first thing to check?
A 1:5 split cuts the price by 80% with no loss to holders. Unadjusted data creates false crashes, the most common data error.
Cleaning checklist
- Gaps: missing dates beyond weekends and holidays. Check against the exchange’s trading calendar.
- Duplicates: the same date twice after merging files. Find them with
df[df.index.duplicated()]. - Outliers: daily moves beyond, say, ±20% for a large company deserve a look. Most are data errors or corporate actions; some are real.
- Stale prices: thinly traded shares may show the same price for days, which understates their volatility.
- Currency and units: rupees versus dollars, lakh versus crore, prices versus returns.
- Time zones and timestamps, for intraday or cross-market data.
Worked example: three checks in pandas. You’ve loaded daily closes into px, indexed by date.
- Duplicates:
px.index.duplicated().sum()should be 0. - Big moves:
r = px["Close"].pct_change(), thenr[r.abs() > 0.2]lists every day that moved more than 20%. Check each against corporate actions. - Stale prices:
(r == 0).sum()counts days with no change at all. Dozens in a row suggest the share barely traded.
Biases that flatter results
- Survivorship bias. Using today’s index members, or today’s surviving funds, ignores those that were removed, delisted, merged or closed. They tend to have done badly. Use point-in-time member lists: who was in the index on each date.
- Look-ahead bias. Using information that wasn’t available at the time. Examples: using annual results before their release date, or using a day’s closing price to trade at that same close.
- Restated data. Company accounts and economic statistics are often revised. The original “as reported” figures are what investors actually saw.
A real case: who’s missing from today’s Nifty
- Satyam Computer Services was a Nifty and Sensex company until January 2009, when its chairman confessed to a huge accounting fraud. Its shares collapsed, and it was removed from the indices.
- Yes Bank was removed from the Nifty 50 in March 2020. The RBI had taken control of the bank, and its shares had fallen more than 90% from their peak.
Test a strategy using today’s Nifty 50 members over the past 20 years, and neither company appears. The backtest quietly avoids two of the worst disasters in Indian markets. Results look better than any real investor could have achieved.
Look-ahead, the Indian way. Listed companies must publish quarterly results within 45 days of the quarter’s end, and annual results within 60 days (SEBI’s listing rules). So a backtest that trades on March-quarter profits on 1 April is using numbers nobody had yet. Use each result’s actual announcement date.
(Statistics & Probability for Finance shows how such biases and data mining combine to produce false discoveries.)
Going further: how adjustment factors work. Data providers don’t change the latest prices; they rescale history. For a 1:2 split, every price before the split date is multiplied by 0.5, so the series runs smoothly through the split. For a dividend of ₹10 on a ₹500 share, earlier prices are multiplied by (500 − 10) ÷ 500 = 0.98. Multiply all the factors together, and you get each day’s cumulative adjustment. Two consequences follow. First, adjusted prices from long ago can look oddly small, and they’re not prices anyone actually paid. Second, a download from last year and one from today can show different historical prices for the same day. New dividends have been added to the factors since. Store the raw data and the factors, not just one adjusted series.
Common mistakes
- Using unadjusted prices. Splits and bonuses create false crashes.
- Ignoring dividends. Use a total-return series to measure what investors earned.
- Testing on today’s index members. Use point-in-time lists.
- Using results before they were published. Use announcement dates.
- Trusting one free source. Cross-check against exchange data.
Practice 1: A ₹2,400 share has a 1:1 bonus, then trades at ₹1,150 and pays ₹15 per share. What's the true total return?
- Holding after the bonus: 2 shares × ₹1,150 = ₹2,300.
- Dividends: 2 × ₹15 = ₹30.
- Total return: (₹2,300 + ₹30) ÷ ₹2,400 − 1 = about −2.9%.
Not the −52% the raw price suggests. Enter 2400, 1150, 2 and 15 in the calculator to check.
Practice 2: A share trades at ₹800 before a 1:4 split (each share becomes four). What adjustment factor applies to earlier prices, and what does the ₹800 become in the adjusted series?
- Split factor: 1 ÷ 4 = 0.25.
- Adjusted earlier price: ₹800 × 0.25 = ₹200.
So the adjusted series shows ₹200 before the split, running smoothly into the new price of about ₹200. Nobody actually paid ₹200 before the split, but returns calculated from the series are correct.
Key takeaways
- Sources: NSE and BSE downloads, index providers, AMFI NAVs, RBI DBIE, the unofficial yfinance library, and broker APIs.
- Use adjusted or total-return prices. Splits and bonuses, like Reliance’s 1:1 bonus in October 2024, otherwise create false crashes.
- Clean for gaps, duplicates, outliers, stale prices, units and timestamps, with simple pandas checks.
- Avoid survivorship bias (Satyam and Yes Bank aren’t in today’s Nifty), look-ahead bias (results come out up to 45–60 days after the period) and restated data.
Go deeper
- RBI: Database on Indian Economy (DBIE).
- yfinance: documentation for the download function.