DECISION SYSTEM FOR STOCK DATA FORECASTING BASED ON HOPFIELD ARTIFICIAL NEURAL NETWORK

The paper describes a new method using Hopfield artificial neural network combined with technical analysis fractal analysis and feed-forward artificial neural networks for predicting share prices for a next day on a Stock Exchange. The developed method and networks are implemented in an Expert System, which is proposed as a valuable comprehensive, analytical tool. A new algorithm for artificial neural networks training and testing is also presented. It automatically chooses the best network structure, and the most important input parameters. Słowa kluczowe: Hybrid intelligent system, Hopfield artificial neural network SYSTEM DECYZYJNY DO PRZEWIDYWANIA CEN AKCJI OPARTY NA SZTUCZNEJ SIECI NEURONOWEJ HOPFIELDA Streszczenie. Artykuł opisuje nową metodę zastosowania sztucznej sieci neuronowej Hopfielda połączonej z analizą techniczną, fraktalną oraz jednokierunkowymi sztucznymi sieciami neuronowymi do przewidywania przyszłych cen akcji na Giełdzie Papierów Wartościowych. Opisane nowe metody zostały zaimplementowane w systemie ekspertowym, który jest polecany jako kompleksowe narzędzie do badania aktualnych i przyszłych zachowań rynku. Zaprezentowany został również algorytm nauki testowania sztucznych sieci neuronowych, który na końcu wybiera najlepszą z nich. Słowa kluczowe: Hybrydowy inteligentny system, sztuczna sieć neuronowa Hopfielda


Introduction
Nowadays, in order to make good investments and make profits in the stock market, investors have to take numerous daily decisions every day on the basis of information coming from many different sources.The more information investor has, the more accurate is his prediction.Analysis of stock exchange trends is not easy, but economic studies provide many mathematical models for stock exchange data processing and prediction [2,3,16,17,25].Also efficient software tools allow for stock exchange data presentation and forecasting trends with a certain probability [27].
Although there are many tools on the market supporting investor decisions, they provide only the possibility to display charts with technical analysis indicators or stock prices (e.g.AmiBroker, Statica AT).Therefore, investors usually support their decisions with analysis of brokers or investment advisers to plan strategy for the upcoming session.
Existing and available information systems implement most of the available economic models designed to analyze trends on a stock exchange, but none of them is able to comprehensively analyze and display future prices of assets.Therefore, a novel expert system was designed and implemented, which uses author's algorithms with soft computing methods for data processing and analysis.Research was based on hybrid models using technical analysis and artificial neural networks.Hybrid modelling approach is used more often lately by many researchers [11,12,13,14,15].The aim, of using hybrid models for shares forecasting on Stock Exchange is to reduce risk of failure and obtain more accurate results.A database of economic models is built on the basis of historical data from the stock exchange, which is used in optimization algorithms.The aim of the implemented algorithms is to examine all companies on the stock market, selecting those, which price is predicted to rise and sort them according to the forecast outcome.Models implemented in the system for CLOSE prices prediction were built on the basis of:  Artificial Neural Networks (ANN)the most common use of ANN on Stock Exchange is: prediction of future stock market indices [3,22,24], exchange rates [16], share prices [19], etc.  Fractal Analysis and ANNit has been proved by the authors, that combination of fractal analysis with ANN is very effective in prediction of future assets [20]  Technical Analysis (40 indicators, Elliott wave principle, Fibonacci sequence, Fisher Transformation, Ichimoku Number Theory, etc.) [17] and ANN.

Technical analysis indicators and theories
Technical analysis indicators are used to determine trend of the market, the strength of the market, and the direction of the market.Some technical analysis indicators can be quantified in the form of an equation or algorithm.Others can show up as patterns (e.g., head and shoulders, trend lines, support, and resistance levels).At some point, the technical analyst will receive a signal.This signal is the result of one technical analysis indicator or a combination of two or more indicators.The signal indicates to the technical analyst a course of action whether to buy, sell, or hold [5].
The most commonly used technical analysis indicators are moving averages and oscillators [17].These indicators which were selected for the proposed approach are described in section 1.1.

Technical analysis indicators
Exponential Moving Average (5-, 10-, 20-days) where: acoefficient Oscillators (chosen 9 from 40) a. Rate of Change (5-, 10-, 20-days) -ROCdetermines the rate of price changes in a given period (usually 10 days) b. Relative Strength Index -RSIi.e. the measure of overbought/oversold market.It assumes values in the range of 0-100.For values greater than 70 it is considered that the market is buyout.When oscillator values are below 30, it signifies that market is sold out.In the case of periods of strong trends it is assumed that the market is buyout when RSI > 80 (at the time of a bull market) and sold out for RSI < 20 (during a bear market).For:  where: U(k)average increase in the k-th day, D(k)average decrease in the k-th day.c.Stochastic oscillator (K%D)determines the relation between the last closing price and the range of price fluctuations in the given period.The result belongs to the range of 0-100.K%D > 70 is interpreted as the closing price near the top of the range of its fluctuations, and K%D < 30 points to the fact that prices are shaping near the lower limit of that range.
where: V(k)total number of shares which were rotated on k-th day.f.Bollinger Oscillator (BOS k ) Its construction is based on Bollinger bands.Bollinger oscillator informs when market is overbought or oversold.
where: SD(k) -Standard Deviation(k).g.Detrend Price Oscillator (DPO)the indicator is designed to help in the search for short-term price cycles, useful for tracking local turning points

h. Bollinger Bands
The use of Bollinger Bands is based on the price line placed in the arms of bands.They are positioned within the double standard deviation from the course line and define the area of price volatility.Reaching the course line to the band is probably a short-term reversal of the trend and the signal to buy or sell.
where: ULis an upper line, DLis down line.
i. Donchian channel indicator Buy when the course stands out above the maximum level of prices of the previous N number of days, close the position if the price falls below the minimum price level of the previous M number of days (N = 10, M = 20).

Technical analysis theories
a. Elliott Wave Principle Theory is based on assumptions [17]:  There is a main trend, which consists of five waves which move in direction of the main trend followed by three corrective waves (5-3 move is a complete cycle). The complete cycle becomes two subdivisions of the next higher cycle.Considering above rules the Elliott wave creates a fractal.b.Fisher Transformation -FT Fisher transformation is used, if the distribution of price changes has not a normal distribution [8].Fisher Transform is a mathematical procedure that transforms a set of input data into a set of data which probability density has the normal distribution.After application of the Fisher transformation the result data set can be used for all statistical methods appropriate for a normal distribution.(11) where: xinput signal, youtput signal.
The solution of equation ( 11) due to x gives the relationship: (12) In this work Fisher transformation is used with RSI indicator.Calculations are based on equations: The result of the equation ( 13) is a number between <-5, 5>, and the output signal y is in the range of <-1, 1>.To obtain a normalized result falling within the range <0, 100>, the following transformation has to be done: 2 2 where: Hhighest asset price for a given period of time where (k = 20, i = 10), Llowest asset price for a given period of time where (k = 20, i = 10).
According to Ichimoku Number theory, if TL line crosses the SL line from a bottom it gives a buying signal.Selling signal is being created when TL line crosses the SL line from a top.Situation when DT line is higher than Close value from current day gives buying signal.In any other case it is a selling signal.
The interval between 1S and 2S lines represents the support and resistance levels.
This technique creates information whether to buy or to sell stocks.The Expert System, which was developed for investment decision support for each result, assigns 0 when receives selling signal or 1, in the case of buying signal.All three values are being summed, and when the result is in the range <2, 3>, application is sending buying signal to Hopfield network.

Fractal analysis
Recently it can be seen that fractal market hypothesis is constantly expanding.It was presented for the first time by Petersin in 1994 [9], and is based on chaos theory [7].Fractal shapes can be formed in many ways.The simplest is a multiple iteration of generating rule (e.g. the Koch curve or Sierpinski triangle).They are generated in deterministic way and all have fractal dimension.There are also random fractals, like stock prices, which are generated with the use of probability rules.
Performing a fractal analysis is based on identification of fractal dimension.To do this, chart has to be divided into N small elements with S surface.The relationship between the number of objects N 1 and N 2 , which are used to cover the first and second graph with objects of surface size, respectively S 1 and S 2 , describes the relationship [9]: where: Dfractal dimension In order to measure fractal dimension on stock exchange, we need to divide the given period of time by two.For each period, share prices curve have to be divided into N pieces.It can be done by dividing the subtraction result of highest and lowest value on graph in given period of time, by this period: where: H T (k)the highest share price in the first period T, H 2T (k)the highest share price in the second period (from T till 2T), H 0-2T (k)the highest share price in 2T period, L T (k)the lowest share price in the first period T, L 2T (k)the lowest share price in the period from T till 2T, L 0-2T (k)the lowest share price in 2T period.
Fractal dimension is used in this paper in Fractal Moving Average (FRAMA).This moving average is based on Exponential Moving Average (eq. 1) where a coefficient is constructed with the use of fractal dimension:

Hopfield artificial neural network
Hopfield ANN (see Fig. 1) is a main representative of recurrent networks, which because of its function is also called associative memory.
Fig. 1.Hopfield ANN scheme [21] Hopfield ANN consists of a set of interconnected neurons.The activation values are binary {-1, 1}.Neurons update their activation values asynchronously.Update of a unit, depends on other units of the network and on the unit itself.A unit i will be influenced by another unit j with a certain weight w ij , and have a threshold value.

Data processing and analysis
Signal flow for a single company in the designed system is shown in Fig. 2. where n is a number of the used prediction algorithms and the current CLOSE price is the last value of results table.
The "Comparator" algorithm counts the differences between assets of the current CLOSE price and the predicted future one.The Comparator algorithm creates a Boolean table and inserts 0 in case of negative value and 1 in the case of positive value for the tested company.3) Results in the table are being processed by the Hopfield artificial neural network, which on its output returns information whether to buy or to sell.Hopfield ANN is working according to following rules:  0 values from "result table" were changed into -1 values so that they would be recognized by Hopfield ANN (HANN). HANN has been taught with words created from signals from previous days (a set of 1 and -1) from companies which share prices had raised. The current "word", created from signals from result table for the next day is compared with known word patterns. If word is similar to one of learned patterns, the difference is calculated and it is determined if stock prices will rise or not.In the case of true, +1 signal is being returned back to Comparator algorithm, in a different case -1 is returned (and changed into 0).Comparator [18] creates a list of all companies which price will increase.The list is being sorted in a descending order (according to the difference between the current and the future price).The sorted list with the current Close values is sent to the Spring Web Layer [25], which fulfils the role of a Graphical User Interface.The number of the displayed companies is specified by the user.

Experimental research
Research was conducted for all companies appearing on the Warsaw stock exchange until 14.04.2014.The aim of the research was to examine by the Hopfield artificial neural network, which assets will be raising on the current day.As an input the Hopfield network receives previously tested ANN [18,19], technical analysis indicators and fractal analysis (Fig. 2).
The research was performed with the use of Java and Encog 3.2 library, creating ANN of MLP [19] type.Each tested network consists of an input, hidden and output layer.
A common feature of all of the tested network architectures is a small number of input nodes and neurons in the hidden layer, and only one neuron in the output layer.Too many neurons would increase the network training error and could cause learning time extension [23].The relations between the number of input nodes and the number of neurons in the hidden layer were tested for the combinations shown in Table 1.Market indicators for the input data were selected as described in literature [1,4,10,16,26] and were selected on the basis of calculated weights of the ANN, learned with the use of Teacher algorithm (Fig. 3).The Teacher algorithm has been used for training and testing artificial neural networks.Every ANN is a multilayer perceptron type (MLP).In the study, MLP networks and hybrid MLP networks predict Close prices for the next day.The algorithm assumes that only ANN with a set of <4, 30> inputs will be trained with Levenberg-Marquardt [20], Resilient Propagation and Back Propagation algorithm.

Table 1. Combinations of the tested MLP architectures
All indicators have been divided on three groups:  Trend Indicators (TI),  Variation Indicators (VI),  Momentum Indicators (MI).
Each indicator has a number which will be used as an identifier during the selection of the input data to ANN.
In the first step the Teacher collects all indicators and closing prices from database and divides them into learning data and testing data in the proportion of 70:30.The algorithm also supplements the list of teaching codes on which basis, ANN will be taught and tested.Code is a three digit number where first digit mean an identifier of a neuron activation function, the second one identifies a teaching method and the last one, defines type of ANN.All tested and used possibilities are shown in Table 2. ANN training was performed according to the following rules: 1.All entered data were normalized using the following formula: (Value/Value max )*0.8 + 0.1 (26) 2. For each ANN architecture and each set of input data, eight neural networks were trained with the use of Teacher algorithm (shown in Fig. 3) and the ANN with the smallest medium square error (MSE) for the testing data has been selected as the best one.
In the next step, the function return Word(t,i,z) creates a string with IDs of indicators that will be used in the learning process.The parameters t, i, z are numbers of different types of indicators (correspondingly TI, VI, MI).Indicators are chosen according to the following rules: 1.There is never less than two TI 2. Choosing indicators as an input is based on randomness.In the third step the algorithm runs the executeTeaching() method for each code combination from the list of codes.The ANN is trained and tested according to the code and the word.The whole process is repeated eight times and the ANN with the best test result is saved in the database.

Results
The presented results refer to all examined feed-forward ANNs.Results of the Hopfield ANN were tested off-line for historical data from the Warsaw Stock Exchange with the use of the Tester program.The Tester allows to download a stock data from the previous month and one by one send them to the examined expert system, where all indicators and ANN are being calculated and tested.Prepared results table is passed to Hopfield network which decide whether to buy current company stocks or not.If result is positive, Comparator algorithm displays companies sorted in a descending order.The predicted and the real Close price values are compared and gains and losses of the system are being calculated.This allows to assess the accuracy of decisions, based on Hopfield artificial neural network.A sample result is presented in Fig. 4.
The system was tested off-line for historical data between 02.02.2015 -31.03.2015.The generated revenues exceeded expenses and brokerage account profits by approximately 13.59% of the investment.Results from February (6,7%) and March (6,89%) have been generated by a Tester program.
In tested period of time, growth in major Polish indices were on the level of 2.82% for WIG20 and 5.69% for MWIG40.

Conclusions
The obtained results indicate that the proposed decision system based on Hopfield artificial neural network and using Multi-Layer Perceptron, fractal analysis, technical analysis and theories allow to analyze and identify companies that will bring profits.In the tested period of time 61,9% correctness (which means 61,9% of correct investment decisions) was achieved, what resulted in 13.59% of profits.The obtained results are better than average percentage profits gained on the Warsaw Stock Exchange in the same period of time estimated from the basic indices changes.-This copy is for personal use only -distribution prohibited.
T h i s c o p y i s f o r p e r s o n a l u s e o n l y -d i s t r i b u t i o n p r o h i b i t e d . 29 c. Ichimoku Number theory Technical analysis method which basis on five lines:  Standard line (20-session) -SL,  Return line (10-session) -TL,  Delayed line (Close price C -21 ) -DL,  First line of the range -1S,  Second line of the range -2S, T h i s c o p y i s f o r p e r s o n a l u s e o n l y -d i s t r i b u t i o n p r o h i b i t e d .2083-0157, e-ISSN 2391-6761

Fig. 2 . 2 )
Fig. 2. Information system scheme At the start all historical shares data from Warsaw Stock Exchange is uploaded into database and used to calculate stock indicators.Since then, every day, after end of each session on the Warsaw Stock Exchange, the system downloads a set of the current day data, such as: close, open, lowest, highest price of stocks and their volume.These data are processed for each company and used to calculate Technical Analysis (TA) indicators. 1) TA indicators and historical data are being processed with:  ANNs, Fractal analysis and based on it Artificial Neural Networks for CLOSE prices prediction for the next day [18, 19]. Algotrading algorithms which on the basis of technical analysis choose the moment of selling and buying shares. Algorithms which build charts developed on the basis of Elliott wave principle [17], Fisher Transformation and Ichimoku Number Theory.T h i s c o p y i s f o r p e r s o n a l u s e o n l y -d i s t r i b u t i o n p r o h i b i t e d .

3 .
Indicators of the same type are being divided with # character.Indicators of a different type are divided with % and $ character (e.g.1#2%2#3#6#15$2#10) 4. For one ANN input k number of tested words are considered k=(input-2)*2+1 where, knumber of tested words, inputnumber of the ANN input node.

Fig. 4 .
Fig. 4. Accuracy of the Expert System prediction based on Hopfield ANN T h i s c o p y i s f o r p e r s o n a l u s e o n l y -d i s t r i b u t i o n p r o h i b i t e d .-This copy is for personal use only -distribution prohibited.-This copy is for personal use only -distribution prohibited.-This copy is for personal use only -distribution prohibited.

Table 2 .
Combinations of the tested MLP architectures