Lab Quickstart
Copy–paste workflows for Week 1
Lab Quickstart (No-install Friendly)
Use this page in Google Colab, GitHub Codespaces, or the lab PCs. Copy the cells into a new notebook and run top-to-bottom.
1) Setup (Colab-only installs)
# If a package is missing, run this once in Colab
!pip -q install yfinance pandas-datareader plotly2) Imports and Settings
import yfinance as yf
import pandas as pd
import plotly.express as px
import pandas_datareader.data as web
pd.options.display.float_format = "{:.4f}".format3) Equity Data: First Look
tickers = ["AAPL", "MSFT"] # Try changing tickers
df = yf.download(tickers, start="2022-01-01", end="2023-01-01")
prices = df["Adj Close"].copy()
# Quick check
prices.tail()Visualize
px.line(prices, title="Adjusted Close Prices")4) Simple Returns and Moving Average
returns = prices.pct_change().dropna()
ma_window = 20 # Try 10 or 30
ma = prices.rolling(ma_window).mean()
px.line(ma, title=f"{ma_window}-Day Moving Average")
returns.tail()5) Macro Series from FRED
gdp = web.DataReader("GDP", "fred", start="2018-01-01")
gdp.tail()6) Save a CSV Snapshot (Optional)
prices.to_csv("prices_sample.csv")
"Saved: prices_sample.csv"7) Mini-Tasks (Submit in your notes)
- Change tickers and describe one observation from the chart
- Compare 10-day vs 30-day moving averages: what’s the effect?
- Fetch a second FRED series (e.g., “CPIAUCSL”). Any simple relationship with prices?
Focus on interpretation; keep code changes small and clear.