28
Introduction of HMMs HMM and its three problems Financial Applications of HMMs Can we use HMMs to make money? Hidden Markov Model for High Frequency Data Nguyet Nguyen Department of Mathematics, Florida State University Joint Math Meeting, Baltimore, MD, January 15 Nguyet Nguyen Hidden Markov Model for High Frequency Data

Hidden Markov Model for High Frequency Data - UCLAwiki.stat.ucla.edu/socr/uploads/b/bd/NguyetNguyen_JMM_2014.pdf · Introduction of HMMs HMM and its three problems Financial Applications

  • Upload
    leanh

  • View
    216

  • Download
    1

Embed Size (px)

Citation preview

Page 1: Hidden Markov Model for High Frequency Data - UCLAwiki.stat.ucla.edu/socr/uploads/b/bd/NguyetNguyen_JMM_2014.pdf · Introduction of HMMs HMM and its three problems Financial Applications

Introduction of HMMs HMM and its three problems Financial Applications of HMMs Can we use HMMs to make money?

Hidden Markov Model for High FrequencyData

Nguyet Nguyen

Department of Mathematics, Florida State University

Joint Math Meeting, Baltimore, MD, January 15

Nguyet Nguyen Hidden Markov Model for High Frequency Data

Page 2: Hidden Markov Model for High Frequency Data - UCLAwiki.stat.ucla.edu/socr/uploads/b/bd/NguyetNguyen_JMM_2014.pdf · Introduction of HMMs HMM and its three problems Financial Applications

Introduction of HMMs HMM and its three problems Financial Applications of HMMs Can we use HMMs to make money?

What are HMMs?

A Hidden Markov model (HMM) is a stochastic signal modelwhich has three assumptions:

The observation at time t, Ot , was generated by some processwhose state, St , is hidden.

The hidden process satisfies the first-order Markov property:given St−1, St is independent of Si for any i < t − 1.

The hidden state variable is discrete.

Nguyet Nguyen Hidden Markov Model for High Frequency Data

Page 3: Hidden Markov Model for High Frequency Data - UCLAwiki.stat.ucla.edu/socr/uploads/b/bd/NguyetNguyen_JMM_2014.pdf · Introduction of HMMs HMM and its three problems Financial Applications

Introduction of HMMs HMM and its three problems Financial Applications of HMMs Can we use HMMs to make money?

History of HMMs

Introduced in 1966 by Baum and Petrie

Baum and his colleagues published HMM training for a singleobservation, 1970

Levonson, Rabiner, and Sondhi presented HMM training formultiple independent observations, 1983

Li, Parizeau, and Plamondo introduced HMM traning formultiple observations, 2000

Nguyet Nguyen Hidden Markov Model for High Frequency Data

Page 4: Hidden Markov Model for High Frequency Data - UCLAwiki.stat.ucla.edu/socr/uploads/b/bd/NguyetNguyen_JMM_2014.pdf · Introduction of HMMs HMM and its three problems Financial Applications

Introduction of HMMs HMM and its three problems Financial Applications of HMMs Can we use HMMs to make money?

Some applications of HMMs

Figure : 1. Speech recognition 2. Bioinformatics 3. Finance

Nguyet Nguyen Hidden Markov Model for High Frequency Data

Page 5: Hidden Markov Model for High Frequency Data - UCLAwiki.stat.ucla.edu/socr/uploads/b/bd/NguyetNguyen_JMM_2014.pdf · Introduction of HMMs HMM and its three problems Financial Applications

Introduction of HMMs HMM and its three problems Financial Applications of HMMs Can we use HMMs to make money?

Elements of HMM

Observation data, O = (Ot), t = 1, ..,T

Hidden states, S = (Si ), i = 1, 2, ...,N

Hidden state sequence: Q = (qt), t = 1, ...,T

Transition matrix A

aij = P(qt = Sj |qt−1 = Si ), i , j = 1, 2, ...,N

Observation symbols per state, V = (vk), k = 1, 2, ...,M

The observation probability

B : bi (k) = P(Ot = vk |qt = Si ), i = 1, 2, ...,N; k = 1, 2, ...,M

Initial probabilities, vector p, of being in state Si at t = 1

pi = P(q1 = Si ), i = 1, 2, ...,N

Nguyet Nguyen Hidden Markov Model for High Frequency Data

Page 6: Hidden Markov Model for High Frequency Data - UCLAwiki.stat.ucla.edu/socr/uploads/b/bd/NguyetNguyen_JMM_2014.pdf · Introduction of HMMs HMM and its three problems Financial Applications

Introduction of HMMs HMM and its three problems Financial Applications of HMMs Can we use HMMs to make money?

Hidden Markov Model

S2

S1 S1

S2

t t+1

a11

a12

a21

a22

Ot Ot+1

b1(Ot)

b2(Ot)

Parameters of HMM: λ = {A,B, p}

Nguyet Nguyen Hidden Markov Model for High Frequency Data

Page 7: Hidden Markov Model for High Frequency Data - UCLAwiki.stat.ucla.edu/socr/uploads/b/bd/NguyetNguyen_JMM_2014.pdf · Introduction of HMMs HMM and its three problems Financial Applications

Introduction of HMMs HMM and its three problems Financial Applications of HMMs Can we use HMMs to make money?

Three problems and corresponding solutions for HMMs

1 Given (O, λ), compute the probability of observations, P(O|λ)

Forward, backward algorithm

2 Given (O, λ), simulate the most likely hidden states, Q

Viterbi algorithm

3 Given O, calibrate HMM parameters, λ

Baum-Welch algorithm

Nguyet Nguyen Hidden Markov Model for High Frequency Data

Page 8: Hidden Markov Model for High Frequency Data - UCLAwiki.stat.ucla.edu/socr/uploads/b/bd/NguyetNguyen_JMM_2014.pdf · Introduction of HMMs HMM and its three problems Financial Applications

Introduction of HMMs HMM and its three problems Financial Applications of HMMs Can we use HMMs to make money?

Three problems and corresponding solutions for HMMs

1 Given (O, λ), compute the probability of observations, P(O|λ)

Forward, backward algorithm

2 Given (O, λ), simulate the most likely hidden states, Q

Viterbi algorithm

3 Given O, calibrate HMM parameters, λ

Baum-Welch algorithm

Nguyet Nguyen Hidden Markov Model for High Frequency Data

Page 9: Hidden Markov Model for High Frequency Data - UCLAwiki.stat.ucla.edu/socr/uploads/b/bd/NguyetNguyen_JMM_2014.pdf · Introduction of HMMs HMM and its three problems Financial Applications

Introduction of HMMs HMM and its three problems Financial Applications of HMMs Can we use HMMs to make money?

Three problems and corresponding solutions for HMMs

1 Given (O, λ), compute the probability of observations, P(O|λ)

Forward, backward algorithm

2 Given (O, λ), simulate the most likely hidden states, Q

Viterbi algorithm

3 Given O, calibrate HMM parameters, λ

Baum-Welch algorithm

Nguyet Nguyen Hidden Markov Model for High Frequency Data

Page 10: Hidden Markov Model for High Frequency Data - UCLAwiki.stat.ucla.edu/socr/uploads/b/bd/NguyetNguyen_JMM_2014.pdf · Introduction of HMMs HMM and its three problems Financial Applications

Introduction of HMMs HMM and its three problems Financial Applications of HMMs Can we use HMMs to make money?

Three problems and corresponding solutions for HMMs

1 Given (O, λ), compute the probability of observations, P(O|λ)

Forward, backward algorithm

2 Given (O, λ), simulate the most likely hidden states, Q

Viterbi algorithm

3 Given O, calibrate HMM parameters, λ

Baum-Welch algorithm

Nguyet Nguyen Hidden Markov Model for High Frequency Data

Page 11: Hidden Markov Model for High Frequency Data - UCLAwiki.stat.ucla.edu/socr/uploads/b/bd/NguyetNguyen_JMM_2014.pdf · Introduction of HMMs HMM and its three problems Financial Applications

Introduction of HMMs HMM and its three problems Financial Applications of HMMs Can we use HMMs to make money?

Three problems and corresponding solutions for HMMs

1 Given (O, λ), compute the probability of observations, P(O|λ)

Forward, backward algorithm

2 Given (O, λ), simulate the most likely hidden states, Q

Viterbi algorithm

3 Given O, calibrate HMM parameters, λ

Baum-Welch algorithm

Nguyet Nguyen Hidden Markov Model for High Frequency Data

Page 12: Hidden Markov Model for High Frequency Data - UCLAwiki.stat.ucla.edu/socr/uploads/b/bd/NguyetNguyen_JMM_2014.pdf · Introduction of HMMs HMM and its three problems Financial Applications

Introduction of HMMs HMM and its three problems Financial Applications of HMMs Can we use HMMs to make money?

Three problems and corresponding solutions for HMMs

1 Given (O, λ), compute the probability of observations, P(O|λ)

Forward, backward algorithm

2 Given (O, λ), simulate the most likely hidden states, Q

Viterbi algorithm

3 Given O, calibrate HMM parameters, λ

Baum-Welch algorithm

Nguyet Nguyen Hidden Markov Model for High Frequency Data

Page 13: Hidden Markov Model for High Frequency Data - UCLAwiki.stat.ucla.edu/socr/uploads/b/bd/NguyetNguyen_JMM_2014.pdf · Introduction of HMMs HMM and its three problems Financial Applications

Introduction of HMMs HMM and its three problems Financial Applications of HMMs Can we use HMMs to make money?

Forward Algorithm

Define the joint probability αt(i) = P(O1,O2, ...,Ot , qt = Si |λ)

Si

t-1 t

t(i)

forwardNguyet Nguyen Hidden Markov Model for High Frequency Data

Page 14: Hidden Markov Model for High Frequency Data - UCLAwiki.stat.ucla.edu/socr/uploads/b/bd/NguyetNguyen_JMM_2014.pdf · Introduction of HMMs HMM and its three problems Financial Applications

Introduction of HMMs HMM and its three problems Financial Applications of HMMs Can we use HMMs to make money?

Forward algorithm

Initialization, α1(i) = pibi (O1) for i = 1, ...,N

For t = 2, 3, ...,T , for j = 1, ...,N

αt(j) =

[N∑i=1

αt−1(i)aij

]bj(Ot),

P(O|λ) =∑N

i=1 αT (i)

Nguyet Nguyen Hidden Markov Model for High Frequency Data

Page 15: Hidden Markov Model for High Frequency Data - UCLAwiki.stat.ucla.edu/socr/uploads/b/bd/NguyetNguyen_JMM_2014.pdf · Introduction of HMMs HMM and its three problems Financial Applications

Introduction of HMMs HMM and its three problems Financial Applications of HMMs Can we use HMMs to make money?

Backward Algorithm

Define the conditional probabilityβt(j) = P(Ot+1,Ot+2, ..,OT |qt = Sj , λ), for j = 1, ...,N

Sj

t+1 t+2

t+1(j)

backwardNguyet Nguyen Hidden Markov Model for High Frequency Data

Page 16: Hidden Markov Model for High Frequency Data - UCLAwiki.stat.ucla.edu/socr/uploads/b/bd/NguyetNguyen_JMM_2014.pdf · Introduction of HMMs HMM and its three problems Financial Applications

Introduction of HMMs HMM and its three problems Financial Applications of HMMs Can we use HMMs to make money?

Backward Algorithm

Algorithm

Initialization, βT (i) = 1 for i = 1, ...,N

For t = T − 1,T − 2, ..., 1, for i = 1, ...,N

βt(i) =N∑j=1

aijbj(Ot+1)βt+1(j)

P(O|λ) =∑N

i=1 pibi (O1)β1(i)

Nguyet Nguyen Hidden Markov Model for High Frequency Data

Page 17: Hidden Markov Model for High Frequency Data - UCLAwiki.stat.ucla.edu/socr/uploads/b/bd/NguyetNguyen_JMM_2014.pdf · Introduction of HMMs HMM and its three problems Financial Applications

Introduction of HMMs HMM and its three problems Financial Applications of HMMs Can we use HMMs to make money?

Choose economics indicators

1 Inflation (CPI)

2 Credit Index

3 Yield Curve

4 Commodity

5 Dow Jones Industrial Average

Nguyet Nguyen Hidden Markov Model for High Frequency Data

Page 18: Hidden Markov Model for High Frequency Data - UCLAwiki.stat.ucla.edu/socr/uploads/b/bd/NguyetNguyen_JMM_2014.pdf · Introduction of HMMs HMM and its three problems Financial Applications

Introduction of HMMs HMM and its three problems Financial Applications of HMMs Can we use HMMs to make money?

Training and Predicting Process

Using the variables above:

Use HMM for single and multiple observation data withnormal distributions.

Calibrate Markov-switching model parameters usingBaum-Welch algorithm

Define state or regime 2 with lower mean/variance

Use the obtained parameters to predict the correspondingstates (regimes), predict the upcoming regime.

Nguyet Nguyen Hidden Markov Model for High Frequency Data

Page 19: Hidden Markov Model for High Frequency Data - UCLAwiki.stat.ucla.edu/socr/uploads/b/bd/NguyetNguyen_JMM_2014.pdf · Introduction of HMMs HMM and its three problems Financial Applications

Introduction of HMMs HMM and its three problems Financial Applications of HMMs Can we use HMMs to make money?

Results

HMM Bear Market (monthly 5/2006−5/2013)

Time

Nor

mal

ized

dat

a

2007 2008 2009 2010 2011 2012 2013

−3

−2

−1

01

2

DJIANDR Bear MarketHMM Bear Market

Figure : Dow Jones observations vs probabilities of being in the bearmarket

Nguyet Nguyen Hidden Markov Model for High Frequency Data

Page 20: Hidden Markov Model for High Frequency Data - UCLAwiki.stat.ucla.edu/socr/uploads/b/bd/NguyetNguyen_JMM_2014.pdf · Introduction of HMMs HMM and its three problems Financial Applications

Introduction of HMMs HMM and its three problems Financial Applications of HMMs Can we use HMMs to make money?

Results

Figure : Forecast bear market using CPI indicator

Nguyet Nguyen Hidden Markov Model for High Frequency Data

Page 21: Hidden Markov Model for High Frequency Data - UCLAwiki.stat.ucla.edu/socr/uploads/b/bd/NguyetNguyen_JMM_2014.pdf · Introduction of HMMs HMM and its three problems Financial Applications

Introduction of HMMs HMM and its three problems Financial Applications of HMMs Can we use HMMs to make money?

Results

HMM Forecast Bear Market (monthly 10/2006−5/2013)

Time

Nor

mal

ized

dat

a

2007 2008 2009 2010 2011 2012 2013

−3

−2

−1

01

2

DJIACredit IndexYield CurveCommodityHMM Bear Market

Figure : Forecast bear market using multiple observations

Nguyet Nguyen Hidden Markov Model for High Frequency Data

Page 22: Hidden Markov Model for High Frequency Data - UCLAwiki.stat.ucla.edu/socr/uploads/b/bd/NguyetNguyen_JMM_2014.pdf · Introduction of HMMs HMM and its three problems Financial Applications

Introduction of HMMs HMM and its three problems Financial Applications of HMMs Can we use HMMs to make money?

S&P 500, a stock market index based on the marketcapitalizations of 500 large companies having common stocklisted on the NYSE or NASDAQ. Monthly percentage changesfrom February 1947 through June 2013.

SPY

GOOG

FORD

AAPL

GE

Nguyet Nguyen Hidden Markov Model for High Frequency Data

Page 23: Hidden Markov Model for High Frequency Data - UCLAwiki.stat.ucla.edu/socr/uploads/b/bd/NguyetNguyen_JMM_2014.pdf · Introduction of HMMs HMM and its three problems Financial Applications

Introduction of HMMs HMM and its three problems Financial Applications of HMMs Can we use HMMs to make money?

Training and Predicting Process

Using the variables above:

Use HMM for single and multiple observation data withnormal distributions.

Calibrate Markov-switching model parameters usingBaum-Welch algorithm

Use the obtained parameters to predict stock prices for thenext trading period.

Nguyet Nguyen Hidden Markov Model for High Frequency Data

Page 24: Hidden Markov Model for High Frequency Data - UCLAwiki.stat.ucla.edu/socr/uploads/b/bd/NguyetNguyen_JMM_2014.pdf · Introduction of HMMs HMM and its three problems Financial Applications

Introduction of HMMs HMM and its three problems Financial Applications of HMMs Can we use HMMs to make money?

●●

●●

●●●●●●●

●●●

●●

●●●●

●●●

●●●

●●●●●●

●●●

●●●

●●●

●●

●●

●●●●●

●●

●●●

●●

●●●

●●

●●

●●●●●●

●●

●●

●●

●●

●●●●

●●●●●

●●

●●●

●●

●●

●●●

●●●●●●

●●●

●●●

●●●●

●●

●●

●●

●●

●●

●●

●●

●●

●●

●●●

●●●

●●

●●

●●●

●●

●●

●●

●●●●

●●●

●●●

0 50 100 150 200 250

1300

1400

1500

1600

1700

S&P500 Using Close Prices 7/30/2012−7/31/2013

Times

S&

P50

0 P

rices

● True priceEstimated price

Figure : Forecast S&P500 close prices using single observation

Nguyet Nguyen Hidden Markov Model for High Frequency Data

Page 25: Hidden Markov Model for High Frequency Data - UCLAwiki.stat.ucla.edu/socr/uploads/b/bd/NguyetNguyen_JMM_2014.pdf · Introduction of HMMs HMM and its three problems Financial Applications

Introduction of HMMs HMM and its three problems Financial Applications of HMMs Can we use HMMs to make money?

Results

●●

●●

●●●●●●●

●●●

●●

●●●●

●●●

●●●

●●●●●●

●●●

●●●

●●●

●●

●●

●●●●●

●●

●●●

●●

●●●

●●

●●

●●●●●●

●●

●●

●●

●●

●●●●

●●●●●

●●

●●●

●●

●●

●●●

●●●●●●

●●●

●●●

●●●●

●●

●●

●●

●●

●●

●●

●●

●●

●●

●●●

●●●

●●

●●

●●●

●●

●●

●●

●●●●

●●●

●●●

0 50 100 150 200 250

1300

1400

1500

1600

1700

S&P500 Using Close−Open−High−Low 7/30/2012−7/31/2013

Times

S&

P50

0 P

rices

● True priceEstimated price

Figure : Forecast S&P500 closing prices using multiple observations(open-close-high-low)

Nguyet Nguyen Hidden Markov Model for High Frequency Data

Page 26: Hidden Markov Model for High Frequency Data - UCLAwiki.stat.ucla.edu/socr/uploads/b/bd/NguyetNguyen_JMM_2014.pdf · Introduction of HMMs HMM and its three problems Financial Applications

Introduction of HMMs HMM and its three problems Financial Applications of HMMs Can we use HMMs to make money?

Results

● ●

● ●

● ●

● ● ● ● ●

● ● ●

● ● ●

● ●

● ●

● ● ●

● ● ●

● ● ●

● ● ● ●

● ● ●

● ● ●

● ● ●

● ● ● ● ●

● ● ● ● ● ● ●

● ●

● ●

● ● ●

● ● ● ● ● ● ● ●

● ● ● ●

● ● ● ● ● ● ● ● ● ●

● ● ● ● ●

● ●

● ● ●

0 20 40 60 80 100

126.

912

7.0

127.

112

7.2

127.

3

SPY 10:51:52 to 10:53:41 on 1/7/2011

Times

S&

P50

0 P

rices

● True priceEstimated price

Figure : Forecast SPY bid price in tick by tick

Nguyet Nguyen Hidden Markov Model for High Frequency Data

Page 27: Hidden Markov Model for High Frequency Data - UCLAwiki.stat.ucla.edu/socr/uploads/b/bd/NguyetNguyen_JMM_2014.pdf · Introduction of HMMs HMM and its three problems Financial Applications

Introduction of HMMs HMM and its three problems Financial Applications of HMMs Can we use HMMs to make money?

Can we use HMMs to make money?

Symbol Initial Investment ($) Earning ($) Earning %

SPY 9,000.00 2050.66 22.79

GOOG 30,000.00 29,036.4 96.79

FORD 250.00 10.10 4.04

AAPL 950.00 19.06 2.01

GE 1,700.00 490.00 28.82

TOTAL 41,900.00 31,606.22 75.43

Table : One year daily stock trading portfolio from December 2012 toDecember 2013

Nguyet Nguyen Hidden Markov Model for High Frequency Data

Page 28: Hidden Markov Model for High Frequency Data - UCLAwiki.stat.ucla.edu/socr/uploads/b/bd/NguyetNguyen_JMM_2014.pdf · Introduction of HMMs HMM and its three problems Financial Applications

Introduction of HMMs HMM and its three problems Financial Applications of HMMs Can we use HMMs to make money?

Thank you!

Nguyet Nguyen: [email protected]

Department of Mathematics, Florida State University

Nguyet Nguyen Hidden Markov Model for High Frequency Data