Analyzing Indian Healthcare Stocks Amid COVID-19 with Python
The COVID-19 pandemic, caused by the novel coronavirus, has reshaped the global landscape in ways previously unimaginable. As the virus rapidly spread across borders, nations grappled with unprecedented challenges in healthcare, economies, and daily life. Within the epicenter of this global health crisis, Indian healthcare stocks have been subject to unique scrutiny, reflecting the multifaceted impact of the pandemic on the healthcare sector.
This analysis will explore the behavior of Indian healthcare stocks during the pandemic, considering key metrics such as stock price performance, volatility, and risk factors. The findings of this analysis aim to shed light on the relationship between the COVID-19 pandemic and the Indian healthcare stocks.
For our analysis, stocks of four private hospital network companies have been taken into consideration. These are Apollo, Fortis, AsterDM and Narayan Hrudayalaya. Stock price performance will be analyzed from March 2018 to December 2022. The analysis will be done using python and its various important functionalities along with Jupyter notebook.
Before performing the analysis following steps were taken to prepare the data for analysis:
- The required python libraries like pandas, matplotlib and seaborn were imported.
- The data was read into the dataframe with company name using read_csv method.
- The date column in the data obtained from Yahoo finance was changed to datetime for pandas library to recognize it as date and set as the index column. This was done by creating a function for doing the said operation.
- Names of the stock were stored in a list to be used further in the code
- The four separate dataframes containing the stock data for the four healthcare stocks were concatenated to form one dataframe containing all the data.
The code for the above 5 operations is shown below
The concatenated data has open, high, low, close, adj close, and volume for the four healthcare stocks as shown below, all of which can be viewed by scrolling to the right.
Let us look at the movement of the adjusted closing price over the entire time period for the four healthcare stocks which is shown below. The x -axis shows the time period in years and y-axis shows the adjusted closing price.
Looking at the image above it can be seen that Apollo clearly had the highest increase over the time period followed by Narayana. Later on, we will see the normalized returns to understand relative movement.
Since, the closing price is different for different stocks, the relative movement in price is difficult to visualize. For this, we will look into the normalized returns later to understand relative movement in prices. For now, let us look at the moving average of 30 days over the entire time period for the four healthcare stocks individually as shown below
The moving averages for the four stocks shows that there is an downward trend in the movement of prices in the start of 2020 due to Covid. For, Fortis and AsterDM there was a downward trend before Covid. However, there is a general upward trend after the dip in 2020 till the end of 2022 with AsterDM showing more volatility during the upward trend.
After looking at the movement of prices for individual stocks, let us look at the correlation between the four stocks in terms of closing price. Correlation is a statistical measure that quantifies the degree to which two variables, in this case, the daily price of financial assets, are related. It can take on values between -1 and 1. First, we will create a correlation matrix using the code shown below by making use of cross-section and correlation method in python.
The matrix gives useful information regarding the correlation. Correlation of prices provides information about the directional movement of stock prices. In the matrix above, the stocks have a 1 correlation with itself which is logical since their price movements will be fully correlated with itself. Positive correlation means the prices tend to move in the same direction, while negative correlation means they tend to move in opposite direction.
Let us visualize this matrix using a heatmap as shown below
The highest correlation are in red whereas the lowest are in blue shown on the color scale on the right. Looking at the correlation, it can be said that Fortis & Apollo have the highest correlation with each other (0.96 in value) and AsterDm & Apollo have the lowest correlation with each other (0.67 in value) in terms of closing prices. A high positive correlation (0.7 to 0.99) suggests that two assets tend to move in the same direction most of the time. For some investors, this may indicate that the assets are closely related and move together, which could be good or bad depending on the investment strategy.
Let us look at the highest correlation stocks more closely with the help of a scatter plot.
The scatter plot above shows the relation between closing prices of Apollo and Fortis. Looking at the plot, it can be seen that both have some linear relationship in terms of prices.
To understand the relative movement of prices for the four stocks, we will look at the normalized return which is obtained by dividing the adjusted closing price for each day for a stock by the adjusted price on the first day of the time period. The calculation in python is shown below.
In the output cell, we have the normalized returns. The returns for the first day is 1 because if we would bought a stock and sold it the same day, we would have received the same amount back. Mathematically, it can be understood as the division of number by itself is 1.
Another way of understanding it is that if we would have invested 1 rupee in Apollo at the start of the time period, we would have 3.84 rupees at the end of time period. It is a useful tool for comparing assets with different price levels. This concept is also useful in understanding portfolio allocation.
The above figure shows the visualization of the normalized returns. It shows the movement of returns relative to each other by normalizing the returns so that each investment starts at 1 for all the four stocks, thus, giving us a good idea of the movement of prices and returns.
It can be seen clearly that all the stocks had a dip around 2020 at the start of Covid lockdowns. But then, Apollo had the fastest recovery and the highest returns till the end of period followed by Narayana, Fortis and AsterDM
Till now we have looked at prices and their movements. Let us look at the daily returns of the four stocks. Daily returns informs us of the percent gain (or loss) if we bought the stock on one day and then sold it the next day. The calculation in python is shown below.
For calculating the daily returns, we used the .pct_change() method to calculate the percent change for each day of the whole period. Data for the first date is NaN (Not a Number) because it was the first day and there was no data before it.
Let us look at the correlation of the returns of the stocks with each other using python. Correlation of daily returns is a fundamental concept in finance used for measuring the relationship between the returns of two or more financial assets over a series of daily observations. Correlation helps in understanding how closely the returns of these assets move in relation to each other. We will make use of the correlation matrix in the same way we did for understanding correlation of prices.
In the figure above, correlation matrix can be seen for the daily returns. This can be visualized using a heatmap and a color scale as shown below.
The heatmap above shows the correlation of returns. It can be seen that the highest correlation of 0.25 is between Fortis and Apollo. Moderate positive correlation (0.3 to 0.69) means that two assets have some tendency to move in the same direction, but not consistently. It can provide some diversification benefits while still maintaining some commonality. Low or No Correlation (0 to 0.29) indicates that two assets’ daily returns move independently of each other. This can be desirable in a diversified portfolio because it helps reduce overall portfolio risk.
Using the daily returns we can perform important calculations like calculating daily volatility, average annual returns, average volatility, and annual returns. Let us perform these calculation using python
The above code gives the average annual rate of return for the four stocks over the entire time period. It is done by taking the mean of the daily returns over the entire time period, then multiplying it by 250 because there are around 250 trading days in a year. For getting the percentage value, we multiply it by 100. It can be seen that Apollo has the highest average annual return of 35.25 % followed by Narayan, Fortis and AsterDM over the entire time period.
Let us look at the annual volatility over the entire time period.
The above code shows the annual volatility over time period. It is obtained by multiplying daily standard deviation of returns by square root of 250 (assuming 250 trading days in a year). It can be seen that AsterDm has the highest annual volatility returns of 41 % followed by Apollo, Narayana and Fortis.
Let us look at the returns and the volatility of the stocks during different periods. Dividing the entire time period in three parts: first part is the pre-Covid period from 2018 to 2020, second part is the Covid period in the year 2020, third part is the post Covid period from 2021 to 2022. We will calculate and analyze the annual returns and volatility separately for these three periods.
The average annual returns and volatility are shown in the image above for the pre-Covid period from March 2018 to March 2020. Apollo has the highest annual return and second highest annual volatility for the period. Narayana has the second highest return and the lowest volatility. AsterDm has the highest volatility.
The average annual returns and volatility are shown in the image above for the Covid period from March 2020 to March 2021. Apollo has the highest annual return and second highest annual volatility for the period. Narayana has the second highest return and the second lowest volatility. AsterDm has the highest volatility and the lowest return.
It can also be noticed that the returns and volatility are higher than the pre-Covid period for all the stocks except AsterDM.
The average annual returns and volatility are shown in the image above for the post-Covid period from March 2021 to December 2022. Fortis has the highest annual return and second highest annual volatility for the period. Narayana has the second highest return and the lowest volatility. AsterDm has the highest volatility and the second lowest return but showed improvement in the returns when compared with the other two periods under consideration. Apollo has the lowest return in this period but second lowest volatility.