Okay. We looked, so far, at the first class of dynamic latent variable models, namely, State-Space Models. These models have continues hidden and observed states. Now, let's talk about the second large class of dynamic latent variable models, namely, Hidden Markov Models. Again, the formulation and setting here is nearly the same as for State-Space Models, where from the observed signal y and we want to build a dynamic hidden variable model. But this time, with a hidden discrete state variable x. Again, the idea here is that such state would capture all the relevant information about the system and would become sufficient statistic for predicting the next failure of the observed signal. The hidden state x takes values in some discrete state of states. Without any loss of generality, we can label the states as one, two, three, and so on. But for any specific model, you could also name these states differently. For example, if a hidden state denotes a state of economy, you could have a state of benign regime, a state of stress regime, a state of crisis regime, and so on. As in the State-Space Models in Hidden Markov Models, we choose first-order Markov dynamics for the hidden state which, as we just said, is discrete in this case. Well, in this case, the same formula as before for the probability of the whole path of xy, which is repeated here for convenience. According to this formula, the probability of a particular pair xt and yt at the time step t is given by the product of transitional probability for x and the mission probability for y. So, so far, we've said that the hidden state in the Hidden Markov Model is assumed to be discrete. Now, what about the observed state y. This can be really anything can HMM models, depending on what you want to model. If your observations are discrete values, you can use a multinomial distribution as the mission distribution for your model. If your model continuous variables, then your mission probabilities should be continuous distributions. For example, Gaussian distributions. Again, the same way as for State-Space Models, as long as a model now includes both the unknown hidden state and model parameters data, forecasting in this framework requires addressing two problems, Inference and Learning. When we do Inference, we learn the hidden state by computing probabilities over path of x conditional on a path of y and model parameters data. In Learning, we learn optimal model parameters by training model with observable data while keeping the distribution over hidden variables fixed. When we just start with the model, we do not know either the distribution of hidden variables or optimal model parameters data so we have to address both tasks simultaneously during model training using, for example, the EM algorithm. For the specific case of Hidden Markov Models, the EM algorithm is known as the Baum-Welch algorithm. In their E-step, it computes the posterior probabilities of hidden variables given observed values of y. This is computed in two consecutive passes through all points in the time series. In their Forward pass, we recursively compute the probability of the whole path of x given the observed path of y in the current model parameters data. In this calculation, we move forward in time across all our data points from the first one to the last one. In the Backward pass, we start from the very last point and recursively compute joint probabilities of all future values of x between time t and the final time T, given future observations of y. The result in posterior for the hidden variable for any given time t event is then computed by combining these two calculations. The M-step computes the optimal values of parameters for a fixed distribution of hidden variables. Again, we will not go into the details of the Baum-Welch algorithm for Hidden Markov Models, but instead, refer you to a very good and old tutorial by L. Rabiner on HMM models and their estimation. So, the framework that we just presented so far is the most basic setting of a Hidden Markov Model in which we have only a single hidden variable x that can take values in some discrete set of K possible values. This approach might not have enough expressive power. For some cases, they need a richer dynamics. And one way to do it would be via extending the basic HMM framework and make it a vector of hidden states instead of a single hidden state. Such a construction is called a factorial Hidden Markov Model. The main problem with a factorial HMM is that, in its most general form, the model has way too many parameters to estimate. And this is because in the general case, there would be many ways, different components of the hidden state could interact between themselves across different time steps. But if we further restrict such models, we can obtain some more practical, useful model and frameworks. For example, Dynamic Bayesian Networks. Finally, a short memory is a serious limitation of both Hidden Markov Models and State-Space Models. As we discussed earlier, if more than one previous failure is important for predictions, some limited ways for this are available in dynamic way and variable models by using keyword of Markov dynamics. But this approach reaches its limits rather fast. In the next video, we will talk about methods that work better whenever a long or medium term history is important for modeling. Now, I want to briefly outline some interesting applications of Hidden Markov Models in Finance. A potential used case for such models in finance arises whenever there is some factor that impacts everything else and yet, this factor is not directly observable or measurable. A good example is the notion of the state of economy. What is the state of economy? There are no market observables that will be called the state of economy. Instead, we can have some observables that are indicative of the state of economy such as, for example, S&P 500, Index GDP, and so on. So, this seems a good setting for Hidden Markov Model. Then let's have a hidden variable called the Regime, that would respond to the current state of the economy. If you have a sizable investment portfolio, you know for a fact that performance of this portfolio does depend on the overall state of economy. So, you can build a model for your portfolio with the hidden factor for the Regime. And make probabilistic forecasts for performance of such portfolios that would acknowledge the uncertainty due to your imperfect knowledge of the actual state of economy. And such models are, actually, widely used in asset management. But similar ideas can also be applied for quantitative trading as well. For example, a paper by a day, and co-workers called "Trend Following Trading under a Regime Switching Model" from 2010, discussed Hidden Markov Model with two states of the market, the "bull market" and the "bear market." Another similar idea is often used in modeling credit portfolios. Credits in the portfolio of loans, mortgages, or credit cards may be affected by some common industry-wide and absorbed factors, sometimes, referred to as "frailty" factors. For example, Sonic like the state of economy can be used here again. But this time, implication to credit risk rather than market risk. So, this, briefly, was a crash introduction to Hidden Markov Models. We will build on the ideas of this approach and other related dynamic latent variable models in the next video when we will talk about Neural Network Methods for Sequential Data. So, let's do it next.