A beginner-friendly Python program that tracks stock portfolio performance and calculates key metrics. This project demonstrates fundamental Python concepts from Chapter 3 of Practical Python for Effective Algorithmic Trading.
- Track multiple stock positions (symbol, purchase price, current price, shares)
- Calculate current value, profit/loss in dollars, and percentage returns
- Generate a complete portfolio summary with overall performance metrics
- Beginner-friendly implementation using only basic Python concepts
- Visual indicators (emojis) to easily identify profitable positions
Try it instantly on Replit: Stock Portfolio Calculator
- Python 3.6 or higher (for local installation)
- No external libraries required - uses only Python standard library
- No programming experience required!
-
Create a Replit Account:
- Go to replit.com and sign up for a free account
-
Create a New Repl:
- Click the "+ Create Repl" button
- Select "Python" as the language
- Name your project (e.g., "StockPortfolioCalculator")
- Click "Create Repl"
-
Add the Code:
- Delete any default code in the main.py file
- Copy and paste the entire contents of
portfolio_calculator.py
into the main.py file - Click "Save"
-
Run the Program:
- Click the "Run" button at the top
- Follow the prompts to enter your stock information
- View your portfolio summary!
If you prefer to run the program on your own computer:
-
Install Python:
- Download and install Python from python.org
- Make sure to check "Add Python to PATH" during installation (Windows)
-
Download the Code:
- Download the
portfolio_calculator.py
file from this repository - Or create a new file and copy-paste the code
- Download the
-
Run the Program:
- Open a terminal/command prompt
- Navigate to the folder containing the file
- Run:
python portfolio_calculator.py
(orpython3 portfolio_calculator.py
on Mac/Linux) - Follow the prompts to enter your stock information
This project demonstrates several fundamental Python concepts from Chapter 3:
- Variables and Data Types: Using strings, integers, and floats
- Lists: Storing collections of related data
- Input/Output: Getting user input and displaying formatted results
- Arithmetic Operations: Calculating financial metrics
- Conditional Logic: Determining portfolio performance status
- Loops: Processing multiple stock positions
It's an excellent starting point for beginners interested in financial applications of Python.
===== STOCK PORTFOLIO SUMMARY CALCULATOR =====
Enter details for your stock positions below:
Stock #1:
Enter stock symbol (e.g., AAPL): AAPL
Enter purchase price per share: $150
Enter current price per share: $175.25
Enter number of shares: 10
... (additional stocks) ...
============================================================
📊 STOCK PORTFOLIO SUMMARY 📊
============================================================
📈 INDIVIDUAL STOCK PERFORMANCE:
------------------------------------------------------------
SYMBOL SHARES PURCHASE CURRENT VALUE P/L($) P/L(%)
------------------------------------------------------------
AAPL 10 $150.00 $175.25 $1752.50 $252.50 16.83% 🟢
MSFT 5 $250.00 $265.75 $1328.75 $78.75 6.30% 🟢
GOOGL 2 $2500.00 $2450.50 $4901.00 $-199.00 -2.00% 🔴
💼 PORTFOLIO SUMMARY:
------------------------------------------------------------
Total Investment: $5750.00
Current Portfolio Value: $7982.25
Overall Profit/Loss: $132.25 (2.30%) 🟢
🎉 Your portfolio is performing well with positive returns!
Want to improve this project? Here are some ideas:
- Save and load portfolio data from a file
- Fetch real-time stock prices automatically
- Add data visualization with charts (using matplotlib)
- Calculate additional metrics like portfolio volatility
- Support for different types of securities (bonds, ETFs, etc.)
These enhancements are covered in later chapters of Practical Python for Effective Algorithmic Trading.
This project is part of a learning path for algorithmic trading with Python:
- Basics: This portfolio calculator (Chapter 3 concepts)
- Intermediate: Adding data analysis and visualization (Chapters 7-8)
- Advanced: Implementing trading strategies and backtesting (Chapters 10-11)
Follow along with the complete guide in the book to build increasingly sophisticated trading tools.
Join The Quantitative Elite Community to:
- Share your implementation
- Get help with customizations
- Connect with other algorithmic traders
- Learn advanced Python trading techniques
This project is licensed under the MIT License - see the LICENSE file for details.
- Based on concepts from Practical Python for Effective Algorithmic Trading
- Inspired by the need for simple financial tools for beginner programmers
- Thanks to the Python community for making programming accessible to everyone
Happy coding and profitable investing! 📈