Using implementation of artificial intelligence in estimating the exchange rate in the foreign exchange market

The Foreign Exchange currency market is considered the most liquid market in the world due to the amount of money that is traded every day. Researchers and investors are interested in having a system that allows predicting the direction of the exchange rate of a pair of currencies in order to create a strategy that allows them to profit from the market. Since the movement of the exchange rate between currencies generates a high frequency time series, recurrent neural networks have gained strength in the prediction of these markets, since they have the characteristic of generating models of non-linear systems. In this document, the study of the prediction of the direction of the exchange rate of different currencies was carried out using the recurrent auto-regressive neural network with exogenous inputs, which has the characteristics to obtain a predictive model of a time series. The tests were carried out in the Euro / Dollar pair in the time frame of one hour, demonstrating the potential of this neural network architecture. These techniques are products of the biological and physical sciences in industrial processes.


Introduction
The foreign exchange (Forex) market is a decentralized global market use to trade between exchange pairs. The key participants are the international banks, hedge funds, commercial companies, central banks, and of course, minimum exchange traders and investors [1,2]; as a result, the exchange rates between currencies are constantly changing, shaping a market of high frequency and volatility that has many directional changes. Market participants enter orders to profit from bullish or bearish movements, depending on the operation case as buying or selling. For this reason, have a way to predict the market price direction between currencies is very important to reduce risks and maximize the participants' profits.
Many approaches have been used to profit from the market, such as technical analysis, fundamental analysis, statistical analysis, and predictive calculation techniques, each of them has their influence on optimization, market analysis, political science, etc. econometrics all of them permeated by the techniques of physics and mathematics.
One theory affirms that the market movement can be analyzed as a chaotic nonlinear time series that seems random but can be predictable; another opposite theory, the efficient market theory, claims that the market is random and unpredictable. Many studies supported the first theory and had applied artificial intelligence techniques like the neural network that have shown promising results when predicting series of times with these characteristics. In this work, recurrent neural networks are used based on diverse authors [3,4]. These networks have the capabilities to predict future values of nonlinear  [5]. This paper focused on applying recurrent neural networks to predict the pair Euro/Dollar (EUR/USD) and for different architectures of the neuronal recurrent auto regressive (NARX) network.

Recurrent neural networks usage at financial markets
Regarding its specific use in the world in recent years, Zheng [6] mentioned one of them, who designed the called neural network of Elman, a typical regression network appliable to process sequential data. The created network was used to predict the action price or its fluctuance. At [7], the authors applied neural network models of multilayer perceptron to predict the action prices from the Information Technology Indian companies; at [5], the studied problem was the prognostic and increase of prices. As data analyzed were taken indexes like Standard and Poor´s 500 (S & P 500), Nasdaq100, and Dow Jones. Different multilayer perceptron setups were used, with different numbers of hidden neurons. The results demonstrated the possibility of forecasting the sign of the price increments with a slightly higher probability of 50%; at [8], the problem studied was to predict the price incremental of S & P 500. Historical data was taken from index S & P 500 for the period 1928 to 1993. Many neural networks have been built and trained with different setups. As a result, surprisingly, almost all the neural networks made a profitable prediction; at [9], the sign of the prices increase was forecasted. Germany stock index (DAX) and financial times stock exchange (FTSE100) indexes were used for some time. The Elman recurrent neural network was chosen. Finally, the authors concluded that the neural networks cannot give better results than simple models, like the Markov model; at [10], a neural network forecast was made of currencies exchanges in Forex. The analyzed data was selected from weekly data of Australian dollar (AUD), Swiss franc (CHF), German mark (DEM), Pound sterling (GPB), and Japanese yen (JPY). Two neural networks were used in this study: the first model is the multilayer perceptron, its inflows fed exchange rate values with some delay, and the second model was the multilayer perceptron, with inflows from which exchange rate of mobile media values were fed with time windows (from 5 to 120 tics). Statistical estimates of the quality of the prognosis were made, showing, for the last model, that neural networks can give good results.

Currencies market
In the foreign exchange market (forex: foreign exchange) when a participant enters a purchase order, it is known as a unity purchase from the primary currency and selling the second currency. Depending on the purchase or sale operation, the market participants enter orders to profit from the bearish and bullish movements. The actual price movement is called ticks that show the existence of transactions between sellers and buyers. There can be numerous ticks per second during active markets, and in slow markets, there can be minutes without a tick. The market formation and the participation option are made through Forex brokers. Through these platforms, the investors see the market and execute their sell or buy orders. In Figure 1 the Forex signal is shown, which is an economic time series that is made up of two composite structures: a long-term trend and a short-term high-frequency oscillation.

Recurrent neural networks
Recurrent neural networks [11] are, in principle, a computational model more potent than the classic neural networks; neural, take an advanced network architecture and add feedback connections to the previous layers. Recurrent neural networks are helpful in situations in which a temporal relation (timedependent) exists in the data; Jordan (1986) and Elman (1990) introduced this architecture type. Neural networks are trained by a standard counter-propagation algorithm, except that the patterns are always presented in sequential order in time. In this way, the network sees the previous knowledge that has over the last posts. Furthermore, the presence of recurrent feedback at the neural network seems a positive factor in the prognostic of financial time series [12]. Thus, the recurrent neural network has a "deeper memory" than an advanced neural network.
These networks have short-and long-term memory blocks depending on the architecture complexity. A nonlinear autoregressive with exogenous input (NARX) is used in this work; it is a frequent dynamic network used commonly to model time series. There are many applications for the NARX network. Furthermore, it can be used to predict the next value of the input signal. Also, the output destiny is a version without noise of the input signal, used as a nonlinear filter. The NARX networks can be applied to model nonlinear dynamic systems. Figure 2 shows a result diagram of the network, using an advanced bilayer network for the approach; this implementation also allows a vectorial ARX, where the input and the output can be multi-dimensional. Figure 2. The NARX architecture [12].
The NARX network can be used in parallel architecture (closed-loop) and series-parallel architecture (open-loop), as shown in Figure 3. In this work, the open loop was used to process the training, allowing the network to be trained with the standard propagation algorithm applied to the multilayer perceptron. For the network training of the open loop, the data series u is presented like n data of the training Equation (1) [13].
The output of a supervised train in a neural network should equal the series u(t) values; in the case of the close loop, the estimation is giving by the data series y, where the training target is to search that the future known data u(t) equals the estimated data by the neural network y(t). Therefore, in Equation (2) [13], the open loop is fed by the input too with the data y(t) = u(t). When the trained network, the loop is closed to predict m future data of u series. 4 y = f(y(t), y(t + 1), y(t + 2),..., y(t + m)). (2)

Proposed methodology for the estimation
A nonlinear autoregressive with exogenous input (NARX) from MATLAB© is proposed for this work to predict the direction and the future value of the currency exchange rate. Figure 4 shows the order process scheme for the training phase.

Number of delays and number of neurons
The network's prediction performance was evaluated in this work for different delay values and the number of neurons.

Data division
The data from the series is divided into the following proportions 70:15:15, which are the training data, validation data, and test data; with these proportions, the neural network has a data series to validate and probe the model.

Network validation
The mean square error is used to validate the prediction's quality. Equation (4) [13], shows the propagation algorithm backward as a criterion to update the networks' weights. Figure 5 shows the ordered process scheme for each prediction stage.

Implementation and results
The prediction is tested for the pair EUR/USD. The closing price is used as data series for the temporality of one-hour H1. With the data from (31/05/2017) to (24/01/2019), for a total data amount of 10036. Following the structure mentioned in Figure 5, the first to do is normalize the data using Equation (3) in the range [-1,1] as shown in Figure 6.  Figure 6. EUR/USD historical, H1 temporality normalized. a) The mean square error (MSE), obtained at the training stage. b) The mean square error to predict one forward data value. c) The mean square error to predict five forward data values. The set of n data estimated in the forward direction through the closed-loop prediction of the neural network is calculated with Equation (5) [13].
Analyzing the information in Table 1, the best test according to the training MSE is test 8. The best test according to the MSE for the prediction of one step forward is test 7. The best test for the prediction of five-step forward is test 3. Finally, the test with an optimum balance is test 7, with ten delays and five neurons in the hidden layer.

Analysis of results
Considering a training with ten delays and five neurons in the hidden layer corresponding to test 7, as shown in Figure 7, the actual data curve, and the prediction of a forward data.  Figure 7, predicted data are closer to the actual data because prediction is dependent on the immediately backward data. However, this kind of prediction is not useful enough for all the market participants because it does not allow them to anticipate sudden market movements and generates imminent equal risk in a sell or buy operation. Also, another executed test is to calculate the prediction of several forward data of the series using the closed loop of the NARX neural network, feedbacking it with the output predictions. Figure 8 shows the projection of ten forward data. It can be observed that the predictions with ten forward data present a slope that helps to identify the market tendency in the medium term. This information is essential for market operators because it allows anticipating the market movement a couple of hours before. With these values, an additional test is executed; calculate the predictions' slopes for five steps forward and their alignment in the same time window to verify if the information allows visualizing relevant characteristics as seen in Figure 9; the prediction slopes give information about the market momentum.
Also, this can be a strategy for researchers and investors when taking an order to the market since there is information that is not possible to see directly; for example, in Figure 9, the optimistic predictions indicate that the market still has an optimistic movement that can be taken as buy operations. On the other hand, in pessimistic predictions, the starting prices suffer a notorious fall. In other words, this would be a good indicator that the market will make a deep retracement or change in trend, allowing open a buy operation; to calculate the predictions slope, Equation (7) [13] is used.

Conclusions
The currency market presents a nonlinear chaotic behavior, and when it is analyzed as time series of this characteristic made it possible to apply prediction techniques with good results. The recurrent neuronal networks can create time series models like those presented by the foreign exchange market.
The forward prediction does not provide valuable information to the investor due to normal price swings. Thus, using a closed loop of the NARX neural networks allows the creation of predictions of several steps forward; furthermore, analyzing the slopes of these predictions gives information about future market direction. When predictions are executed based on time series, the currency market can generate unexpected fluctuation products of impact economic news, making it difficult to use a computational technique without information to get a good prediction. Therefore, it is recommended to extract this data series that generates distortions in the models.
The use of recognition neural networks combined with prediction techniques will be a helpful strategy for a foreign exchange market participant. The previous results allow to affirm that by means of the recognition neural networks it will be possible to identify the patterns that result from the physical experimentation to clarify many of the models of theoretical physics.