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.
-
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
-
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
-
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
-
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
-
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
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
| 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 |
- 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)
- 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
- 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
- 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
- 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
- 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
-
Wipro delivered the highest returns (~60% over 2 years) despite having the lowest share price — proving price alone doesn't indicate growth potential
-
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
-
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
-
Reliance showed the worst risk-reward profile — only 3.56% annual return despite 20.3% volatility — risk was not rewarded at all
-
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
-
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
- Clone the repository
git clone https://github.com/ShravyaHegade/stock-analysis.git
cd stock-analysis- Install required libraries
pip install yfinance pandas matplotlib seaborn jupyter- Open the notebook
jupyter notebook stock_analysis.ipynb- Run all cells — data will be fetched live from Yahoo Finance!
- 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
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





