<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE article  PUBLIC "-//NLM//DTD Journal Publishing DTD v3.0 20080202//EN" "http://dtd.nlm.nih.gov/publishing/3.0/journalpublishing3.dtd"><article xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:xlink="http://www.w3.org/1999/xlink" dtd-version="3.0" xml:lang="en" article-type="research article"><front><journal-meta><journal-id journal-id-type="publisher-id">JSS</journal-id><journal-title-group><journal-title>Open Journal of Social Sciences</journal-title></journal-title-group><issn pub-type="epub">2327-5952</issn><publisher><publisher-name>Scientific Research Publishing</publisher-name></publisher></journal-meta><article-meta><article-id pub-id-type="doi">10.4236/jss.2018.63002</article-id><article-id pub-id-type="publisher-id">JSS-82940</article-id><article-categories><subj-group subj-group-type="heading"><subject>Articles</subject></subj-group><subj-group subj-group-type="Discipline-v2"><subject>Business&amp;Economics</subject><subject> Social Sciences&amp;Humanities</subject></subj-group></article-categories><title-group><article-title>
 
 
  Implementing Trade Strategy with HMM Model: A Practice on Some Telecommunication Companies
 
</article-title></title-group><contrib-group><contrib contrib-type="author" xlink:type="simple"><name name-style="western"><surname>Chuanzhong</surname><given-names>Sun</given-names></name><xref ref-type="aff" rid="aff1"><sub>1</sub></xref></contrib></contrib-group><aff id="aff1"><label>1</label><addr-line>SAS Institute Inc, Cary, USA</addr-line></aff><author-notes><corresp id="cor1">* E-mail:</corresp></author-notes><pub-date pub-type="epub"><day>13</day><month>03</month><year>2018</year></pub-date><volume>06</volume><issue>03</issue><fpage>12</fpage><lpage>19</lpage><history><date date-type="received"><day>19,</day>	<month>December</month>	<year>2017</year></date><date date-type="rev-recd"><day>10,</day>	<month>March</month>	<year>2018</year>	</date><date date-type="accepted"><day>13,</day>	<month>March</month>	<year>2018</year></date></history><permissions><copyright-statement>&#169; Copyright  2014 by authors and Scientific Research Publishing Inc. </copyright-statement><copyright-year>2014</copyright-year><license><license-p>This work is licensed under the Creative Commons Attribution International License (CC BY). http://creativecommons.org/licenses/by/4.0/</license-p></license></permissions><abstract><p>
 
 
  
    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 &amp; 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 &amp; T and Verizon. For China Mobile, although the return is negative, the final loss is still 2% less than if “Buy and Hold”. 
  
 
</p></abstract><kwd-group><kwd>Hidden Markov Model</kwd><kwd> Stock Trend Status</kwd><kwd> Trade Strategy</kwd></kwd-group></article-meta></front><body><sec id="s1"><title>1. Introduction</title><p>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 [<xref ref-type="bibr" rid="scirp.82940-ref1">1</xref>] predicted the next day price by using the “similar” historical 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 [<xref ref-type="bibr" rid="scirp.82940-ref2">2</xref>] used HMM with both single and multiple observations to forecast economic regimes and stock prices. In addition, Aditya Gupta [<xref ref-type="bibr" rid="scirp.82940-ref3">3</xref>] 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.</p><p>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 telecommunication stocks: AT &amp; T, Verizon, and China for 260 trading days from October 25, 2016 to November 06, 2017. With $100 in hand on October 25, 2016, we compare the trade results with a simple “buy and hold” practice. The results 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.</p><p>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.</p></sec><sec id="s2"><title>2. The Hidden Markov Model</title><sec id="s2_1"><title>2.1. Definition of a Hidden Markov Model</title><p>Hidden Markov Model assumes that the distributions of the observation series are determined by an unobserved Markov Chain Process. Rabiner, L. R. [<xref ref-type="bibr" rid="scirp.82940-ref4">4</xref>] provided a good introduction to HMM model. A time discrete observation vector O = ( O 1 , O 2 , ⋯ , O s T ) is said to satisfy a Hidden Markov Model, if</p><p>a) s 0 , s 1 , ⋯ , s T is a Markov Chain Process ;</p><p>b) Given the state of s t , the observation O t is independent of other observations and states;</p><p>c) For a fixed state, the observation O t is generated according to a fixed probability law.</p><p>Given a state k, the probability of O t can be specified as:</p><p>b k ( O t ) = probability mass function, if O t is discrete</p><p>b k ( O t ) = ∑ m = 1 J C k m b k m ( O t ) , if O t is continuous</p><p>where each b k m ( O t ) is density defined by</p><p>b k m ( O t ) = 1 2 π d | ∑ ​ k m | exp ( − 1 2 ( O t − u k m ) ′ ∑ ​ k m − 1 ( O t − u k m ) )</p><p>And C k m is the mixture coefficient for the m t h mixture in state k. In a simple case, j can be one, and b k ( O t ) 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: B = b k ( O t ) , k = 1 , ⋯ , M .</p><p>Let A = ( a i , j ) is the transition probability matrix, and π = ( π i ) is the initial state probability, i = 1 , ⋯ , M , j = 1 , ⋯ , M . AHMM model can be described by parameters: ( A , B , π ) = λ .</p></sec><sec id="s2_2"><title>2.2. Three Basic Problems Can Be Resolved with HMM</title><p>A full HMM model can be described by parameters: ( A , B , π ) = λ . Given the form of HMM model as discussed above, three basic problems can be resolved:</p><p>1) Given the observation vector O = ( O 1 , O 2 , ⋯ , O T ) and model parameters ( A , B , π ) , what is P(O|λ)?</p><p>2) Given the observation vector O = ( O 1 , O 2 , ⋯ , O T ) and model parameters ( A , B , π ) , how to guess the “best” state sequence who generates the O?</p><p>3) How to estimate the model parameters λ to maximize P(O|λ)?</p></sec><sec id="s2_3"><title>2.3. Three Algorithms to Solve the Problems</title><p>The algorithms that can be used to solve these problems are:</p><p>1) Forward Algorithm</p><p>α t ( i ) = P ( O 1 , … , O t , s t = i | λ )</p><p>2) Backward Algorithm</p><p>β t ( i ) = P ( O t + 1 , … , O T | s t = i , λ )</p><p>3) Viterbi Algorithm</p><p>δ t ( i ) = max s 1 , s 2 , … , s t − 1 P ( s 1 s 2 … , s t − 1 , s t = i , O 1 , … , O t , | λ )</p><p>With α t ( i ) the evaluation problem can be resolved as: P ( O 1 , … , O t | λ ) = L t = ∑ i = 1 M α t (i)</p><p>Maximizing L T will solve the learning problem. With β t ( i ) the filtering and smoothing problem can be resolved by:</p><p>f t ( i ) = P ( s t = i | O 1 , … , O t , λ ) = P ( O 1 , … , O t , s t = i | λ ) / P ( O 1 , … , O t | λ ) = α t ( i ) / L t</p><p>s t ( i ) = P ( s t = i | O 1 , … , O t , λ ) = α t ( i ) β t ( i ) / ∑ j M α t ( j ) β t (j)</p><p>Finally, the Decoding problem can be resolved with Viterbi Algorithm:</p><p>1) δ 1 ( i ) = π i b i ( O 1 ) ,   1 ≤ i ≤ M ,</p><p>ψ 1 ( i ) = 0</p><p>2) δ t ( i ) = max 1 ≤ i ≤ M [ δ t − 1 ( i ) a i j ] b j ( O t ) ,   1 ≤ i ≤ M ,   2 ≤ t ≤ T</p><p>ψ t ( j ) = arg max 1 ≤ i ≤ M [ δ t − 1 ( i ) a i j ] ,   1 ≤ i ≤ M ,   2 ≤ t ≤ T</p><p>3) P * = max 1 ≤ i ≤ M [ δ T ( i ) ]</p><p>s T * = arg max 1 ≤ i ≤ M [ δ T ( i ) ]</p><p>4) s t * = ψ t + 1 ( s t + 1 * ) ,   t = T − 1 ,   T − 2 , … , 1</p></sec></sec><sec id="s3"><title>3. Data, Model Calibration, and Trade Strategy</title><sec id="s3_1"><title>3.1. Data</title><p>For the three telecommunication company AT &amp; 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. <xref ref-type="fig" rid="fig1">Figure 1</xref> displays the closing price of the three stocks from October 25, 2016 to November 06, 2017. We can see that the stocks are generally in bearish status before August 2017. <xref ref-type="fig" rid="fig2">Figure 2</xref> displays the prices for 760 days from October 30, 2014 to November 06, 2017.</p></sec><sec id="s3_2"><title>3.2. Model Calibration</title><p>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</p><p>estimated trend level status. After that we move to make the decision for the next trading date, and repeat the process by moving the training dataset one day forward, until we reach November 06, 2017. PROC HMM in SAS Econometrics 8.2 [<xref ref-type="bibr" rid="scirp.82940-ref5">5</xref>] is used for model estimation.</p><p>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.</p></sec><sec id="s3_3"><title>3.3. HMM Based Trading Strategy</title><p>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.</p></sec></sec><sec id="s4"><title>4. HMM Based Trading Results</title><p><xref ref-type="table" rid="table1">Table 1</xref> 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 &amp; 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.</p><table-wrap id="table1" ><label><xref ref-type="table" rid="table1">Table 1</xref></label><caption><title> Market values at end of test period: November 06, 2017</title></caption><table><tbody><thead><tr><th align="center" valign="middle"  rowspan="2"  >Final Market Value</th><th align="center" valign="middle"  colspan="3"  >Company</th></tr></thead><tr><td align="center" valign="middle" >AT &amp; T</td><td align="center" valign="middle" >Verizon</td><td align="center" valign="middle" >China Mobile</td></tr><tr><td align="center" valign="middle" >With HMM Buy and Hold</td><td align="center" valign="middle" >$109.67 $89.54</td><td align="center" valign="middle" >$103.70 $95.17</td><td align="center" valign="middle" >$88.86 $86.89</td></tr></tbody></table></table-wrap><p>a) Assume that there was $100.00 at beginning of the testing.</p><p><xref ref-type="fig" rid="fig3">Figure 3</xref> to <xref ref-type="fig" rid="fig5">Figure 5</xref> compare HMM based trading results with “Buy and Hold” at each testing date for AT &amp; 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. <xref ref-type="fig" rid="fig3">Figure 3</xref> shows that with HMM model, we get out of market on December 12, 2016, hence avoid the losses for the coming down trend after that.</p><p>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%.</p></sec><sec id="s5"><title>5. Conclusions</title><p>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 decision based on that. The trading results are evaluated for 260 trading dates from October 25, 2016 to November 06, 2017. Trading results show that for the generally bearish period, a 9.7% return is achieved for AT &amp; T with HMM based strategy, comparing with more than 10% loss with “Buy and Hold” trade. Similarly, for Verizon, a 3.7% return is achieved with HMM model, while a “Buy and Hold” results in about 5% loss. For China Mobile, HMM model delays our entering into the market until November 02, 2016, hence reduces our final losses by 2%, comparing with “Buy and Hold”.</p><p>It seems that in our cases, HMM model can indicate a downturn promptly and hence help us to avoid possible losses. For people who are interested in this application, possible modifications or improvements include:</p><p>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.</p><p>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.</p><p>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.</p><p>4) The Gaussian assumption for distribution of each state could be extended to Gaussian mixture distribution.</p><p>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.</p></sec><sec id="s6"><title>Cite this paper</title><p>Sun, C.Z. (2018) Implementing Trade Strategy with HMM Model: A Practice on Some Telecommunication Companies. Open Journal of Social Sciences, 6, 12-19. https://doi.org/10.4236/jss.2018.63002</p></sec></body><back><ref-list><title>References</title><ref id="scirp.82940-ref1"><label>1</label><mixed-citation publication-type="other" xlink:type="simple">Hassan, Md.R. and Nath, B. (2005) Stock Market Forecasting Using Hidden Markov Models: A New Approach. Proceeding of IEEE 5th International Conference on Intelligent Systems Design and Applications.</mixed-citation></ref><ref id="scirp.82940-ref2"><label>2</label><mixed-citation publication-type="other" xlink:type="simple">Nguyen, N. and Nguyen, D. (2015) Hidden Markov Model for Stock Selection, Journal of Risks in Special Issue: Recent Advances in Mathematical Modeling of the Financial Markets, Risks, 3, 455-473. https://doi.org/10.3390/risks3040455</mixed-citation></ref><ref id="scirp.82940-ref3"><label>3</label><mixed-citation publication-type="other" xlink:type="simple">Gupta, A. and Dhingra, B. (2012) Stock Market Prediction Using Hidden Markov Models. Students Conference on Engineering and Systems (SCES), Allahabad, 16-18 March 2012. https://doi.org/10.1109/SCES.2012.6199099</mixed-citation></ref><ref id="scirp.82940-ref4"><label>4</label><mixed-citation publication-type="other" xlink:type="simple">Rabiner, L.R. (1989) A Tutorial on Hidden Markov Models and Selected Applications in Speech Recognition. Proceedings of the IEEE, 77, 257-286.  
https://doi.org/10.1109/5.18626</mixed-citation></ref><ref id="scirp.82940-ref5"><label>5</label><mixed-citation publication-type="other" xlink:type="simple">SAS Online Documentation for HMM Procedure/SAS Econometrics.  
http://support.sas.com/documentation/onlinedoc/econometrics/index.html</mixed-citation></ref></ref-list></back></article>