Ruđer Bošković Institute



STOCK MARKET ANALYSIS AND PRICE PREDICTION USING DEEP LEARNING AND ARTIFICIAL NEURAL NETWORKSTomislav MEDI?University of Zagreb, Faculty of Economics & Business – Zagreb, Department of InformaticsTrg J.F.Kennedyja 6, 10000 Zagreb, CroatiaE-mail address: tmedic@net.efzg.hrMirjana PEJI? BACHUniversity of Zagreb, Faculty of Economics & Business – Zagreb, Department of InformaticsTrg J.F.Kennedyja 6, 10000 Zagreb, CroatiaE-mail address: mpejic@efzg.hrBo?idar JAKOVI?University of Zagreb, Faculty of Economics & Business – Zagreb, Department of InformaticsTrg J.F.Kennedyja 6, 10000 Zagreb, CroatiaE-mail address: bjakovic@efzg.hrAbstractThis paper aims to present a deep learning and artificial neural network application in the field of stock market trading, specifically, in the analysis and forecasting of the stock market prices as an additional tool to reduce risk and increase profits. The goal of the paper is to introduce a new form of technology, show its potential, and encourage further research into this subject in Republic of Croatia. To achieve this goal and to present the potential of this technology, two different artificial neural network prototypes were built, trained, and tested on the available set of historical stock price data from the Zagreb Stock Exchange. Two artificial networks were build using Python programming language: Long Short-Term Memory (LSTM) network and Multilayer Perceptron (MLP) network. Both artificial neural networks were built and the data sets they were trained and tested on were taken from the Zagreb Stock Exchange, containing historical stock prices of Croatian telecommunication companies, Optima Telekom (OPTE), and Hrvatski Telekom (HT). The results, i.e. price predictions, of both neural networks are presented in two parts. First, for OPTE stock prices and then for HT stock prices.KeywordsArtificial intelligence, deep learning, artificial neural networks, stock market trading, stock prices, Republic of CroatiaJEL classificationC45 – Neural Networks and Related Topics; C53 – Forecasting and Prediction Methods, Simulation Methods; G11 – Portfolio Choice, Investment DecisionsIntroductionThe analysis involves a careful study of the available facts with an attempt to draw conclusions based on established principles and sound logic. It is part of the scientific method. However, in the application of securities analysis, we encounter a serious obstacle since investing by nature is not an exact science CITATION Gra08 \l 1050 (Graham & Dodd, 2008). Therefore, various approaches are used and tested in the area of analysis and predicting stock market changes.Deep learning is a subclass of machine learning, and today it is the front-runner of machine learning methods and is used in many branches of human life and modern-day society. Many companies have discovered its effectiveness and are actively investing and developing deep learning architectures to increase competitiveness. Some examples of deep learning applications can be found in web searches, e-commerce website recommendation systems, content filtering on social networks, smartphone applications such as artificial intelligence cameras. Deep learning is also used for computer vision, pattern recognition, natural language processing, etc. CITATION LeC15 \l 1050 (LeCun, Bengio, & Hinton, 2015.). Most deep learning methods include the use of an artificial neural network.This paper aims to present a new approach to stock market analysis using artificial intelligence, i.e. deep learning, as one of the fastest-growing technologies today, and to explore its potential in predicting future stock prices. Both a theoretical basis for the application of this model will be presented, as well as a practical example in a form of an artificial neural network, which will analyze historical data and predict future stock prices. The main research question of this paper is “Can artificial intelligence, i.e. deep learning model, successfully predict future price movements?”.To achieve the goal of this paper, two different artificial neural networks were built, Multilayer Perceptron (MLP) and Long Short-term Memory (LSTM) neural network. Both networks were built using Python programming language and its libraries. Stock prices used for training and testing the artificial neural networks were taken from the Zagreb Stock Exchange, and are those of Croatian telecommunication companies, Optima Telekom (OPTE) and Hrvatski Telekom (HT) for the period from January 1, 2015. Until January 1, 2020.After the introduction, the second part of the paper cover similar research involving artificial neural networks. The third part of the paper presents the methodology used in this paper. Results of the utilized artificial neural networks on the datasets from the Zagreb Stock Exchange are presented in the fourth part, and concluding remarks are presented in the final part of the paper. Literature reviewThere is a long history of studying securities, and to this day, it has become a separate scientific discipline, which we call the investors to approach, investment analysis, portfolio management, etc. CITATION Ors \l 1050 (Orsag, 2015). Stock market predictability and tools to increase investment effectiveness have a long history of research and study. While opinions on the subject differ, many empirical studies do show that financial markets, i.e. stock markets, are somewhat predictable.Security analysis can be divided into two basic directions: fundamental and technical analysis. In terms of security analysis and efficient investment, the fundamental analysis includes analysis of entire industries, or individual industries, international industrial trends, inflation, and the like. In the analysis of joint-stock companies, their operations are analyzed based on publicly available financial statements and other public information relevant to their operations. In doing so, various standardized indicators are used, which are publicly available and are monitored continuously. The main goal of fundamental analysis is, based on various indicators, to determine which factors affect a particular price of a security, and to identify those securities that are overvalued or undervalued to achieve a return. Technical analysis is used in the analysis of various conditions in the capital market, such as price changes, exchange volume, supply, and demand, etc. All of these terms are graphically displayed and processed to find the best time to act, be it buying or selling. Capital market indicators such as Dow Jones Industrial Averages, S&P 500 Index (Standard & Poors), NASDAQ, etc. are also used.Deep learning based on usage of neural network emerged recently as the novel approach to the security analysis, with various applications. Deep learning is a subset of machine learning, as machine learning is a subset of artificial intelligence. Deep learning represents a new approach to learning from data that is based on concluding successive layers of increasingly meaningful representationsCITATION Cho18 \l 1050 (Chollet, 2018). The number of layers in a certain model represents its depth. Some machine learning approaches (and earlier neural networks) tend to contain only one or two layers of representations of the data and are commonly known as shallow learning models. Deep learning, on the other hand, at least modern versions of it, use tens or even hundreds of layers of representations and are almost always represented by a model called artificial neural network CITATION Cho18 \l 1050 (Chollet, 2018).Artificial neural networks are often compared to a human brain, hence the name neural network. However, despite some similarities with the human brain, and concepts that were introduced to the development of artificial neural networks based on scientific understanding of a human brain, deep learning models, i.e. artificial neural networks, are not models of the brain and are not modeled after the brain. They are a programmed mathematical framework designed for learning representations and discovering patterns in data CITATION Cho18 \l 1050 (Chollet, 2018).Artificial neural networks are often used for security analysis. For example, Chong, Han, & Park CITATION Cho17 \n \t \l 1050 (2017) proposed a model for stock market prediction using data from the Korean stock market, and compared its results to established linear autoregressive models and have found that deep learning models have outperformed the linear models in the training set. However, they’ve also concluded that the advantage drastically lowers in the testing phase.Hiransha, Gopalakrishnan, Menon, & Soman CITATION Hir18 \n \t \l 1050 (2018) also tested artificial neural networks on the New York Stock Exchange and compared its efficiency with ARIMA linear model. They have found that Convolutional neural network (CNN) outperformed the other types of neural networks used in the research, and have also observed that the neural networks outperformed the ARIMA linear model in price prediction.Selvin, R, Gopalakrishnan, Menon, & Soman CITATION Sel17 \n \t \l 1050 (2017) also proposed a deep learning technology for stock price prediction and have found that the proposed system was capable of identifying patterns within the data, and have also found that CNN networks were capable of capturing changes in trends. They have trained the model on Infosys stock prices and were able to predict future stock prices for Infosys, TCS, and Cipla, once again proving the potential of deep learning technology.Nelson, Pereira, & de Oliveira CITATION Nel17 \n \t \l 1050 (2017) built an LSTM prediction model and tested it through a series of experiments. Their results show promise, as the neural network was getting more than 55% accuracy when predicting a rise or fall of a certain stock.Many more papers have covered the use of deep learning models in some form of prediction, most of which have concluded that artificial neural networks have great potential and a large field of application. Besides, this technology hasn't yet reached its peak. It is still being developed, and new architectures and fields of application are still being discovered almost daily. MethodologyDataThe data for the analysis were taken from the Zagreb Stock Exchange website, and they include the historical prices of Optima Telekom shares (OPTE), and Hrvatski Telekom shares (HT). OPTE and HT are Croatian companies based in Zagreb, and both are providers of telecommunication services. As such they are listed on the Zagreb Stock Exchange as part of the “Telecommunications” sector. The downloaded data sets contain daily data on the starting price, highest price, lowest price, closing price, average share price, quantity, and the number of transactions, all from 1 January 2015. to 1 January 2020.Both data sets were divided into training data (80%) and testing data (20%). The first 80% of the data will be used to train neural networks, and the last 20% of the values in the data sets will be used to test each network and will serve as a measure of neural network performance.The movement of prices of both shares is shown for the period from 1 January 2015 to 1 January 2020 (Figure 1).Figure SEQ Figure \* ARABIC 1: Historical data of OPTE and HT shares (1.1.2015-1.1.2020)Source: Authors’ workResearch methodsSince the use of deep learning models, i.e. artificial neural networks, is an extremely complex process, which requires significant investment, knowledge and time to build, train and test, the aim of this paper is to present two simple models of artificial neural networks as an example of deep learning in the area of predicting future movements, in this case of stock prices.As previously mentioned, there are several types of artificial neural networks that can accept different data to solve different tasks. In this paper, simple Multilayer Perceptron (MLP) and Long Short-term Memory (LSTM) neural networks, created using Python programming language and its packages (keras, tensorflow, etc.), were built and used. The results are presented using the numpy and matplotlib packages.The subject of the paper is the comparison of actual prices of OPTE and HT shares with the prices predicted by the neural network models (last 20% of data – testing data). It is important to emphasize that these models are just a simple representation of the principle by which artificial neural networks operate. For further in-depth analysis and more accurate, i.e. reliable, predictions, it would be necessary to program a more complete neural network that would take many more factors into account and which should be trained in several phases with different data.This paper does not advocate replacing the existing analyses but rather complement them to increase efficiency. The application of simpler neural networks is more in line with technical analysis since the conditions and indices observed through technical analysis are much easier to record, acquire, and load into the neural network. Such is the case with the models in this paper. The downloaded data set contains data on the closing price of shares from the Zagreb Stock Exchange, which is enough for these neural networks to make simple forecasts. In fundamental analysis, data collection would be somewhat more difficult, but not impossible.As a part of building working neural network models, the available data was standardized using the MinMaxScaler package from the sklearn.preprocessing Python module. The data was then divided into training and testing data. 80% of data was used for training and the rest was used for testing the models.Both neural networks were built using a Sequential model which is a part of Keras Python library. To verify the results given by neural network models, we used mean squared error. Neural networks were trained over 100 epochs, in batch size of 33, using MSE as a measure of quality and Adam as the optimizer. Adam is an optimization algorithm commonly used to train deep learning models.The training was completed successfully with a reported MSE of 0.0016 for LSTM network, and 0.0013 for MLP network. The results of testing the models can be found below.ResultsAs previously stated, two different neural network architectures, MLP, and LSTM were used to analyze and predict stock prices, and the results of these two models are presented in this chapter.Stock price prediction with MLP network Multilayer Perceptron is a fairly simple (compared to other neural networks) neural network architecture. However, the simplicity does not hinder its ability to accurately predict future movements. MLP is a commonly used artificial neural network that is being used in multiple fields. For example, Colombet, Ruelland, Chatellier, Gueyffier, Degoulet, & Jaulent CITATION Col00 \n \t \l 1050 (2000) used a MLP model to predict cardiovascular risk, and Lee & Choeh CITATION Lee14 \n \t \l 1050 (2014) used MLP to predict helpfulness of online reviews.Even using a relatively simple neural network that is MLP, when predicting future price movements of HT and OPTE stocks, we can notice the efficiency and potential of deep learning technology. Based on historical stock prices – marked in red – the MLP neural network was able to predict stock price movements to some extent, as is visible by the blue line in Figure 2.Figure SEQ Figure \* ARABIC 2: OPTE stock price prediction using MLP networkSource: Authors’ workWe can view the results in more detail when we enlarge the graph (Figure 3). We can observe that the MLP network, at several time points, has successfully predicted the prices of OPTE shares. For example, for the time interval 50-100, it can be observed that MLP predicted relative price stagnation with a slight short-term decline, followed by a sharp increase present in the time interval 100. The success of the forecast is visible throughout the testing data, however, at several time points, the network failed to accurately predict price movements (e.g., time intervals 150, 170, and 220). These deviations could be somewhat corrected by further adjustment of the MLP model (weight correction), or by additional training and optimization of the MLP neural network.Figure SEQ Figure \* ARABIC 3: Comparison of actual and predicted OPTE stock prices using MLPSource: Authors’ workA similar degree of accuracy can be observed for the HT stock price data set. The MLP network once again predicted the stock price movements, highlighted in blue in Figure 4.Figure SEQ Figure \* ARABIC 4: HT stock price prediction using MLP networkSource: Authors’ workIn Figure 5, when we study the graph in more detail, once again we can observe that the network predicted the price movements and at several time points captured the exact stock price. However, at several time intervals it did not successfully predict HT stock prices (e.g. time intervals 50, 70, 100, etc.).Figure SEQ Figure \* ARABIC 5: Comparison of actual and predicted HT stock prices using MLPSource: Authors’ workEven though the network was not perfectly accurate, MLP network successfully predicted a decline in stock prices (time interval 100), and then an increase (time interval 120), as well as an increase in stock prices for the time interval 190-210. At time points the network was able to predict HT stock prices perfectly (e.g. time intervals 60, 120, 130, etc.).Stock price prediction with LSTM networkLSTM neural network is one of the youngest neural network architectures which is popularly used for time series prediction, classification, and processing because of its ability to “learn” long-term dependencies. An example would be using an LSTM network to predict real-time traffic flow CITATION FuR16 \l 1050 (Fu, Zhang, & Li, 2016). Fu, Zhang, & Li used LSTM model to predict traffic flow because existing models such as ARMA and ARIMA couldn’t capture the nonlinear nature of traffic flow. Similarly, Duan, L.V., & Wang CITATION Dua16 \n \t \l 1050 (2016) used an LSTM neural network to predict travel time. LSTM neural networks show promising results in time series prediction which can also be seen in this paper.The LSTM network has proven to be extremely effective using a simple model built with Keras package of the Python environment. The first graph (Figure 6) shows the actual price movement from 2015 to 2020 (red line) and the predicted prices given by the LSTM network on the testing data (blue line). From the graph, it can be seen that the network noticed and predicted the movement of OPTE stock prices. Of course, this model needs to be further tested on future stock price data to establish its real efficiency and usefulness in stock market analysis and investment.Figure SEQ Figure \* ARABIC 6: OPTE stock price prediction using LSTM networkSource: Authors’ workWhen the graph is enlarged and we study the results in more detail (Figure 8), we can observe that, although the neural network mostly did not perfectly estimate the exact stock prices, it predicted the actual price movement. The network predicted the fall and rise of prices (time points 100, 110, 150, etc.), and at certain time intervals perfectly accurately predicted the price of OPTE shares (time points 90, 105, 110, etc.). Figure SEQ Figure \* ARABIC 7: Comparison of actual and predicted OPTE stock prices using LSTMSource: Authors’ workWe can also notice that the accuracy of the LSTM network decreases over time, which can be mitigated to some extent by optimizing the LSTM model. If we compare MLP and LSTM models in this paper, we will notice that the MLP network gave more accurate predictions for OPTE stock prices. However, the LSTM network is a more complex and more advanced model of an artificial neural network, which with further optimization and development would produce significantly better results. Nevertheless, even with these simple models, we can discern the potential of deep learning, i.e. artificial neural networks.For the results of the LSTM network, in case of HT stock prices, we can observe slightly better, more accurate results. The LSTM network again managed to predict the overall stock price movement (Figure 9).Figure SEQ Figure \* ARABIC 8: HT stock price prediction using LSTM networkSource: Authors’ workWhen we look at the graph more closely (Figure 10), we can see that the LSTM network successfully predicted the rise and fall of stocks (e.g. time interval 100-110) and that the accuracy of the network remained the same over time. We can also notice that the LSTM network at several time points perfectly predicted the price of HT stocks (e.g. time points 60, 80, 135, etc.). However, at some time points it has failed to predict the prices accurately (e.g. time points 45, 105, 190, etc.).Figure SEQ Figure \* ARABIC 9: Comparison of actual and predicted HT stock prices using LSTMSource: Authors’ workDiscussion This paper, and similar research done in the past, can give a clear answer to the question stated at the beginning of this paper: “Can artificial intelligence, i.e. deep learning model, successfully predict future price movements?”. The answer is yes, yes it can. However, an artificial neural network (or any other artificial intelligence model) will never be able to predict price movements 100% of the time. It can, however, reduce risk and increase efficiency of analyses that are currently used for stock market trading and price prediction.This has been proven many times. Even though artificial neural networks have just recently been developed to a point they can be effectively used for time series prediction (and other tasks), the field of deep learning models has been a part of the scientific research for a much longer time. For example, Kimoto, Asakawa, Yoda, & Takeoka CITATION Kim90 \n \t \l 1050 (1990) used modular neural networks to create a time prediction system which buys and sells stocks on the Tokyo Stock Exchange. They developed a number of learning algorithms and prediction methods for the system. The system achieved accurate predictions, and the simulations created for stock trading showed an excellent profit. Guresen, Kayakutlu, & Daim CITATION Gur11 \n \t \l 1050 (2011) used Multilayer Perceptron (MLP), dynamic artificial neural network (DAN2) and a hybrid neural network (GARCH) to predict daily closing values on NASDAQ Stock Exchange. They used MSE and MAD to compare the efficiency for each model. They’ve found that MLP gave satisfying results and was able to predict price movements, DAN2 was architecturally inconsistent, and the hybrid neural network did not give any meaningful results.Chen, Zhou, & Dai CITATION Che15 \n \t \l 1050 (2015) modeled an LSTM neural network and used it to predict stock returns on the stock market in China, and have found their prediction accuracy to increase drastically when using an LSTM neural network.And, as mentioned before, Chong, Han, & Park CITATION Cho17 \n \t \l 1050 (2017) proposed a model for stock market prediction using data from the Korean stock market. Hiransha, Gopalakrishnan, Menon, & Soman CITATION Hir18 \n \t \l 1050 (2018) tested artificial neural networks on the New York Stock Exchange and many more papers have been written on this subject. Most of them conclude that artificial neural networks can predict (to a certain extent) future price movements, and that they outpeform most, if not all, currently used tools for stock market analysis and price prediction.This conclusion can be drawn from the results in this paper as well. It is evident that even simple neural network models can predict future price movements, and with further optimization produce even more accurate results. However, further research and development is required to be able to apply a neural network model in a real world environment.ConclusionAs part of this work, two different artificial neural networks, LSTM and MLP, were built and used to analyze and predict stock prices on the Zagreb Stock Exchange. The data sets used for training and forecasting include historical stock prices of OPTE and HT were taken from the Zagreb Stock Exchange.This paper aimed to present models of deep learning, i.e. artificial neural networks, for analysis and prediction of stock prices. This was achieved by using the Python programming language and its packages. It is important to note that the neural networks used in this paper are simple models, which, with adequate upgrades and optimization, can be improved significantly. Besides, there are a large number of different artificial neural networks that are not part of this paper but do possess the potential for analysis and prediction. One example would be a Convolutional neural network, which is primarily used for computer vision but can also be adapted to a task such as time series prediction. However, since the development of more advanced neural networks requires greater investment and time, research has been conducted with simpler neural network models.However, even the results of simple artificial neural network models allow conclusions to be drawn on the application of deep learning methods in the stock market, and one of the conclusions is that they can be a powerful tool in stock analysis, which can reduce investment risk and increase efficiency.The availability of data today, as well as stronger processing computer power with the development of related technology, allow both large and small investors to strengthen their investments by using various tools. Classical analyses, technical and fundamental, can be optimized by applying various methods, especially deep learning methods. The number of research projects on deep learning is growing exponentially, and methodology and technology are evolving daily, so it is highly likely that deep learning methods, and artificial intelligence in general, will become standard instruments of stock analysis and price prediction.It is important to emphasize that the models used in this paper use a simple neural network architecture, which can most certainly be improved with time and resources. Nevertheless, some conclusions can be drawn by observing and comparing the results. Furthermore, numerous neural network architectures can be used for time series prediction, including predicting stock prices. However, building and optimizing those architectures would also take time, which is beyond the scope of this paper. All these architectures are continuously upgraded; their efficiency is rising rapidly, as is their area of application. Therefore, this poses a new potential area for future research. ReferencesBIBLIOGRAPHYChen, K., Zhou, Y., & Dai, F. (2015). A LSTM-based method for stock returns prediction: A case study of China stock market. 2015 IEEE International Conference on Big Data (Big Data), (pp. 2823-2824). Santa Clara, CA, USA. doi:10.1109/BigData.2015.7364089Chollet, F. (2018). Deep Learning with Python. Greenwich, CT, USA: Manning Publications Co.Chong, E., Han, C., & Park, F. C. (2017). Deep learning networks for stock market analysis and prediction: Methodology, data representations, and case studies. Expert Systems with Applications 83, pp. 187-205. doi:, I., Ruelland, A., Chatellier, G., Gueyffier, F., Degoulet, P., & Jaulent, M. C. (2000). Models to predict cardiovascular risk: comparison of CART, multilayer perceptron and logistic regression. Proceedings. AMIA Symposium, (pp. 156-160). Retrieved from , Y., L.V., Y., & Wang, F. (2016). Travel time prediction with LSTM neural network. 2016 IEEE 19th International Conference on Intelligent Transportation Systems (ITSC), (pp. 1053-1058). Rio de Janeiro. doi:10.1109/ITSC.2016.7795686Fu, R., Zhang, Z., & Li, L. (2016). Using LSTM and GRU neural network methods for traffic flow prediction. 2016 31st Youth Academic Annual Conference of Chinese Association of Automation (YAC), (pp. 324-328). Wuhan. doi:10.1109/YAC.2016.780491Graham, B., & Dodd, D. L. (2008). Security Analysis: Principles and Technique, 6 ed. New York: McGraw-Hill.Guresen, E., Kayakutlu, G., & Daim, T. U. (2011). Using artificial neural network models in stock market index prediction. Expert Systems with Applications(Volume 38, Issue 8), pp. 10389-10397. doi:, M., Gopalakrishnan, E., Menon, V. K., & Soman, K. (2018). NSE Stock Market Prediction Using Deep-Learning Models. Procedia Computer Science, Volume 132, pp. 1351-1362. doi:, T., Asakawa, K., Yoda, M., & Takeoka, M. (1990). Stock market prediction system with modular neural networks. IJCNN International Joint Conference on Neural Networks, (pp. 1-6 vol.1). San Diego, CA, USA. doi:10.1109/IJCNN.1990.137535.LeCun, Y., Bengio, Y., & Hinton, G. (2015.). Deep learning. Nature, pp. 436-444. doi:10.1038/nature14539Lee, S., & Choeh, J. Y. (2014). Predicting the helpfulness of online reviews using multilayer perceptron neural networks. Expert Systems with Applications, Volume 41, Issue 6, pp. 3041-3046. doi:, D. M., Pereira, A. C., & de Oliveira, R. A. (2017). Stock market's price movement prediction with LSTM neural networks. 2017 International Joint Conference on Neural Networks (IJCNN), (pp. 1419-1426). Anchorage, AK, USA. doi:10.1109/IJCNN.2017.7966019Orsag, S. (2015). Poslovne financije. Zagreb: Avantis.Selvin, S., R, V., Gopalakrishnan, E., Menon, V., & Soman, K. (2017). Stock price prediction using LSTM, RNN and CNN-sliding window model. Conference: 2017 International Conference on Advances in Computing, Communications and Informatics (ICACCI), (pp. 1643-1647). doi:10.1109/ICACCI.2017.8126078 ................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download