A Hybrid Fuzzy-Neural Model for Pattern Detection to Predict the Egyptian Stocks Price Movement Direction

In this paper, a hybrid fuzzy-neural system for Egyptian stocks price prediction is proposed. The model helps choosing the right stock mixture with the highest profit within a certain risk factor. A hybrid fuzzy-neural system is applied to significantly save effort and time of portfolio managers. The model increases the individual investors’ local market understanding by providing buy and sells signals that reflect market sentiments, breaking news and technical analysis expectations. An implemented system of the proposed model has demonstrated a promising performance of the applied test datasets containing 100 Stock Symbols over the past 9 years (January 2009-July 2018). The prediction accuracy of the model is computed by comparing the applied system predicted results against the actual results of the Egyptian stock market during the test period.


Introduction
The high degree of risk and uncertainty is one of the characteristics of the stock markets worldwide. No one can be certain of the market movement direction in the short term or even on a long time period. The investors cannot avoid this high level of uncertainty; however the best that one can do is to reduce the degree of uncertainty by using a combination of different time series prediction-based techniques. Moreover, predicting certain price levels is more difficult than the case of predicting the market movement direction. [1] Investor's uses different investment instruments to aid them while making their investment decisions, Candlestick's patterns are one of the most popular techniques used by stock markets investors. The trading volume is very important to indicate the significance of the movement. Therefore the proposed module used Candlesticks techniques to analyze the past market data (price movements and the volume associated with these movements). [2] The proposed model assumes that using Candlesticks pattern detection techniques can predict the trend of the financial time series by detecting certain patterns in the charts. It is a well-known fact that predicting the future price of stocks or the market movement direction is a very difficult task. Lots of investors nowadays rely on using various types of advanced intelligent tools to assist them in the decision making process. This paper presents an intelligent hybrid model for stocks price movement prediction based on Artificial Neural Networks (ANNs) and Fuzzy Logic modules.
The applied system of the proposed model is composed of 3 main modules; A Charting module, Sentiments webbased module and Signal module. The Charting module provides the infrastructure needed for representing the stock price movements in various formats and applying different technical analysis techniques.
Also, the Charting module represented the technical indicators, line studies and price representation styles (candlesticks, point and figure, etc). The second part of the applied system is the Sentiments web based module. It is a webbased solution that gathers the market sentiments from market audience and identifies whether the current market direction is Bullish or Bearish based on a predefined sentiment thresholds. Finally, the Signal module which is a hybrid module consists of tradition pattern recognition techniques and a new intelligent module. The intelligent module used Kohonen's selforganizing neural network and a fuzzy-logic technique for candlesticks pattern recognition. The paper is organized as follows: an overview of the related work in stock market price prediction then explaining the main features of the proposed system, and a representation of the system test results. Snapshots of the system outputs represented the test results. Finally, a conclusion about the current state and the future work that can be implemented to improve the system performance and accuracy, was added at the end of the paper.

Related Work
Turkish and Egyptian markets movements are tightly coupled so it was very helpful to study the achievements that have been done in the Turkish stock market. A study [3] applied advanced seven different prediction models combined in one system to predict the direction of the stock market index in Turkey. The study used a data set consists of more than 2000 records represents the daily closing prices of each stock in Istanbul Stock Index (ISE-30). The findings of this research showed that ANN model outperformed the other six used prediction models. The study claimed that ANN model can be a useful technique for prediction of the stock market direction, because it is capable of capturing unrealized relationships among the represented data even when it is hard to explain or describe it. Another study [4] introduced a Hybrid Intelligent Systems for Stock Market Analysis. The model applied a hybridized soft computing techniques for automated stock market forecasting and trend analysis. The model used a neural network for one day ahead stock forecasting combined with a neuro-fuzzy model for analysing the trend direction. The data set represented 24 months stock data for Nasdaq-100 main index as well as six of the companies listed in the Nasdaq100 index. The forecasting accuracy could have been improved if the model used individual neural networks customized for each stock instead of using a single generic network. A study [5] presented a computational approach for predicting the Australian stock market index -AORD using multi-layer feed-forward neural networks from the time series data of AORD and various interrelated markets. A basic neural network with limited optimality was developed and achieved a correctness in directional prediction of 80%. The paper concludes that probability ensemble of neural networks is one of the most reliable directions for predicting stock markets direction. Overall, these researches concludes that neural networks are suitable for use within trading systems, and that trading systems developed using neural networks can be used to provide economically significant profits.

A Kohonen's self-organizing maps trading model
The suggested model used Kohonen self-organizing map as part of its trading system. The total number of data points is 2208 values. These values consist of the CIB stock prices on regular basis in that case. Daily updates provided by a local data feed company were recorded for the period from  Data set analysis showed that the majority of the changes of the daily stock closing price occur to vary in the spectrum from 1% to 4% .(without taking to account the sign of the change). Therefore the model suggested 7 classes or intervals: (-; -4.5%), (-4.5%; -2.5%), (-2.5%; -0.5%), (-0.5%; 0.5%), (0.5%; 2.5%), (2.5%; 4.5%), (4.5%; -). This number of classes found to be large enough to contain the trading strategy. The input vector was the set of last closing prices of the stock. In another data set, the window represented a set of the opening, closing, highest and lowest price of three or more trading days. The model examined both of these approaches and the better results were found to be that of the first one. The applied system consists of a number of sub models each of which has its own predictive power in a certain direction. Kohonen networks was used to split data into predefined classes. Each class with pre-determined intervals as shown in Figure.3. The window size is relative to the number of input units (there are 20 units). Number of clusters in the Kohonen layer is already determined (seven clusters). Each unit represents a cluster of neurons. Supervised learning approach was used for training as each cluster is trained individually. This is done by freezing all other neuron clusters while the inputs with the desired response identical to the given cluster are processed. Seven stages are needed to train this network accordingly to the number of classes we used for the CIB stock. After the learning is completed, all clusters are de-frozen (all neurons may be active), and the network works in a normal manner. The model used a simple back propagation network as well. It consists of 20 input neurons, 10 hidden neurons and 7 output neurons. The model used a set of last closing prices of the stock as input vector, to predict the market future direction. The best results were achieved with the look-ahead horizon of 4 weeks or 20 trading days.

Fuzzy logic Module
The system used candlesticks as a way to represent the daily stock prices, because it is the most widely used technique among stock market investors. It is also the most appropriate representation technique to detect the patters used in the prediction process. Figure. 4 shows an example of the daily candlestick chart for the stock market. Daily open, close, high, and low prices are recorded in the candlestick lines from day number1 till day number 10.

Fig.4. Candlestick Pattern Examples
The chart represents the CIB stock price movement in 12 consecutive days, represented in the form of daily candlesticks. The five tall black candles show that the stock witnessed a downtrend as its price closes at a lowest price and continues the downtrend from day1 till day 5. However on the day number 6, it opens at a price lower than the previous day closing price. The price closes on that day at the highest price and creates a long lower shadow as shown in the chart. This creates a clear pattern that should be recognized by the experienced or talented investors and technical analysts. It shows that lots of investors wanted to sell during the down trend. The volume of the selling operations during the down trend gives a very important indicator. An important indicator that should be taken in consideration is the volume, the greater the volume of the selling operations, the greater the pattern reliability. Another important indicator is the height of the black candles during the down trend. On day number 6 the down trend reversed because part of the investors finds these low prices attractive and undervalued. As a consequence of the previous events, the price closes at the highest price and leaves a long lower shadow. At this point of the down trend, price bounces and starts at day 7 an uptrend. At day 11, the closing price of the stock is still higher than the opening price, but the long upper shadow indicates that some investors will begin another movement to sell their stocks. At day12, the candlesticks shows that the opening price is much higher than the previous closing price. It closes at a price lowers than the close price on previous day. The day 11 and 12 can represent a reverse of movement direction, because the uptrend is broken at day 12. A candlestick pattern is composed by one or more candlestick lines and the trend before the pattern. By the trading experience, the investor tries to identify the candlestick patterns to help themselves to make the investment decisions such as to buy, sell, or hold the stock. There are many accessible defined candlestick patterns which are widely used by the investors. In Figure.4, the candlestick line on day 6 and the trend formed by day 1till day 5, are defined as a pattern which is called Hammer. It indicates that the downtrend is reversed. Another pattern called Bearish engulfing is also illustrated in Figure.4 and is composed by an uptrend and the candlestick lines on d11 and d12.  Training set was for the period from 1-3-2009 till 31-3-2016 (2/3 of the data set), and the remaining set was used for testing (1/3 of the data set).   Figure 6, 7, and 8. Egyptian Mobile Service "EMOB" in Figure 9, 10, and Orascom Telecom in figure 11.

Conclusion
The proposed model proves that using ANNs for stock market direction prediction can enhance the performance of online trading systems.
Using Fuzzy logic techniques in detecting candlesticks patterns in a multilayer soft computing model successfully predicted the change in the market direction.
Investors can use the applied model to improve their investing strategies and reduce the risk of online trading decision making process by predicting the change in the market direction.