Market pandas examples

Compare stocks with returns, peers, and correlations.

These notebooks use market data as pandas practice: load ticker history, calculate daily returns, compare peers, and build a simple pre-market read-through template. They are educational examples, not investment advice.

Open the data picker

Editable stock notebooks

Open a notebook, rerun the cells, then change the ticker list or pre-market table.

Pre-market idea

For a list of tickers moving before the open, create a small feature table: sector, theme, size bucket, product exposure, or index basket. Then compare each ticker against peers with overlapping features.

pairs['similarity'] = (
    same_sector * 2
    + same_theme * 3
    + same_size_bucket
)
peer_implied_move = weighted_average(peer_moves, similarity)

This is a read-through exercise, not a forecast. The useful pandas lesson is the self-join, feature scoring, weighted average, and residual: actual move minus peer-implied move.

Why returns instead of prices

Price levels are not comparable across tickers. Daily returns make correlations, volatility, and relative performance easier to compare.

wide_close = prices.pivot(index='date', columns='symbol', values='close')
wide_returns = wide_close.pct_change().dropna()
wide_returns.corr()