Stock Market Analysis project using Python on Bajaj-Auto, Maruti Suzuki and Tata Motors.

Mahika Matta
5 min readJun 14, 2021

This is a basic stock market analysis project based on Python programming in financial markets.

I have used the Jupyter notebook from Anaconda Navigator for this project.

Importing the necessary module

Getting stock data from the Yahoo finance API for the three stocks.

I have adjusted the starting reference time to the start of 2011, the 1st of January 2011.

Maruti Suzuki stock (Ticker: MARUTI.NS on the NSE)
Tata Motors stock (Ticker: TATAMOTORS.NS on the NSE)
Bajaj Auto stock (Ticker: BAJAJ-AUTO.NS on the NSE)

Visualisation of the data

Let’s get the open price data of all three stocks in a single table and plot them for comparison.

To plot them on a common scale, we can normalise the data to 100 and plot the results on a graph.

Same for the closed price data, but we take Adjusted closed price for this purpose as it takes into consideration the dividends declared, and the stock splits.

Also, plotting the volume of stocks traded each day gives an overview of the total activity.

Dates of maximum trading volume for each

The Open and Adjusted close price time-series visualisations show Maruti Suzuki as much more valuable than Tata Motors and Bajaj Auto in the second half of the decade. But to confirm this, we will have to look at the total market cap of the company rather than just the opening and closing prices.

Unfortunately, our current data doesn’t have that information about the total units of the stock present. But what we can do as a simple calculation to try to represent total money traded would be to multiply the Volume column by the Open price. This is actually not the exact Market cap, but it’s a visual representation of the total amount of money being traded in the period.

Let’s add another column as “Total Trade”, which will be the product of Open price and Volume and plot it.

Visualisation of total money traded in the period

The total money trade visualisation shows similar results to that of Open price and Volume visualisations, but there's one thing it didn't indicate. Tata Motors was less valued than Maruti Suzuki for most of the time series. Still, there was a huge amount of money traded in Tata Motors at some places, tremendously huge compared to the other two, mainly in early 2021. Why did this happen? What could be the reasons?

Highest money traded day for Tata Motors

Following are the reasons:

  1. Increasing revenues from electric vehicles: Around 53% of JLR (Jaguar Land Rover) sales in the December quarter were from EVs (electric vehicles). The total share of electric vehicles in Tata Motors’ 2020 sales is now 43.3%, and the company says EVs’ contribution is ‘poised for further growth in 2021 and beyond.’ JLR also recorded its second successive quarter-in-quarter recovery, with sales growing 13% to 128,469 vehicles thanks to strong demand from China.
  2. Rising domestic sales: Domestic sales for January 2021 went up 28% to 57,742 units against 45,242 units in January 2020. Total sales for the company have gone up 25.27% in January 2021 compared to January 2020. A total of 59,959 units were sold this January compared to 47,862 units in 2020.
  3. Budget announcement: Finance Minister Nirmala Sitharaman announcement of a voluntary vehicle scrappage policy to get rid of older vehicles (over 20 years old) will mean more sales for the auto industry, and Tata Motors should be a direct beneficiary of this, especially in its growing EV segment.

Plots of Moving Averages. MA50 and MA200 for Bajaj-Auto

Basic Financial Analysis- Comparing Daily returns and plotting for relationships.

Simple rate of Return =

Calculating the simple returns from the Adjusted closing price.

Histogram for returns on Maruti Suzuki
Histogram for returns on Tata Motors
Histogram for returns on Bajaj-Auto

KDE instead of the histogram for another viewpoint. (Probability Density)

Cumulative Daily Returns

Daily Return: Daily return is the profit/loss made by the stock compared to the previous day.

Cumulative Return: Cumulative return is computed relative to the day investment is made. You are in profits only if the cumulative return is greater than 1.

The simple cumulative daily return is calculated by taking the cumulative product of the daily percentage change. The following equation represents this calculation:

This is calculated in python using the .cumprod() method.

Comparing the cumulative returns of the three stocks.

--

--