Rajandran R Creator of OpenAlgo - OpenSource Algo Trading framework for Indian Traders. Telecom Engineer turned Full-time Derivative Trader. Mostly Trading Nifty, Banknifty, High Liquid Stock Derivatives. Trading the Markets Since 2006 onwards. Using Market Profile and Orderflow for more than a decade. Designed and published 100+ open source trading systems on various trading tools. Strongly believe that market understanding and robust trading frameworks are the key to the trading success. Building Algo Platforms, Writing about Markets, Trading System Design, Market Sentiment, Trading Softwares & Trading Nuances since 2007 onwards. Author of Marketcalls.in

Nifty Daily Returns – Distribution Statistics – Python Code

3 min read

The Nifty index is one of the most popular stock market indices in India among traders and investors, and it tracks the performance of the top 50 companies listed on the National Stock Exchange (NSE). As a trader or investor, it is important to understand the distribution statistics of the Nifty index in order to know the trading instrument behavior based on the past historical data

Nifty Daily Returns – Distribution

Distribution statistics are a set of measures that describe the distribution of data points in a sample or population. These measures include the mean, standard deviation, skewness, and kurtosis. Here, we will discuss each of these measures and how they can be used to analyze the distribution of daily returns for the Nifty index.

Python Code for Nifty Distribution Stats and to Plot the Distribution of Daily Returns

import yfinance as yf
import numpy as np
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt

# Download Nifty data
nifty = yf.download('^NSEI', start='2010-01-01', end='2023-03-16')

# Compute daily returns
nifty['daily_returns'] = nifty['Close'].pct_change()*100

# Remove first row with NaN
nifty = nifty.iloc[1:]

# Compute distribution statistics
mean = np.mean(nifty['daily_returns'])
std_dev = np.std(nifty['daily_returns'])
skewness = pd.Series(nifty['daily_returns']).skew()
kurtosis = pd.Series(nifty['daily_returns']).kurt()

# Print statistics
print('Mean: ', round(mean, 4))
print('Standard Deviation: ', round(std_dev, 4))
print('Skewness: ', round(skewness, 4))
print('Kurtosis: ', round(kurtosis, 4))

# Set plot size
plt.figure(figsize=(25, 12))

# Plot distribution of daily returns
sns.histplot(nifty['daily_returns'], kde=True, bins=100)

# Show plot
plt.xlabel('Returns %')
plt.ylabel('Density')
plt.show()
      

Output

Mean:  0.0004
Standard Deviation:  0.0109
Skewness:  -0.6827
Kurtosis:  11.2955

Interpretation of Distribution Statistics

1)Mean :

The value of “Mean: 0.0004” indicates that the average daily return for the Nifty index over the specified time period (from 2010-01-01 to 2023-03-16) is 0.0004, which can be interpreted as 0.04%. This means that, on average, the Nifty index has gained 0.04% per day over this time period.

It’s important to note that this value is an average and does not indicate that the return on any given day will be exactly 0.04%. There may be days where the return is higher or lower than the average, and the distribution of returns may not be symmetrical around the mean. As a trader, it’s important to consider the full distribution of returns, as well as other factors, when making investment decisions.

2)Standard Deviation

The value of “Standard Deviation: 0.0109” indicates the volatility of the Nifty index over the specified time period. Specifically, it represents the average amount of deviation or dispersion of daily returns from the mean daily return.

A smaller standard deviation indicates that the returns are less variable and more consistent, while a larger standard deviation indicates that the returns are more variable and less predictable. In this case, a value of 0.0109 indicates that the daily returns of the Nifty index have, on average, deviated from the mean daily return by approximately 1.09%.

As a trader, understanding the standard deviation of daily returns can help in evaluating risk and determining optimal portfolio allocation. Higher standard deviation implies greater risk, but also greater potential reward, while lower standard deviation implies lower risk but lower potential reward. However, it is important to keep in mind that standard deviation is just one measure of risk and other factors such as liquidity, diversification, and market trends should also be considered when making investment decisions.

3)Skewness

The value of “Skewness: -0.6827” indicates that the distribution of daily returns for the Nifty index is slightly skewed to the left, which means that there are slightly more negative returns than positive returns.

A negative skewness value means that the tail of the distribution is longer on the negative side, which can be seen in the histogram plot where the left side of the curve extends further than the right side. This indicates that there are more extreme negative returns compared to extreme positive returns, and the distribution is not symmetrical.

It’s important to note that skewness is just one measure of the shape of the distribution and should be considered in conjunction with other statistical measures, such as the mean and standard deviation. As a trader, it’s important to consider the full distribution of returns and other market factors when making investment decisions.

4)Kurtosis

The value of “Kurtosis: 11.2955” indicates that the distribution of daily returns for the Nifty index is leptokurtic, which means it has a higher peak and more values in the tails compared to a normal distribution.

A kurtosis value of 3 is considered to be normal or mesokurtic, and values above 3 are considered to be leptokurtic. The value of 11.2955 indicates that the distribution has a much higher peak and more values in the tails than a normal distribution.

This means that there is a higher likelihood of extreme returns, both positive and negative, compared to a normal distribution. As a trader, it’s important to consider the possibility of extreme events and factor that into risk management strategies. However, it’s also important to note that kurtosis is just one measure of the shape of the distribution and should be considered in conjunction with other statistical measures and market factors when making investment decisions.

Rajandran R Creator of OpenAlgo - OpenSource Algo Trading framework for Indian Traders. Telecom Engineer turned Full-time Derivative Trader. Mostly Trading Nifty, Banknifty, High Liquid Stock Derivatives. Trading the Markets Since 2006 onwards. Using Market Profile and Orderflow for more than a decade. Designed and published 100+ open source trading systems on various trading tools. Strongly believe that market understanding and robust trading frameworks are the key to the trading success. Building Algo Platforms, Writing about Markets, Trading System Design, Market Sentiment, Trading Softwares & Trading Nuances since 2007 onwards. Author of Marketcalls.in

[Live Coding Webinar] Build Your First Trading Bridge for…

In this course, you will be learning to build your own trading bridge using Python. This 60-minute session is perfect for traders, Python enthusiasts,...
Rajandran R
1 min read

How to Place Orders Concurrently using ThreadPoolExecutor – Python…

Creating concurrent orders is essential for active traders, especially those handling large funds, as it allows for executing multiple trade orders simultaneously, thereby maximizing...
Rajandran R
2 min read

Host your Python Flask Web Application using pyngrok and…

Ngrok offers several significant advantages for developers, especially when it comes to testing applications or hosting machine learning models. Ngrok allows you to expose...
Rajandran R
1 min read

Leave a Reply

Get Notifications, Alerts on Market Updates, Trading Tools, Automation & More