Implementing Trade Strategy with HMM Model : A Practice on Some Telecommunication Companies

Stock trend prediction has been a challenge task for many traders. For stock traders, promptly predicting the bearish or bullish market status is very helpful in reducing the losses and increasing returns. This paper presents a Hidden Markov Models (HMM) approach for determining stock trend status: “upper trend”, “low trend”, or “Medium”. And a simple trade strategy based on the estimated trend status is formulated. Then the strategy is applied to three telecommunication stocks: AT & T, Verizon, and China Mobile for trade performance evaluation. We use the real daily trading data of NYSE from October 25, 2016 to November 06, 2017 to test performance of the strategy. The results show that the strategy is actually very encouraging. For the generally bearish period of telecommunication sector, a 9.7% and 3.7% return rate can still be achieved for AT & T and Verizon. For China Mobile, although the return is negative, the final loss is still 2% less than if “Buy and Hold”.


Introduction
Predicting stock price has been a challenging task for many investors and researchers.Methods such as time Series Models (ARIMA), Neural Networks, Fuzzy Logic and Support Vector Machines have been used to predict the stock price, or determine the stock trend.In addition, there have been some applications using Hidden Markov Model (HMM) for this problem.Md.Rafiul Hassan and Baikunth Nath [1] predicted the next day price by using the "similar" his-C.Z.Sun DOI: 10.4236/jss.2018.6300213 Open Journal of Social Sciences torical difference of neighboring daily prices.The "similarity" was identified by comparing current model likelihood value with likelihood values of a previous dataset window under the currently estimated HMM model.Nguyen [2] used HMM with both single and multiple observations to forecast economic regimes and stock prices.In addition, Aditya Gupta [3] presented the Maximum a Posteriori HMM approach for forecasting stock values for the next day.The HMM model describes the temporal relationships of observed data with an unobserved Markov Chain.This feature is similar to fact that the observed stock prices are determined by unobserved market trend (or mood).So applying HMM for stock prediction is a pretty intuitive choice.
In this paper, instead of predicting the stock price, we try to determine the current market price level for a stock with Gaussian type HMM.Based on the estimated trend levels, our trade strategy is very simple: sell when stock is in high trend level and buy when it is in low trend.We apply this strategy to three tele- show that even for a general bearish period for telecommunication sector for tested period, we can still get a reasonable benefit by using the HMM model strategy.
This paper is organized as follows: Sections 2 gives general description of HMM model and related estimation and evaluation algorithms.Section 3 introduces the three stock price series used for model calibration and model performance test.In addition, to mimic the real stock trade scenario, method of one day shift for data block window for is also described.Section 4 presents the simulated results.Section 5 includes conclusions and discussions of possible modifications.

Definition of a Hidden Markov Model
Hidden Markov Model assumes that the distributions of the observation series are determined by an unobserved Markov Chain Process.Rabiner, L. R. [4] provided a good introduction to HMM model.A time discrete observation vector ( ) And km C is the mixture coefficient for the th m mixture in state k.In a sim- ple case, j can be one, and b O becomes Gaussian in each state, and the HMM model is called Gaussian HMM.In such a case, the conditional observation probability can de described by: ( ) is the transition probability matrix, and ( ) . AHMM model can be described by parameters: ( , , )

Three Basic Problems Can Be Resolved with HMM
A full HMM model can be described by parameters: ( , , ) Given the form of HMM model as discussed above, three basic problems can be resolved: 1) Given the observation vector ( ) 2) Given the observation vector ( )  and model parameters ( , , ) A B π , how to guess the "best" state sequence who generates the O? 3) How to estimate the model parameters λ to maximize P(O|λ)?

Three Algorithms to Solve the Problems
The algorithms that can be used to solve these problems are: the evaluation problem can be resolved as: Maximizing T L will solve the learning problem.With ( ) t i β the filtering and smoothing problem can be resolved by: ( ) ( ) Finally, the Decoding problem can be resolved with Viterbi Algorithm: 1) ( ) arg max

Model Calibration
To mimic the actual trade scenario, we use the last 260 trading prices from October 25, 2016 to November 06, 2017 for model performance test, assuming that we have $100 in hand on October 25, 2016.Start on October 25, 2016, for each trading date in the test period, we use the last 500 trading prices before that date to calibrate the HMM model and obtain the current stock trend level state with Viterbi method.We then make the decision of buying or selling based on the  Although the number of states for a HMM model can be determined with criteria such as AIC, BIC, etc., we use a three states HMM model here, assuming that the stock trend may have "Upper trend", "Lower trend", or "Medium" state.

HMM Based Trading Strategy
The HMM based trading strategy used here is pretty straightforward: on each test date, if the calibrated HMM indicates the stock is currently in "Upper trend", we will sell if we have the stock.If HMM tells that it is in "Lower trend", we will buy if we have cash in hand.Otherwise do nothing.Finally, the trading results are compared with "Buy and Hold" at the end of the test date.We did not consider the costs of trading fees here.

HMM Based Trading Results
Table 1 contains the final market values with HMM based trade strategy, assuming that there was $100 cash at the beginning of the test period.It shows that even for a generally bearish period for AT & T and Verizon, significant positive returns are obtained with HMM based strategy.For China Mobile, although the return is negative, the loss of HMM based trading is still 2% less than "Buy and Hold" by end of the testing period.

C. Z. Sun
Table 1.Market values at end of test period: November 06, 2017.

Conclusions
This paper demonstrates an approach to use a simple Gaussian Hidden Markov Model to determine the stock price "trend status" and make the stock trade deci- 1) In this paper we apply the HMM model directly on the stock close price.
Hence our HMM model in fact juts tell use which "level" status the stock price is at.It will be interesting to see how it will work if apply the HMM on returns, or difference.
2) We use the Viterbi algorithm to determine the "current status".It is actually the "status" of last traded date.It is possible to use the one step ahead forecast to determine the current status.
3) The Simple Gaussian HMM used here can describe relatively long term pattern of the observation level status.To capture the short variability and influence of other factors, a HMM with regression, or auto regression may be considered.
4) The Gaussian assumption for distribution of each state could be extended to Gaussian mixture distribution.
Finally, it should be pointed out that the stocks in our example have stock prices up and down periodically for period we considered.If a stock is in a pure long term growing, or downing period, the trading strategy described here may not be modified.
that there was $100.00 at beginning of the testing.

Figure 3 .
Figure 3. Comparing HMM based trade results with buy and hold: AT & T.

Figure 4 .
Figure 4. Comparing HMM based trade results with buy and hold: Verizon.

Figure 5 .
Figure 5. Comparing HMM based trade results with buy and hold: china mobile.

Figure 3 to
Figure 3 to Figure 5 compare HMM based trading results with "Buy and Hold" at each testing date for AT & T, Verizon, and China Mobile respectively.In the figures market_value_trade1 and market_value_bh represent HMM based and "Buy and Hold" results respectively.Figure3shows that with HMM model, we get out of market on December 12, 2016, hence avoid the losses for the coming down trend after that.Similarly, for Verizon, HMM successfully tell us to get out of the market from December 14, 2016 to April 25, 2017, and avoid the big downturn from January to March of 2017.For China Mobile, although the final return is negative, HMM model helps us not to enter the market until November 02, 2016.That reduces our final losses about 2%.
For the three telecommunication company AT & T, Verizon, and China Mobile, we obtain daily stock close price of NYSE from google finance service (finance.google.com).Totally 760 trading day prices from October 30, 2014 to November 06, 2017 are pulled for each company.Figure1displays the closing price of the three stocks from October to November 06, 2017.We can see that the stocks are generally in bearish status before August 2017.Figure2displays the prices for 760 days from October 30, 2014 to November 06, 2017.