VIETNAM NATIONAL UNIVERSITY, HANOI INTERNATIONAL SCHOOL GRADUATION PROJECT APPLYING MACHINE LEARNING ALGORITHMS FOR STOCK PRICE FORECASTING Student’s name NGUYEN THU HUYEN Hanoi - 2024. VIETNAM NATIONAL UNIVERSITY, HANOI INTERNATIONAL SCHOOL GRADUATION PROJECT APPLYING MACHINE LEARNING ALGORITHMS FOR STOCK PRICE FORECASTING SUPERVISOR: DR. NGUYEN DOAN DONG (Academic title, academic degree, full name) STUDENT: NGUYEN THU HUYEN STUDENT ID: 20070937 COHORT: QH2020 SUBJECT CODE: INS401101 MAJOR: BUSINESS DATA ANALYTICS Hanoi - 2024. ACKNOWLEDGMEMTS Through my time studying and practicing at the International School - Hanoi National University, the enthusiastic guidance and teaching of the teachers has imparted valuable knowledge to me throughout my time studying at the University.
With my own efforts, I completed my graduation project. From these achieved results, I would like to sincerely thank the teachers of the International School, in general, and the teachers in the Faculty of Applied Sciences in particular, for teaching me knowledge about general subjects as well as like specialized subjects, help you gain a solid theoretical basis and create conditions to help you throughout the learning process. In particular, Dr. Nguyen Doan Dong wholeheartedly guided and helped me complete this thesis report.
Finally, I want to express my gratitude to my friends and family for always creating conditions, caring for me, helping and encouraging me throughout the study process and completing my graduation thesis. Due to limited knowledge and experience, shortcomings in expression and presentation are inevitable. I look forward to receiving your comments so that the thesis report achieves the best results. I would like to wish all teachers and friends lots of health, joy, and success in work and life.
I would like to sincerely thank you. 1 DECLARATION I hereby declare that the thesis “APPLYING MACHINE LEARNING ALGORITHMS FOR STOCK PRICE FORECASTING” is my research project under the guidance of Dr. Nguyen Doan Dong, stemming from his own practical needs and desire to learn. Except for the reference results from other works clearly stated in the thesis, the contents presented in this thesis are the results of research conducted by myself and the results of the thesis have never been published before under any form.
2 SUMMARIZATION The evolution of contemporary civilization is significantly influenced by the stock market. They make it possible to allocate financial resources. Variations in stock prices are a reflection of market movements. Deep learning is frequently employed in the financial industry for tasks including stock market prediction, optimum investing, and financial information processing due to its strong data processing capabilities in many domains.
Put financial trading concepts into practice. For this reason, one of the most significant and well-liked professions in the financial industry is stock market prediction. In this research, I suggest using the Transformer - supervised deep learning method for predicting stock price. The supervised deep learning model for stock price prediction problems uses a structure consisting of many encoder layers to create a powerful and flexible system for stock price prediction.
In this report, I will report on an experiment on CTG stock (Vietinbank) and some stocks of other banks in the top 4 large banks in Vietnam, which are stocks with a wide range of trading days and use them to try to predict the daily closing price. Experimental results show that my proposed Transformer for time series method can outperform a lot of other prediction algorithms in terms of stock price prediction. In addition, in this thesis, I also propose to build a web application to visualize research results and support users in predicting market stock prices from stock transactions at the top 4 banks in Vietnam that are operating in the market today. Experimental results show that the proposed model achieves good results on the data sets used for training and evaluation on all measures: The R-square index measures the model's level of explanation.
for the dependent variable and measures include Root Mean Square Error (RMSE), Mean Absolute Error (MAE), Mean Absolute Percentage Error (MAPE). 3 LIST OF TABLES Table 4.1: Vietinbank stock dataset .2: BIDV stock dataset .3: Vietcombank stock data .4: Techcombank stock data .5: Evaluation results using the ANN model .6: Evaluation results using the SVR model.7: Evaluation results using the Random Forest model .8: Evaluation results using the LSTM model .9: Evaluation results using the Transformer model .10: Measurement results of the methods. 56 4 LIST OF FIGURES Figure 2.1: Stock market classification model .2: Model of different types of stock markets .3: Brief history of deep learning Deep learning.4: Simple regression network model .5: Model of an LSTM cell .7: Structure of two Attention mechanisms .1: Structure of two Attention mechanisms .2: My proposed Transformer structure .3: Details of my proposed Transformer structure .1: Stock price chart using ANN method .2: Stock price chart using SVR method .3: Stock price chart using Random Forest method .4: Stock price chart using LSTM method .5: Stock price chart using the Transformer method – 3 encoder layers.8: "Model training" function .9: "Model Evaluation" function .10: "Model Evaluation" function - Vietinbank example .11: "Prediction" function - Vietinbank example. 60 5 LIST OF ABBREVIATIONS Abbreviations Full words DL Deep learning ML Machine learning MLP Multilayer Perceptron ReLu Rectified Linear Unit API Application Programming Interface RNN Recurrent Neural Network CNN Convolutional Neural Network GAN Generative Adversarial Network ANN Artificial Neural Networks SVM Support Vector Machines SVR Support Vector Regression LSTM Long Short Term Memory BiLSTM Bidirectional Long Short Term Memory FFN Feed Forward Network R! R-square index MAE Mean Absolute Error RMSE Root Mean Square Error MAPE Mean Absolute Percentage Error 6 TABLE OF CONTENTS ACKNOWLEDGMEMTS.
3 LIST OF TABLES. 4 LIST OF FIGURES. 5 LIST OF ABBREVIATIONS. 6 TABLE OF CONTENTS.
OBJECTIVES OF THE STUDY. SUBJECT AND SCOPE OF RESEARCH. SCIENTIFIC AND PRACTICAL SIGNIFICANCE. CHAPTER 2: THEORETICAL BACKGROUND.
BASIC ISSUES ABOUT STOCKS. OVERVIEW OF THE STOCK MARKET. Stock market concept. The role of the stock market.
Classification of stock markets. MACHINE LEARNING AND THE STOCK MARKET. DEEP LEARNING AND THE STOCK MARKET. Recurrent neural network (RNN).
Long-short term memory neural network (LSTM). STOCK PRICE PREDICTION. CHAPTER 3: PROPOSED METHODS. OVERVIEW OF THE PROPOSED METHODS.
CHARACTERISTICS OF THE PROPOSED MODEL. BUILD AN APPLICATION THAT VISUALIZES RESULTS. Motivation Today, all developed countries and most developing countries have stock markets, an indispensable market for any economy that wants to develop strongly. In Vietnam, even though over 24 years of formation and development since the Ho Chi Minh City Stock Exchange Center (later renamed Ho Chi Minh City Stock Exchange - HOSE) had its first trading session on December 28.
Since July 2000, up to now the Securities industry has achieved certain achievements along with the growing transformation of the country's economy. As of April 2024, Vietnam's stock market (stock market) has continued to maintain an important role in mobilizing capital for the economy. In 2023, the stock market mobilized a total of VND 418,271 billion, an increase of 33.5% compared to the previous year [23]. Since its establishment, Vietnam's stock market has mobilized a total of about 2.7 million billion VND.
From 2011 to April 2024, the scale of capital mobilization through the stock market reached about 1.8 million billion VND, contributing an average of 20.5% of total social investment capital [24][25]. Market share: By the end of March 2024, stock market capitalization is estimated to reach nearly 6.7 million billion VND, an increase of 12.2% compared to the end of 2023 [24]. In 2023, stock market capitalization will reach nearly 6 million billion VND, an increase from the start of the year of 14% [26]. Bond market: By the end of February 2024, the bond market will have a listed value of more than 2,040 trillion VND, an increase of 17.1% compared to the end of 2023 [24].
As of 2019, the bond market capitalization reached over 30.3% of GDP, of which the corporate bond market reached nearly 10. As of April 2024, Vietnam's stock market capitalization will reach about 92% of GDP, continuing to contribute to shaping a modern financial system, harmonizing the stock market and the currency-credit market [24][27]. Regarding typical trading indices: VN-Index: By the end of March 2024,VN-Index reached 1,286.11 points, an increase of 13.8% compared to the end of 2023 [24]. 9 Average transaction value: In the first quarter of 2024, the average transaction value reached 22,529 billion VND/session, an increase of 28.2% compared to the average in 2023 [24].
The above results show the strong and stable development of Vietnam's stock market, although there are still many challenges and fluctuations from the macroeconomic and international environment. The development of Vietnam's stock market has made an important contribution to the process of restructuring the economy on all three main pillars. First, the stock market has promoted state-owned enterprise reform through equitization and divestment of state capital, with transparent and modern auction mechanisms, while also linking equitization with transaction registration and listing. listed on the stock market.
Second, the stock market has become an important capital mobilization channel for the state budget, contributing to the restructuring of public investment. Third, the stock market supports the restructuring process of credit institutions, especially commercial banks participating in listing on the market, helping to increase transparency and efficiency in the operations of these banks. Transparency and complete information about stock prices on the stock market help business managers, investors and individuals make decisions to participate in the market in a profitable and sustainable way. Thereby, improving trust and reliability in the stock market, bringing maximum satisfaction to investors, while making the stock market more efficient and better.
That is why predicting the stock market is an urgent need and has practical significance. This topic has been of interest to many domestic and foreign researchers and many solutions have been proposed. Each solution has different advantages and disadvantages, but using machine learning is currently the solution that brings good results. For the above reasons I have chosen the topic "Applying Machine learning algorithms for Stock Price Forecasting” as the topic of my graduation thesis.
Objectives of the study This thesis focuses on researching and solving the problem of predicting stock prices in the banking stock market in Vietnam with the top 4 large banks such as BIDV, 10 Vietinbank, Vietcombank, Techcombank,. On the basis of data collected from the website specializing in providing, evaluating, and analyzing financial stocks around the world Yahoo Finance, I preprocess, extract features, apply machine learning methods and Supervised deep learning Transformer for time series for stock price prediction problem thereby proposing the most optimal model. Subject and scope of research Research object of the thesis: Stock data from the website specializing in providing, evaluating and analyzing the characteristics of financial stocks in the world Yahoo Finance, which is related to stocks of corporations. Large corporations and companies in the world.
Scope of research: Deep learning and machine learning techniques are used to the problem of stock price prediction in stocks with a wide range of trading days. Research Methods - Theoretical research methods: Synthesize and research documents on securities stocks; Research methods and algorithms used for stock price prediction; Research deep learning methods into the stock market. Learn related knowledge such as stock market, machine learning, and computer programming techniques. - Experimental research methods: After studying the theory, stating the problem, and proposing a model; Build and develop applications based on the proposed model; Install a test program and evaluate the results achieved - Comparison and evaluation methods: Analyze and evaluate the proposed model with previous research models using different metrics.
Scientific and practical significance Scientific significance of the thesis: The thesis suggests an approach to feature extraction as a solution to the stock price prediction problem. The thesis tests approaches to different models, thereby introducing Create the most optimal model 11 for price prediction.