Day 62 of 100 Days Coding Challenge: Python
Yesterday, I taught my script how to look into the past—specifically, the last 30 days of each tracked stock’s closing prices. Today, we’re talking emotions—well, stock emotions. I added a function in Python to show each stock’s daily percentage change, color-coded like a moody person: green when it’s up, red when it’s down, and default when it’s flat.
Now, to be clear, I’m not a day trader glued to five monitors with live tickers whizzing by. I have a full-time job, thank you very much, and no one’s got time for that kind of circus. I check in weekly, adjust when needed, and focus on consistency over drama. Still, this function gives me a quick visual snapshot of how things are moving—and more importantly, how they might move. It’s like giving your portfolio a morning coffee and asking, “How are we feeling today?”
Patterns are the name of the game. If I can start spotting them, maybe one day I’ll teach this program to make some educated guesses—and eventually, add a bit of risk management to keep me from playing financial roulette. The next few days are all about adding the kind of analytical firepower that helps with smarter decisions down the road. And honestly? I’m kind of pumped.
Today’s Motivation / Challenge
You know that moment when you look at your bank account and squint, wondering, “What happened yesterday?” That’s what this feature is for. It’s like a digital mood chart for your stocks—without the therapy bills. Adding daily change percentages, especially in color, helps me scan for drama or calm in seconds. It’s a tiny step toward building a truly useful tool for hands-off investors like me, who want the intel without the stress.
Purpose of the Code (Object)
This code adds a quick visual check-in for each stock in my portfolio. It tells me whether a stock’s price went up or down today—and by how much—without needing a spreadsheet or third-party app. It’s lightweight, readable, and tailored to my investment rhythm.
AI Prompt (used to create today’s function):
“Please add the following function to the script.
Daily Change (%): Show today’s % change for each stock with green/red highlight.“
Functions & Features
- Calculates daily percent change for each stock.
- Highlights gains in green and losses in red.
- Leaves unchanged stocks in default color.
- Makes my console look like it actually cares.
Requirements / Setup
pip install yfinance
Minimal Code Sample
if change_percent > 0:
color = “\033[92m” # Green
elif change_percent < 0:
color = “\033[91m” # Red
else:
color = “\033[0m” # Reset
This assigns a text color based on the day’s percent change in stock price.
Notes / Lessons Learned
I’m starting to feel like a feature-adding machine—well-oiled, slightly caffeinated, and surprisingly organized. Thanks to the roadmap I drafted early on, it’s easier to stack new functions like LEGO bricks (minus the foot pain).
Today, I learned how to add color using ANSI escape codes. Think of them as secret signals you whisper to your terminal to make it look fancier. So now, green means the stock had a good day, red means it might need a hug, and the reset command keeps the rest of the terminal from turning into Christmas.
What I love about this feature? It’s subtle but powerful. Visual clarity goes a long way when you don’t have time to deep dive. And hey—who knew the terminal had a flair for drama?
Optional Ideas for Expansion
- Add arrows (↑/↓) next to the percent for more flair.
- Let users set custom alert colors (purple for panic? Why not).
- Create a summary line showing how many stocks gained vs. lost today.
