A foreign exchange market trading system by combining GHSOM and SVR

There are many researches aimed to predict times series of various financial markets. Some of these papers have shown that it is possible to obtain satisfactory results, thereby contradicting the theory that financial time series follow a random walk model. This study applies an architecture based on two stages for trading with two of the most traded foreign exchange rates (forex), the EUR/USD and GBP/USD. It also proposes a trading system to evaluate the model under a financial perspective, both in terms of profitability and risk, and to compare the application of the model in different timeframes (daily or intraday). The architecture consists of a GHSOM network, whose goal is to divide the dataset into regions with similar statistical distribution in order to circumvent the problem of nonstationarity, and a support vector regression machine (SVR), to make forecasts for the regions defined by GHSOM. We report on experiments that the SVR+GHSOM architecture performance is far superior compared to a model based solely on SVR. The comparison considered performance measures such as profitability (ROI) and the maximum drawdown (MD) and has shown that the best results are obtained in daily timeframe. The experiments have also shown that it is possible to increase profit by adjusting the risk parameter (number of lots), at the expense of increasing the risk. Furthermore, the proposed model proved to be much more profitable than a buy-and-hold model using the same time series (EUR/USD and GBP/USD); it also outperformed buy-and-hold with the Dow Jones in the same period.


INTRODUCTION
Forecasting of financial time series such as stock market and foreign exchange market (forex) has attracted researchers from various areas of science such as physicists, computer scientists and statisticians. Although the efficient market hypothesis (EMH) [1] claims that the market can't be outperformed, recent research has shown that models based on neural networks outperformed the random walk model [2] [3] [4]. This justifies research efforts on the use of computational intelligence techniques to perform market forecasts.
Due to the complexity of the market and of its time series, the use of simple techniques for trading, such as simple technical indicators like the MACD (moving average convergence/divergence) does not give good results in terms of profit [5]. Therefore, the application of computational intelligence techniques for forecasting has been investigated by researchers, including the multilayer perceptron (MLP) neural network [5], radial basis functions (RBF) [6], self-organizing maps (SOM) [7], support vector machine (SVM) [8], extreme learning machine (ELM) [9], among others [10]. Most of the papers that appear in the literature focus on the application of such techniques for the stock market. However, research on the application of these techniques to predict the forex market is increasing due to its great importance for the international monetary scenario.
In [5], forex rates are used as inputs to predict the Dow Jones Average Index, with satisfactory results. The use of parametric and nonparametric modeling methods has been found to produce promising results when tested on foreign exchange rates [11]. The prediction of a longer term period has also been explored by researchers. In [6], a multistage nonlinear radial basis function (RBF) neural network ensemble forecasting model was proposed for four foreign exchange rates prediction, with consistent results when compared with some existing neural network ensemble approaches. Experiments regarding a mixture of regressive neural network models were conducted by [8], such as temporal selforganizing maps and SVR, to predict the GBP/USD exchange rate. A genetic algorithm was also employed to fuse the mixture and some economic indicators. This hybrid method showed to be profitable, yet the authors did not analyzed the risk of the model (for instance, using the maximum drawdown) [8].
Research conducted in this area commonly compare the use of various models through experiments, taking as performance measures indicators such as error rates and predictive accuracy. Unfortunately, such performance measures do not indicate whether the proposed model is profitable when put into operation in practice. Measures such as error rate do not ensure profitability, as might be found in [5].
In [7], the authors proposed a neural network architecture for stock price forecasting with two stages. In this architecture the models used are the Growing hierarchical self-organizing maps (GHSOM) and the Support Vector Regression (SVR). GHSOM is responsible for dividing the series into regions with similar statistical distributions, bypassing the problem of nonstationarity, whereas SVR is used to make predictions for each region, thus increasing the predictive power. The performance of the model was not analyzed in terms of profitability or risk; the experimental results were reported considering the normalized mean squared error (NMSE), mean absolute error (MAE), directional symmetry (DS) and weighted directional symmetry (WDS) [7].
In this paper, we propose to apply the method introduced in [7] to the problem of trading in the forex market instead of the stock market. In addition, we aim to evaluate the model considering profit and risk instead of error measures. To this end, a trading system was developed to evaluate the performance in terms of profitability and risk. Performance of the model was investigated by applying it to two pairs of currencies, namely, the series EUR/USD (Euro to US Dollar) and GBP/USD (British Pound to US Dollar). We also analyze the financial impact of using different time frames, namely, daily operations (one day) and timeframe intraday (one hour). We also compared the results of the model with one of the strategies commonly used by conservative traders, the buy-andhold, applied to both for the forex market as well as to the Dow Jones.
This paper is organized as follows. In Section II we briefly review the models used in the method investigated in this paper, namely, Support Vector Regression (SVR) and Growing hierarchical self-organizing maps (GHSOM). Section III describes the proposed method, including the two stage architecture and the trading system. Section IV presents the experiments and analyses the results. Finally, in Section V conclusions and suggestions for further research are presented.

A. Support Vector Regression
Support vector regression (SVR) is one of the components of the model investigated in this paper for forex trading. SVR is closely related to SVM and is based on the structured risk minimization principle. It was introduced by [12], which defines the ε-insensitive zone in the error loss function. It has been proposed as a good alternative to MLP neural networks in time series forecasting, having a high generalization performance in time series modeling. Besides that, the solution for SVR is unique and globally optimal, in contrast to many other networks and learning algorithms which tend to be trapped to local minima. A schematic representation of the SVR using the ε-insensitive loss function is illustrated in Fig. 1.
A penalty is introduced when data-points are far from the predicted line, but no penalty is received when inside the εtube. That is, errors inside the tube are considered to be zero. When the penalty occurs, the errors are measured by the variables ξ and ξ * .
The function that represents f(x) in the case of SVR for nonlinear regression is defined by where is some nonlinear function which maps the input space to a higher dimensional feature space. The weight vector w and the threshold b are chosen for optimization. The optimization problem can be stated as The constant C > 0, which is one of the user-defined parameters of training together with ε, determines the trade-off between the flatness of f and the amount up to which deviations larger than ε are tolerated. ξ and ξ * are the slack variables, which measure the cost of penalties on the training points. ξ and ξ * measures the deviations from training points outside the ε-tube to f(x) + ε and f(x) -ε respectively, as shown in Fig. 1. The idea of SVR is to minimize an objective function which considers both the norm of the weight vector w and the losses measured by the slack variables (see (2)). Minimizing the norm of w is one of the ways to ensure the flatness of f [13].
The decision function can be computed by the inner products of ( ) ( ) without explicitly mapping x into a higher dimension, which saves considerable computation efforts. Thus, the kernel function is defined as In this work, we consider SVRs with the RBF kernel, which is computed as where is a parameter of the kernel and must be defined by the user.

B. Growing Hierarchical self-organizing maps (GHSOM)
The GHSOM was proposed by [14] and is based on the self-organizing maps (SOM) [15]. GHSOM is used mainly as a clustering technique and offers as an advantage the fact that it is not necessary to specify the shape of its grid, that is, it is not required to have a previous knowledge of the problem to define the grid. The GHSOM has a hierarchical structure of multiple layers, with each layer representing an independent growing SOM, as shown in Fig. 2, which is an example of GHSOM. Layer 0 is responsible for the control of the growth process. The next layer consists of a 3x2 grid. All of the units of Layer 1 are expanded to six additional SOMs, creating Layer 2. In this layer, many units have not been expanded since the data representation quality was already accurate enough. It is important to note that the maps have different sizes according to the structure of the data. That is the reason why this work adopted GHSOM, since it is not necessary to define its structure beforehand.

A. Architecture
The method proposed in this paper is based on the architecture used in [7]. The architecture is composed of two stages, where the first one divides the entire data set into partitions with similar statistical distributions using a GHSOM network. This is done to tackle the problem of the nonstationarity of financial time series. The second stage consists of using SVR models specific to each region to make predictions. This architecture was first proposed by [16] and was inspired by the divide-and-conquer principle applied to simplify complex problems. The architecture can be seen in Fig. 3.
The second stage produces SVR models for prediction of each partition selected by the GHSOM network. The paper by Hsu et al. [7] uses performance indicators that do not provide relevant information regarding the profitability of the model. In contrast, our paper aims at analyzing the performance of the architecture in terms of profit and risk through a simulated trading system. Furthermore, our work considers the forex market whereas Hsu et al. experiments were carried out in the stock market [7]. All experiments were conducted using MATLAB. We used the LIBSVM toolbox for MATLAB [17], GHSOM [18] and TA-Lib [19] , for technical indicators.

B. Trading System
The trading system was developed to simulate buying and selling in the forex market from the proposed model in order to examine whether it is possible to profit from the model. The trading system was simulated considering both the timeframes 1D (daily) and 1H (intraday), in order to compare their performance in terms of profits and risk.
The profits reported in [5] and [20] were obtained exclusively in buy operations in the stock market. In our trading system, on the other hand, profits can be obtained in both directions, that is, in the buying and selling directions. In the trading system proposed here, we decided that hedging can be used, i.e., there may be one or more bought orders and one or more sold orders at the same time interval. The trading system, shown in Algorithm 1, unlike the work of [5] and [20], does not use a system of buying and selling based on stop and reverse. For each day or hour, depending on the timeframe used, an operation is always performed, which may be buying or selling, depending on the forecast of the movement of the series for the next five quotes. Based on the forecast, the system performs an operation on the opening of the next quote and closes the operation in the fifth opening price, which is the lag of the prediction model. Transaction costs are provided in the system through the spreads used for buying and selling transactions using the opening bid and ask prices.
In Algorithm 1, while the trading system is active (line 6) it will place orders for each open bar (line 12) considering the predictions carried out in the previous close bar (line 7). The orders are closed after being opened for five days when the bar is open (line 22). The "for" loop (line 22) closes all orders that are active for more than five days. This was included in the algorithm to tackle potential failures in the system, such as loss of internet connection.

Variables
Type Calculation

A. Dataset
Experiments using two time series were conducted in order to analyze the performance of the proposed method. The time series utilized in the experiments are the most commonly used pairs of currencies in the foreign exchange market (forex), namely, the EUR/USD and the GBP/USD. Data were obtained from OANDA, a financial institution dedicated to forex trading and currency information services [21]. For EUR/USD we used data from April 2, 2004 to January 19, 2011, whereas for the pair GBP/USD we used data from January 2, 2004 to June 24, 2011. For both series, 50 records were removed from both the beginning and the end of the data set to make it possible to carry out experiments using technical analysis indicators, such as a 40-day moving average as input, and predictions of price movements for the next 30 days. OANDA provides data for students and clients and the data were obtained in "tick data", with each record representing a single variation of price (that is, without constant timeframe). Next, we used the tick data to generate data sets with timeframes both of one day (1D) and one hour (1H).
The time series were transformed into input and output sets for training, validation and test following the procedure of [7]. The input was generated from four lagged relative differences in percentage of price (RDP) -namely RDP-5, RDP-10, RDP-15, RDP-20 -and an exponential moving average EMA15. The output variable was transformed into RDP+5, through a process of smoothing the closing index in order to improve the model forecasting. The transformations of these variables were performed using the close bid price for each symbol. Table I illustrates how the data set was formed.
In the experiments conducted in this study the data sets were divided into training sets having 90% of the data and test sets having 10% of the data. The training sets were formed using the first portion of each data set whereas the test sets had the latest data points. The percentage of data in training and test sets were chosen due to the high volatility of the forex market, which is highly influenced by international economic news that frequently change the movement of market [22]. The number of records in the training and test sets is shown in Table II. Data of all data sets were normalized to the range [-0.9, 0.9].

B. Performance Indicators
One of the main objectives of this study is to analyze the performance of the proposed method from a financial perspective, therefore, we selected the performance indicators shown in Table III. The DS (direction success) indicates the ability of the model to predict the market movement according to the output variable. It is important to remember that in the forex market profits can be obtained in both movements, that, 1: begin trading system 2: account_balance = 10000; // account_balance: initial deposit 3: lots = 1; 4: mini_account_units = 10000; 5: bars = 0; 6: while trading system is active do 7: if bar close then 8: calculate inputs according to Table I;  9: calculate GHSOM partition of the input space; 10: calculate output according to Table I   in falling or rising. The ROI (return on investment) can be used as a measure of profitability, where the financial return is measured in percentage. The ROI can be compared to other types of investments and can be easily understood by market participants. The MD (maximum drawdown) shows, in percentage, the greatest loss during the period tested, thus it is an important measure to determine the risk involved in the investment.

C. Model parameters
As described in section III, the model consists of a twostage architecture, integrating GHSOM and SVR. GHSOM parameters determine the characteristics of hierarchical and horizontal growth of the network. The values used in the experiments for the parameters of hierarchical and horizontal growth were 0.05 and 1, respectively. Furthermore, each partition of the network must contain at least 30 records. Therefore, partitions with fewer records were grouped into neighboring partitions.
The kernel function of the SVR used in the experiments was the Radial Basis Function, represented by (4). We use the default value of ε for the package LIBSVM [17] utilized in the experiments, i.e., ε = 0.001. The values of parameters γ and C were selected from the sets [2,1,0.5,0.1,0.01,0.001,0.0001] and [1000,750,500,100,50,2] respectively. These parameters were varied in order to obtain the best network for each partition from the cross-validation training (10-fold cross validation). The best SVR is the one that gives the greatest profit.

D. Trading System
Different levels of risk can be assumed in the operations in the forex market. The choice of the type of trader one wants to operate, that is, more conservative or more aggressive, depends on the amount of lots invested in the transaction. In the first set of experiments, we used one mini lot, which equals US$ 0.10 per pipette. We also report on experiments using 10 lots. The term "pip" is an acronym for price interest point and is used in forex market to determine the minimum price change in floating foreign exchange rates. For example, a change in a quoted price from 1.5898 to 1.5899 is equal to one pip. A pipette is a fractional pip, which is equal to 1/10th of a pip. It is represented by the 5th decimal digit. We consider a fictitious account with an initial deposit of US$ 10,000.00.

E. Results
The results for the test sets are shown in Tables IV and V for EUR/USD and GBP/USD, respectively. We can see from the tables that the results obtained for the experiments 01, 03, 04, 05, 07 and 08 do not achieve satisfactory results, having a negative ROI. With respect to the performance indicator MD, notice that the experiments involving the proposed model, i.e., SVR+GHSOM, had smaller losses in comparison to SVR, except in experiments in 7 and 8, in which all initial investment was eliminated for both SVR and SVR+GHSOM (MD=100).
For both EUR/USD and GBP/USD the proposed model was able to obtain positive results for the ROI using 1D timeframe (daily operations), as shown in Tables IV and V. For both time series with 1D timeframe, SVR obtained negative ROI whereas SVR+GHSROM obtained positive ROI. On the other hand, for 1H timeframe (intraday operations) both SVR and SVR+GHSOM obtained negative ROI. Therefore, we can state that the proposed model for daily operations exceeds the intraday operations for both the model using only the SVR and SVR+GHSOM. The results of the DS has not influence significantly the final results in terms of profitability, which makes it an indicator with little relevance to market operations.
The application of the model SVR+GHSOM in daily time series (1D timeframe) proved to be a superior alternative to other forms of investment, as shown in Fig. 4 and Fig. 5. We simulated a buy-and-hold system for the series EUR/USD (1D) and GBP/USD (1D) and the Dow Jones on the same test period of each series. A comparison of these investment strategies can be viewed also in Tables VI and VII, considering the ROI. These results show that the SVR+GHSOM is considerably superior to buy-and-hold for both EUR/USD and GPB/USD. For EUR/USD the SVR+GHSOM model is also far superior in comparison to buy-and-hold with the Dow Jones (see Table  VI), whereas for GBP/USD the SVR+GHSOM gives slightly better results than buy-and-hold with the Dow Jones (see Table  VII).
The number of lots invested can be increased to achieve greater profitability, which is one of the advantages of operating in the currency market, since the trader has flexibility in its operations. On the other hand, such increase may lead to an increase in risk. We increased the number of lots to 10 for the best results of Tables IV and V and obtained the results shown in Table VIII. We can see that by increasing the number of lots of the operation we also increase the risk involved in the operation due to the growth of the MD. On the other hand, this enable a considerable increase in the ROI in comparison to the previously performed experiments (with lots = 1), as shown in Table VIII.

V. CONCLUSION
This work showed that profitability can be obtained from a model based on two stages, integrating GHSOM and SVR. A set of experiments were carried out using the EUR/USD and the GBP/USD time series and the results have shown that the SVR+GHSOM achieved significant results when operated in daily timeframe. On the other hand, intraday operations obtained unsatisfactory results (negative returns on investiment -ROI). The experiments involving only the SVR model have not generated profit (that is, the ROI was negative), which may be attributed to the fact that the time series are nonstationarity, a problem that is better tackled by the SVR+GHSOM model. Moreover, the experiments revealed that, regardless of timeframe, the SVR+GHSOM model had lower rates of drawdown (MD), i.e., the risk involved was lower for the SVR+GHSOM in comparison to SVR. It was found that the accuracy rates of movement of the market (DS) did not influence the rates of return (ROI) and the system showed much better results when compared to the buyand-hold model for both the Dow Jones Average Index and for the foreign exchange rate itself.
Future work may be performed in order to improve the results. To this end, the trading system could be modified to manage the risk involved in the operation, adjusting the number of lots for each transaction and using automated closing operations, such as the use of trailing stops, stop loss and take profit. In addition, the proposed model can use more technical indicators as inputs aiming to improve profit. The choice of the indicators could be carried out by a genetic algorithm and this may improve the results of intraday operations. However, the number of parameter of SVR and its relatively slow training can hinder the use of genetic algorithms for selecting input technical indicators. A solution to this problem would be to use regression models with faster training, as is the case of OPELM, which was shown to perform several orders of magnitude faster than SVR while maintaining the accuracy [23].  Table VI for ROI comparison)  Table VII for ROI comparison)