This action might not be possible to undo. Are you sure you want to continue?
HIDDEN MARKOV MODELS
by
Yingjian Zhang
B.Eng. Shandong University, China, 2001
a thesis submitted in partial fulfillment
of the requirements for the degree of
Master of Applied Science
in the School
of
Computing Science
c Yingjian Zhang 2004
SIMON FRASER UNIVERSITY
May 2004
All rights reserved. This work may not be
reproduced in whole or in part, by photocopy
or other means, without the permission of the author.
APPROVAL
Name: Yingjian Zhang
Degree: Master of Applied Science
Title of thesis: Prediction of Financial Time Series with Hidden Markov Models
Examining Committee: Dr. Ghassan Hamarneh
Chair
Dr. Anoop Sarkar
Assistant Professor, Computing Science
Senior Supervisor
Dr. Andrey Pavlov
Assistant Professor, Business Administration
CoSenior Supervisor
Dr. Oliver Schulte
Assistant Professor, Computing Science
Supervisor
Dr. Martin Ester
Associate Professor, Computing Science
SFU Examiner
Date Approved:
ii
Abstract
In this thesis, we develop an extension of the Hidden Markov Model (HMM) that addresses
two of the most important challenges of ﬁnancial time series modeling: nonstationary and
nonlinearity. Speciﬁcally, we extend the HMM to include a novel exponentially weighted
ExpectationMaximization (EM) algorithm to handle these two challenges. We show that
this extension allows the HMM algorithm to model not only sequence data but also dynamic
ﬁnancial time series. We show the update rules for the HMM parameters can be written
in a form of exponential moving averages of the model variables so that we can take the
advantage of existing technical analysis techniques. We further propose a double weighted
EM algorithm that is able to adjust training sensitivity automatically. Convergence results
for the proposed algorithms are proved using techniques from the EM Theorem.
Experimental results show that our models consistently beat the S&P 500 Index over
ﬁve 400day testing periods from 1994 to 2002, including both bull and bear markets. Our
models also consistently outperform the top 5 S&P 500 mutual funds in terms of the Sharpe
Ratio.
iii
To my mom
iv
Acknowledgments
I would like to express my deep gratitude to my senior supervisor, Dr. Anoop Sarkar for his
great patience, detailed instructions and insightful comments at every stage of this thesis.
What I have learned from him goes beyond the knowledge he taught me; his attitude toward
research, carefulness and commitment has and will have a profound impact on my future
academic activities.
I am also indebted to my cosenior supervisor, Dr. Andrey Pavlov, for trusting me before
I realize my results. I still remember the day when I ﬁrst presented to him the ”super ﬁve
day pattern” program. He is the source of my knowledge in ﬁnance that I used in this
thesis. Without the countless time he spent with me, this thesis surely would not have been
impossible.
I cannot thank enough my supervisor, Dr. Oliver Schulte. Part of this thesis derives
from a course project I did for his machine learning course in which he introduced me the
world of machine learning and interdisciplinary research approaches.
Many of my fellow graduate students oﬀered great help during my study and research at
the computing science school. I thank Wei Luo for helping me with many issues regarding
the L
A
T
E
Xand Unix; Cheng Lu and Chris Demwell for sharing their experiences with Hidden
Markov Models; my labmates at the Natural Language Lab for the comments at my practice
talk and for creating such a nice environment in which to work.
I would also like to thank Mr. Daniel Brimm for the comments from the point of view
of a real life business professional.
Finally I would like to thank my mom for all that she has done for me. Words cannot
express one millionth of my gratitude to her but time will prove the return of her immense
love.
v
Contents
Approval ii
Abstract iii
Dedication iv
Acknowledgments v
Contents vi
List of Tables ix
List of Figures x
1 Introduction 1
1.1 Financial Time Series . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.2 Return of Financial Time Series . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.3 The Standard & Poor 500 data . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.4 Traditional Techniques and Their Limitations . . . . . . . . . . . . . . . . . . 5
1.5 Noneﬃciency of Financial Markets . . . . . . . . . . . . . . . . . . . . . . . . 6
1.6 Objective . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
1.7 Contributions of the Thesis . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
1.8 Thesis Organization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
1.9 Notation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
2 Hidden Markov Models 13
2.1 Markov Models . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
vi
2.2 A Markov chain of stock market movement . . . . . . . . . . . . . . . . . . . 14
2.3 Hidden Markov Models . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
2.4 Why HMM? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
2.5 General form of an HMM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
2.6 Discrete and continuous observation probability distribution . . . . . . . . . . 20
2.6.1 Discrete observation probability distribution . . . . . . . . . . . . . . . 20
2.6.2 Continuous observation probability distribution . . . . . . . . . . . . . 21
2.7 Three Fundamental Problems for HMMs . . . . . . . . . . . . . . . . . . . . . 22
2.7.1 Problem 1: ﬁnding the probability of an observation . . . . . . . . . . 23
2.7.2 Problem 2: Finding the best state sequence . . . . . . . . . . . . . . . 27
2.7.3 Problem 3: Parameter estimation . . . . . . . . . . . . . . . . . . . . . 29
2.8 Chapter Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
3 HMM for Financial Time Series Analysis 32
3.1 Previous Work . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
3.2 BaumWelch Reestimation for Gaussian mixtures . . . . . . . . . . . . . . . 34
3.3 Multivariate Gaussian Mixture as Observation Density Function . . . . . . . 37
3.3.1 Multivariate Gaussian distributions . . . . . . . . . . . . . . . . . . . . 38
3.3.2 EM for multivariate Gaussian mixtures . . . . . . . . . . . . . . . . . 38
3.4 Multiple Observation Sequences . . . . . . . . . . . . . . . . . . . . . . . . . . 39
3.5 Dynamic Training Pool . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
3.6 Making Predictions with HMM . . . . . . . . . . . . . . . . . . . . . . . . . . 42
3.6.1 Setup of HMM Parameters . . . . . . . . . . . . . . . . . . . . . . . . 42
3.6.2 Making predictions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
3.7 Chapter Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
4 Exponentially Weighted EM Algorithm for HMM 46
4.1 Maximumlikelihood . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
4.2 The Traditional EM Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . 47
4.3 Rewriting the Q Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
4.4 Weighted EM Algorithm for Gaussian Mixtures . . . . . . . . . . . . . . . . . 50
4.5 HMGM Parameter Reestimation with the Weighted EM Algorithm . . . . . 54
4.6 Calculation and Properties of the Exponential Moving Average . . . . . . . . 55
4.7 HMGM Parameters Reestimation in a Form of EMA . . . . . . . . . . . . . 58
vii
4.8 The EM Theorem and Convergence Property . . . . . . . . . . . . . . . . . . 61
4.9 The Double Weighted EM Algorithm . . . . . . . . . . . . . . . . . . . . . . . 63
4.9.1 Problem with the Exponentially Weighted Algorithm . . . . . . . . . . 63
4.9.2 Double Exponentially Weighted Algorithm . . . . . . . . . . . . . . . 63
4.10 Chapter Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
5 Experimental Results 65
5.1 Experiments with Synthetic Data Set . . . . . . . . . . . . . . . . . . . . . . 65
5.2 Recurrent Neural Network Results . . . . . . . . . . . . . . . . . . . . . . . . 67
5.3 HMGM Experimental Results . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
5.4 Test on Data Sets from Diﬀerent Time Periods . . . . . . . . . . . . . . . . . 71
5.5 Comparing the Sharpe Ratio with the Top Five S&P 500 Mutual Funds . . . 72
5.6 Comparisons with Previous Work . . . . . . . . . . . . . . . . . . . . . . . . . 79
6 Conclusion and Future Work 81
6.1 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
6.2 Future Work . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82
A Terminology List 84
Bibliography 86
viii
List of Tables
1.1 Data format of the experiment (for the segment from Jan 2, 2002 to Jan 7, 2002) . . 5
1.2 Notation list . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
2.1 State transition probability matrix of the HMM for stock price forecast. As the
market move from one day to another, the professional might change his strategy
without letting others know . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
5.1 Comparison of the recurrent network and exponentially weighted HMGM on the
synthetic data testing. The EWHMGM outperforms the recurrent network in overall
result, and has less volatility. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
5.2 Comparison of the Sharpe Ratio between the HMM and the top 5 S&P 500 funds
during the period of August 5, 1999 to March 7, 2001. Four of the ﬁve funds have
negative Sharpe Ratios. The absolute value of the positive one is much smaller than
the HMGM prediction. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
5.3 Comparison of the Sharpe Ratios during the period of March 8, 2001 to October 11,
2002. The Double weighted HMGM consistently outperforms the top ﬁve S&P 500
mutual funds. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
ix
List of Figures
1.1 The return curve of a prediction system. $1 input at the beginning of the trading
period generates a return of $2.1 while the index drops below 1. . . . . . . . . . 4
1.2 A Super Five Day Pattern in the NASDAQ Composite Index from 1984 to 1990.
The ﬁrst three days and the last two days tend to have higher return than the rest
of the trading days. However, the pattern diminished in the early 1990s. . . . . . . 8
2.1 Modeling the possible movement directions of a stock as a Markov chain. Each of
the nodes in the graph represent a move. As time goes by, the model moves from
one state to another, just as the stock price ﬂuctuates everyday. . . . . . . . . . . . 15
2.2 The ﬁgure shows the set of strategies that a ﬁnancial professional can take. The
strategies are modeled as states. Each strategy is associated with a probability of
generating the possible stock price movement. These probabilities are hidden to the
public, only the professional himself knows it. . . . . . . . . . . . . . . . . . . . . 17
2.3 The trellis of the HMM. The states are associated with diﬀerent strategies and are
connected to each other. Each state produces an observation picked from the vector
[LR, SR, UC, SD, LD]. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
2.4 The forward procedure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
2.5 The backward procedure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
2.6 Finding best path with the Viterbi algorithm . . . . . . . . . . . . . . . . . . . . 29
3.1 Three single Gaussian density functions. Each of them will contributing a percentage
to the combined output in the mixture. . . . . . . . . . . . . . . . . . . . . . . . 35
x
3.2 A Gaussian mixture derived from the three Gaussian densities above. For each
small area δ close to each point x on the x axis, there is a probability of 20% that
the random variable x is governed by the ﬁrst Gaussian density function, 30% of
probability that the distribution of x is governed by the second Gaussian, and 50%
of probability by the third Gaussian. . . . . . . . . . . . . . . . . . . . . . . . . 36
3.3 The dynamic training pool . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
3.4 Hidden Markov Gaussian Mixtures . . . . . . . . . . . . . . . . . . . . . . . . . . 43
4.1 When the 30day moving average moves above the 100day moving average, the trend
is considered bullish. When the 30day moving average declines below the 100day
moving average, the trend is considered bearish. (picture from stockcharts.com) . . . 56
4.2 The portion of each of the ﬁrst 19 days’ EMA in calculating the EMA for the 20th
day. As is shown in the ﬁgure, the EMA at the 19th day accounts for 2/3 of the
EMA at day 20. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
4.3 The portion of each of the 20 days’ actual data in calculating the EMA for the 20th
day. The last day account for 1/3 of the EMA at day 20. The data earlier than day
10 take up a very small portion but they are still included in the overall calculation . 59
4.4 The prediction falls behind the market during highly volatile periods of time. This
is because the system is too sensitive to recent changes. . . . . . . . . . . . . . . . 63
5.1 Experimental results on computer generated data. . . . . . . . . . . . . . . . . . . 66
5.2 Prediction of the NASDAQ Index in 1998 with a recurrent neural network. . . . . . 67
5.3 Prediction of the NASDAQ Index in 1999 with a recurrent neural network. . . . . . 68
5.4 Prediction of the NASDAQ Index in 2000 with a recurrent neural network. . . . . . 68
5.5 Prediction of the 400day S&P 500 Index starting from Jan 2, 1998. Training
window size = 10 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
5.6 Prediction of the 400day S&P 500 Index starting from Jan 2, 1998. Training
window size = 20 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
5.7 Prediction of the 400day S&P 500 Index starting from Jan 2, 1998. Training
window size = 40 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
5.8 Prediction of the 400day S&P 500 Index starting from Jan 2, 1998. Training
window size = 100 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
5.9 Prediction with HMGM for 400 days of the S&P 500 Index. Note from t213 to t228,
the HMM was not able to catch up with the change in trend swiftly. . . . . . . . . 73
xi
5.10 Prediction with multivariate HMGM for 400 days of the S&P 500 Index. . . . . . . 73
5.11 Prediction with single exponentially weighted HMGM . . . . . . . . . . . . . . . . 74
5.12 Prediction with double weighted HMGM that has a conﬁdence adjustment variable. 74
5.13 Results from all models for comparison. . . . . . . . . . . . . . . . . . . . . . . . 75
5.14 Results on the period from November 2, 1994 to June 3, 1996 . . . . . . . . . . . . 75
5.15 Results on the period from June 4, 1996 to December 31, 1998 . . . . . . . . . . . 76
5.16 Results on the period from August 5, 1999 to March 7, 2001 . . . . . . . . . . . . . 76
5.17 Results on the period from March 8, 2001 to October 11, 2002 . . . . . . . . . . . 77
5.18 Too many positive signals result in a curve similar to the index. . . . . . . . . . . . 80
xii
Chapter 1
Introduction
This thesis explores a novel model in the interdisciplinary area of computational ﬁnance.
Similar to traditional ﬁnancial engineering, we build models to analyze and predict ﬁnancial
time series. What distinguish us from the previous work is rather than building models based
on regression equations, we apply a machien learning model–the Hidden Markov Model to
ﬁnancial time series. This chapter describes the basic concepts in ﬁnancial time series, the
diﬃculties of accurate ﬁnancial time series prediction, the limitations of regression models,
motivation and objective of our machine learning model. The organization of the thesis is
also outlined in the later part this chapter.
1.1 Financial Time Series
Financial time series data are a sequence of prices of some ﬁnancial assets over a speciﬁc
period of time. In this thesis we will focus our research on the most volatile and challenging
ﬁnancial market – the stock market. More speciﬁcally, our experiment data include the
daily data of NASDAQ Composite Index, the Dow Jones Industrial Index and the S&P 500
Index.
Over the past 50 years, there has been a large amount of intensive research on the
stock market. All the ﬁnancial analysts carry out many kinds of research in the hope of
accomplishing one goal: to beat the market. To beat the market means to have a rate
of return that is consistently higher than the average return of the market while keeping
the same level of risk as the market. In this thesis, the average rate of return is the Dow
Jones Industrial Index , which is a weighted average of 30 signiﬁcant stocks, and the S&P
1
CHAPTER 1. INTRODUCTION 2
500 Index, which is a combination of 500 stocks. Generally there are two main streams in
ﬁnancial market analysis: fundamental analysis and technical analysis.
Fundamental analysis is the examination of the underlying forces that aﬀect the well
being of the economy, industry sectors, and individual companies. For example, to forecast
future prices of an individual stock, fundamental analysis combines economic, industry, and
company analyses to derive the stock’s current fair value and forecast its future value. If fair
value is not equal to the current stock price, fundamental analysts believe that the stock is
either over or under valued and the market price will ultimately gravitate toward fair value.
There are some inherent weaknesses in fundamental analysis. First, it is very time
consuming: by the time fundamental analysts collect information of the company or economy
health and give their prediction of the future price, the current price has already changed
to reﬂect the most updated information. Second, there is an inevitable analyst bias and
accompanying subjectivity.
Technical analysis is the examination of past price movements to forecast future price
movements. In our experiments we base our forecast of the daily stock price on the past
daily prices.
The theoretical basis of technical analysis is: price reﬂects all the relevant information;
price movements are not totally random; history repeats itself. And all these are derived
from the belief in the noneﬃciency of the ﬁnancial markets. We will discuss the market
eﬃciency hypothesis later in this chapter and the evidence of noneﬃciency in the market.
We will focus only on methods of technical analysis in this thesis.
In this thesis, we use forecast and prediction alternatively to represent the process of
generating unseen data in a ﬁnancial time series.
1.2 Return of Financial Time Series
One of the most important indicators of measuring the performance of mutual funds or
prediction systems is the return of the system. Usually we have a benchmark series to
compare against. In our experiment we use the S&P 500 index as the benchmark.
Let P
t
be the price of an asset at time index t. The oneperiod simple net return R
t
of
a ﬁnancial time series is calculated with the following formula:
CHAPTER 1. INTRODUCTION 3
R
t
=
P
t
−P
t−1
P
t−1
(1.1)
For a kperiod ﬁnancial time series, the return at the end of the period is a cumulative
return that is composed of all the periods:
1 +P
t
[k] = (1 +R
1
)(1 +R
2
) . . . (1 +R
k
)
=
k
t=1
(1 +R
t
) (1.2)
In developing a prediction system, our goal is to make as many accurate predictions
as possible. This will result in a return curve for the prediction system. The higher the
prediction accuracy, the higher the return curve will be above the index curve. Figure 1.1
shows the return based on a strategy using some prediction system. If we invest 1 dollar at
the beginning of the period, we will get $2.1 at the end of the period.
If one get an accuracy 100% for any 400 consecutive days in the ten year period 1987
to 1994, the return at the end of the period would be roughly 25 times the initial input.
This is the upper bound for the return. Normally we care more about the return than the
accuracy rate of the prediction because the simple net return at each day is diﬀerent. For
example, two days of accurate predictions of small changes may not oﬀset the loss of one
day’s incorrect prediction of a large change in the market.
Prediction of ﬁnancial time series is a very extensive topic. In this thesis, we only predict
the direction of the time series, generating a signal of either up or down for each trading
day.
1.3 The Standard & Poor 500 data
The real world ﬁnancial time series we input into the HMM prediction system is the daily
return of the Standard & Poor 500 Index (S&P 500). The S&P 500 index is a weighted
average of the stock prices of 500 leading companies in leading industry sectors of the US.
The index reﬂects the total market value of all component stocks relative to a particular
period of time. The S&P 500 Index is viewed as one of the best indicators of the US economy
health. Unlike the Dow Jones Industrial Average, which is an average of the 30 component
stock prices, the S&P 500 represents the market value of the 500 component stocks. To
CHAPTER 1. INTRODUCTION 4
0.8
1
1.2
1.4
1.6
1.8
2
2.2
0 50 100 150 200 250 300 350 400
r
e
t
u
r
n
trading day
prediction
market
Figure 1.1: The return curve of a prediction system. $1 input at the beginning of the trading period
generates a return of $2.1 while the index drops below 1.
calculate the S&P 500 Index, we ﬁrst add up the total market value of all the 500 stocks,
then divide them by the total number of outstanding shares in the market. Because it looks
at the total market value and includes stocks from diﬀerent industries than the Dow, the
S&P 500 has some diﬀerent characteristics from the Dow.
In some scenarios of the experiments we also include the Dow Jones Index that span
during the same time period as the S&P 500 Index. One reason to use another time series
to facilitate the prediction is that there are sideway movements in the long term trends,
also called the whipsaws(see 3.1). These are the reverse signals in a long term trend. We
need to identify the real trend change signals from the noisy whipsaws. The Dow is a less
sensitive index than the S&P 500 so we use it to help smooth the prediction.
The return of the S&P 500 Index for each day is calculated using the techniques
introduction in Section 1.2. The price we use for the calculation is the close price for
each day. In some experiments we use a second sequence of data: the volume. An example
of the data format is shown in Table 1.1:
CHAPTER 1. INTRODUCTION 5
Date Close Return Volume
Jan22002 1154.67 0.00574 1418169984
Jan32003 1165.27 0.00918 1874700032
Jan42002 1172.51 0.006213 1943559936
Jan72002 1164.89 0.0065 1682759936
Table 1.1: Data format of the experiment (for the segment from Jan 2, 2002 to Jan 7, 2002)
1.4 Traditional Techniques and Their Limitations
Traditionally, people use various forms of statistical models to predict volatile ﬁnancial
time series [GP86]. Sometimes stocks move without any apparent news, as the Dow Jones
Industrial Index did on Monday, October 19, 1987. It fell by 22.6 percent without any
obvious reason. We have to identify whether an irrational price movement is noise or is
part of a pattern. Perhaps the most prominent of all these models is the BlackScholes
model for stock option pricing [BS73] [Hul00]. The BlackScholes model is a statistical
model for pricing the stock option at a future time based on a few parameters. Most of
these statistical models require one assumption: the form of population distribution such
as Gaussian distributions for stock markets or binomial distribution for bonds and debts
markets [MCG04].
Before we go on to the machine learning solution to the problem, let’s take a short review
of the econometrics method. Classical econometrics has a large literature for the time series
forecast problem. The basic idea is as follows:
To make things simple, assume the time series follow a linear pattern. We then ﬁnd a
linear regression predicting the target values from the time, y
t
= a+b ×y
t−1
+noise, where
a and b are regression weights. Then work out the weights given some form of noise. This
method is rather crude but may work for deterministic linear trends. For nonlinear trends,
one needs to use a nonlinear regression such as y
t
= a ×y
t−1
+b ×y
2
t−1
. But sometimes this
nonlinear formulation is very hard to ﬁnd.
The econometrics method usually proposes a statistical model based on a set of parameters.
As these models are independent of the past prices, some of these parameters must be
estimated based on other current situations. The process of the estimation of these parameters
will bring in human analyst bias. For example, in the BlackScholes option pricing model,
CHAPTER 1. INTRODUCTION 6
the noarbitrage
1
option cost is calculated as:
C = C(s, t, K, σ, r)
= e
−rt
E[(se
W
−K)
+
]
= E[(se
W−rt
−Ke
−rt
)
+
]
= E[(se
−σ
2
t/2+σ
√
t
−Ke
−rt
)
+
] (1.3)
s is the security’s initial price, t is the exercise time of the option, K is the strike price,
r is the interest rate. These four parameters are ﬁxed and can be easily identiﬁed. W is a
normal random variable with mean (r −σ
2
/2) and variance σ
2
t. The only way to decide it
is to pick a segment of past price data, then assume the logarithm of this data follows the
normal random distribution. The choosing of the price segment and the assumption that
the logarithm of the prices follows the normal random distribution is rather subjective.
Another inherent problem of the statistical methods is that sometimes there are price
movements that cannot be modeled with one single probability density function (pdf). In
[Ros03], we see an experiment on the crude oil data. The example shows rather than just one
function, these are four distributions that determine the diﬀerence between the logarithm
of tomorrow’s price and the logarithm of today’s price. These four pdfs must work together
with each of them providing a contribution at diﬀerent time points.
Finally, there are times that we cannot ﬁnd the best approximation function. This can
be caused by the rapid change in the data patterns. For diﬀerent time windows, there are
diﬀerent patterns thus cannot be described with one stationary model. It has been agreed
that no single model can make accurate predictions all the time.
1.5 Noneﬃciency of Financial Markets
In a classic statement on the Eﬃcient Market Hypothesis (EMH), Fama [Fam65] [Fam70]
deﬁned an eﬃcient ﬁnancial market as one in which security prices always fully reﬂects the
available information. The EMH “rules out the possibility of trading systems based only on
currently available information that have expected proﬁts or returns in excess of equilibrium
expected proﬁt or return” [Fam70]. In plain English, an average investor cannot hope to
1
Arbitrage is the simultaneous buying and selling of securities to take advantage of price discrepancies.
Arbitrage opportunities usually surface after a takeover oﬀer.
CHAPTER 1. INTRODUCTION 7
consistently beat the market, and the best prediction for a future price is the current price.
This is called a random walk of the market. If equal performance is obtained on the random
walk data as compared to the real data then no signiﬁcant predictability has been found.
The EMH was met with harsh challenges both theoretically and empirically shortly after it
was proposed.
De Bondt et. [BWT85] compare the performance of two groups of companies: extreme
losers and extreme winners. They study the stock price of two groups of companies from
1933 to 1985. They ﬁnd that the portfolios of the winners chosen in the previous three years
have relatively low returns than the loser’s portfolio over the following ﬁve years. A more
prominent example is the socalled January Eﬀect [Wac42] [Tha87]. For small companies,
there are superior returns around the end of the year and in early January than other times
of the year. This phenomenon was observed many years after Wachtel’s initial observation
and discussion. Interestingly the January eﬀect has disappeared in the last 15 years. But
this does not mean the market is fully eﬃcient as the process took a long time and there
may have evolved other new patterns that are yet to ﬁnd out.
Our own program also ﬁnds some interesting patterns. There is a super ﬁve day pattern
in the NASDAQ Composite Index from 1984 to 1990. This means the ﬁrst three days and
the last two days of each month generate a higher return in the index than any other day
of the month. The shape of the return curve thus looks like a parabola. After 1990, the
pattern became more random and less recognizable.
1.6 Objective
Financial time series consists of multidimensional and complex nonlinear data that result
in of pitfalls and diﬃculties for accurate prediction. We believe that a successful ﬁnancial
time series prediction system should be hybrid and custom made, which means it requires
a perfect combination of sophistication in the prediction system design and insight in the
input data preprocessing.
Both areas have been extensively researched. Data mining people have developed
some very useful techniques of dealing with data, such as missing values [HK01], data
multiplication [WG93]. Traders and technical analysts also have done lots of work. They
derive enhanced features of interest from the raw time series data, such as the variety of
indicators including Moving Average Convergence Divergence (MACD), Price by Volume,
CHAPTER 1. INTRODUCTION 8
60
40
20
0
20
40
60
80
0 5 10 15 20 25
r
e
t
u
r
n
trading day
daily return
Figure 1.2: A Super Five Day Pattern in the NASDAQ Composite Index from 1984 to 1990. The
ﬁrst three days and the last two days tend to have higher return than the rest of the trading days.
However, the pattern diminished in the early 1990s.
CHAPTER 1. INTRODUCTION 9
Relative Strength Index (RSI) etc. some of which have been conﬁrmed to pertain useful
information [STW99].
On the other hand, there have been several straightforward approaches that apply a
single algorithm to relatively unprocessed data, such as Back Propagation Network [CWL96],
Nearest Neighbor [Mit97], Genetic Algorithm [Deb94], Hidden Markov Models (HMM)[SW97]
and so on.
There are three major diﬃculties about accurate forecast of ﬁnancial time series. First,
the patterns of wellknown ﬁnancial time series are dynamic, i.e. there is no single ﬁxed
models that work all the time. Second, it is hard to balance between longterm trend and
shortterm sideway movements during the training process. In other words, an eﬃcient
system must be able to adjusting its sensitivity as time goes by. Third, it is usually hard
to determine the usefulness of information. Misleading information must be identiﬁed and
eliminated.
This thesis aims at solving all these three problems with a Hidden Markov Model(HMM)
based forecasting system. The HMM has a Gaussian mixture at each state as the forecast
generator. Gaussian mixtures have desirable features in that they can model series that
does not fall into the single Gaussian distribution. Then the parameters of the HMM are
updated each iteration with an adddrop ExpectationMaximization (EM) algorithm. At
each timing point, the parameters of the Gaussian mixtures, the weight of each Gaussian
component in the output, and the transformation matrix are all updated dynamically to
cater to the nonstationary ﬁnancial time series data.
We then develop a novel exponentially weighted EM algorithm that solves the second
and third diﬃculties at one stroke. The revised EM algorithm gives more weight to the
most recent data while at the same time adjust the weight according to the change in
volatility. The volatility is calculated as the divergence of the S&P Index from the Dow
Jones Composite Index. It is included as new information that help make better judgment.
Longterm and shortterm series balance is then found throughout the combined training
forecast process.
1.7 Contributions of the Thesis
This thesis is an interdisciplinary work that combines computer science and ﬁnancial engineering.
Techniques from the two areas are interweaved. The major contributions are:
CHAPTER 1. INTRODUCTION 10
1. There are few applications of Hidden Markov Model with Gaussian Mixtures in time
dependent sequence data. This is one of the ﬁrst large scale applications to ﬁnancial
time series.
2. We develop a novel dynamic training scheme. The concept of the dynamically updated
training pool enables the system to absorb newest information from data.
3. We develop an exponentially weighted EM algorithm. This algorithm realizes that
recent data should be given more attention and enables us to recognize trend changes
faster than the traditional EM algorithm, especially when training data set is relatively
large.
4. Based on the exponentially weighted EM algorithm, we propose a double weighed
EM algorithm. The double weighted EM algorithm solves the drawback of the single
exponentially weighted EM caused by oversensitivity.
5. We show the weighted EM algorithms can be written in a form of Exponentially
Moving Averages of the model variables of the HMM. This allows us to take the
advantage of this existing econometrics technique in generating the EMbased re
estimation equations.
6. Using the techniques from the EM Theorem, we prove that the convergence of the two
proposed algorithms is guaranteed.
7. Experimental results show our model consistently outperform the index fund in returns
over ﬁve 400day testing periods from 1994 to 2002.
8. The proposed model also consistently outperforms toplisted S&P 500 mutual funds
on the Sharpe Ratio.
1.8 Thesis Organization
Chapter 2 of this thesis introduces general form of HMMs. Chapter 3 describes an HMM
with Gaussian mixtures for the observation probability density functions and derives the
parameter reestimation formulas based on the classic EM algorithm. Then in chapter 5,
some detailed aspects of the HMM are studied, including multiple observation sequence
and multivariate Gaussian mixtures as pdfs. We also derive our revised exponentially
CHAPTER 1. INTRODUCTION 11
weighted EM algorithm and the new parameter updating rules in this chapter. Chapter 6
shows the experimental results and concludes the thesis. Future work that indicate possible
improvements of the model are also included in chapter 6.
1.9 Notation
We list the Roman and Greek letters used in this thesis for reference. These symbols are
used in the derivations of the reestimation formulas and proof in chapters 2, 3 and 4.
CHAPTER 1. INTRODUCTION 12
Symbol Notation
s
t
The state at time t
π
i
Probability of being at state i at time 0
a
ij
Probability of moving from state i to state j
b
j
(o
t
) Probability of being at state j and observing o
t
w
jk
Mixture weight for the k
th
component at state j
O The observation sequence
o
t
The t
th
observation
α
i
(t) Forward variable in HMM
β
i
(t) Backward variable in HMM
p
t
(i, j) Prob. of being at state i at time t, and state j at t + 1
γ
i
(t) Prob. of being at state i at time t
δ
i
(t) Prob. of the best sequence ending in state j at time t
δ
im
(t) Prob. of the best sequence ending at the m
th
component
of the i
th
state
ψ
t
The node of the incoming arc that lead to the best path
X Observed data
Y Hidden part governed by a stochastic process
Z Complete data set
η Exponential weight imposed on intermediate variables in EM
ζ Selfadjustable weight in double weighted EM
ρ The multiplier in calculating EMA
δ
im
(T) The EMA of δ
im
at time T
δ
i
(T) The EMA of δ
i
at time T
θ
j
Parameters of the j
th
component in a Gaussian mixture
Θ Parameters of a Gaussian mixture
L The likelihood function
Table 1.2: Notation list
Chapter 2
Hidden Markov Models
This chapters describes the general Markov process and Hidden Markov Models (HMMs).
We start by introducing the properties of the Markov process, then the characteristics of
the HMMs. [RJ86] and [Rab89] provide a thorough introduction to the Markov process,
Hidden Markov Models and the main problems involved with Hidden Markov Models. These
discussions form the base of our modeling and experiments with ﬁnancial time series data.
2.1 Markov Models
Markov models are used to train and recognize sequential data, such as speech utterances,
temperature variations, biological sequences, and other sequence data. In a Markov model,
each observation in the data sequence depends on previous elements in the sequence. Consider
a system where there are a set of distinct states, S = {1, 2, . . . , N}. At each discrete time
slot t, the system takes a move to one of the states according to a set of state transition
probabilities P. We denote the state at time t as s
t
.
In many cases, the prediction of the next state and its associated observation only
depends on the current state, meaning that the state transition probabilities do not depend
on the whole history of the past process. This is called a ﬁrst order Markov process. For
example, knowing the number of students admitted this year might be adequate to predict
next year’s admission. There is no need to look into the admission rate of the previous
13
CHAPTER 2. HIDDEN MARKOV MODELS 14
years. These are the Markov properties described in [MS99]:
P(X
t+1
= s
k
X
1
, . . . , X
t
) = P(X
t+1
= s
k
X
t
) (Limited horizon) (2.1)
= P(X
2
= s
k
X
1
) (Time invariant) (2.2)
Because of the state transition is independent of time, we can have the following state
transition matrix A:
a
ij
= P(X
t+1
= s
j
X
t
= s
i
) (2.3)
a
ij
is a probability, hence:
a
ij
≥ 0, ∀i, jΣ
N
j=1
a
ij
= 1. (2.4)
Also we need to know the probability to start from a certain state, the initial state
distribution:
π
i
= P(X
1
= s
i
) (2.5)
Here, Σ
N
i=1
π
i
= 1.
In a visible Markov model, the states from which the observations are produced and the
probabilistic functions are known so we can regard the state sequence as the output.
2.2 A Markov chain of stock market movement
In this section we use a Markov chain to represent stock movement. We present a ﬁve state
model to model the movement of a certain stock(See Figure 2.1).
In the ﬁgure, nodes 1, 2, 3, 4, 5 represent a possible movement vector {large rise, small
rise, no change, small drop, large drop}.
From the model in ﬁgure we are able to answer some interesting questions about how
this stock behaves over time. For example: What is the probability of seeing “small drop,
no change, small rise, no change, no change, large rise” in six consecutive days?
First we can deﬁne the state sequence as X = {1, 2, 3, 2, 2, 4}. Given the Markov chain,
the probability of seeing the above sequence, P(XA, π), can be calculated as:
P(XA, π) = P(1, 2, 3, 2, 2, 4A, π) (2.6)
= P(1)P(21)P(32)P(23)P(22)P(42) (2.7)
= π ∗ a
12
∗ a
23
∗ a
32
∗ a
22
∗ a
24
(2.8)
CHAPTER 2. HIDDEN MARKOV MODELS 15
0
uc/0.400
1
ld/0.100
2
sd/0.200
3
sr/0.200
4
lr/0.100
ld/0.100
sd/0.200
uc/0.400
sr/0.200
lr/0.100
sr/0.200
uc/0.400
lr/0.100
sd/0.200
ld/0.100
ld/0.100
sr/0.200
sd/0.200
uc/0.400
lr/0.100
uc/0.400
sd/0.200
sr/0.200
lr/0.100
ld/0.100
Figure 2.1: Modeling the possible movement directions of a stock as a Markov chain. Each of the
nodes in the graph represent a move. As time goes by, the model moves from one state to another,
just as the stock price ﬂuctuates everyday.
CHAPTER 2. HIDDEN MARKOV MODELS 16
More generally, the probability of a state sequence X
1
, . . . , X
T
can be calculated as the
product of the transition probabilities:
P(XA, π) = P(X
1
)P(X
2
X
1
)P(X
3
X
1
, X
2
) · · · P(X
T
X
1
, . . . , X
T−1
) (2.9)
= P(X
1
)P(X
2
X
1
)P(X
3
X
2
) · · · P(X
T
X
T−1
) (2.10)
=
T−1
t=1
πX
t
X
t+1
(2.11)
2.3 Hidden Markov Models
The Markov model described in the previous section has limited power in many applications.
Therefore we extend it to a model with greater representation power, the Hidden Markov
Model (HMM). In an HMM, one does not know anything about what generates the observation
sequence. The number of states, the transition probabilities, and from which state an
observation is generated are all unknown.
Instead of combining each state with a deterministic output(such as large rise, small
drop, etc), each state of the HMM is associated with a probabilistic function. At time t,
an observation o
t
is generated by a probabilistic function b
j
(o
t
), which is associated with
state j, with the probability:
b
j
(o
t
) = P(o
t
X
t
= j) (2.12)
Figure 2.2 shows the example of an HMM that models an investment professional’s
prediction about the market based on a set of investment strategies. Assume the professional
has ﬁve investment strategies, each of them gives a distinctive prediction about the market
movement (large drop, small drop, no change, small rise, and large rise) on a certain day.
Also assume he performs market prediction everyday with only one strategy.
Now how does the professional make his prediction? What is the probability of seeing
the prediction sequence {small drop, small rise} if the prediction starts by taking strategy
2 on the ﬁrst day?
To answer the ﬁrst question, think of HMM as a ﬁnancial expert. Each of the ﬁve
strategies is a state in the HMM. The movement set has all the movement symbols and each
symbol is associated with one state. Each strategy has a diﬀerent probability distribution for
all the movement symbols. Each state is connected to all the other states with a transition
probability distribution, see Figure 2.3 and Table 2.1.
CHAPTER 2. HIDDEN MARKOV MODELS 17
Strategy 4 Strategy 3 Strategy 5 Strategy 2 Strategy 1
LR
SR
UC
SD
LD
10% 15% 5%
15%
20%
40%
5%
30%
30%
15%
10%
5%
20%
40%
30%
40%
30%
20%
5%
5%
20%
20%
20%
20%
20%
Figure 2.2: The ﬁgure shows the set of strategies that a ﬁnancial professional can take. The
strategies are modeled as states. Each strategy is associated with a probability of generating the
possible stock price movement. These probabilities are hidden to the public, only the professional
himself knows it.
Unlike the Markov chain of the previous section, the HMM will pick a particular strategy
to follow one that was taken based also on the observation probability. The key to the HMM
performance is that it can pick the best overall sequence of strategies based on an observation
sequence. Introducing density functions at the states of the HMM gives more representation
power than ﬁxed strategies associated with the states.
Strategy 1
Strategy 2
Strategy 3
Strategy 4
Strategy 2
Strategy 1 Strategy 1
Strategy 2
Strategy 3
Strategy 4
Strategy 5
Strategy 3
Strategy 4
Strategy 5 Strategy 5
Day1 Day2 Day3
Figure 2.3: The trellis of the HMM. The states are associated with diﬀerent strategies and are
connected to each other. Each state produces an observation picked from the vector [LR, SR, UC,
SD, LD].
The steps for generating the prediction sequence:
CHAPTER 2. HIDDEN MARKOV MODELS 18
Probability Strategy1 Strategy2 Strategy3 Strategy4 Strategy5
Strategy1 10% 10% 20% 30% 30%
Strategy2 10% 20% 30% 20% 20%
Strategy3 20% 30% 10% 20% 20%
Strategy4 30% 20% 20% 15% 15%
Strategy5 30% 20% 20% 15% 15%
Table 2.1: State transition probability matrix of the HMM for stock price forecast. As the market
move from one day to another, the professional might change his strategy without letting others
know
1. Choose an initial state(i.e. a strategy) X
1
= i according to the initial state distribution
Π.
2. Set the time step t = 1, since we are at the ﬁrst day of the sequence.
3. Get the prediction according to the strategy of the current state i, i.e. b
ij
(o
t
). Then
we get the prediction for the current day. For example, the probability of seeing a
large rise prediction on the ﬁrst day if we take strategy 2 is 15
4. Transit to a new state X
t+1
, according to the state transition probability distribution.
5. Set t=t+1, go to step 3, if t ≤ T, otherwise terminate.
To answer the second question, sum up all the probabilities the movement sequence may
happen, through diﬀerent state sequences. We know the prediction starts with strategy 2,
which means the initial state is state 2. Then there are ﬁve possible states for the second
day. So the probability of seeing the movement sequence {small drop, small rise} is:
0.15 + 0.1 ×0.4 + 0.2 ×0.3 + 0.3 ×0.05 + 0.2 ×0.3 + 0.2 ×0.2 = 0.365
2.4 Why HMM?
From the previous example, we can see that there is a good match of sequential data analysis
and the HMM. Especially in the case of ﬁnancial time series analysis and prediction, where
the data can be thought of being generated by some underlying stochastic process that is
not known to the public. Just like in the above example, if the professional’s strategies and
CHAPTER 2. HIDDEN MARKOV MODELS 19
the number of his strategies are unknown, we can take the imaginary professional as the
underlying power that drives the ﬁnancial market up and down. As shown in the example
we can see the HMM has more representative power than the Markov chain. The transition
probabilities as well as the observation generation probability density function are both
adjustable.
In fact, what drives the ﬁnancial market and what pattern ﬁnancial time series follows
have long been the interest that attracts economists, mathematicians and most recently
computer scientists. See [ADB98].
Besides the match between the properties of the HMM and the time series data, the
Expectation Maximization(EM) algorithm provides an eﬃcient class of training methods
[BP66]. Given plenty of data that are generated by some hidden power, we can create an
HMM architecture and the EM algorithm allows us to ﬁnd out the best model parameters
that account for the observed training data.
The general HMM approach framework is an unsupervised learning technique which
allows new patterns to be found. It can handle variable lengths of input sequences, without
having to impose a “template” to learn. We show a revised EM algorithm in later chapters
that gives more weight to recent training data yet also trying to balance the conﬂicting
requirements of sensitivity and accuracy.
HMMs have been applied to many areas. They are widely used in speech recognition
[Rab89][Cha93], bioinformatics [PBM94], and diﬀerent time series analysis, such as weather
data, semiconductor malfunction [GS00][HG94],etc. Weigend and Shi [SW97] have previously
applied HMMs to ﬁnancial time series analysis. We compare our approach to theirs in
Chapter 5.
2.5 General form of an HMM
An HMM is composed of a ﬁvetuple: (S, K, Π, A, B).
1. S = {1, . . . , N} is the set of states. The state at time t is denoted s
t
.
2. K = {k
1
, . . . , k
M
} is the output alphabet. In a discrete observation density case, M
is the number of observation choices. In the above example, M equals the number of
possible movements.
CHAPTER 2. HIDDEN MARKOV MODELS 20
3. Initial state distribution Π = {π
i
}, i ∈ S. π
i
is deﬁned as
π
i
= P(s
1
= i) (2.13)
4. State transition probability distribution A = {a
ij
}, i, j ∈ S.
a
ij
= P(s
t+1
s
t
), 1 ≤ i, j ≤ N (2.14)
5. Observation symbol probability distribution B = b
j
(o
t
). The probabilistic function
for each state j is:
b
j
(o
t
) = P(o
t
s
t
= j) (2.15)
After modeling a problem as an HMM, and assuming that some set of data was generated
by the HMM, we are able to calculate the probabilities of the observation sequence and the
probable underlying state sequences. Also we can train the model parameters based on the
observed data and get a more accurate model. Then use the trained model to predict unseen
data.
2.6 Discrete and continuous observation probability distribution
2.6.1 Discrete observation probability distribution
There are ﬁxed number of possible observations in the example in section 2.3. The function
at each state is called a discrete probability density function. In ﬁnancial time series analysis,
we sometimes need to partition probability density function of observations into discrete set
of symbols v
1
, v
2
, . . . , v
M
. For example, we might want to model the direction of the price
movement as a ﬁveelement vector {large drop, small drop,no change, small rise, large rise}.
This partitioning process is called vector quantization. [Fur01] provides a survey on some of
the most commonly used vector quantization algorithms.
After the vector quantization, a codebook is created and the following analysis and
prediction are with the domain of the codebook. In the previous example, the observation
symbol probability density function will be in the form:
b
j
(o
t
) = P(o
t
= ks
t
= j), 1 ≤ k ≤ M (2.16)
CHAPTER 2. HIDDEN MARKOV MODELS 21
Using discrete probability distribution functions greatly simpliﬁes modeling of the problem.
However they have limited representation power. To solve this problem, the continuous
probability distribution functions are used during the training phase, enabling us to get as
accurate a model as possible. Then in the prediction step, the codebook is used to estimate
the probability of each possible symbol and produce the most probable one.
2.6.2 Continuous observation probability distribution
In a continuous observation probability HMM, the function b
j
(o
t
) is in the form of a
continuous probability density function(pdf) or a mixture of continuous pdfs:
b
j
(o
t
) =
M
k=1
w
jk
b
jk
(o
t
), j = 1, . . . , N (2.17)
M is the number of the mixtures and w is the weight for each mixture. The mixture
weights have the following constraints:
M
k=1
w
jk
= 1, j = 1, . . . , N; w
jk
≥ 0, j = 1, . . . , N; k = 1, . . . , M (2.18)
Each b
jk
(o
t
)is a Ddimensional logconcave or elliptically symmetric density with mean
vector µ
jk
and covariance matrix Σ
jk
:
b
j
k(o
t
) = N(o
t
, µ
jk
, Σ
jk
) (2.19)
Then the task for training is to learn the parameters of these pdfs. For details in mixtures
of Gaussian distributions, please refer to [Mit97] and [MS99].
This Ddimensional multivariate time series training requires that we pick the most
correlated time series as input. For example, in order to predict the price of IBM, it will
make more sense to include the prices of Microsoft, Sun and other high tech stocks rather
than include Exxon or McDonald’s, whose behavior have less correlation with that of IBM.
An automatic method for dimension reduction is Principal Component Analysis(PCA). The
dimension of the multivariate time series cannot be too large as it increases computation
complexity by quadratic factor, we will need to ﬁnd out the most correlated factors to our
prediction. We will describe more about this subject in Chapter 3.
Another problem is the selection of the pdf for each mixture. The most used D
dimensional logconcave or elliptically symmetric density is the Gaussian density, or Normal
Distribution.
CHAPTER 2. HIDDEN MARKOV MODELS 22
The single Gaussian density function has the form:
b
jk
(o
t
) = N(o
t
, µ
jk
, Σ
jk
) =
1
√
2πσ
exp
_
−
(x −µ)
2
2σ
2
_
(2.20)
where o
t
is a real value.
The multivariate Gaussian density is in the form:
b
jk
(o
t
) = N(o
t
, µ
jk
, Σ
jk
) =
1
(2π)
D/2
Σ
jk

1/2
exp
_
−
1
2
(o
t
−µ
jk
)
T
Σ
−1
jk
(o
t
−µ
jk
)
_
(2.21)
where o
t
is a vector.
2.7 Three Fundamental Problems for HMMs
There are three fundamental problems about the HMM that are of particular interest to us:
1. Given a model µ = (A, B, Π), and an observation sequence O = (o
1
, . . . , o
T
), how do
we eﬃciently compute the probability of the observation sequence given the model?
i.e., what is P(Oµ)?
2. Given a model µ and the observation sequence O, what is the underlying state
sequence(1, . . . , N) that best “explains” the observations?
3. Given an observation sequence O, and a space of possible models, how do we adjust
the parameters so as to ﬁnd the model µ that maximizes P(Oµ)?
The ﬁrst problem can be used to determine which of the trained models is most likely
when the training observation sequence is given. In the ﬁnancial time series case, given the
past history of the price or index movements, which model best accounts for the movement
history. The second problem is about ﬁnding out the hidden path. In our previous example
in section 2.3, what is the strategy sequence the ﬁnancial professional applied on each trading
day? The third problem is of the most signiﬁcant interest because it deals with the training
of the model. In the reallife ﬁnancial times series analysis case, it is about training the
model with the past historical data. Only after training can we use the model to perform
further predictions.
CHAPTER 2. HIDDEN MARKOV MODELS 23
2.7.1 Problem 1: ﬁnding the probability of an observation
Given an observation sequence O = (o
1
, . . . , o
T
) and an HMM µ = (A, B, Π), we want to
ﬁnd out the probability of the sequence P(Oµ). This process is also known as decoding.
Since the observations are independent of each other the time t, the probability of a state
sequence S = (s
1
, . . . , s
T
) generating the observation sequence can be calculated as:
P(OS, µ) =
T
t=1
P(o
t
s
t
, s
t+1
, µ) (2.22)
= b
s
1
(o
1
) · · · b
s
1
s
2
(o
2
) · · · b
s
T−1
s
T
(o
T
) (2.23)
and the state transition probability,
P(Sµ) = π
s
1
· a
s
1
s
2
· a
s
2
s
3
· · · a
s
T−1
s
T
. (2.24)
The joint probability of O and S:
P(O, Sµ) = P(OS, µ)P(Sµ) (2.25)
Therefore,
P(Oµ) =
S
P(OS, µ)P(Sµ) (2.26)
=
s
1
···s
T+1
π
s
1
T
t=1
a
sts
t+1
b
sts
t+1
ot
(2.27)
The computation is quite straightforward by summing the observation probabilities for
each of the possible state sequence. A major problem with this approach is enumerating each
state sequence is ineﬃciency. As the length of T of the sequence grows, the computation
grows exponentially. It requires (2T −1) · N
T+1
multiplications and N
T
−1 additions.
To solve this problem, an eﬃcient algorithm–the forward backward algorithm was developed
that cuts the computational complexity to linear in T.
The forward procedure
The forward variable α
i
(t) is deﬁned as:
α
i
(t) = P(o
1
o
2
· · · o
t−1
, s
t
= iµ) (2.28)
CHAPTER 2. HIDDEN MARKOV MODELS 24
α(t) stores the total probability of ending up in state s
i
at time t, given the observation
sequence o
1
· · · o
t−1
. It is calculated by summing probabilities for all incoming arcs at a
trellis node. The forward variable at each time t can be calculated inductively, see Figure
2.4.
t−1 t t+1
State
Time
s1
s2
s3
s n
Figure 2.4: The forward procedure
1. Initialization
α
i
(1) = π
i
, 1 ≤ i ≤ N (2.29)
2. Induction
α
j
(t + 1) =
N
i=1
α
i
(t)a
ij
b
ijot
, 1 ≤ t ≤ T, 1 ≤ j ≤ N (2.30)
CHAPTER 2. HIDDEN MARKOV MODELS 25
3. Update time Set t = t + 1; Return to step 2 if t < T;
Otherwise, terminate algorithm
4. Termination
P(Oµ) =
N
i=1
α
i
(T) (2.31)
The forward algorithm requires N(N+1)(T −1)+N multiplications and N(N−1)(T −1)
additions. The complexity is O(TN
2
).
The backward procedure
The induction computation for the forward procedure can also be performed in the
reverse order. The backward procedure calculates the probability of the partial observation
sequence from t + 1 to the end, given the model µ and state s
i
at time t. The backward
variable β
i
(t) is deﬁned as:
β
i
(t) = P(o
t+1
o
t+2
· · · o
T
s
t
= i, µ) (2.32)
The backward algorithm works from right to left on through the same trellis:
1. Initialization
β
i
(T) = 1, 1 ≤ i ≤ N (2.33)
2. Induction
β
i
(t) =
N
j=1
a
ij
b
ijot
β
j
(t + 1), 1 ≤ t ≤ T, 1 ≤ i ≤ N (2.34)
3. Update time
Set t = t −1; Return to step 2 if t > 0; Otherwise terminate algorithm.
4. Total
P(Oµ) =
N
i=1
π
i
β
i
(1) (2.35)
CHAPTER 2. HIDDEN MARKOV MODELS 26
t−1 t t+1
State
Time
s1
s2
s3
s n
Figure 2.5: The backward procedure
CHAPTER 2. HIDDEN MARKOV MODELS 27
2.7.2 Problem 2: Finding the best state sequence
The second problem is to ﬁnd the best state sequence given a model and the observation
sequence. This is one a problem often encountered in parsing speech and in pattern
recognition. There are several possible ways to solve this problem. The diﬃculty is that
there may be several possible optimal criteria. One of them is to choose the states that are
individually most likely at each time t. For each time t, 1 ≤ t ≤ T +1, we ﬁnd the following
probability variable:
γ
i
(t) = P(s
t
= iO, µ) (2.36)
=
P(s
t
= i, Oµ)
P(Oµ)
(2.37)
=
α
i
(t)β
i
(t)
N
j=1
α
j
(t)β
j
(t)
(2.38)
The individually most likely state sequence S
can be found as:
S
= argmax
1≤i≤N
γ
i
(t), 1 ≤ t ≤ T + 1, 1 ≤ i ≤ N (2.39)
This quantity maximizes the expected number of correct states. However the approach
may generate an unlikely state sequence. This is because it doesn’t take the state transition
probabilities into consideration. For example, if at some point we have zero transition
probability a
ij
= 0, the optimal state sequence found may be invalid.
Therefore, a more eﬃcient algorithm, the Viterbi algorithm, based on dynamic programming,
is used to ﬁnd the best state sequence.
The Viterbi algorithm
The Viterbi algorithm is designed to ﬁnd the most likely state sequence, S
= (s
1
, s
2
, . . . , s
T
)
given the observation sequence O = (o
1
, o
2
, . . . , o
T
) :
argmax
S
P(S
O, µ)
It is suﬃcient to maximize for a ﬁxed observation sequence O:
argmax
S
P(S
, Oµ)
The following variable:
δ
j
(t) = max
s
1
···s
t−1
P(s
1
· · · s
t−1
, o
1
· · · o
t−1
, s
t
= jµ) (2.40)
CHAPTER 2. HIDDEN MARKOV MODELS 28
This variable stores the probability of observing o
1
o
2
· · · o
t
using the most likely path
that ends in state i at time t, given the model µ. The corresponding variable ψ
j
(t) stores
the node of the incoming arc that leads to this most probable path. The calculation is done
by induction, similar to the forwardbackward algorithm, except that the forwardbackward
algorithm uses summing over previous states while the Viterbi algorithm uses maximization.
The complete Viterbi algorithm is as follows:
1. Initialization
δ
i
(1) = π
i
b
i
(o
1
), 1 ≤ i ≤ N (2.41)
ψ
i
(1) = 0, 1 ≤ i ≤ N (2.42)
2. Induction
δ
j
(t) = b
ijot
max
1≤i≤N
δ
i
(t −1)a
ij
(2.43)
ψ
j
(t) = argmax
1≤i≤N
[δ
i
(t −1)a
ij
] (2.44)
3. Update time
t = t + 1 (2.45)
Return to step 2 if t ≤ T else terminate the algorithm
4. Termination
P
∗
= max
1≤i≤N
[δ
i
(T)] (2.46)
s
∗
T
= argmax
1≤i≤N
[δ
i
(T)] (2.47)
5. Path readout
s
∗
t
= ψ
t+1
(s
∗
t+1
) (2.48)
When there are multiple paths generated by the Viterbi algorithm, we can pick up one
randomly or choose the best n paths. Fig 2.6 shows how the Viterbi algorithm ﬁnds a single
best path.
CHAPTER 2. HIDDEN MARKOV MODELS 29
State
Time
2
3
1 2 3 4
1
Figure 2.6: Finding best path with the Viterbi algorithm
2.7.3 Problem 3: Parameter estimation
The last and most diﬃcult problem about HMMs is that of the parameter estimation. Given
an observation sequence, we want to ﬁnd the model parameters µ = (A, B, π) that best
explains the observation sequence. The problem can be reformulated as ﬁnd the parameters
that maximize the following probability:
argmax
µ
P(Oµ)
There is no known analytic method to choose µ to maximize P(Oµ) but we can use a
local maximization algorithm to ﬁnd the highest probability. This algorithm is called the
BaumWelch. This is a special case of the Expectation Maximization method. It works
iteratively to improve the likelihood of P(Oµ). This iterative process is called the training
of the model. The BaumWelch algorithm is numerically stable with the likelihood non
decreasing of each iteration. It has linear convergence to a local optima.
To work out the optimal model µ = (A, B, π) iteratively, we will need to deﬁne a few
intermediate variables. Deﬁne pt(i, j), 1 ≤ t ≤ T, 1 ≤ i, j ≤ N as follows:
CHAPTER 2. HIDDEN MARKOV MODELS 30
pt(ij) = P(s
t
= i, s
t+1
= jO, µ) (2.49)
=
P(s
t
= i, s
t+1
= j, Oµ)
P(Oµ)
(2.50)
=
α
i
(t)a
ij
b
ijot
β
j
(t + 1)
N
m=1
α
m
(t)β
m
(t)
(2.51)
=
α
i
(t)a
ij
b
ijot
β
j
(t + 1)
N
m=1
N
n=1
α
m
(t)a
mn
b
mnot
β
n
(t + 1)
(2.52)
This is the probability of being at state i at time t, and at state j at time t + 1, given
the model µ and the observation O.
Then deﬁne γ
i
(t). This is the probability of being at state i at time t, given the
observation O and the model µ:
γ
i
(t) = P(s
t
= iO, µ) (2.53)
=
N
j=1
P(s
t
= i, s
t+1
= jO, µ) (2.54)
=
N
j=1
p
t
(i, j) (2.55)
The above equation holds because γ
i
(t) is the expected number of transition from state
i and p
t
(i, j) is the expected number of transitions from state i to j.
Given the above deﬁnitions we begin with an initial model µ and run the training data
O through the current model to estimate the expectations of each model parameter. Then
we can change the model to maximize the values of the paths that are used. By repeating
this process we hope to converge on the optimal values for the model parameters.
CHAPTER 2. HIDDEN MARKOV MODELS 31
The reestimation formulas of the model are:
π
i
= probability of being at state i at time t = 1
= γ
i
(1) (2.56)
a
ij
=
expected number of transitions from state i to j
expected number of transitions from state i
=
T
t=1
p
t
(i, j)
T
t=1
γ
i
(t)
(2.57)
b
ijk
=
expected number of transitions from i to j with k observed
expected number of transitions from i to j
=
t:ot=k,1≤t≤T
p
t
(i, j)
T
t=1
p
t
(i, j)
(2.58)
In the following calculations, we will replace b
ijot
with b
jot
, i.e. each observation is
generated by the probability density function associated with one state at one time step.
This is also called a ﬁrst order HMM.
2.8 Chapter Summary
In this chapter, the general form of the HMM is introduced, both theoretically and with
examples. The conditions that HMMs must observe, i.e. the Markov properties are also
described. Then we studied the three basic problems involved with any HMM. The following
model design and experiments are all extensions based on the basic model and the techniques
to solve the three problems. In fact, in the prediction task, both Viterbi algorithm and the
BaumWelch algorithm are used in combination to make the system work.
Chapter 3
HMM for Financial Time Series
Analysis
In this chapter we construct an HMM based on the discussions in chapter 2. We ﬁrst give
a brief survey of Weigend and Shi’s previous work on the application of Hidden Markov
Experts to ﬁnancial time series prediction [SW97], analyze problems with their approach
and then propose a new model.
We use an HMM with emission density functions modeled as mixtures of Gaussians in
combination with the usual transition probabilities. We introduce Gaussian mixtures which
we have as the continuous observation density function associated with each state. The
reestimation formulas are then derived for the Gaussian Mixtures. We apply an adddrop
approach to the training data.
3.1 Previous Work
In [SW97], Weigend and Shi propose a Hidden Markov Expert Model to forecast the change
of the S&P 500 Index at halfhour time step. The “experts” at each state of the Hidden
Markov Model applied for ﬁnancial time series prediction are three neural networks, with
characteristics and predicting bias distinct from each other. One of the experts is good at
forecasting low volatility data, the second expert is best for high volatility regions, and the
32
CHAPTER 3. HMM FOR FINANCIAL TIME SERIES ANALYSIS 33
third expert is responsible for the “outliers”.
1
The training of the Hidden Markov Experts mainly involves the reestimation of the
transition probability matrix A. Just like we did in equations (2.58) and (2.59). But there
are no reestimations for each of the three “experts”. This means that the experts are ﬁxed
and we must trust them during the whole prediction process because there is no way of
improving their accuracy of prediction. This is problematic because even if we can divide
a long time series into several segments with diﬀerent volatilities, segments with similar
volatilities may not necessarily reﬂect similar pattern. In the later sections of this chapter
we will introduce the Gaussian mixtures where all parameters of each mixture component,
the counterpart of the “expert”, are adjustable.
Then in the prediction phase, a training pool is created. This pool keeps updating by
adding the last available data and eliminating the ﬁrst data in the pool. The data in each
pool is then trained together to generate the prediction for the next coming day. In this
approach, data at each time step are of equal importance. This can cause big problems
during highly volatile period or at the turning point of long term trends. Too much weight
is given to the early samples. We will solve this problem with an adjustable weighted EM
algorithm in chapter 4.
Another problem with Shi and Weigend’s model is the lack of additional information to
help prediction decisions. Their model takes the destination time series as the only input
time series. By providing more available information, such as similar time series or indicator
series derived from the original series, we can make the model more reliable. In section 3.3
we introduce the multivariate Gaussian mixtures that take a vector composed of the Dow
Jones Composite Index and the S&P 500 Index as input. Without having to worry about
the exactly mathematical relationship between these two series, we let the HMM combine
them together to make predictions for the S&P 500 Index. Then in chapter 4, the Dow
Jones Index is used as an error controller. When the system prediction of the S&P 500
doesn’t coincide with the Dow, we will give less conﬁdence in the HMM. This is because
the Dow is a less volatile index than the S&P 500. By comparing the movement prediction
of the S&P 500 with the Dow, we can balance between long term trend and short
2
term
1
Outliers are a few observations that are not well ﬁtted by the “best” available model. Refer to appendix
I for more explanation.
2
To short means to sell something that you don’t have. To do this, you have to borrow the asset that
you want to short.
CHAPTER 3. HMM FOR FINANCIAL TIME SERIES ANALYSIS 34
whipsaws.
3
3.2 BaumWelch Reestimation for Gaussian mixtures
The reestimation formulas in the previous chapter have mainly focused on the case where
the symbol emission probabilities are discrete, in other words, the emitted symbols are
discrete symbols from a ﬁnite alphabet list. Although as mentioned before, we can use
the vector quantization technique to map each continuous value into a discrete value via
the codebook, there might be serious degradation after the quantization. Therefore it is
advantageous to use HMMs with continuous observation densities.
The most generally used form of the continuous probability density function(pdf) is the
Gaussian mixture in the form of:
b
im
(o
t
) =
M
m=1
w
im
N(o
t
, µ
im
, Σ
im
) (3.1)
o
t
is the observed vector, w
im
is the weight of the mth Gaussian mixture at state i. The
mixture weights w must satisfy the following constraints:
M
m=1
w
im
= 1, 1 ≤ i ≤ N (3.2)
w
im
≥ 0, 1 ≤ i ≤ N, 1 ≤ m ≤ M
N(O, µ
im
, Σ
im
) is a multivariate Gaussian distribution with mean vector µ
and covariance
matrix Σ
:
N(O, µ
im
, Σ
im
) =
1
_
(2π)
n
Σ

exp
_
−
1
2
(o −µ
)Σ
−1
(o −µ
)
_
(3.3)
The learning of the parameters of the HMMs thus becomes learning of the means and
variances of each Gaussian mixture component. The intermediate variable δ is redeﬁned as:
δ
i
(t) =
M
m=1
δ
im
(t) =
M
m=1
1
P
α
j
(t −1)a
ji
w
im
b
im
(o
t
)β
i
(t) (3.4)
As previously deﬁned M is the total number of Gaussian mixture components at state
i and N is the total number of states. The diﬀerence with the previous example is that
3
A whipsaw occurs when a buy or sell signal is reversed in a short time. Volatile markets and sensitive
indicators can cause whipsaws
CHAPTER 3. HMM FOR FINANCIAL TIME SERIES ANALYSIS 35
0
0.05
0.1
0.15
0.2
0.25
0.3
0.35
0.4
0 5 10 15 20 25
G1: 20%
G2: 30%
G3: 50%
Figure 3.1: Three single Gaussian density functions. Each of them will contributing a percentage
to the combined output in the mixture.
CHAPTER 3. HMM FOR FINANCIAL TIME SERIES ANALYSIS 36
0
0.02
0.04
0.06
0.08
0.1
0.12
0.14
0.16
0 5 10 15 20 25
mixture of the three Gaussians
Figure 3.2: A Gaussian mixture derived from the three Gaussian densities above. For each small
area δ close to each point x on the x axis, there is a probability of 20% that the random variable x
is governed by the ﬁrst Gaussian density function, 30% of probability that the distribution of x is
governed by the second Gaussian, and 50% of probability by the third Gaussian.
CHAPTER 3. HMM FOR FINANCIAL TIME SERIES ANALYSIS 37
rather than associating each state with one probability density function, each observation
is generated by a set of Gaussian mixtures, with each mixture component contributing to
the overall result by some weight.
Then we also need a variable that denotes the probability of being at state j at time t
with the kth mixture component that accounts for the current observation o
t
:
γ
j,k
(t) =
α
j
(t)β
j
(t)
N
j=1
α
j
(t)β
j
(t)
·
w
jk
N(o
t
, µ
jk
, Σ
jk
)
M
k=1
w
jk
N(o
t
, µ
jk
, Σ
jk
)
(3.5)
With the new intermediate variable δ deﬁned, we are able to derive the reestimation
formulas below:
µ
im
=
T
t=1
δ
im
(t)o
t
T
t=1
δ
im
(t)
(3.6)
σ
im
=
T
t=1
δ
im
(t)(o
t
−µ
im
)(o
t
−µ
im
)
T
t=1
δ
im
(t)
(3.7)
w
im
=
T
t=1
δ
im
(t)
T
t=1
δ
i
(t)
(3.8)
a
ij
=
T
t=1
α
i
(t)a
ij
b
j
(o
t+1
)β
j
(t + 1)
T
t=1
α
i
(t)β
i
(t)
(3.9)
3.3 Multivariate Gaussian Mixture as Observation Density
Function
Sometimes we have observation vectors that have more than one element. In other words the
observed data are generated by several distinct underlying causes that have some unknown
relationship between them. Each cause contributes independently to the generation process
but we can only see the observation sequence as a ﬁnal mixture, without knowing how much
and in what way each cause contributes to the resulted observation sequence.
This phenomenon is of great interest in ﬁnancial time series analysis. Many time series
could be correlated with other time series. For example in stock market, the volume by itself
is of little interest, but it will contain plenty of information about the trend of the market
when combined with close price. Canada’s stock market is aﬀected by the US economy
circle because Canada is the largest trading partner of US. As such the factors that aﬀect
CHAPTER 3. HMM FOR FINANCIAL TIME SERIES ANALYSIS 38
US stock market also have an impact on the Canadian market. Researchers have found that
the best Canadian year is the third year of the US president election cycle.
Some day traders have used a technique called “pairedtrading”. They trade two stocks
with similar characteristics at the same time, aiming at proﬁting from arbitrage opportunities
or averse possible risks. If they buy the stocks of WalMart, they will short the stocks of
Kmart. These examples show that there is a need for including relevant information beyond
the time series that we are studying.
3.3.1 Multivariate Gaussian distributions
The multivariate mdimensional Gaussian has the same parameters as the single normal
distribution, except that the mean is in the form of a vector µ and the covariance is in the
form of a m× m covariance matrix Σ
j
. The probability density function for a Gaussian is
given by:
n
j
(x, m
j
, Σ
j
) =
1
_
(2π)
m
Σ
j

exp
_
−
1
2
(x − µ
j
)
T
Σ
−1
j
(x − µ
j
)
_
(3.10)
At each state, we assume the observation is generated by k Gaussians, so the overall
output is:
k
j=1
w
j
N(x, µ
j
, Σ
j
) (3.11)
The initial value of the weights w
j
for each mixture component should sum up to 1.
The training process then becomes a process of ﬁnd the parameters that maximizes the
probability of this output observation.
3.3.2 EM for multivariate Gaussian mixtures
We now develop the EM algorithm for reestimating the parameters of the multivariate
Gaussian mixture. Let θ
j
= ( µ
j
, Σ
j
, π
j
) be the jth mixture component, then the parameters
of the model are deﬁned as Θ = (θ
1
, . . . , θ
k
)
T
. Also deﬁne a hidden variable E[z
ij
] as the
probability of generating the ith observation with the jth mixture. The EM algorithm that
ﬁnds the parameters that maximize the probability of the observation sequence O consists
of the following two steps (we use a mixture of two θ
1
, θ
2
to explain the algorithm):
CHAPTER 3. HMM FOR FINANCIAL TIME SERIES ANALYSIS 39
Estimation step:
Calculate the expected value E[z
ij
] of each hidden variable z
ij
, given that we know the
current values of Θ = (θ
1
, θ
2
).
Maximization step:
Calculate a new maximum likelihood value of Θ
= (θ
1
, θ
2
), assuming the value taken on by
each hidden variable z
ij
is the expected value in the ﬁrst step.
In the HMM context, the probability of the hidden variable z
ij
is the intermediate
variable γ
ij
(t) we talked about in 3.2. Combining the EM algorithm for multivariate
Gaussian mixtures and the EM algorithm for HMMs, we develop the following formulas
for each of the parameters of the HMM with multivariate Gaussian mixtures as observation
density function:
µ
im
=
T
t=1
δim(t) o
t
T
t=1
δ
im
(t)
(3.12)
Σ
j
=
T
t=1
δ
im
(t)( o
i
−
µ
j
)( o
i
−
µ
j
)
T
T
t=1
δ
im
(t)
(3.13)
w
im
=
T
t=1
δ
im
(t)
T
t=1
δ
i
(t)
(3.14)
a
ij
=
T
t=1
α
i
(t)a
ij
b
j
(o
t+1
)β
j
(t + 1)
T
t=1
α
i
(t)β
i
(t)
(3.15)
3.4 Multiple Observation Sequences
In the previous discussions, the EM algorithm is applied to a single observation sequence O.
However, the reallife ﬁnancial time series data can have a very long range. Modeling them
as one single observation sequence might give low recognition rate when testing data from
some speciﬁc period of time. This is because the pattern or trend at some point of time
may be quite diﬀerent to that of the overall pattern. As stated by Graham [Gra86]: “There
is no generally known method of chart reading that has been continuously successful for a
long period of time. If it were known, it would be speedily adopted by numberless traders.
This very following would bring its usefulness to an end.”
Rabiner oﬀers a way to solve the similar kind of problem in speech recognition by splitting
CHAPTER 3. HMM FOR FINANCIAL TIME SERIES ANALYSIS 40
the original observation sequence O into a set of k short sequences [Rab89]:
O = [O
(1)
, O
(2)
, . . . , O
(k)
] (3.16)
where O
(k)
= [O
(k)
1
, O
(k)
2
, . . . , O
(k)
T
k
] is the kth observation sequence and T
k
is the kth
observation sequence length. Assume that each observation sequence is independent of each
other, the probability function P(Oµ) to maximize now becomes:
P(Oµ) =
K
k=1
P(O
(k)
µ) (3.17)
The variables α
i
(t), β
i
(t), p
t
(i, j) and δ
i
(t) are calculated for each training sequence O
(k)
.
Then the reestimation formulas are modiﬁed by adding together all the probabilities for
each sequence. In this way the new parameters can be vowed as averages of the optima given
by the individual training sequences. The reestimation formulas for multiple observation
sequences are:
µ
im
=
K
k=1
1
P
k
Tr
t=1
δ
(k)
im
(t)o
(k)
t
K
k=1
1
P
k
Tr
t=1
δ
(k)
im
(t)
(3.18)
σ
im
=
K
k=1
1
P
k
Tr
t=1
δ
(k)
im
(t)(o
(k)
t
−µ
im
)(o
(k)
t
−µ
im
)
K
k=1
1
P
k
Tr
t=1
δ
(k)
im
(t)
(3.19)
w
im
=
K
k=1
1
P
k
Tr
t=1
δ
(k)
i
(t)
K
k=1
1
P
k
Tr
t=1
M
m=1
δ
(k)
im
(t)
(3.20)
a
ij
=
K
k=1
1
P
k
Tr−1
t=1
α
(k)
i
(t)a
ij
b
j
(o
(k)
t+1
)β
(k)
j
(t + 1)
K
k=1
1
P
k
Tr−1
t=1
α
(k)
i
(t)β
(k)
i
(t)
(3.21)
Rabiner’s algorithm is used to process a batch of speech sequences that are of equal
importance, so he includes all the training sequences in the training process. In our ﬁnancial
time series, often cases are that patterns change from time to time. In order to capture the
most recent trend, we create a dynamic training pool. The ﬁrst data in the pool are popped
out and new data are pushed into it when a trading day ends. Each time the training starts
from the parameters of last day’s trading yet with today’s data.
CHAPTER 3. HMM FOR FINANCIAL TIME SERIES ANALYSIS 41
Figure 3.3: The dynamic training pool
3.5 Dynamic Training Pool
We introduce a new concept in the training process called the training pool. This is a
segment of data that is updated dynamically throughout the training. At the end of a
trading day, when the market closes, we can calculate the return for that day and add it to
the pool. In the meantime, drop the oldest data in the pool. The training is then performed
again based on the parameters from last training and the data from the new pool. This
way the system always trains on fresh data. In the training pool each data sample serves
as both prediction target and training sample. See ﬁgure 3.3 for a graphical illustration of
the dynamic training pool.
CHAPTER 3. HMM FOR FINANCIAL TIME SERIES ANALYSIS 42
3.6 Making Predictions with HMM
3.6.1 Setup of HMM Parameters
We construct a HMM with Gaussian Mixtures as observation density function(call it HMGM).
The HMM has 5 states. Each state is associated with a Gaussian mixture that has 4
Gaussian probability distributions. The HMM is a fully connected trellis, each of the
transition probability is assigned a real value at random between 0 and 0.2. The initial
state probability distribution probabilities Π = {π
i
} are assigned a set of random values
between 0 and 0.2. And there are a set of random values ranging between 0 and 0.25 for
the initial mixture weights w. The initial values of the covariance for each of the Gaussian
probability distribution function is assigned 1. And the mean of each Gaussian mixture
component is assigned a real value between 0.3 and 0.3. This is the normal range of
possible returns for each day.
Intuitively, the number of states is the number of the strategies we have to make
predictions. This number should be neither too large nor too small. Too many strategies
will make little distinction between each other and will increase the cost of computing.
On the other hand if the number of states is too small, risk of misclassiﬁcation will
increase. This can also be explained intuitively using ﬁnancial theory: the more diversiﬁed
the strategies, the less investment risk and the less return. The number of the mixture
components follow the same discussion. We have launched experiments with diﬀerent state
and mixture numbers. Based on our experience, 5 states and 4 mixture components are
reasonable numbers for the model. The architecture of the HMGM is shown in Fig 3.4.
This setting is similar to Shi and Weigend’s experimental environment where they have
one neural net expert associated with each of the three states. See [WMS95] and [SW97].
The optimal number of states can be decided through experiments.
The input into the HMGM is the real number vector introduced in section 1.3. In the
following section we will describe how the real number is transformed into long or short
signals.
3.6.2 Making predictions
We now come to the core part of the problem: making predictions before each trading day
starts. Actually the prediction process is carried out together with the training at the same
CHAPTER 3. HMM FOR FINANCIAL TIME SERIES ANALYSIS 43
G
1
G
2
G
3
G
4
State
Time
s1
s2
s3
s4
s5
Mixtures
Figure 3.4: Hidden Markov Gaussian Mixtures
CHAPTER 3. HMM FOR FINANCIAL TIME SERIES ANALYSIS 44
time. In other words, at the end of each trading day, when the market return of that day
is known to the public, we include it in the training system to absorb the most updated
information. This is exactly what human analysts and professional traders do. Many of
them work hours after the market closes 4pm Atlantic time. The HMGM is then trained
again with the newest time series and the parameters are updated.
When the training is done and parameters of the HMGM are updated, we performed
the Viterbi algorithm to ﬁnd the most “reliable” Gaussian mixtures associated with the
most probable state. The weighted average of the mean of the Gaussian mixture is taken
as the prediction for tomorrow. The induction step in section 2.7.2 is revised by replacing
the function b
ijot
with the Gaussian density function N(o
t
, µ
jm
, Σ
jm
) for each state j and
mixture component m:
δ
j
(t) = max
1≤i≤N
δ
i
(t −1)a
ij
M
m=1
w
jm
N(o
t
, µ
jm
, Σ
jm
) (3.22)
ψ
jk
(t) = argmax
1≤i≤N
δ
i
(t −1)a
ij
M
m=1
w
jm
N(o
t
, µ
jm
, Σ
jm
) (3.23)
Next we transform the real values generated by the Gaussian mixtures into binary
symbols–positive or negative signals of the market. If the weighted mean of the Gaussian
mixtures at the selected state is positive or zero, we output a positive signal, otherwise we
output a negative signal. In other words, we have a threshold at zero. In our experiment,
a weighted mean of zero will generate a positive signal, that will further result in a long
strategy.
Algorithm 3.1 is the revised multiobservation EM algorithm for HMGM written in
the pseudo code.
The training set can be of any size, however as most ﬁnancial analysts believe, a ﬁve
day or twenty day set would be desirable because ﬁve days are the trading days in a week
and one month consists of roughly twenty trading days. There is a balance between the size
of the training set and the sensitivity of the model. The bigger the training set, the more
accurate the model in terms of ﬁnding long term trend. However the trained model may
not be sensitive to whipsaws.
CHAPTER 3. HMM FOR FINANCIAL TIME SERIES ANALYSIS 45
Algorithm 3.1: Combined trainingprediction algorithm for the HMGM
while not End of Series do
initialization
if tradingDay = ﬁrst day of series then
assign random values to the HMM parameters
else
initialize parameters with the last updated values
end if
Training data set update
1.State drop day 1 in the previous training set
2.State add current day (the day that has just ended) to the training set
3.Update all parameters using the EM algorithm
Prediction
1.Run the Viterbi algorithm to ﬁnd the Gaussian mixture with the most probable state
2.Compare the weighted mean of the Gaussian mixture against the threshold zero
3.Output the predicted signal
end while
3.7 Chapter Summary
In this chapter, we construct an HMM to predict the ﬁnancial time series, more speciﬁcally
the S&P 500 Index. Issues considered in the modeling process include the selection of the
emission density function, the EM update rule and characteristics of the selected ﬁnancial
time series. These issues are addressed throughout the explanations in this chapter. Each
state of the HMM is associated with a mixture of Gaussian functions with diﬀerent parameters,
which give each state diﬀerent prediction preference. Some states are more sensitive to
low volatile data and others are more accurate with high volatile segments. The revised
weighted EM update algorithm puts more emphasis on the recent data. The Dow Jones
Index is included in the experiments as a supporting indicator to decide the volatility of the
S&P 500 series. We have achieved impressive results that are shown in chapter 5.
Chapter 4
Exponentially Weighted EM
Algorithm for HMM
In this chapter we ﬁrst review the traditional EM algorithm in more depth by taking a close
look at the composition of the likelihood function and the Q function. Originally formalized
in [DLR77], The EM algorithm for reestimation is intensively studied under all sorts of
problem settings, including Hidden Markov Model [BP66] [RJ86] [Rab89], conditional/joint
probability estimation [BF96] [JP98], constrained topology HMM [Row00], coupled HMM
[ZG02], hierarchical HMM [FST98], and Gaussian mixtures [RW84] [XJ96] [RY98]. However,
all these variances of the EM algorithm do not take the importance attenuation in the time
dimension into consideration. They take it for granted that each data sample in the training
data set is of equal importance and the ﬁnal estimation is based on this equal importance
assumption, no matter how big the training set is. This approach works well when the
training set is small and the data series studied are not timesensitive or the time dimension
is not a major concern. The traditional EM based HMM models have found great success
in language and video processing where the order of the observed data is not signiﬁcantly
important.
However ﬁnancial time series diﬀer from all the above signals. They have some unique
characteristics. We need to focus more on recent data while keep in mind of the past
patterns, but at a reduced conﬁdence. As we have discussed in chapter 1, many patterns
disappeared or diminished after they had been discovered for a while. A most persuasive
argument is the change of the Dow Jones Index. It took the Dow Jones Index 57 years to
46
CHAPTER 4. EXPONENTIALLY WEIGHTED EM ALGORITHM FOR HMM 47
rise from 200 to 2000, yet it only took 12 years to rise from 2000 to 10, 000.
Realizing the change of importance over the time dimension and motivated by the
concept of Exponential Moving Average (EMA) of ﬁnancial time series, we presents the
derivation of the exponentially weighted EM algorithm. We show that the ﬁnal reestimation
of the parameters of the HMM and the Gaussian densities can be expressed in a form of a
combination of the exponential moving averages (EMAs) of the intermediate state variables.
To ﬁnd better balance between shortterm and longterm trends, we further develop a double
weighted EM algorithm that is sensitivityadjustable by including the volatility information.
We show the convergence of the exponentially weighted EM algorithm is guaranteed by a
weighted version of the EM Theorem.
4.1 Maximumlikelihood
We have a density function p(XΘ) that represents the probability of the observation
sequence X = {x
1
, . . . , x
N
} given the parameter Θ. In the HMGM model Θ includes
the set of means and covariances of the Gaussian mixtures associated with each state as
well as the transition probability matrix and the probability of each mixture component.
Assuming the data are independent and identically distributed (i.i.d.) with distribution p,
the probability of observing the whole data set is:
p(XΘ) =
N
i=1
p(x
i
θ) = L(ΘX) (4.1)
The function L is called the likelihood function of the parameters given the data. Our goal
of the EM algorithm is to ﬁnd the Θ
∗
that maximizes L:
Θ
∗
= argmax
Θ
L(ΘX) (4.2)
Since the log function is monotonous, we often maximize the logarithm form of the likelihood
function because it reduces multiplications to additions thus makes the derivation analytically
easier.
4.2 The Traditional EM Algorithm
The EM algorithm takes the target data as composed of two parts, the observed part and
the underlying part. The observed data are governed by some distribution with given form
CHAPTER 4. EXPONENTIALLY WEIGHTED EM ALGORITHM FOR HMM 48
but unknown parameters. The underlying data can be viewed as a random variable itself.
The task of the EM algorithm is to ﬁnd out the parameters for the distribution governing
the observed part and the distribution generating the underlying part.
Now assume X as the observed part governed by some distribution with known form
but unknown parameters. X is called the incomplete data. Then Assume the complete data
Z = (X, Y ). By the Bayes rule, the joint density function of one data in the complete data
sample is:
p(zΘ) = p(x, yΘ)
= p(yx, Θ)p(xΘ) (4.3)
x and y are individual data in the data sample X and Y . Note the a prior probability
p(xΘ) and the distribution of the hidden data are initially generated by assigning some
random values. We now deﬁne the complete data likelihood function for the overall data set
based on the above joint density function of individual data:
L(ΘZ) = L(ΘX, Y )
= p(X, Y Θ) (4.4)
When estimating the hidden data Y , X and Θ can be taken as constants and the complete
data likelihood becomes a function of Y : L(ΘX, Y ) = h
X,Θ
(Y ) where Y is the only random
variable.
Next the EM algorithm ﬁnds the expected value of the complete data loglikelihood
log p(X, Y Θ) with respect to the unknown data Y , given the observed part X and the
parameters from last estimation. We deﬁne a Q function to denote this expectation:
Q(Θ, Θ
(i−1)
) = E
_
log p(X, Y Θ)X, Θ
(i−1)
_
=
_
y∈Υ
log p(X, yΘ)f(yX, Θ
(i−1)
) dy (4.5)
Θ
(i−1)
are the estimates from last run of the EM algorithm. Based on Θ
(i−1)
we try to
ﬁnd the current estimates Θ that optimize the Q function. Υ is the space of possible values
of y.
As mentioned above, we can think of Y as a random variable governed by some distribution
f
Y
(y) and h(Θ, Y ) is a function of two variables. Then the expectation can be rewritten in
CHAPTER 4. EXPONENTIALLY WEIGHTED EM ALGORITHM FOR HMM 49
the form:
Q(Θ) = E
Y
[h(Θ, Y )]
=
_
y
h(Θ, Y )f
Y
(y) dy (4.6)
In the MStep of the EM algorithm, we ﬁnd the parameter Θ that maximizes the Q
function:
Θ
(i)
= argmax
Θ
Q(Θ, Θ
(i−1)
) (4.7)
The two steps are repeated until the probability of the overall observation does not
improve signiﬁcantly. The EM algorithm is guaranteed to increase the loglikelihood at
each iteration and will converge to a local maximum of the likelihood. The convergence is
guaranteed by the EM Theorem [Jel97].
4.3 Rewriting the Q Function
An assumption that is not explicitly stated in the derivation of the EM algorithm in all
works cited above is that: in calculating the Q function, we take it for granted that each
data is of equal importance in the estimation of the new parameters. This is reasonable
in problems like speech and visual signal recognition because the order of the data in the
observed data sample is not that important, rather the general picture consisting of all data
points is of more interest. However as stated in the beginning of this chapter, ﬁnancial time
series have characteristics which make the time dimension very important. As time goes
on, old patterns attenuate and new patterns emerge. If the local data set that we use as
training set is very large, the new emerged patterns or trends will be inevitably diluted.
Therefore we need a new EM algorithm that gives more importance to more recent data.
To achieve this goal, we must ﬁrst rewrite the Q function. Recall that the Q function is
the expectation of the complete data likelihood function L with respect to the underlying
data Y , given the observed data X and the last parameter estimates Θ. Now we include a
timedependent weight η in the expectation to reﬂect information on the time dimension.
The revised expectation of the likelihood function
ˆ
Q:
ˆ
Q(Θ, Θ
(i−1)
) = E
_
log ηp(X, Y Θ)X, Θ
(i−1)
_
=
_
y∈Υ
log ηp(X, yΘ)f(yX, Θ
(i−1)
) dy (4.8)
CHAPTER 4. EXPONENTIALLY WEIGHTED EM ALGORITHM FOR HMM 50
Since the logarithm function is monotonous and 0 < η ≤ 1, we can take η out of the log
function.
[log η · P(X, yΘ) ≤ log η · P(X, yΘ
g
)] ⇐⇒
[η · P(X, yΘ) ≤ η · P(X, yΘ
g
)] ⇐⇒
[η · log P(X, yΘ) ≤ η · log P(X, yΘ
g
)] (4.9)
This move can bring great convenience to the E step. The
ˆ
Q function then becomes:
ˆ
Q(Θ, Θ
(i−1)
) = E
_
η log p(X, Y Θ)X, Θ
(i−1)
_
=
_
y∈Υ
η log p(X, yΘ)f(yX, Θ
(i−1)
) dy (4.10)
The weight η is actually a vector of real values between 0 and 1: η = {η
1
, η
2
, . . . , η
N
}
where N is the number of data. The whole point is that the likelihood of each data is
discounted by a conﬁdence density. The weighted expectation function can be understood
intuitively: Given the last parameter estimates and the observed data, if the expected
probability of observing one data is 40%, given its position in the whole data sequence, we
might have only 60% conﬁdence in the accuracy of this result–meaning the ﬁnal expected
likelihood is only 0.4 ×0.6 = 24%.
In a later section we will show that the
ˆ
Q function converges to a local maximum using
techniques from the EM Theorem.
4.4 Weighted EM Algorithm for Gaussian Mixtures
We now show how the parameters of the HMGM introduced in chapter 3 can be reestimated
with the weighted EM algorithm. To begin with, we will use a mixture of Gaussians as an
example to illustrate the derivation process, the HMGM is only a special case of Gaussian
mixtures in nature.
Under this problem setting, ﬁrst assume the following density for one single data x
j
,
given the parameter Θ of the Gaussian mixture:
p(x
j
Θ) =
M
i=1
η
j
α
i
p
i
(xθ
i
) (4.11)
The parameters now consist of three types of variables Θ = (η
j
, α
1
, . . . , α
M
, θ
1
, . . . , θ
M
). η
j
is
the timedependent conﬁdence weight for the j
th
observed data. α
i
indicates which mixture
CHAPTER 4. EXPONENTIALLY WEIGHTED EM ALGORITHM FOR HMM 51
component generates the observed data and it must observe the constraint
M
i=1
α
i
= 1. p
i
is a density function for the i
th
mixture component with parameter θ
i
.
We assume a set of initial parameter values, for example y
i
= k indicates the i
th
data
is generated by the k
th
mixture component. Also assume θ
i
as the parameters for the i
th
Gaussian function of the mixture. (θ
i
includes the mean and covariance for the i
th
Gaussian).
Last assume the conﬁdence weight η
n
for the n
th
data. We can obtain the complete data
log likelihood function based on these hypothesized parameters:
log
ˆ
L(ΘX, Y ) = η log P(X, Y Θ)
=
N
i=1
η
i
log P(x
i
y
i
)P(y)
=
N
i=1
η
i
log α
y
i
p
y
i
(x
i
θ
y
i
) (4.12)
So we start from a set of guessed parameters and from the assumed parameters we can go
on to compute the likelihood function. We guess that Θ
g
=
_
η
1
, . . . , η
N
; α
g
1
, . . . , α
g
M
; θ
g
1
, . . . , θ
g
M
_
are the best possible parameters for the likelihood
ˆ
L(Θ
g
X, Y ). Note the subscripts of η are
in the time dimension, there are N data in the training set. The subscripts for α and θ are
in the spatial dimension, indicating the parameter of a certain mixture component. η
i
and
α
y
i
can be thought of as prior probabilities. And p
y
i
(y
i
x
i
, Θ
g
) in the likelihood function
can be computed using the Bayes’s rule:
p(y
i
x
i
, Θ
g
) =
α
g
y
i
p
y
i
(x
i
θ
g
y
i
)
p(x
i
Θ
g
)
=
α
g
y
i
p
y
i
(x
i
θ
g
y
i
)
M
k=1
α
g
k
p
k
(x
i
θ
g
k
)
(4.13)
and same as the basic EM algorithm,
p(yX, Θ
g
) =
N
i=1
p(y
i
x
i
, Θ
g
) (4.14)
where y = (y
1
, . . . , y
N
) retain the independent property.
As mentioned above the conﬁdence weight η can be taken as a prior probability. The
p
y
i
(y
i
x
i
, Θ
g
) is actually a conditional probability conditional on the data position i. However
this conditional probability is often ignored in traditional EM algorithm because it was taken
for granted that the prior probability is always equal to 1.
CHAPTER 4. EXPONENTIALLY WEIGHTED EM ALGORITHM FOR HMM 52
With these initial parameters Θ
g
made by guessing, we can try to ﬁnd out the current
parameters Θ that maximizes the
ˆ
Q function:
ˆ
Q(Θ, Theta
g
) =
y∈Υ
η log(L(ΘX, y))p(yX, Θ
g
)
=
y∈Υ
η log P(X, yΘ)p(yX, Θ
g
)
=
y∈Υ
N
i=1
η
i
log(α
y
i
p
y
i
(x
i
θ
y
i
))
N
j=1
p(y
j
x
j
,
ˆ
Θ
g
)
=
M
y
1
=1
M
y
2
=1
· · ·
M
y
N
=1
N
i=1
log(α
y
i
p
y
i
(x
i
θ
y
i
))
N
j=1
p(y
j
x
j
,
ˆ
Θ
g
)
=
M
y
1
=1
M
y
2
=1
· · ·
M
y
N
=1
N
i=1
M
l=1
δ
l,y
i
log(α
l
p
l
(x
i
θ
l
))
N
j=1
p(y
j
x
j
,
ˆ
Θ
g
)
=
M
l=1
N
i=1
log(α
l
p
l
(x
i
θ
l
))
M
y
1
=1
M
y
2
=1
· · ·
M
y
N
=1
δ
l,y
i
N
j=1
p(y
j
x
j
,
ˆ
Θ
g
) (4.15)
The latter part of the above formula can be simpliﬁed as below:
M
y
1
=1
M
y
2
=1
· · ·
M
y
N
=1
δ
l,y
i
N
j=1
p(y
j
x
j
,
ˆ
Θ
g
)
=
_
_
M
y
1
=1
· · ·
M
y
i−1
=1
M
y
i+1
=1
· · ·
M
y
N
=1
N
j=1,j=i
p(y
j
x
j
, Θ
g
)
_
_
p(lx
i
, Θ
g
)
=
N
j=1,j=i
_
_
M
y
j
=1
p(y
j
x
j
, Θ
g
)
_
_
p(lx
i
, Θ
g
)
= p(lx
i
, Θ
g
) (4.16)
This simpliﬁcation can be carried out because of the constraint
M
i=1
p(ix
j
, θ
g
) = 1.
Although the overall expectation is discounted by the time factor, the constraint on mixture
components still holds at each data point over the time axis. Then the
ˆ
Q function can be
written as:
ˆ
Q(Θ, Θ
g
) =
M
l=1
N
i=1
η
i
log(α
l
p
l
(x
i
θ
l
))p(lx
i
, Θ
g
)
=
M
l=1
N
i=1
η
i
log(α
l
)p(lx
i
, Θ
g
) +
M
l=1
N
i=1
η
i
log(p
l
(x
i
Θ
l
))p(lx
i
, Θ
g
) (4.17)
CHAPTER 4. EXPONENTIALLY WEIGHTED EM ALGORITHM FOR HMM 53
It becomes clear that to maximize the
ˆ
Q function we must maximize both terms in the
above formula separately. The ﬁrst term has α
l
which must observe the constraint
l
α
l
= 1.
So it is a constrained function optimization problem where the Lagrange multiplier λ can
be applied. And the maximum is achieved when the following equation is satisﬁed:
∂
∂α
l
_
M
l=1
N
i=1
η
i
log(α
l
)p(lx
i
, Θ
g
) +λ
_
l
α
l
−1
__
= 0 (4.18)
From above, we have:
N
i=1
1
α
l
η
i
p(lx
i
, Θ
g
) +λ = 0 (4.19)
Summing both the numerator and denominator of the ﬁrst term over l, the left side of the
equation becomes:
M
l=1
N
i=1
η
i
p(lxi, Θ
g
)
M
l=1
α
l
+λ =
N
i=1
M
l=1
η
i
p(lx
i
, Θ
g
)
M
l=1
α
l
+λ (4.20)
=
N
i=1
η
i
+λ (4.21)
Let the above expression equal 0, we can easily get λ = −
N
i=1
η
i
. Substituting λ in the
above equation we ﬁnally get the estimation of α
l
:
α
l
=
N
i=1
η
i
p(lx
i
, Θ
g
)
N
i=1
η
i
(4.22)
Next we derive the update rule for the mean and covariance of the Gaussian components.
This is done by maximizing the second term in the
ˆ
Q function. Given the form of a D
dimensional Gaussian distribution, we know
p
l
(xµ
l
, Σ
l
) =
1
(2π)
d
/2Σ
l

1/2
exp
_
−
1
2
(x −µ
l
)
T
Σ
−1
l
(x −µ
l
)
_
(4.23)
Substituting this distribution form into the second term of 4.17 and taking away constant
terms that will be eliminated after taking derivatives, we get:
M
l=1
N
i=1
η
i
log(p
l
(x
i
Θ
l
))p(lx
i
, Θ
g
)
=
M
l=1
N
i=1
η
i
_
−
1
2
log(Σ
l
) −
1
2
(x
i
−µ
l
)
T
Σ
−1
l
(x
i
−µ
l
)
_
p(lx
i
, Θ
g
) (4.24)
CHAPTER 4. EXPONENTIALLY WEIGHTED EM ALGORITHM FOR HMM 54
The maximization of the above expression is achieved by taking the derivative with
respect to µ
l
and letting it equal to 0:
N
i=1
η
i
Σ
−1
(x
i
−µ
l
)p(lx
i
, Θ
g
) = 0 (4.25)
Then we can work out the current estimation for µ
l
:
µ
l
=
N
i=1
x
i
p(lx
i
, Θ
g
)
N
i=1
η
i
p(lx
i
, Θ
g
)
(4.26)
Similarly, take the derivative of (4.45) with respect to the covariance Σ
l
and setting it
equal to 0, we get:
N
i=1
η
i
p(lx
i
, Θ
g
)
_
Σ
l
−(x
i
−µ
l
)(x
i
−µ
l
)
T
_
= 0 (4.27)
So the estimation for Σ is:
Σ
l
=
N
i=1
η
i
p(lx
i
, Θ
g
)(x
i
−µ
l
)(x
i
−µ
l
)
T
N
i=1
η
i
p(lx
i
, Θ
g
)
(4.28)
4.5 HMGM Parameter Reestimation with the Weighted EM
Algorithm
After showing the derivation of the exponentially weighted EM algorithm for the Gaussian
mixture case, we now return to our HMGM model. As discussed in chapter 2 and 3, we
have two intermediate variables describing the whole process of generating the observed
data: γ
i
(t) represents the probability of being in state i at time t and w
im
is the probability
of picking the m
t
h mixture component at state i. These intermediate variables combine
together to generate the probability of the observed data. We can deﬁne the probability
δ
im
(t) that denotes the m
th
mixture density generating observation o
t
as:
δ
im
(t) = γ
i
(t)
w
im
b
im
(o
t
)
b
i
(o
t
)
(4.29)
We ﬁnd that the δ
im
(t) enjoys the same status as the prior probability p(lx
i
, Θ
g
) in previous
discussions. The calculation of the transition probability a
ij
also involves a time variable
CHAPTER 4. EXPONENTIALLY WEIGHTED EM ALGORITHM FOR HMM 55
thus can also be weighted. So the exponential weighted update rules for the HMGM are
derived in a similar form, taking the timeintensifying weight into consideration:
µ
im
=
T
t=1
η
t
δ
im
(t)o
t
T
t=1
η
t
δ
im
(t)
(4.30)
σ
im
=
T
t=1
η
t
δ
im
(t)(o
t
−µ
im
)(o
t
−µ
im
)
T
t=1
η
t
δ
im
(t)
(4.31)
w
im
=
T
t=1
η
t
δ
im
(t)
T
t=1
η
t
δ
i
(t)
(4.32)
a
ij
=
T
t=1
η
t
α
i
(t)a
ij
b
j
(o
t+1
)β
j
(t + 1)
T
t=1
η
t
α
i
(t)β
i
(t)
(4.33)
4.6 Calculation and Properties of the Exponential Moving
Average
Before we go on to show how we can rewrite the reestimation formulas with EMAs of the
intermediate variables, let’s take a closer look at the calculation and properties of the EMA.
The EMA is invented originally as a technical analysis indicator that keeps track of
the trend changes in ﬁnancial time series. Shortterm EMAs response faster than long
term EMAs to changes in the trend. When the curves of two EMA with diﬀerent length
cross each other, this usually means a trend change. Technical analysis people developed
other indicators based on the EMA, such as the Moving Average Convergence Divergence
(MACD). Figure 4.1 shows the signals indicated by comparing the 30day EMA and the
100day EMA for an individual stock Intel :
Take the variable p
t
(ij) for illustration. We denote p
t
(ij) as the exponential moving
average of the original variable p
t
(ij) at time t. As by its name implies, the EMA changes
as time moves on. The calculation of a ﬁve day exponentially moving average for this new
intermediate variable consists of two steps:
First, calculate the arithmetic average of the ﬁrst ﬁve days. Denote this average as
p
5
(ij). Second, starting from the sixth day, the EMA of each day is:
p
t
(ij) = ρ ×p
t
(ij) + (1 −ρ) ×p
t−1
(ij) (4.34)
CHAPTER 4. EXPONENTIALLY WEIGHTED EM ALGORITHM FOR HMM 56
Figure 4.1: When the 30day moving average moves above the 100day moving average, the trend
is considered bullish. When the 30day moving average declines below the 100day moving average,
the trend is considered bearish. (picture from stockcharts.com)
CHAPTER 4. EXPONENTIALLY WEIGHTED EM ALGORITHM FOR HMM 57
Note that in the above equation, p
t
(ij) is the actual intermediate variable value at time
t, while p
t
(ij) is the exponential moving average of that variable at time t. We keep running
the second step until the last day of the training pool.
The EMA of the second intermediate variable δ
i
(t) that stores the probability of being
at state i at time t, can be calculated in a similar way:
δ
i
(t) = ρ ×δ
i
(t) + (1 −ρ) ×δ
i
(t −1) (4.35)
In equations (4.1) and (4.2), ρ is the weight that we have been talking about all the
time. The value of ρ is given by the formula: ρ =
2
1+k
, k = the number of days in the
moving window
For example, if the size the moving window is 5, which means we are calculating a ﬁve
day EMA, then the value of ρ would be:
ρ =
2
1 + 5
= 0.3333... (4.36)
So the last day accounts for one third of the ﬁnal value.
The 5day EMA at the 20th day of the training pool is calculated by running equation
(4.1) until the 20th day:
p
6
(ij) = p
6
(ij) ×ρ +p
5
(ij) ×(1 −ρ)
p
7
(ij) = p
7
(ij) ×ρ +p
6
(ij) ×(1 −ρ)
......
p
20
(ij) = p
20
(ij) ×ρ +p
19
(ij) ×(1 −ρ)
As we can see from equation (4.2), the last day in the training window takes up a
quite large portion and should notably aﬀect the training procedure. As time goes on, the
importance of the early data drops exponentially, as shown in Fig 4.3. This is easily shown
when we go into the details of the calculation of equation (4.1):
p
t
(ij) = ρ ×p
t
(ij) + (1 −ρ) ×p
t−1
(ij)
= ρ ×p
t
(ij) + (1 −ρ) ×[ρ ×p
t−2
(ij) + (1 −ρ) ×p
t−2
(ij)]
= ρ ×p
t
(ij) + (1 −ρ) ×[ρ ×p
t−2
(ij) + (1 −ρ)
2
×p
t−2
(ij)] (4.37)
CHAPTER 4. EXPONENTIALLY WEIGHTED EM ALGORITHM FOR HMM 58
0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0 2 4 6 8 10 12 14 16 18 20
E
M
A
p
e
r
c
e
n
t
a
g
e
trading day
EMA
Figure 4.2: The portion of each of the ﬁrst 19 days’ EMA in calculating the EMA for the 20th day.
As is shown in the ﬁgure, the EMA at the 19th day accounts for 2/3 of the EMA at day 20.
Now we see from (4.5), in calculating the EMA at day t, the weight of the EMA at day
t −1 takes up a portion of (1 −ρ) while the weight of the EMA at day t −2 is only (1 −ρ)
2
.
We can also know by inference that day t −3 will have a portion of (1 −ρ)
3
in EMA at day
t. Fig 4.4 gives a graphical view of the portion each day takes in calculating of the EMA.
4.7 HMGM Parameters Reestimation in a Form of EMA
In previous sections we derived the exponentially weighted estimation rules for the parameters
of the HMGM. We show the formulas with the exponential discount weight η. However,
there is still one problem regarding η: how is the timedependent variable η deﬁned? In fact
η can be taken as a density function whose distribution is prior knowledge. Our task now
is to ﬁnd an expression of time for η.
A nice property about the exponentially weighted intermediate parameters is that, when
calculating this weighted average, while the large part of weight is given to the recent data,
the information from the early data are not lost. The old data are also included in the ﬁnal
CHAPTER 4. EXPONENTIALLY WEIGHTED EM ALGORITHM FOR HMM 59
0
0.05
0.1
0.15
0.2
0.25
0.3
0.35
0 2 4 6 8 10 12 14 16 18 20
d
a
i
l
y
d
a
t
a
p
e
r
c
e
n
t
a
g
e
trading day
daily data
Figure 4.3: The portion of each of the 20 days’ actual data in calculating the EMA for the 20th
day. The last day account for 1/3 of the EMA at day 20. The data earlier than day 10 take up a
very small portion but they are still included in the overall calculation
CHAPTER 4. EXPONENTIALLY WEIGHTED EM ALGORITHM FOR HMM 60
average, by a discounted weight. The older the data, the less important they become, and
thus take up less portion in the average. But their impact never disappear.
Giving more recent data more weight makes the HMM getting sensitive to trend changes
in time series. The HMM will ride on the new trend quickly, without having to make too
many mistakes at the beginning of a new trend before it gets ﬁt for the new trend. That is
one important motivation of replacing the arithmetic average with EMA in the EM update
rule.
Originally, the EMA was invented as a technical analysis tool that deals with ﬁnancial
time series data, such as prices, volume, etc directly. In the EM algorithm for HMM
parameters reestimation, there are a set of middle variables: α
i
(t), β
i
(t), δ
im
(t), δ
i
(t). These
middle variables all have their actual meanings: they indicate the probabilities of some
events at a certain point of time. So these model variables are also related to the time series
data. This is another motivation we rewrite the reestimation formulas in the form of EMA
of the model variables. We take the denominator of the µ reestimation for example. From
T
t=1
η
t
δ
im
(t) we can see each δ
im
(t) at a timing point t is associated with one value of η
t
.
The sum can be extended as:
T
t=1
η
t
δ
im
(t)
= η
1
δ
im
(1) +η
2
δ
im
(2) +· · · +η
T−1
δ
im
(T −1) +η
T
δ
im
(T) (4.38)
Let ρ =
2
1+k
where k is for the multiplier in a kEMA. Then set η
t
by the following rules:
1. If 1 ≤ t ≤ k, η
t
= (1 −ρ)
(T−k)
·
1
k
;
2. If k < t < T, η
t
= ρ · (1 −ρ)
(T−t)
;
3. If t = T, η
t
= ρ.
Let δ
im
(t) represent the kEMA of δ
im
at time t. Based on these rules, the expression
(4.38) is turned into a form of the EMA of the intermediate variable δ
im
(t):
η
1
δ
im
(1) +η
2
δ
im
(2) +· · · +η
T−1
δ
im
(T −1) +η
T
δ
im
(T)
CHAPTER 4. EXPONENTIALLY WEIGHTED EM ALGORITHM FOR HMM 61
= (1 −ρ)
(T−k)
·
1
k
· δ
im
(1) +· · · + (1 −ρ)
(T−k)
·
1
k
· δ
im
(k)
+ρ · (1 −ρ) · δ
im
(T −1) +ρ · δ
im
(T)
= (1 −ρ)
(T−k)
· δ
im
(k) +ρ · (1 −ρ)
(n−(k+1))
· δ
im
(k + 1)
+ρ · (1 −ρ)
(n−(k+2))
· δ
im
(k + 2) +· · ·
+ρ · (1 −ρ) · δ
im
(T −1) +ρ · δ
im
(T) (4.39)
The ﬁrst k terms work together to generate the EMA for the ﬁrst k periods, then from
k + 1 to T, apply Formula (4.35) to δ
im
and induction on Equation (4.39), we can get the
following result:
(1 −ρ) ·
_
ρ · δ
im
(T −1) + (1 −ρ) · δ
im
(T −2)
_
= (1 −ρ) · δ
im
(T −1) +ρ · δ
im
(T)
= δ
im
(T) (4.40)
Therefore, the reestimation formulas ﬁnally came into a form of EMA of some intermediate
variables.
µ
im
=
T
t=1
η
t
δ
im
(t)o
t
δ
im
(T)
(4.41)
σ
im
=
T
t=1
η
t
δ
im
(t)(o
t
−µ
im
)(o
t
−µ
im
)
δ
im
(T)
(4.42)
w
im
=
δ
im
(T)
δ
i
(T)
(4.43)
a
ij
=
T
t=1
η
t
α
i
(t)a
ij
b
j
(o
t+1
)β
j
(t + 1)
α
i
(T)β
i
(T)
(4.44)
4.8 The EM Theorem and Convergence Property
This section shows that our exponentially weighted EM algorithm is guaranteed to converge
to a local maximum by a revised version of the EM Theorem. For review of the EM Theorem
please refer to [Jel97].
The EM Theorem for exponentially weighted EM algorithm: Let X and Y be
random variables with distributions
ˆ
P(X) and
ˆ
P(Y ) under some model
ˆ
Θ. And let
ˆ
P
(X)
CHAPTER 4. EXPONENTIALLY WEIGHTED EM ALGORITHM FOR HMM 62
and
ˆ
P
(Y ) be the distribution under a model Θ
after running the exponentially weighted
EM algorithm. Then,
_
Y
ˆ
P(Y X, η) log
ˆ
P
(Y, Xη)
ˆ
P(Y, Xη)
≥ 0
_
⇒
ˆ
P
(Xη) ≥
ˆ
P(Xη) (4.45)
This Theorem implies that if for a model
ˆ
Θ and an updated model
ˆ
Θ
, if the left hand
inequality holds, then the observed data Y will be more probable under
ˆ
Θ
than
ˆ
Θ.
Proof: From the derivation of the exponentially weighted update rule we know
0 ≤
Y
ˆ
P(Y X, η) ≤ 1
And the logarithm function is a monotonous one. So,
log
ˆ
P
(Xη) ≥ log
ˆ
P(Xη)
⇔
Y
ˆ
P(Y X, η) log
ˆ
P
(Xη) ≥
Y
ˆ
P(Y X, η) log
ˆ
P(Xη)
⇔
Y
ˆ
P(Y X, η) log
ˆ
P
(Xη) −
Y
ˆ
P(Y X, η) log
ˆ
P(Xη) ≥ 0 (4.46)
Then we can perform a series of logarithm transformation operations on expression (4.86):
Y
ˆ
P(Y X, η) log
ˆ
P
(Xη) −
Y
ˆ
P(Y X, η) log
ˆ
P(Xη)
=
Y
ˆ
P(Y X, η) log
ˆ
P
(Y, Xη)
ˆ
P
(Y X, η)
−
Y
ˆ
P(Y X, η) log
ˆ
P(Y, Xη)
ˆ
P(Y X, η)
=
Y
ˆ
P(Y X, η) log
ˆ
P
(Y, Xη)
ˆ
P
(Y X, η)
+
Y
ˆ
P(Y X, η) log
ˆ
P(Y X, η)
ˆ
P(Y, Xη)
=
Y
ˆ
P(Y X, η) log
ˆ
P
(Y, Xη)
ˆ
P(Y, Xη)
+
Y
ˆ
P(Y X, η) log
ˆ
P(Y X, η)
ˆ
P
(Y X, η)
≥
Y
P(Y X, η) log
ˆ
P
(Y, X)
ˆ
P(Y, X)
≥ 0 (4.47)
Q. E. D.
The last step follows from the Jensen’s inequality. The Jensen’s inequality basically states
that misestimation of the distribution governing a random variable will eventually result in
increased uncertainty/information. For a thorough review of the Jensen’s inequality please
refer to [?] [HLP88] and [GI00].
CHAPTER 4. EXPONENTIALLY WEIGHTED EM ALGORITHM FOR HMM 63
Market
Prediction
Figure 4.4: The prediction falls behind the market during highly volatile periods of time. This is
because the system is too sensitive to recent changes.
4.9 The Double Weighted EM Algorithm
There is still room for improvement in the previous exponentially weighted EM rule. However,
just as any other improvements, we have to consider the cost of the improvement of
sensitivity and ﬁnd out a way to overcome any possible problem.
4.9.1 Problem with the Exponentially Weighted Algorithm
The exponentially weighted EM algorithm quickly picks the trend at times when there is
a turning of the trend. However, sometimes, especially during the highly volatile periods,
the direction of the ﬁnancial time series reverse at a very high frequency in a very short
period of time. In these cases, there is danger of falling right behind the market movement,
as shown in Fig 4.5.
Fig 4.5 shows a problem caused by high sensitivity. Not only the turning points of the
market are all missed, the prediction of the turning points are not the actual market turning
points. This is because the system is too sensitive to recent data that they fall into the pitfall
of high volatility. Actually if one keeps making prediction of one same direction, or if he
refers to the long term trend during that period of time, he may have a better opportunity
of getting a higher gain.
4.9.2 Double Exponentially Weighted Algorithm
To solve this problem, we arm the HMM with a selfconﬁdence adjustment capability.
Multiply the weight for the most recent data η with a second weight ζ. ζ is the conﬁdence
rate for the weight η. It is calculated by comparing the trend signal, i.e., positive and
CHAPTER 4. EXPONENTIALLY WEIGHTED EM ALGORITHM FOR HMM 64
negative symbols of the S&P 500 Index with the trend signal of the Dow Jones Index. The
Dow Jones is a relatively mild index, comparing to the S&P 500 and NASDAQ. We can of
course use other indicators that reserves long term trend well, but for the time being, we
will use the Dow for our experiment.
Comparing the S&P 500 with the Dow for the past ﬁve days. If they have the same
directions for everyday of the past 5 days, the HMM gets full conﬁdence 1. Otherwise, the
conﬁdence weight ζ is calculated as the total number of days that Dow coincides with the
S&P divided by 5. Then time the two weights together, this is the weight that we will use
for further calculation.
The adjustable weighted exponential average for the two intermediate variables are:
p
t
(ij) = η ×ζ ×p
t
(ij) + (1 −η ×ζ) ×p
t−1
(ij)δ
i
(t)
= η ×ζ ×δ
i
(t) + (1 −η ×ζ) ×δ
i
(t −1) (4.48)
Then apply the formulas (4.134.16) to get the updated parameters.
4.10 Chapter Summary
In this chapter we derived a novel exponentially weighted EM algorithm for training HMGMs.
The EWEM algorithm takes the time factor into consideration by discounting the likelihood
function in traditional EM by an exponential attenuation weight which we call the conﬁdence
weight. This is very important in ﬁnancial time series analysis and prediction because
ﬁnancial time series are known to be nonstationary and diﬀerent periods should be of
diﬀerent interest in generating a prediction for the future. We show that the reestimation
of the parameters come in a form of exponential moving average of the intermediate variables
used for calculation of the ﬁnal parameters. We prove the convergence to a local maximum
is guaranteed by an exponential version of the EM Theorem. To ﬁnd better balance between
longterm and shortterm trends, we develop a doubleweighted EM algorithm.
Chapter 5
Experimental Results
This section has all the experimental results inside. The ﬁrst section shows the prediction
results on a synthetic data set. The second section includes the predictions for the years
1998 to 2000 of the NASDAQ Composite Index with a recurrent neural network. The
third section includes prediction results of the HMM with Gaussian mixtures as emission
density functions and trained with the simple weighted EM algorithm. We test a set of data
with diﬀerent training windows. The last section shows the results from the weighted EM
algorithm.
5.1 Experiments with Synthetic Data Set
We ﬁrst test diﬀerent models on an artiﬁcially generated data set. The data is generated
by a function composed of three parts:
f(t) = 0.2 ∗ (τ(t)/100 −0.005) + 0.7 ∗ f(t −1) + 0.1 ∗ 0.00001 (5.1)
τ(t) is a random number that takes 20% of the overall output. 70% of the data at step
t is from that of step t −1. This is to try to hold the impact of the recent past. And lastly
there is a 10% of upgrowing trend at the growth rate of 0.00001. 20% of the data are
generated randomly. This may not exactly be the case in real life ﬁnancial time series, but
our model should be able to at least handle it before applied to real data.
We test the recurrent neural network and the HMGM on this artiﬁcial data set for
400 days. Both models predict the signal 5 days ahead. Results show that over the test
period of 395 days (prediction starts on the 6th day), the HMGM performs better than
65
CHAPTER 5. EXPERIMENTAL RESULTS 66
0.9
0.95
1
1.05
1.1
1.15
1.2
1.25
1.3
0 50 100 150 200 250 300 350 400
r
e
t
u
r
n
trading day
follow
HMM
recurrent network
index
Figure 5.1: Experimental results on computer generated data.
the recurrent neural network by 10.55%, and 22.2% above the cumulative return based on
the artiﬁcial generated data. The HMGM underperforms a followthetrend strategy which
takes yesterday’s signal as today’s prediction. This is because the data are composed in
a way that a large portion of the data is taken directly from the recent past. However, it
is clearly shown that the HMGM is a better model of the two statistical learning models
and it works better than the buyandhold strategy (which is the index). In the following
sections we will test the HMGM on reallife data, the S&P 500 Index.
The following table shows the comparisons of accuracy between the recurrent network
and the exponentially weighted HMGM. The accuracy rates are based on statistics from
ten runs of both models on ten data sets generated by the equation 5.1. As we can see the
exponentially weighted HMGM(EWHMGM) outperforms the recurrent network for positive
signals and slightly behind on negative ones, but has a better overall performance. And the
EWHMGM has less volatility in prediction accuracy at diﬀerent runs of experiment.
CHAPTER 5. EXPERIMENTAL RESULTS 67
Positive Negative Overall
Min/Max/Avg Min/Max/Avg Min/Max/Avg
Recurrent Net 0.44/0.72/0.55 0.52/0.79/0.62 0.53/0.65/0.58
EWHMGM 0.54/0.80/0.64 0.54/0.68/0.57 0.54/0.64/0.61
Table 5.1: Comparison of the recurrent network and exponentially weighted HMGM on the synthetic
data testing. The EWHMGM outperforms the recurrent network in overall result, and has less
volatility.
5.2 Recurrent Neural Network Results
The NASDAQ Index data are separated into three years. As can be seen from the data,
the recurrent neural network has a positve bias toward steady trends. By that we mean the
recurrent network performs better during long term bull market (as in late 1998 and early
1999) or long term bear market (as in the year 2000).
0.9
1
1.1
1.2
1.3
1.4
1.5
1.6
0 50 100 150 200 250 300
r
e
t
u
r
n
trading day
prediction
market
Figure 5.2: Prediction of the NASDAQ Index in 1998 with a recurrent neural network.
As we can see from the above ﬁgures, recurrent neural networks work better during low
volatile, steady trends, no matter it is a bull market or bear market. This is especially
CHAPTER 5. EXPERIMENTAL RESULTS 68
0.7
0.75
0.8
0.85
0.9
0.95
1
1.05
1.1
1.15
1.2
1.25
0 50 100 150 200 250 300
r
e
t
u
r
n
trading day
prediction
market
Figure 5.3: Prediction of the NASDAQ Index in 1999 with a recurrent neural network.
0.8
0.85
0.9
0.95
1
1.05
1.1
1.15
1.2
1.25
1.3
1.35
0 50 100 150 200 250 300
r
e
t
u
r
n
trading day
prediction
market
Figure 5.4: Prediction of the NASDAQ Index in 2000 with a recurrent neural network.
CHAPTER 5. EXPERIMENTAL RESULTS 69
apparent in the prediction for the year 2000. Part of the reason is due to the memory
brought by the recurrent topology. The past data has too much impact on the current
training and prediction.
5.3 HMGM Experimental Results
We launch a series of experiments on the Hidden Markov Gaussian Mixtures (HMGM). The
training window introduced in chapter 3 is adjustable from 10day to 100day. The EM
algorithm is performed on the training data with diﬀerent training windows. Results show
that the prediction performance changes as the training window size is adjusted. The best
result is achieved by the 40day training day window. And prediction becomes worse as the
training window is changed in either direction.
0.95
1
1.05
1.1
1.15
1.2
1.25
1.3
1.35
1.4
1.45
1.5
0 50 100 150 200 250 300 350 400
r
e
t
u
r
n
trading day
prediction
market
Figure 5.5: Prediction of the 400day S&P 500 Index starting from Jan 2, 1998. Training
window size = 10
We test all the above mentioned approaches in chapter 4 with 400 days of the S&P 500
Index starting from Jan 2, 1998.
First take a look at the HMGM with Rabiner’s arithmetic average update rule. From
t213 to t228, the actual market had an apparent reverse in direction, from a decline to an
CHAPTER 5. EXPERIMENTAL RESULTS 70
0.9
1
1.1
1.2
1.3
1.4
1.5
1.6
0 50 100 150 200 250 300 350 400
t213 t228
r
e
t
u
r
n
trading day
prediction
market
Figure 5.6: Prediction of the 400day S&P 500 Index starting from Jan 2, 1998. Training
window size = 20
increase. The simple HMGM was not able to recognize this in a short time, which costs a
loss in proﬁt. But the overall cumulative proﬁt at the end of the testing period is still 20%
above the market return.
The multivariate HMGM takes a vector of {S&P daily return, Dow Jones daily return}
as input. We do not know the exact relationship between those two ﬁnancial time series, but
the multivariate HMM uses the EM algorithm to ﬁnd the best parameters that maximizes
the probability of seeing both series data. The multivariate HMGM model generates similar
cumulative return as the single series HMGM but has less volatility at the later part of the
testing data.
The exponentially weighted EM algorithm performs signiﬁcantly better than the ﬁrst
two models, mainly because it picks up a reverse trend much faster. During the periods of
t164 to t178 and t213 to t228, the trend reversals were recognized and we gain points here,
so that the later cumulative gains can be based on a higher early gain. However, it also
loses points during periods where the volatility is higher, such as the period after t228. At
the end of the whole period, a bull market started and the model responded quickly to this
CHAPTER 5. EXPERIMENTAL RESULTS 71
0.8
1
1.2
1.4
1.6
1.8
2
2.2
0 50 100 150 200 250 300 350 400
r
e
t
u
r
n
trading day
prediction
market
Figure 5.7: Prediction of the 400day S&P 500 Index starting from Jan 2, 1998. Training
window size = 40
signal and made no mistake during the long bull. We made nearly twice as much at the end
of the 400 days.
Then we tested the double weighted EM algorithm. There isn’t quite much diﬀerence
from the single exponentially weighted EM algorithm. This is partly because the S&P 500
and the Dow give identical direction signals most of the time during the testing period. But
a small diﬀerence at the end of the 400 days gives the double weight algorithm a 2% better
performance.
Finally we produce an allinone picture with all the prediction results from diﬀerent
models for comparison. As seen from the picture, the two weighted HMGM performs
convincingly better than the traditional EM algorithm.
5.4 Test on Data Sets from Diﬀerent Time Periods
To show the results generated by the HMGM are not random and can repeatedly beat the
buyandhold strategy, we test the model on data sets from diﬀerent time periods. The
data tested are four segments of the S&P 500 Index: November21994 to June31996,
CHAPTER 5. EXPERIMENTAL RESULTS 72
0.8
0.9
1
1.1
1.2
1.3
1.4
1.5
0 50 100 150 200 250 300 350
r
e
t
u
r
n
trading day
prediction
market
Figure 5.8: Prediction of the 400day S&P 500 Index starting from Jan 2, 1998. Training
window size = 100
June41996 to December311998, August51999 to March72001 and March82001 to
October112002 (the period January21998 to August41999 has been tested before), The
ﬁrst two segments are the index in the bull market cycle while the latter two segments are
the periods of a bear market. Experiments show that HMGM performs equally well under
both situations.
5.5 Comparing the Sharpe Ratio with the Top Five S&P 500
Mutual Funds
The Sharpe Ratio, also called the rewardtovariability ratio, is a measure of the riskadjusted
return of an investment. It was derived by W. Sharpe [Sha66]. Sharpe argues that the mean
and variance by themselves are not suﬃcient to measure the performance of a mutual fund.
Therefore he combined the two variable into one and developed the Sharpe Ratio.
The deﬁnition of the Sharpe Ratio is quite straightforward: Let R
Ft
be the return on
the fund in period t, R
Bt
the return on the benchmark portfolio or security in period t, and
CHAPTER 5. EXPERIMENTAL RESULTS 73
0.9
1
1.1
1.2
1.3
1.4
1.5
1.6
0 50 100 150 200 250 300 350 400
t213 t228
r
e
t
u
r
n
trading day
prediction
market
Figure 5.9: Prediction with HMGM for 400 days of the S&P 500 Index. Note from t213 to t228,
the HMM was not able to catch up with the change in trend swiftly.
0.9
1
1.1
1.2
1.3
1.4
1.5
1.6
1.7
0 50 100 150 200 250 300 350 400
r
e
t
u
r
n
trading day
prediction
market
Figure 5.10: Prediction with multivariate HMGM for 400 days of the S&P 500 Index.
CHAPTER 5. EXPERIMENTAL RESULTS 74
0.8
1
1.2
1.4
1.6
1.8
2
0 50 100 150 200 250 300 350 400
t164 t178 t213 t228
r
e
t
u
r
n
trading day
prediction
market
Figure 5.11: Prediction with single exponentially weighted HMGM
0.8
1
1.2
1.4
1.6
1.8
2
0 50 100 150 200 250 300 350 400
r
e
t
u
r
n
trading day
prediction
market
Figure 5.12: Prediction with double weighted HMGM that has a conﬁdence adjustment variable.
CHAPTER 5. EXPERIMENTAL RESULTS 75
0.8
1
1.2
1.4
1.6
1.8
2
0 50 100 150 200 250 300 350 400
r
e
t
u
r
n
trading day
double weight
single weight
HMGM
multivariate Gaussian
market
Figure 5.13: Results from all models for comparison.
0.9
1
1.1
1.2
1.3
1.4
1.5
1.6
1.7
0 50 100 150 200 250 300 350 400
r
e
t
u
r
n
trading day
prediction
market
Figure 5.14: Results on the period from November 2, 1994 to June 3, 1996
CHAPTER 5. EXPERIMENTAL RESULTS 76
0.8
1
1.2
1.4
1.6
1.8
2
2.2
0 50 100 150 200 250 300 350 400
r
e
t
u
r
n
trading day
prediction
market
Figure 5.15: Results on the period from June 4, 1996 to December 31, 1998
0.8
1
1.2
1.4
1.6
1.8
2
2.2
0 50 100 150 200 250 300 350 400
r
e
t
u
r
n
trading day
prediction
market
Figure 5.16: Results on the period from August 5, 1999 to March 7, 2001
CHAPTER 5. EXPERIMENTAL RESULTS 77
0.6
0.8
1
1.2
1.4
1.6
1.8
2
0 50 100 150 200 250 300 350 400
r
e
t
u
r
n
trading day
prediction
market
Figure 5.17: Results on the period from March 8, 2001 to October 11, 2002
D
t
the diﬀerential return in period t:
D
t
= R
Ft
−R
Bt
(5.2)
Let
¯
D be the average value of Dt over the historic period from t = 1 through T:
¯
D =
1
T
T
t=1
D
t
(5.3)
and σ
D
be the standard deviation over the period:
σ
D
=
¸
T
t=1
(D
t
−
¯
D)
2
T
(5.4)
The Sharpe Ratio (S
h
) is:
S
h
=
¯
D
σ
D
(5.5)
As we can see, the ratio indicates the average diﬀerential return per unit of historic
variability of the diﬀerential return. Using the Sharpe Ratio, we can compare the return of
CHAPTER 5. EXPERIMENTAL RESULTS 78
Symbol Explanation
BTIIX 0.02948
FSMKX 0.011475
SPFIX 0.000502
SWPPX 0.024323
VINIX 0.00142
HMGM 0.084145
Table 5.2: Comparison of the Sharpe Ratio between the HMM and the top 5 S&P 500 funds during
the period of August 5, 1999 to March 7, 2001. Four of the ﬁve funds have negative Sharpe Ratios.
The absolute value of the positive one is much smaller than the HMGM prediction.
Symbol Explanation
BTIIX 0.05465
FSMKX 0.003319
SPFIX 0.01856
SWPPX 0.01726
VINIX 0.001446
HMGM 0.098967
Table 5.3: Comparison of the Sharpe Ratios during the period of March 8, 2001 to October 11,
2002. The Double weighted HMGM consistently outperforms the top ﬁve S&P 500 mutual funds.
diﬀerent strategies at the same risk. This is the meaning of beat the market mentioned in
chapter 1.
The Sharpe Ratio can be used for signiﬁcance testing for ﬁnancial time series analysis
and prediction. This is because the tstatistic equals the Sharpe Ratio times the square
root of the total number of testing units. The Sharpe Ratio is thus proportional to the
t −statistic of the means.
We now compare the top 5 S&P 500 mutual funds that performed best over the past
three years with the HMGM model we proposed. The HMGM outperforms all of them. 4
of the 5 funds have negative Sharpe Ratios while the positive one is much smaller than the
HMGM.
CHAPTER 5. EXPERIMENTAL RESULTS 79
5.6 Comparisons with Previous Work
Hidden Markov Model, as a sequence learning model, has been applied to many ﬁelds
including natural language processing, bioinformatics, audio and video signals processing
(see 2.4). But there have been few applications on the application of HMMs to ﬁnancial time
series analysis and prediction. One reason is it is usually hard to ﬁnd functions associated to
the states that characterizes the behavior of the time series. This is an empirical research.
For example, in [MCG04], they use a binomial density function at each state to represent
the risk of default.
Second reason lies in the EM algorithm. Financial time series diﬀers from other sequence
data in that they are time dependent. In video/audio/language/bio info signals processing,
this dependence is not important, or the data must be treated of equal importance. Patterns
in ﬁnancial time series tend to change over time, as we have shown in the super ﬁve day
pattern and the January Eﬀect cases.
Bengio [BF96] introduced an InputOutput Hidden Markov Model (IOHMM) and applies
it to the Electroencephalographic signal rhythms [CB04]. Their model enables the HMM
to generate the output probability based on the current state as well as the current input
data sample from the input sequence. But they still don’t realize the importance of time.
The input sequence is just another sequence data.
In the two weighted EM algorithms we propose in the thesis, the input sequence is a
time dependent value that changes from time to time. The state parameters in the re
estimation formulas all have actual meanings. They represent the probabilities of a variety
of situations happening in the HMM. Adding the timedependent weights incorporates
temporal information into the training process of the HMM. Further, the double weighted
EM algorithm enables selfadjustment of the weights. These techniques enrich the representation
power of the HMM in dealing with ﬁnancial time series data.
We now compare our experimental results with Shi and Weigend’s work [SW97]. As
described before, they used three neural networks (called experts) as the emission functions
at each state. So there are three states in all. Each expert has its own expertise: the ﬁrst
one is responsible for low volatility regions, the second one is good at high volatility regions,
and the third expert acts as a collector for the outliers.
They test on 8 years of daily S&P 500 data from 1987 to 1994. Their return over the 8
year period is 120%. In our experiments, each of the ﬁve 400day testing periods generates
CHAPTER 5. EXPERIMENTAL RESULTS 80
a return close to 100%.
However the main problem of their prediction is not the rate of return. As we can see
from the proﬁt curve (Figure 5.6), the proﬁt curve has a similar shape as the index curve.
This means that there are too many positive signals generated by the prediction system. In
other words, many times they are taking a long position. The proﬁt of the prediction thus
follows the index behavior to a large extent.
Figure 5.18: Too many positive signals result in a curve similar to the index.
In all our ﬁve 400day periods, the proﬁt curves based on the prediction have a diﬀerent
shape than the index curve. This reﬂects a more sophisticated strategy that generates
dynamically changing signals.
Chapter 6
Conclusion and Future Work
This chapter concludes the thesis. We show our ﬁndings through the experiments and
indicate possible improvements to the tested model.
6.1 Conclusion
Our experiments can be sorted into three categories: testing of HMGM with diﬀerent
training window sizes; testing of the weighted EM algorithm in comparison with the classic
EM algorithm; the use of supporting time series to help predict the targeting series.
Comparing with neural network experts, the parameters of the HMGM as emission
density functions can be clearly derived from the EM algorithm. By using a mixture of
Gaussian density functions at each state, the emission functions provide a broad range of
predictions.
Results show that there is no incorrect bias as shown in the neural network experiments.
The HMGM performs equally good in both bull market and bear market. Although at
times where the ﬁnancial time series is volatile, it will make more mistakes, HMGM can
eventually catch up with the trend. In a 20day experiment the cumulative rate of return
is 20% above the actual market return over the 400 days of training and testing period.
We introduce an important concept in the model design, the training window. In fact,
the training window is used in both training and testing as these two processes are combined
together throughout the experiment. It is an empirical study what the size of the training
window should be. Experimental results show that a 40day training window generates the
best prediction. The accuracy of prediction decreases as the size of the training window
81
CHAPTER 6. CONCLUSION AND FUTURE WORK 82
changes in either direction. This means to get the best prediction, we have to balance
between shortterm sensitivity and longterm memory.
Noticing that recent data should be given more emphasis than older data from the
past, we revise the general EM algorithm to a exponentially weighted EM algorithm. This
algorithm is motivated by the exponential moving average technique used widely in ﬁnancial
engineering. The weighted EM algorithm shows an increased sensitivity to recent data.
However during highly sensitive periods, the model might fall in the pitfall of frequently
changing whipsaws, i.e., buy and short signal reverses in very a very short time. To
overcome this we add a second weight to the exponential weight. The second weight which
is calculated by the divergence of the S&P 500 and the Dow Jones Index, represents the
market volatility. In a 20day training window testing within the same training data, the
revised model generates more stable predictions and a higher rate of return. The end of the
400day training and testing period generates a return of 195%.
6.2 Future Work
Rather than the predeﬁned 20day training window, the size of the training pool and
training window could be decided by a hill climbing or dynamic programming approach.
Identifying useful side information for prediction, such as developing of new indicators will
help making better predictions. Then we can extend the prediction to a form of density
function rather than simply values. This way can we output richer information about the
market movements.
Functions and how functions are mixed at each state are not studied in this thesis. This
can be a valuable work to do. Gaussian distribution is the most popular distribution when
modeling random or unknown processes. But it has been observed that many time series
may not follow the Gaussian distribution.
In this thesis, we discussed the application of the Hidden Markov Model to one single
ﬁnancial time series, more speciﬁcally, we studied the S&P 500 Composite Index. We didn’t
take the portfolio selection problem into consideration. Since diﬀerent ﬁnancial time series
have diﬀerent characteristics, a portfolio composed of diﬀerent stocks will have diﬀerent
rate of returns and risk levels. In other words, they will have diﬀerent patterns. It will be
interesting to apply the HMM technique to a portfolio of ﬁnancial assets and study the time
series generated by these groups of assets. The Viterbi algorithm could play an important
CHAPTER 6. CONCLUSION AND FUTURE WORK 83
role in this application. If we put functions that are estimated to best characterize diﬀerent
assets at diﬀerent states, the path of the Viterbi algorithm will be able to tell what assets
should be included in the portfolio, observing the price movements. [Cov91] oﬀers a nice
introduction to universal portfolio selection problem.
The double weights in the HMGM model can also be trained. These weights decide the
sensitivity of the model, so by setting up a function that studies the relationship between
sensitivity and accuracy, we can expect to ﬁnd better weights.
The outputs of the HMGM models we present in the thesis are positive and negative
symbols. A more delicate model will be able to output densities rather than symbols, i.e.,
by how much probability the market will go up or down. Furthermore, the density can be
designed to describe the probability of falling into a range of values.
Appendix A
Terminology List
outlier Outliers are a few observations that are not well ﬁtted by the best available model.
Usually if there is no doubt about the accuracy or veracity of the observation, then it
should be removed, and the model should be reﬁtted.
whipsaw A whipsaw occurs when a buy or sell signal is reversed in a short time. Volatile
markets and sensitive indicators can cause whipsaws.
trend Refers to the direction of prices. Rising peaks and troughs constitute an uptrend;
falling peaks and troughs constitute a downtrend. A trading range is characterized by
horizontal peaks and troughs.
volatility Volatility is a measurement of change in price over a given period. It is usually
expressed as a percentage and computed as the annualized standard deviation of the
percentage change in daily price.
risk Same meaning as volatility. The more volatile a stock or market, the more risky the
stock is, and the more money an investor can gain (or lose) in a short time.
indicator An indicator is a value, usually derived from a stock’s price or volume, that an
investor can use to try to anticipate future price movements.
Sharpe Ratio Also called the rewardtorisk ratio, equals the potential reward divided by
the potential risk of a position.
Exponential Moving Average A moving average (MA) is an average of data for a certain
number of time periods. It moves because for each calculation, we use the latest x
84
APPENDIX A. TERMINOLOGY LIST 85
number of time periods’ data. By deﬁnition, a moving average lags the market. An
exponentially smoothed moving average (EMA) gives greater weight to the more recent
data, in an attempt to reduce the lag.
proﬁt Proﬁt is the cumulative rate of return of a ﬁnancial time series. To calculate today’s
cumulative return, multiply today’s actual gain with yesterday’s cumulative return.
short To short means to sell something that you don’t have. To do this, you have to borrow
the asset that you want to short. The reason to sell short is that you believe the price
of that asset will go down.
Bibliography
[ADB98] A. S. Weigend A. D. Back. What Drives Stock Returns?An Independent
Component Analysis. In Proceedings of the IEEE/IAFE/INFORMS 1998
Conference on Computational Intelligence for Financial Engineering, pages
141–156. IEEE, New York, 1998.
[APM02] M. Bicego A. Panuccio and V. Murino. A Hidden Markov ModelBased
Approach to Sequential Data Clustering . In Structural, Syntactic, and
Statistical Pattern Recognition, Joint IAPR International Workshops SSPR
2002 and SPR 2002, Windsor, Ontario, Canada, August 69, 2002, Proceedings,
volume 2396 of Lecture Notes in Computer Science, pages 734–742. Springer,
2002.
[BF96] Y. Bengio and P. Frasconi. InputOutput HMM’s for Sequence Processing.
IEEE Transaction on Neural Networks, 7(5):1231–1249, 1996.
[Bil97] J. A. Bilmes. A Gentle Tutorial of the EM Algorithm and its Application to
Parameter Estimation for Gaussian Mixture and Hidden Markov Models. TR
97021. International Computer Science Institute, UC Berkeley, 1997.
[Boy83] R. A. Boyles. On the Convergence Properties of the EM Algorithm. Journal of
the Royal Statistical Society, Ser B 44:47–50, 1983.
[BP66] L. E. Baum and T. Petrie. Statistical Inference for Probabilistic Functions of
Finite State Markov Chains. Annals of Mathematical Statistics, 37:1559–1563,
1966.
[BS73] F. Black and M. Scholes. The Pricing of Options and Corporate Liabilities.
Journal of Political Economy, 81:637, 1973.
[BWT85] De Bondt, F. M. Werner., and R. H. Thaler. Does the market overreact?
Journal of Finance, 40:793–805, 1985.
[CB04] S. Chiappa and S. Bengio. HMM and IOHMM modeling of EEG rhythms
for asynchronous BCI systems. European Symposium on Artiﬁcial Neural
Networks, ESANN, 2004.
86
BIBLIOGRAPHY 87
[Cha93] E. Charniak. Statistical Language Learning. MIT Press, Cambridge,
Massachusetts, 1993.
[Chi95] G. Chierchia. Dynamics of Meaning: Anaphora, Presupposition and the Theory
of Grammar. The University of Chicago Press: Chicago, London, 1995.
[Cov91] T. Cover. Universal Portfolios. Mathematical Finance, 1(129), 1991.
[CWL96] W. Cheng, W. Wagner, and C.H Lin. Forecasting the 30year U.S. treasury
bond with a system of neural networks. NeuroVe$t Journal, 1996.
[Deb94] G. Deboeck. Trading on the edge : neural, genetic, and fuzzy systems for chaotic
ﬁnancial markets. Wiley, New York, 1994.
[DLR77] A. P. Dempster, N. M. Laird, and D. B. Rubin. Maximumlikelihood from
incomplete data via the EM algorithm. Journal of the Royal Statistical Society,
Ser B 39:1–38, 1977.
[Dor96] G. Dorﬀner. Neural Networks for Time Series Processing. Neural Network
World, pages 447–468, 1996.
[Fam65] E. F. Fama. The Behaviour of Stock Market Prices. Journal of Business,
38:34–105, 1965.
[Fam70] E.F. Fama. Eﬃcient Capital Markets: A Review of Theory and Empirical
Work. Journal of Finance, 25:383–417, 1970.
[FST98] S. Fine, Y. Singer, and N. Tishby. The hierarchical Hidden Markov Model:
analysis and applications. Machine Learning, 32, 1998.
[Fur01] S. Furui. Digital speech processing, synthesis, and recognition. Marcel Dekker,
New York, 2001.
[GI00] I. S. Gradshteyn and I.M.Ryzhik. Table of Integrals, Series, and Products.
Academic Press, San Diego, CA, 2000.
[GLT01] C. Lee Giles, S. Lawrence, and A.C. Tsoi. Noisy Time Series Prediction using
a Recurrent Neural Network and Grammatical Inference. Machine Learning,
44:161–183, 2001.
[GP86] C. W. J. Granger and P.Newbold. Forecasting Economic Time Series. Academic
Press, San Diego, 1986.
[Gra86] B. Graham. The Intelligent Investor: The Classic Bestseller on Value Investing.
HarperBusiness, 1986.
BIBLIOGRAPHY 88
[GS00] X. Ge and P. Smyth. Deformable Markov model templates for timeseries
pattern matching. In Proceedings of the sixth ACM SIGKDD international
conference on Knowledge discovery and data mining , pages 81–90. ACM Press
New York, NY, USA, 2000.
[HG94] J. P. Hughes and P. Guttorp. Incorporating spatial dependence and atmospheric
data in a model of precipitation. In Journal of Applied Meteorology, volume
33(12), pages 1503–1515. IEEE, 1994.
[HK01] J. Han and M. Kamber. Data mining: concepts and techniques. Morgan
Kaufmann, San Francisco, 2001.
[HLP88] G. H. Hardy, J. E. Littlewood, and G. Plya. Inequalities. Cambridge University
Press, Cambridge, England, 1988.
[Hul00] J. Hull. Futures, Options and Other Derivatives. PrenticeHall, Upper Saddle
River, NJ, 2000.
[Jel97] F. Jelinek. Statistical methods for speech recognition. MIT Press, Cambridge,
Mass.; London, 1997.
[JP98] T. Jebara and A. Pentland. Maximum conditional likelihood via bound
maximization and the cem algorithm. Advances in Neural Information
Processing Systems, 10, 1998.
[MCG04] M. Davis M. Crowder and G. Giampieri. A Hidden Markov Model of Default
Interaction. In Second International Conference on Credit Risk, 2004.
[Mit97] T. Mitchell. Machine Learning. McGraw Hill, New York ; London, 1997.
[MS99] C. D. Manning and H. Sch¨ utze. Chapter 9: Markov Models. In Foundations of
Statistical Natural Language Processing, Papers in Textlinguistics, pages 317–
379. The MIT Press, 1999.
[Nic99] A. Nicholas. Hidden Markov Mixtures of Experts for Prediction of Switching
Dynamics. In E. Wilson Y.H. Hu, J. Larsen and S. Douglas, editors,
Proceedings of Neural Networks for Signal Processing IX: NNSP’99, pages 195–
204. IEEE Publishing, 1999.
[PBM94] T. Hunkapiller P. Baldi, Y. Chauvin and M.A. McClure. Hidden Markov
Models of Biological Primary Sequence Infromation. In Proceedings of National
Academy of Science USA , volume 91(3), pages 1059–1063. IEEE, 1994.
[Rab89] L. R. Rabiner. A tutorial on hidden markov models and selected applications
in speech recognition. In Proceedings of IEEE, volume 77, pages 257–286, 1989.
BIBLIOGRAPHY 89
[RIADC02] B. C. Lovell R. I. A. Davis and T. Caelli. Improved Estimation of Hidden
Markov Model Parameters from Multiple Observation Sequences. In 16th
International Conference on Pattern Recognition (ICPR’02) Quebec City, QC,
Canada , volume 2, page 20168, 2002.
[RJ86] L. R. Rabiner and B. H. Juang. An introduction to hidden Markov models.
IEEE ASSP Mag., June:4–16, 1986.
[Ros03] S. M. Ross. An Introduction to Mathematical Finance. Cambridge University
Press, Cambridge, New York, 2003.
[Row00] S. Roweis. Constrained Hidden Markov Models. Advances in Neural
Information Processing Systems, 12, 2000.
[RW84] R. Redner and H. Walker. Mixture densities, maximum likelihood and the EM
algorithm. SIAM Review, 26(2), 1984.
[RY98] E. Ristad and P. Yianilos. Towards EMstyle Algorithms for a posteriori
Optimization of Normal Mixtures. IEEE International Symposium on
Information Theory, 1998.
[Sha49] C. E. Shannon. Communication Theory of Secrecy Systems. Bell System
Technical Journal, 28(4):656–715, 1949.
[Sha66] W. F. Sharpe. Mutual Fund Performance. Journal of Business, 39:119–138,
1966.
[STW99] R. Sullivan, A. Timmermann, and H. White. Datasnooping, technical trading
rule performance and the bootstrap. Journal of Finance, 54:1647–1691, 1999.
[SW97] S. Shi and A. S. Weigend. Taking Time Seriously: Hidden Markov Experts
Applied to Financial Engineering. In Proceedings of the IEEE/IAFE 1997
Conference on Computational Intelligence for Financial Engineering , pages
244–252. IEEE, 1997.
[Tha87] R. Thaler. Anomalier: The January Eﬀect. Journal of Economics Perspectives,
1:197–201, 1987.
[Wac42] S. Wachtel. Certain Observations on Seasonal Movements in Stock Prices.
Journal of Business, 15:184–193, 1942.
[WG93] A. S. Weigend and N.A. Gershenfeld. Time Series Prediction: Forecasting the
Future and Understanding the past. AddisonWesley, 1993.
[WMS95] A. S. Weigend, M. Mangeas, and A. N. Srivastava. Nonlinear gated experts
for time series: Discovering regimes and avoiding overﬁtting. In International
Journal of Neural Systems, volume 6, pages 373–399, 1995.
BIBLIOGRAPHY 90
[Wu83] C. F. J. Wu. On the Convergence Properties of the EM Algorithm. The Annals
of Statistics, 11:95–103, 1983.
[XJ96] L. Xu and M. Jordan. On Convergence Properties of the EM Algorithm for
Gaussian Mixtures. Neural Computation, 8(1):129–151, 1996.
[XLP00] M. Parizeau X. Li and R. Plamondon. Training Hidden Markov Models with
Multiple ObservationsA Combinatorial Method. In IEEE Transaction on
Pattern Analysis and Machine Intelligence, volume 22(4), pages 371–377. IEEE
pressing, 2000.
[ZG02] S. Zhong and J. Ghosh. HMMs and coupled HMMs for multichannel EEG
classiﬁcation. Proceedings of the IEEE International Joint Conference on Neural
Networks, 2:1254–1159, 2002.
APPROVAL
Name: Degree: Title of thesis:
Yingjian Zhang Master of Applied Science Prediction of Financial Time Series with Hidden Markov Models
Examining Committee:
Dr. Ghassan Hamarneh Chair
Dr. Anoop Sarkar Assistant Professor, Computing Science Senior Supervisor
Dr. Andrey Pavlov Assistant Professor, Business Administration CoSenior Supervisor
Dr. Oliver Schulte Assistant Professor, Computing Science Supervisor
Dr. Martin Ester Associate Professor, Computing Science SFU Examiner
Date Approved:
ii
Abstract
In this thesis, we develop an extension of the Hidden Markov Model (HMM) that addresses two of the most important challenges of ﬁnancial time series modeling: nonstationary and nonlinearity. Speciﬁcally, we extend the HMM to include a novel exponentially weighted ExpectationMaximization (EM) algorithm to handle these two challenges. We show that this extension allows the HMM algorithm to model not only sequence data but also dynamic ﬁnancial time series. We show the update rules for the HMM parameters can be written in a form of exponential moving averages of the model variables so that we can take the advantage of existing technical analysis techniques. We further propose a double weighted EM algorithm that is able to adjust training sensitivity automatically. Convergence results for the proposed algorithms are proved using techniques from the EM Theorem. Experimental results show that our models consistently beat the S&P 500 Index over ﬁve 400day testing periods from 1994 to 2002, including both bull and bear markets. Our models also consistently outperform the top 5 S&P 500 mutual funds in terms of the Sharpe Ratio.
iii
To my mom
iv
Acknowledgments
I would like to express my deep gratitude to my senior supervisor, Dr. Anoop Sarkar for his great patience, detailed instructions and insightful comments at every stage of this thesis. What I have learned from him goes beyond the knowledge he taught me; his attitude toward research, carefulness and commitment has and will have a profound impact on my future academic activities. I am also indebted to my cosenior supervisor, Dr. Andrey Pavlov, for trusting me before I realize my results. I still remember the day when I ﬁrst presented to him the ”super ﬁve day pattern” program. He is the source of my knowledge in ﬁnance that I used in this thesis. Without the countless time he spent with me, this thesis surely would not have been impossible. I cannot thank enough my supervisor, Dr. Oliver Schulte. Part of this thesis derives from a course project I did for his machine learning course in which he introduced me the world of machine learning and interdisciplinary research approaches. Many of my fellow graduate students oﬀered great help during my study and research at the computing science school. I thank Wei Luo for helping me with many issues regarding
A the L TEXand Unix; Cheng Lu and Chris Demwell for sharing their experiences with Hidden
Markov Models; my labmates at the Natural Language Lab for the comments at my practice talk and for creating such a nice environment in which to work. I would also like to thank Mr. Daniel Brimm for the comments from the point of view of a real life business professional. Finally I would like to thank my mom for all that she has done for me. Words cannot express one millionth of my gratitude to her but time will prove the return of her immense love.
v
Contents
Approval Abstract Dedication Acknowledgments Contents List of Tables List of Figures 1 Introduction 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 Financial Time Series . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Return of Financial Time Series . . . . . . . . . . . . . . . . . . . . . . . . . . The Standard & Poor 500 data . . . . . . . . . . . . . . . . . . . . . . . . . . Traditional Techniques and Their Limitations . . . . . . . . . . . . . . . . . . Noneﬃciency of Financial Markets . . . . . . . . . . . . . . . . . . . . . . . . Objective . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Contributions of the Thesis . . . . . . . . . . . . . . . . . . . . . . . . . . . . ii iii iv v vi ix x 1 1 2 3 5 6 7 9
Thesis Organization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 Notation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 13
2 Hidden Markov Models 2.1
Markov Models . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
vi
. . . .1 3. . . . . . . . . . . . . . .2 Discrete observation probability distribution . .1 3. . . . 16 Why HMM? . . . . . . . . 22 2. . . . . . . . . .5 3. . . . . .3 2. . . . . . . . . . . . .6. . . . . . . . . . . . . . . .3 4. . . . 32 BaumWelch Reestimation for Gaussian mixtures . . . . . . .6. . . . . . . . . . . . . . . . . . . . . .1 4. . . .2 3. . . . . . . . . . . . .6. . . . . . 29 2. . . . . . . . . . . . . . . . . 38 EM for multivariate Gaussian mixtures . . . . . . . . . . . . . . . . . . . . . . . . .5 4. . . . . . . . . . . 20 2.7 Chapter Summary . .4 2. . . . . . . . . . . . . . . . 38 . . . . . . . . . . . . . . 18 General form of an HMM . . . . . . . . . .4 4. . . . . . . . . . .7. . . . . . 47 Rewriting the Q Function . . . .5 2. . . . . . .7. . . . . . . . . . . . . . . . .2 2. . . 50 HMGM Parameter Reestimation with the Weighted EM Algorithm . . . . 31 32 3 HMM for Financial Time Series Analysis 3. . . . . . . . . . . . . . . . . .3 Previous Work . . 21 Problem 1: ﬁnding the probability of an observation . 45 46 4 Exponentially Weighted EM Algorithm for HMM 4. . . . 41 3. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58 vii . . . . . .6 A Markov chain of stock market movement . . . . . . . . . . . . . . . . .6. . . . . . . . .6 Multiple Observation Sequences . . . . . . . . . . . . . . . . . . . . . .7 Three Fundamental Problems for HMMs . . . . 34 Multivariate Gaussian Mixture as Observation Density Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42 3.3 2. . . . . . . . . . . . . . . . 42 Setup of HMM Parameters .7 Maximumlikelihood . . . . . . . . . . . .1 2. 55 HMGM Parameters Reestimation in a Form of EMA . . . . 54 Calculation and Properties of the Exponential Moving Average . . . . . . . . . . . . . 47 The Traditional EM Algorithm . . . . . . . . .8 Chapter Summary . . 37 3. . . . . . . . . . . . . . . . . .2 Multivariate Gaussian distributions . . . . .2 Making Predictions with HMM . . . . . . . . . . . . . . . . . . . 23 Problem 2: Finding the best state sequence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7. . 14 Hidden Markov Models . . .3. .2 2. . 20 Continuous observation probability distribution . . . . . . . . . 42 Making predictions . . . . . . . . .4 3. . . . . . . .6 4. . . 19 Discrete and continuous observation probability distribution . . . . . . . . . .1 3. . . . . . . . . . . . . . . . . . . .2 4. . . . . . . . . 27 Problem 3: Parameter estimation . . . . . . . . . . .2. . . . . . . . . . . . . . . . .3. . 39 Dynamic Training Pool 3. . . . . . . . . . . . . . . . . . 49 Weighted EM Algorithm for Gaussian Mixtures . . .1 2. .
.9 The EM Theorem and Convergence Property . . .2 Conclusion . . . . . . . . . . . .5 5. . . . . . . . . . . 64 5 Experimental Results 5. .1 6.4. . . . . . . . . . . . . . . . . . . . . . .8 4. . . . . . . . . . . . . . . . . . . . . . . . . . . . 82 84 86 A Terminology List Bibliography viii . . . . . . . . . . . . 63 Double Exponentially Weighted Algorithm . . . . . . . . . . .10 Chapter Summary . . . .3 5. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72 Comparisons with Previous Work . . . . .4 5. . . . . . .2 Problem with the Exponentially Weighted Algorithm . . . . . . . . . . 63 4. . . . . . . 61 The Double Weighted EM Algorithm . . .9. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81 Future Work . . . . . . . . . . . . . . . 69 Test on Data Sets from Diﬀerent Time Periods . . .1 5. . . . .6 Experiments with Synthetic Data Set 65 . . . . . .1 4. . . . . . . . . . 67 HMGM Experimental Results . . . . . .2 5. . 71 Comparing the Sharpe Ratio with the Top Five S&P 500 Mutual Funds . . . . . . . . . . . . . . . . . . 79 81 6 Conclusion and Future Work 6. . . 63 4. . . . . . . . . . . . . . .9. . . . . . 65 Recurrent Neural Network Results . . . . . .
. . . . . . .3 Comparison of the Sharpe Ratios during the period of March 8. . . . . . 67 5. . . . . . . . . .2 2. . . . . . . . . . .1 Comparison of the recurrent network and exponentially weighted HMGM on the synthetic data testing. . 1999 to March 7. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2002. . . . 2002 to Jan 7. . . . . . . . . . and has less volatility. . The absolute value of the positive one is much smaller than the HMGM prediction. Four of the ﬁve funds have negative Sharpe Ratios. . .1 Data format of the experiment (for the segment from Jan 2. 5 Notation list . . . . . . . . The Double weighted HMGM consistently outperforms the top ﬁve S&P 500 mutual funds. . . . . . . . . . As the market move from one day to another. The EWHMGM outperforms the recurrent network in overall result. . . . . .List of Tables 1. . . . . . . 78 ix . 12 State transition probability matrix of the HMM for stock price forecast. . . . . . 78 5. .2 Comparison of the Sharpe Ratio between the HMM and the top 5 S&P 500 funds during the period of August 5. . . . 2001 to October 11. . . . . . . 2001. . . . . . . . . . . . . . . . . . . . the professional might change his strategy without letting others know .1 1. . . . 18 5. . . . . 2002) . . . . . . . . . . . . . . . .
4 A Super Five Day Pattern in the NASDAQ Composite Index from 1984 to 1990. However. . .2 The ﬁgure shows the set of strategies that a ﬁnancial professional can take. . . Each of them will contributing a percentage to the combined output in the mixture. .5 2.2 The return curve of a prediction system. . . The states are associated with diﬀerent strategies and are connected to each other. . . . . . . . . . . .4 2. . .List of Figures 1. . . UC. . . . . . . . . . As time goes by. . . . . . . . . . . . . $1 input at the beginning of the trading period generates a return of $2. . 24 The backward procedure . . . . . . . . . . 17 2. the model moves from one state to another. . . SD.3 The trellis of the HMM. . . . . . 8 2. . . . 29 Three single Gaussian density functions. . . . . . . . . . . . . . . . . These probabilities are hidden to the public. . . . . . . . . . . . The strategies are modeled as states. . 35 x . . . . Each of the nodes in the graph represent a move. . . .1 1. . . . . . . . . . . only the professional himself knows it. . . . . . the pattern diminished in the early 1990s. . . . .1 The forward procedure . . . SR. . . . . . . . . . just as the stock price ﬂuctuates everyday. . . . . . . 26 Finding best path with the Viterbi algorithm . . . . . . . . Each state produces an observation picked from the vector [LR. .1 while the index drops below 1. . . . The ﬁrst three days and the last two days tend to have higher return than the rest of the trading days. . LD]. Each strategy is associated with a probability of generating the possible stock price movement. . . . . . . 17 2. . .1 Modeling the possible movement directions of a stock as a Markov chain. . . . . . . . . . . . . . . . .6 3. . 15 2. . . . . . . . . . . .
. . . . . . . . . . . . . . .4 The prediction falls behind the market during highly volatile periods of time. . . . . 72 Prediction with HMGM for 400 days of the S&P 500 Index. . . . . . . . . . 59 4. . . . . . . . . . 67 Prediction of the NASDAQ Index in 1999 with a recurrent neural network. . . . 68 Prediction of the 400day S&P 500 Index starting from Jan 2. . . . . . . . . . . . . . . . . 56 4.9 Experimental results on computer generated data. and 50% of probability by the third Gaussian. . . . . .2 The portion of each of the ﬁrst 19 days’ EMA in calculating the EMA for the 20th day. . .2 A Gaussian mixture derived from the three Gaussian densities above. . . . . . . .com) . . This is because the system is too sensitive to recent changes. . . As is shown in the ﬁgure. . .3 3. . . . . . . . . . . .4 4. the HMM was not able to catch up with the change in trend swiftly. . Note from t213 to t228. . . . .4 5. Training window size = 20 Prediction of the 400day S&P 500 Index starting from Jan 2. . . . . The data earlier than day 10 take up a very small portion but they are still included in the overall calculation . . . . .8 5. . . When the 30day moving average declines below the 100day moving average. . .1 The dynamic training pool . . . . Training window size = 40 Prediction of the 400day S&P 500 Index starting from Jan 2. . . . 71 Prediction of the 400day S&P 500 Index starting from Jan 2. . . . . . . . 43 When the 30day moving average moves above the 100day moving average. . . . . . . . . . . . . (picture from stockcharts. . .2 5. .3 5.3 The portion of each of the 20 days’ actual data in calculating the EMA for the 20th day. . . . 1998. . . . . 1998. . . the trend is considered bullish. . . . .1 5.6 5. . . . . The last day account for 1/3 of the EMA at day 20. . . . . . . . . . For each small area δ close to each point x on the x axis.5 5. . . . . . Training window size = 10 . . . . . . . . . . . . the EMA at the 19th day accounts for 2/3 of the EMA at day 20. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41 Hidden Markov Gaussian Mixtures . . Training window size = 100 . 69 . . . . . . . . 30% of probability that the distribution of x is governed by the second Gaussian. . . . . . . . . . . . . . 70 . 1998. . . . . 1998. . .7 5. . . . . .3. . there is a probability of 20% that the random variable x is governed by the ﬁrst Gaussian density function. . . . . . . . . . the trend is considered bearish. . . . . . . . . . . . . . . . . 36 3. . . . . . . . . . . . . . . . . . . 68 Prediction of the NASDAQ Index in 2000 with a recurrent neural network. . . . . . . . . . . . . . 73 xi . 66 Prediction of the NASDAQ Index in 1998 with a recurrent neural network. . . 63 5. . . 58 4. . . . . .
18 Too many positive signals result in a curve similar to the index. 76 5. . 75 5. . . . . 73 5. . . . 77 5. . 1996 . 2002 . . . . . . . . . 1998 . 80 xii . . . . . 2001 . 75 5. . . . . . . . . . . . . . . . 1996 to December 31. .15 Results on the period from June 4. . .17 Results on the period from March 8. . . . . . .14 Results on the period from November 2. . . . . . . . 1994 to June 3. . . . . . . .5. . . . . 76 5. . . . . . . .10 Prediction with multivariate HMGM for 400 days of the S&P 500 Index. . 2001 to October 11. 74 5. . . . . .13 Results from all models for comparison. .12 Prediction with double weighted HMGM that has a conﬁdence adjustment variable. . .16 Results on the period from August 5. . .11 Prediction with single exponentially weighted HMGM . . . . . . . . 1999 to March 7. . . . 74 5. . . . . . . .
our experiment data include the daily data of NASDAQ Composite Index. Similar to traditional ﬁnancial engineering. motivation and objective of our machine learning model. This chapter describes the basic concepts in ﬁnancial time series. which is a weighted average of 30 signiﬁcant stocks. Over the past 50 years. In this thesis. What distinguish us from the previous work is rather than building models based on regression equations. More speciﬁcally. All the ﬁnancial analysts carry out many kinds of research in the hope of accomplishing one goal: to beat the market. there has been a large amount of intensive research on the stock market. we build models to analyze and predict ﬁnancial time series. In this thesis we will focus our research on the most volatile and challenging ﬁnancial market – the stock market. the diﬃculties of accurate ﬁnancial time series prediction. and the S&P 1 . The organization of the thesis is also outlined in the later part this chapter. the average rate of return is the Dow Jones Industrial Index . we apply a machien learning model–the Hidden Markov Model to ﬁnancial time series.1 Financial Time Series Financial time series data are a sequence of prices of some ﬁnancial assets over a speciﬁc period of time.Chapter 1 Introduction This thesis explores a novel model in the interdisciplinary area of computational ﬁnance. 1. the limitations of regression models. To beat the market means to have a rate of return that is consistently higher than the average return of the market while keeping the same level of risk as the market. the Dow Jones Industrial Index and the S&P 500 Index.
industry. The theoretical basis of technical analysis is: price reﬂects all the relevant information. there is an inevitable analyst bias and accompanying subjectivity. For example. We will focus only on methods of technical analysis in this thesis. to forecast future prices of an individual stock. 1. we use forecast and prediction alternatively to represent the process of generating unseen data in a ﬁnancial time series. The oneperiod simple net return R t of a ﬁnancial time series is calculated with the following formula: . In this thesis. and company analyses to derive the stock’s current fair value and forecast its future value. it is very time consuming: by the time fundamental analysts collect information of the company or economy health and give their prediction of the future price. history repeats itself. Let Pt be the price of an asset at time index t. If fair value is not equal to the current stock price. Second. And all these are derived from the belief in the noneﬃciency of the ﬁnancial markets. In our experiment we use the S&P 500 index as the benchmark. There are some inherent weaknesses in fundamental analysis. Usually we have a benchmark series to compare against. the current price has already changed to reﬂect the most updated information. We will discuss the market eﬃciency hypothesis later in this chapter and the evidence of noneﬃciency in the market. which is a combination of 500 stocks. In our experiments we base our forecast of the daily stock price on the past daily prices. and individual companies. industry sectors. Generally there are two main streams in ﬁnancial market analysis: fundamental analysis and technical analysis. INTRODUCTION 2 500 Index. fundamental analysts believe that the stock is either over or under valued and the market price will ultimately gravitate toward fair value. First.CHAPTER 1. fundamental analysis combines economic. Fundamental analysis is the examination of the underlying forces that aﬀect the wellbeing of the economy. Technical analysis is the examination of past price movements to forecast future price movements.2 Return of Financial Time Series One of the most important indicators of measuring the performance of mutual funds or prediction systems is the return of the system. price movements are not totally random.
. The index reﬂects the total market value of all component stocks relative to a particular period of time. For example. the higher the return curve will be above the index curve. Normally we care more about the return than the accuracy rate of the prediction because the simple net return at each day is diﬀerent. the return at the end of the period would be roughly 25 times the initial input. the return at the end of the period is a cumulative return that is composed of all the periods: 1 + Pt [k] = (1 + R1 )(1 + R2 ) . If we invest 1 dollar at the beginning of the period. . Unlike the Dow Jones Industrial Average. The S&P 500 Index is viewed as one of the best indicators of the US economy health. we will get $2.1) For a kperiod ﬁnancial time series.3 The Standard & Poor 500 data The real world ﬁnancial time series we input into the HMM prediction system is the daily return of the Standard & Poor 500 Index (S&P 500). The higher the prediction accuracy. we only predict the direction of the time series. (1 + Rk ) k = t=1 (1 + Rt ) (1.1 at the end of the period. The S&P 500 index is a weighted average of the stock prices of 500 leading companies in leading industry sectors of the US. 1.2) In developing a prediction system. To . INTRODUCTION 3 Rt = Pt − Pt−1 Pt−1 (1. two days of accurate predictions of small changes may not oﬀset the loss of one day’s incorrect prediction of a large change in the market. Figure 1. This will result in a return curve for the prediction system. In this thesis. Prediction of ﬁnancial time series is a very extensive topic. If one get an accuracy 100% for any 400 consecutive days in the ten year period 1987 to 1994. generating a signal of either up or down for each trading day.CHAPTER 1. our goal is to make as many accurate predictions as possible. the S&P 500 represents the market value of the 500 component stocks. which is an average of the 30 component stock prices.1 shows the return based on a strategy using some prediction system. This is the upper bound for the return.
In some experiments we use a second sequence of data: the volume. These are the reverse signals in a long term trend.1: .2.1 while the index drops below 1. also called the whipsaws(see 3. An example of the data format is shown in Table 1. We need to identify the real trend change signals from the noisy whipsaws.1: The return curve of a prediction system. Because it looks at the total market value and includes stocks from diﬀerent industries than the Dow. INTRODUCTION 4 2.6 return 1. we ﬁrst add up the total market value of all the 500 stocks. The Dow is a less sensitive index than the S&P 500 so we use it to help smooth the prediction.2 prediction market 2 1.4 1. The return of the S&P 500 Index for each day is calculated using the techniques introduction in Section 1.8 1.1).8 0 50 100 150 200 trading day 250 300 350 400 Figure 1. One reason to use another time series to facilitate the prediction is that there are sideway movements in the long term trends. The price we use for the calculation is the close price for each day. calculate the S&P 500 Index. $1 input at the beginning of the trading period generates a return of $2. the S&P 500 has some diﬀerent characteristics from the Dow. then divide them by the total number of outstanding shares in the market. In some scenarios of the experiments we also include the Dow Jones Index that span during the same time period as the S&P 500 Index.2 1 0.CHAPTER 1.
The basic idea is as follows: To make things simple. We have to identify whether an irrational price movement is noise or is part of a pattern. October 19. Before we go on to the machine learning solution to the problem.6 percent without any obvious reason. This method is rather crude but may work for deterministic linear trends.89 Return 0. Then work out the weights given some form of noise. The BlackScholes model is a statistical model for pricing the stock option at a future time based on a few parameters. in the BlackScholes option pricing model.006213 0.27 1172. people use various forms of statistical models to predict volatile ﬁnancial time series [GP86].4 Traditional Techniques and Their Limitations Traditionally. assume the time series follow a linear pattern. For example. INTRODUCTION 5 Date Jan22002 Jan32003 Jan42002 Jan72002 Close 1154.67 1165. y t = a + b × yt−1 + noise.1: Data format of the experiment (for the segment from Jan 2. The econometrics method usually proposes a statistical model based on a set of parameters.0065 Volume 1418169984 1874700032 1943559936 1682759936 Table 1. 1987. Most of these statistical models require one assumption: the form of population distribution such as Gaussian distributions for stock markets or binomial distribution for bonds and debts markets [MCG04]. as the Dow Jones Industrial Index did on Monday. Classical econometrics has a large literature for the time series forecast problem. where nonlinear formulation is very hard to ﬁnd. Perhaps the most prominent of all these models is the BlackScholes model for stock option pricing [BS73] [Hul00]. 2002 to Jan 7. The process of the estimation of these parameters will bring in human analyst bias.00918 0. . some of these parameters must be estimated based on other current situations. let’s take a short review of the econometrics method. Sometimes stocks move without any apparent news. For nonlinear trends. But sometimes this linear regression predicting the target values from the time.00574 0. 2002) 1.51 1164. It fell by 22. 2 one needs to use a nonlinear regression such as y t = a × yt−1 + b × yt−1 . As these models are independent of the past prices.CHAPTER 1. We then ﬁnd a a and b are regression weights.
Another inherent problem of the statistical methods is that sometimes there are price movements that cannot be modeled with one single probability density function (pdf ). r) = e−rt E[(seW − K)+ ] = E[(se−σ 2 t/2+σ = E[(seW −rt − Ke−rt )+ ] √ t − Ke−rt )+ ] (1. These four parameters are ﬁxed and can be easily identiﬁed. W is a is to pick a segment of past price data. The EMH “rules out the possibility of trading systems based only on currently available information that have expected proﬁts or returns in excess of equilibrium expected proﬁt or return” [Fam70]. σ. there are times that we cannot ﬁnd the best approximation function. In [Ros03].5 Noneﬃciency of Financial Markets In a classic statement on the Eﬃcient Market Hypothesis (EMH). For diﬀerent time windows. Arbitrage opportunities usually surface after a takeover oﬀer. The only way to decide it normal random distribution. normal random variable with mean (r − σ 2 /2) and variance σ 2 t. t is the exercise time of the option. Fama [Fam65] [Fam70] deﬁned an eﬃcient ﬁnancial market as one in which security prices always fully reﬂects the available information. r is the interest rate. The example shows rather than just one function. These four pdf s must work together with each of them providing a contribution at diﬀerent time points. K. we see an experiment on the crude oil data. these are four distributions that determine the diﬀerence between the logarithm of tomorrow’s price and the logarithm of today’s price. INTRODUCTION 6 the noarbitrage1 option cost is calculated as: C = C(s. In plain English. there are diﬀerent patterns thus cannot be described with one stationary model. This can be caused by the rapid change in the data patterns. . an average investor cannot hope to 1 Arbitrage is the simultaneous buying and selling of securities to take advantage of price discrepancies.3) s is the security’s initial price. It has been agreed that no single model can make accurate predictions all the time. t. then assume the logarithm of this data follows the the logarithm of the prices follows the normal random distribution is rather subjective. Finally. K is the strike price.CHAPTER 1. The choosing of the price segment and the assumption that 1.
This is called a random walk of the market. But this does not mean the market is fully eﬃcient as the process took a long time and there may have evolved other new patterns that are yet to ﬁnd out. There is a super ﬁve day pattern in the NASDAQ Composite Index from 1984 to 1990. This means the ﬁrst three days and the last two days of each month generate a higher return in the index than any other day of the month. INTRODUCTION 7 consistently beat the market. After 1990. such as missing values [HK01]. De Bondt et. For small companies. the pattern became more random and less recognizable. . If equal performance is obtained on the random walk data as compared to the real data then no signiﬁcant predictability has been found. which means it requires a perfect combination of sophistication in the prediction system design and insight in the input data preprocessing. data multiplication [WG93]. They derive enhanced features of interest from the raw time series data. A more prominent example is the socalled January Eﬀect [Wac42] [Tha87].CHAPTER 1. Data mining people have developed some very useful techniques of dealing with data. Both areas have been extensively researched. The EMH was met with harsh challenges both theoretically and empirically shortly after it was proposed. The shape of the return curve thus looks like a parabola. This phenomenon was observed many years after Wachtel’s initial observation and discussion. Our own program also ﬁnds some interesting patterns. Price by Volume. We believe that a successful ﬁnancial time series prediction system should be hybrid and custom made. They study the stock price of two groups of companies from 1933 to 1985.6 Objective Financial time series consists of multidimensional and complex nonlinear data that result in of pitfalls and diﬃculties for accurate prediction. Traders and technical analysts also have done lots of work. [BWT85] compare the performance of two groups of companies: extreme losers and extreme winners. such as the variety of indicators including Moving Average Convergence Divergence (MACD). and the best prediction for a future price is the current price. They ﬁnd that the portfolios of the winners chosen in the previous three years have relatively low returns than the loser’s portfolio over the following ﬁve years. 1. there are superior returns around the end of the year and in early January than other times of the year. Interestingly the January eﬀect has disappeared in the last 15 years.
2: A Super Five Day Pattern in the NASDAQ Composite Index from 1984 to 1990. However.CHAPTER 1. The ﬁrst three days and the last two days tend to have higher return than the rest of the trading days. the pattern diminished in the early 1990s. INTRODUCTION 8 80 daily return 60 40 20 return 0 20 40 60 0 5 10 trading day 15 20 25 Figure 1. .
and the transformation matrix are all updated dynamically to cater to the nonstationary ﬁnancial time series data. Gaussian mixtures have desirable features in that they can model series that does not fall into the single Gaussian distribution. We then develop a novel exponentially weighted EM algorithm that solves the second and third diﬃculties at one stroke. it is usually hard to determine the usefulness of information. The revised EM algorithm gives more weight to the most recent data while at the same time adjust the weight according to the change in volatility. First. Second. The major contributions are: . Techniques from the two areas are interweaved. there is no single ﬁxed models that work all the time. Third. This thesis aims at solving all these three problems with a Hidden Markov Model(HMM) based forecasting system. Then the parameters of the HMM are updated each iteration with an adddrop ExpectationMaximization (EM) algorithm. some of which have been conﬁrmed to pertain useful information [STW99]. an eﬃcient system must be able to adjusting its sensitivity as time goes by. There are three major diﬃculties about accurate forecast of ﬁnancial time series. INTRODUCTION 9 Relative Strength Index (RSI) etc. i. Hidden Markov Models (HMM)[SW97] and so on. Longterm and shortterm series balance is then found throughout the combined trainingforecast process. such as Back Propagation Network [CWL96]. The volatility is calculated as the divergence of the S&P Index from the Dow Jones Composite Index. Nearest Neighbor [Mit97]. The HMM has a Gaussian mixture at each state as the forecast generator. Genetic Algorithm [Deb94]. there have been several straightforward approaches that apply a single algorithm to relatively unprocessed data. It is included as new information that help make better judgment. it is hard to balance between longterm trend and shortterm sideway movements during the training process. the weight of each Gaussian component in the output. 1. At each timing point.CHAPTER 1. Misleading information must be identiﬁed and eliminated. the parameters of the Gaussian mixtures.e. the patterns of wellknown ﬁnancial time series are dynamic.7 Contributions of the Thesis This thesis is an interdisciplinary work that combines computer science and ﬁnancial engineering. On the other hand. In other words.
8 Thesis Organization Chapter 2 of this thesis introduces general form of HMMs. We develop an exponentially weighted EM algorithm. Chapter 3 describes an HMM with Gaussian mixtures for the observation probability density functions and derives the parameter reestimation formulas based on the classic EM algorithm. This is one of the ﬁrst large scale applications to ﬁnancial time series. especially when training data set is relatively large. There are few applications of Hidden Markov Model with Gaussian Mixtures in timedependent sequence data. Then in chapter 5. we prove that the convergence of the two proposed algorithms is guaranteed. 8. Using the techniques from the EM Theorem. We also derive our revised exponentially . we propose a double weighed EM algorithm. 1. The concept of the dynamically updated training pool enables the system to absorb newest information from data.CHAPTER 1. 3. Based on the exponentially weighted EM algorithm. We show the weighted EM algorithms can be written in a form of Exponentially Moving Averages of the model variables of the HMM. 5. This allows us to take the advantage of this existing econometrics technique in generating the EMbased reestimation equations. 4. including multiple observation sequence and multivariate Gaussian mixtures as pdfs. The double weighted EM algorithm solves the drawback of the single exponentially weighted EM caused by oversensitivity. Experimental results show our model consistently outperform the index fund in returns over ﬁve 400day testing periods from 1994 to 2002. INTRODUCTION 10 1. This algorithm realizes that recent data should be given more attention and enables us to recognize trend changes faster than the traditional EM algorithm. The proposed model also consistently outperforms toplisted S&P 500 mutual funds on the Sharpe Ratio. 2. some detailed aspects of the HMM are studied. 7. 6. We develop a novel dynamic training scheme.
Chapter 6 shows the experimental results and concludes the thesis. These symbols are used in the derivations of the reestimation formulas and proof in chapters 2.9 Notation We list the Roman and Greek letters used in this thesis for reference. 1. INTRODUCTION 11 weighted EM algorithm and the new parameter updating rules in this chapter. 3 and 4. Future work that indicate possible improvements of the model are also included in chapter 6.CHAPTER 1. .
of being at state i at time t Prob. j) γi (t) δi (t) δim (t) ψt X Y Z η ζ ρ δim (T ) δi (T ) θj Θ L Notation The state at time t Probability of being at state i at time 0 Probability of moving from state i to state j Probability of being at state j and observing o t Mixture weight for the k th component at state j The observation sequence The tth observation Forward variable in HMM Backward variable in HMM Prob.CHAPTER 1. of the best sequence ending in state j at time t Prob. of being at state i at time t. and state j at t + 1 Prob. of the best sequence ending at the m th component of the ith state The node of the incoming arc that lead to the best path Observed data Hidden part governed by a stochastic process Complete data set Exponential weight imposed on intermediate variables in EM Selfadjustable weight in double weighted EM The multiplier in calculating EMA The EMA of δim at time T The EMA of δi at time T Parameters of the j th component in a Gaussian mixture Parameters of a Gaussian mixture The likelihood function Table 1. INTRODUCTION 12 Symbol st πi aij bj (ot ) wjk O ot αi (t) βi (t) pt (i.2: Notation list .
the system takes a move to one of the states according to a set of state transition probabilities P .1 Markov Models Markov models are used to train and recognize sequential data. We denote the state at time t as s t . Consider slot t. In a Markov model. biological sequences. each observation in the data sequence depends on previous elements in the sequence. [RJ86] and [Rab89] provide a thorough introduction to the Markov process. There is no need to look into the admission rate of the previous a system where there are a set of distinct states. In many cases. 2. such as speech utterances. N }. For example. . the prediction of the next state and its associated observation only depends on the current state.Chapter 2 Hidden Markov Models This chapters describes the general Markov process and Hidden Markov Models (HMMs). . . This is called a ﬁrst order Markov process. knowing the number of students admitted this year might be adequate to predict next year’s admission. S = {1. 2. Hidden Markov Models and the main problems involved with Hidden Markov Models. At each discrete time 13 . . temperature variations. These discussions form the base of our modeling and experiments with ﬁnancial time series data. and other sequence data. We start by introducing the properties of the Markov process. then the characteristics of the HMMs. meaning that the state transition probabilities do not depend on the whole history of the past process.
small From the model in ﬁgure we are able to answer some interesting questions about how this stock behaves over time. small rise. can be calculated as: P (XA. Xt ) = P (Xt+1 = sk Xt ) (Limited horizon) = P (X2 = sk X1 ) (Time invariant) transition matrix A: aij = P (Xt+1 = sj Xt = si ) aij is a probability. no change. . In the ﬁgure. no change. 2. π) = P (1)P (21)P (32)P (23)P (22)P (42) = π ∗ a12 ∗ a23 ∗ a32 ∗ a22 ∗ a24 First we can deﬁne the state sequence as X = {1. 5 represent a possible movement vector {large rise. (2. 3. 2. . ∀i. the initial state 2. HIDDEN MARKOV MODELS 14 years.4) (2. jΣN aij = 1. These are the Markov properties described in [MS99]: P (Xt+1 = sk X1 . j=1 distribution: πi = P (X1 = si ) Here. 4. Given the Markov chain. 4A. no change. . . We present a ﬁve state model to model the movement of a certain stock(See Figure 2. we can have the following state Also we need to know the probability to start from a certain state. large rise” in six consecutive days? the probability of seeing the above sequence.CHAPTER 2. no change.6) (2.1).2 A Markov chain of stock market movement In this section we use a Markov chain to represent stock movement.7) (2. the states from which the observations are produced and the probabilistic functions are known so we can regard the state sequence as the output.8) . 3. 2. 2. small drop.5) (2.3) (2. ΣN πi = 1.1) (2. hence: aij ≥ 0. large drop}. rise. 2. π) = P (1. P (XA. (2. 4}.2) Because of the state transition is independent of time. 2. π). 2. i=1 In a visible Markov model. 3. For example: What is the probability of seeing “small drop. nodes 1.
CHAPTER 2.200 3 sd/0.200 sr/0.400 ld/0.200 uc/0.400 sr/0.200 ld/0.100 1 sd/0.400 4 lr/0.200 lr/0. Each of the nodes in the graph represent a move.400 sd/0.100 Figure 2.200 sr/0. just as the stock price ﬂuctuates everyday. the model moves from one state to another. HIDDEN MARKOV MODELS 15 sd/0.200 sd/0.200 sr/0.400 uc/0.200 ld/0.100 sr/0.100 uc/0.1: Modeling the possible movement directions of a stock as a Markov chain.100 2 uc/0.100 0 ld/0.100 lr/0.100 ld/0. As time goes by. .200 uc/0.100 lr/0.100 lr/0.
XT can be calculated as the product of the transition probabilities: P (XA. etc). In an HMM. which is associated with state j. .12) Figure 2.CHAPTER 2. the transition probabilities. Therefore we extend it to a model with greater representation power. small rise} if the prediction starts by taking strategy To answer the ﬁrst question. Instead of combining each state with a deterministic output(such as large rise. HIDDEN MARKOV MODELS 16 More generally. Now how does the professional make his prediction? What is the probability of seeing 2 on the ﬁrst day? the prediction sequence {small drop. and large rise) on a certain day. . At time t.11) πXt Xt+1 2. no change. The movement set has all the movement symbols and each symbol is associated with one state. . with the probability: bj (ot ) = P (ot Xt = j) (2. Each of the ﬁve strategies is a state in the HMM. think of HMM as a ﬁnancial expert. see Figure 2. The number of states. Assume the professional has ﬁve investment strategies. and from which state an observation is generated are all unknown. the Hidden Markov Model (HMM).3 Hidden Markov Models The Markov model described in the previous section has limited power in many applications.10) (2. each of them gives a distinctive prediction about the market movement (large drop.1. π) = P (X1 )P (X2 X1 )P (X3 X1 . . Also assume he performs market prediction everyday with only one strategy. . XT −1 ) = P (X1 )P (X2 X1 )P (X3 X2 ) · · · P (XT XT −1 ) = T −1 t=1 (2. one does not know anything about what generates the observation sequence.9) (2. the probability of a state sequence X 1 . Each strategy has a diﬀerent probability distribution for all the movement symbols.2 shows the example of an HMM that models an investment professional’s prediction about the market based on a set of investment strategies. an observation ot is generated by a probabilistic function b j (ot ). . Each state is connected to all the other states with a transition probability distribution.3 and Table 2. . . each state of the HMM is associated with a probabilistic function. small drop. small rise. small drop. . X2 ) · · · P (XT X1 .
the HMM will pick a particular strategy to follow one that was taken based also on the observation probability. The key to the HMM performance is that it can pick the best overall sequence of strategies based on an observation sequence. LD]. HIDDEN MARKOV MODELS 17 Strategy 1 Strategy 2 Strategy 3 Strategy 4 Strategy 5 LR SR UC SD LD 10% 40% 20% 15% 5% 15% 30% 30% 15% 10% 5% 5% 20% 40% 30% 40% 30% 20% 5% 5% 20% 20% 20% 20% 20% Figure 2. Each strategy is associated with a probability of generating the possible stock price movement. only the professional himself knows it. The steps for generating the prediction sequence: . SR. The states are associated with diﬀerent strategies and are connected to each other.CHAPTER 2. Each state produces an observation picked from the vector [LR. Introducing density functions at the states of the HMM gives more representation power than ﬁxed strategies associated with the states. These probabilities are hidden to the public. UC. The strategies are modeled as states.3: The trellis of the HMM.2: The ﬁgure shows the set of strategies that a ﬁnancial professional can take. Unlike the Markov chain of the previous section. SD. Strategy 1 Strategy 1 Strategy 1 Strategy 2 Strategy 2 Strategy 2 Strategy 3 Strategy 3 Strategy 3 Strategy 4 Strategy 4 Strategy 4 Strategy 5 Day1 Strategy 5 Day2 Strategy 5 Day3 Figure 2.
otherwise terminate. To answer the second question.2 × 0. Especially in the case of ﬁnancial time series analysis and prediction.3 + 0.05 + 0. We know the prediction starts with strategy 2. Just like in the above example. Then there are ﬁve possible states for the second day. according to the state transition probability distribution. Set t=t+1. Get the prediction according to the strategy of the current state i. So the probability of seeing the movement sequence {small drop. Then we get the prediction for the current day. 3. through diﬀerent state sequences.1: State transition probability matrix of the HMM for stock price forecast. the probability of seeing a large rise prediction on the ﬁrst day if we take strategy 2 is 15 4. b ij (ot ).2 = 0. which means the initial state is state 2. the professional might change his strategy without letting others know 1. Choose an initial state(i.2 × 0. 5. if t ≤ T . where the data can be thought of being generated by some underlying stochastic process that is not known to the public. since we are at the ﬁrst day of the sequence. HIDDEN MARKOV MODELS 18 Probability Strategy1 Strategy2 Strategy3 Strategy4 Strategy5 Strategy1 10% 10% 20% 30% 30% Strategy2 10% 20% 30% 20% 20% Strategy3 20% 30% 10% 20% 20% Strategy4 30% 20% 20% 15% 15% Strategy5 30% 20% 20% 15% 15% Table 2.1 × 0.CHAPTER 2.e.e. Transit to a new state Xt+1 .3 × 0. i. For example. 2.3 + 0.15 + 0.4 Why HMM? From the previous example. we can see that there is a good match of sequential data analysis and the HMM. small rise} is: 0. sum up all the probabilities the movement sequence may happen. go to step 3. As the market move from one day to another. if the professional’s strategies and . Set the time step t = 1. a strategy) X 1 = i according to the initial state distribution Π.2 × 0.365 2.4 + 0.
. The state at time t is denoted s t . 2.etc. . We show a revised EM algorithm in later chapters that gives more weight to recent training data yet also trying to balance the conﬂicting requirements of sensitivity and accuracy. . The general HMM approach framework is an unsupervised learning technique which allows new patterns to be found. bioinformatics [PBM94]. the Expectation Maximization(EM) algorithm provides an eﬃcient class of training methods [BP66]. N } is the set of states. Weigend and Shi [SW97] have previously applied HMMs to ﬁnancial time series analysis. we can create an HMM architecture and the EM algorithm allows us to ﬁnd out the best model parameters that account for the observed training data. As shown in the example we can see the HMM has more representative power than the Markov chain. In fact. See [ADB98]. semiconductor malfunction [GS00][HG94].5 General form of an HMM An HMM is composed of a ﬁvetuple: (S. without having to impose a “template” to learn. The transition probabilities as well as the observation generation probability density function are both adjustable. 1. B). M possible movements. . K. Π. In a discrete observation density case. mathematicians and most recently computer scientists. kM } is the output alphabet. is the number of observation choices. what drives the ﬁnancial market and what pattern ﬁnancial time series follows have long been the interest that attracts economists. such as weather data. We compare our approach to theirs in Chapter 5. HMMs have been applied to many areas. In the above example. . Given plenty of data that are generated by some hidden power. K = {k1 . . HIDDEN MARKOV MODELS 19 the number of his strategies are unknown.CHAPTER 2. A. . M equals the number of . They are widely used in speech recognition [Rab89][Cha93]. . It can handle variable lengths of input sequences. and diﬀerent time series analysis. Besides the match between the properties of the HMM and the time series data. 2. we can take the imaginary professional as the underlying power that drives the ﬁnancial market up and down. S = {1.
In the previous example.no change. HIDDEN MARKOV MODELS 20 3. .15) After modeling a problem as an HMM. v2 . the observation symbol probability density function will be in the form: bj (ot ) = P (ot = kst = j). Also we can train the model parameters based on the observed data and get a more accurate model. and assuming that some set of data was generated by the HMM. 1 ≤ k ≤ M (2. i.1 Discrete and continuous observation probability distribution Discrete observation probability distribution There are ﬁxed number of possible observations in the example in section 2.3. After the vector quantization.14) (2. . large rise}. The function at each state is called a discrete probability density function. small drop.16) movement as a ﬁveelement vector {large drop. a codebook is created and the following analysis and prediction are with the domain of the codebook. State transition probability distribution A = {a ij }. 2.6 2. . we might want to model the direction of the price This partitioning process is called vector quantization. The probabilistic function for each state j is: bj (ot ) = P (ot st = j) (2. . Then use the trained model to predict unseen data. vM .CHAPTER 2. In ﬁnancial time series analysis. we sometimes need to partition probability density function of observations into discrete set of symbols v1 .6. For example. j ≤ N (2. aij = P (st+1 st ). [Fur01] provides a survey on some of the most commonly used vector quantization algorithms. j ∈ S. Initial state distribution Π = {π i }.13) 5. . Observation symbol probability distribution B = b j (ot ). 1 ≤ i. we are able to calculate the probabilities of the observation sequence and the probable underlying state sequences. small rise. πi is deﬁned as πi = P (s1 = i) 4. i ∈ S.
. . it will make more sense to include the prices of Microsoft. please refer to [Mit97] and [MS99]. j = 1. µjk . N . This Ddimensional multivariate time series training requires that we pick the most correlated time series as input. However they have limited representation power. HIDDEN MARKOV MODELS 21 Using discrete probability distribution functions greatly simpliﬁes modeling of the problem. in order to predict the price of IBM. wjk ≥ 0. For details in mixtures . k = 1. N . Σjk ) of Gaussian distributions. the function b j (ot ) is in the form of a continuous probability density function(pdf) or a mixture of continuous pdf s: M bj (ot ) = k=1 wjk bjk (ot ).19) Then the task for training is to learn the parameters of these pdf s. The dimension of the multivariate time series cannot be too large as it increases computation complexity by quadratic factor. . .CHAPTER 2. We will describe more about this subject in Chapter 3. . . . . The mixture weights have the following constraints: M k=1 wjk = 1. . . Another problem is the selection of the pdf for each mixture.6. . the codebook is used to estimate the probability of each possible symbol and produce the most probable one. j = 1. . Then in the prediction step. . Distribution. The most used Ddimensional logconcave or elliptically symmetric density is the Gaussian density. . N (2. whose behavior have less correlation with that of IBM. Sun and other high tech stocks rather than include Exxon or McDonald’s.18) Each bjk (ot )is a Ddimensional logconcave or elliptically symmetric density with mean vector µjk and covariance matrix Σjk : bj k(ot ) = N (ot . . j = 1. To solve this problem.17) M is the number of the mixtures and w is the weight for each mixture. we will need to ﬁnd out the most correlated factors to our prediction. An automatic method for dimension reduction is Principal Component Analysis(PCA). M (2. 2. or Normal (2.2 Continuous observation probability distribution In a continuous observation probability HMM. . enabling us to get as accurate a model as possible. For example. the continuous probability distribution functions are used during the training phase.
Σjk ) = √ exp − 2σ 2 2πσ where ot is a real value.20) 1/2 1 exp − (ot − µjk )T Σ−1 (ot − µjk ) jk 2 (2. Σjk ) = where ot is a vector. . The multivariate Gaussian density is in the form: bjk (ot ) = N (ot . N ) that best “explains” the observations? 3.CHAPTER 2. .. . . Given a model µ = (A. . Given a model µ and the observation sequence O. In the ﬁnancial time series case. In our previous example in section 2. it is about training the model with the past historical data. In the reallife ﬁnancial times series analysis case. oT ). and an observation sequence O = (o 1 .7 Three Fundamental Problems for HMMs There are three fundamental problems about the HMM that are of particular interest to us: 1. and a space of possible models. The second problem is about ﬁnding out the hidden path. which model best accounts for the movement history. Only after training can we use the model to perform further predictions. . what is the underlying state sequence(1. 1 (2π)D/2 Σ jk (2. what is the strategy sequence the ﬁnancial professional applied on each trading day? The third problem is of the most signiﬁcant interest because it deals with the training of the model. µjk . what is P (Oµ)? 2.21) 2. Π). HIDDEN MARKOV MODELS 22 The single Gaussian density function has the form: 1 (x − µ)2 bjk (ot ) = N (ot . µjk .e. B. Given an observation sequence O. how do we eﬃciently compute the probability of the observation sequence given the model? i. . . . how do we adjust the parameters so as to ﬁnd the model µ that maximizes P (Oµ)? The ﬁrst problem can be used to determine which of the trained models is most likely when the training observation sequence is given.3. given the past history of the price or index movements.
. Sµ) = P (OS. an eﬃcient algorithm–the forward backward algorithm was developed . This process is also known as decoding. Π). The joint probability of O and S: P (O. st = iµ) (2. the computation grows exponentially. The forward procedure The forward variable αi (t) is deﬁned as: αi (t) = P (o1 o2 · · · ot−1 . µ) = t=1 P (ot st . st+1 . A major problem with this approach is enumerating each state sequence is ineﬃciency.28) To solve this problem.27) The computation is quite straightforward by summing the observation probabilities for each of the possible state sequence. Since the observations are independent of each other the time t. . oT ) and an HMM µ = (A.22) (2.1 Problem 1: ﬁnding the probability of an observation Given an observation sequence O = (o 1 . . . P (Oµ) = S T (2. .CHAPTER 2. that cuts the computational complexity to linear in T . As the length of T of the sequence grows.23) = bs1 (o1 ) · · · bs1 s2 (o2 ) · · · bsT −1 sT (oT ) and the state transition probability.25) P (OS. It requires (2T − 1) · N T +1 multiplications and N T − 1 additions. P (Sµ) = πs1 · as1 s2 · as2 s3 · · · asT −1 sT . µ)P (Sµ) Therefore. the probability of a state sequence S = (s1 . . HIDDEN MARKOV MODELS 23 2.26) = s1 ···sT +1 π s1 t=1 ast st+1 bst st+1 ot (2. . µ) (2. . sT ) generating the observation sequence can be calculated as: T P (OS. µ)P (Sµ) (2. B. we want to ﬁnd out the probability of the sequence P (Oµ).7.24) (2.
Initialization αi (1) = πi . 1 ≤ t ≤ T.29) αj (t + 1) = i=1 αi (t)aij bijot . given the observation trellis node. 1 ≤ i ≤ N 2.4. Induction N (2.4: The forward procedure 1.30) . It is calculated by summing probabilities for all incoming arcs at a s1 s2 State s3 s n t−1 t t+1 Time Figure 2. HIDDEN MARKOV MODELS 24 α(t) stores the total probability of ending up in state s i at time t. 1 ≤ j ≤ N (2. see Figure 2. sequence o1 · · · ot−1 .CHAPTER 2. The forward variable at each time t can be calculated inductively.
34) 3. Induction N (2.31) additions. The backward variable βi (t) is deﬁned as: βi (t) = P (ot+1 ot+2 · · · oT st = i. The backward procedure calculates the probability of the partial observation sequence from t + 1 to the end. The backward procedure The forward algorithm requires N (N +1)(T −1)+N multiplications and N (N −1)(T −1) The induction computation for the forward procedure can also be performed in the reverse order.33) βi (t) = j=1 aij bijot βj (t + 1). terminate algorithm 4. Total N P (Oµ) = i=1 πi βi (1) (2. 4.CHAPTER 2. 1 ≤ t ≤ T. Return to step 2 if t < T . HIDDEN MARKOV MODELS 25 3. Initialization βi (T ) = 1.32) (2. Return to step 2 if t > 0. given the model µ and state s i at time t. 1 ≤ i ≤ N (2. Update time Set t = t + 1.35) . 1 ≤ i ≤ N 2. Otherwise terminate algorithm. Update time Set t = t − 1. µ) The backward algorithm works from right to left on through the same trellis: 1. Termination N P (Oµ) = i=1 αi (T ) (2. Otherwise. The complexity is O(T N 2 ).
5: The backward procedure .CHAPTER 2. HIDDEN MARKOV MODELS 26 s1 s2 State s3 s n t−1 t t+1 Time Figure 2.
This is one a problem often encountered in parsing speech and in pattern recognition.7. µ) P (st = i. . o1 · · · ot−1 . we ﬁnd the following γi (t) = P (st = iO. 1 ≤ t ≤ T + 1. There are several possible ways to solve this problem. the optimal state sequence found may be invalid.38) (2. This is because it doesn’t take the state transition probabilities into consideration. a more eﬃcient algorithm. s2 . . The Viterbi algorithm The Viterbi algorithm is designed to ﬁnd the most likely state sequence.37) (2. oT ) : argmax P (S O. sT ) given the observation sequence O = (o 1 . µ) S It is suﬃcient to maximize for a ﬁxed observation sequence O: argmax P (S . . is used to ﬁnd the best state sequence. However the approach may generate an unlikely state sequence. The diﬃculty is that there may be several possible optimal criteria. based on dynamic programming. 1 ≤ i ≤ N 1≤i≤N (2. . HIDDEN MARKOV MODELS 27 2. For example. Oµ) = P (Oµ) αi (t)βi (t) = N j=1 αj (t)βj (t) The individually most likely state sequence S can be found as: S = argmax γi (t). One of them is to choose the states that are probability variable: individually most likely at each time t. S = (s1 . Therefore. 1 ≤ t ≤ T + 1. For each time t.36) (2. .39) This quantity maximizes the expected number of correct states.CHAPTER 2. . the Viterbi algorithm.2 Problem 2: Finding the best state sequence The second problem is to ﬁnd the best state sequence given a model and the observation sequence. Oµ) S The following variable: δj (t) = max P (s1 · · · st−1 .40) . . if at some point we have zero transition probability aij = 0. o2 . st = jµ) s1 ···st−1 (2. .
except that the forwardbackward algorithm uses summing over previous states while the Viterbi algorithm uses maximization. HIDDEN MARKOV MODELS 28 that ends in state i at time t.6 shows how the Viterbi algorithm ﬁnds a single best path. Update time t = t+1 Return to step 2 if t ≤ T else terminate the algorithm 4. The complete Viterbi algorithm is as follows: 1. similar to the forwardbackward algorithm.48) 1≤i≤N (2.44) ψj (t) = argmax[δi (t − 1)aij ] 1≤i≤N 3. Fig 2. .47) = argmax[δi (T )] When there are multiple paths generated by the Viterbi algorithm.43) (2. The calculation is done by induction. The corresponding variable ψ j (t) stores the node of the incoming arc that leads to this most probable path.41) (2.45) max [δi (T )] 1≤i≤N (2. 1 ≤ i ≤ N 2. Termination P∗ = s∗ T 5. 1 ≤ i ≤ N ψi (1) = 0. Path readout s∗ = ψt+1 (s∗ ) t t+1 (2. we can pick up one randomly or choose the best n paths. given the model µ.46) (2.42) (2. Initialization δi (1) = πi bi (o1 ).CHAPTER 2. Induction δj (t) = bijot max δi (t − 1)aij 1≤i≤N This variable stores the probability of observing o 1 o2 · · · ot using the most likely path (2.
This is a special case of the Expectation Maximization method. The BaumWelch algorithm is numerically stable with the likelihood nondecreasing of each iteration.CHAPTER 2. we want to ﬁnd the model parameters µ = (A. It has linear convergence to a local optima.3 Problem 3: Parameter estimation The last and most diﬃcult problem about HMMs is that of the parameter estimation.6: Finding best path with the Viterbi algorithm 2. we will need to deﬁne a few intermediate variables. Deﬁne pt(i. j ≤ N as follows: . 1 ≤ i. 1 ≤ t ≤ T. HIDDEN MARKOV MODELS 29 1 State 2 3 1 2 3 4 Time Figure 2. B. j). Given an observation sequence. π) that best explains the observation sequence. π) iteratively.7. The problem can be reformulated as ﬁnd the parameters that maximize the following probability: argmax P (Oµ) µ There is no known analytic method to choose µ to maximize P (Oµ) but we can use a local maximization algorithm to ﬁnd the highest probability. This algorithm is called the BaumWelch. This iterative process is called the training of the model. It works iteratively to improve the likelihood of P (Oµ). B. To work out the optimal model µ = (A.
j) is the expected number of transitions from state i to j.53) (2. HIDDEN MARKOV MODELS 30 pt(ij) = P (st = i. (2.54) = j=1 N P (st = i. given the observation O and the model µ: γi (t) = P (st = iO.52) This is the probability of being at state i at time t. This is the probability of being at state i at time t. st+1 = jO. µ) P (st = i.49) (2. µ) N (2.55) The above equation holds because γi (t) is the expected number of transition from state i and pt (i. j) (2. . µ) = j=1 pt (i. given Then deﬁne γi (t). st+1 = jO.51) (2. and at state j at time t + 1.CHAPTER 2.50) (2. Given the above deﬁnitions we begin with an initial model µ and run the training data O through the current model to estimate the expectations of each model parameter. Then we can change the model to maximize the values of the paths that are used. Oµ) = P (Oµ) αi (t)aij bijot βj (t + 1) = N m=1 αm (t)βm (t) αi (t)aij bijot βj (t + 1) = N N m=1 n=1 αm (t)amn bmnot βn (t + 1) the model µ and the observation O. By repeating this process we hope to converge on the optimal values for the model parameters. st+1 = j.
j) (2.57) bijk = = expected number of transitions from i to j with k observed expected number of transitions from i to j t:ot =k. Then we studied the three basic problems involved with any HMM. j) T t=1 γi (t) (2. we will replace b ijot with bjot . both Viterbi algorithm and the BaumWelch algorithm are used in combination to make the system work. the Markov properties are also described.58) In the following calculations. . HIDDEN MARKOV MODELS 31 The reestimation formulas of the model are: πi = probability of being at state i at time t = 1 = γi (1) expected number of transitions from state i to j expected number of transitions from state i T t=1 pt (i. i.e.56) aij = = (2. This is also called a ﬁrst order HMM. in the prediction task.8 Chapter Summary In this chapter. each observation is generated by the probability density function associated with one state at one time step.1≤t≤T pt (i. 2. The following model design and experiments are all extensions based on the basic model and the techniques to solve the three problems.e. The conditions that HMMs must observe. i. both theoretically and with examples. the general form of the HMM is introduced. j) T t=1 pt (i.CHAPTER 2. In fact.
The reestimation formulas are then derived for the Gaussian Mixtures. We introduce Gaussian mixtures which we have as the continuous observation density function associated with each state. the second expert is best for high volatility regions. We use an HMM with emission density functions modeled as mixtures of Gaussians in combination with the usual transition probabilities. We ﬁrst give a brief survey of Weigend and Shi’s previous work on the application of Hidden Markov Experts to ﬁnancial time series prediction [SW97]. The “experts” at each state of the Hidden Markov Model applied for ﬁnancial time series prediction are three neural networks.Chapter 3 HMM for Financial Time Series Analysis In this chapter we construct an HMM based on the discussions in chapter 2. One of the experts is good at forecasting low volatility data. We apply an adddrop approach to the training data. 3. and the 32 .1 Previous Work In [SW97]. analyze problems with their approach and then propose a new model. Weigend and Shi propose a Hidden Markov Expert Model to forecast the change of the S&P 500 Index at halfhour time step. with characteristics and predicting bias distinct from each other.
the counterpart of the “expert”. the Dow Jones Index is used as an error controller. are adjustable. such as similar time series or indicator series derived from the original series. When the system prediction of the S&P 500 doesn’t coincide with the Dow.58) and (2. This is problematic because even if we can divide a long time series into several segments with diﬀerent volatilities. Then in the prediction phase.59). The data in each pool is then trained together to generate the prediction for the next coming day. By providing more available information. data at each time step are of equal importance. In this approach. To short means to sell something that you don’t have. Without having to worry about the exactly mathematical relationship between these two series. By comparing the movement prediction of the S&P 500 with the Dow. we can make the model more reliable. In section 3.3 we introduce the multivariate Gaussian mixtures that take a vector composed of the Dow Jones Composite Index and the S&P 500 Index as input. We will solve this problem with an adjustable weighted EM algorithm in chapter 4. Then in chapter 4. Just like we did in equations (2. we can balance between long term trend and short 2 term Outliers are a few observations that are not well ﬁtted by the “best” available model. 1 The training of the Hidden Markov Experts mainly involves the reestimation of the transition probability matrix A. Too much weight is given to the early samples. Refer to appendix I for more explanation. To do this. a training pool is created. Another problem with Shi and Weigend’s model is the lack of additional information to help prediction decisions. Their model takes the destination time series as the only input time series. But there are no reestimations for each of the three “experts”. segments with similar volatilities may not necessarily reﬂect similar pattern. 2 1 . This is because the Dow is a less volatile index than the S&P 500. This means that the experts are ﬁxed and we must trust them during the whole prediction process because there is no way of improving their accuracy of prediction. This can cause big problems during highly volatile period or at the turning point of long term trends. we will give less conﬁdence in the HMM. In the later sections of this chapter we will introduce the Gaussian mixtures where all parameters of each mixture component. we let the HMM combine them together to make predictions for the S&P 500 Index. This pool keeps updating by adding the last available data and eliminating the ﬁrst data in the pool. you have to borrow the asset that you want to short.CHAPTER 3. HMM FOR FINANCIAL TIME SERIES ANALYSIS 33 third expert is responsible for the “outliers”.
4) As previously deﬁned M is the total number of Gaussian mixture components at state i and N is the total number of states. The diﬀerence with the previous example is that 3 A whipsaw occurs when a buy or sell signal is reversed in a short time. Σim ) is a multivariate Gaussian distribution with mean vector µ and covariance N (O. Therefore it is advantageous to use HMMs with continuous observation densities. Σim ) (3. HMM FOR FINANCIAL TIME SERIES ANALYSIS 34 whipsaws. in other words. The most generally used form of the continuous probability density function(pdf) is the Gaussian mixture in the form of: M bim (ot ) = m=1 wim N (ot . we can use the vector quantization technique to map each continuous value into a discrete value via the codebook. 3 3. µim . the emitted symbols are discrete symbols from a ﬁnite alphabet list.2 BaumWelch Reestimation for Gaussian mixtures The reestimation formulas in the previous chapter have mainly focused on the case where the symbol emission probabilities are discrete.1) ot is the observed vector.2) wim ≥ 0. 1 ≤ i ≤ N. 1 ≤ m ≤ M matrix Σ : N (O. 1 ≤ i ≤ N (3. wim is the weight of the mth Gaussian mixture at state i.CHAPTER 3. µim .3) The learning of the parameters of the HMMs thus becomes learning of the means and variances of each Gaussian mixture component. The mixture weights w must satisfy the following constraints: M m=1 wim = 1. Volatile markets and sensitive indicators can cause whipsaws . The intermediate variable δ is redeﬁned as: M δi (t) = m=1 δim (t) = 1 αj (t − 1)aji wim bim (ot )βi (t) P m=1 M (3. there might be serious degradation after the quantization. µim . Although as mentioned before. Σim ) = 1 (2π)n Σ 1 exp − (o − µ )Σ −1 (o − µ ) 2  (3.
15 0.1 0.CHAPTER 3.2 0. .1: Three single Gaussian density functions.25 0. HMM FOR FINANCIAL TIME SERIES ANALYSIS 35 0.35 0.4 G1: 20% G2: 30% G3: 50% 0.05 0 0 5 10 15 20 25 Figure 3.3 0. Each of them will contributing a percentage to the combined output in the mixture.
1 0. and 50% of probability by the third Gaussian.12 0.2: A Gaussian mixture derived from the three Gaussian densities above. HMM FOR FINANCIAL TIME SERIES ANALYSIS 36 0. 30% of probability that the distribution of x is governed by the second Gaussian. there is a probability of 20% that the random variable x is governed by the ﬁrst Gaussian density function.16 mixture of the three Gaussians 0. For each small area δ close to each point x on the x axis.04 0.06 0.02 0 0 5 10 15 20 25 Figure 3. .14 0.CHAPTER 3.08 0.
In other words the observed data are generated by several distinct underlying causes that have some unknown relationship between them. the volume by itself is of little interest. µjk .8) aij = αi (t)aij bj (ot+1 )βj (t + 1) T t=1 αi (t)βi (t) (3. For example in stock market. µjk . but it will contain plenty of information about the trend of the market when combined with close price. HMM FOR FINANCIAL TIME SERIES ANALYSIS 37 rather than associating each state with one probability density function. we are able to derive the reestimation formulas below: µim = T t=1 δim (t)ot T t=1 δim (t) T t=1 δim (t)(ot − µim )(ot T t=1 δim (t) T t=1 δim (t) T t=1 δi (t) T t=1 (3. with each mixture component contributing to the overall result by some weight. Σjk ) M k=1 wjk N (ot .CHAPTER 3.9) 3. without knowing how much and in what way each cause contributes to the resulted observation sequence. Canada’s stock market is aﬀected by the US economy circle because Canada is the largest trading partner of US. Σjk ) (3.3 Multivariate Gaussian Mixture as Observation Density Function Sometimes we have observation vectors that have more than one element.6) − µim ) σim = (3.k (t) = αj (t)βj (t) N j=1 αj (t)βj (t) · wjk N (ot .5) With the new intermediate variable δ deﬁned. each observation is generated by a set of Gaussian mixtures. Many time series could be correlated with other time series. This phenomenon is of great interest in ﬁnancial time series analysis. Then we also need a variable that denotes the probability of being at state j at time t with the kth mixture component that accounts for the current observation o t : γj.7) wim = (3. As such the factors that aﬀect . Each cause contributes independently to the generation process but we can only see the observation sequence as a ﬁnal mixture.
except that the mean is in the form of a vector µ and the covariance is in the given by: form of a m × m covariance matrix Σj . we assume the observation is generated by k Gaussians.2 EM for multivariate Gaussian mixtures We now develop the EM algorithm for reestimating the parameters of the multivariate Gaussian mixture. The training process then becomes a process of ﬁnd the parameters that maximizes the probability of this output observation. θ2 to explain the algorithm): . . Let θj = (µj . so the overall output is: k j=1 wj N (x.3. HMM FOR FINANCIAL TIME SERIES ANALYSIS 38 US stock market also have an impact on the Canadian market. .CHAPTER 3.1 Multivariate Gaussian distributions The multivariate mdimensional Gaussian has the same parameters as the single normal distribution. they will short the stocks of Kmart. 3. Also deﬁne a hidden variable E[zij ] as the probability of generating the ith observation with the jth mixture. πj ) be the jth mixture component. They trade two stocks with similar characteristics at the same time.3. µj . Σj . 3. Σj ) (3. . θk )T . Researchers have found that the best Canadian year is the third year of the US president election cycle. then the parameters of the model are deﬁned as Θ = (θ1 . The probability density function for a Gaussian is nj (x. mj . Σj ) = 1 1 exp − (x − µj )T Σ−1 (x − µj ) j 2 (2π)m Σj  (3.11) The initial value of the weights wj for each mixture component should sum up to 1.10) At each state. These examples show that there is a need for including relevant information beyond the time series that we are studying. If they buy the stocks of WalMart. aiming at proﬁting from arbitrage opportunities or averse possible risks. The EM algorithm that ﬁnds the parameters that maximize the probability of the observation sequence O consists of the following two steps (we use a mixture of two θ 1 . . Some day traders have used a technique called “pairedtrading”.
θ2 ). the EM algorithm is applied to a single observation sequence O. If it were known.4 Multiple Observation Sequences In the previous discussions. given that we know the current values of Θ = (θ1 .15) 3. we develop the following formulas for each of the parameters of the HMM with multivariate Gaussian mixtures as observation density function: µim = T t=1 δim(t)ot T t=1 δim (t) T t=1 δim (t)(oi − µj )(oi T t=1 δim (t) T t=1 δim (t) T t=1 δi (t) T t=1 (3.2. However.12) − µj )T Σj = (3. the reallife ﬁnancial time series data can have a very long range. As stated by Graham [Gra86]: “There is no generally known method of chart reading that has been continuously successful for a long period of time. Combining the EM algorithm for multivariate Gaussian mixtures and the EM algorithm for HMMs.13) wim = (3. θ2 ). In the HMM context.CHAPTER 3. This is because the pattern or trend at some point of time may be quite diﬀerent to that of the overall pattern.14) aij = αi (t)aij bj (ot+1 )βj (t + 1) T t=1 αi (t)βi (t) (3. This very following would bring its usefulness to an end. assuming the value taken on by each hidden variable zij is the expected value in the ﬁrst step. it would be speedily adopted by numberless traders. the probability of the hidden variable z ij is the intermediate variable γij (t) we talked about in 3. Maximization step: Calculate a new maximum likelihood value of Θ = (θ1 . HMM FOR FINANCIAL TIME SERIES ANALYSIS 39 Estimation step: Calculate the expected value E[zij ] of each hidden variable zij . Modeling them as one single observation sequence might give low recognition rate when testing data from some speciﬁc period of time.” Rabiner oﬀers a way to solve the similar kind of problem in speech recognition by splitting .
. the probability function P (Oµ) to maximize now becomes: K P (Oµ) = k=1 P (O (k) µ) (3. . OTk ] is the kth observation sequence and T k is the kth observation sequence length. j) and δi (t) are calculated for each training sequence O (k) . O (2) .16) where O (k) = [O1 . often cases are that patterns change from time to time. The reestimation formulas for multiple observation sequences are: (k) (k) Tr K 1 t=1 δim (t)ot k=1 Pk (k) K Tr 1 k=1 Pk t=1 δim (t) K 1 k=1 Pk (k) (k) (k) Tr t=1 δim (t)(ot − µim )(ot (k) K Tr 1 k=1 Pk t=1 δim (t) µim = (3. In this way the new parameters can be vowed as averages of the optima given by the individual training sequences. O (k) ] (k) (k) (k) (3. .20) + 1) aij = (3. O2 . . In order to capture the most recent trend. HMM FOR FINANCIAL TIME SERIES ANALYSIS 40 the original observation sequence O into a set of k short sequences [Rab89]: O = [O (1) . . In our ﬁnancial time series.19) wim = (k) K Tr 1 k=1 Pk t=1 δi (t) (k) K Tr M 1 k=1 Pk t=1 m=1 δim (t) K 1 k=1 Pk (k) (k) Tr −1 (k) t=1 αi (t)aij bj (ot+1 )βj (t (k) Tr −1 (k) K 1 t=1 αi (t)βi (t) k=1 Pk (3. . Then the reestimation formulas are modiﬁed by adding together all the probabilities for each sequence. so he includes all the training sequences in the training process. . The ﬁrst data in the pool are popped out and new data are pushed into it when a trading day ends. . Assume that each observation sequence is independent of each other.17) The variables αi (t).CHAPTER 3.18) − µim ) σim = (3. βi (t).21) Rabiner’s algorithm is used to process a batch of speech sequences that are of equal importance. Each time the training starts from the parameters of last day’s trading yet with today’s data. we create a dynamic training pool. pt (i. .
In the meantime. See ﬁgure 3. . drop the oldest data in the pool. we can calculate the return for that day and add it to the pool. HMM FOR FINANCIAL TIME SERIES ANALYSIS 41 Figure 3.3 for a graphical illustration of the dynamic training pool. when the market closes. The training is then performed again based on the parameters from last training and the data from the new pool. This is a segment of data that is updated dynamically throughout the training. This way the system always trains on fresh data.3: The dynamic training pool 3.5 Dynamic Training Pool We introduce a new concept in the training process called the training pool. In the training pool each data sample serves as both prediction target and training sample. At the end of a trading day.CHAPTER 3.
And there are a set of random values ranging between 0 and 0.3 and 0.CHAPTER 3. Each state is associated with a Gaussian mixture that has 4 Gaussian probability distributions. risk of misclassiﬁcation will increase.3.3. The optimal number of states can be decided through experiments. state probability distribution probabilities Π = {π i } are assigned a set of random values 3.25 for the initial mixture weights w. The number of the mixture components follow the same discussion. The HMM has 5 states. The architecture of the HMGM is shown in Fig 3. Too many strategies will make little distinction between each other and will increase the cost of computing. This setting is similar to Shi and Weigend’s experimental environment where they have one neural net expert associated with each of the three states. Based on our experience. the number of states is the number of the strategies we have to make predictions. This can also be explained intuitively using ﬁnancial theory: the more diversiﬁed the strategies.2 Making predictions We now come to the core part of the problem: making predictions before each trading day starts. The input into the HMGM is the real number vector introduced in section 1. 5 states and 4 mixture components are reasonable numbers for the model. See [WMS95] and [SW97].6 3. And the mean of each Gaussian mixture component is assigned a real value between 0. In the following section we will describe how the real number is transformed into long or short signals. On the other hand if the number of states is too small.2. This number should be neither too large nor too small. The initial between 0 and 0. Intuitively. Actually the prediction process is carried out together with the training at the same . the less investment risk and the less return. HMM FOR FINANCIAL TIME SERIES ANALYSIS 42 3. This is the normal range of possible returns for each day. each of the transition probability is assigned a real value at random between 0 and 0. The HMM is a fully connected trellis.1 Making Predictions with HMM Setup of HMM Parameters We construct a HMM with Gaussian Mixtures as observation density function(call it HMGM ).6. The initial values of the covariance for each of the Gaussian probability distribution function is assigned 1.4.6.2. We have launched experiments with diﬀerent state and mixture numbers.
HMM FOR FINANCIAL TIME SERIES ANALYSIS 43 Mixtures G1 s1 G2 G3 G4 s2 State s3 s4 s5 Time Figure 3.4: Hidden Markov Gaussian Mixtures .CHAPTER 3.
Σjm ) (3. In our experiment. The HMGM is then trained again with the newest time series and the parameters are updated. This is exactly what human analysts and professional traders do. Many of them work hours after the market closes 4pm Atlantic time. that will further result in a long strategy. If the weighted mean of the Gaussian mixtures at the selected state is positive or zero. at the end of each trading day.2 is revised by replacing mixture component m: the function bijot with the Gaussian density function N (o t . however as most ﬁnancial analysts believe. a ﬁve day or twenty day set would be desirable because ﬁve days are the trading days in a week and one month consists of roughly twenty trading days. HMM FOR FINANCIAL TIME SERIES ANALYSIS 44 time.23) Next we transform the real values generated by the Gaussian mixtures into binary symbols–positive or negative signals of the market. The training set can be of any size. There is a balance between the size of the training set and the sensitivity of the model. Algorithm 3.CHAPTER 3. the more accurate the model in terms of ﬁnding long term trend. µjm .22) M ψjk (t) = argmax δi (t − 1)aij 1≤i≤N m=1 wjm N (ot . we include it in the training system to absorb the most updated information. The weighted average of the mean of the Gaussian mixture is taken as the prediction for tomorrow. The induction step in section 2. a weighted mean of zero will generate a positive signal. When the training is done and parameters of the HMGM are updated. Σjm ) (3.1 is the revised multiobservation EM algorithm for HM GM written in the pseudo code. However the trained model may not be sensitive to whipsaws. we performed the Viterbi algorithm to ﬁnd the most “reliable” Gaussian mixtures associated with the most probable state. we output a positive signal. when the market return of that day is known to the public. . µjm . The bigger the training set. Σjm ) for each state j and M δj (t) = max δi (t − 1)aij 1≤i≤N m=1 wjm N (ot . In other words.7. In other words. µjm . we have a threshold at zero. otherwise we output a negative signal.
Output the predicted signal end while 3. These issues are addressed throughout the explanations in this chapter. Each state of the HMM is associated with a mixture of Gaussian functions with diﬀerent parameters. The Dow Jones Index is included in the experiments as a supporting indicator to decide the volatility of the S&P 500 series.1: Combined trainingprediction algorithm for the HMGM while not End of Series do initialization if tradingDay = ﬁrst day of series then assign random values to the HMM parameters else initialize parameters with the last updated values end if Training data set update 1. The revised weighted EM update algorithm puts more emphasis on the recent data. Issues considered in the modeling process include the selection of the emission density function.State drop day 1 in the previous training set 2.Run the Viterbi algorithm to ﬁnd the Gaussian mixture with the most probable state 2. which give each state diﬀerent prediction preference.7 Chapter Summary In this chapter.Compare the weighted mean of the Gaussian mixture against the threshold zero 3. more speciﬁcally the S&P 500 Index.Update all parameters using the EM algorithm Prediction 1. we construct an HMM to predict the ﬁnancial time series.CHAPTER 3. the EM update rule and characteristics of the selected ﬁnancial time series.State add current day (the day that has just ended) to the training set 3. . We have achieved impressive results that are shown in chapter 5. HMM FOR FINANCIAL TIME SERIES ANALYSIS 45 Algorithm 3. Some states are more sensitive to low volatile data and others are more accurate with high volatile segments.
It took the Dow Jones Index 57 years to 46 . coupled HMM [ZG02]. This approach works well when the training set is small and the data series studied are not timesensitive or the time dimension is not a major concern. and Gaussian mixtures [RW84] [XJ96] [RY98]. including Hidden Markov Model [BP66] [RJ86] [Rab89]. but at a reduced conﬁdence. The traditional EM based HMM models have found great success in language and video processing where the order of the observed data is not signiﬁcantly important. Originally formalized in [DLR77]. They take it for granted that each data sample in the training data set is of equal importance and the ﬁnal estimation is based on this equal importance assumption. no matter how big the training set is. all these variances of the EM algorithm do not take the importance attenuation in the time dimension into consideration. hierarchical HMM [FST98]. many patterns disappeared or diminished after they had been discovered for a while. However. conditional/joint probability estimation [BF96] [JP98]. A most persuasive argument is the change of the Dow Jones Index. However ﬁnancial time series diﬀer from all the above signals. As we have discussed in chapter 1. They have some unique characteristics.Chapter 4 Exponentially Weighted EM Algorithm for HMM In this chapter we ﬁrst review the traditional EM algorithm in more depth by taking a close look at the composition of the likelihood function and the Q function. We need to focus more on recent data while keep in mind of the past patterns. constrained topology HMM [Row00]. The EM algorithm for reestimation is intensively studied under all sorts of problem settings.
EXPONENTIALLY WEIGHTED EM ALGORITHM FOR HMM 47 rise from 200 to 2000. yet it only took 12 years to rise from 2000 to 10. xN } given the parameter Θ.CHAPTER 4.1 Maximumlikelihood We have a density function p(XΘ) that represents the probability of the observation the set of means and covariances of the Gaussian mixtures associated with each state as well as the transition probability matrix and the probability of each mixture component. 4.i. 000. we presents the derivation of the exponentially weighted EM algorithm. 4. Realizing the change of importance over the time dimension and motivated by the concept of Exponential Moving Average (EMA) of ﬁnancial time series. Assuming the data are independent and identically distributed (i. the probability of observing the whole data set is: N sequence X = {x1 . We show the convergence of the exponentially weighted EM algorithm is guaranteed by a weighted version of the EM Theorem.) with distribution p. we often maximize the logarithm form of the likelihood function because it reduces multiplications to additions thus makes the derivation analytically easier. . In the HMGM model Θ includes p(XΘ) = i=1 p(xi θ) = L(ΘX) (4. To ﬁnd better balance between shortterm and longterm trends. We show that the ﬁnal reestimation of the parameters of the HMM and the Gaussian densities can be expressed in a form of a combination of the exponential moving averages (EMAs) of the intermediate state variables. we further develop a double weighted EM algorithm that is sensitivityadjustable by including the volatility information.2) Since the log function is monotonous.d. the observed part and the underlying part. Our goal of the EM algorithm is to ﬁnd the Θ∗ that maximizes L: Θ∗ = argmax L(ΘX) Θ (4. . The observed data are governed by some distribution with given form .2 The Traditional EM Algorithm The EM algorithm takes the target data as composed of two parts.1) The function L is called the likelihood function of the parameters given the data. . .
yΘ) = p(yx. Θ(i−1) = y∈Υ log p(X. given the observed part X and the parameters from last estimation. Y ). Then the expectation can be rewritten in . Y ) is a function of two variables. Θ(i−1) ) dy (4. Y Θ) with respect to the unknown data Y .Θ (Y ) where Y is the only random variable. the joint density function of one data in the complete data sample is: p(zΘ) = p(x. As mentioned above.5) Θ(i−1) are the estimates from last run of the EM algorithm. EXPONENTIALLY WEIGHTED EM ALGORITHM FOR HMM 48 but unknown parameters. Υ is the space of possible values of y. Next the EM algorithm ﬁnds the expected value of the complete data loglikelihood log p(X. Now assume X as the observed part governed by some distribution with known form but unknown parameters. Y Θ)X. Θ)p(xΘ) (4. Then Assume the complete data Z = (X.4) When estimating the hidden data Y . By the Bayes rule. The task of the EM algorithm is to ﬁnd out the parameters for the distribution governing the observed part and the distribution generating the underlying part. Y ) = h X. Y Θ) (4. yΘ)f (yX. X and Θ can be taken as constants and the complete data likelihood becomes a function of Y : L(ΘX. Based on Θ (i−1) we try to ﬁnd the current estimates Θ that optimize the Q function. The underlying data can be viewed as a random variable itself.3) x and y are individual data in the data sample X and Y . Θ(i−1) ) = E log p(X. X is called the incomplete data.CHAPTER 4. Note the a prior probability p(xΘ) and the distribution of the hidden data are initially generated by assigning some random values. Y ) = p(X. we can think of Y as a random variable governed by some distribution fY (y) and h(Θ. We deﬁne a Q function to denote this expectation: Q(Θ. We now deﬁne the complete data likelihood function for the overall data set based on the above joint density function of individual data: L(ΘZ) = L(ΘX.
If the local data set that we use as training set is very large. yΘ)f (yX.7) The two steps are repeated until the probability of the overall observation does not improve signiﬁcantly. we must ﬁrst rewrite the Q function. To achieve this goal. old patterns attenuate and new patterns emerge. Now we include a timedependent weight η in the expectation to reﬂect information on the time dimension. Θ(i−1) = y∈Υ log ηp(X. we take it for granted that each data is of equal importance in the estimation of the new parameters. This is reasonable in problems like speech and visual signal recognition because the order of the data in the observed data sample is not that important. ˆ The revised expectation of the likelihood function Q: ˆ Q(Θ. Y )] = y h(Θ. ﬁnancial time series have characteristics which make the time dimension very important. 4.3 Rewriting the Q Function An assumption that is not explicitly stated in the derivation of the EM algorithm in all works cited above is that: in calculating the Q function. we ﬁnd the parameter Θ that maximizes the Q function: Θ(i) = argmax Q(Θ.CHAPTER 4. However as stated in the beginning of this chapter.8) . The EM algorithm is guaranteed to increase the loglikelihood at each iteration and will converge to a local maximum of the likelihood. Recall that the Q function is the expectation of the complete data likelihood function L with respect to the underlying data Y . Θ(i−1) ) dy (4. the new emerged patterns or trends will be inevitably diluted. Θ(i−1) ) Θ (4. As time goes on. given the observed data X and the last parameter estimates Θ. Y )fY (y) dy (4. Therefore we need a new EM algorithm that gives more importance to more recent data. Y Θ)X. The convergence is guaranteed by the EM Theorem [Jel97]. rather the general picture consisting of all data points is of more interest.6) In the MStep of the EM algorithm. Θ(i−1) ) = E log ηp(X. EXPONENTIALLY WEIGHTED EM ALGORITHM FOR HMM 49 the form: Q(Θ) = EY [h(Θ.
given the parameter Θ of the Gaussian mixture: M p(xj Θ) = ηj αi pi (xθi ) i=1 (4. α1 . αM . The whole point is that the likelihood of each data is intuitively: Given the last parameter estimates and the observed data. Θ(i−1) = y∈Υ η log p(X. . ηN } discounted by a conﬁdence density. Θ(i−1) ) = E η log p(X.4 × 0. .CHAPTER 4. we can take η out of the log [log η · P (X. if the expected probability of observing one data is 40%. yΘg )] ⇐⇒ [η · P (X. θM ). we might have only 60% conﬁdence in the accuracy of this result–meaning the ﬁnal expected likelihood is only 0. . . To begin with. . yΘ) ≤ η · log P (X. yΘ) ≤ log η · P (X.11) The parameters now consist of three types of variables Θ = (η j . ηj is the timedependent conﬁdence weight for the j th observed data. 4. yΘ)f (yX. θ1 .4 Weighted EM Algorithm for Gaussian Mixtures We now show how the parameters of the HMGM introduced in chapter 3 can be reestimated with the weighted EM algorithm. The Q function then becomes: ˆ Q(Θ. Since the logarithm function is monotonous and 0 < η ≤ 1. we will use a mixture of Gaussians as an example to illustrate the derivation process.10) where N is the number of data. the HMGM is only a special case of Gaussian mixtures in nature. . given its position in the whole data sequence.9) ˆ This move can bring great convenience to the E step. . yΘ) ≤ η · P (X. αi indicates which mixture . The weight η is actually a vector of real values between 0 and 1: η = {η 1 . Θ(i−1) ) dy (4. η2 . . yΘg )] (4. ﬁrst assume the following density for one single data x j . yΘg )] ⇐⇒ [η · log P (X. . . The weighted expectation function can be understood ˆ In a later section we will show that the Q function converges to a local maximum using techniques from the EM Theorem. . Under this problem setting. Y Θ)X.6 = 24%. EXPONENTIALLY WEIGHTED EM ALGORITHM FOR HMM 50 function. .
14) where y = (y1 . . . Y Θ) N = i=1 N ηi log P (xi yi )P (y) ηi log αyi pyi (xi θyi ) (4. . for example y i = k indicates the ith data is generated by the k th mixture component. θ1 . ηN . Θg ) = i=1 p(yi xi . . Θg ) is actually a conditional probability conditional on the data position i.13) p(yX. We assume a set of initial parameter values.CHAPTER 4. . . . . However this conditional probability is often ignored in traditional EM algorithm because it was taken for granted that the prior probability is always equal to 1. yN ) retain the independent property. η i and αyi can be thought of as prior probabilities. N g αgi pyi (xi θyi ) y p(xi Θg ) g αgi pyi (xi θyi ) y g g M k=1 αk pk (xi θk ) (4. Θg ) in the likelihood function can be computed using the Bayes’s rule: p(yi xi . Note the subscripts of η are in the time dimension. Also assume θi as the parameters for the ith Gaussian function of the mixture. pi component generates the observed data and it must observe the constraint is a density function for the ith mixture component with parameter θ i .12) = i=1 So we start from a set of guessed parameters and from the assumed parameters we can go g g on to compute the likelihood function. . . The subscripts for α and θ are in the spatial dimension. Θg ) = = and same as the basic EM algorithm. EXPONENTIALLY WEIGHTED EM ALGORITHM FOR HMM M i=1 αi 51 = 1. And p yi (yi xi . Y ). Y ) = η log P (X. . We guess that Θ g = η1 . . αg . there are N data in the training set. . αg . . Θg ) (4. . As mentioned above the conﬁdence weight η can be taken as a prior probability. Last assume the conﬁdence weight ηn for the nth data. The pyi (yi xi . indicating the parameter of a certain mixture component. . θM 1 M ˆ are the best possible parameters for the likelihood L(Θg X. We can obtain the complete data log likelihood function based on these hypothesized parameters: ˆ log L(ΘX. (θ i includes the mean and covariance for the i th Gaussian). .
Θg ) (4. Θg ) p(lxi . yΘ)p(yX. Θg ) M N = l=1 i=1 ηi log(αl )p(lxi . EXPONENTIALLY WEIGHTED EM ALGORITHM FOR HMM 52 With these initial parameters Θg made by guessing. T hetag ) = y∈Υ η log(L(ΘX. Θg ) (4.17) . Θg ) ˆ p(yj xj .yi yN =1 M j=1 M ˆ p(yj xj . the constraint on mixture ˆ components still holds at each data point over the time axis. Θg ) = l=1 i=1 M N ηi log(αl pl (xi θl ))p(lxi . we can try to ﬁnd out the current ˆ parameters Θ that maximizes the Q function: ˆ Q(Θ. Θg ) M i=1 p(yj xj . Θg ) M N = M y1 =1 N ··· yi−1 =1 yi+1 =1 M ··· yN =1 j=1.yi yN =1 j=1 The latter part of the above formula can be simpliﬁed as below: M M y1 =1 y2 =1 M N ··· δl. Θg ) y∈Υ N N = = y∈Υ i=1 M M ηi log(αyi pyi (xi θyi )) M N j=1 ˆ p(yj xj . Θg ) (4.15) = l=1 i=1 log(αl pl (xi θl )) y1 =1 y2 =1 ··· δl. This simpliﬁcation can be carried out because of the constraint Although the overall expectation is discounted by the time factor. θ g ) = 1. Θg ) N = y1 =1 y2 =1 M N yN =1 i=1 l=1 δl.16) p(ixj .yi log(αl pl (xi θl )) M M M j=1 N ˆ p(yj xj . Θg ) η log P (X. Θg ) p(lxi .j=i = p(lxi . Θg ) + l=1 i=1 ηi log(pl (xi Θl ))p(lxi .j=i = j=1.CHAPTER 4. y))p(yX. Θ ) yj =1 g p(yj xj . Then the Q function can be written as: M N ˆ Q(Θ. Θg ) N = y1 =1 y2 =1 M M ··· ··· yN =1 i=1 M N log(αyi pyi (xi θyi )) M j=1 ˆ p(yj xj .
Θg ) + λ = 0 αl (4.21) = i=1 ηi + λ N i=1 ηi . we know pl (xµl .17 and taking away constant terms that will be eliminated after taking derivatives. The ﬁrst term has α l which must observe the constraint be applied. ˆ This is done by maximizing the second term in the Q function. Θg ) M N l=1 i=1 = 1 1 ηi − log(Σl ) − (xi − µl )T Σ−1 (xi − µl ) p(lxi . Θ ) M l=1 αl +λ (4.24) l 2 2 . Let the above expression equal 0. we can easily get λ = − above equation we ﬁnally get the estimation of α l : αl = N g i=1 ηi p(lxi .19) Summing both the numerator and denominator of the ﬁrst term over l. we have: N i=1 1 ηi p(lxi . Σl ) = 1 1 exp − (x − µl )T Σ−1 (x − µl ) l 2 (2π)d /2Σl 1/2 (4. Θ ) N i=1 ηi Substituting λ in the (4. we get: M l=1 N i=1 ηi log(pl (xi Θl ))p(lxi . Given the form of a Ddimensional Gaussian distribution. Θg ) + λ l=1 i=1 l αl − 1 =0 (4. So it is a constrained function optimization problem where the Lagrange multiplier λ can ηi log(αl )p(lxi .23) Substituting this distribution form into the second term of 4.20) (4.22) Next we derive the update rule for the mean and covariance of the Gaussian components.18) From above. EXPONENTIALLY WEIGHTED EM ALGORITHM FOR HMM 53 ˆ It becomes clear that to maximize the Q function we must maximize both terms in the above formula separately. And the maximum is achieved when the following equation is satisﬁed: ∂ ∂αl M N l αl = 1. the left side of the equation becomes: M l=1 N g i=1 ηi p(lxi. Θg ) (4. Θ ) M l=1 αl +λ = N N i=1 M g l=1 ηi p(lxi .CHAPTER 4.
The calculation of the transition probability a ij also involves a time variable . Θ )(xi − µl )(xi N g i=1 ηi p(lxi . we now return to our HMGM model. Θg ) Σl − (xi − µl )(xi − µl )T = 0 (4.28) 4. Θ ) (4. Θg ) = 0 (4.29) We ﬁnd that the δim (t) enjoys the same status as the prior probability p(lx i . we have two intermediate variables describing the whole process of generating the observed data: γi (t) represents the probability of being in state i at time t and w im is the probability of picking the mt h mixture component at state i.26) Similarly.25) Then we can work out the current estimation for µ l : µl = N g i=1 xi p(lxi . Θg ) in previous discussions. We can deﬁne the probability δim (t) that denotes the mth mixture density generating observation o t as: δim (t) = γi (t) wim bim (ot ) bi (ot ) (4. These intermediate variables combine together to generate the probability of the observed data. Θ ) N g i=1 ηi p(lxi .5 HMGM Parameter Reestimation with the Weighted EM Algorithm After showing the derivation of the exponentially weighted EM algorithm for the Gaussian mixture case. As discussed in chapter 2 and 3.CHAPTER 4. we get: N i=1 ηi p(lxi .45) with respect to the covariance Σ l and setting it equal to 0. Θ ) − µ l )T (4.27) So the estimation for Σ is: Σl = N g i=1 ηi p(lxi . take the derivative of (4. EXPONENTIALLY WEIGHTED EM ALGORITHM FOR HMM 54 The maximization of the above expression is achieved by taking the derivative with respect to µl and letting it equal to 0: N i=1 ηi Σ−1 (xi − µl )p(lxi .
starting from the sixth day. Technical analysis people developed other indicators based on the EMA. We denote pt (ij) as the exponential moving average of the original variable pt (ij) at time t.6 Calculation and Properties of the Exponential Moving Average Before we go on to show how we can rewrite the reestimation formulas with EMAs of the intermediate variables. Figure 4. The calculation of a ﬁve day exponentially moving average for this new intermediate variable consists of two steps: First. When the curves of two EMA with diﬀerent length cross each other.34) . such as the Moving Average Convergence Divergence (MACD).CHAPTER 4. As by its name implies.33) 4. Second.30) − µim ) σim = (4. calculate the arithmetic average of the ﬁrst ﬁve days. the EMA changes as time moves on. taking the timeintensifying weight into consideration: µim = T t=1 ηt δim (t)ot T t=1 ηt δim (t) T t=1 ηt δim (t)(ot − µim )(ot T t=1 ηt δim (t) T t=1 ηt δim (t) T t=1 ηt δi (t) T t=1 ηt αi (t)aij bj (ot+1 )βj (t T t=1 ηt αi (t)βi (t) (4. So the exponential weighted update rules for the HMGM are derived in a similar form. EXPONENTIALLY WEIGHTED EM ALGORITHM FOR HMM 55 thus can also be weighted. The EMA is invented originally as a technical analysis indicator that keeps track of the trend changes in ﬁnancial time series. Shortterm EMAs response faster than longterm EMAs to changes in the trend.32) + 1) aij = (4. Denote this average as p5 (ij). this usually means a trend change.1 shows the signals indicated by comparing the 30day EMA and the 100day EMA for an individual stock Intel : Take the variable pt (ij) for illustration. the EMA of each day is: pt (ij) = ρ × pt (ij) + (1 − ρ) × pt−1 (ij) (4.31) wim = (4. let’s take a closer look at the calculation and properties of the EMA.
the trend is considered bearish. When the 30day moving average declines below the 100day moving average.CHAPTER 4.1: When the 30day moving average moves above the 100day moving average. EXPONENTIALLY WEIGHTED EM ALGORITHM FOR HMM 56 Figure 4.com) . (picture from stockcharts. the trend is considered bullish.
(4. as shown in Fig 4..2).3333. We keep running the second step until the last day of the training pool.1): pt (ij) = ρ × pt (ij) + (1 − ρ) × pt−1 (ij) = ρ × pt (ij) + (1 − ρ) × [ρ × pt−2 (ij) + (1 − ρ) × pt−2 (ij)] = ρ × pt (ij) + (1 − ρ) × [ρ × pt−2 (ij) + (1 − ρ)2 × pt−2 (ij)] (4. ρ is the weight that we have been talking about all the k = the number of days in the For example.3.. This is easily shown when we go into the details of the calculation of equation (4..1) and (4. The 5day EMA at the 20th day of the training pool is calculated by running equation (4. EXPONENTIALLY WEIGHTED EM ALGORITHM FOR HMM 57 Note that in the above equation.1) until the 20th day: p6 (ij) = p6 (ij) × ρ + p5 (ij) × (1 − ρ) p7 (ij) = p7 (ij) × ρ + p6 (ij) × (1 − ρ) .37) . p20 (ij) = p20 (ij) × ρ + p19 (ij) × (1 − ρ) As we can see from equation (4.CHAPTER 4. The value of ρ is given by the formula: ρ = moving window 2 1+k . the last day in the training window takes up a quite large portion and should notably aﬀect the training procedure. then the value of ρ would be: 2 = 0.36) So the last day accounts for one third of the ﬁnal value. pt (ij) is the actual intermediate variable value at time t. 1+5 ρ= (4. As time goes on. which means we are calculating a ﬁve day EMA. if the size the moving window is 5.. the importance of the early data drops exponentially. while pt (ij) is the exponential moving average of that variable at time t..2).35) In equations (4. can be calculated in a similar way: δi (t) = ρ × δi (t) + (1 − ρ) × δi (t − 1) time. The EMA of the second intermediate variable δ i (t) that stores the probability of being at state i at time t...
4 gives a graphical view of the portion each day takes in calculating of the EMA. The old data are also included in the ﬁnal . while the large part of weight is given to the recent data.4 0. there is still one problem regarding η: how is the timedependent variable η deﬁned? In fact η can be taken as a density function whose distribution is prior knowledge. the information from the early data are not lost. However. in calculating the EMA at day t.CHAPTER 4.5 EMA percentage 0.3 0. Now we see from (4.7 EMA 0. Fig 4. Our task now is to ﬁnd an expression of time for η. We show the formulas with the exponential discount weight η.2 0. As is shown in the ﬁgure.7 HMGM Parameters Reestimation in a Form of EMA In previous sections we derived the exponentially weighted estimation rules for the parameters of the HMGM. EXPONENTIALLY WEIGHTED EM ALGORITHM FOR HMM 58 0. the EMA at the 19th day accounts for 2/3 of the EMA at day 20.5). t.2: The portion of each of the ﬁrst 19 days’ EMA in calculating the EMA for the 20th day.6 0. the weight of the EMA at day We can also know by inference that day t − 3 will have a portion of (1 − ρ) 3 in EMA at day t − 1 takes up a portion of (1 − ρ) while the weight of the EMA at day t − 2 is only (1 − ρ) 2 .1 0 0 2 4 6 8 10 trading day 12 14 16 18 20 Figure 4. when calculating this weighted average. A nice property about the exponentially weighted intermediate parameters is that. 4.
15 0. The data earlier than day 10 take up a very small portion but they are still included in the overall calculation .25 daily data percentage 0.35 daily data 0.3: The portion of each of the 20 days’ actual data in calculating the EMA for the 20th day.CHAPTER 4. The last day account for 1/3 of the EMA at day 20.3 0.05 0 0 2 4 6 8 10 trading day 12 14 16 18 20 Figure 4. EXPONENTIALLY WEIGHTED EM ALGORITHM FOR HMM 59 0.1 0.2 0.
and thus take up less portion in the average. by a discounted weight. From T t=1 ηt δim (t) we can see each δim (t) at a timing point t is associated with one value of η t . ηt = (1 − ρ)(T −k) · k . such as prices.CHAPTER 4. In the EM algorithm for HMM parameters reestimation. ηt = ρ. the expression (4. Then set η t by the following rules: 1 1.38) is turned into a form of the EMA of the intermediate variable δ im (t): η1 δim (1) + η2 δim (2) + · · · + ηT −1 δim (T − 1) + ηT δim (T ) . That is one important motivation of replacing the arithmetic average with EMA in the EM update rule. Originally. Based on these rules. The older the data. δi (t). etc directly. So these model variables are also related to the time series data. δim (t). If t = T. volume. The HMM will ride on the new trend quickly. This is another motivation we rewrite the reestimation formulas in the form of EMA of the model variables. But their impact never disappear. Giving more recent data more weight makes the HMM getting sensitive to trend changes in time series. βi (t). 3. without having to make too many mistakes at the beginning of a new trend before it gets ﬁt for the new trend. If 1 ≤ t ≤ k. These middle variables all have their actual meanings: they indicate the probabilities of some events at a certain point of time. The sum can be extended as: T t=1 ηt δim (t) η1 δim (1) + η2 δim (2) + · · · + ηT −1 δim (T − 1) + ηT δim (T ) (4. EXPONENTIALLY WEIGHTED EM ALGORITHM FOR HMM 60 average. Let δim (t) represent the kEMA of δim at time t. there are a set of middle variables: α i (t). the less important they become. the EMA was invented as a technical analysis tool that deals with ﬁnancial time series data. We take the denominator of the µ reestimation for example.38) = Let ρ = 2 1+k where k is for the multiplier in a kEMA. ηt = ρ · (1 − ρ)(T −t) . 2. If k < t < T.
44) 4. the reestimation formulas ﬁnally came into a form of EMA of some intermediate variables.35) to δim and induction on Equation (4. then from k + 1 to T .8 The EM Theorem and Convergence Property This section shows that our exponentially weighted EM algorithm is guaranteed to converge to a local maximum by a revised version of the EM Theorem. For review of the EM Theorem please refer to [Jel97]. apply Formula (4.39) The ﬁrst k terms work together to generate the EMA for the ﬁrst k periods.40) Therefore.CHAPTER 4. EXPONENTIALLY WEIGHTED EM ALGORITHM FOR HMM 1 1 · δim (1) + · · · + (1 − ρ)(T −k) · · δim (k) k k +ρ · (1 − ρ) · δim (T − 1) + ρ · δim (T ) +ρ · (1 − ρ)(n−(k+2)) · δim (k + 2) + · · · 61 = (1 − ρ)(T −k) · = (1 − ρ)(T −k) · δim (k) + ρ · (1 − ρ)(n−(k+1)) · δim (k + 1) +ρ · (1 − ρ) · δim (T − 1) + ρ · δim (T ) (4.43) + 1) aij = T t=1 ηt αi (t)aij bj (ot+1 )βj (t αi (T )βi (T ) (4. And let P (X) .41) − µim )(ot − µim ) σim = δim (T ) δim (T ) δi (T ) (4. The EM Theorem for exponentially weighted EM algorithm: Let X and Y be ˆ ˆ ˆ ˆ random variables with distributions P (X) and P (Y ) under some model Θ. µim = T t=1 ηt δim (t)ot δim (T ) T t=1 ηt δim (t)(ot (4. we can get the following result: (1 − ρ) · ρ · δim (T − 1) + (1 − ρ) · δim (T − 2) = (1 − ρ) · δim (T − 1) + ρ · δim (T ) = δim (T ) (4.42) wim = (4.39).
η) log P (Xη) ≥ ˆ ˆ P (Y X. η) log ˆ P (Y. η) log + ˆ P (Y X.45) Y ˆ ˆ This Theorem implies that if for a model Θ and an updated model Θ . η) log ˆ P (Y X. Xη) ˆ − P (Y X. X) ≥0 ˆ P (Y. So. EXPONENTIALLY WEIGHTED EM ALGORITHM FOR HMM 62 ˆ and P (Y ) be the distribution under a model Θ after running the exponentially weighted EM algorithm. Xη) P (Y X. η) log ˆ P (Y. For a thorough review of the Jensen’s inequality please refer to [?] [HLP88] and [GI00]. E. η) ˆ P (Y X.CHAPTER 4. η) log ≥ 0 ⇒ P (Xη) ≥ P (Xη) ˆ P (Y. The Jensen’s inequality basically states that misestimation of the distribution governing a random variable will eventually result in increased uncertainty/information.47) Y Y Y ˆ P (Y. Xη) (4. ˆ ˆ log P (Xη) ≥ log P (Xη) ⇔ ⇔ Y ˆ ˆ P (Y X. Xη) ˆ + P (Y X. η) log ˆ P (Y X. η) log P (Xη) ˆ ˆ P (Y X. Xη) ˆ P (Y X. η) log P (Xη) − Y ˆ ˆ P (Y X. Proof: From the derivation of the exponentially weighted update rule we know 0≤ ˆ P (Y X. η) ≤ 1 Y And the logarithm function is a monotonous one. η) (4. η) log P (Xη) ≥ 0 (4. Y Y ˆ P (Y. Xη) ˆ ˆ ˆ P (Y X. η) log P (Xη) − Y ˆ ˆ P (Y X. η) log P (Xη) ˆ P (Y. ˆ P (Y. Then. X) The last step follows from the Jensen’s inequality. η) ˆ P (Y. D. Xη) ˆ P (Y X. η) log ˆ P (Y. η) log ˆ P (Y X. then the observed data Y will be more probable under Θ than Θ. Xη) ˆ P (Y X.46) Y Y Then we can perform a series of logarithm transformation operations on expression (4. η) Y Y ˆ P (Y X. if the left hand ˆ ˆ inequality holds.86): Y ˆ ˆ P (Y X. η) = = = ≥ Q. η) ˆ P (Y X. .
or if he refers to the long term trend during that period of time. 4. Multiply the weight for the most recent data η with a second weight ζ. there is danger of falling right behind the market movement. just as any other improvements. i. especially during the highly volatile periods. Fig 4. However. 4. It is calculated by comparing the trend signal. we arm the HMM with a selfconﬁdence adjustment capability. EXPONENTIALLY WEIGHTED EM ALGORITHM FOR HMM 63 Market Prediction Figure 4.9 The Double Weighted EM Algorithm There is still room for improvement in the previous exponentially weighted EM rule.CHAPTER 4. 4..2 Double Exponentially Weighted Algorithm To solve this problem. the direction of the ﬁnancial time series reverse at a very high frequency in a very short period of time. Not only the turning points of the market are all missed. This is because the system is too sensitive to recent changes.5 shows a problem caused by high sensitivity. In these cases.5.e. However. positive and . sometimes.9. This is because the system is too sensitive to recent data that they fall into the pitfall of high volatility.1 Problem with the Exponentially Weighted Algorithm The exponentially weighted EM algorithm quickly picks the trend at times when there is a turning of the trend. we have to consider the cost of the improvement of sensitivity and ﬁnd out a way to overcome any possible problem. Actually if one keeps making prediction of one same direction.9.4: The prediction falls behind the market during highly volatile periods of time. ζ is the conﬁdence rate for the weight η. the prediction of the turning points are not the actual market turning points. he may have a better opportunity of getting a higher gain. as shown in Fig 4.
comparing to the S&P 500 and NASDAQ. the conﬁdence weight ζ is calculated as the total number of days that Dow coincides with the S&P divided by 5. We prove the convergence to a local maximum is guaranteed by an exponential version of the EM Theorem. To ﬁnd better balance between longterm and shortterm trends. The Dow Jones is a relatively mild index.48) 4. we develop a doubleweighted EM algorithm. Comparing the S&P 500 with the Dow for the past ﬁve days. but for the time being.134. this is the weight that we will use for further calculation.CHAPTER 4.16) to get the updated parameters. we will use the Dow for our experiment. We show that the reestimation of the parameters come in a form of exponential moving average of the intermediate variables used for calculation of the ﬁnal parameters. The EWEM algorithm takes the time factor into consideration by discounting the likelihood function in traditional EM by an exponential attenuation weight which we call the conﬁdence weight. the HMM gets full conﬁdence 1. This is very important in ﬁnancial time series analysis and prediction because ﬁnancial time series are known to be nonstationary and diﬀerent periods should be of diﬀerent interest in generating a prediction for the future. We can of course use other indicators that reserves long term trend well. The adjustable weighted exponential average for the two intermediate variables are: pt (ij) = η × ζ × pt (ij) + (1 − η × ζ) × pt−1 (ij)δi (t) = η × ζ × δi (t) + (1 − η × ζ) × δi (t − 1) Then apply the formulas (4. . Otherwise. EXPONENTIALLY WEIGHTED EM ALGORITHM FOR HMM 64 negative symbols of the S&P 500 Index with the trend signal of the Dow Jones Index. (4. If they have the same directions for everyday of the past 5 days.10 Chapter Summary In this chapter we derived a novel exponentially weighted EM algorithm for training HMGMs. Then time the two weights together.
The data is generated by a function composed of three parts: f (t) = 0. 5.1 ∗ 0. the HMGM performs better than 65 t is from that of step t − 1. We test a set of data with diﬀerent training windows. but our model should be able to at least handle it before applied to real data. The last section shows the results from the weighted EM algorithm. We test the recurrent neural network and the HMGM on this artiﬁcial data set for 400 days. Results show that over the test period of 395 days (prediction starts on the 6th day).1 Experiments with Synthetic Data Set We ﬁrst test diﬀerent models on an artiﬁcially generated data set. And lastly .Chapter 5 Experimental Results This section has all the experimental results inside. 70% of the data at step there is a 10% of upgrowing trend at the growth rate of 0.2 ∗ (τ (t)/100 − 0. The third section includes prediction results of the HMM with Gaussian mixtures as emission density functions and trained with the simple weighted EM algorithm. The second section includes the predictions for the years 1998 to 2000 of the NASDAQ Composite Index with a recurrent neural network.005) + 0. This is to try to hold the impact of the recent past. 20% of the data are generated randomly. The ﬁrst section shows the prediction results on a synthetic data set.1) τ (t) is a random number that takes 20% of the overall output.00001. Both models predict the signal 5 days ahead.7 ∗ f (t − 1) + 0. This may not exactly be the case in real life ﬁnancial time series.00001 (5.
As we can see the exponentially weighted HMGM(EWHMGM) outperforms the recurrent network for positive signals and slightly behind on negative ones. EXPERIMENTAL RESULTS 66 1. This is because the data are composed in a way that a large portion of the data is taken directly from the recent past.CHAPTER 5. .1. In the following sections we will test the HMGM on reallife data.9 0 50 100 150 200 trading day 250 300 350 400 Figure 5.2% above the cumulative return based on the artiﬁcial generated data. The HMGM underperforms a followthetrend strategy which takes yesterday’s signal as today’s prediction. The following table shows the comparisons of accuracy between the recurrent network and the exponentially weighted HMGM. the S&P 500 Index.05 1 0.1: Experimental results on computer generated data.2 1. but has a better overall performance. and 22. the recurrent neural network by 10.1 1.3 follow HMM recurrent network index 1.15 return 1. it is clearly shown that the HMGM is a better model of the two statistical learning models and it works better than the buyandhold strategy (which is the index). And the EWHMGM has less volatility in prediction accuracy at diﬀerent runs of experiment.95 0. However. The accuracy rates are based on statistics from ten runs of both models on ten data sets generated by the equation 5.25 1.55%.
44/0. As can be seen from the data. steady trends.1: Comparison of the recurrent network and exponentially weighted HMGM on the synthetic data testing. The EWHMGM outperforms the recurrent network in overall result. EXPERIMENTAL RESULTS 67 Recurrent Net EWHMGM Positive Min/Max/Avg 0.54/0.64 Negative Min/Max/Avg 0. As we can see from the above ﬁgures.1 1 0.52/0.55 0. 1.6 prediction market 1. 5.80/0.62 0.64/0.9 0 50 100 150 trading day 200 250 300 Figure 5.72/0.54/0.2: Prediction of the NASDAQ Index in 1998 with a recurrent neural network. and has less volatility.3 return 1.5 1.57 Overall Min/Max/Avg 0. By that we mean the recurrent network performs better during long term bull market (as in late 1998 and early 1999) or long term bear market (as in the year 2000). no matter it is a bull market or bear market.54/0.CHAPTER 5. the recurrent neural network has a positve bias toward steady trends.79/0.4 1. recurrent neural networks work better during low volatile. This is especially .65/0.61 Table 5.2 Recurrent Neural Network Results The NASDAQ Index data are separated into three years.2 1.58 0.68/0.53/0.
9 0.35 prediction market 1.15 1.25 prediction market 1. .95 0.95 0.7 0 50 100 150 trading day 200 250 300 Figure 5.05 return 1 0.CHAPTER 5.1 1.9 0.4: Prediction of the NASDAQ Index in 2000 with a recurrent neural network.15 return 1.85 0. EXPERIMENTAL RESULTS 68 1.2 1.2 1.8 0.25 1. 1.05 1 0.85 0.75 0.3 1.1 1.3: Prediction of the NASDAQ Index in 1999 with a recurrent neural network.8 0 50 100 150 trading day 200 250 300 Figure 5.
15 1.2 1. window size = 10 Training We test all the above mentioned approaches in chapter 4 with 400 days of the S&P 500 Index starting from Jan 2.3 HMGM Experimental Results We launch a series of experiments on the Hidden Markov Gaussian Mixtures (HMGM). the actual market had an apparent reverse in direction. 1998. And prediction becomes worse as the training window is changed in either direction. The training window introduced in chapter 3 is adjustable from 10day to 100day.35 1. from a decline to an .25 1. 1. EXPERIMENTAL RESULTS 69 apparent in the prediction for the year 2000. First take a look at the HMGM with Rabiner’s arithmetic average update rule. 5. Part of the reason is due to the memory brought by the recurrent topology. The past data has too much impact on the current training and prediction.45 1.3 return 1.5 prediction market 1. The EM algorithm is performed on the training data with diﬀerent training windows.5: Prediction of the 400day S&P 500 Index starting from Jan 2. From t213 to t228. Results show that the prediction performance changes as the training window size is adjusted.4 1.05 1 0.95 0 50 100 150 200 trading day 250 300 350 400 Figure 5.CHAPTER 5. 1998. The best result is achieved by the 40day training day window.1 1.
CHAPTER 5. EXPERIMENTAL RESULTS
70
t213 t228 1.6 prediction market 1.5
1.4
1.3 return 1.2 1.1 1 0.9 0 50 100 150 200 trading day 250 300 350 400
Figure 5.6: Prediction of the 400day S&P 500 Index starting from Jan 2, 1998. window size = 20
Training
increase. The simple HMGM was not able to recognize this in a short time, which costs a loss in proﬁt. But the overall cumulative proﬁt at the end of the testing period is still 20% above the market return. as input. We do not know the exact relationship between those two ﬁnancial time series, but the multivariate HMM uses the EM algorithm to ﬁnd the best parameters that maximizes the probability of seeing both series data. The multivariate HMGM model generates similar cumulative return as the single series HMGM but has less volatility at the later part of the testing data. The exponentially weighted EM algorithm performs signiﬁcantly better than the ﬁrst two models, mainly because it picks up a reverse trend much faster. During the periods of t164 to t178 and t213 to t228, the trend reversals were recognized and we gain points here, so that the later cumulative gains can be based on a higher early gain. However, it also loses points during periods where the volatility is higher, such as the period after t228. At the end of the whole period, a bull market started and the model responded quickly to this The multivariate HMGM takes a vector of {S&P daily return, Dow Jones daily return}
CHAPTER 5. EXPERIMENTAL RESULTS
71
2.2 prediction market 2
1.8
1.6 return 1.4 1.2 1 0.8 0 50 100 150 200 trading day 250 300 350 400
Figure 5.7: Prediction of the 400day S&P 500 Index starting from Jan 2, 1998. window size = 40
Training
signal and made no mistake during the long bull. We made nearly twice as much at the end of the 400 days. Then we tested the double weighted EM algorithm. There isn’t quite much diﬀerence from the single exponentially weighted EM algorithm. This is partly because the S&P 500 and the Dow give identical direction signals most of the time during the testing period. But a small diﬀerence at the end of the 400 days gives the double weight algorithm a 2% better performance. Finally we produce an allinone picture with all the prediction results from diﬀerent models for comparison. As seen from the picture, the two weighted HMGM performs convincingly better than the traditional EM algorithm.
5.4
Test on Data Sets from Diﬀerent Time Periods
To show the results generated by the HMGM are not random and can repeatedly beat the buyandhold strategy, we test the model on data sets from diﬀerent time periods. The data tested are four segments of the S&P 500 Index: November21994 to June31996,
CHAPTER 5. EXPERIMENTAL RESULTS
72
1.5 prediction market 1.4
1.3
1.2 return 1.1 1 0.9 0.8 0 50 100 150 200 trading day 250 300 350
Figure 5.8: Prediction of the 400day S&P 500 Index starting from Jan 2, 1998. window size = 100
Training
June41996 to December311998, August51999 to March72001 and March82001 to October112002 (the period January21998 to August41999 has been tested before), The ﬁrst two segments are the index in the bull market cycle while the latter two segments are the periods of a bear market. Experiments show that HMGM performs equally well under both situations.
5.5
Comparing the Sharpe Ratio with the Top Five S&P 500 Mutual Funds
The Sharpe Ratio, also called the rewardtovariability ratio, is a measure of the riskadjusted return of an investment. It was derived by W. Sharpe [Sha66]. Sharpe argues that the mean and variance by themselves are not suﬃcient to measure the performance of a mutual fund. Therefore he combined the two variable into one and developed the Sharpe Ratio. The deﬁnition of the Sharpe Ratio is quite straightforward: Let R F t be the return on the fund in period t, RBt the return on the benchmark portfolio or security in period t, and
2 1.1 1 0. 1.2 1.10: Prediction with multivariate HMGM for 400 days of the S&P 500 Index.3 1.6 1.CHAPTER 5.4 1. the HMM was not able to catch up with the change in trend swiftly. EXPERIMENTAL RESULTS 73 t213 t228 1.1 1 0.7 prediction market 1. Note from t213 to t228.9: Prediction with HMGM for 400 days of the S&P 500 Index.9 0 50 100 150 200 trading day 250 300 350 400 Figure 5.5 1.5 1.9 0 50 100 150 200 trading day 250 300 350 400 Figure 5.4 return 1.6 prediction market 1.3 return 1. .
6 return 1.4 1.12: Prediction with double weighted HMGM that has a conﬁdence adjustment variable.8 1.8 0 50 100 150 200 trading day 250 300 350 400 Figure 5.4 1.8 1.2 1 0. EXPERIMENTAL RESULTS 74 t164 t178 t213 t228 2 prediction market 1.2 1 0.CHAPTER 5. .6 return 1.11: Prediction with single exponentially weighted HMGM 2 prediction market 1.8 0 50 100 150 200 trading day 250 300 350 400 Figure 5.
8 0 50 100 150 200 trading day 250 300 350 400 Figure 5.14: Results on the period from November 2.6 1.1 1 0.2 1.13: Results from all models for comparison.4 1.5 1.9 0 50 100 150 200 trading day 250 300 350 400 Figure 5. 1994 to June 3. 1.CHAPTER 5.6 return 1.3 1. 1996 . EXPERIMENTAL RESULTS 75 2 double weight single weight HMGM multivariate Gaussian market 1.7 prediction market 1.4 return 1.2 1 0.8 1.
1998 2. 1996 to December 31.2 prediction market 2 1. 2001 .8 1.8 1.15: Results on the period from June 4.16: Results on the period from August 5.CHAPTER 5.2 prediction market 2 1.8 0 50 100 150 200 trading day 250 300 350 400 Figure 5.8 0 50 100 150 200 trading day 250 300 350 400 Figure 5.4 1.6 return 1. EXPERIMENTAL RESULTS 76 2.4 1.6 return 1.2 1 0.2 1 0. 1999 to March 7.
3) and σD be the standard deviation over the period: σD = The Sharpe Ratio (Sh ) is: Sh = ¯ D σD (5. 2002 Dt the diﬀerential return in period t: Dt = RF t − RBt ¯ Let D be the average value of Dt over the historic period from t = 1 through T : 1 ¯ D= T T (5. EXPERIMENTAL RESULTS 77 2 prediction market 1.8 1. Using the Sharpe Ratio.6 0 50 100 150 200 trading day 250 300 350 400 Figure 5. 2001 to October 11.CHAPTER 5.8 0.4) As we can see.2) Dt t=1 (5.6 1. the ratio indicates the average diﬀerential return per unit of historic variability of the diﬀerential return.17: Results on the period from March 8.2 1 0. we can compare the return of .4 return 1.5) T t=1 (Dt T ¯ − D)2 (5.
01726 0. diﬀerent strategies at the same risk.2: Comparison of the Sharpe Ratio between the HMM and the top 5 S&P 500 funds during the period of August 5. The absolute value of the positive one is much smaller than the HMGM prediction. .CHAPTER 5.00142 0. 4 of the 5 funds have negative Sharpe Ratios while the positive one is much smaller than the HMGM. 2001.098967 Table 5. The Sharpe Ratio is thus proportional to the t − statistic of the means.003319 0. The HMGM outperforms all of them. This is the meaning of beat the market mentioned in chapter 1.02948 0. This is because the tstatistic equals the Sharpe Ratio times the square root of the total number of testing units.011475 0. Symbol BTIIX FSMKX SPFIX SWPPX VINIX HMGM Explanation 0.084145 Table 5. The Double weighted HMGM consistently outperforms the top ﬁve S&P 500 mutual funds.05465 0. 2001 to October 11. We now compare the top 5 S&P 500 mutual funds that performed best over the past three years with the HMGM model we proposed.001446 0.01856 0.3: Comparison of the Sharpe Ratios during the period of March 8. EXPERIMENTAL RESULTS 78 Symbol BTIIX FSMKX SPFIX SWPPX VINIX HMGM Explanation 0. Four of the ﬁve funds have negative Sharpe Ratios. The Sharpe Ratio can be used for signiﬁcance testing for ﬁnancial time series analysis and prediction.000502 0. 2002. 1999 to March 7.024323 0.
this dependence is not important. as a sequence learning model.CHAPTER 5. They represent the probabilities of a variety of situations happening in the HMM. Bengio [BF96] introduced an InputOutput Hidden Markov Model (IOHMM) and applies it to the Electroencephalographic signal rhythms [CB04]. So there are three states in all. Second reason lies in the EM algorithm. But they still don’t realize the importance of time. In the two weighted EM algorithms we propose in the thesis. For example. These techniques enrich the representation power of the HMM in dealing with ﬁnancial time series data. One reason is it is usually hard to ﬁnd functions associated to the states that characterizes the behavior of the time series. in [MCG04]. Each expert has its own expertise: the ﬁrst one is responsible for low volatility regions. the second one is good at high volatility regions.6 Comparisons with Previous Work Hidden Markov Model. each of the ﬁve 400day testing periods generates . Patterns in ﬁnancial time series tend to change over time. Further. and the third expert acts as a collector for the outliers. as we have shown in the super ﬁve day pattern and the January Eﬀect cases. In video/audio/language/bio info signals processing. Financial time series diﬀers from other sequence data in that they are time dependent.4). they used three neural networks (called experts) as the emission functions at each state. the double weighted EM algorithm enables selfadjustment of the weights. But there have been few applications on the application of HMMs to ﬁnancial time series analysis and prediction. audio and video signals processing (see 2. Adding the timedependent weights incorporates temporal information into the training process of the HMM. We now compare our experimental results with Shi and Weigend’s work [SW97]. has been applied to many ﬁelds including natural language processing. The state parameters in the reestimation formulas all have actual meanings. This is an empirical research. The input sequence is just another sequence data. bioinformatics. they use a binomial density function at each state to represent the risk of default. Their model enables the HMM to generate the output probability based on the current state as well as the current input data sample from the input sequence. Their return over the 8 year period is 120%. or the data must be treated of equal importance. EXPERIMENTAL RESULTS 79 5. As described before. the input sequence is a time dependent value that changes from time to time. They test on 8 years of daily S&P 500 data from 1987 to 1994. In our experiments.
As we can see from the proﬁt curve (Figure 5. the proﬁt curves based on the prediction have a diﬀerent shape than the index curve. The proﬁt of the prediction thus follows the index behavior to a large extent. the proﬁt curve has a similar shape as the index curve.6). EXPERIMENTAL RESULTS 80 a return close to 100%. However the main problem of their prediction is not the rate of return.18: Too many positive signals result in a curve similar to the index. In all our ﬁve 400day periods. . Figure 5.CHAPTER 5. This reﬂects a more sophisticated strategy that generates dynamically changing signals. In other words. many times they are taking a long position. This means that there are too many positive signals generated by the prediction system.
it will make more mistakes. Comparing with neural network experts. It is an empirical study what the size of the training window should be. We introduce an important concept in the model design. HMGM can eventually catch up with the trend. 6. the training window is used in both training and testing as these two processes are combined together throughout the experiment. We show our ﬁndings through the experiments and indicate possible improvements to the tested model. Experimental results show that a 40day training window generates the best prediction. Although at times where the ﬁnancial time series is volatile. By using a mixture of Gaussian density functions at each state.Chapter 6 Conclusion and Future Work This chapter concludes the thesis. the emission functions provide a broad range of predictions. testing of the weighted EM algorithm in comparison with the classic EM algorithm. the use of supporting time series to help predict the targeting series.1 Conclusion Our experiments can be sorted into three categories: testing of HMGM with diﬀerent training window sizes. the parameters of the HMGM as emission density functions can be clearly derived from the EM algorithm. In fact. Results show that there is no incorrect bias as shown in the neural network experiments. The HMGM performs equally good in both bull market and bear market. The accuracy of prediction decreases as the size of the training window 81 . the training window. In a 20day experiment the cumulative rate of return is 20% above the actual market return over the 400 days of training and testing period.
e. buy and short signal reverses in very a very short time. We didn’t take the portfolio selection problem into consideration. we have to balance between shortterm sensitivity and longterm memory. Then we can extend the prediction to a form of density function rather than simply values. It will be interesting to apply the HMM technique to a portfolio of ﬁnancial assets and study the time series generated by these groups of assets. Since diﬀerent ﬁnancial time series have diﬀerent characteristics. This means to get the best prediction. we studied the S&P 500 Composite Index. we revise the general EM algorithm to a exponentially weighted EM algorithm. The weighted EM algorithm shows an increased sensitivity to recent data. such as developing of new indicators will help making better predictions.. But it has been observed that many time series may not follow the Gaussian distribution. In this thesis. This can be a valuable work to do. This way can we output richer information about the market movements. To overcome this we add a second weight to the exponential weight. the revised model generates more stable predictions and a higher rate of return. However during highly sensitive periods. the model might fall in the pitfall of frequently changing whipsaws. In a 20day training window testing within the same training data. Identifying useful side information for prediction. Functions and how functions are mixed at each state are not studied in this thesis. Noticing that recent data should be given more emphasis than older data from the past. 6. In other words. they will have diﬀerent patterns. CONCLUSION AND FUTURE WORK 82 changes in either direction. more speciﬁcally. This algorithm is motivated by the exponential moving average technique used widely in ﬁnancial engineering. The Viterbi algorithm could play an important .2 Future Work Rather than the predeﬁned 20day training window. i. we discussed the application of the Hidden Markov Model to one single ﬁnancial time series. The second weight which is calculated by the divergence of the S&P 500 and the Dow Jones Index. represents the market volatility. a portfolio composed of diﬀerent stocks will have diﬀerent rate of returns and risk levels. the size of the training pool and training window could be decided by a hill climbing or dynamic programming approach. The end of the 400day training and testing period generates a return of 195%. Gaussian distribution is the most popular distribution when modeling random or unknown processes.CHAPTER 6.
[Cov91] oﬀers a nice introduction to universal portfolio selection problem. the path of the Viterbi algorithm will be able to tell what assets should be included in the portfolio. by how much probability the market will go up or down. so by setting up a function that studies the relationship between sensitivity and accuracy. i. A more delicate model will be able to output densities rather than symbols. observing the price movements. Furthermore.e. The double weights in the HMGM model can also be trained. the density can be designed to describe the probability of falling into a range of values. we can expect to ﬁnd better weights. . These weights decide the sensitivity of the model. If we put functions that are estimated to best characterize diﬀerent assets at diﬀerent states.CHAPTER 6. The outputs of the HMGM models we present in the thesis are positive and negative symbols.. CONCLUSION AND FUTURE WORK 83 role in this application.
whipsaw A whipsaw occurs when a buy or sell signal is reversed in a short time. Usually if there is no doubt about the accuracy or veracity of the observation. Volatile markets and sensitive indicators can cause whipsaws. Sharpe Ratio Also called the rewardtorisk ratio. and the model should be reﬁtted. Rising peaks and troughs constitute an uptrend. Exponential Moving Average A moving average (MA) is an average of data for a certain number of time periods. It moves because for each calculation. that an investor can use to try to anticipate future price movements. risk Same meaning as volatility. then it should be removed. It is usually expressed as a percentage and computed as the annualized standard deviation of the percentage change in daily price. and the more money an investor can gain (or lose) in a short time. The more volatile a stock or market. the more risky the stock is. trend Refers to the direction of prices. indicator An indicator is a value. A trading range is characterized by horizontal peaks and troughs. equals the potential reward divided by the potential risk of a position. volatility Volatility is a measurement of change in price over a given period.Appendix A Terminology List outlier Outliers are a few observations that are not well ﬁtted by the best available model. falling peaks and troughs constitute a downtrend. usually derived from a stock’s price or volume. we use the latest x 84 .
a moving average lags the market. To do this. The reason to sell short is that you believe the price of that asset will go down. TERMINOLOGY LIST 85 number of time periods’ data.APPENDIX A. short To short means to sell something that you don’t have. To calculate today’s cumulative return. . By deﬁnition. proﬁt Proﬁt is the cumulative rate of return of a ﬁnancial time series. multiply today’s actual gain with yesterday’s cumulative return. you have to borrow the asset that you want to short. An exponentially smoothed moving average (EMA) gives greater weight to the more recent data. in an attempt to reduce the lag.
IEEE. A Hidden Markov ModelBased Approach to Sequential Data Clustering . European Symposium on Artiﬁcial Neural Networks. 81:637. pages 734–742. Joint IAPR International Workshops SSPR 2002 and SPR 2002. Canada. Journal of Political Economy. M. and Statistical Pattern Recognition. 1973. Syntactic. Scholes. L. Does the market overreact? Journal of Finance. Petrie. Y. Proceedings. Bengio. The Pricing of Options and Corporate Liabilities. HMM and IOHMM modeling of EEG rhythms for asynchronous BCI systems. Annals of Mathematical Statistics. F. [APM02] [BF96] [Bil97] [Boy83] [BP66] [BS73] [BWT85] [CB04] 86 . F. volume 2396 of Lecture Notes in Computer Science. In Structural. 1997. A Gentle Tutorial of the EM Algorithm and its Application to Parameter Estimation for Gaussian Mixture and Hidden Markov Models. 2002. Bengio and P. Black and M. Ontario. 1985. De Bondt. In Proceedings of the IEEE/IAFE/INFORMS 1998 Conference on Computational Intelligence for Financial Engineering. 2002.Bibliography [ADB98] A. InputOutput HMM’s for Sequence Processing. Back. pages 141–156. Statistical Inference for Probabilistic Functions of Finite State Markov Chains.. Boyles. M. Weigend A. 40:793–805. 1966. E. 37:1559–1563. New York. TR97021. H. A. A. 1996. Baum and T. August 69. What Drives Stock Returns?An Independent Component Analysis. 1983. Journal of the Royal Statistical Society. Frasconi. IEEE Transaction on Neural Networks. S. International Computer Science Institute. J. UC Berkeley. 1998. Thaler. Werner. 2004. Panuccio and V. and R. Murino. On the Convergence Properties of the EM Algorithm. Bilmes. Windsor. 7(5):1231–1249. R. Ser B 44:47–50. D. Bicego A. S. ESANN. Chiappa and S. Springer.
S. Forecasting the 30year U.Newbold. Wiley. T. New York. 1970. P. treasury bond with a system of neural networks. Maximumlikelihood from incomplete data via the EM algorithm. B. J. and C. 1991. 1993. Graham. 1(129). N. Academic Press. Journal of the Royal Statistical Society. Trading on the edge : neural. 1965. and fuzzy systems for chaotic ﬁnancial markets. G. Cambridge.H Lin.BIBLIOGRAPHY 87 MIT Press. W. Forecasting Economic Time Series. Dynamics of Meaning: Anaphora.F. Cover. 1986. 2001. 1996. 44:161–183. Noisy Time Series Prediction using a Recurrent Neural Network and Grammatical Inference. Furui. W. 1977. The Behaviour of Stock Market Prices. 2000. Neural Networks for Time Series Processing. The hierarchical Hidden Markov Model: analysis and applications. E. and N. Rubin. 2001. Journal of Business. Series. NeuroVe$t Journal. Fine. Lee Giles. and D. Ser B 39:1–38. Machine Learning. Academic Press. Deboeck. The University of Chicago Press: Chicago. The Intelligent Investor: The Classic Bestseller on Value Investing. 38:34–105. 1986. Mathematical Finance. Table of Integrals. I. Eﬃcient Capital Markets: A Review of Theory and Empirical Work. 32. [Cha93] [Chi95] [Cov91] [CWL96] [Deb94] [DLR77] E. Laird. Cheng. Journal of Finance. G. Fama. Tishby. C. Digital speech processing. A. Tsoi. Universal Portfolios. Presupposition and the Theory of Grammar. 1995. S. Y. Singer. Marcel Dekker. Dempster. CA. Gradshteyn and I. and A. [Dor96] [Fam65] [Fam70] [FST98] [Fur01] [GI00] [GLT01] [GP86] [Gra86] . B. S.S. Machine Learning. Charniak. and Products.Ryzhik. W. San Diego. pages 447–468. Fama. and recognition. M. 1998. 25:383–417. C.C. Dorﬀner. Lawrence. HarperBusiness.M. Wagner. genetic. F. S. 1996. New York. E. G. Chierchia. San Diego. synthesis. Neural Network World. Statistical Language Learning. Granger and P. Massachusetts. London. 1994.
Data mining: concepts and techniques. San Francisco. MIT Press. Rabiner. Baldi. Douglas. Han and M. A tutorial on hidden markov models and selected applications in speech recognition. Smyth. J. Mass. Cambridge. Hull. Incorporating spatial dependence and atmospheric data in a model of precipitation. McClure. P. 1989. J. Statistical methods for speech recognition. In Second International Conference on Credit Risk. 1997. Cambridge. Giampieri. 1994. Littlewood. IEEE. Kamber. In Proceedings of IEEE.H. McGraw Hill. ACM Press New York. Manning and H. Jelinek. J. Jebara and A. J. Y. Wilson Y. H. Larsen and S. pages 317– 379. Mitchell. [MCG04] [Mit97] [MS99] [Nic99] [PBM94] [Rab89] . In Proceedings of the sixth ACM SIGKDD international conference on Knowledge discovery and data mining . E. T. Crowder and G. In Journal of Applied Meteorology. Deformable Markov model templates for timeseries pattern matching. T. D.. Sch¨ tze. T. IEEE. 1994. Nicholas. 1999. L. Advances in Neural Information Processing Systems. Morgan [HG94] [HK01] [HLP88] [Hul00] [Jel97] [JP98] G. volume 91(3). M. Hunkapiller P. The MIT Press. A. 2004.A. IEEE Publishing. Options and Other Derivatives. volume 33(12). pages 195– 204. PrenticeHall. Machine Learning. Guttorp. and G.BIBLIOGRAPHY 88 [GS00] X. Hidden Markov Models of Biological Primary Sequence Infromation. 1988. In Proceedings of National Academy of Science USA . Hidden Markov Mixtures of Experts for Prediction of Switching Dynamics. England. R. Futures. Maximum conditional likelihood via bound maximization and the cem algorithm. C. A Hidden Markov Model of Default Interaction. 2000. Plya. 1999. pages 257–286. Chauvin and M. volume 77. NJ. Kaufmann. Ge and P. NY. Papers in Textlinguistics. editors. 10. Cambridge University Press. Pentland. London. London. Inequalities. In E. Upper Saddle River. Hu. Davis M. 2000. pages 1503–1515. Hardy. Proceedings of Neural Networks for Signal Processing IX: NNSP’99. In Foundations of u Statistical Natural Language Processing. USA. pages 81–90. pages 1059–1063. 1997. 1998. Chapter 9: Markov Models. New York . F. Hughes and P. J. 2001.
Srivastava. H. QC. Sharpe. Cambridge. Canada . M. Journal of Business. S. Ross. Timmermann. S. 1986.A. A. and H. C. Shannon. pages 244–252. 2002. An Introduction to Mathematical Finance. In 16th International Conference on Pattern Recognition (ICPR’02) Quebec City. Sullivan. Thaler. 1942. 1995. E. [RJ86] [Ros03] [Row00] [RW84] [RY98] L. Weigend. Constrained Hidden Markov Models. Weigend. 1998. Taking Time Seriously: Hidden Markov Experts Applied to Financial Engineering. S. Weigend and N. R. Certain Observations on Seasonal Movements in Stock Prices. In Proceedings of the IEEE/IAFE 1997 Conference on Computational Intelligence for Financial Engineering . In International Journal of Neural Systems. Walker. E. technical trading rule performance and the bootstrap. Yianilos. 39:119–138. A. 54:1647–1691. 1999. 15:184–193. Juang. S.. 1993. 26(2). [Sha49] [Sha66] [STW99] [SW97] [Tha87] [Wac42] [WG93] [WMS95] .BIBLIOGRAPHY 89 [RIADC02] B. Lovell R. A. 1966. New York. I. Davis and T. S. Communication Theory of Secrecy Systems. Time Series Prediction: Forecasting the Future and Understanding the past. 2000. Mutual Fund Performance. S. IEEE ASSP Mag. Anomalier: The January Eﬀect. AddisonWesley. Mixture densities. volume 2. 2003. Rabiner and B. R. Advances in Neural R. M. Shi and A. Journal of Business. Gershenfeld. 1987. An introduction to hidden Markov models. S. Caelli. 1:197–201. Journal of Finance. and A. maximum likelihood and the EM algorithm. A. IEEE International Symposium on Information Theory. Wachtel. 1949. June:4–16. R. SIAM Review. Datasnooping. page 20168. 12. F. volume 6. Towards EMstyle Algorithms for a posteriori Optimization of Normal Mixtures. 1984. Journal of Economics Perspectives. N. 1997. Cambridge University Press. Ristad and P. Roweis. W. White. Redner and H. Bell System Technical Journal. Nonlinear gated experts for time series: Discovering regimes and avoiding overﬁtting. pages 373–399. IEEE. 28(4):656–715. Information Processing Systems. Mangeas. Improved Estimation of Hidden Markov Model Parameters from Multiple Observation Sequences. C.
8(1):129–151. J. 1996. Xu and M. S. Zhong and J. The Annals of Statistics. On the Convergence Properties of the EM Algorithm. F. Training Hidden Markov Models with Multiple ObservationsA Combinatorial Method. In IEEE Transaction on Pattern Analysis and Machine Intelligence. On Convergence Properties of the EM Algorithm for Gaussian Mixtures. [ZG02] .BIBLIOGRAPHY 90 [Wu83] [XJ96] [XLP00] C. L. Neural Computation. 2002. Li and R. Wu. 11:95–103. volume 22(4). Plamondon. 1983. Proceedings of the IEEE International Joint Conference on Neural Networks. Jordan. pages 371–377. IEEE pressing. 2:1254–1159. 2000. HMMs and coupled HMMs for multichannel EEG classiﬁcation. Parizeau X. M. Ghosh.
This action might not be possible to undo. Are you sure you want to continue?
We've moved you to where you read on your other device.
Get the full title to continue reading from where you left off, or restart the preview.