Calculating The NIFTY Index
In this discussion, We will attempt to calculate the NIFTY Index in program directly from the stock prices. Till date, there has been many attempt to calculate the NIFTY index by various programmers but it all ended in non conclusive discussions because of lack of clarity.
As We are aiming the impossible, Keep an open mind and think this as a constructive discussion rather than some validated assertion.
Here is a snapshot of NIFTY as we are discussing. This image will act as a good reference point.
Lets refer to this document – NIFTY 50 Methodology
In this document shared, in the page 11, You can see this formula –
- Free Float Market Capitalization = Shares outstanding * Price * IWF
- Index Value = Current Market Value / Base Market Capital * Base Index Value (1000)
Also, in the Page 6, it is written that the Base capital was 2.06 trillion.
df["free_float_market_cap"] = df['sharesOutstanding']*df['ltP']*df['investableWeightFactor'] net_free_float_market_cap =df["free_float_market_cap"].sum() net_free_float_market_cap/2060000000000 * 1000
Well, the value of NIFTY is not nowhere near 39177! What went wrong?
Net_Indexmcap_todaybecause the marketcap was directly given in the API itself. Why calculate it again? Anyways, Lets compare
net_free_float_market_capout of curiocity.
net_free_float_market_capis constructed out of LTP directly. It entails the immediate and realtime value.
Net_Indexmcap_todayis made out of
Indexmcap_todaywhich is updated at the beginning of the day only.
Now, the only thing that can be changed here is the assumption i.e. value of base market capital using back calculation.
Net_Indexmcap_today/18244.2 * 1000
"Indexmcap_yst"and if it comes all correct then it is more than enough for moment being!
today_nifty = Net_Indexmcap_today/4422466759975.828 * 1000 yst_nifty = df["Indexmcap_yst"].sum()/4422466759975.828 * 1000 print(today_nifty) print(round(yst_nifty,2))
Our hypothesized value of base capital gives the proper output of NIFTY50’s yesterday’s price!
This is a part of the live discussion that happened on Unofficed Discussion Forum. Feel free to participate and engage in future discussions. Here are some agenda to be discussed later –
- Will there be an arbitrage opportunity if there is a difference in the value?
Let’s discuss this further in the next part of this discussion. Don’t shy away to share your code snippets or variations in the forum if You trying something