Building a Python application with CSV validation, live stock prices, and automated testing.
As part of my journey into data science and AI engineering, I’ve been focusing on strengthening my Python programming skills through practical projects. After reviewing Python fundamentals, I wanted to move beyond individual exercises and build something that combined several concepts into one working application. I chose to develop an Investment Portfolio Tracker, a command-line application that reads stock holdings from a CSV file, retrieves stock prices, and calculates portfolio performance. The project also connects my interest in finance with programming, making it a practical starting point for my learning journey.
What I built
The application reads a CSV file containing stock symbols, share quantities, and purchase prices. It then calculates the investment cost, current value, gain or loss, and percentage return for each holding and for the overall portfolio. It supports two modes:
- Manual prices: Uses predefined stock prices for demonstration and testing.
- Live prices: Retrieves stock prices through the Alpha Vantage API.
I also implemented input validation to identify missing symbols, invalid numerical values, and other issues in the CSV data. The final result is a formatted portfolio report displayed in the terminal.

Investment Portfolio Tracker: example output using hypothetical holdings and manual demonstration prices, including portfolio calculations and data validation warnings.
Challenges along the way
One of the more interesting challenges was integrating live stock prices. Although making an API request was relatively straightforward, handling unexpected responses required additional work. I needed to account for missing prices, HTTP errors, and API rate limits.
During testing, I encountered a rate-limit response from Alpha Vantage. I addressed this by adding a delay between requests and improving the error handling so the application could stop gracefully when prices were unavailable.
Another challenge was organizing the code as the application grew. Initially, some operations were being repeated unnecessarily, including loading the CSV file more than once. I refactored the report-generation logic into a reusable function shared by the manual and live-price workflows. This helped me better understand the importance of separating responsibilities and avoiding duplicated work.
Learning to test my code
Automated testing was another major learning experience. Using pytest, I wrote tests for portfolio calculations, CSV validation, API responses, and error handling.
I also learned how to use mocking to simulate API responses without making actual requests. This allowed me to test different scenarios, including failed requests and rate-limit messages, without depending on the external service.
By the end of the project, I had 34 passing automated tests.
What I learned
The biggest lesson from this project was that building an application involves more than writing functions that produce the correct calculations. I gained practical experience with debugging, error handling, working with APIs, organizing code into modules, and writing automated tests.
I also learned the basics of Git and GitHub, created a README, and published the completed project as my first public repository.
There are still improvements I would like to explore, including handling partially available prices, adding historical performance, and improving the command-line interface. For now, I’m happy to have completed a working first version that brings together several Python concepts I’ve been studying. This project marks my first step from learning Python fundamentals toward building more complex data and AI applications.
Project code: Investment Portfolio Tracker on GitHub
