Scrutinizing Stock Prices in Eye of Benford's Law Using Python: Dinesh Thakali, MD, Prabhu Capital

Mon, Apr 18, 2022 12:12 PM on Stock Market, Recommended, Exclusive,

The Law

One and half decades back while I was pursuing my Chartered Accountancy, I had come across an interesting topic on fraud detection in accounting and taxation, using Benford’s Law. Benford’s Law is nothing complex, it just states that unless any data is manipulated, the occurrence of the first digit of naturally-occurring numbers follows a pattern and shows a consistent probability of occurrence. This is because of simple logic that the first digit if it is 1 must increase by 100 percent to change to 2 while for 2 to change to 3, it only needs to increase by 50 percent. Newcomb first noticed and Frank Benford rediscovered this occurrence of logarithmically decaying distribution of the first digit from 1 to 9 represented by the formula.

P(D1=d) = log10(1 + 1/d) (Where d is the number from 1 to 9)

Being in the role of Investment Banker at present, I wondered whether the often controversy of anomalies in the trading of stock in the market could be scrutinized using the same law. While there seemed difficult for Benford’s Law to hold true, there needs to be a large sample size, but manipulations or malpractices in any trading stock happen for a short period. However, few have tried to scrutinize the rampant trading manipulations of cryptos like Bitcoin. This law however has been effectively used in fraud detection in accountancy, taxation, elections, etc.


For veracity of whether Benford’s Law applies truly, I took the NEPSE Closing prices from the inception. Further data of closing prices of two highly volatile scrips from the Finance Companies Sector was taken for testing purposes.

Python Codes

Step 1-Import necessary Python Libraries and Defining Benford’s Percentages

Step 2-Import NEPSE Closing Indexes and Sample Finance Company Prices

Step 3-Creating Function for the purpose of calculating the percentage

Outcomes (Visualization)

Step-4 Plotting and Visualizing the Graphs


While as initially disclaimed, Benford’s law can not be a litmus test for finding manipulations. Given that there is adequately large data, the prescribed probability distribution of Benford’s Law should certainly hold true if it is naturally occurring data.

In Figure No. 1 when NEPSE Closing Indexes are plotted over Benford’s distribution, the plots seem to be nearly overlapping each other except for digits 6 and 7. Indexes which are a mix of a large number of various scrips can hardly be manipulated in huge amount and hence seems to follow the Law. In the case of sample Finance Companies that had largely volatile price movements in recent periods, the plot seemed hugely deviating from the Law, especially where the first digit is 1 (so possibly somebody wanted to keep prices above 1000 ?)

Dinesh Thakali is an employee of Prabhu Bank Ltd and currently, Managing Director at Prabhu Capital Ltd. Views expressed are personal and Author intends only to illustrate the results of Law but doesn’t prescribe or authenticate usage of the methods for any purpose.