A Stock Price Prediction Model Based on Investor
Sentiment and Optimized Deep Learning
A Major Project Report
Submitted in partial fulfillment of the requirements for the award of the degree of
BACHELOR OF TECHNOLOGY
With specialization in
COMPUTER SCIENCE AND ENGINEERING
Submitted by
Y. SAI KIRAN (20BT1A0529)
T. TRIVENI
Assistant Professor (CSE)
VISVESVARAYA COLLEGE OF ENGINEERING&
TECHNOLOGY
Approved by AICTE, New Delhi & Govt. of T.S. Accredited with NAAC ‘A’ Grade, Affiliated
to JNTUH, Hyderabad
(MP Patelguda, Ibrahimpatnam, Telangana, INDIA-501 510)
2023-2024
i
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
CERTIFICATE
This is to certify that this project report entitled A STOCK PRICE
PREDICTION MODEL BASED ON INVESTOR SENTIMENT AND
OPTIMIZED DEEP
LEARNING submitted by Y. Sai Kiran (20BT1A0529) in partial fulfillment of the
requirements for the degree Bachelor of Technology in Computer science &
Engineering to Jawaharlal Nehru Technological University , Hyderabad, during the
academic year 2023-24, is a bonafide record of work carried out under our guidance and
supervision.
The results embodied in this report have not been submitted to any other University
or Institution for the award of any degree or diploma.
Mrs. T. TRIVENI Mrs. T. Ramya Sri
Assistant Professor Head of Department
Dept. of CSE Dept. of CSE
INTERNAL EXAMINER EXTERNAL EXAMINER
ii
DECLARATION
I hereby declare that this submission is our own work and that, to the best of our
knowledge and belief, it contains no material previously published or written by another
person nor material which to a substantial extent has been accepted for the award of any
other degree or diploma of the university or other institution of higher learning, except
where due acknowledgement has been made in the text.
Signatures
NAME: Y. Sai Kiran
ROLL NO: (20BT1A0529)
iii
ACKNOWLEDGEMENT
It gives us a great sense of pleasure to present the report of the Minor project
undertaken during final year of B.Tech. We like to express our special thanks to our
Principal & Professor Dr. D. Ramesh for moral support and College Management of
Visvesvaraya College of Engineering & Technology, Hyderabad for providing us
infrastructure to complete the project.
I owe special debt of gratitude to Dr. S. Selvakumar, Dean (Academics) of
Visvesvaraya College of Engineering & Technology, Hyderabad for his constant support
and guidance throughout the course of our work.
I thank T. Ramya Sree, Head of the Department of Computer Science &
Engineering for her constant support and cooperation
I owe special debt of gratitude to guide T. TRIVENI, Assistant Professor
Department of Computer Science and Engineering, for her full support and guidance
throughout the courseof our work. It is only her cognizant efforts that our endeavors have
seen light of the day.
I also like to express our gratitude towards our Parents/Guardians & siblings for
their kind co-operation and encouragement which helped us in completion of this project.
We do not want to miss the opportunity to acknowledge the contribution of all faculty
members of the department for their kind assistance and cooperation during the
development of our project. Last but not the least, we acknowledge our friends for their
contribution in the Completion of the project.
Y. Sai Kiran (20BT1A0529)
iv
ABSTRACT
Accurate prediction of stock prices can reduce investment risks and increase returns. This paper
combines the multi-source data affecting stock prices and applies sentiment analysis, swarm
intelligence algorithm, and deep learning to build the MS-SSA-LSTM model. Firstly, we crawl the
East Money forum posts information to establish the unique sentiment dictionary and calculate the
sentiment index. Then, the Sparrow Search Algorithm (SSA) optimizes the Long and Short-Term
Memory network (LSTM) hyperparameters. Finally, the sentiment index and fundamental trading
data are integrated, and LSTM is used to forecast stock prices in the future. Experiments demonstrate
that the MS-SSA-LSTM model outperforms the others and has high universal applicability. Compared
with standard LSTM, the R2 of MS-SSA-LSTM is improved by 10.74% on average. We found that:
1) Adding the sentiment index can enhance the model’s predictive performance. 2) The LSTM’s
hyperparameters are optimized using SSA, which objectively explains the model parameter settings
and improves the prediction effect. 3) The high volatility of China’s financial market is more
suitableforshort-termprediction
v
INDEX
CHAPTER 1: INTRODUCTION 1-3
CHAPTER 2: LITERATURE SURVEY 4-7
CHAPTER 3: SOFTWARE REQUIREMENT ANALYSIS
1.1 Proposed System 8
1.1.1 Prediction stock with Deep Learning 9
1.1.2 Factors Effecting the Stock price 9
1.1.3 Sentiment Analysis Technology 9
1.2 Sparrow Search Algorith 10
1.3 Long and Short Term Memory Network 10-11
1.4 Constructing of Mr -SSA-LSTM Srock Price Prediction Model 12
1.5 Model Evaluation Criteria 13
1.5.1 Data Acquisition 13
1.5.2 Data Set 13
1.5.3 Analysing the stock price prediction model 14
1.6. Influence of Trading on the Stock Price Prediction Model 15
1.7 Trading Investigation 15
2.1 Preliminary Investigation 16
2.1.1 Requesting Clarification 16
2.1.2 Feasibility Analysis 17
2.1.3 Requesting Approval 18
2.2 Algorithms 18-22
2.2.1 Decision tree classifiers 18
2.2.2 Gradient boosting 18-19
vi
2.2.3 K-Nearest Neighbors (KNN) 19
2.2.4 Logistic regression Classifiers 19-20
2.2.5 Naïve Bayes 20-21
2.2.6 Random Forest 21-22
2.2.7 SVM 22
2.3 Modules 23
2.3.1 Service Provider 23
2.3.2 View and Authorize Users 23
2.3.3 Remote User 23
CHAPTER 4: SOFTWARE DESIGN
4.1 Class Diagram 24
4.2 Use Case Diagram 25
4.3 Sequence Diagram 26
4.4 Data Flow Diagram 27
4.5 Flow Charts: Remote User 28
4.6 Flow Charts: Service provide 29
CHAPTER 5: SOFTWARE AND HARDWARE REQUIREMENTS
5.1 Software Requirements 30
5.2 Hardware Requirements 30
CHAPTER 6: CODING
6.1 Code 31-38
6.2 Python 39-40
6.3 Django Web Framework (Python) 41-42
vii
CHAPTER 7: TESTING
7.1 Unit Testing 43
7.2 Integration Testing 43-44
7.3 User Acceptance Testing 44-45
7.4 Output Testing 45
7.5 Validation Testing 45-46
7.6 User Training 47
CHAPTER 8: OUTPUT SCREENS
8.1 Home Page 49
8.2 Admin Pages 49
8.3 User Pages 50-54
CHAPTER 9: CONCLUSION 55
CHAPTER 10: FUTURE SCOPE 56-57
CHAPTER 11: REFERENCE 58-60
viii
LIST OF FIGURES
Figure 1: Literature Surve of Stock Price Prediction 5
Figure 2: Data Acquisiting of Stock Price 13
Figure 3: Analysis of Stock Price Prediction Model 14
Figure 4: Infuence of Stock Price 15
Figure 5: Class Diagram 24
Figure 6: Use case Daigram 25
Figure 7: Sequence Diagram 26
Figure 8: Dataflow Diagram 27
Figure 9: Flow Chart : Remote User 28
Figure 10: Flow Chart :Service Provider 29
ix
LIST OF SCREENS
Screen 1: Home page 49
Screen 2: Registration page 49
Screen 3: User Prediction 50
Screen 4: User Profile 50
Screen 5: Service provider login page 51
Screen 6: View Investor Sentiment Prediction Type Ratio Details 51
Screen 7: Trained and Tested Accuracy in Bar Chart 52
Screen 8: Trained and Tested Accuracy in Pie Chart 52
Screen 9: Trained And Tested Accuracy in Line Chart 53
Screen 10: View Investor Sentiment Prediction Type 53
Screen 11: Datasets Trained And Tested Results 54
Screen 12: View All Remote Users 54