A Quantile based historical Stock Analysis

Please note that the below article should not be used solely for making investment decisions as the real purpose of this artefact is only to demonstrate how data analytics can prove to be extremely powerful in making historical stock price analysis. Readers are advised to exercise caution by doing the required fundamental and technical analysis in conjunction with this analytical analysis and make judicious investment decisions.  

What is quantile?

In simple terms, “Quantile” refers to points in a distribution that relates to the rank order of values in that distribution. The median is a quantile such that exactly half of the data is lower than the median and the other half is exactly above the median. Figure 1 demonstrates a sample distribution of stock prices of a company X over 11 days and explains the quantiles of various data points.

Figure 1: Quantile

With this brief introduction to quantile, let us see how quantiles are helpful in historical stock analysis to check if the current stock price is cheap or expensive in comparison with the past prices.

Quantile analysis to determine if current stock prices are cheaper or expensive than the past:

I have a dataset that gives the past 10-year stock data for 5 stocks that are trading in NSE. We would be using the quantile-based analysis to assess the price distribution of these stocks. By calculating various quantile values such as 10th, 20th, 50th quantiles, and so on, we’ll be able to see in which quantile the current stock price fits.

For example, if the current stock price fits in the 30th quantile, it means that the stock is currently available at a cheaper valuation in comparison to the last 10 years because 70% of the times during this period, the stock price has remained higher. On the other hand, if the current price fits at the 80th quantile, the stock is probably trading at a higher price in comparison to the last 10 years, and hence, it may be a good idea for the prices to see some correction.

A piece of simple Python code to calculate percentile values and plot a box plot for historical values can be found here.

Example 1 – ITC

Output – Quantile values and Box Plot for ITC’s stock

Figure 2: 10-year stock price – Quantiles & Box Plot for ITC

Analysis of ITC’s Stock Price Quantiles & Box Plot

From Figure 2, it is evident that the 5th & 100th quartile of ITC’s stock is Rs 172.87 and Rs 399.55 respectively. This means that if someone has purchased the stock for any value less than Rs 172.87, they are more likely to see an upward movement in their prices as the stock has traded at higher prices for 95% of the time in the past 10 years. Similarly, if the current trading price of ITC is higher than or equal to Rs 313, investors can potentially wait as only on 30% of times during the last 10-year horizon has the stock traded at a price higher than Rs 313 and also, they are purchasing the stock higher than the 10-year median price.

The box plot gives a quick view of the last 10 year prices of ITC and a few seconds’ glance at it would help the investor to make a decision based on the historical prices.  

Example 2 – Gujarat Alkali

Output – Quantile values and Box Plot for Gujarat Alkali’s stock

Figure 3: 10 year stock price – Quantiles & Box Plot for Gujarat Alkali

Analysis of Gujarat Alkali’s Stock Price Quantiles & Box Plot

From Figure 3, we note that there are outliers in the stock prices at the upper end above Rs 800 approximately. Hence, the dataset is checked to see the percentage of outliers.

Figure 4: Outliers in Gujarat Alkali’s Stock Price

Of the 2400+ rows, the outliers are noted only in 14 entries, which is less than 0.5%. Hence, the outliers can be deleted, and the python code be run for the revised dataset so that outliers are eliminated from the analysis.

Figure 5: 10 year stock price – Quantiles & Box Plot for Gujarat Alkali – Outliers Removed


Quantile based historical stock analysis can be very helpful in understanding the past price movements and make judicious calls. Depending on the quantile under which the current stock price fits, an investor can take a BUY or SELL decision.

More Great AIM Stories

Arunagiri Babu
I’m S. Arunagiri Babu Sailesh, a professional with close to 14 years of work experience. I have spent more than 75% of my time with IT organizations and found a renewed interest in data analytics, thanks to the proliferation of data in recent years. I’d like to call myself a technology enthusiast, with a specific focus on Hyperautomation & Analytics. Currently, a student of IIM Lucknow, pursuing an Executive Education in Business & Data Analytics.

3 Ways to Join our Community

Discord Server

Stay Connected with a larger ecosystem of data science and ML Professionals

Telegram Channel

Discover special offers, top stories, upcoming events, and more.

Subscribe to our newsletter

Get the latest updates from AIM