Skip to content

Latest commit

 

History

4 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

📈 Indian Stock Market Analysis (NSE)

Analyzing TCS, Infosys, Reliance, HDFC Bank & Wipro | 2023–2025


🔍 Project Overview

This project performs an end-to-end analysis of 5 major Nifty 50 stocks from the National Stock Exchange (NSE) using 2 years of real market data (Jan 2023 – Jan 2025). The goal is to identify price trends, compare risk-adjusted returns, understand sector correlations, and detect buy/sell trading signals using Moving Average crossovers.


🎯 Business Questions Answered

  1. Which stock gave the best returns over 2 years? → Wipro delivered the highest returns of ~60% over 2 years despite having the lowest share price among the 5 stocks

  2. Which stock is the safest (lowest risk) investment? → TCS had the lowest annual volatility of 19.7% making it the most stable stock among the 5

  3. Do IT sector stocks move together? → Yes! TCS, Infosys and Wipro showed high correlation of 60–70% — they move together because they are affected by the same industry news and global IT demand

  4. Which stock has the best risk vs return balance? → TCS — 16.4% annual return with the lowest volatility (19.7%) — high return with lowest risk makes it the most efficient stock

  5. When were the best times to buy and sell TCS? → 6 Golden Cross (buy) signals and 5 Death Cross (sell) signals were detected over 2 years — signals accurately predicted major price movements throughout 2023–2024


📁 Project Structure

STOCK-ANALYSIS/
├── charts/
│   ├── all_stocks_comparison.png
│   ├── all_stocks_prices.png
│   ├── correlation_heatmap.png
│   ├── risk_return.png
│   ├── tcs_moving_averages.png
│   └── tcs_signals.png
├── data/
│   └── tcs_data.csv
├── .gitignore
├── README.md
└── stock_analysis.ipynb


🛠️ Tools & Technologies

Tool Purpose
Python Core programming language
yfinance Fetching live NSE stock data
pandas Data manipulation and analysis
matplotlib Data visualization
seaborn Statistical visualizations
Jupyter Notebook Interactive development environment

📊 Analysis Performed

1. Data Collection

  • Fetched 2 years of real OHLCV data for 5 NSE stocks using yfinance API
  • Verified data quality — checked for missing values, duplicates, correct date ranges
  • 491 trading days of data per stock (Jan 2023 – Jan 2025)

2. Moving Average Analysis

  • Calculated 20-day and 50-day Simple Moving Averages (SMA)
  • Identified short-term and long-term price trends for TCS
  • Visualized price trends with Moving Average overlays

3. Stock Performance Comparison

  • Compared actual prices of all 5 stocks
  • Normalised prices to % growth from Day 1 for fair comparison
  • Identified best and worst performing stocks over 2 years

4. Daily Returns & Correlation Analysis

  • Calculated daily percentage returns for all 5 stocks
  • Built a correlation matrix to measure how stocks move together
  • Created a seaborn heatmap to visualize sector correlations

5. Risk vs Return Analysis

  • Calculated annualized return and annualized volatility for each stock
  • Plotted Risk vs Return scatter chart to identify most efficient stock
  • Identified best risk-adjusted investment opportunity

6. Trading Signals — Golden Cross & Death Cross

  • Detected 6 Golden Cross (buy) signals on TCS over 2 years
  • Detected 5 Death Cross (sell) signals on TCS over 2 years
  • Signals accurately predicted major price movements

📸 Charts

TCS Stock Price with Moving Averages

TCS Moving Averages

All 5 Stocks — Actual Price Comparison

All Stocks Price

All 5 Stocks — % Growth Comparison (from Jan 2023)

Growth Comparison

Correlation Heatmap — Daily Returns

Correlation Heatmap

Risk vs Return — All 5 Stocks

Risk vs Return

Golden Cross & Death Cross Signals — TCS

Trading Signals


💡 Key Insights

  1. Wipro delivered the highest returns (~60% over 2 years) despite having the lowest share price — proving price alone doesn't indicate growth potential

  2. TCS showed the best risk-adjusted performance — 16.4% annual return with the lowest volatility (19.7%) — the safest and most efficient stock among the 5

  3. IT sector stocks (TCS, Infosys, Wipro) showed high correlation (60–70%) — they move together because they are affected by the same industry news and global IT demand

  4. Reliance showed the worst risk-reward profile — only 3.56% annual return despite 20.3% volatility — risk was not rewarded at all

  5. HDFC Bank spent most of 2023 below the zero line — investors were in loss for the majority of the year before recovering in late 2024

  6. Golden Cross and Death Cross signals on TCS accurately predicted major price movements — buy signals preceded rallies and sell signals preceded corrections throughout 2023–2024


🚀 How to Run This Project

  1. Clone the repository
git clone https://github.com/ShravyaHegade/stock-analysis.git
cd stock-analysis
  1. Install required libraries
pip install yfinance pandas matplotlib seaborn jupyter
  1. Open the notebook
jupyter notebook stock_analysis.ipynb
  1. Run all cells — data will be fetched live from Yahoo Finance!

📚 What I Learned

  • Fetching real-time financial data using APIs (yfinance)
  • Time-series data analysis using pandas
  • Moving Average calculations and their significance in finance
  • Correlation analysis between multiple financial instruments
  • Risk vs Return analysis — a fundamental concept in portfolio management
  • Detecting trading signals using Moving Average crossovers
  • Data sanity checking and validation before analysis

👩‍💻 Author

Shravya Hegade B.E. in AI & Data Science | SIES Graduate School of Technology, Navi Mumbai 📧 [hegdeshrav22@gmail.com] 🔗 [https://linkedin.com/in/shravya-hegade] 🐙 [https://github.com/ShravyaHegade]


Data source: Yahoo Finance via yfinance library Analysis period: January 2023 – January 2025 Exchange: National Stock Exchange (NSE), India

About

Analysis of 5 NSE stocks using Python, Pandas, matplotlib, Seaborn and yfinance

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages