Skip to content

aadithyakrishnamethil/nse-portfolio-tracker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Stock Portfolio Tracker

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.


Features

  • 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)

Demo

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.


Installation

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.py

Portfolio Setup

Edit 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.json is excluded from git via .gitignore — your personal holdings stay private.


Project Structure

stock-portfolio-tracker/
├── portfolio_tracker.py     # Main application
├── portfolio.sample.json    # Example portfolio structure
├── requirements.txt         # Python dependencies
├── .gitignore               # Excludes portfolio.json
└── README.md

Planned Improvements

  • Auto-refresh prices every N minutes
  • Export summary to CSV
  • Add buy date and calculate holding period
  • Support for mutual funds

Tech Stack

  • Language: Python 3
  • Libraries: yfinance, matplotlib, json
  • Data source: Yahoo Finance (via yfinance)

License

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.

About

A Python CLI tool that fetches live NSE stock prices and displays portfolio profit/loss with a colour-coded bar chart

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages