APPL stock price prediction based on LSTM and GRU

Research Article
Open access

APPL stock price prediction based on LSTM and GRU

Tao Pang 1*
  • 1 University of Pennsylvania    
  • *corresponding author taop@upenn.edu
Published on 15 March 2024 | https://doi.org/10.54254/2755-2721/47/20241343
ACE Vol.47
ISSN (Print): 2755-273X
ISSN (Online): 2755-2721
ISBN (Print): 978-1-83558-335-7
ISBN (Online): 978-1-83558-336-4

Abstract

In particular, LSTM and GRU are two frequently used models in stock price prediction. With this in mind, this study will test these two useful tools from three aspects, actual using, limitations and possible future improving. Based on the stock price of (APPL), Apple company from 2022 to 2023. There are a lot of past research shows that LSTM and GRU are useful in forecasting stock price. However, one important part to notice is the rely on historical data. These two models may find difficult to address the correct prediction and make real profit. As a result, the usefulness of LSTM and GRU are tested by the unstable stock market. Additionally, overfitting can be a big problem. To make the models more useful and eliminate limitations. In this research, there will be some real examples of change in stock price based on graphs. There will be some future strategy to solve issues on LSTM and GRU, from possible improvements on the current reliability on historical data, and the easily influenced stock market. Overall, LSTM and GRU can provide useful details based on the past data of certain stock. However, the limitations of these two models are a big issue.

Keywords:

Machine learning, LSTM, GRU, RNN

Pang,T. (2024). APPL stock price prediction based on LSTM and GRU. Applied and Computational Engineering,47,200-206.
Export citation

1. Introduction

Nowadays with the emerging of global economy, Stock Market is becoming the tool of livelihood to many people, because of its irreparability, participatory, profitability, liquidity, Price Volatility and Risk. Most importantly, people can make money out of it. With the develop of modern technology in finance, and data analysis. stock market has a long history which begins from 17th, in Europe, at that time it is basically done by mouth to mouth. After that in 19th, people using diagrams and pir charts to predict the volume of trading. People also developed fundamental analysis, which is to predict based on the company itself. These days with the help and computer, people are using mathematical models and statistical techniques to predicting. Based on that there are methods like Efficient Market Hypothesis, and High Frequency Trading are discovered [1]. One generation ago, academic financial economists commonly embraced the efficient market hypothesis. In the article, Malkiel uses the example: Refer to Eugene Fama's influential survey paper titled Efficient Capital Markets. The prevailing belief at the time was that securities markets were highly efficient in promptly incorporating information regarding individual stocks and the overall stock market. Previously findings indicate that high-frequency traders (HFTs) contribute to price efficiency by engaging in trading activities that align with permanent price shifts and counteract temporary pricing inaccuracies [2]. There are also some authors demonstrates on the method of (HFT) [3]. By challenging slower limit order traders, HFTs cause a welfare impact by displacing the most profitable limit orders. Hossain also has positive review on the method of (HFT) [4]. High-frequency trading (HFT) has had a beneficial impact in the past by reducing both the actual bid-ask spreads and the expenses associated with adverse selection.

This study will use some well-known strategies to predict certain stock’s price, for example, LSTM and GRU. In modern days, with the help of huge outcome from stock market and technology improvements, recurrent neural network is widely used. LSTM, which is one important method within Recurrent Neural Network (RNN). The reason why (RNN) is useful is that RNN is an artificial neural network, which is extremely useful for dealing with sequential data. With the understanding of that, time series data can be processed by RNN models, stock price data with the characteristic of changing daily, and past data follows the trend of time series, So RNN can be helpful in this field. Because of the ability of processing timeseries data, to do stock price forecasting RNN models are the right one to choose [5]. The usefulness of RNN models in predicting stock price is also mentioned by other researchers. During the process of future stock market price, RNN models are widely used because of its accuracy [6]. There is also another useful model called Convolutional Neural Network which can be applied in stock predicting, one finds out that Convolutional Neural Network (CNN) can be the foundation of deep learning model which is used to predict Stock price changes in Chinese stock market price [7]. Beside that TensorFlow is also used to help with the design of this model. In addition to Recurrent Neural Networks (RNN) and Convolutional Neural Networks (CNN), the model of Prophet, which is also a tool to forecast stock price that is designed by Facebook. Based on Prophet, users can process stock prices with the patterns of daily, weekly, annual as well as holiday stock price changes, with the help of regression model from Prophet. there are some researchers who compare the Prophet with LSTM, to decide which one is better [8]. This study will use Prophet, which is an advanced and widely adopted machine learning algorithm, to forecast the future stock price of one certain company [9]. The overall outcome of this test will posit that LSTM (Long Short-Term Memory networks) can surpass other models, for example Prophet.

The reason why this study started this research is because of the inherent volatility of stock price, where the public engage together to make some money out of it. however, only a few people can success in it. This study also wants to prove the usability and effectiveness of employing Long Short-Term Memory (LSTM) and Gated Recurrent Unit (GRU) models in stock price prediction. The following paper will follow a structured sequence, encompassing important details, for example, date source, and data time range, also a brief introduction to the two models that this study will use in this test, LSTM and GRU architectures. After that this study will test these two models and explain on the outcomes to decide whether they are useful in stock price forecast. Moreover, evaluations on that. Finally, this study will address some limitations and possible solutions of the current issues of LSTM and GRU models as well as a comprehensive conclusion of the whole research.

2. Data and method

To generate empirical research, the experiment data will be gathered from finance.yahoo.com, which is a reputable source of stock price data. The major focus will be stock price of APPLE (APPL). The time range will from June 2023 to September 2023. Both LSTM (Long Short-Term Memory) and GRU (Gated Recurrent Unit) models will be used to process the given data of (APPL), and the reason is to discern which model will yields more discernible outputs. Nowadays, researchers are using deep learning model to predict stock price, but there is a major issue which is overfitting, GRU’s benefits can be easily seen [10]. LSTM, which is Long Short-Term Memory constitutes a recurrent neural network (RNN) architecture in the concept of deep learning and natural language processing, (RNN) gains an extensive utilization. Because of the limitations within RNN, the development of LSTM is aiming to surmount specific constrains, particularly in the process of sequential data, like timeseries analysis and text. The network of LSTM offers an innovative solution. One big difference between RNN and LSTM is the remarkable aptitude for capturing protracted dependencies inherent in sequences; however, RNN architecture always have formidable changes for that. LSTM can facilitate through the integration of a memory cell and an intricate system of gates.

After discussing LSTM, another type of RNN called Gated Recurrent Unit (GRU) deserves mention. In this paper the author will utilize both methods to determine which one performs better. LSTM employs a short term memory approach, for data processing while GRU focuses on memory and boasts faster computation than LSTM. Compared to LSTM, GRU is less complex, because of the difference with its architecture, e.g., GRU only contains update and reset two gates, and LSTM has one output gate [11]. Similar to LSTM GRU incorporates gating mechanisms that effectively capture and retain information across sequences. These mechanisms involve an update gate and a reset gate enabling the model to adapt to sequences. Moreover, GRU offers the advantage of having parameters compared to LSTM resulting in improved efficiency particularly when working with smaller datasets. Its streamlined architecture combines the cell state and hidden state into an entity making GRU easier to implement and train. Additionally, like LSTM, GRU excels at handling dependencies within data, a capability in applications such as time series forecasting, natural language processing and speech recognition, in academic and industrial settings.

/word/media/image1.png

Figure 1. Apple Inc. (APPL) Stock Price Prediction (Photo/Picture credit: Original).

/word/media/image2.png

Figure 2. Residual Plot of (APPL) (Photo/Picture credit: Original).

3. Results and discussion

In this research, the author has utilized Python to implement two methods, for predicting stock prices specifically focusing on Apple Inc. (AAPL) Stock Price Prediction. The analysis involves studying stock data for AAPL including attributes such as Date, Open, High, Low, Close Adjusted Close and Volume. These attributes provide insights into the price dynamics of AAPL over time. For the study, one has used the Long Short-Term Memory (LSTM) model with a scope of two months from July 15th to September 15th in 2023. Throughout this period the research has demonstrated an analysis between AAPL stock prices and the corresponding predictions obtained from the models. This analysis reveals correlations and similar trends, between the two datasets showcasing the effectiveness of the examined models. Fig. 1 and Fig. 2 showcase the correlation, between the prices of APPL and the predicted prices revealing similarities in their peak values. The first chart visually represents how well the LSTM model captures the trend in stock prices. The lines depicting predicted, and prices follow a path indicating that the model has a good grasp of stock price movements general direction. By comparing predicted and actual prices one can evaluate the model’s accuracy in its predictions. If there is an alignment between these two lines, it suggests predictions whereas significant deviations imply room for improvement. The Residuals plot helps us determine whether the LSTM model successfully captures patterns within stock price data. If residuals (the differences between actual values) appear random without any pattern it indicates accurate predictions by the model. Therefore, based on insights, from the graph it appears that the LSTM model is functioning accurately.

/word/media/image3.png

Figure 3. APPL Stock Price Prediction using GRU (Photo/Picture credit: Original).

/word/media/image4.png

Figure 4. Training and Validation Loss Curves based on GRU (Photo/Picture credit: Original).

Seen from Fig. 3, for train data and the actual train data exhibit a pattern of stock price changes. They tend to follow a direction whether it is an increase or decrease. This information sheds light on the stock price fluctuations starting from 2022 until September 2023. The first graph demonstrates that the predicted prices move in a manner to the prices indicating that the model captures the underlying trends in the data. Moreover, the GRU model accurately forecasts turning points in stock prices, such as peaks and troughs. Such precise predictions of reversals or inflection points can be highly valuable, for traders and investors. As given in Fig. 4, One important aspect to consider is the convergence of the training process. The key observation here is whether both the training and validation loss curves reach a value over time. This indicates that the model is effectively learning and enhancing its ability to make predictions. A decreasing loss value suggests that the model is improving its fit to the training data. Initially there may be a difference, in loss, between the training and validation sets. Towards the end they tend to align closely and appear as a straight line. As illustrated in Fig. 5, the first thing that catches the attention is the performance of models or model configurations. RMSE measures how well predictions match values and lower values suggest performance. From this it is evident that the training model outperforms the testing model.

/word/media/image5.png

Figure 5. RMSE Comparison based on GRU (Photo/Picture credit: Original).

4. Limitations and prospects

Long Short Term Memory (LSTM) and Gated Recurrent Unit (GRU) models have become highly effective, in predicting stock prices by capturing relationships over time in financial data. Despite their achievements it is crucial to acknowledge the limitations of these models and explore ways to improve their abilities, in the future. There are a lots of limitations to consider:

Dependence, on Historical Data: LSTM and GRU models heavily rely on price and volume data to make predictions. While this context is valuable it can be a limitation when sudden market shifts or unexpected events occur, like crises or geopolitical developments. In these cases, the models may struggle to adapt resulting in predictions.

Stationary Data. Stock prices exhibit stationary behaviour meaning their statistical properties change over time. LSTM and GRU models designed for data may not effectively handle this non stationarity. This could require retraining of the models to maintain accuracy and make them less suitable for long term predictions.

Risk of Overfitting. The complexity of LSTM and GRU models makes them prone to overfitting. Overfitting happens when a model captures noise or random fluctuations in the training data of underlying trends. As a result, the model may perform well during training. Fail to generalize to unseen data leading to poor performance, outside the training set.

To address these limitations, various strategies and research directions can be exploredVarious techniques can be used by researchers and practitioners to address the issue of overfitting, such, as incorporating dropout layers and weight decay. These approaches encourage the model to focus on the features in the data resulting in improved generalization. Additionally tuning hyperparameters like the number of layers, units and learning rates can lead to enhanced model performance. Exploring configurations within the hyperparameter space systematically can help identify settings that yield better outcomes. To further enhance prediction accuracy a combination of LSTM and GRU models with deep learning architectures, like neural networks (CNNs) or transformer models can be employed. This approach allows for capturing features in the data. Moreover integrating reinforcement learning algorithms and attention mechanisms can contribute to adaptability when facing changing market conditions. The future of predicting stock prices using LSTM and GRU models holds possibilities:

Enhanced Feature Engineering. By incorporating data sources like analysing news sentiment, economic indicators, and social media trends one can enrich the features used for prediction. This approach allows us to capture a range of information that influences stock prices.

Leveraging Transfer Learning. Drawing from trained neural networks and domain knowledge in areas such, as portfolio optimization or risk management can speed up model training and improve performance. Transfer learning enables models to understand financial dynamics.

Enhancing Explain ability. Transparency and interpretability are highly valued in the industry. By integrating AI techniques into LSTM and GRU models one can gain insights into how the models make decisions making predictions more understandable and actionable for traders and investors.

Harnessing Ensemble Methods. Combining predictions, from LSTM and GRU models or using architectures can mitigate the risks associated with individual models. Ensemble methods enhance prediction robustness and overall performance of stock price prediction systems.

Addressing Ethical Considerations. As AI driven trading strategies become ethical considerations and regulatory compliance take centre stage.

These advancements will shape the landscape of stock price prediction by empowering traders and investors with accurate insights while ensuring ethical standards are upheld. In order to ensure transparent adoption of AI, in the industry it is important for future research to focus on developing models and practices that adhere to ethical standards and regulatory guidelines. While LSTM and GRU models have shown success in predicting stock prices it is crucial to acknowledge their limitations and explore ways to improve them. By addressing these limitations and embracing developments one can achieve accurate and reliable predictions of stock prices benefiting traders, investors and financial institutions.

5. Conclusion

To sum up, this paper discusses the use of LSTM and GRU models for predicting the stock prices of APPL within the time range of 2022 to 2023. The study includes six graphs: one for sample data two for LSTM model results and three for GRU model results. Although LSTM and GRU models have demonstrated their potential in predicting stock prices they face challenges related to dependence on data, non-stationary behaviour, and overfitting. Overcoming these limitations requires implementing regularization techniques tuning hyperparameters effectively and integrating hybrid models with deep learning architectures. Looking ahead advanced feature engineering techniques along with transfer learning methods will play a role, in enhancing the accuracy and reliability of stock price predictions while also considering aspects. Studying LSTM and GRU models, for predicting stock prices is valuable because they have the potential to assess market efficiency help with risk management and improve trading strategies. These models provide insights into investor behaviour, market anomalies and techniques for preprocessing data, which encourages research. Moreover, considering their implications, limitations in predictability and applications, in real world finance makes this research area significant and diverse.


References

[1]. Malkiel G B 2003, The Efficient Market Hypothesis and Its Critics, Princeton University CEPS Working Paper p 91.

[2]. Brogaard J, Hendershott T and Riordan R 2013, High Frequency Trading and Price Discovery, Working Paper Series p 1602.

[3]. Goldstein A M, Kwan A and Philip R 2021, High-Frequency Trading Strategies, University of Sydney Business School Date Written p 5.

[4]. Hossain S, 2018, The Intersectionality of High Frequency Trading (HFT) and Market Fragmentation and their impact on Liquidity: New Evidence vol 15 p 102.

[5]. Zhu Y 2020, Stock price prediction using the RNN model

[6]. J Phys: Conf Ser vol 1650 p 032103

[7]. Islam S B, Hasan M M and Khan M M 2021, Prediction of Stock Market Using Recurrent Neural Network, IEEE 12th Annual Information Technology, Electronics and Mobile Communication Conference (IEMCON) pp 479-483.

[8]. Chen S and He H 2018, Stock Prediction Using Convolutional Neural Network, IOP Conf Ser: Mater Sci Eng vol 435 p 012026

[9]. Kaninde S, Mahajan M, Janghale A and Joshi B 2022, Stock Price Prediction using Facebook Prophet, 6th International Conference for Convergence in Technology (I2CT) pp 1-7.IOP Conf Ser: Mater Sci Eng vol 435 p 012026

[10]. Alshara A 2022, Stock Forecasting Using Prophet vs. LSTM Model Applying Time-Series Prediction, International Journal of Computer Science and Network Security vol 22(2) p 185.

[11]. Chen C, Xue L, Xing W 2023, Research on Improved GRU-Based Stock Price Prediction Method, Appl Sci vol 13(15) p 8813.

[12]. Lin Z, Tian F and Zhang W 2022, Evaluation and Analysis of an LSTM and GRU Based Stock Investment Strategy, AEBMR vol 226 pp 1615–1626.


Cite this article

Pang,T. (2024). APPL stock price prediction based on LSTM and GRU. Applied and Computational Engineering,47,200-206.

Data availability

The datasets used and/or analyzed during the current study will be available from the authors upon reasonable request.

Disclaimer/Publisher's Note

The statements, opinions and data contained in all publications are solely those of the individual author(s) and contributor(s) and not of EWA Publishing and/or the editor(s). EWA Publishing and/or the editor(s) disclaim responsibility for any injury to people or property resulting from any ideas, methods, instructions or products referred to in the content.

About volume

Volume title: Proceedings of the 4th International Conference on Signal Processing and Machine Learning

ISBN:978-1-83558-335-7(Print) / 978-1-83558-336-4(Online)
Editor:Marwan Omar
Conference website: https://www.confspml.org/
Conference date: 15 January 2024
Series: Applied and Computational Engineering
Volume number: Vol.47
ISSN:2755-2721(Print) / 2755-273X(Online)

© 2024 by the author(s). Licensee EWA Publishing, Oxford, UK. This article is an open access article distributed under the terms and conditions of the Creative Commons Attribution (CC BY) license. Authors who publish this series agree to the following terms:
1. Authors retain copyright and grant the series right of first publication with the work simultaneously licensed under a Creative Commons Attribution License that allows others to share the work with an acknowledgment of the work's authorship and initial publication in this series.
2. Authors are able to enter into separate, additional contractual arrangements for the non-exclusive distribution of the series's published version of the work (e.g., post it to an institutional repository or publish it in a book), with an acknowledgment of its initial publication in this series.
3. Authors are permitted and encouraged to post their work online (e.g., in institutional repositories or on their website) prior to and during the submission process, as it can lead to productive exchanges, as well as earlier and greater citation of published work (See Open access policy for details).

References

[1]. Malkiel G B 2003, The Efficient Market Hypothesis and Its Critics, Princeton University CEPS Working Paper p 91.

[2]. Brogaard J, Hendershott T and Riordan R 2013, High Frequency Trading and Price Discovery, Working Paper Series p 1602.

[3]. Goldstein A M, Kwan A and Philip R 2021, High-Frequency Trading Strategies, University of Sydney Business School Date Written p 5.

[4]. Hossain S, 2018, The Intersectionality of High Frequency Trading (HFT) and Market Fragmentation and their impact on Liquidity: New Evidence vol 15 p 102.

[5]. Zhu Y 2020, Stock price prediction using the RNN model

[6]. J Phys: Conf Ser vol 1650 p 032103

[7]. Islam S B, Hasan M M and Khan M M 2021, Prediction of Stock Market Using Recurrent Neural Network, IEEE 12th Annual Information Technology, Electronics and Mobile Communication Conference (IEMCON) pp 479-483.

[8]. Chen S and He H 2018, Stock Prediction Using Convolutional Neural Network, IOP Conf Ser: Mater Sci Eng vol 435 p 012026

[9]. Kaninde S, Mahajan M, Janghale A and Joshi B 2022, Stock Price Prediction using Facebook Prophet, 6th International Conference for Convergence in Technology (I2CT) pp 1-7.IOP Conf Ser: Mater Sci Eng vol 435 p 012026

[10]. Alshara A 2022, Stock Forecasting Using Prophet vs. LSTM Model Applying Time-Series Prediction, International Journal of Computer Science and Network Security vol 22(2) p 185.

[11]. Chen C, Xue L, Xing W 2023, Research on Improved GRU-Based Stock Price Prediction Method, Appl Sci vol 13(15) p 8813.

[12]. Lin Z, Tian F and Zhang W 2022, Evaluation and Analysis of an LSTM and GRU Based Stock Investment Strategy, AEBMR vol 226 pp 1615–1626.