 In this talk, I will show you how to use an infinite state hidden markup model to help model the state of the markets. When it comes to the stock market, you'll hear it commonly being in a bull or bear state. If it's in a bull market, this means that it is moving up on average. And if it is in a bear market, this means that it is moving downwards on average. You'll commonly see statues of bulls and bears around stock exchanges around the world, but how does this help us model the stock market? In markup state models, each observation depends on what state the world is in. So in this case, a bull market would be a state where the average is greater than zero because it is going up and increasing every day. And a bear market would be the opposite. It would be a state where the average is less than zero because it is decreasing every day. You'd need to pick how many states there are before fitting the model. So in that case, if you want to add more states, this can be a piece of a problem. For example, you might want to include things such as a sideways state where the average is equal to zero, or maybe a strong bull or a strong bear state where the average values are a lot larger. And also, what if the states are different? In a markup state model, you're assuming that each state is the same, but actually each bull market might have a different average over time. So instead, we can use an infinite state markup model, and this lets the data decide how many states are appropriate. And each state has its own parameters, and it is a Dirichlet process type of model. So this means we can use my Dirichlet process package to fit these types of models very simply. And in just three lines of code, you can start fitting these types of models on your own data. Now in terms of data for this application, we have the daily returns of the SPI ETF, which represents the top 500 US companies, and is a good representation of the stock market. You can download this data from alpha-vantage.co for free. And after downloaded, we normalised this data by the daily 30-day rolling volatility. We then fit the infinite state-healer markup model using my Dirichlet process package. Now this fits this type of model by doing two things. Every day, we check whether that day belongs to the previous states, or whether it should create its own new states. We go through each data point in sequence, asking this question and seeing if it belongs to the previous state, or it should create its own states. Once all the states have been assigned, we then update the underlying parameters of each state using all the data that belongs to that state. And then we repeat this process until it has converged. Now in terms of results, I've plotted here the SPI price, again over time, and coloured the data points based on whether they are enabled or bear markets. The ball markets are indicated by the black dots, and the bear markets are indicated by the yellow dots. And we can see that there has been three bear markets over the last 20 years. The first being in the early 2000s after the dot-com crash, and then the next bear market was in 2007 over the great financial crisis. And then finally the third bear market was in early 2020 with the COVID crisis. When we look at the average parameters over these different states, we can see that the bear markets have got values that are less than zero as they correspond to bear markets, and the ball markets have values greater than zero, and the current ball market that we are in has got a slightly higher average than previously seen before. Now as this is a Bayesian model, we get the uncertainty for free, so we can plot the 95% incredible interval around the average values as well. So what have we learned from this type of model? Will we no longer have to set the number of states beforehand and the data has decided how many states are appropriate? We've also got the average length of each market state to help us understand on average how each state long lasts for. We have also observed how the parameters have changed with each state and can see that our current market that we are in, the average parameter seems to be larger than the previous ball markets. If you'd like to learn more, you can read my original blog post on my websites, or you can download my Derechu process package from Cran or go to the GitHub. And then finally I suggest that you check out AlphaVantage for their free market data and see what other things they also provide. Thank you for listening to my talk.