A Python CLI tool that fetches live stock prices and shows your portfolio's profit/loss — with a colour-coded bar chart.
Built for Indian stocks (NSE) using the Yahoo Finance API.
- Fetches live stock prices via
yfinance - Calculates P/L (profit/loss) per stock in ₹ and %
- Displays a clean aligned summary table in the terminal
- Generates a colour-coded bar chart (green = gain, red = loss)
- Supports any stock available on Yahoo Finance (NSE, BSE, US markets)
Ticker Qty Buy Price Cur Price P/L (₹) P/L (%)
-----------------------------------------------------------------
RELIANCE.NS 10 2800.00 2950.00 1500.00 5.36%
TCS.NS 5 3500.00 3380.00 -600.00 -3.43%
INFY.NS 15 1450.00 1600.00 2250.00 10.34%
-----------------------------------------------------------------
Total Invested : ₹1,04,750.00
Total Value : ₹1,07,900.00
Overall P/L : ₹3,150.00 (3.01%)
A bar chart window also opens showing P/L per stock visually.
Requirements: Python 3.8+
# 1. Clone the repository
git clone https://github.com/YOUR_USERNAME/stock-portfolio-tracker.git
cd stock-portfolio-tracker
# 2. (Optional) Create a virtual environment
python -m venv venv
venv\Scripts\activate # Windows
# source venv/bin/activate # macOS / Linux
# 3. Install dependencies
pip install -r requirements.txt
# 4. Set up your portfolio
cp portfolio.sample.json portfolio.json
# Edit portfolio.json with your own holdings
# 5. Run
python portfolio_tracker.pyEdit portfolio.json with your holdings:
[
{
"ticker": "RELIANCE.NS",
"quantity": 10,
"buy_price": 2800.00
},
{
"ticker": "TCS.NS",
"quantity": 5,
"buy_price": 3500.00
}
]Ticker format:
| Market | Suffix | Example |
|---|---|---|
| NSE (India) | .NS |
INFY.NS |
| BSE (India) | .BO |
INFY.BO |
| US Stocks | none | AAPL |
portfolio.jsonis excluded from git via.gitignore— your personal holdings stay private.
stock-portfolio-tracker/
├── portfolio_tracker.py # Main application
├── portfolio.sample.json # Example portfolio structure
├── requirements.txt # Python dependencies
├── .gitignore # Excludes portfolio.json
└── README.md
- Auto-refresh prices every N minutes
- Export summary to CSV
- Add buy date and calculate holding period
- Support for mutual funds
- Language: Python 3
- Libraries:
yfinance,matplotlib,json - Data source: Yahoo Finance (via yfinance)
MIT License — free to use, fork, and modify.
Built to track Indian stock market holdings and learn about API integration and data visualisation in Python.