Skip to content

Tech Stock Prices

This dataset consists of the daily stock prices and volume of ten different tech companies: Apple (AAPL), Amazon (AMZN), Alibaba (BABA), Salesforce (CRM), Facebook (FB), Alphabet (GOOG), Intel (INTC), Microsoft (MSFT), Nvidia (NVDA), and Tesla (TSLA).

There are ten CSV files in the data/ folder named with the stock symbol for each of the ten companies listed above. Looking for another company? You can download it from Yahoo Finance and upload it to your workspace.

Not sure where to begin? Scroll to the bottom to find challenges!

import pandas as pd
aapl = pd.read_csv("data/AAPL.csv")
print(aapl.shape)
aapl.head(100)

Data Dictionary

ColumnExplanation
DateDate of observation
OpenOpening price
HighHighest price during trading day
LowLowest price during trading day
CloseClose price
Adj CloseAdjusted close price adjusted for splits and dividend and/or capital gain distribution
VolumeNumber of shares traded during trading day

Source of dataset.

Don't know where to start?

Challenges are brief tasks designed to help you practice specific skills:

  • 🗺️ Explore: Which of the ten companies has the highest closing price based on the most recent data?
  • 📊 Visualize: Create a plot that visualizes the closing price at the end of each month for the 10 tech stocks.
  • 🔎 Analyze: Which of the ten companies have experienced the greatest percent increase in closing price over the course of their existence?

Scenarios are broader questions to help you develop an end-to-end project for your portfolio:

You have been hired as an analyst for a small investment firm. They currently specialize in commodities, focusing on coffee, cocoa, and sugar. However, they are now interested in expanding to technology companies. Your manager has asked you to explore the returns and volatilities of the ten stocks provided and contrast them with the three commodities they currently invest in.

They also want you to recommend how tech stocks could be integrated into a portfolio with the existing commodities they invest in to minimize risk while gaining exposure to the new market.

You will need to prepare a report that is accessible to a broad audience. It should outline your motivation, steps, findings, and conclusions.

Commodity prices can be found here.

import pandas as pd
import os
import matplotlib.pyplot as plt
import seaborn as sns

data_folder = "data"
csv_files = [file for file in os.listdir(data_folder) if file.endswith('.csv')]
stock_data = {}
for file in csv_files:
    # Extract stock ticker from filename (e.g., AAPL from AAPL.csv)
    ticker = file.replace(".csv", "")
    ## Load the CSV into a DataFrame
    df = pd.read_csv(
        os.path.join(data_folder, file),
        parse_dates = ['Date'],
        index_col = 'Date'
    ).sort_index()
    ## Store in dictionary
    stock_data[ticker] = df
    
    ## Print exploratory information
    print(f"Ticker: {ticker}")
    print(f"Shape: {df.shape}")
    print(df.head(5))
    print("="*75)

    print(df.columns)
    
    latest_closing_prices = {
    ticker: df['Close'].iloc[-1]
    for ticker, df in stock_data.items()
}

# Identify the top ticker
top_ticker   = max(latest_closing_prices, key=latest_closing_prices.get)
top_price    = latest_closing_prices[top_ticker]   

print(
    f"The highest recent closing price is {top_ticker} at ${top_price:,.2f}"
)
import pandas as pd

# Resample to end of month and take last available Close price
monthly_close = {
    ticker: df['Close'].resample('M').last()
    for ticker, df in stock_data.items()
}

# Combine into a DataFrame
monthly_df = pd.DataFrame(monthly_close)

# Melt the DataFrame to clean format for Seaborn
clean_df = (monthly_df
            .reset_index()
            .melt(
                id_vars='Date', 
                var_name='Ticker', 
                value_name='Close'
                )
)
# Set Seaborn theme
sns.set(style="whitegrid")
plt.figure(figsize=(14, 7))
sns.lineplot(
    data=clean_df,
    x='Date',
    y='Close',
    hue='Ticker',
    linewidth=2
)
plt.title('Monthly Closing Prices of Tech Stocks')
plt.xlabel('Date')
plt.ylabel('Closing Price (USD)')
plt.tight_layout()
plt.show()
# Compute percent change: (last - first) / first * 100
pct_changes = {}
for ticker, df in stock_data.items():
    first, last = df['Close'].iloc[0], df['Close'].iloc[-1]
    pct_changes[ticker] = (last - first) / first * 100

# Sort descending
sorted_changes = sorted(
    pct_changes.items(),
    key=lambda x: x[1],
    reverse=True
)

# Display top performers
print("Percent gains over full history:")
for ticker, pct in sorted_changes:
    print(f"• {ticker}: {pct:.1f}%")

best_ticker, best_pct = sorted_changes[0]
print(
    f"\nTop gainer: {best_ticker} with a {best_pct:.1f}% increase."
)