An Analysis and Implementation of the Hidden Markov Model to Technology Stock Prediction

Similar documents
This specification describes the models that are used to forecast

VaR and Low Interest Rates

A Note on Missing Data Effects on the Hausman (1978) Simultaneity Test:

UCLA Department of Economics Fall PhD. Qualifying Exam in Macroeconomic Theory

Extreme Risk Value and Dependence Structure of the China Securities Index 300

You should turn in (at least) FOUR bluebooks, one (or more, if needed) bluebook(s) for each question.

VOLATILITY CLUSTERING, NEW HEAVY-TAILED DISTRIBUTION AND THE STOCK MARKET RETURNS IN SOUTH KOREA

Midterm Exam. Use the end of month price data for the S&P 500 index in the table below to answer the following questions.

R e. Y R, X R, u e, and. Use the attached excel spreadsheets to

Documentation: Philadelphia Fed's Real-Time Data Set for Macroeconomists First-, Second-, and Third-Release Values

Estimating Earnings Trend Using Unobserved Components Framework

STATIONERY REQUIREMENTS SPECIAL REQUIREMENTS 20 Page booklet List of statistical formulae New Cambridge Elementary Statistical Tables

PARAMETER ESTIMATION IN A BLACK SCHOLES

Advanced Forecasting Techniques and Models: Time-Series Forecasts

FORECASTING WITH A LINEX LOSS: A MONTE CARLO STUDY

Pricing FX Target Redemption Forward under. Regime Switching Model

On the Impact of Inflation and Exchange Rate on Conditional Stock Market Volatility: A Re-Assessment

An Incentive-Based, Multi-Period Decision Model for Hierarchical Systems

Comparison of back-testing results for various VaR estimation methods. Aleš Kresta, ICSP 2013, Bergamo 8 th July, 2013

IJRSS Volume 2, Issue 2 ISSN:

CENTRO DE ESTUDIOS MONETARIOS Y FINANCIEROS T. J. KEHOE MACROECONOMICS I WINTER 2011 PROBLEM SET #6

Macroeconomics II A dynamic approach to short run economic fluctuations. The DAD/DAS model.

INSTITUTE OF ACTUARIES OF INDIA

The Mathematics Of Stock Option Valuation - Part Four Deriving The Black-Scholes Model Via Partial Differential Equations

Market and Information Economics

Financial Econometrics Jeffrey R. Russell Midterm Winter 2011

Asymmetry and Leverage in Stochastic Volatility Models: An Exposition

a. If Y is 1,000, M is 100, and the growth rate of nominal money is 1 percent, what must i and P be?

Market risk VaR historical simulation model with autocorrelation effect: A note

Equivalent Martingale Measure in Asian Geometric Average Option Pricing

1 Purpose of the paper

Watch out for the impact of Scottish independence opinion polls on UK s borrowing costs

Output: The Demand for Goods and Services

The Impact of Interest Rate Liberalization Announcement in China on the Market Value of Hong Kong Listed Chinese Commercial Banks

Models of Default Risk

On the Relationship between Time-Varying Price dynamics of the Underlying. Stocks: Deregulation Effect on the Issuance of Third-Party Put Warrant

Problem Set 1 Answers. a. The computer is a final good produced and sold in Hence, 2006 GDP increases by $2,000.

INSTITUTE OF ACTUARIES OF INDIA

Macroeconomics. Part 3 Macroeconomics of Financial Markets. Lecture 8 Investment: basic concepts

Data Mining Anomaly Detection. Lecture Notes for Chapter 10. Introduction to Data Mining

Data Mining Anomaly Detection. Lecture Notes for Chapter 10. Introduction to Data Mining

A NOVEL MODEL UPDATING METHOD: UPDATING FUNCTION MODEL WITH GROSS DOMESTIC PRODUCT PER CAPITA

The Relationship between Money Demand and Interest Rates: An Empirical Investigation in Sri Lanka

A NOTE ON BUSINESS CYCLE NON-LINEARITY IN U.S. CONSUMPTION 247

Introduction. Enterprises and background. chapter

MA Advanced Macro, 2016 (Karl Whelan) 1

Predictive Analytics : QM901.1x Prof U Dinesh Kumar, IIMB. All Rights Reserved, Indian Institute of Management Bangalore

Stock Market Behaviour Around Profit Warning Announcements

Finance Solutions to Problem Set #6: Demand Estimation and Forecasting

Forecasting Financial Time Series

FINAL EXAM EC26102: MONEY, BANKING AND FINANCIAL MARKETS MAY 11, 2004

GUIDELINE Solactive Gold Front Month MD Rolling Futures Index ER. Version 1.1 dated April 13 th, 2017

Importance of the macroeconomic variables for variance. prediction: A GARCH-MIDAS approach

Description of the CBOE S&P 500 2% OTM BuyWrite Index (BXY SM )

May 2007 Exam MFE Solutions 1. Answer = (B)

Portfolio Risk of Chinese Stock Market Measured by VaR Method

Measuring and Forecasting the Daily Variance Based on High-Frequency Intraday and Electronic Data

Ch. 10 Measuring FX Exposure. Is Exchange Rate Risk Relevant? MNCs Take on FX Risk

A Regime Switching Independent Component Analysis Method for Temporal Data

Introduction to Black-Scholes Model

Financial Markets And Empirical Regularities An Introduction to Financial Econometrics

Prediction of Rain-fall flow Time Series using Auto-Regressive Models

Final Exam Answers Exchange Rate Economics

Inventory Investment. Investment Decision and Expected Profit. Lecture 5

Agenda. What is an ESG? GIRO Convention September 2008 Hilton Sorrento Palace

8/17/2015. Lisa M. Grantland Product Manager, Epicor

Have bull and bear markets changed over time? Empirical evidence from the US-stock market

TESTING FOR SKEWNESS IN AR CONDITIONAL VOLATILITY MODELS FOR FINANCIAL RETURN SERIES

Forecasting with Judgment

Computer Lab 6. Minitab Project Report. Time Series Plot of x. Year

UNIVERSITY OF MORATUWA

International transmission of shocks:

Available online at ScienceDirect

Systemic Risk Illustrated

DOES EVA REALLY HELP LONG TERM STOCK PERFORMANCE?

Robustness of Memory-Type Charts to Skew Processes

Non-Stationary Processes: Part IV. ARCH(m) (Autoregressive Conditional Heteroskedasticity) Models

GUIDELINE Solactive Bitcoin Front Month Rolling Futures 5D Index ER. Version 1.0 dated December 8 th, 2017

Modelling Volatility Using High, Low, Open and Closing Prices: Evidence from Four S&P Indices

San Francisco State University ECON 560 Summer 2018 Problem set 3 Due Monday, July 23

Key Formulas. From Larson/Farber Elementary Statistics: Picturing the World, Fifth Edition 2012 Prentice Hall. Standard Score: CHAPTER 3.

Linkages and Performance Comparison among Eastern Europe Stock Markets

Volatility Spillovers between U.S. Home Price Tiers. Tiers during the Housing Bubble

Predictive Ability of Three Different Estimates of Cay to Excess Stock Returns A Comparative Study for South Africa and USA

Web Usage Patterns Using Association Rules and Markov Chains

Multiple Choice Questions Solutions are provided directly when you do the online tests.

Online Appendix to: Implementing Supply Routing Optimization in a Make-To-Order Manufacturing Network

Determination Forecasting Sporadic Demand in Supply Chain Management

Financial markets behavior changes

Forecasting Value at Risk and Expected Shortfall Using a Semiparametric. Approach Based on the Asymmetric Laplace Distribution

Multi-Time-Scale Decision Making for Strategic Agent Interactions

Proposed solution to the exam in STK4060 & STK9060 Spring Eivind Damsleth

Hedging Performance of Indonesia Exchange Rate

ANSWER ALL QUESTIONS. CHAPTERS 6-9; (Blanchard)

A Vector Autoregression Framework for the Modeling of Commodity Spreads

ECONOMIC GROWTH. Student Assessment. Macroeconomics II. Class 1

Jarrow-Lando-Turnbull model

OPTIMALITY OF MOMENTUM AND REVERSAL

Data-Driven Demand Learning and Dynamic Pricing Strategies in Competitive Markets

The macroeconomic effects of fiscal policy in Greece

Transcription:

risks Aricle An Analysis and Implemenaion of he Hidden Markov Model o Technology Sock Predicion Nguye Nguyen Faculy of Mahemaics and Saisics, Youngsown Sae Universiy, 1 Universiy Plaza, Youngsown, OH 44555, USA; nnguyen01@ysu.edu; Tel.: +1-330-941-1805; Fax: +1-330-941-3170 Academic Edior: Alber Cohen Received: 20 April 2017; Acceped: 17 November 2017; Published: 24 November 2017 Absrac: Fuure sock prices depend on many inernal and exernal facors ha are no easy o evaluae. In his paper, we use he Hidden Markov Model, (HMM), o predic a daily sock price of hree acive rading socks: Apple, Google, and Facebook, based on heir hisorical daa. We firs use he Akaike informaion crierion (AIC) and Bayesian informaion crierion (BIC) o choose he numbers of saes from HMM. We hen use he models o predic close prices of hese hree socks using boh single observaion daa and muliple observaion daa. Finally, we use he predicions as signals for rading hese socks. The crieria ess resuls showed ha HMM wih wo saes worked he bes among wo, hree and four saes for he hree socks. Our resuls also demonsrae ha he HMM ouperformed he naïve mehod in forecasing sock prices. The resuls also showed ha acive raders using HMM go a higher reurn han using he naïve forecas for Facebook and Google socks. The sock price predicion mehod has a significan impac on sock rading and derivaive hedging. Keywords: hidden Markov model; sock prices; observaions; saes; predicions; AIC; BIC; likelihood; rading 1. Inroducion Sock invesmens can have a huge reurn or a significan loss due o he high volailiies of sock prices. An adapable sock price predicion model would reduce risk and enhance poenial reurn in financial derivaive rading. Recenly, researchers have applied he hidden Markov model for sock prices forecass. Hassan and Nah (2005) used HMM o predic he sock price for inerrelaed markes. Krizman, Page, and Turkingon (Krizman e al. 2012) applied HMM wih wo saes o predic regimes in marke urbulence, inflaion, and indusrial producion index. Guidolin and Timmermann (2006) used HMM wih four saes and muliple observaions o sudy asse allocaion decisions based on regime swiching in asse reurns. Nguyen (2014) used HMM wih boh single and muliple observaions o forecas economic regimes and sock prices. Nobakh, Joseph and Loni (Nobakh e al. 2012) implemened HMM using various observaion daa (open, close, low, high) prices of sock o predic is close prices. In our previous work Nguyen and Nguyen (2015), we used HMM for single observaion sequence for he S&P 500 o selec socks for rading based on performances of hese socks during he prediced regimes. In his sudy, we use HMM o predic sock prices and apply he resuls o rade socks. We use HMM for muliple independen observaion sequences in his sudy. Three socks: Apple Inc., Alphabe Inc., and Facebook, Inc., were chosen o implemen he model. We limi numbers of saes of he HMM o a maximum of four saes and use wo goodness of fi ess o choose he bes HMM model among HMMs wih wo, hree, or four saes. The predicion process is based on he work of Hassan and Nah (2005). The auhors use HMM wih he four observaions: close, open, high, and low prices of some airline socks o predic heir fuure close price using four saes. They used HMM o find a day in he pas ha was similar o Risks 2017, 5, 62; doi:10.3390/risks5040062 www.mdpi.com/journal/risks

Risks 2017, 5, 62 2 of 16 he recen day and used he price change in dae and price of he curren day o predic fuure close price. However, in he paper, he auhors did no explain why hey chose HMM wih four saes. Our approach is differen from heir work in he hree following modificaions. The firs difference is ha we use he Akaike informaion crierion (AIC) and Bayesian informaion crierion (BIC) o es he HMM s performances wih numbers of saes from wo o four o find he bes HMM model. The second modificaion is ha we apply HMM for sock reurns o predic fuure close prices and compare he resuls wih he naïve forecas mehod. The modificaion is based on he assumpion of he HMM s algorihms presened in his paper: he observaion sequences are independen. Applying he HMM o sock reurns, our predicion mehod is simpler han he mehod in Hassan and Nah (2005), which will be explained in Secion 3.1. Finally, we use sock prices prediced via he HMM and he naïve mehod o rade hese hree socks and compare he resuls. The paper is organized as follows: Secion 2 gives a brief inroducion o HMM and is algorihms for muliple observaion sequences. Secion 3 describes he HMM model selecions and daa collecions for sock price predicion. Secion 4 presens he resuls of sock price predicions and sock rading, and Secion 5 gives conclusions. 2. Hidden Markov Model and Is Algorihms The Hidden Markov Model, HMM, is a signal deecion model ha was inroduced in 1966 by Baum and Perie (Baum and Perie 1966). HMM assumes ha an observaion sequence was derived from a hidden sae sequence of discree daa and saisfies he firs order of a Markov process. HMM was developed from a model for a single observaion variable o a model for muliple observaion variables. The applicaions of HMM also were expanded o many areas such as speech recogniion, biomahemaics, and financial mahemaics. In our previous paper Nguyen and Nguyen (2015), we described HMM for one observaion, is algorihms, and applicaions. In his secion, we presen HMM for muliple observaions and is corresponding algorihms. We assume ha he muliple observaions daa are independen and have he same lengh. The basic elemens of an HMM for muliple observaions are: Observaion daa, O = {O (l), = 1, 2,..., T, l = 1, 2,..., L}, where l is numbers of independen observaion sequences and T is he lengh of each sequence, Hidden sae sequence of O, Q = {q, = 1, 2,..., T}, Possible values of each sae, {S i, i = 1, 2,..., N}, Possible symbols per sae, {v k, k = 1, 2,..., M}, Transiion marix, A = (a ij ), where a ij = P(q = S j q 1 = S i ), i, j = 1, 2,..., N, Iniial probabiliy of being in sae (regime) S i a ime = 1, p = (p i ), where p i = P(q 1 = S i ), i = 1, 2,..., N, Observaion probabiliy marix, B = {b i (k)}, where b i (k) b i (O = v k ) P(O = v k q = S i ), i = 1, 2,..., N, k = 1, 2,..., M. Parameers of an HMM are he marices A and B and he vecor p. For convenience, we use a compac noaion for he parameers, given by λ {A, B, p}. If he observaion probabiliy assumes he Gaussian disribuion, hen we have a coninuous HMM wih b i (k) = b i (O = v k ) = N (v k, µ i, σ i ), where µ i and σ i are he mean and variance of he disribuion corresponding o he sae S i, respecively, and N is Gaussian densiy funcion. For convenience, we wrie b i (O = v k ) as b i (O ). Then, he parameers of HMM are λ {A, µ, σ, p},

Risks 2017, 5, 62 3 of 16 where µ and σ are vecors of means and variances of he Gaussian disribuions, respecively. Wih he assumpion ha he observaions are independen, he probabiliy of observaion, denoed by P(O λ), is P(O λ) = L l=1 P(O (l) λ). There are hree main quesions ha readers should consider when using he HMM: 1. Given an observaion daa O and he model parameers λ, can we compue he probabiliies of he observaions P(O λ)? 2. Given he observaion daa O and he model parameers λ, can we find he bes hidden sae sequence of O? 3. Given he observaion O, can we find he model s parameers λ? The firs problem can be solved by using forward or backward algorihms Baum and Egon (1967); Baum and Sell (1968), he second problem was solved by using Vierbi algorihm Forney (1973); Vierbi (1967) and he Baum Welch algorihm Rabiner (1989) was developed o solve he las problem. In he paper, we only use he algorihms o solve he firs and he las problem. We firs use he Baum Welch algorihm o calibrae parameers for he model and he forward algorihm o calculae he probabiliy of observaion o predic rending signals for socks. In his secion, we inroduce he forward algorihm and he Baum Welch algorihm for HMM wih muliple observaions. These algorihms are wrien based on Baum and Egon (1967); Baum and Sell (1968); Forney (1973); Perushin (2000); Rabiner (1989). 2.1. Forward Algorihm We define he join probabiliy funcion as α (l) (i) = P(O (l) 1, O(l) 2,..., O(l), q = S i λ), = 1, 2,..., T and l = 1, 2,..., L. Then, we calculae α (l) (i) recursively. The probabiliy of observaion P(O (l) λ) is jus he sum of he α (l) T (i) s. The forward algorihm 1. Iniializaion P(O λ) = 1 2. For l = 1, 2,..., L do (a) Iniializaion: for i = 1, 2,..., N α (l) =1 (i) = p ib i (O (l) 1 ). (b) Recursion: for = 2, 3,..., T, and for j = 1, 2,..., N, compue [ N ] α (l) (j) = α 1 (i)a ij b j (O (l) ). i=1 (c) Calculae: (d) Updae: 3. Oupu: P(O λ). P(O (l) λ) = N α (l) T (i). i=1 P(O λ) = P(O λ) P(O (l) λ).

Risks 2017, 5, 62 4 of 16 2.2. Baum Welch Algorihm The Baum Welch algorihm is an algorihm o calibrae parameers for he HMM given he observaion daa. The algorihm was inroduced in 1970 Baum e al. (1970), in order o esimae he parameers of HMM for a single observaion. Then, in 1983, he algorihm was exended o calibrae HMM s parameers for muliple independen observaions, Levinson e al. (1983). In 2000, he algorihm was developed for muliple observaions wihou he assumpion of independence of he observaions, Li e al. (2000). In his paper, we use HMM for independen observaions, so we will inroduce he Baum Welch algorihm for his case. The Baum Welch mehod or he expecaion modificaion (EM) mehod is used o find a local maximizer, λ, of he probabiliy funcion P(O λ). In order o describe he procedure, we define he condiional probabiliy β (l) (i) = P(O (l) +1, O(l) +2,.., O(l) T q = S i, λ), for i = 1,..., N, l = 1, 2,..., L. Obviously, for i = 1, 2,..., N β (l) T (i) = 1, and we have he following backward recursive: β (l) N (i) = a ij b j (O (l) +1 )β(l) +1 (j), = T 1, T 2,..., 1. j=1 We hen defined γ (l) (i), he probabiliy of being in sae S i a ime of he observaion O (l), l = 1, 2,..., L as: γ (l) (i) = P(q = S i O (l), λ) = α(l) (i)β (l) (i) P(O (l) λ) = α(l) N i=1 α(l) (i)β (l) (i) (i)β (l) (i). The probabiliy of being in sae S i a ime and sae S j a ime + 1 of he observaion O (l), l = 1, 2,..., L as: Clearly, ξ (l) (i, j) = P(q = S i, q +1 = S j O (l), λ) = α(l) (i)a ij b j (O (l) +1 )β(l) P(O (l), λ) γ (l) (i) = N j=1 ξ (l) (i, j). +1 (j) Noe ha he parameer λ was updaed in Sep 2 of he Baum Welch algorihm o maximize he funcion P(O λ) so we will have = P(O, λ ) P(O, λ) > 0. If he observaion probabiliy b i (k), defined in Secion 2, is Gaussian, we will use he following formula o updae he model parameer, λ {A, µ, σ, p} µ i = L l=1 T 1 =1 γ(l) L l=1 T 1 =1 γ(l) (i)o (l) (i). σ i = L l=1 =1 T γ(l) (i)(o (l) µ i )(O (l) µ i ) l=1 L =1 T γ. (i) 3. Model Selecions and Daa Collecions The Hidden Markov Model has been widely used in financial mahemaics area o predic economic regimes (Krizman e al. 2012; Guidolin and Timmermann 2006; Ang and Bekaer 2002; Chen 2005; Nguyen 2014) or predic sock prices (Hassan and Nah 2005; Nobakh e al. 2012; Nguyen 2014). In his paper, we explore a new approach of HMM in predicing sock prices. In his secion, we discuss how o use he Akaike informaion crierion, AIC, and he Bayesian informaion crierion, BIC, o es he HMM s performances wih differen numbers of saes. We hen will presen

Risks 2017, 5, 62 5 of 16 how o use HMM o predic sock prices and apply he resuls o rade socks. Firs, we will describe he chosen daa and he AIC and BIC for HMM wih seleced numbers of saes. Baum Welch for L independen observaions O = (O (1), O (2),..., O (L) ) wih he same lengh T 1. Iniializaion: inpu parameers λ, he olerance ol, and a real number 2. Repea unil < ol Calculae P(O, λ) = Π L l=1 P(O(l) λ) using he forward algorihm (??) Calculae new parameers λ = {A, B, p }, for 1 i N p i = 1 L L γ (l) 1 (i) l=1 aij = L l=1 =1 T 1 ξ(l) (i, j) l=1 L T 1 (i), 1 j N b i (k) = Calculae = P(O, λ ) P(O, λ) Updae 3. Oupu: parameers λ. =1 γ(l) L l=1 T =1 O (l) =v (l) k γ (l) l=1 L =1 T γ(l) (i) λ = λ. (i), 1 k M 3.1. Overview of Daa Selecions We chose hree socks ha are acively rading in he sock marke o examine our model: Apple Inc. (AAPL), Alphabe Inc. (GOOGL), and Facebook Inc. (FB). The daily sock prices (open, low, high, close) of hese socks and informaion of hese companies can be found from finance.yahoo.com. We used daily hisorical prices of hese socks from 4 January 2010 o 30 Ocober 2015 in his paper. 3.2. Checking Model Assumpions The HMM s algorihms presened in his paper are based on he assumpion ha he observaion sequences are independen. However, he open, low, high, and close prices of a sock are highly correlaed, which can be since from he marix of correlaion in Figure 1. On he oher hand, sock reurns of hese four series prices are independen, which are shown in Figure 2. We use he Auocorrelaion funcion (ACF) o calculae he paired correlaion beween he series and plo in Figures 1 and 2. The ACF for he Facebook and Google socks are presened in Appendix A. We can see clearly from he figures ha he reurn price series have low correlaions while he sock price series have very high correlaions. Furhermore, we conduc he Ljung Box es o es he independence of each ime series. We use he es wih lag = 1 for reurns of he hree socks: AAPL, FB, and GOOGL, from 1 Ocober 2014 o 1 Ocober 2015, and presen resuls in Table 1. Noe ha he sock prices are no independen, and hey failed he Ljung Box es a significance level α = 5%, so Table 1 only displays resuls for sock reurns.

Risks 2017, 5, 62 6 of 16 Figure 1. ACF es for correlaion beween open, low, high, and close of Apple sock daily prices from 1 Ocober 2014 o 1 Ocober 2015. Figure 2. ACF es for correlaion beween open, low, high, and close of Apple sock daily reurn prices from 1 Ocober 2014 o 1 Ocober 2015.

Risks 2017, 5, 62 7 of 16 Table 1. p-values from he Ljung Box es for independencies of sock reurn series: Open, High, Low, and Close. * indicaes ha he p-value is saisically significan a α = 5%, ** indicaes ha he p-value is saisically significan a α = 1%, and *** indicaes ha he p-value is saisically significan a α = 0.1%. Sock Open High Low Close AAPL 0.0010 0.0718 0.6584 0.6566 FB 0.2151 0.0153 0.3273 0.0094 GOOGL 0.5378 0.0214 0.0010 0.0608 The null hypohesis of he Ljung Box es is ha he daa are independenly disribued. Thus, we will accep he null hypohesis if he p-value is bigger han he chosen significan level α. From Table 1, we can see ha mos of he sock reurns series pass he independen es a he significan level α = 1%, and he only wo series ha do no pass he es a he significan level α = 0.1% are APPL s open reurns and GOOGL s low reurns. The HMM works for dependen observaion daa wih a modificaion in calculaing probabiliies of observaions. We will explore he case in our fuure sudy. We will apply HMM for predicing he daily reurns and hen forecas fuure sock prices in he nex secion. 3.3. Model Selecion Choosing a number of hidden saes for he HMM is a criical ask. We firs use wo sandard crieria: he AIC and he BIC o examine he performances of HMM wih differen numbers of saes. The wo measures are suiable for HMM because, in he model raining algorihm, he Baum Welch algorihm, he EM mehod was used o maximize he log-likelihood of he model. We limi numbers of saes from wo o four o keep he model simple and feasible for sock predicion. The AIC and BIC are calculaed using he following formulas, respecively: AIC = 2 ln(l) + 2k, BIC = 2 ln(l) + k ln(m), where L is he likelihood funcion for he model, M is he number of observaion poins, and k is he number of esimaed parameers in he model. In his paper, we assume ha he disribuion corresponding o each hidden sae is a Gaussian disribuion. Therefore, he number of parameers, k, is formulaed as k = N 2 + 2N 1, where N is numbers of saes used in he HMM. To rain HMM s parameers, I use hisorical observed daa of a fixed lengh T, O = {O (1), O (2), O (3), O (4), = 1, 2,..., T}, where O (i) wih i = 1, 2, 3, or 4 represens he daily reurns of open, low, high or close price of a sock, respecively. For he HMM wih single observaion, we use only he reurns of close price daa, O = O, = 1, 2,..., T, where O is sock s reurn of close price a ime. We ran he model calibraions wih differen ime lenghs, T, and saw ha he model worked well for T 80. On he resuls below, we used blocks of T = 100 rading days of sock price daa, O, o calibrae HMM s parameers and calculae he AIC and BIC numbers. Thus, he oal number of observaion poins in each BIC calculaion is M = 400 for four observaion daa and M = 100 for one observaion daa. For convenience, we did 100 calibraions for 100 blocks of daa by moving he block of daa forward, (we ook off he price of he oldes day on he block and added he price of he following day o he recen day of he block). The calibraed

Risks 2017, 5, 62 8 of 16 parameers of he previous sep are used as iniial parameers for he new calibraion. The raining daa se is from 16 January 2015 o 30 Ocober 2015. The firs block of sock prices of 100 rading days from 16 January 2015 o 6 June 2015 was used o calibrae HMM s parameers and calculae corresponding AIC and BIC. Le µ (O) and σ (O) be he mean and sandard deviaion of observaion daa, O, respecably. We chose iniial parameers for he firs predicion as follows: A =(a ij ), a ij = 1 N, p =(1, 0,.., 0), µ i =µ (O) + Z, Z N (0, 1), σ i =σ (O), (1) where i, j = 1,.., N and N (0, 1) is he sandard normal disribuion. The second block of 100 rading day daa from 17 January 2015 o 7 June 2015 was used for he second calibraion and so on. The HMM calibraed parameers from he curren calibraion are used as iniial parameers for he nex esimaion. We coninued he process unil we go 100 calibraions. We plo he AICs and BICs of he 100 calibraions of hese hree socks (AAPL, FB, and GOOGL) on Figures 3 5. On Figures 3 5, he graph of AIC is locaed on he lef and BIC is locaed on he righ. The lower AIC or BIC is he beer model calibraion. However, he Baum Welch algorihm only finds a local maximizer of he likelihood funcion. Therefore, we did no expec o have he same AIC or BIC if we run he calibraion wice. The resuls on Figures 3 5 showed ha he calibraion performances of he model wih differen numbers of saes differ from one simulaion o ohers. Based on he AIC resuls, he performances of HMM wih wo, hree, or four saes are almos he same. However, based on he BIC, he HMM wih wo saes is he bes candidae for all hree of he socks. Therefore, we choose he HMM wih wo saes o predic prices of he hree socks in he nex secion. Figure 3. AIC (lef) and BIC (righ) for 100 parameer calibraions of HMM using Apple, AAPL, sock daily reurn prices.

Risks 2017, 5, 62 9 of 16 Figure 4. AIC (lef) and BIC (righ) for 100 parameer calibraions of HMM using Google, GOOGL, sock daily reurn prices. Figure 5. AIC (lef) and BIC (righ) for 100 parameer calibraions of HMM using Facebook, FB, sock daily reurn prices. 4. Sock Price Predicion and Sock Trading In his secion, we will use HMM o predic sock prices and compare he predicion wih he real marke prices. We will predic sock prices of GOOGL, APPL, and FB using HMM wih wo saes, he bes model seleced from Secion 3.3, and calculae he relaive errors o he real marke prices. The resuls will be compared wih he naïve none change mehod. A rading sraegy using HMM is also presened in his secion. 4.1. Sock Price Predicion We firs inroduce how o predic sock prices using HMM. The predicion process can be divided ino hree seps. Sep 1: calibrae HMM s parameers and calculae he likelihood of he model.

Risks 2017, 5, 62 10 of 16 Sep 2: find he day in he pas ha has a similar likelihood o he recen day. Sep 3: use he sock reurns on he day afer he similar day in he hisory o be he prediced reurn for omorrow price. This predicion approach is based on he work of Hassan and Nah (2005). However, our procedure is differen from heir mehod in ha we apply HMM for he reurns of open, low, high, and close prices, which are independen, while he auhors used he HMM direcly o open, low, high, and close prices, which are no independen. Due o applying he HMM for sock reurns, our mehod is simpler han heir mehod in he hird sep. We use HMM wih he reurns of he four observaion sequences (open, low, high, close price), as in Hassan and Nah (2005). Suppose ha we wan o predic omorrow s closing price of sock A, he predicion can be explained as follows. In he firs sep, we chose a block of T of he four daily reurn prices of sock A: open, low, high, and close, (O = {O (1), O (2), O (3), O (4), = T 99, T 98,..., T}), o calibrae HMM s parameers, λ, of he HMM. We hen calculae he probabiliy of observaion, P(O λ). We assumed ha he observaion probabiliy b i (k), defined in Secion 2, is Gaussian disribuion, so he marix B, in he parameer λ = {A, B, p}, is a 2 by N marix of means, µ, and variances, σ, of he N normal disribuions, where N is numbers of saes. In he second sep, we move he block of daa backward by one day o have new observaion daa O new = {O (1), O (2), O (3), O (4), = T 100, T 99,..., T 1} and calculae P(O new λ). We keep moving blocks of daa backward day by day unil we find a daa se O, (O = {O (1), = T 99, T 98,..., T }) such ha P(T λ) P(O λ). In he, O (2), O (3), O (4) hird sep, afer finding he pas similar day, T, we esimae he reurn of close price a ime T + 1, by using he following formula: O (4) T+1 = O(4) T +1. (2) Afer he firs predicion for sock reurn of day T + 1 we updae daa window, O, by moving i forward one day, O = {O (1), O (2), O (3), O (4), = T 98, T 97,..., T + 1}, o predic sock reurn for he day T + 2. The calibraed HMM s parameers in he firs predicion were used as he iniial parameers for he second predicion. We repea he predicion process as menioned in he firs predicion for he second predicion and so on. For HMM wih a single observaion sequence, we use O = O (4), where O (4) is he reurn of close price. The prediced close price a ime T + 1, P T+1, is calculaed by he prediced sock reurns: P T+1 = P T (O (4) T+1 + 1), (3) where P T is close price a ime T and O (4) T+1 is he reurn of close price calculaed in (2). The naïve none change mehod is applied for reurns of he hree socks close prices. The model simply akes he reurn of he close price oday o use as he reurn of he omorrow s close price O (4) T+1 = O(4) T. Afer forecasing O (4) T+1, we predic he nex day s close price by using Equaion (3). We use he naïve mehod for sock reurns insead of sock prices because, for rading purposes, if we assume no change in fuure sock prices, hen here is no rade. We presen resuls of using he HMM o predic hese hree socks AAPL, GOOGL, and FB closing prices for one year rading, 252 days, in Figures 6 8. The resuls indicae ha he HMM capures he rends of he hree socks well, while he naïve forecass ofen go o he opposie direcions of he real marke rends. We can see from Figure 7 ha he naïve forecas mehod had a few huge errors in predicing sock prices in February. The naïve model also showed is weakness when prediced prices of Google sock a he end of July 2015 are far from he acual prices.

Risks 2017, 5, 62 11 of 16 Figure 6. HMM predicion of Apple sock daily close prices from 15 Augus 2016 o 11 Augus 2017 using wo-saes HMM and he naïve model. Figure 7. HMM predicion of Facebook sock daily close prices from 15 Augus 2016 o 11 Augus 2017 using wo-saes HMM and he naïve model. Figure 8. HMM predicion of Google sock daily close prices from 15 Augus 2016 o 11 Augus 2017 using wo-saes HMM and he naïve model.

Risks 2017, 5, 62 12 of 16 We also compare he forecasing resuls of using he wo-sae HMM and he naïve mehod numerically by calculaing he mean absolue percenage error, MAPE, of he esimaions. MAPE = 1 N N M i P i, M i=1 i where N is number of prediced poins, M is marke price, and P is prediced price of a sock. The resuls were shown in Table 2. In Table 2, he Price Sd. and Reurn Sd. are he sandard deviaion of he sock prices and sock reurns, respecively, and he efficiencies are calculaed by aking he errors of he naïve mehod divided by he errors of he HMM. All efficiencies in he able are bigger han one, showing ha he HMM ouperformed he naïve in forecasing sock prices. Table 2. Comparison of MAPE of sock price predicions of Apple, Google, and Facebook from 15 Augus 2016 o 11 Augus 2017, beween he HMM and he naïve forecas model. Sock Price Sd. Reurn Sd. HMM s MAPE Naïve s MAPE Efficiency AAPL 17.0934 0.0113 0.0113 0.0133 1.1770 FB 14.4879 0.0111 0.0116 0.0213 1.8362 GOOGL 69.9839 0.0098 0.0107 0.0137 1.2804 Among hese hree socks, GOOGL s prices have he highes volailiy, bu is reurns have he lowes volailiy. These facors will affec sock rading resuls so ha we will presen he resuls in he nex secion. 4.2. Sock Trading In his secion, we will use he prediced reurns o rade hese hree socks: AAPL, FB, and GOOGL. The rading sraegy is: if HMM predics ha he sock price of AAPL will move up omorrow, or is reurn is posiive, we will buy his sock oday and sell i omorrow, assuming ha we buy and sell wih close prices. If he HMM predics ha he sock price will no increase omorrow, hen we will do nohing. We also assume ha here is no rading cos. For each rade, we will buy or sell 100 shares of each of hese hree socks. Based on he AIC and BIC resuls, we only use HMM wih wo saes for he sock rading. Again, we will use a block of 252 rading days, one year, from 15 Augus 2016 o 11 Augus 2017 for model esing. We presen he resuls of one year rading in he Table 3. Table 3. Sock rading resuls from 15 Augus 2016 o 11 Augus 2017. Sock Models Invesmen $ Earning $ Profi % AAPL FB GOOGL HMM 10,908 3481 31.91 Naïve 10,818 3513 32.47 HMM 12,490 2939 23.53 Naïve 12,488 2565 20.54 HMM 80,596 20,039 24.86 Naïve 79,965 2715 3.40 In Table 3, he Invesmen is he price ha we bough 100 shares of he socks he firs ime. The Earning is he money gained, and he Profi is he percenage of reurn of he one-year rading. The resuls show ha he HMM worked beer han he naïve in rading he Facebook and Google socks. Especially in he one year rading period, he GOOGL sock yielded a much higher reurn compared o he naïve forecas mehod. However, he resuls are reversed for AAPL sock. From Figures 6 8 and Table 2, we can see ha, in he one period, he GOOGL prices have he highes volailiy and lowes risk of reurns among he hree socks. The naïve resuls are consisen wih he

Risks 2017, 5, 62 13 of 16 risk of reurn levels, he Reurn Sd. in Table 2: he higher he risk, he beer he reurn. The HMM followed close o he risk level heoreical. Based on he resuls in Table 3, using an HMM model, raders had reurns of 32.00%, 24%, and 25% for AAPL, FB, GOOGL, respecively. Trading using HMM gave much higher reurns han using he naïve for wo socks FB and GOOGL, bu a likely lower reurn for he AAPL sock compare o he naïve. 5. Conclusions Sock s performances are an essenial indicaor of he srengh or weakness of he sock s corporaion and economic viabiliy in general. Many facors will drive sock prices up or down. In his paper, we use a Hidden Markov Model, HMM, o predic prices of hree socks: AAPL, GOOGL, and FB. We firs use he AIC and BIC crierions o examine he performances of HMM numbers of saes from wo o four. The resuls showed ha he HMM wih wo saes is he bes model among he wo, hree and four saes. We hen use he models o predic sock prices and compare he predicions wih he naïve forecas resuls by ploing he forecased prices versus he marke prices and evaluaing he mean absolue percenage error, MAPE. The predicion errors show ha HMM worked beer in predicing prices of he hree socks AAPL, FB, and GOOGL compared wih he naïve mehod. In sock rading, he HMM ouperformed he naïve for wo socks: FB and GOOGL. The graphs indicae ha he HMM is he poenial model for sock rading since i capures he rends of sock prices well. Acknowledgmens: I hank hree anonymous referees a Risks, he edior Alber Cohen, and he assisan edior Shelly Liu for heir commens and assisances. Conflics of Ineres: The auhor declares no conflic of ineres. Appendix A Figure A1. ACF es for correlaion beween open, low, high, and close of Facebook daily sock prices from 1 Ocober 2014 o 1 Ocober 2015.

Risks 2017, 5, 62 14 of 16 Figure A2. ACF es for correlaion beween open, low, high, and close of Facebook sock daily reurns from 1 Ocober 2014 o 1 Ocober 2015. Figure A3. ACF es for correlaion beween open, low, high, and close of Google daily sock prices from 1 Ocober 2014 o 1 Ocober 2015.

Risks 2017, 5, 62 15 of 16 Figure A4. ACF es for correlaion beween open, low, high, and close of Google sock daily reurns from 1 Ocober 2014 o 1 Ocober 2015. References Ang, Andrew, and Geer Bekaer. 2002. Inernaional Asse Allocaion wih Regime Shifs. The Review of Financial Sudies 15: 1137 87. Baum, Leonard E., and John Alonzo Eagon. 1967. An inequaliy wih applicaions o saisical esiaion for probabilisic funcions of Markov process and o a model for ecnogy. Bullein of he American Mahemaical Sociey 73: 360 63. Baum, Leonard E., and Ted Perie. 1966. Saisical Inference for Probabilisic Funcions of Finie Sae Markov Chains. The Annals of Mahemaical Saisics 37: 1554 63. Baum, Leonard E., and George Roger Sell. 1968. Growh funcions for ransformaions on manifolds. Pacific Journal of Mahemaics 27: 211 27. doi: 10.2140/pjm.1968.27.211 Baum, Leonard E., Ted Perie, George Soules, and Norman Weiss. 1970. A maximizaion echnique occurring in he saisical analysis of probabilisic funcions of Markov chains. The Annals of Mahemaical Saisics 41: 164 71. Chen, Chunchih. 2005. How Well Can We Predic Currency Crises? Evidence from a Three-Regime Markov-Swiching Model. Davis: Deparmen of Economics, UC Davis. Forney, G. David. 1973. The Vierbi algorihm. Proceedings of he IEEE 61: 268 78. Guidolin, Massimo, and Allan Timmermann. 2006. Asse Allocaion under Mulivariae Regime Swiching. SSRN FRB of S. Louis Working Paper No. 2005-002C, FRB of S. Louis, MO, USA. Hassan, Md Rafiul, and Baikunh Nah. 2005. Sock Marke Forecasing Using Hidden Markov Models: A New approach. Paper presened a he IEEE fifh Inernaional Conference on Inelligen Sysems Design and Applicaions, Warsaw, Poland, Sepember 8 10. Krizman, Mark, Sebasien Page, and David Turkingon. 2012. Regime Shifs: Implicaions for Dynamic Sraegies. Financial Analyss Journal 68: 22 39. Levinson, Sephen E., Lawrence R. Rabiner, and Man Mohan Sondhi. 1983. An inroducion o he applicaion of he heory of probabilisic funcions of Markov process o auomaic speech recogniion. Bell Sysem Technical Journal 62: 1035 74. Li, Xiaolin, Marc Parizeau, and Réjean Plamondon. 2000. Training Hidden Markov Models wih Muliple Observaions A Combinaorial Mehod. IEEE Transacions on PAMI 22: 371 77.

Risks 2017, 5, 62 16 of 16 Nguyen, Nguye, and Dung Nguyen. 2015. Hidden Markov Model for Sock Selecion. Journal of Risks in special issue: Recen Advances in Mahemaical Modeling of he Financial Markes. Risks 3: 455 73. doi:10.3390/risks3040455. Nguyen, Nguye Thi. 2014. Probabilisic Mehods in Esimaion and Predicion of Financial Models. Elecronic Theses, Treaises and Disseraions Ph.D. disseraion, The Florida Sae Universiy, Tallahassee, FL, USA. Nobakh, B., C. E. Joseph, and B. Loni. 2012. Sock marke analysis and predicion using hidden markov models. Paper presened a he 2012 Sudens Conference on IEEE Engineering and Sysems (SCES), Allahabad, Uar Pradesh, India, March 16 18, pp. 1 4. Perushin, Valery A. 2000. Hidden Markov Models: Fundamenals and Applicaions (par 2-discree and coninuous hidden markov models). Online Symposium for Elecronics Engineer. Available online: hp://cieseerx.is.psu.edu/viewdoc/download?doi=10.1.1.378.3099&rep=rep1&ype=pdf (accessed on 23 November 2017). Rabiner, Lawrence R. 1989. A Tuorial on Hidden Markov Models and Seleced Applicaions in Speech Recogniion. Proceedings of he IEEE 77: 257 86. Vierbi, Andrew J. 1967. Error bounds for convoluional codes and an asympoically opimal decoding algorihm. IEEE Transacions on Informaion Theory IT-13: 260 69. c 2017 by he auhor. Licensee MDPI, Basel, Swizerland. This aricle is an open access aricle disribued under he erms and condiions of he Creaive Commons Aribuion (CC BY) license (hp://creaivecommons.org/licenses/by/4.0/).