- Overview
- Objectives
- Key LSTM Concepts & Novel Approach
- Methodology
- System Analysis and Design
- System Development and Key Features
- Evaluation
- Conclusion
- Contact and Code Availability
Accurate stock market forecasting is crucial for investors, traders, and financial analysts seeking to optimize returns and minimize risk. This project investigates the use of LSTM (Long Short-Term Memory)-based deep learning models for stock market trend prediction across multiple time horizons (short-, medium-, and long-term).
In the current literature, most research emphasizes short-term daily data, making it difficult to capture longer-term trends effectively. To address this gap, our project explores the potential of LSTM models trained on weekly and monthly data to capture extended market behaviors more accurately.
Key Highlights
- Investigated the effectiveness of LSTM networks for stock data in various time horizons.
- Employed extensive data pre-processing and a retraining loop to minimize prediction errors.
- Novel approach for iterative model training and evaluation ensures only high-performing models are deployed.
- Deployed a user-friendly system with real-time and batch prediction capabilities.
-
Develop an LSTM-based Deep Learning Model
Design and implement an LSTM network capable of capturing sequential dependencies in stock market data for multiple time horizons. -
Evaluate Model Performance
Assess model accuracy via RMSE, K-Fold Cross-Validation, and a custom multi-training approach that continuously retrains the model until it meets a minimal error threshold. -
Deploy a User-Friendly Prediction System
Create an interactive system that leverages trained LSTM networks to provide timely, flexible predictions, supporting real-time data feeds or user-uploaded datasets.
- Core Idea: LSTM networks address the vanishing and exploding gradient problems commonly encountered in traditional recurrent neural networks (RNNs). By introducing cell states and gates (input, forget, and output), LSTMs can learn long-term dependencies, making them well-suited for complex time series tasks such as stock market prediction.
- Why LSTM for Stock Prediction:
- Can handle varying time scales (daily, weekly, monthly data).
- Effectively captures both short-term fluctuations (volatility) and long-term trends (market cycles).
-
Multi-Horizon Focus
- Instead of relying solely on daily data, models are additionally trained on weekly and monthly aggregations. This enables the system to capture both high-frequency noise and long-range market movements.
-
Iterative Multi-Training and Evaluation
- A custom training loop evaluates a newly trained model’s predictive performance (e.g., RMSE and number of “wrong” predictions).
- If the model does not meet a predefined accuracy threshold, the training is restarted (model weights reset) until performance criteria are met.
- This ensures that only high-performing models are saved for future predictions.
-
Hybrid Validation
- Alongside traditional K-Fold Cross-Validation, the system implements a “live” test that checks actual predictions against current real data. This hybrid approach highlights real-world applicability and robust error handling.
By combining LSTM’s strength in temporal sequence modeling with a novel iterative retraining approach and longer aggregation windows, our system presents a more holistic and accurate tool for stock market forecasting.
-
Data Collection
- Historical stock market data is sourced primarily from Yahoo Finance.
- The system also allows the user to upload custom CSV files or select from existing internal datasets.
-
Data Pre-processing
- Cleaning: Handled missing values, outliers, and inconsistencies.
- Scaling: Used
sklearn.preprocessing.MinMaxScalerto normalize features into a[0,1]range, improving training stability.
-
LSTM Model Architecture
- Implemented multiple LSTM configurations using PyTorch.
- Experimented with single-layer and multi-layer LSTM networks to capture short- and long-term dependencies effectively.
-
Training and Multi-Training Approach
- Split data into training (67%) and validation/test (33%) sets.
- Monitored RMSE and number of wrong predictions. If error exceeded the threshold, the model was reset and retrained until acceptable accuracy was achieved.
-
Evaluation
- RMSE: Calculated for both training and test sets, typically every 100 epochs.
- K-Fold Cross-Validation: 5-Fold approach for robust performance estimation.
- Novel Iterative Evaluation: After training, the model is tested again on real or withheld data. If performance is unsatisfactory, retraining commences.
-
System Development
- Backend: Python (PyTorch, NumPy, Pandas) handles data pipeline, model training, and inference.
- Frontend: Built using frameworks like NiceGUI for user input, real-time visuals, and reporting.
-
Result Analysis
- Compared LSTM’s predicted vs. actual stock values.
- Found weekly/monthly-trained models often outperform daily-based ones for longer horizons.
- Demonstrated efficiency and improved accuracy through iterative training and validation.
Below is an overview of the system’s conceptual and technical layout.
Explanation:
- Showcases the data flow from raw historical stock data to the LSTM-based AI engine, and finally to the output prediction.
Functional Requirements
- Input: Users can upload CSV files (historical data) or select from existing companies/datasets.
- LSTM-Based Prediction: The system runs single-/multi-layer LSTM models for more accurate predictions.
- User Interface: Provides both tabular and graphical representations of predictions in a desktop or mobile view.
Non-Functional Requirements
- Performance: Efficient GPU-based training and inference to handle large datasets.
- Reliability: Graceful error handling with
try-exceptblocks to avoid runtime crashes. - Usability: Clear navigational flow, instructions, and results for all user experience levels.
-
AI Methods
- Data Pre-processing:
MinMaxScalerfromsklearn. - PyTorch LSTM Models: Single-/multi-layer configurations.
- Multi-Training: Automated loops to fine-tune until model error is under the threshold.
- Data Pre-processing:
-
Technical Stack
- Python for core logic.
- PyTorch for deep learning.
- Pandas/NumPy for data manipulation.
- Matplotlib for plotting predictions.
-
User Accessibility
- Responsive Web Interface for desktops and mobile.
- Options to run locally or on cloud infrastructure (AWS, or via PageKite tunnels).
-
System Complexity
- Incorporates advanced LSTM architectures (multi-layer).
- Adapts to weekly/monthly data for extended market behavior.
- Robust error handling ensures continuous operation even with invalid inputs.
Explanation:
- Example interface section where users specify the stock ticker, CSV upload, timeframe (daily, weekly, monthly), and additional training parameters.
Explanation:
- Displays actual vs. predicted stock prices, error metrics (RMSE), and future-day forecasts.
-
RMSE Tracking
- Every 100 epochs, RMSE is logged for train/test data to confirm learning progress.
-
K-Fold Cross-Validation
- 5-Fold approach to assess model consistency and generalization across different data splits.
-
Novel Iterative Evaluation
- After each training session, the system checks whether RMSE or number of wrong predictions exceed a threshold.
- If the model fails, it resets and continues training until the performance criteria are met.
-
Result Observations
- Weekly and monthly data reduce model overfitting on noise and often yield lower RMSE than daily data for extended horizons.
- Iterative retraining ensures minimal error and improved accuracy.
This project fulfills its objective to develop, deploy, and rigorously evaluate LSTM-based deep learning models for stock market prediction across multiple time horizons. We demonstrated:
- Improved long-term accuracy with weekly/monthly data, capturing extended market patterns.
- Robust multi-training and cross-validation strategies, resulting in consistent and reliable predictions.
- A novel iterative approach that resets and retrains the model until acceptable error thresholds are met.
- A user-friendly system capable of real-time or batch inference, suitable for both academic research and professional financial analysis.
Closed Source Notice
- The main codebase for this project is closed source and is not shared publicly. We welcome inquiries from interested researchers or industry professionals.
If you would like further details or access to the private repository, please contact:
- Email: [mehran.gharuni@gmail.com]
Sharing the source code may be possible upon request and under specific collaboration or licensing conditions.
Thank you for your interest in our project!



