Search this site
Embedded Files
Usama Usman
  • Home
  • About
  • Projects
  • Blog
  • Contact
Usama Usman
  • Home
  • About
  • Projects
  • Blog
  • Contact
  • More
    • Home
    • About
    • Projects
    • Blog
    • Contact

Stock Price Prediction - LSTM

Introduction
2 - Programming Language and Libraries
3 - Data
4 - Project
Load data and EDA
Preparing the data for the training
Creating the model
Predicting and evaluating the model
Predicting the next day
5 - Conclusion

Introduction

Stock price prediction is the process of using historical data to predict future stock prices. It is a complex and challenging task, as stock prices are often volatile and can be affected by a variety of factors, including economic news, company announcements, and investor sentiment. 

There are a number of different methods that can be used for stock price prediction, each with its own advantages and disadvantages. One of these methods is Long short-term memory (LSTM) is a type of recurrent neural network (RNN) that is commonly used for natural language processing (NLP) and time series prediction. And in this project, we will predict Aramco's Stock Price using LSTM. 

2 - Programming Language and Libraries

  • Python 

  • yfinance library

  • TensorFlow library

  • Deep Learning

  • LSTM 

3 - Data

In this project I used yfinance library,  It's an open-source tool that uses Yahoo's publicly available APIs to get historical financial data. Yfinance is a powerful tool that can be used to research investments, track market performance, and build trading strategies. 

4 - Project

  • Load data and EDA

I imported yfinaance library to get historical and most recent data. In this project I choose Aramco Stock, the company was listed three years ago on 12/2019. The data that is available in this project is from 2019 to the date I publish this project at the end of May 2023. 

  • Preparing the data for the training

We filtered the data only to include the Closing Price column, then we split the data by creating a training dataset. After that, we scaled and transformed the data from 0 to 1.

In order to insert the data into the training we need to reshape the data into certain dimensions that would be accepted by deep learning algorithms.


  • Creating the model

We created the model by importing keras and loading the related libraries. Then we fitted the data with the appropriate input to extract the best values from the training data.

 Images source wikipedia

A typical LSTM model consists of three main components: an input gate, a forget gate, and an output gate. These gates are responsible for controlling the flow of information inside the LSTM cell, which is the basic unit of computation. 

  • Predicting and evaluating the model

As we did with the training data, we also here prepare the test data for the proper shape then we predict and used the RMSE metric to evaluate the model. 

After We predict the data, now we plot the data.

As we can see in the plot, the model performed well and captured the trend the pattern in the data

  • Predicting the next day 

We tried to predict the the next day's price using the model.

The result was impressive and different was a few Halalas in SAR.  

5 - Conclusion

LSTM is a powerful technique for predicting stock price based on historical data. It can capture the complex patterns and trends in the stock market and handle the sequential nature of the data. LSTM has a unique structure that consists of three gates and a cell state, which enable it to remember and forget information over long periods of time. LSTM can be trained using various loss functions and output layers to produce accurate forecasts. LSTM is one of the most popular and effective methods for stock price prediction, and it has many applications and benefits for investors and traders. 

  • For more about the project visit GitHub

Google Sites
Report abuse
Google Sites
Report abuse