Skip to content

SHAROZ221/codealpha_stock_portfolio_tracker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

4 Commits
ย 
ย 
ย 
ย 

Repository files navigation

Stock Portfolio Tracker

CodeAlpha Python Programming Internship | Task 2


๐Ÿ“Œ Goal

A stock tracker that calculates total investment value, current value, and profit/loss based on manually defined stock prices.


๐Ÿ“ Project Files

File Purpose
main.py Main script โ€” stock tracker with menu
portfolio_<timestamp>.csv Auto-generated output file with portfolio summary

โ–ถ๏ธ How to Run

No external libraries needed. Uses only built-in Python modules.

python main.py

๐ŸŽฎ How to Use

==================================================
  Stock Portfolio Tracker
==================================================

  1. Add stock
  2. View portfolio (with profit/loss)
  3. Remove/sell stock
  4. Save portfolio to CSV
  5. Exit
  1. Add stock โ€” enter symbol, quantity, and your buy price (or press Enter to use the current market price). Adding more shares of an existing stock automatically calculates a weighted average buy price.
  2. View portfolio โ€” shows quantity, buy price, current price, invested amount, current value, and profit/loss (in $ and %) for each stock, plus an overall total.
  3. Remove/sell stock โ€” sell part or all of your shares of a stock.
  4. Save portfolio to CSV โ€” exports the full breakdown including profit/loss to a .csv file.
  5. Exit โ€” quit the program.

๐Ÿ“ˆ Available Stocks (Current Market Price)

Symbol Price ($)
AAPL 180
TSLA 250
GOOGL 140
MSFT 380
AMZN 185
META 490
NFLX 620
NVDA 875
AMD 165
INTC 35

๐Ÿ” Sample Output

  ================================================================================
  PORTFOLIO SUMMARY
  ================================================================================
  Symbol     Qty      Buy $      Cur $     Invested        Value          P/L    P/L %
  --------------------------------------------------------------------------------
  AAPL         5     170.00     180.00       850.00       900.00 +      50.00 +   5.88%
  TSLA         5     250.00     250.00     1,250.00     1,250.00 +       0.00 +   0.00%
  --------------------------------------------------------------------------------
  TOTAL                                    2,100.00     2,150.00 +      50.00 +   2.38%
  ================================================================================
  [+] Overall: You're up $50.00 (2.38%)

๐Ÿ’ก Key Concepts Used

  • dictionary โ€” hardcoded current stock prices
  • input/output โ€” user enters stock symbol, quantity, and buy price
  • basic arithmetic โ€” invested amount, current value, profit/loss calculations
  • file handling โ€” saves portfolio summary (with P/L) to .csv file

๐Ÿš€ Extra Features Added Beyond the Original Brief

  • Profit/Loss tracking โ€” compares your buy price against current market price to show gains/losses per stock and overall, in both dollar amount and percentage.
  • Weighted average buy price โ€” adding more shares of a stock you already own recalculates your average cost basis automatically.
  • Sell/remove option โ€” sell part or all of a holding directly from the menu.
  • Detailed CSV export โ€” saved file includes buy price, current price, invested amount, value, and P/L columns.

About

A command-line stock portfolio tracker built in Python. Add stocks by symbol and quantity, view your total investment value, and export your portfolio to a CSV file. Built as part of the CodeAlpha Python Programming Internship.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages