Skip to content

m4nn2609-dot/Stock-Prediction-Model-V1

Repository files navigation

📈 Stock Market Direction Prediction

A machine learning project focused on predicting the next day's stock market direction using multiple machine learning models, backtesting, and an ensemble approach.

Note: This was my first end-to-end machine learning project. The primary goal was to understand the complete ML workflow—from data collection and preprocessing to model training, evaluation, deployment, and experimentation with different tools. While the current results are not production-ready, this project provided a strong foundation for future improvements.


🚀 Features

  • Historical stock price prediction (next-day direction)
  • Data preprocessing and feature engineering
  • Multiple machine learning models
  • LSTM-based deep learning model
  • Ensemble learning combining classical ML models and LSTM
  • Rolling window backtesting for realistic evaluation
  • Hyperparameter optimization using Optuna
  • MongoDB integration using PyMongo for storing experiment data
  • Interactive Streamlit web application
  • Modular project structure for easy experimentation

🛠️ Tech Stack

Languages

  • Python

Libraries & Frameworks

  • Pandas
  • NumPy
  • Scikit-learn
  • PyTorch (LSTM)
  • Optuna
  • Streamlit
  • PyMongo
  • Matplotlib

Database

  • MongoDB

⚙️ Workflow

  1. Collect historical stock market data.
  2. Perform preprocessing and feature engineering.
  3. Create the prediction target (next day's movement).
  4. Train multiple machine learning models.
  5. Train an LSTM model on sequential data.
  6. Tune model hyperparameters using Optuna.
  7. Combine models using ensemble learning.
  8. Evaluate performance using rolling backtesting.
  9. Store experiment information in MongoDB.
  10. Visualize predictions using a Streamlit application.

📊 Backtesting

Instead of randomly splitting the dataset, the project uses rolling window backtesting.

For every iteration:

  • Train on historical data only.
  • Predict the next unseen time period.
  • Expand the training window.
  • Repeat until the entire dataset has been evaluated.

This better simulates how a model would perform in real-world trading.


🤖 Models Used

  • Random Forest
  • XGBoost (if enabled in the project)
  • LSTM Neural Network
  • Ensemble model using probability averaging

🎯 Hyperparameter Optimization

Optuna was used to search for better hyperparameters automatically instead of relying solely on manual tuning.


🗄 Database Integration

MongoDB (via PyMongo) was used to store model-related information and experiment data, making it easier to keep track of different training runs.


🌐 Streamlit Application

A simple Streamlit interface was created to make predictions easier to visualize and interact with.


📚 What I Learned

This project helped me understand:

  • Structuring an end-to-end machine learning project
  • Data preprocessing pipelines
  • Time-series prediction basics
  • Rolling window backtesting
  • Ensemble learning
  • Hyperparameter optimization with Optuna
  • Working with MongoDB from Python
  • Building simple ML applications with Streamlit
  • Organizing larger Python projects

⚠️ Current Limitations

Since this was my first machine learning project, there are several areas that can be improved:

  • Limited feature engineering
  • Basic LSTM architecture
  • Simple ensemble strategy
  • No advanced financial indicators
  • Limited experimentation with modern forecasting models
  • Performance is not suitable for real trading decisions

🔮 Future Improvements

Some improvements I plan to implement include:

  • Better feature engineering using technical indicators
  • Transformer-based time-series models
  • Attention mechanisms
  • More advanced ensemble techniques
  • Walk-forward optimization
  • Better risk management metrics
  • Portfolio-level prediction instead of single-stock prediction
  • Automated experiment tracking
  • Docker support
  • CI/CD pipeline
  • Cloud deployment
  • Explainable AI (SHAP/LIME)
  • Better visualization dashboard

💡 Motivation

Rather than building a perfect prediction model, the objective of this project was to gain hands-on experience with the complete machine learning development lifecycle.

It served as a learning project that introduced me to model training, evaluation, optimization, deployment, databases, and practical software organization.

I plan to revisit this project in the future and apply the knowledge I gain as I continue learning machine learning and deep learning.


📄 License

This project is intended for educational purposes.

It should not be used as financial or investment advice.

About

Just learning about stocks and machine learning through basic projects

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors