Watching Your Stocks Like a Hawk (But With a Graph)

Day 61 of 100 Days Coding Challenge: Python

The last five days were all about laying the foundation—think of it as assembling IKEA furniture, but with Python and fewer Allen wrenches. I got the stock tracker’s bones in place, installing essentials like the yfinance library. Now, it’s time to dress it up and make it do something more alive—like track real stock movement over time.

I’m finally stepping into the exciting part: creating a portfolio visualization that doesn’t require squinting at 14 browser tabs.

We’re starting simple. One historical price chart per stock. No more, no less. Why? Because trying to cram five charts into one screen is like watching five soap operas at once—dramatic, confusing, and probably bad for your blood pressure.

Back in university, my finance professors swore by stock observation like it was a sacred rite. Watch the markets, they said. Understand the impact of events—unemployment numbers, interest rate announcements, or when Jerome Powell so much as blinks. These things shake the market, and now, thanks to a bit of Python magic, I can watch those ripples without hopping from one website to another.

Today’s Motivation / Challenge

Have you ever tried checking your stocks manually, one by one? It’s like chasing toddlers in different directions. Today’s goal: automate that madness. With a single function, I want to see the historical price trends of each stock in my portfolio—visually. Because numbers are fine, but a chart? A chart speaks volumes.

Purpose of the Code (Object)

This little script fetches and plots the past 30 days of closing prices for each stock in your portfolio. It doesn’t try to impress anyone with fancy calculations. It just shows you what your stock has been up to, in a nice, simple line graph—so you can stop opening 27 browser tabs.

AI Prompt

Add the function to plot past 30-day price history for a single stock

Functions & Features

  • Plots past 30-day price history for a single stock
  • Automatically fetches historical data from Yahoo Finance.
  • Easy to reuse for each stock in your portfolio

Requirements / Setup

pip install yfinance matplotlib

Minimal Code Sample

import yfinance as yf

import matplotlib.pyplot as plt

def plot_stock_history(ticker):

    stock = yf.Ticker(ticker)

    hist = stock.history(period=”30d”)

    hist[‘Close’].plot(title=f”{ticker} – Last 30 Days”)

    plt.xlabel(“Date”)

    plt.ylabel(“Price ($)”)

    plt.grid(True)

    plt.show()

→ Fetches and plots 30-day closing price for a given stock symbol.

Stock Tracker

Notes / Lessons Learned

To get this feature working, I first installed yfinance and matplotlib. Easy enough—until I noticed the pip version nagging me to update (again). I was on 25.1.1, and suddenly it wants 25.2. It’s like that one friend who insists on “just one more update” before going out.

This is the reality of programming: libraries get updated more often than your favorite streaming shows, and if you’re not careful, your working code might just throw a tantrum the next day. I used to roll my eyes when game servers went down for “maintenance.” Now I know—those devs were heroes.

Also, pro tip: stock movements don’t just come from earnings reports. Tariff announcements? Those hit hard. I saw a few of my stocks tumble right after one went into effect. Should’ve bought the dip… but hey, now I can at least see it happening, in style.

Optional Ideas for Expansion

  • Add a dropdown menu or an input box to select stock instead of typing it
  • Color-code gains vs losses on the chart
  • Combine charts into one interactive dashboard (when you’re feeling brave)

Leave a Reply

Your email address will not be published. Required fields are marked *