{'fraction_non_alphanumeric': 0.03065173116089613, 'fraction_numerical': 0.011575016972165649, 'mean_word_length': 4.825786039153648, 'pattern_counts': {'":': 0, '<': 0, '<?xml version=': 0, '>': 0, 'https://': 3, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
Generative Adversarial Network (GAN) and Enhanced Root Mean Square Error (ERMSE): Deep Learning for Stock Price Movement Prediction

The prediction of stock price movement direction is significant in financial circles and academic. Stock price contains complex, incomplete, and fuzzy information which makes it an extremely difficult task to predict its development trend. Predicting and analysing financial data is a nonlinear, time-dependent problem. With rapid development in machine learning and deep learning, this task can be performed more effectively by a purposely designed network. This paper aims to improve prediction accuracy and minimizing forecasting error loss through deep learning architecture by using Generative Adversarial Networks. It was proposed a generic model consisting of Phase-space Reconstruction (PSR) method for reconstructing price series and Generative Adversarial Network (GAN) which is a combination of two neural networks which are Long Short-Term Memory (LSTM) as Generative model and Convolutional Neural Network (CNN) as Discriminative model for adversarial training to forecast the stock market. LSTM will generate new instances based on historical basic indicators information and then CNN will estimate whether the data is predicted by LSTM or is real. It was found that the Generative Adversarial Network (GAN) has performed well on the enhanced root mean square error to LSTM, as it was 4.35% more accurate in predicting the direction and reduced processing time and RMSE by 78 secs and 0.029, respectively. This study provides a better result in the accuracy of the stock index. It seems that the proposed system concentrates on minimizing the root mean square error and processing time and improving the direction prediction accuracy, and provides a better result in the accuracy of the stock index.


Introduction
The stock market is an organized financial institute; shares and currency are bought and sold governed by the forces of demand and supply. The main purpose of a stock market is to serve as a primary and secondary market for an investor facilities price discovery and indicating economic activity. Stock price contains complex, incomplete and fuzzy information which makes it an extremely difficult task to predict its development trend [1]. Fluctuating financial data depend on a myriad of correlated constantly changing factors [2]. To predict the stock price, the traders use fundamental technical analysis methods. The fundamental analysis of exchange market suggests methods for the stock price to be used for prediction.
Several artificial neural network (ANN) models have been compared against the traditional model for stock exchange prediction [3]. The standard ANN technique was used in the last two decades in the stock exchange price prediction and trading strategies. However, various feature extraction methods were used for stock price prediction. Little researches have manifested that ANN has some limitations and it will not fit the stock price prediction ability. In another hand, the Deep learning techniques have addressed to overcome limitations and showed accurate results in several fields such as natural language, speech recognition and image analysis and recognition [3].
Deep Neural Network learning has been successfully implemented in several applications including speech and voice recognition and led towards to conclude that the deep learning techniques have performed well in the time-series data [4]. So, it seems possible that deep learning can be implemented to stock exchanges data as well. Nevertheless, accurate stock exchange prediction is considered chaotic. Furthermore, the logical analysis has shown that all current and new information results in the unpredicted stock price, thus this subject is still considered an open area for research [5]. So to attract an investor, an accurate predictive model is a major part of the stock exchange prediction model. Some requirements must be considered in defining an accurate model which is the direction prediction accuracy and forecast error during training and testing of the model. The studies of deep learning in the stock exchange have used a wide range of techniques and algorithms to improve the prediction accuracy and forecast error loss during the kerning and testing of the model. The purpose of this paper is to enhance the prediction accuracy by minimizing the stock price direction prediction and forecast losses. The LSTM based RNN doesn't verify the correctness of the predicted value with the actual value during training and testing of the model leading to the increase in the value of Root Mean Square Error (RMSE). The research aims to improve the predictive performance of the stock price. This study proposes a Generative Adversarial Networks GAN as the combination of two neural networks (i.e. Generator and Discriminator) [6]. Stock data is typical time series, and the model G (Generator) is based on the LSTM model, which is broadly used for time series prediction. To estimate the probability of whether a sequence comes from the dataset or being predicted by generative model G, Convolutional Neural Network (CNN) was selected as discriminative model D to perform convolutional operations on one-dimensional input [6].The main contributions of this study can be described as follows: • Using the Loss function to measure the forecast error loss of each training sample.
• Directional Accuracy (DA) is the measurement of the accuracy relating to the series trend. It is used to measure the prediction capacity of the model. Higher the DA is higher the prediction accuracy. Or in other words, higher DA means more promising winning trades. • MSRE is an indicator for the closeness of prediction to actual price.
The rest of the paper is organized as follows. Section 2 reviews the literature review. Section 3 proposes system and methods. Section 4 provides extensive experiments. Finally, give the conclusion in Section 5.

Literature Review
Yu and Yan [7] have compared four prediction methods which were deep LSTM model with no PSR, deep LSTM with PSR, deep multilayer perceptron (MLP) model conventional Support Vector Regression (SVR) machine learning method and the conventional ARIMA linear analytical method. The proposed method was a combination of PSR method with a DNN based LSTM model for time series analysis which improved the prediction accuracy. DNN based LSTM model showed prediction accuracy of an average of 56.85% which was 3-5% better than those of MLP and SVR models and much higher than that of ARIMA model. Although this model has shown higher prediction capacity than conventional machine learning algorithms. However, macroscopic factors and unstructured data were missing that need to be considered for far better accuracy and reliability. Other study [8] has extracted the hidden information from noisy text by initially normalizing it using Soundex phonetic algorithm with an inverse edit term frequency method. Then, it was analysed by character level Convolutional Neural Network (CNN) learning model. It has provided an accuracy of 75% in sentiment analysis and F-measure of 79%. This solution has helped to consider the impact of unstructured data (news, social media) and external factors while predicting the stock price. Unstructured data or factors have not been considered while making the stock price prediction model. Zhou et al [6] have created a generic framework to predict the stock market by using Generative Adversarial Network (GAN) and used LSTM and CNN for adversarial training. Improved the stock price direction prediction accuracy to an average of 71.16% and minimize the forecast error (Root Mean Squared Relative error) to an average of 0.0079. Smaller model update cycles can improve the forecasting result by minimizing direction prediction loss. This work has showed a way to avoid complicated input preprocessing by adopting simple technical indexes. Previous study [3] has proposed design and architecture, based on market news and stock prices concurrently, of trading signal mining platform which implements Extreme Machine Learning (ELM). Kernelized ELM has achieved faster speed with a higher prediction of stock indexes than RBF SVM, BPNN, and basic ELM. This solution has focused on speed of prediction along with accuracy. Speed and accuracy are an important aspect of online trading. k-ELM has proved to have faster prediction speed and similar highest accuracy with RBF SVM.
Recent work [5] has elevated the accuracy and stability of stock price prediction. It has created a stock prediction model with 715 novel-input features and plunge filtering technique to improve accuracy. Accurate prediction of the stock price, by different techniques such as filtering techniques, target vector configuration and input-features used which were parts of the deep learning model. The model showed a high return rate of about 130% over a period of a year. However, the same model without the filtering technique has also showed high results. Therefore, plunge filtering technique did not make any high impact on returns. Moreover, several deep learning models such as CNN, RNN, GAN showed high return results were not considered. Göçken et al [9] have improved the prediction of highly complex stock price data. They have analyzed the stock market predictions by using Harmony Search for variable selection and parameter tuning then passing them to a hybrid model to hedge against potential risk in the market by testing harmony search with different prediction terms. Harmony Search -Jordan Recurrent Neural Network (HS-JRNN) outperforms the other prediction methods (Recurrent Extreme Learning Machine, Generalized Linear Model, Regression Tree, Gaussian Process Regression) and provides a promising direction to the study of stock market predictions. This solution has provided a way to select the number of neurons in hidden and context layers based on the input variables. As, not all parameters were considered such as training functions, iteration number which can highly affect the performance of the model. Similar study [10] has offered a time-series information fusion framework, that is, an extended coupled hidden Markov model (ECHMM) for stock prediction. The solution has taken both stock events and price into consideration to improve the accuracy of prediction. It has provided an accuracy of 62.70% compared to 59.43% and 60.48% of ECHMM-NC (without using stock price information) and ECHMM-NE (without using stock event observation), respectively. This solution has included macroscopic factors as input for the prediction model, which has improved the result. However, sentiment factors have not been considered and they proved to be able to drive stock fluctuations. Other smilar work [11] has investigated the relationship between macroeconomic variables (inflation rate, money supply, exchange rate, interest rate) and the market return between Shanghai and Hong Kong by using Arbitrage Pricing Theory (APT), Vector Error Correction Model (VECM) and Granger-Causality test. It has tested the Johansen's cointegration test, VECM and Grangercausality and provided the outcomes as a long-term relationship, short term dynamics relationship, Granger-causality relationship, respectively. It implies that investors in the Chinese stock market should focus on long term investments whereas in Hong Kong stock market, the focus can be on both long-term and short-term.
Zhou et al [12] have enhanced the Support Vector Machine (SVM) model with based emotions selected (SVM-ES) to improve the prediction accuracy of the stock market. This solution has improved the accuracy of tradition SVM by integrating sentiment analysis. It revealed that inexperienced investors are 98% more sensitive to market fluctuations and SVM-ES provides an accuracy of 45.28% to 56.6% over traditional SVM. SVM-ES provides better results based on sentiment analysis. However, recent deep learning (CNN, RNN, GAN) models were not taken into consideration which tends to provide a more promising results than traditional methods. Other recent study [13] has introduced two deep CNN based frameworks, 2D-CNNpred and 3D-CNNpred, in order to improve prediction performance and accuracy by considering relation among different markets. This framework collects data from various sources, including different markets, for stock market prediction by extracting features. It has improves the prediction performance by about 3% to 11%, in terms of F-measure. However, it predicted the stock market, but no evidence provided for more fluctuating individual stock index.
Previous study [2] has proposed a novel methodology to improve the accuracy of market index forecast. It has conducted a research by forecasting market volatility using GARCH, and then Markov Switching combined with artificial neural fuzzy inference system (ANFIS) to determine the states of external factors and individual impact on each index, and ANN to improve the forecast accuracy. Suryoday et al [1] have developed a framework consisting of a random forest algorithm and gradient boosted decision trees to minimizing forecasting error and investment risk. This solution predicts the direction of stock price to signifying losses and gains. It was able to attain 78% accuracy. However, the proposed solution was only able to provide robust results for long term predictions. Derakhshan and Beigy [14] have improved Latent Dirichlet Allocationpart of speech (LDA-POS) by implementing part-of-speech into LDA to improve the accuracy of stock price prediction by assessing human sentiments in user reviews. It has provided an accuracy of 56.24% and 55.33% from English and Persian datasets, respectively. It has achieved better results than methods using explicit sentiment labels. However, other models have far better results than this model. Sermpinis et al [15] have designed an adaptive SVR for stock data at different periods of time. The results found that the improved SVR with dynamic optimization of learning parameters by PSO can achieve higher prediction results than the traditional SVR. Moreover, machine learning models in the last years, are challenged by deep learning models in stock prediction [16].

State of the Art
Yu and Yan [7] have presented a system for predicting a stock index. Time series dataset usually contains insufficient data and the model is often over-fitted when trained using machine learning. To overcome this problem, it was used the common sliding window method for Phase-space Reconstruction (PSR). Prediction of the stock price was performed by deep learning framework with Long Short-Term Memory (LSTM) and Recurrent Neural Networks (RNN). Fig.1 illustrates "The blue borders show the good features of this state-of-the-art solution, and the red border refers to the limitation of it". This model consists of four major stages which were data-collection environment, preprocessing environment and prediction environment.  (2021). https://doi.org/10.1007/s11042-021-11670-w 5 | P a g e • Data-Collection stage: In this stage, the data is collected from Yahoo Finance (finanace.yahoo.com), TuShare financial data interface (tushare.org) and relevant organizations. Basically, the individual stock is considered during the prediction process because the company sharing data does not indicate the firm value. • Pre-Processing stage: In this stage, data is de-noised by using wavelet technique. Time-series data is inconsistent, so PSR is used to fold and replicate the data multiple times using the common sliding window method. The dimensionality of price data is extended by PSR. The result is fed to the LSTM based Recurrent Neural Network (RNN) algorithm. • Prediction stage: In this stage, two processes are mainly involved in any prediction system which are training and testing. LSTM is a basic deep learning model and capable of learning long term dependencies. An LSTM consists of so-called dynamic gate structures, an input gate, an output gate, and a forget gate [4]. RNN model using the LSTM node is effective and expendable when used to solve time series problems [7]. However, this model does not provide enough prediction accuracy because it fails to minimize the direction prediction loss and Root mean square error (RMSE) value. RMSE is frequently used to measure the difference between values predicted by LSTM based RNN and the observed values. • Evaluation Stage: In this stage, the prediction result is evaluated on the defined metrics and presented in the form of charts. The prediction result is subject to multi-dimensional analysis.
The loss function is used to measure the forecast error loss of each training sample. This will only find the loss on the bases of the LSTM based RNN model. However, the number of iterations in this function increases the loss error and processing time.

=0
. (1) Where: trend' = predicted value trend = actual value the trend at time t is defined as: The Root Mean Square Error (RMSE) is the preferred method to measure the prediction power of a single stock. However, it is ineffective in performing a uniform comparison of multiple stocks.  Step 5: At time t, xt is the input and yt is the output of the node Step 6: ft = (Wfxt + Rfht-1 + bf) is the output of the forget gate at time t Step 7: it = (Wixt + Riht-1 + bi) is the output of the input gate at time t Step 8: Ćt, Ct is the input and cell structure of the node at time t, respectively, which are expressed as: Ć = tanh(Wcxt + Rcht-1 + bc) C = it ⊙ Ćt + ft ⊙ ct-1 Step 9: Ot = (Woxt + Roht-1 + bo) is the output of the output gate Step 10: The final output ht of the node is expressed: h = Ot ⊙ tanh (Ct) End

Proposed System
This model consists of three major parts as shown in Fig.2 which are pre-processing, prediction and evaluation environments.. The blue borders show the good features of this state-of-the-art solution, and the green border refers to new proposed feature.
• Data-Collection stage: In this stage, the data is collected from Yahoo Finance (finanace.yahoo.com). Basically, the individual stock is considered during the prediction process because the company sharing data does not indicate the firm value. • Pre-Processing stage: In this stage, data is de-noised by using wavelet technique. Time-series data is inconsistent, so Phase-space Reconstruction (PSR) is used to fold and replicate the data multiple times using the common sliding window method. The dimensionality of price data is extended by PSR. The result is fed to new proposed Generative Adversarial Network. • Prediction stage: This stage consists of two main processes which are training and testing. Both processes are performed by using stock price dataset obtained in the data collection stage. Generative Adversarial Networks GAN is the combination of two neural networks (i.e. Generator and Discriminator) [6]. Stock data is typical time series, and the model G (Generator) is based on the LSTM model, which is broadly used for time series prediction. To estimate the probability whether a sequence comes from the dataset or being predicted by generative model G, Convolutional Neural Network (CNN) is selected as discriminative model (D) to perform convolutional operations on one-dimensional input. • Evaluation Stage: In this stage, the prediction result is evaluated on the defined metrics and presented in the form of charts. The prediction result is subject to multi-dimensional analysis.

Proposed Equation
Loss Function expressed by [6] is the sum of all loss function in the model to minimize the forecast error loss of each training sampler. In order to make discriminative model D as confused as possible, adversarial loss function ( ) for generative model G should be minimized. Forecast Error Loss (Lp) should also be minimized to over the problem of being of confusing model D by model G without being close to Y′T+1. Ldpl is direction prediction loss function as stock price direction is very crucial for trading. There by combining all loss function, it was achieved final loss function (5).
Where: Y′ = predicted output by generative model G Y = actual price is adversarial loss function for model G Directional Accuracy (DA) is the measurement of the accuracy relating to the series trend. It is used to measure the prediction capacity of the model. Higher the DA is higher the prediction accuracy. Or in other words, higher DA means more promising winning trades.

DA = 100
where: T0 = total number of time points being tested Y′ = predicted stock price from generative model G Y = actual stock price Below mentioned formula (7) is being modified result of equation (2) MDA = 100 where: T0 = total number of time points being tested Y′ = predicted stock price from generative model G Y = actual stock price Root Mean Square Relative Error (RMSRE) is an indicator of prediction accuracy. A low RMSRE which means that predicted data agrees with real. RMSRE facilitates the comparison of multiple stocks due to which this method is preferred over the RMSE.
where: t = time T0 = total number of time points being tested Y′ = predicted stock price from generative model G Y = actual stock price It was extracted formula from equation (8) and used it to enhance the equation (3). Formula (9) is the enhanced version. It calculated the loss function with the modification of root mean square error expression.

MRMSE =√
Where: MRMSE = Modified Root Mean Square Error t = time T = maximum lag of time Y' = predicted stock price from generative model G Y = actual stock price

Area of Improvement
In this study, it was considered to minimize the RMSE and forecast error loss which commonly occurs during the regulation in the calculation of the loss function by using equation 5. The algorithm has not performed well during the calculation of RMSE and forecast error loss due to the number of iterations (m) during training and testing of the model. However, several solutions  (2021). https://doi.org/10.1007/s11042-021-11670-w 10 | P a g e were proposed to address this issue, but so far, more accurate minimization of forecast error loss and root mean square error (RMSE) has not been achieved.
Generative Adversarial Networks GAN is the combination of two neural networks (i.e. Generator and Discriminator) [6]. Stock data is typical time series, and the model G (Generator) is based on the LSTM model broadly used for time series prediction. To estimate the probability whether a sequence comes from the dataset or being predicted by generative model G, Convolutional Neural Network (CNN) was selected as discriminative model D to perform convolutional operations on one-dimensional input. The reason behind using adversarial loss is that it can mimic the behaviour of a financial trader. The available indicator is the main factor for an experienced trader for prediction of stock price then finds the true probability of his prediction with the old stock price, which is the work of generative model G and discriminative model D, respectively. Step 1: Set learning rates ρD and ρG, and parameters λadv, λp, λdpl; Step 2: Initialize weights WD and WG Step 3: while not converged do Step 4: Update the Generator G; Step 5: Get K new data samples (X (1) , Y (1) ), (X (2) , Y (2) ), …., (X (K) , Y (K) ) Step 6: Step 7: Update the discriminator D: Step 8: Get K new data samples (X (1) , Y (1) ), (X (2) , Y (2) ), ….., (X (K) , Y (K) ) Step 9: Step 10: end while End

Dataset
Python 3.7 IDE was used in the implementation and representation of the model by stock index dataset of various companies from 1 Jan 2013 to 31 Dec 2018. The dataset that taken as samples for testing has a different date (open, low, high, close, and volume data). Comprehensive examples which include different training epochs and batch size were undertaken. The dataset was obtained from Yahoo finance (finance.yahoo.com). Additionally the dataset considered an open-source and freely available on the internet as a (CSV file). The data will read it from the CSV file and fed it to a deep neural network. All the dataset has been tested in different window size as shown in fig 6, 7, 8 , 9, 10. For the experiment, 23.2 GHz AMD Ryzen 5 2400GE with Radeon Vega Graphics and 8 GB RAM memory is used.
During the pre-processing phase, the wavelet technique has reduced the noise from dataset, folded volume ,data and replicated multiple times using common sliding window method to normalize the data. During the prediction phase, the Generative adversarial network was constructed by loading the dataset over the network. The generative model G has performed prediction Y'T+1 on the input split dataset X. The predicted output Y'T+1 and stock index closed price from CSV file were loaded to discriminative model D to perform convolution operations on the 1-D input sequence to estimate the probability whether time series comes from the dataset Y or being produced by a generative model G.  (2021). https://doi.org/10.1007/s11042-021-11670-w 11 | P a g e

Discussion
Results show the difference in accuracy and processing time between the current state-of-theart and the proposed solution concerning the accuracy and the processing time. The proposed algorithm has minimized the root mean square error value to 0.0295 from 0.0585. Besides, the average processing time was reduced from 3 min 26 sec to 2 min 8 sec due to reducing number of iterations. During the experimental tests, it was found that the LSTM has not performed well when it compared to the GAN. Although, GAN have performed very well, as the predicted value was close to the actual value. For the prediction of the stock index closed price, a range of techniques have been implemented, but continuously refined by the desire for accuracy and lower processing time.
This research has successfully overcome the limitations of the current best solution with 2 min and 8 sec against 3 min and 26 sec of average processing time. This research also has increased the directional accuracy to 61.45% against the current directional accuracy of 57.1%. This process was done by Phase-space reconstruction technique (common sliding window) for normalization of the data and fast processing. Additionally, the new feature has minimized the RMSE value and increased the

Processing Time (Seconds) of state-of-the-art and proposed model for 5 sample dataset
directional accuracy of stock price prediction. The proposed system has been implemented and tested on Python programming language (Python 3.7) and shown to reduce the processing time and to increase accuracy. Along with this, the proposed solution with the actual and predicted result about the closed price helps to identify the closed stock price of following day. The above results show the differences between the accuracy and the processing time between the current solution and the proposed solution in terms of stock index closed price.
The system has been tested on Python 3.7 programming language, and the result shows that the proposed algorithm has successfully minimized the RMSE and forecast error loss. Also, it has reduced number of iterations during the training and the testing of the model which ultimately increases the processing time during the learning phase of the model. Based on the analysis results the GAN has used a window size of 121 and 100 epochs, as well as, it has used 25 hidden layers and 1 output. The values that have achieved by the RMSE are 0.0295 and the training period was 2 min 8 sec.
The comparative results of the state of the art and proposed solutions are shown in Table 2. Reduce the loss function and tanh function Reduce the loss function with modified root mean square error and linear rectification (ReLU) function Algorithm The algorithm is considered as a supervised learning The algorithm is considered as an unsupervised learning

Prediction Stage
Use the output from Phase-space reconstruction algorithm and number of iterations to calculate the root mean square error Use the output from Phase-space reconstruction algorithm and reduces the number of iterations to calculate the enhanced root mean square error (RMSE) Equation It calculated the loss function using equation-1 It calculated the loss function with the modification of root mean square error expression from equation-9

Processing time
The average processing time is 3 min and 26 sec The average processing time is 2 min and 8 sec secs Accuracy The average directional accuracy is 57.10% and RMSE is 0.0585 The average directional accuracy of the proposed model is 61.45% and RMSE is 0.0295

Conclusion
This paper presented combinations of Phase-space reconstruction (PSR) and GAN on the different form of dataset has improved the accuracy of stock prediction then it compares to the long short-term memory (LSTM) method with PSR.
The proposed method has been tested with diverse window size and epoch to find out the best parameters which can result in improving the system accuracy.
The experimental results show that the proposed GAN algorithm and deep learning perform well in the stock index closed price prediction. Although a range of techniques is available to predict the stock index close price, but they have so far failed to provide enough accuracy and processing time. Sufficient accuracy and low processing time considered major factors that affect the stock market prediction value.