Batch 13 Report 3
Batch 13 Report 3
Batch 13 Report 3
PREDICTION USING
LSTM AND BERT
Submitted by
degree of
BACHELOR OF TECHNOLOGY
in
ARTIFICIAL
INTELLIGENCE AND
DATA SCIENCE
i
Dr. MAHALINGAM COLLEGE OF
ENGINEERING AND
TECHNOLOGY
An Autonomous Institution
Affiliated to ANNA
UNIVERSITY CHENNAI - 600
025
MAY-2023
i
Dr. MAHALINGAM COLLEGE OF ENGINEERING
AND TECHNOLOGY, POLLACHI -642 003
BONAFIDE CERTIFICATE
Certified that this Mini project report titled “STOCK MARKET PREDICTION
USING LSTM AND BERT” is the bonafide work of
ii
Submitted for the Autonomous End Semester Examination Project Viva-voce
held on
iv
ACKNOWLEDGEMENT
gratitude to our institution and our department for providing us a chance to fulfil our
Principal and Deans of our college, for his constant motivation and continual
Incharge, Artificial Intelligence and Data Science, for her direction delivered at all times
required. We also thankher for her tireless and meticulous efforts in bringing out this
Professor/AD for her constant support and guidance offered to us during the course of
our project by being one among us and all the noble hearts that gave us immense
AP(SS) & Mrs. Thelungu Laxmi AP for their continuous support and guidance.
v
ABSTRACT
Abstract: The stock market is a venue for people to buy and sell their stocks. This
background involves risk and the goal is to maximize the profit and minimize the
losses to maximum extent. And to make this possible they try to predict stock
prices but, predicting the stock prices is a hectic job and involves large amount of
risk. But this can be uncovered by using some deep learning and machine learning
techniques. The techniques include the machine learning’s BERT and deep
learning’s LSTM. In this paper we suggest a hybrid model of the LSTM (Long
Short Term Memory) and BERT (Bi-directional Encoder Representations from
Transformers). BERT model is a Transformer based model and is able to
understand the contextual meaning of the data and capture complex relationships
and LSTM model is a type of RNN (Recurrent Neral Network) that is commonly
used for time series forecasting. LSTM has the potential to capture the long-term
dependencies in the data making it suitable for analyzing and predict stock market
trends. The hybrid model of BERT and LSTM combines the strengths of both the
model to improve the accuracy in stock market price prediction. Values that
evolve in the data are open, close ,high ,low and volume .
vi
TABLE OF CONTENTS
2 LITERATURE SURVEY 3
3 PROBLEM STATEMENT 6
4 OBJECTIVE OF THE PROJECT 7
5 EXISTING MODEL 8
6 PROPOSED MODEL 10
7 SOFTWARE DESCRIPTION 14
1 REFERENCES 19
1
1 APPENDIX 20
2
A. SOURCE CODE
B. SCREENSHOT 25
C. COURSE COMPLETION 26
CERTIFICATES
vi
D. CONTEST PARTICIPATION 30
E. PLAGIARISM REPORT 34
vi
LIST OF FIGURES
ix
LIST OF ABBREVIATIONS
BERT Bidirectional-Encoder
Representations from
Transformers
x
CHAPTER 1
INTRODUCTION
2
contextual linkages inside text. Considering the impact of sentiment and news on
stock prices, BERT can offer insightful information that enhances more
comprehensive prediction models. A special advantage in stock market prediction is
provided by combining LSTM and BERT. BERT can handle the qualitative
component by extracting sentiment, whereas LSTM concentrates on the quantitative
side by evaluating past stock prices and other numerical data. and background from
written materials. With a wider range of factors influencing stock prices captured,
projections may be more accurate as a result of this combination. With the help of
both LSTM and BERT, this study seeks to create a hybrid model that can forecast
stock market movements. The strategy will evaluate textual data, such as financial
news and social media sentiment, to comprehend external factors that can effect
stock prices. Meanwhile, LSTM will be used to analyze consecutive stock price
data, finding patterns and trends. We intend to combine these two models to produce
a reliable and efficient stock market forecast system. If this project is completed
successfully, investors and financial institutions may benefit practically by having a
more precise tool for estimating stock prices and selecting investments. This project
also intends to demonstrate the potential of hybrid models in stock market
prediction, contributing to the ongoing research in the field of financial machine
learning.
3
CHAPTER 2
LITERATURE SURVEY
"Optimizing LSTM for stock market prediction in India stock market "
Authors: Anita Yadav, C K Jha, Aditi Sharan . Published: 2019
An LSTM model was designed and a dataset sourced from the Indian stock market
was created for this study. Then, by contrasting stateful and stateless models and
adjusting for the number of hidden layers, it was optimized.
5
data from the NASDAQ-100 index stocks and news items from the New York
Times to assess the performance of the MLP, LSTM, and FinBERT-LSTM models.
6
CHAPTER 3
PROBLEM STATEMENT
Predicting the performance of the stock market is difficult because of its inherent
volatility and the intricate relationships between its many affecting elements. A
variety of factors, including business performance, industry developments,
geopolitical events, investor attitude, and economic indicators, influence stock
prices. Conventional prediction techniques, such technical and fundamental analysis,
frequently depend on human interpretation and may have biases or scope
restrictions. Furthermore, these techniques might not be able to capture the complex
patterns and abrupt changes in the market that result from breaking news, opinions
expressed on social media, or worldwide trends. The main issue is the requirement
for a reliable prediction model that can take into consideration the qualitative (like
financial news, market sentiment, and economic developments) as well as the
quantitative (like historical price trends, trading volumes, and technical indicators)
aspects of stock market data. To tackle this issue, a method that blends sentiment
and news context with sequential analysis of stock prices is needed. While useful in
certain situations, current machine learning models frequently concentrate on one
kind of data qualitative or quantitative—which results in imprecise or insufficient
predictions. Accurate stock market predictions need to be made using a hybrid
technique that incorporates both kinds of data. In order to close this gap, this
research is creating a model that mixes Bidirectional Encoder Representations from
Transformers (BERT) is used for text-based sentiment analysis, and Long Short-
Term Memory (LSTM) networks are used for time series analysis.
7
CHAPTER 4
OBJECTIVE OF THE
PROJECT
The principal aim of this project is to create a hybrid stock market prediction model
that enhances the accuracy of stock price forecasts by integrating LSTM and BERT.
The following are some ways that the model hopes to take advantage of both LSTM
and BERT's strengths:
Sequential Analysis with LSTM: Apply LSTM to examine past stock prices and
other numerical data so that long-term relationships can be captured and patterns or
trends can be recognized. This part addresses the time series character of stock prices
and concentrates on the quantitative side of stock market prediction.
Contextual Understanding with BERT: Employ BERT to evaluate textual
information from press releases, social media posts, and financial news stories in
order to determine market sentiment and significant events that may have an effect on
stock prices. This part concentrates on the qualitative side, including more
background information and comprehension of outside variables affecting stock
values.
8
CHAPTER 5
EXISTING MODEL
FIGURE:5.1
1
CHAPTER 6
PROPOSED SYSTEM
1
DATA COLLECTION: Gathering historical stock prices, trade volumes, and
technical indicators is known as technical data collection. While textual data is
gathered from news stories, social media, and other sources that could impact stock
values, data usually consists of daily or hourly prices.
DATA PREPROCESSING: Technical Data Preprocessing: Creating time-series
sequences for LSTM, addressing missing values, and normalizing stock price data to
a consistent scale. Tokenizing and cleaning the textual data are steps in the textual
data preprocessing process. Typical procedures involve eliminating special
characters, stopwords, and tokenizing text to create BERT tokens or subwords.
MODEL DEVELOPMENT: To process the technical data, an LSTM model is
built by the LSTM Model portion of the code. One or more LSTM layers may be
part of the architecture, with dense (completely connected) layers coming next to
produce predictions.Initializing a BERT model to process textual data is covered in
the BERT Model section. Usually, the BERT model is optimized for contextual
understanding or sentiment analysis.
INTEGRATION: The results from the BERT and LSTM models are combined in
this stage. To generate the stock market prediction, the combined output is sent into
a final prediction layer (like a dense layer).
MODEL TRAINING: Using the training data, the combined model is trained
during the training process. It entails defining the optimizer, loss function, and
training parameters, such as epochs and batch size. To keep an eye on performance
and prevent overfitting, the model is verified against a validation dataset throughout
training.
RESULT AND ANALYSIS: The outcome is anticipated, and the model is assessed.
To overcome the shortcomings of previous models, this project's suggested model
mixes Long Short-Term Memory (LSTM) networks with Bidirectional Encoder
1
Representations from Transformers (BERT). To provide a more thorough approach
1
to stock market prediction, the suggested model integrates both qualitative and
quantitative data.
LSTM Component
The LSTM component of the model focuses on analyzing historical stock price data,
capturing long-term dependencies, and identifying patterns in price movements.
LSTM networks are well-suited for time series data, as they can retain memory of
past states and adapt to new patterns. In this project, LSTMs are used to analyze
various stock-related metrics, including closing prices, trading volumes, and
technical indicators, to generate predictions based on historical trends.
BERT Component
The BERT component addresses the qualitative aspect of stock market prediction by
processing textual data from financial news articles, social media, and other relevant
sources. BERT, a transformer-based model, is pre-trained to understand context and
relationships within text, allowing it to extract sentiment and key information from
textual sources. This component is crucial for capturing broader contextual factors
that might impact stock prices, such as economic news, company announcements, or
geopolitical events.
Integration and Prediction
To produce stock market predictions, the suggested model combines the results from
the BERT and LSTM components. The goal of merging quantitative and qualitative
data is to enhance the accuracy and resilience of the model. Combining the
contextual insights from BERT with the sequential patterns found by LSTM is the
integration process. With a wider range of parameters taken into account, the model
may be able to anticipate stock prices more accurately as a result of this
combination. The suggested model aims to address the shortcomings of the current
1
models by employing
1
this hybrid approach, offering a more thorough and dependable technique for stock
market prediction. The goal of the experiment is to show how combining LSTM and
BERT can increase prediction accuracy and provide fresh perspectives on stock
market fluctuations.
1
CHAPTER7
SOFTWARE DESCRIPTION
1
CHAPTER 8
The stock market prediction project using Long Short-Term Memory (LSTM)
networks and Bidirectional Encoder Representations from Transformers (BERT) is
presented in this part. This project's main goal was to increase the accuracy of stock
market predictions by combining technical and qualitative (textual) data sources.
The hybrid model, which combines BERT and LSTM, was trained using text from
financial news and social media as well as historical stock price data. The hybrid
model fared better than the traditional models that employed various conventional
machine learning techniques or just LSTM. This suggests that stronger prediction
skills can be achieved by combining BERT for text-based context and sentiment
analysis with LSTM for time-series analysis. Lower values for the average error
metrics (MSE, RMSE) suggested a better match to the test data. By using BERT to
integrate textual input, the model was able to take market sentiment and pertinent
news events into account, adding context to the predictions. The model's overall
performance was enhanced by this innovation, which also revealed information
about outside variables affecting stock prices. The LSTM analysis of the technical
data enhanced the model's resilience to time-series data by identifying long-term
relationships and sequential patterns in stock prices. The hybrid model was
contrasted with more conventional approaches, such as LSTM models without
textual data and simple models. The hybrid model continuously demonstrated
improved forecast precision and flexibility in response to shifting market
circumstances. This comparison emphasizes how crucial it is to combine qualitative
and quantitative data in order to make accurate stock market predictions.
15
CHAPTER 9
CONCLUSION
In summary, the goal of our project was to anticipate stock price changes by
analyzing stock market data using LSTM (Long Short-Term Memory) and BERT
(Bidirectional Encoder Representations from Transformers) models. Several
significant revelations and conclusions have come from our investigation.First, the
efficiency of LSTM in capturing temporal relationships in stock price data was
shown. For short-term forecasting, its capacity to retain long-term patterns and apply
them to forecasts proved useful. We achieved competitive predictive performance by
using historical stock price data to train LSTM models.Second, by adding textual data
like financial news and stories, integrating BERT into our study gave our analysis a
fresh perspective. The models' comprehension of the sentiment and context
surrounding stock movements was improved by BERT's pre-trained contextual
knowledgeAn in-depth investigation is provided here:Improved Model Tuning: The
performance of LSTM and BERT models can be greatly improved by further
adjusting hyperparameters and architectures.It is possible to find ideal configurations
by using methods like grid search, random search, or Bayesian
optimization.Combining predictions from several LSTM and BERT models can be
done through the use of ensemble techniques like stacking and blending, or ensemble
learning.In doing so, you can strengthen the forecasts and lessen the impact of the
individual model flaws. The process of feature engineeringBetter model performance
can be achieved by adding new features that are obtained from textual and numerical
data.Further complex information can be captured by using sentiment ratings, event-
based characteristics, or technical indicators.Look at dynamic time series forecasting
techniques to help models adjust to shifting market
1
conditions. Temporal Attention Mechanisms: In LSTM models, employ temporal
attention mechanisms to direct attention toward more pertinent past data points.
In making forecasts, this might assist the model in highlighting significant time periods
and patterns.
1
CHAPTER 10
FUTURE SCOPE
There are a lot of opportunities for future research and development in the field of
stock market analysis employing LSTM and BERT projects.
Model Architecture Fine-Tuning: To increase the efficiency of LSTM and BERT
designs in recognizing intricate patterns and comprehending textual input, they need
be continuously improved.
Try out different LSTM implementations, like stacked LSTMs, attention-based
LSTMs, or hybrid architectures that combine LSTMs with other convolutional or
recurrent layers.
Examine BERT variants such as pre-trained models tailored to a certain domain or
models optimized for financial language.
Combining Data from Multiple Modes:
Integrate data from sources other than stock prices and financial news, such social
media emotions on the market, economic indicators, or alternative data like site
traffic or satellite imagery.
Provide strategies for integrating various data modalities, such as textual, numerical,
1
CHAPTER 11
REFERENCES
1. Sidra Mehtab, Jaydip Sen, Abhishek Dutta: Stock Price Prediction Using Machine Learning
and LSTM-Based Deep Learning Models, Springer, 2021.
2. Greff, Klaus, Rupesh Kumar Srivastava, Jan Koutník, Bas R. Steunebrink, and Jürgen
Schmidhuber. (2017) “LSTM: A Search Space Odyssey.” IEEE Transactions on Neural
Networks and Learning Systems 28 (10): 2222 – 2232
3. Sherstinsky, A. (2020), “Fundamentals of recurrent neural network (RNN) and long short-
term memory (LSTM) network”, Physica D: Nonlinear Phenomena, Vol. 404, 132306.
4. K. A. Althelaya, E. M. El-Alfy and S. Mohammed, "Evaluation of bidirectional LSTM for
short-and long-term stock market prediction," 2018 9th International Conference on
Information and Communication Systems (ICICS), Irbid, 2018, pp. 151-156
5. Devlin J, Chang M-W, Lee K, Toutanova K. 2018. Bert: pre-training of deep bidirectional
transformers for language understanding. ArXiv preprint. arXiv:1810.04805
6. Venkata Sasank Pagolu, Kamal Nayan Reddy Challa, Ganapati Panda, Babita Majhi:
Sentiment Analysis of Twitter Data for Predicting Stock Market Movements
7. M. Alsulmi: Reducing Manual Effort to Label Stock Market Data,Riyadh 11451, Saudi
Arabia,2021
8. M. Nabipour et al.: Predicting Stock Market Trends Using Machine Learning and Deep
Learning Algorithms,2020
9. Willem Sebastian,Balamurugan G,International Journal of Emerging Trends in Engineering
Research, 8(9), September 2020, 5430 – 5433
10. Shayan Halder:FinBERT-LSTM: Deep Learning based stock price prediction using News
Sentiment Analysis,2022
11. Karlo Puh and Marina Bagic Babac:Predicting stock market using natural language
processing,American Journal of Business Vol. 38 No. 2, 2023 pp. 41-61
12. Rouf, N.; Malik, M.B.; Arif, T.; Sharma, S.; Singh, S.; Aich, S.; Kim, H.-C. Stock Market
Prediction Using Machine Learning Techniques: A Decade Survey on Methodologies,
Recent Developments, and Future Directions. Electronics 2021
1
CHAPTER 12
APPENDIX
A) SOURCE CODE:
2
B) SCREENSHOTS
2
COURSE COMPLETED
2
2
2
2
.
CONTEST
PARTICIPATED
3
3
3
3
PLAGIARISM REPORT
3
3
3
3