Forecasting about EURJPY exchange rate using hidden Markova model and CART classification algorithm

The goal of this paper is forecasting direction (increase or decrease) of EURJPY exchange rate in a day. For this purpose five major indicators are used. The indicators are exponential moving average (EMA), stochastic oscillator (KD), moving average convergence divergence (MACD), relative strength index (RSI) and Williams %R (WMS %R). Then a hybrid approach using hidden Markov models and CART classification algorithms is developed. Proposed approach is used for forecasting direcation (increase or decrease) of Euro-Yen exchange rates in a day. Also the approach is used for forecasting differnece between intial and maximum exchange rates in a day. As well as it is used for forecasting differnece between intial and minimum exchange rates in a day. Reslut of proposed method is compared with CART and neural network. Comparison shows that the forecasting with proposed method has higher accuracy.


Introduction
Initially an overview of foreign exchange market (Forex) is presented. In Forex market, the traders exchange different currencies via Internet. There are three major orders for trading.  Buy order: Consider that analysis expresses that the EURJPY exchange rate will increase soon. In this condition, the trader request "Buy" order.  Sell order: Consider that analysis expresses that the EURJPY exchange rate will decrease soon. In this conditions, the trader request "Sell" order.  Close order: Each opened trade must be closed at a time. The suitable time for trade closing depends to trader analysis. For example closing can be occurred when the trader is acquiescent for trade profit. As well as, closing can be occurred when the trader is afraid of the trade loss. Moreover traders can assign two limits to their trades. These limits are called stop loss (SL) and take profit (TP). After trade opening if the loss of that trade reaches to a specific limit (SL), the broker automatically close that trade. Also if the profit of a trade reaches to a specific limit (TP), the broker automatically close that trade. These limits are used for decreasing trade risks. There are four major exchange rates in each time period. A time period is a time interval such as an hour, a day, a week and etc.  Exchange rate at the start of a period. This exchange rate is called Open.

Problem definition
In this paper a hybrid approach from hidden Markov model (HMM) and CART classification algorithm is used for forecasting about euro-yen (That is called EURJPY) exchange rate. Initially direction (increase or decrease) of EURJPY exchange rate in day is considered. Then the approach is used for forecasting differnece between High and Open exchange rate in day. Alos the approach is used for forecasting differnece between Open and Low exchange rate in day. At the end results of proposed approach are compared with results of CART classification algorithm and neural network.
There are many indicators for analysis and decision making in Forex market. Traders use indicators and exchange rate changes for analysis. In this paper, five major indicators on the basis of the [13] are used for forecasting. The indicators are exponential moving average (EMA), stochastic indicators (KD), moving average convergence divergence (MACD), relative strength index (RSI) and Williams %R (WMS %R). A short description about the indicators are mentioned as follows:  Exponential moving average (EMA): EMA is weighted average of exchange rate at previous days. EMA is a useful indicator that assigns grater weights to the latest data to respond faster to changes.  Stochastic oscillator (KD): Stochastic oscillator is based on as exchange rate is advanced, closing exchange rate tend to move to upper of its range. This indicator uses two moving averages and converts them to two %K and %D lines that swing permanently between 0 and 100. So this indicator also called KD. When value of KD is more than 80, it is a signal that exchange rate is placed on the upper bound. Also when value of KD is less than 20, it is a signal that exchange rate is placed on the lower bound.

Description about hidden Markova models (HMM)
A Markov chain is a sequence of stochastic variables.
Consider that j indicates j-th hidden state. P1j is the average value of observable state j when the first hidden state is occurred. As well as p 2j is the average value of observable state j when the second hidden state is occurred. Note that in this paper stages are stated as days. So at the beginning of each day the average value of previous days is specific. So p 1j is the average value of observable state j in (j-1) previous days when the first hidden state is occurred. Also p 2j is the average value of observable state j in (j-1) previous days when the second hidden state is occurred. q j is the average value of observable state j. Is calculated from equation (1). Then α is attained from equation (2). After achieving α, it is necessary to present a decision making criterion to forecast about hidden states. For this purpose CART, a major and strong classification algorithm, is used. Indeed CART tries to find the best relationship among values of α and hidden states. So the proposed model first attains α value on the basis of the observable states. Then on the basis of the value of α and using of CART algorithm, decides to present forecasting about hidden states. So this method is a combined approach from HMM model and CART algorithm. It is possible to consider observable and hidden states in financial markets such as Forex. At whole it can be said that all of history data are observable states. Also all of data that are belongs to future are hidden states. In this paper, values of five indicators (EMA, KD, MACD, RSI and WMS) at the beginning of each day are considered to define observable states. For each indicator two fields are defined. One Field includes normalized value of indicator. Max-min method is used for normalization. For example normalized value of moving average indicator in day (i) is calculated from equation 3.
In above relation, n is number of total of days that is considered. The other Field equals to change percentage of each normalized value of an indicator. For example, change percentage of moving average indicator in period i is calculated from equation (4). Values of those ten fields are observable states in whole of this paper. This procedure for defining observable states is similar to [13].

Forecasting about direction of exchange rate
Enough descriptions about observable states are presented in previous section. Now it is necessary to define hidden states. Hidden states relate to goal of forecasting. In this section direction of exchange rate changes in a day is considered as hidden state and is showed with D. If exchange rate at the end of a day (Close) is greater than exchange rate at the start of that day (Open), then the value of hidden state is equal to 1. Also if exchange rate at the end of a day (Close) is less than or equal to exchange rate at the start of that day (Open), then the value of hidden state is equal to 0.

Forecasting about the value of exchange rate change
In previous section the direction of exchange rate changes is considered to hidden state. In this section the measure of exchange rate changes is considered as hidden state. It is said in section 1 that there are four important exchange rates (Open, High, Low and close) in a day. Traders in each day attend to these four exchange rates. Differences among said rates such as (High-Open) (that is called HO) and (Open-Low) (than is called OL) are important for traders and investors. Indeed Each trader is interested to answer to these questions: At least how much exchange rate increase in a day? Or at least how much exchange rate decrease in a day? Answers of these questions are very important. For example consider that analysis is stated that in future day exchange rate increase 30 pips. So trader can open a buy trade at the beginning of a day and sets take profit (TP) of the trade equal to the point that exchange rate increase 30 pips. As well as consider that analysis is stated that in future day exchange rate decrease 20 pips. So trader can open a sell trade at the beginning of a day and sets take profit of the trade equal to the point that exchange rate decrease 20 pips.
For achieving to answer of the said questions two new variables are defined. The variables are HON and OLN. Values of those variables are attained as follows: If HO ≥ A then HON = 1 else HON = 0 If OL ≥ A then OLN = 1 else OLN = 0 A is a constant value that can be used for adjusting take profit (TP) values. Relation (5)

Computational results and discussion
In  Table 1 shows results of three approaches for forecasting direction of daily exchange rate (D variable).  Table 1 shows that accuracy of the proposed method is greater than or equal to accuracy of the other methods on testing data set. Table 2 shows results of three approaches for forecasting about the difference among High and Open (HON variable).
Calculations are performed for five values for A.  Table 2 shows that the accuracy of the proposed method for all value of A is greater than the other methods on testing data set. Table 3 shows results of three approaches for forecasting about the difference among Open and Low (OLN variable). Calculations are performed for five values for A.  Table 3 shows that the accuracy of the proposed method for all value of A except 20 and 50 is greater than the other methods on testing data set. Also table 3 shows that in average the accuracy of proposed model is greater than the others on testing data set.

Conclusion & future research
In this paper a proposed approach for forecasting in foreign exchange market is presented. Five major indicators (EMA, KD, MACD, RSI and WMS) are used for forecasting. The proposed approach uses hidden Markov model and CART classification algorithm. Three goals for forecasting are considered. First direction of exchange rate in a day (increase or decrease) is forecasted. Then forecasting about difference among High and Open exchange rates is performed. Also forecasting about difference among Open and Low exchange rates is considered. Data set is divided to two sections. First section includes EURJPY daily exchange rates in 2002 to 2007 years and used for training. Second section includes EURJPY daily exchange rates in the first six months of 2008 are used for testing. Results of the proposed model are compared with CART algorithm and neural network approach. Results show that accuracy of the proposed method is better than the accuracy of the other two methods. The novelties of this paper are:  Using efficiently of hidden Markov model to forecast in foreign exchange market  Present forecasting about difference among High and Open exchange rates and Open and Low exchange rates  Using a classification algorithm for forecasting  Considering five major indicators for forecasting At the end an offer for future research is presented. It is possible to present profitable trading strategy on the basis of the considered models that are used for forecasting. That can be a good topic for a future research. Also researches can use other forecasting methods on the outputs of proposed method to increase the accuracy of forecasting.