APPLICATION OF A CONVOLUTIONAL NEURAL NETWORK TO CREATE A DETECTOR OF TECHNICAL ANALYSIS FIGURES ON EXCHANGE QUOTES CHARTS

Today, the use of artificial intelligence based on neural networks is the most effective approach to solving image recogni - tion problems. The possibility of using a convolutional neural network to create a pattern detector for technical analysis based on stock chart data has been investigated. The found figures of technical analysis can serve as the basis for making trading decisions in the financial markets. In the conditions of an ever-growing array of various information, the use of visual data reading tools is becoming more and more expedient, as it allows to speed up the process of searching and processing the necessary information for decision-makers. The modeling process, analysis, and results of applying the pattern detector of technical analysis are presented. The


Introduction
Working in the financial markets, traders quite often are guided by technical analysis and, in particular, apply graphical models to make various trading decisions.Using visual data, it is easier to interpret the current market situation, as well as see the history of price movements over long periods of time.One of the main components of this analysis is the pattern.A pattern (figure) in technical analysis refers to constant repeating combinations of data on price, volume or indicator.Pattern analysis is based on one of the axioms of technical analysis: "history repeats itself" -it is believed that repeated combinations of data lead to a similar result.The problem with the trader is that it is necessary to follow one chart to identify the pattern.If still keep a few charts on timeframes older than 4 hours, then it will become difficult to switch to lower timeframes.Along with the above, the problem of pattern identification and the lack of statistics on the successful working out of a graphic figure on a specific chart also arise.
One of the methods of pattern recognition is the use of neural networks (NN).The most modern type of NNs used in pattern recognition is the Convolution Neural Network (CNN) [1].For the high-quality operation of this type of network, it is necessary that the size of the recognized object be comparable with the size of the objects in the learning set.Obviously, the creation of a learning sample, in which, in addition to various types of desired objects, there is also a change in the scale of the object in the image, is an extremely difficult task.To detect patterns of different sizes, a detector has been developed that breaks the analyzed charts into parts of different sizes and scales them to the size necessary for analysis in a convolutional NN.This article discusses the operating principles of the created pattern detector, which allows detecting and recognizing figures of technical analysis, as well as extracting statistically significant information from the obtained data.

Literature review and problem statement
Today, there are a number of works [2][3][4][5], where the use of convolutional NN for pattern recognition of technical analysis has been investigated.Some authors compare the technical capabilities of the convolutional network and the recurrent neural network (RNN) for pattern recognition with subsequent analysis of the data, while others compare them directly for use as a trading strategy in the stock and currency markets.In [2], the results of modeling NN for image recognition are presented, in which the image is first recognized by the convolution network, and then compared with the result of the RNN.The authors chose AlexNet as the structure of the convolutional NN.In [3], a convolutional NN for recognition of the MA (moving average) indicator patterns is presented.As shortcomings in [2,3], one can note a small learning sample of images, as well as a small period of historical data taken for testing the algorithm.The work [4] demonstrated an algorithm designed for automated trading in the stock market with various financial instruments.The National Assembly was learned on the basis of data obtained from sources such as: Yahoo Finance, Bloomberg, Reuters.The data for the learning of the National Assembly from October 2006 to November 2013 amounted to over 10 million events.In this work, the authors using market simulation compared the convolutional NN and the direct distribution network, and according to the results of the experiment, the convolutional network turned out to be more effective for the chosen problem.In [5], deep convolutional NN learning was used to predict the direction of change in the exchange rates EUR/USD, GBP/USD, JPY/USD.The learning was built on the basis of 1565 closing prices, taken from 2010-2015.In a comparative analysis conducted in the work, it was found that econometric models work well only for long-term forecasts.

Computer Sciences
Of particular interest is the use of NN to predict the movement of stock and foreign exchange markets.In [6], convolutional NN was used for multitasking machine learning and forecasting the direction of price movement in financial markets.In this paper, the authors proposed a new method of regularization based on neural networks, requiring only 4 additional hyperparameters that can be easily introduced into any machine learning architecture.In [7], a convolutional network is used to predict price movements and form trends in the stock market by analyzing the time series of S&P500 quotes in the Forex market.
To search for patterns of different sizes on one exchange chart, it is necessary to create a detector that divides the original chart into parts, which will be sent for analysis to a convolutional NТ.The article [8] describes the convolutional NТ architecture and its use for detecting images, and in [9] for the analysis of video sequences.Articles [10][11][12][13][14] show the evolution of the R-CNN (Region-based Convolutional Network) algorithm in Fast and Faster R-CNN, Mask R-CNN, intended for the detection and recognition of objects in images.
The article [15] presents the YOLO algorithm (You Only LookOnce), which allows detecting and recognizing objects in images 103 times faster than R-CNN and 102 times faster than Fast R-CNN, but with lower accuracy.The algorithm overlays the grid on the input image and divides it into cells.Around each cell, the algorithm determines the bounding box of the zone of the possible location of objects with an assessment of the accuracy of detection and the probability of belonging to classes.Then, the accuracy estimate for each zone is multiplied by the probability of the class and the final value of the probability of detection is obtained.The algorithm processes from several hundred to tens of thousands of parts of the image with bounding frames of different sizes.
In [16], the SSD: Single Shot Multi Box Detector algorithm was demonstrated, which is comparable in accuracy and speed to YOLO.The algorithm covers the entire area of the input image with bounding frames, the size of which varies within the set limits, which allows to detect and recognize objects of various sizes.
In the article [17], the theme of creating a boundary detector of objects of interest based on Kohonen neural networks with the subsequent analysis of data in a convolutional NN is discussed.
To minimize the time and resources spent during the operation of the detection algorithm, it is necessary to reduce the amount of data required for subsequent analysis.This algorithm can be implemented in the following ways: 1) Phased splitting of the input image into frames the size necessary for convolutional NN, with the frame shifted by a certain number of pixels relative to the previous one.
2) Using the algorithms R-CNN, Fast and FasterR-CNN, Mask R-CNN, YOLO, as well as SSD.
Both methods require a lot of time and computational resources, dividing the input image into several thousand frames, which are fed to the convolutional NN for analysis.
From the above it follows that at the moment there is a need for the financial industry for algorithms that can quickly and efficiently recognize patterns, reduce the human factor in evaluating visual data, and also extract additional information from financial market charts.
The aim of research is creation of a detector for determining patterns of technical analysis on a timeline using a convolutional NN based on data obtained from financial markets, as well as obtaining statistical data on the economic feasibility of using various types of patterns.
To achieve the aim, the following objectives are set: -creating a learning sample for convolutional NN; -development of the detector operation algorithm for searching and highlighting the boundaries of patterns that are present on the time chart; -assessment of the speed of the convolutional NN and the accuracy of the detector on test and real input data.

Materials and methods for highlighting the boundaries of patterns located on the charts of financial markets 1. The principle of operation of the convolutional neural network
The use of neural network technologies is primarily due to one important property -the ability of NNs to learn based on available data.In the standard case, NN is a program based on a mathemati- Computer Sciences cal model of the functioning of biological NN and simulates the brain processing a specific task.As in biological NN, the basic element of artificial NN is a neuron.Neurons connected among themselves form layers, the number of which can vary depending on the complexity of the NN and the tasks it solves.Pattern (signal) recognition is formally defined as a process, as a result of which the input image should be assigned to one of the predefined classes (categories).In this case, the NN must decide on whether the objects under study belong to certain classes.So that the NN can solve the problem of pattern recognition, it must be learned on a number of examples organized in the form of a set of input data associated with known output values (classes).The more variously noisy learning data will be supplied, the more reliable will be the recognition of images in conditions of random interference.One of the most modern types of NN used in pattern recognition is the convolutional NN, which got its name due to the presence of the convolution operation.The essence of this operation is that each fragment of the input image is element-wise multiplied by the convolution kernel, and the result is summed and written to the same position in the output image.After that, the result is fed to the sub-sampling layer (dimension decreases) and, in the simplest case, a fully-connected NN (multilayer perceptron).The structure of the convolutional neural network is shown in Fig. 1.

2. Pattern detector operation algorithm
Before to transfer the input data for analysis to the convolutional NN, it is necessary to carry out their preliminary processing.
The algorithm of the pattern detector located on the charts of financial markets is as follows: 1) According to financial markets for a selected time period, a "window" of various durations is run, breaking it into frames.
2) The frames highlighted by the "window" are normalized to the range from 0 to 1 according to the formula (1): where f( ) -the normalization function, p -the numerical value of the discrete input signal, min -the minimum value of the signal sample, max -the maximum value of the signal sample.
3) The obtained data is scaled to the size necessary for analysis in a convolutional NN and converted into a 2D matrix.
4) 2D convolutional NN determines the probability of each frame belonging to one of the types of patterns or noise.
NN with three layers of 2D convolution, as well as using the BatchNormalization, MaxPooling, Dropout and RELULayer layers in front of the fully connected layer and the classification layer, was learned on images of ideal figures of technical analysis, the amplitude values of which were applied augmentation with standard deviation 0.2 and normalization by the formula (1).Scaling all the "windows" to a single size made it possible to avoid variations in the length of the figure in the learning set, significantly reducing its size.

Results of the pattern detector operation
To evaluate the results of the detector's work, graphs were simulated similar to financial market data, which contain noisy figures of technical analysis of various durations and random When highlighting the boundaries of patterns that differ by less than 3 samples, the boundaries with the highest probability of belonging to the class were selected.
The detector was also tested on real data from stock charts, where it showed high results, comparable with the results of work on test data.Data processing for 1000 days by a neural network took about 0.65 seconds on a personal computer in the configuration of Core i7-8700, 32 GB of RAM, NVIDIA GeForce GTX 1080.
The result of the pattern detector using real input data is shown in As can be seen from Fig. 2, the detector successfully selects the "Double Bottom" and "Rising Triangle" patterns of technical analysis of different sizes on the financial market price charts depending on the closing date.Analysis of the data presented in the National Assembly amounted to 0.23 and 0.32 seconds, respectively.

Research results
As a result of the research, a detector was developed that defines the boundaries of the patterns of technical analysis of various sizes on the charts of stock quotes.The accuracy of the detector is about 98.6 % with a convolutional NN response speed of about 0.65 seconds per 1000 data samples.
The developed pattern detector has the following advantages: 1) A detector that automatically analyzes data removes the need for a visual analysis of exchange charts by a person and opens up prospects for building trading strategies based on the obtained statistical data for each type of pattern.
2) Due to the scaling of "windows" to a single size, there is no need for a large and varied learning sample for the convolution network.
3) The detector provides the user with the opportunity to choose the deviation degree of the shape of the found patterns from the base, thereby expanding the possibilities of further statistical processing.
4) The speed of the detector allows to search for patterns and analyze statistics in real time.
Defining the boundaries of patterns allows to identify the following important statistics: 1) By analyzing the values of the price before the beginning of the figure, it is possible to determine the context preceding the appearance of the patterns and exerting a certain influence on them.
2) By analyzing the price values after the end of the figure, it is possible to determine the percentage of successfully worked out figures that were already present on the chart earlier in order to assess the degree of confidence for each type of pattern in relation to a specific chart or to their combination.

Discussion of the results of the created pattern detector
Today, people in the stock market have access to a tremendous amount of different information that is necessary to make the right decisions about buying or selling various assets.The success of the trader directly depends on the speed of processing and the accuracy of the assessment of the incoming information, which in the conditions of an ever-increasing amount of it, is becoming increasingly difficult.The use of automatic data processing tools is becoming more and more expedient, since it allows to speed up the process of analyzing the necessary information and provide an estimate of the probability of future events, based on an analysis of previous ones.In terms of accuracy and speed of operation, the created detector complies with world analogues, allowing data analysis in real time and for any time period, which meets market requirements and is not available to most similar solutions.Also, the developed detector allows one to determine the exact boundaries of the beginning and end of patterns, which makes it possible to analyze the context before the pattern and play it back after, while most analogs determine only approximate boundaries.Based on world experience, in the future it is planned to compare various types of NN for use in the pattern detector and to automate the analysis of the context and wagering of figures.It is also planned to study the possibility of reducing the data analyzed by the detector when searching for patterns, i. e. the number of "windows" entering the NN.

Conclusions
The learning sample for the convolutional NN was obtained by augmenting the ideal figures of technical analysis, and scaling the size of the "windows" in the detector to a single size made it possible to abandon the use of a large and varied sample.
The algorithm of the detector is as follows.According to financial markets, a "window" of various durations is run, breaking it into frames that scale in duration to a single size and to 1 in amplitude.Further, the received frames are converted into 2D matrices and fed for analysis to a 2D convolutional NN, which determines the probability of frames belonging to the classes of patterns.
The detector was tested on data in which noisy figures of technical analysis of various durations and random noise are present, as well as on real input data of stock quotes.The accuracy of the detector is about 98.6 % with a convolutional NN response speed of about 0.65 seconds per 1000 data samples, which corresponds to an analysis of the closing prices of trades on the exchange for more than 2.5 years.

Fig. 1 .
Fig. 1.The structure of the convolutional neural network accuracy of the detector when searching for patterns on test data was about 98.6 %.