Forecasting JPFA Share Price using Long Short Term Memory Neural Network

—To invest or buy and sell on the stock exchange requires understanding in the field of data analysis. The movement of the curve in the stock market is very dynamic, so it requires data modeling to predict stock prices in order to get prices with a high degree of accuracy. Machine Learning currently has a good level of accuracy in processing and predicting data. In this study, we modeled data using the Long-Short Term Memory (LSTM) algorithm to predict the stock price of a company called Japfa Comfeed. The main objective of this journal is to analyze the level of accuracy of Machine Learning algorithms in predicting stock price data and to analyze the number of epochs in forming an optimal model. The results of our research show that the LSTM algorithm has a good level of accurate prediction shown in mape values and the data model obtained on variations in epochs values. All optimization models show that the higher the epoch value, the lower the loss value. Adam's Optimization Model is the model with the highest accuracy value of 98.44%.


Introduction
The economy of a country is strongly influenced by the role of the capital market. The capital market is a long-term financial instrument in which there are stock buying and selling transactions, funding facilities for companies, as well as a means for investment activities. Several countries that follow the market economy system, the source of the country's economic progress is strongly influenced by the capital market, because the capital market is alternative source of funds for the companies that join it. In the capital market, one form of investment that can be made is investing in stocks. Shares are a form of participation in a company or business entity that invests in the capital market [1].
Stock prices are not something constant or stable but fluctuate. Fluctuations in stock prices are caused by several factors, including the demand and supply of these shares. Demand and supply are caused by many things, such as the company's performance, the field the company is in, as well as several dominant factors such as inflation, currency exchange rates, interest rates [2].
Demand and supply are caused by many things, such as the company's performance, the field the company is in, as well as several dominant factors such as inflation, currency exchange rates, interest rates. In Indonesia, there is one company in the agree-food sector, namely JAPFA Comfeed. PT Japfa Comfeed Indonesia, Tbk. is one of the largest and leading agri-food companies in the country. We are a producer of quality and reliable animal protein, which faithfully serves the needs and has become the pride of Indonesia since 1975. because Indonesia is an agricultural country, this company is in great demand by investors to invest [3].
According to Anthony Wijaya and Nanik Linawati, the higher the stock price, the higher the company's value. The increase in share prices was triggered by the higher investor valuation of these shares [4].
Seeing the condition of stocks that continue to fluctuate every day, investors need to pay attention and study banking data in the past, as a strategy for investing. This is very important because investors can find out the prospects for the condition of the stock prices in the company. There are many methods that can be used to predict stock prices. Machine Learning is one of the methods to approach predicting stock prices. Machine Learning is a sub of Artificial Intelligence which aims to increase knowledge or performance [5][6] [7].

Forecasting
Forecasting is a process of systematically estimating something that is most likely to happen in the future based on past and present information that is owned, so that the error (the difference between something that happened and the forecast result) can be minimized. Predictions do not have to give a definite answer to what will happen, but try to find answers as close as possible to what will happen [8].

Recurent Neural Network
Recurrent Neural Networks (RNN) is a form of Artificial Neural Networks (ANN) architecture specifically designed to process sequential data. RNN does not throw away information from the past in its learning process. This is what distinguishes RNN from ordinary ANN. RNN is capable of storing memory/memory (feedback loop) which makes it possible to recognize data patterns well, then use them to make accurate predictions. The way in which RNN can store information from the past is by looping in its architecture, which automatically keeps information from the past stored [9].
The idea behind the RNN architecture is how to exploit sequential data structures. The name RNN comes from the fact that it operates on a iterative basis. This means that the same operation is performed for every element of a sequence, with the output depending on the current input and the previous operation. The point is that RNN focuses on the nature of data where the instance of the previous or current time (t) affects the instance of the next time (t + 1).
[10] [11]. In Figure 1, the image on the left is a circuit diagram, where the black squares represent the time delay of one time step. The diagram shows an RNN in an unrolled position to a full network. While the figure on the right shows an RNN that has been unfolded (unrolled / unfolded) to become a full network so that the sequence is complete [5].

Long Short Term Memory
Long Short Term Memory (LSTM) is a development of the RNN architecture. Hochreiter & Schmidhuber are the figures behind the emergence of the LSTM method which was first introduced to the public in 1997. LSTM emerged because there was dissatisfaction in the RNN architecture for processing long-term sequential data. RNN has the disadvantage that the gradient disappears when it adopts the backpopagation algorithm. LSTM emerged because there was dissatisfaction in the RNN architecture for processing long-term sequential data. RNN has the disadvantage that the gradient disappears when it adopts the backpopagation algorithm [12]. There are several previous studies using the LSTM Algorithm, including research to predict product sales [13], and research on motor conditions [14].
LSTM is said to be the development of RNN because basically they have the same structure which consists of input layer, hidden layer, and output layer. In RNN, the hidden layer only consists of one simple layer with the tanh activation function as shown in figure 2 [13].

Methods
This research will be carried out in several trial stages, including preprocessing, LSTM data modeling, data training process, data testing process, and data visualization. Stock data was taken from 16 February 2018 to 16 February 2023. In the second stage, the process of sharing training data and testing data was carried out where 75% was for training and 25% for testing. In the trial process, three different optimizers were used including Adam, RMSProp, and SGD. In addition, the trial also uses variations of epochs, including 25, 50, 75, and 100 and using 64 batch. The last stage, visualizes the trial data by displaying training data, actual data, and predictions. The research flow diagram can be seen in figure 3.

Collecting Data
Stock data was obtained by taking JPFA stock data from 16 February 2018 to 16 February 2023. Stock data includes date, stock price when it was opened on that day, highest price, lowest price, closed stock price and stock transaction volume. Sample data can be seen in the table 1. Japfa's stock data comes from yahoo finance [15] and the stock data taken includes the date, open, close, high, low and volume columns. Date is the date, month and year data for stock data issued at the time the stock market opens. Open is stock price data for the first time making a transaction that day. High and Low are daily price movements to sell or buy stocks rationally. Close is the stock price when all trading on the stock exchange ends. In this study, the focus is on daily close stock prices as a reference or input data to be processed for training data and testing data. So that the form of this research data can be seen in table 2.

Preprocessing Data
In the preprocessing of the data, segmentation or grouping of data will be carried out from the data retrieval process on yahoo finance. Data taken as many as 1252 data based on Japfa stock data. Sequentially taken 75% of the data (939 data) for training and 25% of the data (313 data) used for testing. Illustration of data segmentation can be seen in Figure 4.

LSTM Model Design
LSTM is a variation of Recurrent Neural Network (RNN) which is used to solve hidden layer problems. The essence of the LSTM algorithm is to incorporate non-linear and dependent control into RNN cells [16], on the other hand to ensure the gradient of the objective function by observing the signal does not disappear. LSTM is used to overcome vanishing gradients or situations when the gradient is 0 or close to 0 by passing through the gate mechanism [17]. The LSTM algorithm combines the previous state, with the current memory and input values. For the level of efficiency, LSTM is able to record longterm dependencies. Based on figure 5, the LSTM has three gates including the Forget gate ( ) which is used to determine the information to be eliminated from the cell using the sigmoid layer by activating the Relu function. The input gate ( ) is used as forwarding information from the sigmoid layer which will be updated and the tanh layer will be changed to a vector that will be updated. The gate output is used to display the contents of the memory cells in the LSTM output process. In the LSTM process, the first step is to terminate information from −1 by using a forget gate. This gate has the task of reading the values of −1 and , resulting in a value between 0 to 1, for each element in −1 . When formulated, it will form the following equation [11].
For elements in −1 it is possible to store gender subject information temporarily, so that the correct pronoun can be used. When looking at new subjects, the old elements in −1 can be removed. The next process, the input gate decides which value to update. Then, for the tanh layer, generate a new context vector candidate ̃ . Therefore it will be merged between the two to make updates to the context later. So, in this case the process can be formulated as follows [11]. Now it will be done to update the old context −1 into the new context . To eliminate things that have been decided, the forget gate process ( ) in equation (1) is multiplied by the old context in equation (2) and equation (3). Then, a new equation will be obtained as follows [11]. In the output gate process, cell and sigmoid layers will be updated to decide what parts of the context will be generated. So the following equation will be obtained [11].
Where for sigma () is the sigmoid activation function with a range of values between -1 and 1 then tanh is the target activation function with a value (-1,1) while , , , is the matrix weight and for −1 is the hidden the previous state as well as , , , are vectors of can.

Result and Disccusion
This chapter will discuss the results of research conducted using the Japfa stock dataset from 2018-2023 by dividing 75% training data and 25% testing data by emphasizing the open price column stock data. In the process of running the LSTM algorithm it is divided into several processes including the use of the optimizer Adam, SGD and Rmsprop with variations of epochs 25, 50, 75 and 100.
The dataset used in this research is ordered from 16 February 2018 to 16 February 2023. The data analysis process using machine learning is focused on the close price column, which is the daily closing price for each stock data. The data is visualized in the form of a line chart using Python programming on the Google Colabs platform. Visualization of Japfa stock data in the Close column can be seen in Figure 6. After testing each optimization and epoch variation using the data provided, the visualization results of prediction graphs with Adam Optimization can be seen in Figure 6 to 10, SGD Optimization Results can be seen in Figure 11 to 14, and RMSprop optimization results can be seen in Figure 15 to 18.

Result of Accuracy Testing
The accuracy test results use the 1-Mean Absolute Percentage Error (MAPE) formula. The experimental results used the 3 types of optimization that have been mentioned, and 4 variations of epoch values. The results of the Accuracy Value can be seen in Table 3 and Visualization using the Line Chart can be seen in Figure  19.  figure 19 it is known that the highest accuracy value is obtained in Adam optimization with an epoch value of 100 with an accuracy value of 98.44% and the lowest accuracy value is obtained in SGD optimization with an epoch value of 25 with an accuracy value of 92.04%. In Adam and SGD Optimization, the higher the epoch value used, the better the accuracy value obtained. However, the RMSprop optimization does not apply. The accuracy value of the optimization is not too influential based on the epoch. In the RMSprop optimization the highest accuracy value is obtained at epoch 25.

Result of Loss Testing
The Loss test results use the Mean Squared Error (MSE) formula. The experimental results used the 3 types of optimization that have been mentioned, and 4 variations of epoch values. The results of the Loss values can be seen in Table 4 and Visualization using the Line Chart can be seen in Figure 20.

Result of Total Computing Time Testing
The total computational test results use the sum of the computational calculation results for each epoch experiment contained in the library. The experimental results using the 3 types of optimization that have been mentioned, and 4 variations of epoch values can be seen in Table 5 and visualization using the Line Chart can be seen in Figure 21.

Conclusion
In this study, several experiments were obtained including analyzing the optimization model, epoch