An end-to-end financial analytics and machine learning project that analyzes historical performance of NIFTY stocks, predicts next-day stock price movement using technical indicators, and presents the results through an interactive Streamlit dashboard.
๐ Live Demo:
https://sector-wise-performance-and-risk-analysis-ml.streamlit.app/
Disclaimer:
This project is for educational purposes only and should not be considered financial or investment advice.
- ๐ฅ Automated historical stock data collection using Yahoo Finance
- ๐ Statistical analysis of daily stock returns
- ๐ Annual return and volatility calculations
- โ๏ธ Sharpe Ratio computation for risk-adjusted performance
- ๐ฆ Sector-wise performance comparison
- ๐ Correlation analysis between stocks
- ๐ Professional financial visualizations
- โ๏ธ Technical indicator generation
- ๐ค Machine Learning pipeline for stock movement prediction
- ๐ง Automatic model comparison and best model selection
- ๐พ Model persistence using Joblib
- ๐ฎ Next-day stock movement prediction with confidence scores
- ๐ Automatic CSV report generation
- Analysed 24 NIFTY stocks across 5 sectors
- Built an end-to-end ML pipeline
- Engineered 13 technical indicators
- Trained and compared multiple classification models
- Developed an interactive multi-page Streamlit dashboard
- Automated prediction generation for all supported stocks
Historical Stock Data
โ
โผ
Data Collection (Yahoo Finance)
โ
โผ
Data Cleaning & Processing
โ
โผ
Financial Metrics Calculation
โ
โผ
Visualization Generation
โ
โผ
Feature Engineering
โ
โผ
Machine Learning Models
โ
โผ
Model Evaluation
โ
โผ
Best Model Selection
โ
โผ
Prediction Generation
โ
โผ
Interactive Streamlit Dashboard
Sector-Performance-Analysis-ML/
โ
โโโ assets/ # Images used in the README
โ
โโโ dashboard/ # Reusable Streamlit components
โ โโโ chart_style.py
โ โโโ charts.py
โ โโโ components.py
โ โโโ config.py
โ โโโ indicators.py
โ โโโ load_data.py
โ โโโ sidebar.py
โ โโโ styles.py
โ โโโ technical_indicators.py
โ โโโ theme.py
โ
โโโ data/
โ โโโ raw/ # Historical stock data
โ โโโ processed/ # Processed datasets
โ
โโโ figures/ # Generated visualizations
โ
โโโ models/ # Trained ML models
โ
โโโ outputs/
โ โโโ model_summary.csv
โ โโโ stock_summary.csv
โ โโโ descriptive_statistics.csv
โ โโโ predictions/ # Model prediction outputs
โ
โโโ pages/ # Streamlit application pages
โ โโโ 1_Dashboard.py
โ โโโ 2_Sector_Analysis.py
โ โโโ 3_Stock_Analysis.py
โ โโโ 4_Model_Analysis.py
โ โโโ 5_Prediction.py
โ โโโ 6_About.py
โ
โโโ src/
โ โโโ config.py
โ โโโ data_ingestion.py
โ โโโ feature_engineering.py
โ โโโ metrics.py
โ โโโ visualize.py
โ โโโ ml/
โ โโโ evaluation.py
โ โโโ ml_pipeline.py
โ โโโ model_training.py
โ โโโ prediction.py
โ โโโ prediction_pipeline.py
โ โโโ preprocessing.py
โ โโโ utils.py
โ
โโโ app.py # Streamlit entry point
โโโ main.py # Data processing pipeline
โโโ requirements.txt
โโโ LICENSE
โโโ README.md
The project analyzes 24 large-cap NIFTY stocks across five major sectors:
| Sector | Companies |
|---|---|
| Banking | HDFC Bank, ICICI Bank, SBI, Axis Bank, Kotak Bank |
| Information Technology | TCS, Infosys, Wipro, HCLTech, Tech Mahindra |
| Pharmaceuticals | Sun Pharma, Dr. Reddy's, Cipla, Divi's Labs, Lupin |
| Automobile | Maruti Suzuki, M&M, Bajaj Auto, Hero MotoCorp |
| FMCG | Hindustan Unilever, ITC, Nestlรฉ India, Britannia, Dabur |
Historical data is downloaded automatically using the yfinance API.
The project computes:
- Daily Returns
- Descriptive Statistics
- Annual Returns
- Annual Volatility
- Sharpe Ratio
- Correlation Matrix
- Sector Performance
- Investment Growth
The machine learning pipeline creates the following technical indicators:
| Feature |
|---|
| Daily Return |
| 5-Day Moving Average |
| 10-Day Moving Average |
| 20-Day Moving Average |
| Volume Change |
| Rolling Volatility |
| High-Low Percentage |
| Open-Close Percentage |
| RSI (Relative Strength Index) |
| MACD |
| MACD Signal |
| Bollinger Band Upper |
| Bollinger Band Lower |
These features are used to predict whether the stock price will move UP or DOWN on the following trading day.
Three supervised learning algorithms are trained and evaluated.
| Model | Purpose |
|---|---|
| Logistic Regression | Baseline linear classifier |
| Decision Tree | Non-linear decision model |
| Random Forest | Ensemble learning model |
Each model is evaluated using:
- Accuracy
- Precision
- Recall
- F1 Score
The model with the highest F1 Score is automatically selected and saved.
The project automatically generates:
- Risk vs Return Scatter Plot
- Correlation Heatmap
- Sector-wise Returns
- Sector-wise Volatility
- Investment Growth Comparison
- Top 5 Performing Stocks
- Bottom 5 Performing Stocks
- Sector Growth Comparison
- Sharpe Ratio Comparison
All plots are saved inside the figures/ directory.
After execution, the project automatically creates:
outputs/
โ
โโโ descriptive_statistics.csv
โโโ stock_summary.csv
โโโ model_summary.csv
It also generates:
- trained machine learning models
- prediction CSV files
- processed datasets
- financial visualizations
git clone https://github.com/abhiminav/Sector-Performance-Analysis-ML.git
cd Sector-Performance-Analysis-ML
pip install -r requirements.txtpython main.pystreamlit run app.py| Category | Technology |
|---|---|
| Programming | Python |
| Data Analysis | Pandas, NumPy |
| Machine Learning | Scikit-learn |
| Dashboard | Streamlit |
| Interactive Charts | Plotly |
| Static Visualisation | Matplotlib |
| Data Source | yfinance |
| Model Persistence | Joblib |
Potential enhancements include:
- Cross-validation
- Hyperparameter tuning using GridSearchCV
- XGBoost and LightGBM models
- LSTM-based time-series forecasting
- Portfolio optimization
- Real-time stock prediction
- Model explainability using SHAP values
Abhinav Mishra
B.Tech Computer Science Engineering
Built as a portfolio project showcasing skills in:
- Data Analysis
- Financial Analytics
- Machine Learning
- Streamlit Dashboard Development
This project is licensed under the MIT License.




