Skip to content

A hybrid AI-based stock market prediction system using LSTM, Random Forest, and XGBoost, built for real-world deployment with Optuna-powered tuning, feature-rich engineering, and ensemble prediction logic. Designed to optimize F1 score and accuracy, this system aims to generate reliable buy/sell signals on stocks.

License

Notifications You must be signed in to change notification settings

AaravMehta-07/LSTM-Random-Forest-XGBoost-Stock-Predictor-with-Optuna

Repository files navigation

LSTM-Random-Forest-XGBoost-Stock-Predictor-with-Optuna

A hybrid AI-based stock market prediction system using LSTM, Random Forest, and XGBoost, built for real-world deployment with Optuna-powered tuning, feature-rich engineering, and ensemble prediction logic. Designed to optimize F1 score and accuracy, this system aims to generate reliable buy/sell signals on stocks. still work under progress

πŸ“ˆ LSTM + Random Forest + XGBoost Stock Predictor


πŸš€ About the Project

This project integrates:

  • πŸ” Recurrent Neural Networks (LSTM) for sequential financial patterns
  • 🌲 Random Forest for ensemble-based classification
  • ⚑ XGBoost for gradient boosting decision trees
  • 🎯 Optuna for automatic hyperparameter tuning (optional mode)
  • πŸ“Š Backtesting Module to simulate trading performance

βš™οΈ Built by a Computer Engineering student to demonstrate real-world ML/AI skills in finance and time series prediction.


πŸ“Œ Features

  • βœ”οΈ Ensemble of 3 models: LSTM + RF + XGBoost
  • βœ”οΈ Flag-based retraining (no need to retrain every time)
  • βœ”οΈ Real stock data from Yahoo Finance
  • βœ”οΈ Feature-rich engineering: RSI, Moving Averages, Volatility, Volume
  • βœ”οΈ Backtesting for historical performance validation
  • βœ”οΈ Soft voting for final trade signal (BUY / SELL)
  • βœ”οΈ CLI-based output, no GUI bloat
  • βœ”οΈ Saved model reuse (models/ folder)

🧠 Technologies Used

Category Stack
Language Python 3.10
ML Models RandomForestClassifier, XGBClassifier
Deep Learning TensorFlow / Keras LSTM
Optimization Optuna
Data Source yfinance
Indicators RSI, MA5/10/20, Volatility, Volume

πŸ“‚ Project Structure

LSTM-RandomForest-XGBoost-Stock-Predictor/ β”œβ”€β”€ LSTM+Random Forest+XGboost Stock Predictor.py β”œβ”€β”€ LSTM+Random Forest+XGboost Stock Predictor with optuna.py β”œβ”€β”€ backtest.py β”œβ”€β”€ models/ # Contains saved models β”œβ”€β”€ README.md β”œβ”€β”€ LICENSE # MIT License


πŸ§ͺ How to Run

βœ… 1. Install Dependencies

pip install -r requirements.txt If no requirements.txt, install manually pip install yfinance numpy pandas scikit-learn xgboost tensorflow optuna


βœ… 2. Run Prediction Scripts

Without Optuna (default hyperparameters):

python "LSTM+Random Forest+XGboost Stock Predictor.py"

With Optuna (automatic tuning):

python "LSTM+Random Forest+XGboost Stock Predictor with optuna.py"


βœ… 3. Backtest the System

python backtest.py This will simulate trades and give statistics based on past 3 years of stock data.


πŸ“Š Output Example

πŸ“ˆ Processing RELIANCE... βœ… Trained RF | Accuracy: 0.72 | F1: 0.75
βœ… Trained XGB | Accuracy: 0.74 | F1: 0.77
βœ… Trained LSTM | Accuracy: 0.76 | F1: 0.79
πŸ”Ž RF Signal: BUY
πŸ”Ž XGB Signal: BUY
πŸ”Ž LSTM Signal: SELL
🟒 Final Signal: BUY


🧠 Why This Project Matters

βœ… Real-world applicability
βœ… Combines traditional ML and DL
βœ… Good F1/accuracy across multiple models
βœ… Shows model saving, loading, and production-like behavior
βœ… Demonstrates ability to tune, backtest, and validate system performance


πŸ“œ License

This project is licensed under the MIT License.


πŸ‘¨β€πŸ’» Author

Aarav Vinayak Mehta B.Tech Integrated Computer Engineering
MPSTME, NMIMS Mumbai Campus


πŸ™‹β€β™‚οΈ Want to Hire Me?

If you're a company looking for a student with real-world skills in AI, ML, and applied engineering β€” this is just the start. Let's connect on LinkedIn or drop me a message!

About

A hybrid AI-based stock market prediction system using LSTM, Random Forest, and XGBoost, built for real-world deployment with Optuna-powered tuning, feature-rich engineering, and ensemble prediction logic. Designed to optimize F1 score and accuracy, this system aims to generate reliable buy/sell signals on stocks.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages