As described in the previous section, in this paper the authors proposed an innovative profitable grid trading system for the FOREX market, which, therefore, bring all together the advantages of each part of the described pipeline, i.e., the performance and efficiency of the grid algorithms, the capability of recent machine learning tools and the high liquidity of the FOREX market. In
Figure 1, the authors reported an overall representation of the proposed pipeline.
As previously introduced, the target of the pipeline showed in
Figure 1 was to propose an innovative trading algorithm that exploits the capability of the grid methodology together with the HFT approaches. A brief introduction of the pipeline scheme highlighted in
Figure 1 was reported. Preliminarily, like any trading system, it appears propaedeutic to determine the trend of the instrument to be traded so as to define the direction of the financial transaction (long or short or null operation in the case of no well-defined trend). For this task, the authors proposed the use of a non-linear “Regression Network” for instrument close price forecast, together with a “Trend Classifier” block that on the basis of analytical predictions performed by the regression network, estimates the most probable short-term financial trend. At this point, the proposed system will take care of autonomously organizing the trading grid by evaluating the current state of trading such as the opened transactions of the same sign as the opposite sign, the current drawdown, balance of the trading account, opening constraints, etc. These evaluations will be performed by the “Grid System Manager” block illustrated in
Figure 1. For the correct evaluation of the performance of the trading system, the authors suggested the use of a block called “Basket Equity System Manager” that will deal with evaluating and monitoring the financial exposure of the trading grid, therefore, to close all positions as soon as the system reaches a pre-established target profit.
The proposed approach was implemented and designed for high frequency trading (HFT). Particularly, we performed trading strategies on the FX market considering 1 min (one minute) timeframe EUR/USD currency cross. We collected the EUR/USD currency data from the Tickstory Database [
7], which exports historical data with 99.9% accuracy. Specifically, we have collected the following currency prices EUR/USD data: Open, close, high and low as well as the volume in a 1 min timeframe. In order to validate the proposed method, the training and testing data were selected from latest five years of EUR/USD quotations. Each of the referred blocks in
Figure 1 will be detailed in the following sections.
3.1. GTSbot: Regression Network SCG
The purpose of the regression network scaled conjugate gradient block (SCG) is to forecast EUR/USD currency close price using previous pricing data such as open, close, low, high and the volume of exchanged currency shares. As described in the previous section, machine learning and deep learning are widely used in the field of automatic trading systems development as well as for addressing a lot of financial issues including time-series forecast [
3]. As it is well known in literature, the financial time-series are highly unpredictable in the mid-long-term timeframe while they showed a fair predictability in the short-term [
3]. Considering that, the proposed approach has been designed to be integrated into a high frequency trading (HFT) system in order to improve the overall predictability of the financial trend. In the method herein described, the authors proposed a classical feed-forward regression neural network in combination with a modified back-propagation (BP) method known as scaled conjugate gradient (SCG) BP algorithm. The core idea of the SCG algorithm is included on the classical conjugate gradient methods (CGM), i.e., a class of optimization techniques that allow for minimizing the second derivative of the used learning goal function [
8]. From a general point of view, the neural network learning procedure is equivalent to minimizing a well-defined performance error function, which is basically a function that depends on the weights of the network. For these reasons, the neural network learning phase often involves the adjustment of several thousands of weights so that optimization methods are relevant to reduce the overall learning complexity.
Most of the mentioned optimization methods are based on the same strategy. They try to minimize the performance error function by means of a local iterative process in which an approximation (usually trough a first order Taylor series expansion of the performance error function) in a neighborhood of the current point (in the weight space) is applied in order to search a minimum of the performance error function. Basically, for each interaction “
k”, the learning algorithm determines a search direction for which the global performance error function, at interaction “
k”, is lower with respect to the previous value at interaction “
k-1”. Once the search direction has been found we have to decide how far to go in the specified search direction, i.e., a step size has to be determined. Some algorithms propose to set the search direction to the negative gradient direction (the so called “gradient descent algorithm”) as they usually occur in most of the back-propagation learning algorithms described in the literature [
8].
The recalled conjugate gradient methods are also based on the above general strategy with the only exception being the choice of the search direction and step size are performed by using information from the second order Taylor expansion approximation of the performance error (the so called Hessian matrix). This means that performance error is basically a quadratic function. Well, by means of specific mathematical proprieties of the quadratic functions [
8], the CGM algorithms assures that the global minimum is detected in a reduced number of iterations with respect to a classical gradient descent-BP algorithm. Anyway, for each learning iteration, the Hessian matrix has to be computed considerably increasing the computational complexity of the algorithm. In the SCG algorithm this complexity is reduced by means of an estimation and approximation of the Hessian matrix for which it will no longer be necessary to calculate each matrix coefficients at each iteration but rather it will be possible to proceed with an estimation, evaluating in any case the goodness of this approximation by means of some heuristic parameters and checks. This result can be obtained by applying the Levenberg-Marquardt approach to the conjugate gradient methods [
8]. Obviously, for these reasons the SCG algorithm requires only O(N) memory usage and O(NlogN) of learning complexity (against O(N
2) and O(N
2logN) of classical BP algorithm, respectively) where N is the number of used neural weights in the network [
8]. According to this, we implemented a SCG BP neural network composed by five neurons in the input layer, 500 neurons in the hidden layer and one neuron in the output layer. The output is the predicted currency cross close price. As reported in [
8], the SCG BP neural network achieves effective results in terms of fast convergence even if it shows some drawbacks in terms of regression performance [
8]. Anyway, the purpose of our pipeline consisted in predicting the trend in the short-term timeframe and not the exact close price. In
Figure 2, an instance of the EUR/USD forecasted close prices for a subset of days on January 2018 is reported.
In
Figure 2 and
Figure 3 represented the regression performance showed by the used SCG BP neural network, which was not optimal while on the other hand it was evident the ability of the used neural network to predict the trend of the traded currency.
Future works aims of improving the performance of the SCG BP regression block in forecasting the currency close price. We are analyzing the application of ad-hoc cross currencies correlation analysis [
9] or by replacing the SCG BP neural network with recent deep neural network architectures such as Stacked AutoEncoders, Convolutional Neural Networks (CNNs) or Long Short Term Memory neural networks (LSTMs) [
10].
3.2. GTSbot: Trend Classification Block
The output of the regression network SCG block (the predicted currency close price) was used to estimate the most probable trend of the traded financial currency cross. In a classical 1 min (one minute) intraday trading timeframe, there are
n close price quotations so that if we denote
the close price to be the predicted at k-time (by the SCG BP neural network), then we define the following relationship (1):
We denoted
as the regression map function of the SCG regression network block. At the next step, the trend classification block (TCB) provided an estimation of the current financial trend performing the following check:
Basically, the TCB performs ad-hoc fast mathematical analysis of the financial currency time-series acquired from the broker quotations. More in detail, the TCB system performs careful analysis of the first and second derivative of the collected FX cross time-series and the predicted close price at (
k+1)-time. It can be noted that, if the first derivative is greater than an empirically defined threshold
(defined equal to the broker spread), then the trend increases over time (long trend). To confirm this we needed to check whether the sign of the second derivative, which is a robust measure of the concavity of the acquired time-series curve. If both conditions were true, the TCB confirmed the long trend or short trend, otherwise. If at least one of the above check failed (i.e., the first and second derivative did not show same mathematical behavior), it was enough to indicate that the trend was not well determined, therefore, no operation was suggested. For the mathematical computation of the first and the second derivative, we used the Equations (3) and (4), respectively.
In
Figure 4 an instance of the trend prediction made by TCB is reported, both for the long trend as well as for the short ones.
We tested the described trend forecast algorithm over EUR/USD currency historical data (as said: Latest five years (2014–2018)) at 1 min timeframe. From our experimental results, the TCB was able to forecast the trend with an accuracy of 73.2%.
3.3. GTSbot: Grid System Manager Block
The aim of this block was to open a grid-trading scheme according to the predicted trend as per the algorithm inside the previously described TCB. As already stated, if the trend predicted was null, the system would not perform any operations. The grid system manager (GSM) block performed a long operation if the TCB estimated the long trend while it performed a short operation if the TCB estimated a short trend. In the first case, we bought the FX cross, while in the second case we decided to perform a short selling of the FX currency. The FX market price at which the GSM performed the operation was the available open currency price. Anyway the GSM block performed the specified operation if and only if the grid condition was also verified. The grid condition represented the additional constraint in the GSM block we had designed to build a robust and effective trading framework for the proposed pipeline. According to the trend estimation from TCB, the GSM block performed a careful check of the current status of the trading acitivities.
Figure 5 shows the workflow followed by the GSM block. The first target of the GSM block was a further deep analysis of the estimated trend made by TCB. If TCB returned the null trend, the GSM block workflow jumped to “No Operations” waiting for the next prediction made by the GSM block. Otherwise, if the long or short trend was detected by TCB, the GSM algorithm checked the overall number of opened operations in the current grid trading system. During the trading activities, a maximum number of operations (long and short) was defined, according to the available investment fund in our trading account. Consequently, the GSM block checked if the maximum number of operations was reached and it proceeded with the next check on the workflow, i.e., the grid distance. Obviously, if the system had already opened all the allowed operations, the GSM algorithm jumped to “No operations”. Instead, in case the maximum number of operations had not been reached in both the long and short trades, the GSM workflow checked the grid distance constraint, i.e., the minimum distance in number of samples (abscissa axis of the
Figure 3) and in the currency price with respect to all opened trades with the same direction. Basically, the GSM block will open a trade (long or short) if and only if the x-distance and y-distance between the current FX cross price at which we want to open the trade and all the corresponding x-values and y-values we still had for each opened trades (with the same direction) was greater than the x-threshold and y-threshold we had defined in our GSM block.
Figure 6 reports the described pipeline.
From the representation shown in
Figure 6 we can better understand the working flow of the GSM block. In the detail of the financial time-series explored in
Figure 6, the already opened operation was identified by the green circle. During the normal trading activity, the proposed algorithm proposed the opening of another long position represented by the red circle reported in
Figure 6. However, the GSM block discarded this proposal as they were not respecting the grid conditions both in reference to the abscissa axis (distance x1) and in relation to the price value (distance y1) as they were both considerably below the pre-set thresholds. On the other hand, the subsequent proposal to open another long position (blue circle) was granted by the GSM block because it respected both the conditions relative to the grid distance with respect to the position already open (distance x2) and the condition relating to the distance of the price value (distance y2). Therefore, in the hypothesis that was in the example shown in
Figure 6, the maximum number of operations had not been reached, the GSM block would confirm and execute the opening of the second long order proposal, characterized by the blue circle in detail in
Figure 6. In this way, the GSM block would be able to open such trades in grid schemes and operations appropriately spaced from each other in order to average any wrong trades open against the real trend. The heuristically defined x-thresholds and y-thresholds allowed the prevention of several wrong trades very close to each other being opened by the GSM block. To confirm what has been said, we had tried the proposed approach disabling the checks performed by means of the mentioned x-thresholds and y-thresholds. Specifically, we had tried the grid trading system robot (GTSbot) system without the x-threshold based check. The so modified algorithm had performed lower with respect to the same with the x-threshold check enabled. More in detail, we noticed a considerable increase in the drawdown (on average +25%) accompanied by a reduction in profit (−10% of daily profit in average). Similarly, with the y-threshold control disabled, we found a considerable increase in the drawdown (+18.3%) along with a reduction in daily profit (−11.25%). The above tests (performed in the scenarios reported in
Table 1 and
Table 2) confirmed the key role played by the x-thresholds and y-thresholds based checks in the proposed system.
This approach provides a simple and effective method to compensate any drawdown drifts due to wrong opened trades. We performed several tests in order to select a robust values of x-threshold and y-threshold as well as the maximum number of allowed operations with an intraday investment perspective. According to our experimental results, we decided to use the following values:
x-threshold = 15 (candlestick, i.e., 15 min in a 1 min timeframe);
y-threshold = 0.00020 (two pips according to FX 5-digits quotations);
Maximum number of operations = 13.
The x-threshold set to 15 indicated that the GSM block did not open any operation if we have at least 15 samples (or candlesticks) of distance between each opened operation and new ones. Similarly, GSM block did not open any operations (long or short) if the FX cross quotation value at which we want to open a new trade was greater or lower (according to the type of operation if it was long or short, respectively) than the y-threshold with respect to all the prices at which previous trades (in the same directions) had been opened.
The used distance metric was the absolute distance. The FX cross quotation value was measured in pips, which was the standard unit for FX markets. The maximum number of allowed operations had been defined as an odd number because we want to avoid a perfect hedging condition in which we had a number of long trades exactly equal to short ones as the trading system became market neutral. Formerly, the GSM block would proceed opening a trade if (in the hypothesis of the defined trend detected by TCB):
Short trade:
where we have defined
and
as the x-threshold, y-threshold and maximum number of trades respectively while
represents the current currency price at which we want to open a trade and
represents the price at which we have already opened previous trades.
3.4. GTSbot: Basket Equity System Manager
The basket equity system manager (BESM) block is able to monitor the econometric balance of the trading account. This block performs at each quotation (according to the timeframe we have selected) the current monitoring of the overall balance indicators of the FX broker account we were using. It checks the drawdown, the account fund availability, net account availability, which is basically the total balance account deducted, the current drawdown and the operative margin amount the broker incoming for each opened trade (this value is strictly correlated to the adopted leverage, i.e., for a leverage 1:30 for each LOT FX trade, i.e., an investment of 100,000 US dollars; an amount of about 3000 US dollars is required as a margin withheld from the broker). By means of BESM block the proposed pipeline monitors the current status of the trading account according to the prefixed take profit and stop loss. In the proposed grid strategy, we avoided to use stop loss as the grid algorithm, as explained in the previous sections, was able to compensate for the drawdown, resulting in the opening of incorrect trades. Instead, we had defined a take profit as the amount of gain at which the BSEM block will close the basket trades (i.e., the set of all opened trades).