Analysis of TSLA and GME Stock Revenue¶

Description: This notebook is used to analyze the stock prices of Tesla and GameStop. The data is pulled from Yahoo Finance and then analyzed using the pandas library. The data is then visualized using the matplotlib library.

  • yfinance is used to pull the stock data from Yahoo Finance
  • pandas is used to analyze the data
  • plotly is used to visualize the data

Short Link: shorturl.at/nCP89


Importing the libraries

In [ ]:
import yfinance as yf
import pandas as pd
import plotly.graph_objects as go
from plotly.subplots import make_subplots

Get the stock data from Yahoo Finance API

In [ ]:
tsla=yf.Ticker("TSLA")
tsla_data=tsla.history(period="max")
tsla_data=tsla_data.reset_index()

Get quarterly data for TSLA

In [ ]:
tsla_data['Quarter']=tsla_data['Date'].dt.quarter
tsla_data['Year']=tsla_data['Date'].dt.year
tsla_data['Revenue']=tsla_data['Open']*tsla_data['Volume']
tsla_data=tsla_data.groupby(['Year','Quarter'])['Revenue'].sum().reset_index()

Get stock data for GME

In [ ]:
gme=yf.Ticker("GME")
gme_data=gme.history(period="max")
gme_data=gme_data.reset_index()

Get quarterly data for GME

In [ ]:
gme_data['Quarter']=gme_data['Date'].dt.quarter
gme_data['Year']=gme_data['Date'].dt.year
gme_data['Revenue']=gme_data['Open']*gme_data['Volume']
gme_data=gme_data.groupby(['Year','Quarter'])['Revenue'].sum().reset_index()

Plot the stock data for TSLA and GME since listing

In [ ]:
fig = make_subplots(rows=1, cols=2, shared_yaxes=True, subplot_titles=("GME", "TSLA"))
fig.add_trace(go.Bar(x=gme_data['Year'].astype(str) + ' Q' + gme_data['Quarter'].astype(str), y=gme_data['Revenue'], name='GME'), row=1, col=1)
fig.add_trace(go.Bar(x=tsla_data['Year'].astype(str) + ' Q' + tsla_data['Quarter'].astype(str), y=tsla_data['Revenue'], name='TSLA'), row=1, col=2)
fig.update_layout(title_text="GME and TSLA Quarterly Revenue").show()

Result: The stock data for TSLA and GME is plotted since listing. The stock data for TSLA is plotted in blue and the stock data for GME is plotted in orange.

Conclusion: TSLA stock has been on a steady rise since listing. GME stock has been on a steady decline since listing.