4. We had created a Trend column in module 1. We want to see how often each Trend type occurs. This can be seen as a pie chart, with each sector representing the percentage of days each trend occurs. Plot a pie chart for all the ‘Trend’ to know about the relative frequency of each trend. You can use the groupby function with the trend column to group all days with the same trend into a single group before plotting the pie chart. From the grouped data, create a BAR plot of average & median values of the ‘Total Traded Quantity’ by Trend type.
Output Plots :
5. Plot the daily return (percentage) distribution as a histogram. Histogram analysis is one of the most fundamental methods of exploratory data analysis. In this case, it’d return a frequency plot of various values of percentage changes.
Output Plot :
6. We next want to analyse how the behaviour of different stocks are correlated. The correlation is performed on the percentage change of the stock price instead of the stock price.
Load any 5 stocks of your choice into 5 dataframes. Retain only rows for which the ‘Series’ column has the value ‘EQ’. Create a single dataframe that contains the ‘Closing Price’ of each stock. This dataframe should hence have five columns. Rename each column to the name of the stock that is contained in the column. Create a new dataframe which is a percentage change of the values in the previous dataframe. Drop Nan’s from this dataframe. Using seaborn, analyse the correlation between the percentage changes in the five stocks. This is extremely useful for a fund manager to design a diversified portfolio. To know more, check out these resources on correlation and diversification.
Output Plot :
7. Volatility is the change in variance in the returns of a stock over a specific period of time. Do give the following documentation on volatility a read. You have already calculated the percentage changes in several stock prices. Calculate the 7 day rolling average of the percentage change of any of the stock prices, then compute the standard deviation (which is the square root of the variance) and plot the values. Note: pandas provides a rolling() function for dataframes and a std() function also which you can use.
Output Plot :
8. Calculate the volatility for the Nifty index and compare the 2. This leads us to a useful indicator known as ‘Beta’ ( We’ll be covering this in length in Module 3)
Output Plot :
9. Plot the 21 day and 34 day Moving average with the average price and decide a Call ! Call should be buy whenever the smaller moving average (21) crosses over longer moving average (34) AND the call should be sell whenever smaller moving average crosses under longer moving average. One of the most widely used technical indicators.
Output Plot :
10. Plot the bollinger bands for this stock — the duration of 14 days and 2 standard deviations away from the average The bollinger bands comprise the following data points- The 14 day rolling mean of the closing price (we call it the average) Upper band which is the rolling mean + 2 standard deviations away from the average. Lower band which is the rolling mean — 2 standard deviations away from the average. Average Daily stock price. Bollinger bands are extremely reliable, with a 95% accuracy at 2 standard deviations, and especially useful in the sideways moving market. Observe the bands yourself, and analyse the accuracy of all the trade signals provided by the bollinger bands. Save to a new CSV file.
Output Plot :
Link to the Datasets :
Link to my previous article :