import yfinance as yf
import matplotlib.pyplot as plt
Lecture 02
Jupyter Notebook - Empty
Market Capitalization of NVIDIA and Intel (2012 - 2024)
The Python library yfinance
is often used to download stock market data.
Let’s define the stocks that are of interest for this analysis.
# Define the tickers for NVIDIA and Intel
= ['NVDA', 'INTC'] tickers
Now, downloading the data to our Colab instance or local computer.
# Download the historical market data since 2012
= yf.download(tickers, start='2012-01-01', end='2024-01-01', group_by='ticker') data
Focusing on the closing prices.
# Extract the adjusted closing prices
= data['NVDA']['Adj Close']
nvda_data = data['INTC']['Adj Close'] intc_data
Drawing.
# Plot the stock price data
=(12, 6))
plt.figure(figsize='NVIDIA')
plt.plot(nvda_data.index, nvda_data, label='Intel')
plt.plot(intc_data.index, intc_data, label'Stock Prices of NVIDIA and Intel (2012 - 2024)')
plt.title('Date')
plt.xlabel('Stock Price (USD)')
plt.ylabel(
plt.legend()True)
plt.grid( plt.show()
Now calculating the market capitalisation.
# Fetch the number of shares outstanding (this gives the most recent value)
= yf.Ticker('NVDA').info['sharesOutstanding']
nvda_shares = yf.Ticker('INTC').info['sharesOutstanding']
intc_shares
# Calculate market capitalization (Adjusted Close * shares outstanding)
= data['NVDA']['Adj Close'] * nvda_shares
nvda_market_cap = data['INTC']['Adj Close'] * intc_shares intc_market_cap
While the share prices of NVIDIA and Intel are comparable, NVIDIA’s market capitalization has experienced a significant increase since 2020, in contrast to Intel’s more stable market capitalization.
# Plot the market capitalization data
=(12, 6))
plt.figure(figsize='NVIDIA')
plt.plot(nvda_market_cap.index, nvda_market_cap, label='Intel')
plt.plot(intc_market_cap.index, intc_market_cap, label'Market Capitalization of NVIDIA and Intel (2012 - 2024)')
plt.title('Date')
plt.xlabel('Market Capitalization (USD)')
plt.ylabel(
plt.legend()True)
plt.grid( plt.show()