Skip to content

charanachanta2/Stock-Prediction-System

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Stock Prediction System using LSTM, Fuzzy Logic, and Genetic Algorithm

Project Overview

The Stock Prediction System is a Soft Computing project designed to forecast stock market trends and prices by combining the strengths of three intelligent computing techniques:

  • Long Short-Term Memory (LSTM) Neural Networks
  • Fuzzy Logic (Fuzzy Sets)
  • Genetic Algorithms (GA)

Traditional statistical models often struggle with the nonlinear and uncertain nature of financial markets. This project leverages Soft Computing techniques to improve prediction accuracy and handle uncertainty effectively.


Objectives

  • Predict future stock prices using historical market data.
  • Handle uncertainty and imprecise market conditions using Fuzzy Logic.
  • Optimize model parameters using Genetic Algorithms.
  • Provide a scalable and web-integrated prediction platform.

Technologies Used

Machine Learning & AI

  • TensorFlow
  • Keras
  • NumPy
  • Pandas
  • Scikit-learn

Soft Computing Techniques

  • LSTM Neural Networks
  • Fuzzy Sets and Fuzzy Inference System
  • Genetic Algorithm (GA)

Web Technologies

  • Flask (Backend)
  • HTML
  • CSS
  • JavaScript

Visualization

  • Matplotlib
  • Plotly

Why TensorFlow?

TensorFlow was chosen because:

  1. Efficient Deep Learning Framework

    • Provides optimized implementations of LSTM networks.
    • Supports GPU acceleration for faster training.
  2. Scalability

    • Handles large stock market datasets efficiently.
  3. Production Ready

    • Easy deployment of trained models to web applications.
  4. Model Saving and Loading

    • Allows trained prediction models to be stored and reused.
  5. Strong Community Support

    • Extensive documentation and resources.

Long Short-Term Memory (LSTM)

LSTM is a specialized Recurrent Neural Network (RNN) designed to learn long-term dependencies in sequential data.

Why LSTM for Stock Prediction?

Stock prices are time-series data where previous trends influence future values.

LSTM helps by:

  • Remembering long-term patterns.
  • Avoiding the vanishing gradient problem.
  • Capturing temporal dependencies.
  • Learning market trends and fluctuations.

Inputs

  • Opening Price
  • Closing Price
  • High Price
  • Low Price
  • Volume
  • Historical Price Sequences

Output

  • Predicted Future Stock Price
  • Market Trend (Upward / Downward)

Fuzzy Logic Integration

Financial markets contain uncertainty and ambiguity that cannot always be represented using exact mathematical values.

Fuzzy Logic allows the system to reason using linguistic variables such as:

  • Low Risk
  • Medium Risk
  • High Risk

Example Fuzzy Rules

IF Volume is High AND Trend is Rising THEN Buy Signal is Strong

IF Volatility is High AND Confidence is Low THEN Risk is High

Benefits

  • Handles uncertain market behavior.
  • Improves interpretability.
  • Provides risk assessment alongside predictions.

Genetic Algorithm (GA)

Type of GA Used

Real-Valued Genetic Algorithm (RVGA)

Instead of binary chromosomes, real-valued chromosomes were used because stock prediction parameters are continuous values.

Why Real-Valued GA?

  • Faster convergence.
  • Better optimization of neural network parameters.
  • Reduced computational complexity.
  • Suitable for continuous optimization problems.

GA Components

Chromosome Representation

Each chromosome contains:

  • Learning Rate
  • Number of LSTM Units
  • Dropout Rate
  • Batch Size
  • Window Size

Example:

[0.001, 128, 0.2, 64, 60]


Fitness Function

The fitness score is calculated using:

  • Mean Squared Error (MSE)
  • Root Mean Squared Error (RMSE)
  • Prediction Accuracy

Lower error corresponds to higher fitness.


Selection Method

Tournament Selection

Reason:

  • Maintains population diversity.
  • Reduces premature convergence.
  • Simple and effective for optimization.

Crossover Method

Arithmetic Crossover

Reason:

  • Works naturally with real-valued parameters.
  • Produces smoother offspring solutions.
  • Preserves useful traits from parents.

Mutation Method

Gaussian Mutation

Reason:

  • Introduces controlled randomness.
  • Helps escape local optima.
  • Enhances exploration of search space.

Role of GA in the Project

The Genetic Algorithm automatically optimizes:

  • LSTM Hyperparameters
  • Training Parameters
  • Feature Selection
  • Prediction Performance

This eliminates the need for manual tuning and improves model accuracy.


System Architecture

  1. Historical Stock Data Collection
  2. Data Preprocessing
  3. Feature Engineering
  4. Fuzzy Logic Evaluation
  5. Genetic Algorithm Optimization
  6. LSTM Model Training
  7. Stock Prediction
  8. Result Visualization
  9. Web Application Deployment

Web Integration Benefits

Integrating the prediction system with a web application provides several advantages:

Real-Time Accessibility

Users can access predictions from anywhere using a browser.

Interactive Dashboards

Display:

  • Predicted Prices
  • Historical Trends
  • Risk Levels
  • Buy/Sell Signals

Centralized Model Deployment

The trained AI model runs on the server, eliminating the need for local installations.

Multi-User Support

Multiple users can access the prediction platform simultaneously.

Automated Updates

The system can automatically fetch new market data and generate updated predictions.

Scalability

Future features can include:

  • Portfolio Management
  • Personalized Recommendations
  • News Sentiment Analysis
  • Cryptocurrency Prediction
  • Real-Time Market Monitoring

Expected Outcomes

  • Improved stock price prediction accuracy.
  • Better handling of uncertainty through Fuzzy Logic.
  • Automated hyperparameter optimization using Genetic Algorithms.
  • User-friendly web-based prediction platform.
  • Enhanced decision-making support for investors.

Future Enhancements

  • Transformer-based Deep Learning Models
  • Reinforcement Learning Trading Agents
  • Real-Time API Integration
  • Multi-Stock Prediction
  • News and Social Media Sentiment Analysis
  • Mobile Application Support
  • Explainable AI (XAI) Integration

Conclusion

This project demonstrates the power of Soft Computing by combining LSTM, Fuzzy Logic, and Genetic Algorithms into a unified stock prediction framework. LSTM captures temporal patterns in stock prices, Fuzzy Logic manages uncertainty in market conditions, and Genetic Algorithms optimize model performance. The integration of these techniques results in a robust, intelligent, and scalable stock forecasting system that can be deployed through a web platform for real-world use.

About

The stock market is a system that changes a lot and is influenced by things like economy, politics and how people feel. Predicting stock prices is hard because the market can be unpredictable and there are ups and downs. This project wants to make a system to predict stock prices using special computer techniques focusing on deep learning.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors