Skip to content

Kush05Bhardwaj/Stocksense-AI

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

53 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿ“ˆ StockSense AI

An AI-powered stock price prediction platform that leverages multiple machine learning models to provide comprehensive market analysis and predictions.

Python React

๐ŸŒŸ Features

Multi-Model Predictions

  • Linear Regression - Simple trend analysis with bar charts
  • Random Forest - Ensemble learning with line charts
  • XGBoost - Gradient boosting with area charts
  • LSTM (Deep Learning) - Neural network-based predictions with candlestick-style charts

Real-Time Data

  • Live stock data fetching from Yahoo Finance
  • Support for global markets (US, India, UK, Japan, Europe, etc.)
  • Automatic currency detection and display (USD $, INR โ‚น, GBP ยฃ, EUR โ‚ฌ, JPY ยฅ)

Sentiment Analysis

  • News scraping for stock-related articles
  • Sentiment analysis using NLP
  • Integration of sentiment data with price predictions

Interactive Dashboard

  • Clean, card-based UI with 2x2 grid layout
  • Multiple chart types for different models
  • Real-time prediction updates
  • Responsive design

๐Ÿ—๏ธ Architecture

StockSense AI/
โ”œโ”€โ”€ app/
โ”‚   โ”œโ”€โ”€ backend/          # Flask REST API
โ”‚   โ”‚   โ”œโ”€โ”€ routes/       # API endpoints
โ”‚   โ”‚   โ””โ”€โ”€ utils/        # Model runners
โ”‚   โ””โ”€โ”€ frontend/         # React + Vite
โ”‚       โ””โ”€โ”€ src/
โ”‚           โ”œโ”€โ”€ components/
โ”‚           โ”œโ”€โ”€ pages/
โ”‚           โ””โ”€โ”€ api/
โ”œโ”€โ”€ data/                 # Data processing
โ”œโ”€โ”€ models/              # ML model training
โ”œโ”€โ”€ sentiment/           # News & sentiment analysis
โ”œโ”€โ”€ portfolio/           # Portfolio simulation
โ””โ”€โ”€ risk/               # Risk analysis tools

๐Ÿš€ Getting Started

Prerequisites

  • Python 3.10+
  • Node.js 16+
  • npm or yarn

Installation

  1. Clone the repository
git clone https://github.com/Kush05Bhardwaj/Stocksense-AI.git
cd "StockSense AI"
  1. Set up Python environment
python -m venv venv
.\venv\Scripts\activate  # On Windows
source venv/bin/activate # On Mac/Linux

pip install -r requirements.txt
  1. Set up Frontend
cd app/frontend
npm install

Running the Application

  1. Start the Backend Server
# From project root
.\venv\Scripts\activate
python app/backend/app.py

Backend runs on: http://localhost:5000

  1. Start the Frontend
cd app/frontend
npm start

Frontend runs on: http://localhost:3000

  1. Access the Application Open your browser and navigate to: http://localhost:3000

๐Ÿ“Š Usage

Making Predictions

  1. Enter a stock symbol in the search box:

    • US Stocks: AAPL, MSFT, GOOGL, TSLA
    • Indian Stocks: RELIANCE.NS, TCS.NS, INFY.NS
    • Japanese Stocks: 7203.T (Toyota), 9984.T (SoftBank)
    • UK Stocks: BP.L, HSBA.L
  2. Click "Predict" to get predictions from all 4 models

  3. View results in the card layout:

    • Current price
    • Predicted prices from each model
    • Expected change percentage
    • Visual charts for each prediction

Data Collection (Optional)

For training custom models:

# 1. Fetch stock data
python data/fetch_data.py

# 2. Scrape news
python sentiment/news_scraper.py

# 3. Analyze sentiment
python sentiment/sentiment_analyzer.py

# 4. Merge data
python sentiment/merge_sentiment.py

# 5. Compare models
python models/compare_models.py

# 6. Train LSTM
python models/lstm_model.py

๐Ÿ› ๏ธ Technology Stack

Backend

  • Flask - Web framework
  • yFinance - Stock data API
  • pandas - Data manipulation
  • scikit-learn - ML models (Linear Regression, Random Forest)
  • XGBoost - Gradient boosting
  • TensorFlow/Keras - Deep learning (LSTM)
  • TextBlob - Sentiment analysis
  • NewsAPI - News data

Frontend

  • React 18 - UI framework
  • Vite - Build tool and dev server
  • Axios - HTTP client
  • Recharts - Data visualization
  • CSS3 - Styling

Data & ML

  • NumPy - Numerical computing
  • Matplotlib/Seaborn - Data visualization
  • BeautifulSoup4 - Web scraping

๐Ÿ“ Project Structure

StockSense AI/
โ”‚
โ”œโ”€โ”€ app/
โ”‚   โ”œโ”€โ”€ backend/
โ”‚   โ”‚   โ”œโ”€โ”€ app.py                    # Flask application entry point
โ”‚   โ”‚   โ”œโ”€โ”€ routes/
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ predict.py           # Prediction endpoints
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ portfolio.py         # Portfolio management
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ sentiment.py         # Sentiment analysis
โ”‚   โ”‚   โ””โ”€โ”€ utils/
โ”‚   โ”‚       โ”œโ”€โ”€ model_runner.py      # ML model execution
โ”‚   โ”‚       โ””โ”€โ”€ risk_runner.py       # Risk calculations
โ”‚   โ”‚
โ”‚   โ””โ”€โ”€ frontend/
โ”‚       โ”œโ”€โ”€ src/
โ”‚       โ”‚   โ”œโ”€โ”€ components/
โ”‚       โ”‚   โ”‚   โ”œโ”€โ”€ StockSearch.jsx  # Main search component
โ”‚       โ”‚   โ”‚   โ””โ”€โ”€ PredictionCard.jsx
โ”‚       โ”‚   โ”œโ”€โ”€ pages/
โ”‚       โ”‚   โ”‚   โ”œโ”€โ”€ Dashboard.jsx    # Main dashboard
โ”‚       โ”‚   โ”‚   โ””โ”€โ”€ Portfolio.jsx    # Portfolio view
โ”‚       โ”‚   โ”œโ”€โ”€ api/
โ”‚       โ”‚   โ”‚   โ””โ”€โ”€ api.js           # API integration
โ”‚       โ”‚   โ”œโ”€โ”€ App.jsx              # Root component
โ”‚       โ”‚   โ””โ”€โ”€ main.jsx             # Entry point
โ”‚       โ”œโ”€โ”€ index.html
โ”‚       โ”œโ”€โ”€ vite.config.js
โ”‚       โ””โ”€โ”€ package.json
โ”‚
โ”œโ”€โ”€ data/
โ”‚   โ”œโ”€โ”€ fetch_data.py               # Stock data fetching
โ”‚   โ”œโ”€โ”€ visualize.py                # Data visualization
โ”‚   โ”œโ”€โ”€ raw/                        # Raw data storage
โ”‚   โ”œโ”€โ”€ processed/                  # Processed data
โ”‚   โ””โ”€โ”€ visualizations/             # Charts and graphs
โ”‚
โ”œโ”€โ”€ models/
โ”‚   โ”œโ”€โ”€ prepare_data.py             # Feature engineering
โ”‚   โ”œโ”€โ”€ linear_model.py             # Linear Regression
โ”‚   โ”œโ”€โ”€ rf_model.py                 # Random Forest
โ”‚   โ”œโ”€โ”€ xgb_model.py                # XGBoost
โ”‚   โ”œโ”€โ”€ lstm_model.py               # LSTM Neural Network
โ”‚   โ””โ”€โ”€ compare_models.py           # Model comparison
โ”‚
โ”œโ”€โ”€ sentiment/
โ”‚   โ”œโ”€โ”€ news_scraper.py             # News article scraping
โ”‚   โ”œโ”€โ”€ sentiment_analyzer.py       # Sentiment analysis
โ”‚   โ””โ”€โ”€ merge_sentiment.py          # Data integration
โ”‚
โ”œโ”€โ”€ portfolio/
โ”‚   โ””โ”€โ”€ simulator.py                # Portfolio simulation
โ”‚
โ”œโ”€โ”€ risk/
โ”‚   โ”œโ”€โ”€ volatility.py               # Volatility calculations
โ”‚   โ””โ”€โ”€ confidence.py               # Confidence intervals
โ”‚
โ”œโ”€โ”€ requirements.txt                # Python dependencies
โ”œโ”€โ”€ .gitignore                      # Git ignore rules
โ””โ”€โ”€ README.md                       # This file

๐ŸŽฏ API Endpoints

Prediction

POST /api/predict
Content-Type: application/json

{
  "symbol": "AAPL"
}

Response:
{
  "symbol": "AAPL",
  "company_name": "Apple Inc.",
  "current_price": 230.45,
  "currency": "$",
  "predictions": [
    {
      "model": "Linear Regression",
      "prediction": 232.10,
      "change": 0.72
    },
    ...
  ]
}

๐Ÿ”ง Configuration

Backend Configuration

Edit app/backend/app.py:

  • Port: Default 5000
  • Debug mode: True for development

Frontend Configuration

Edit app/frontend/vite.config.js:

  • Port: Default 3000
  • Proxy: Routes /api/* to backend

๐Ÿ“ˆ Model Performance

Based on AAPL stock data (2020-2026):

Model MAE RMSE Type
Linear Regression 2.5 3.1 Simple
Random Forest 1.8 2.4 Ensemble
XGBoost 1.6 2.1 Gradient Boosting
LSTM 1.4 1.9 Deep Learning

Lower values indicate better performance

๐Ÿค Contributing

Contributions are welcome! Please follow these steps:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

๐Ÿ“ License

This project is licensed under the MIT License - see the LICENSE file for details.

๐Ÿ™ Acknowledgments

Libraries & Frameworks

Data Sources

Inspiration & Resources

  • Financial machine learning research papers
  • Kaggle stock prediction competitions
  • Time series forecasting methodologies
  • Sentiment analysis in financial markets

Special Thanks

  • The open-source community for amazing tools and libraries
  • Contributors and testers
  • Stack Overflow community for troubleshooting help

๐Ÿ‘จโ€๐Ÿ’ป Author

Kushagra Bhardwaj

๐Ÿ“ž Support

For support, questions, or feedback:

  • Open an issue on GitHub

๐Ÿ”ฎ Future Enhancements

  • Real-time WebSocket updates
  • Advanced portfolio optimization
  • Technical indicators (RSI, MACD, etc.)
  • Multi-timeframe analysis
  • User authentication and saved portfolios
  • Email alerts for price targets
  • Mobile app (React Native)
  • Cryptocurrency support
  • Options pricing models

โš ๏ธ Disclaimer

This application is for educational and informational purposes only. It is not financial advice.

  • Stock predictions are based on historical data and machine learning models
  • Past performance does not guarantee future results
  • Always do your own research before making investment decisions
  • Consult with a qualified financial advisor for investment advice
  • The developers are not responsible for any financial losses

If you find this project helpful, please give it a โญ on GitHub!

About

AI-powered stock price prediction platform using ML models (Linear Regression, Random Forest, XGBoost, LSTM). Features real-time data, sentiment analysis, and interactive visualizations for global markets.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors