Iraqi Stock Market Prediction using Proposed Model of Convolution Neural Network

: The stock market, sometimes known as the share market, is a marketplace for stock sellers and buyers. A stock exchange is defined as a mechanism through which stockbrokers can purchase and sell shares, bonds, and other assets. Many businesses, regardless of their industries or domains, make their shares or stocks available on the stock exchange. For value investors, predicting the price direction of a company is crucial. Due to its volatile nature, forecasting the stock market is a challenging task. Accurate stock forecasting is essential for building important trading systems that help customers purchase and sell equities. Due to the dynamic nature and non-stationary nature of data, stock price prediction and modeling is a difficult endeavor. By decreasing investment risks, developing a successful stock prediction system would assist shareholders in making profitable investment decisions. Using deep learning-based methodologies, this research provides a deep learning-based strategy for dramatically boosting stock forecasting accuracy. This study is a comparison between the results of LeNet and the proposed model for the prediction of Iraqi stock marketing for five years (from 2017 to 2021). The results of the proposed model demonstrate the average training accuracy is 99%, the average validation accuracy is 95%, the average training loss is 0.28% and for validation, loss is 0.014%.


Introduction
One of the most common investment activities is stock trading on the stock exchange. Investors have created a variety of stock research methods in the past to assist them in predicting the direction of stock price movement. Projecting future share prices and modeling them based on news and current financial data is extremely useful to investors. Investors want to know if a stock will decline or rise over a specific time period (Chen et al., 2016). They devised a number of analytical methodologies based on current and past financial data and other information about the firm in order to anticipate how a company in which an investor wants to invest would perform in the future. Technical analysis is used by investors to examine and forecast a company's future stock price using financial balance sheets as well as other statistics that represent the company's health. Forecasting the direction of a stock's price is critical for value investors (Bekiros, 2010). Forecasting the stock market is a difficult challenge due to its fluctuating nature. Accurate stock forecasting is critical for developing critical trading methods that can assist clients in buying and selling stocks (Zhang and Yang, 2016). Generally, stock data suffers from two major issues: Noise as well as uncertainty.
Uncertainty in stock valuations can be attributed to a variety of external factors, such as market conditions, global events, political order, corporate worth, and so on. All of which can impact stock market trading. Simultaneously, stock market fluctuations are unpredictable, resulting in noisy data (Cavalcante et al., 2016).
The emergence of trading algorithms has unquestionably altered the stock market. Algorithms make it simple to react quickly to certain stock market developments. Additionally, deep learning algorithms made it much easier for analysts to develop models for predicting stock prices (Wang and Hajric, 2020). Because of the introduction of deep learning, a new model based on previous data may now be constructed. The primary idea was that by utilizing machine learning and training it on past data, it was feasible to forecast the movement of the stock price as well as the ratio of the movement over a specified time period. Over time, investors have been unable to forecast the percentage increase in stock prices. This knowledge, on the other hand, is critical for investors when choosing equities. Typically, investors seek out stocks that will significantly increase in value (Wang et al., 2012).

Related Work
The aim of this part is to present and discuss the most important previous studies in the field of forecasting and detecting financial stumbles. And also, the most important findings of previous research. The most common related works on the stock market are. Jain et al. (2018) A comparison of different Deep Neural Network approach used for stock price prediction has been carried out. Short long-Term good Memory Networks, Conv1D-LSTM, and Convolutional Neural Networks are some of the networks utilized pertinent to the problem. Daily stock price data is used to train the various neural network models, which contain low, high, close, and open price values. It has been used to forecast the closing value of the next day. Their forecast is based on the last five days of data. The outcomes of various models are compared to one another. This research introduces the Conv1D-LSTM deep neural network, which combines layers from two different techniques-LSTM and CNN-to predict the stock price. MAE, MAPE, as well as RMSE are used to assess the performance of the models. In comparison to CNN and LSTM, the Conv1D-LSTM model exhibits relatively few mistakes. The Conv1D-LSTM network has been shown to be effective at forecasting stock prices. Depending on the nature of the stock hyperparameters, various changes may be required. Khan et al. (2020), this study used algorithms to analyze the impact of financial news and social media data on the accuracy of stock market predictions over a 10-day period. To increase prediction performance and quality, data sets are subjected to feature selection and spam tweet reduction. This study also aimed to identify stock markets that are more affected by financial media and news and are thus more difficult to anticipate. Examine the results of several strategies in order to obtain a consistent classifier. Finally, deep learning is used and certain classifiers are combined to reach the highest prediction accuracy possible. According to our findings, the maximum prediction accuracy of 80.53 and 75.16%, respectively, was obtained when financial news and social media were used. Additionally, it is demonstrated that forecasting the New York and Red Hat stock markets is challenging because the IBM and New York stock markets are more influenced by social media, whereas the Microsoft and London stock markets are influenced by financial news. Consistency is established for the random forest classifier and its ensemble reaches a maximum accuracy of 83.22%. Shaikh et al. (2021), the article's major objective is to forecast any company's stock price using cutting-edge machine learning algorithms. The machine learning model is fed by two distinct inputs: Human sentiment and historical pricing data and the result is displayed as a graph with a future forecast and a label (negative or positive neutral). A Recurrent Neural Network (RNN), a Long-term Short-Term Memory (LSTM) model, and sentiment analysis are used to perform the prediction. Following that, the model of machine learning is trained using the assessed results and a diverse set of data points. Sentiment analysis is a process that takes public sentiment from social media and categorizes it. Rath et al. (2022), various machine learning algorithms for market forecasting is discussed. supervised machine learning technologies like support Neural Networks (NN), Vector Machines (SVM), Decision Trees (DT), and Random Forests (RF), For the purpose of forecasting the stock market. This research used the above algorithms to analyze stock market data from the Bombay Stock Exchange (BSE), with accuracy as the primary criterion for recommending the best algorithm for making better predictions.
Christy Jeba Malar et al. (2022), Stock experts and Finance experts are always working on this study in order to forecast future stock prices, which aids in selecting whether to sell or purchase stocks for profit. Stock markets encourage investment by pooling resources, allowing businesses to raise capital to expand their operations. There are millions of resources available in the stock market. People worry about finding good resources from a pool of resources as an investor.
Investors will benefit from the suggested stock price prediction model since it will assist them in pricing the resource. The research proposes a unique approach to stock market forecast management over time based on deep learning.

Convolution Neural Network
The most powerful deep learning approaches are CNNs, which have been utilized to solve a wide range of computer vision problems. In a conventional CNN design, pooling layers and convolutional layers alternate. In contrast to traditional machine learning methods, the primary objective of this sequence of layers is to derive high-level features, thus avoiding the human feature engineering stage. Due to the fact that the convolutional layers generate a big feature map, the pooling layers are used to reduce it. Additionally, multiple entirely connected layers are added at the network's termination to generate the final output and introduce nonlinearity into the network (Kamilaris and Prenafeta-Boldú, 2018).
While CNN's are most commonly employed to analyze two-dimensional data like images, One-dimensional data, such as time series stock or financial data, can likewise be handled using this technique. To process historical data in this experiment, a 1D-CNN is employed. The structure of the stock market data input was also taken into consideration when choosing the convolutional kernels (Tsuruta et al., 2000). A CNN is typically made up of 3 layers: Pooling, convolutional, and fully linked layers. Activation functions, dropout, convolutions, pooling, fully connected blocks, and batch normalization are just a few of the components/techniques used in these layers, which can be combined in a variety of ways. The following aspects can be used to construct a CNN structure (Yamins et al., 2014): A. The input data can be in one of three formats: Onedimensional, two-dimensional, or three-dimensional. This data can come from a variety of video sources, including 3D images, audio, and sensors B. Convolutional layers are in charge of performing feature extraction tasks. It performs the extraction by convolution the input and then feeding the convolution result to the next layer's input. Multiple filters, a kernel size, stride, and padding are used to create the convolution processes, which result in the generation of a feature map after applying an activation function such as the Tanh or ReLU function (LeCun et al., 1989) C. Pooling layers are often used after a convolutional layer.
They store the data that the feature maps make. When you're processing an image, for example, these layers cut down on the amount of data that needs to be input. This leads to faster computation times, a faster training process, and more accurate feature detection. Average pooling and Max pooling are the most often used algorithms on these layers (Huang and Lee, 2021) D. The fully connected layer is a backpropagation neural network in the classic sense that it processes the characteristics generated by the previous layers. There are two types of tasks that the network can do: One is called regression and the other is called classification Taking into account the previous layers, it is important to give a quick explanation of the most important parts of CNN: A. Kernel: A kernel runs/slides the input in each of the convolution layers. Kernels are composed of mathematical processes that result in a matrix dot product known as an activation map. This procedure is repeated on the same input several times (specified by the number of filters), each time using a different kernel. Each filter, when combined with its appropriate kernel, extracts distinct properties from the input. Consider a basic instance in which the first layer of a two-dimensional convolutional neural network receives an input of a grayscale image with a resolution of 28 × 28. The input will be a two-dimensional matrix with pixel values for each element (784 pixels). The kernel size determines the dimension of the kernel matrix, which is a weight matrix. The most commonly used kernel sizes are 5 × 5 or 3×3, which are initialized using the initialization procedure. To generate an activation map, each pixel is multiplied by the kernel matrix and multiple filters are typically used, resulting in multiple activation maps per layer. The padding parameters and stride (Yamashita et al., 2018) influence the way these maps are built (as well as their size) B. Stride: The stride value specifies the direction in which the kernel traverses the input data. The value "one" is the most common, indicating that the kernel traverses the input one column at a time. The kernel will move two columns if the value is two and so on. The stride parameter can be used to get different kinds of information (LeCun et al., 1989) C. Padding: Padding is a technique that prevents information loss at the input data boundaries due to kernel operations. It is accomplished by adding zeros around the input margins. Using the grey image as an example and a kernel size of 3×3: Without padding, the first pixel would be processed once, the second pixel twice and some pixels (those outside the image boundary) nine times. Padding allows all pixels to be looked at equally, which helps the model learn (Ma et al., 2017) D. Activation Function: Activation functions add nonlinearity by performing operations on activation maps, which allows for complex input interactions to be added to the model. This can be accomplished by submitting activation maps to activation functions, which will generate feature maps. Activation functions like ReLU or Sigmoid can be used to do this. Each has, thus, different output and different behavior. For instance, a Sigmoid will analyze each value in the activation map and output 1 or 0, whereas a ReLU will output the same value for negative and positive values, resulting in a range of features E. In this case, pooling strategies are used to make sure there isn't too much overlap between the features that are conjoined and the features that are being analyzed. Pooling can be treated in a variety of ways, each of which consists of a set of mathematical operations that are processed in the same way as kernel operations. For example, max-pooling includes running the input with a specified spatial stride and neighborhood and then obtaining the maximum value inside the relevant region. The average pooling process is identical to the maximum pooling procedure, except that the maximum is omitted. In a nutshell, it gives a quick look at the outputs in the immediate area (Yamins et al., 2014) F. Dropout is a technique for avoiding overfitting that may be used with either purely convolutional or linked layers. It entails randomly nullifying some of the neural network's connections, which means that individual neurons can be disposed of without affecting the model's output. Additionally, the method enhances model generality (Huang and Lee, 2021)

Proposed Work
This proposal has been worked on for datasets for Iraqi stock markets and has been done through the work of a system of reading and prediction over the past five years (from 2017 to 2021).

a. Data Pre-Processing
Data preparation is crucial when attempting to extract information from data sets in order to aid in forecasting. Due to the possibility, that the initial data has a high level of noise, it is critical to minimize it so that it does not affect the final result. In addition, some data elements may be useless, so they should be left out of data training in order to be as efficient as possible.

b. Preparing Dataset
In this step, the data is separated into two sections: One for testing purposes and the other for training purposes, as well as the data in the five databases, has been divided into 70% training and 30% testing. Figure (1) illustrates preparing datasets for training and testing models for the Iraq stock market for years (from 2017 to 2021), and

c. Training CNN Models
In the proposed work, training and testing datasets with two models are shown and a comparison has been made between the proposed models and the LeNet model for training and predicting the Iraqi stock market. The architecture of the LeNet model consists of five layers as in Fig. (2). Whilst the architecture of the proposed model which consists of ten layers is illustrated in Fig. (3).

Results and Discussion
Several tests have been conducted on the proposed system; this section has been dedicated to displaying the results for each model with all datasets: Case 1: Hen training datasets use the LeNet model, Fig. (4) illustrates the results of accuracy of the LeNet model, as well as Fig. (5), illustrates the loss of the LeNet model The comparison between the set of results for the LeNet model such as the comparison between (accuracy of training and validation) and (loss of training and validation) by applying the model to the five datasets is illustrated in Table (2). Acknowledgment: Case 2: When training datasets use the proposed model, Fig. (6) illustrates the results of accuracy of the proposed model, as well as Fig. (7), illustrates the loss of the proposed model The comparison between the set of results for the proposed model such as the comparison between (accuracy of training and validation) and (loss of training and validation) by applying the proposed model to the five datasets is illustrated in Table (3).      Fig. 1: a, b, c, d and e datasets preparing

Conclusion
In this post, we developed a CNN model for stock forecasting and used the CONV1D function to analyze the convolutional layer's 1D data. Additionally, I've preprocessed the stock data that will be included in the model in order to improve its performance. Even when the source data is 1D sequential, the findings show that the suggested CNN model is dependable and capable of producing predictions. There are various fascinating research avenues to explore. Can create predictions using enhanced stock data, as the movement of the stock is not just determined by the close, open, low, and high prices. Additionally, we may do a comparison of which characteristics are critical to the outcome. It is possible to make use of additional data sets to determine whether the outcome is superior, as the amount of data used in deep learning is critical. Another convolutional neural network arch can be used.