Skip to content

stock_portfolio_calculator_basic based on the chapter 3 from the book Practical Python For Effective Algorithmic Trading

Notifications You must be signed in to change notification settings

thekuldeepsingh/stock_portfolio_calculator_basic

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 

Repository files navigation

Stock Portfolio Calculator

Python Status License Beginner Friendly

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.

🌟 Features

  • 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

🚀 Live Demo

Try it instantly on Replit: Stock Portfolio Calculator

📋 Prerequisites

  • Python 3.6 or higher (for local installation)
  • No external libraries required - uses only Python standard library
  • No programming experience required!

⚡ Quick Deploy to Replit (No Installation Required)

  1. Create a Replit Account:

  2. Create a New Repl:

    • Click the "+ Create Repl" button
    • Select "Python" as the language
    • Name your project (e.g., "StockPortfolioCalculator")
    • Click "Create Repl"
  3. 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"
  4. Run the Program:

    • Click the "Run" button at the top
    • Follow the prompts to enter your stock information
    • View your portfolio summary!

💻 Local Installation

If you prefer to run the program on your own computer:

  1. Install Python:

    • Download and install Python from python.org
    • Make sure to check "Add Python to PATH" during installation (Windows)
  2. Download the Code:

    • Download the portfolio_calculator.py file from this repository
    • Or create a new file and copy-paste the code
  3. Run the Program:

    • Open a terminal/command prompt
    • Navigate to the folder containing the file
    • Run: python portfolio_calculator.py (or python3 portfolio_calculator.py on Mac/Linux)
    • Follow the prompts to enter your stock information

🎓 Educational Value

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.

📊 Example Output

===== 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!

✅ Future Enhancements

Want to improve this project? Here are some ideas:

  1. Save and load portfolio data from a file
  2. Fetch real-time stock prices automatically
  3. Add data visualization with charts (using matplotlib)
  4. Calculate additional metrics like portfolio volatility
  5. Support for different types of securities (bonds, ETFs, etc.)

These enhancements are covered in later chapters of Practical Python for Effective Algorithmic Trading.

📚 Learning Path

This project is part of a learning path for algorithmic trading with Python:

  1. Basics: This portfolio calculator (Chapter 3 concepts)
  2. Intermediate: Adding data analysis and visualization (Chapters 7-8)
  3. Advanced: Implementing trading strategies and backtesting (Chapters 10-11)

Follow along with the complete guide in the book to build increasingly sophisticated trading tools.

🤝 Community Support

Join The Quantitative Elite Community to:

  • Share your implementation
  • Get help with customizations
  • Connect with other algorithmic traders
  • Learn advanced Python trading techniques

📝 License

This project is licensed under the MIT License - see the LICENSE file for details.

🙏 Acknowledgments


Happy coding and profitable investing! 📈

About

stock_portfolio_calculator_basic based on the chapter 3 from the book Practical Python For Effective Algorithmic Trading

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published