0% found this document useful (0 votes)
7 views

Stock Prediction

The document discusses using an LSTM algorithm to predict stock prices. It provides background on the motivation for accurate stock prediction and surveys related literature and their drawbacks. The objective is to preprocess data for an LSTM model and construct and optimize an LSTM neural network architecture to improve price forecasting accuracy.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

Stock Prediction

The document discusses using an LSTM algorithm to predict stock prices. It provides background on the motivation for accurate stock prediction and surveys related literature and their drawbacks. The objective is to preprocess data for an LSTM model and construct and optimize an LSTM neural network architecture to improve price forecasting accuracy.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 27

Stock

Prediction
using LSTM algorithm
V.S.S.Sriannaamalai 2021503564
S.Nithishkumar 2021503530
B.Vignesh 2021503714
Motivation
The accurate prediction of stock prices has a significant role to play in the present
economic world.

However, stocks have an ever-changing nature coupled with a risk factor that always
seems much of a gamble, making it worthwhile for researchers to analyze them with
machine learning algorithms.

We thus seek to develop a machine-based model replacing the traditional yet


unreliable time-series forecasting to predict the stocks from the past historical data of
a firm and to uncover the underlying patterns to improve the accuracy of the prediction
of the model.
Literature Survey
Paper Year Author Proposed Work Drawback

In stock prediction,
Proposes a prediction where data can be
system based on highly nonlinear,
Stock Market Prediction Sadia, K. Hiba,
Machine Learning SVM's reliance on
Using Machine Learning 2019 Aditya Sharma,
algorithm Support Vector linear boundaries
Algorithms. Adarrsh Paul
Machine (SVM) and might not capture
Random Forest Classifier complex patterns
effectively.

Logistic regression
A Logistic Regression
assumes a linear
based model using
A new approach of stock Gong, Jibing, relationship between
feature index values and
price prediction based on 2009 and Shengtao the independent
significant time-
logistic regression model. Sun variables and the log-
effectiveness has been
odds of the
proposed
dependent variable.
Literature Survey
Paper Year Author Proposed Work Drawback

KNN requires storing


A prediction model
the entire training
where they measure the
Khan, W., M. A. dataset in memory,
Predicting trend in stock best algorithm before
2016 Ghazanfar, M. making it
market exchange and after applying the
Asam, A. Iqbal computationally
Principal Component
expensive, especially
Analysis (PCA)
for large datasets.

ANNs are prone to


Customize the features in overfitting, especially
Deepak, Raut ANN and then it is tested when the model
Machine learning approach in
2017 Sushrut, Shinde on the Support Vector capacity (number of
stock market prediction
Isha Uday Machine (SVM), which is parameters) is high
a binary classifier. relative to the amount
of training data.
Literature Survey
Paper Year Author Proposed Work Drawback

They evaluate the model CNN can overfit the


Selvin,
performance based on training data and
Sreelekshmy, R.
percentage error. They feature selection for
Stock price prediction using Vinayakumar, E.
2017 train their model on the CNN is also critical.
CNN-sliding window model Gopalakrishnan,
Infosys' stock prices and Poor feature selection
Vijay Krishna
can predict the stock can lead to ineffective
Menon
prices of TCS and Cipla. predictions.

Get a dividend gain in Overlook subtle


Nelson, David
predicting the price but patterns or fail to
Stock market's price MQ, Adriano CM
can increment it if predict sudden shifts
movement prediction with 2017 Pereira, and
variance could be less in market dynamics.
LSTM neural networks. Renato A. de
and make the LSTM LSTM models can be
Oliveira
model perform well. implemented better.
Literature Survey
Paper Year Author Proposed Work Drawback

Combined the
historical data
SVM performance can be
with the
sensitive to the choice of the
sentiments like
Nayak, kernel and the regularization
Prediction news/tweets of a
Aparna, MM parameter. Selecting
models for company.This
2016 Manohara Pai, appropriate values for these
Indian stock type of dataset,
and Radhika parameters can require
market Decision Tree
M. Pai extensive tuning and cross-
performs better
validation, which can be
than Logistic
computationally expensive.
Regression and
SVM.
Limitations KNN
149
LSTM model is the best proposed model Decision tree
as it can depict the near representation 59
Linear
of predicted values from the actual
Regression
stock price value and has the least
54
RMSE value.
LSTM
21.83
Whereas Linear Regression, Decision
Tree and KNN cannot predict the prices
as accurately as LSTM.

RMSE VALUES
Objective
01. Preprocess the data to handle missing values,
normalize the features, and create appropriate
input sequences for the LSTM model.

02. Construct LSTM-based neural network


architecture for stock price forecasting, optimizing
hyperparameters for improved accuracy.

03. Evaluate the model's performance on a separate


validation or test dataset to assess its ability to
generalize to unseen data.
.
Dataset - General features
01. 02. 03.
DATE gives the date OPEN is the opening price at HIGH represents the highest price
corresponding to which the stock which the market opens, i.e., the at which the stock has reached on
prices are stored.. price for which the first trading the given day.
executes.

04. 05. 06.


CLOSE is the closing price, ADJ CLOSE price is the price that is
LOW represents the most quoted by the data provider after
and it is the most crucial price as
economical value at which the reviewing any corporate actions
it is the closing price for the given
stock has concluded on the day. . like dividends or stock splits.
period.
Architecture Diagram
Methodologies
Data Preprocessing

Scaling
Slidingwindow
approach Labeling
Splitting of dataset
Input Dataset
Scaling
Scale the features to a range suitable for the activation function of the neural network.

Commonly, the Min-Max scaling method is used to scale the features between 0 and 1.

Scaling ensures that each feature contributes equally to the model's learning process
and prevents features with larger magnitudes from dominating the model.
Sliding window approach labelling
Convert the time series data into input-output pairs suitable for training a sequence
prediction model like LSTM.

In the sliding window approach, you create input sequences (X) and corresponding
output labels (y) by sliding a window of a fixed size over the time series data.

For example, if you're using a window size of 60 time steps, each input sequence
contains the historical values of the selected features for the past 60 time steps,
and the corresponding output label is the value of the target feature at the next
time step.

This process effectively converts the time series data into a supervised learning
problem.
Splitting of dataset

We distribute the dataset in the training phase and in the testing


phase, where 80% of the data goes to the training phase and
20% of the data goes to the testing phase.

In the training phase, the model gets coached on the data and
then the testing data gets tested on the trained model so that it
can predict the stock price more accurately
Methodologies

LSTM Model
Building model
Compiling model
Evaluating model
.
LSTM
LSTM stands for Long Short Term Memory is a deep
neural network..
01. Input Gate
In LSTM, the hidden layers that generally all neural
network uses are replaced with memory cells, a
series of gates. 02. Forget Gate
These gates decide whether to pass the detailed
information to the next cell or ignore it. There are
three gates in LSTM 03. Output Gate
Memory cells containing gates

01. 02. 03.


At forget gate the input is Input gate operates on the same At output gate, the input and
combined with the previous signals as the forget gate, but previous state are gated as
output to generate a fraction here the objective is to decide before to generate another
between 0 and 1, that determines which new information is going to scaling fraction that is combined
how much of the previous state enter the state of LSTM. The with the output of tanh block that
need to be preserved . An output of the input gate (again a brings the current state. This
activation output of 1.0 means fraction between 0 and 1) is output is then given out. The
“remember everything” and multiplied with the output of tan output and state are fed back into
activation output of 0.0 means h block that produces the new the LSTM block.
“forget everything.” values
C0mpiling Model
The loss function, also known as the cost function or objective function, quantifies the
difference between the predicted output of the model and the actual target values.
Its purpose is to measure how well the model is performing on a given task.

MSE is one of the most commonly used loss functions in regression tasks, including
stock price prediction. It calculates the average squared difference between the
predicted values and the true values.
C0mpiling Model
Backpropagation is used to update the weights of the neural network in order to
minimize the loss function. Gradients of the loss with respect to the model's
parameters are computed and used to adjust the weights through gradient descent
optimization algorithms like Adam

Adam (Adaptive Moment Estimation) is an optimization algorithm commonly used to


update the parameters of a neural network during training
Implementation
We have employed Keras library to implement the LSTM model, which works
sequentially, which means layers are sequentially added one after the other.

Consequently, we have used four layers of the LSTM model in which the first two
layers take the input of 50 set.

The third layer, usually known as the "Dense" layer, serves as the connection between
the second layer and the next Dense layer, which is the output layer

Ultimately, for compiling the model, we consider the two parameters – Adam
optimizer and loss function as mean square error
Evaluation Graph

By using the LSTM model the predicting stock values ( represented using orange colour) are almost
accurately equal to the valid value which is represented using red colour
Contributions
Sriannaamalai - Built and trained the model

Nithishkumar - Data visualization and evaluation

Vignesh - Data preprocessing


Thank
you very
much!

You might also like