Original link:tecdat.cn/?p=3784

Original source:Tuo End number according to the tribe public number

 

Understanding how different market conditions affect the performance of your strategy can have a huge impact on your earnings.

Some strategies perform well in volatile markets, while others need a strong and smooth trend or risk a prolonged decline. Figuring out when to start or stop a trading strategy, adjusting risk and money management techniques, and even setting parameters for entry and exit conditions all depend on the “state” or current conditions of the market.

Being able to identify different market states and change your strategy accordingly can mean the difference between market success and failure. In this article, we will explore how to identify different market segments (mechanisms) by using a powerful machine learning algorithm called a “hidden Markov model”.

Hidden Markov model

A Markov model is a probabilistic process that looks at the current state to predict the next state. A simple example is watching the weather. Suppose we have three weather conditions (also known as zones or mechanisms) : rainy, cloudy, and sunny. If it rains today, the Markov model looks for the probability of each different weather situation happening. For example, there is a higher probability that it will continue to rain tomorrow, a slightly lower probability that it will be cloudy, and a lower probability that it will be sunny.

The probability that today’s weather will change tomorrow

Rainy rainy 65 percent

Rainy and cloudy 25%

Rainy sunny 10%

Cloudy and rainy 55%

Cloudy 20% of cloudy

Cloudy sunny 25%

Sunny and rainy 10%

Sunny and cloudy 30%

Sunny sunny 60%

This seems like a very simple process, but the complexity lies in not knowing the probability of each state’s transition and how to interpret these probabilities over time. This is where hidden Markov models (HMM) come in. They are able to estimate the transition probability of each state and then output the most likely state based on the current situation.

We can define markets as bullish, bearish, flat, or high or low volatility, or a combination of factors that we know affect the performance of our strategies, not weather conditions.

Build a real-world data model

We are looking at different market mechanisms based on these factors, which we can then use to optimize our trading strategies. To do this, we will use EUR/USD data to build the model.

First, build our data set.

ModelData <-data.frame (LogReturns, ATR) # create data for our HMM model ModelData < -modelData [-c (1:14), Colnames (ModelData) < -c ("LogReturns", "ATR") # name our columnCopy the code

  

We set logarithmic return and ATR as our dependent variables. Using the data box we just built, we set up three different states and set the dependent variable distribution to a Gaussian distribution.

HMMfit <-fit (HMM, verbose = FALSE) # Add our model to the datasetCopy the code

The transition matrix gives us the probability of moving from one state to the next.

HMMpost <-posterior (HMMfit) # to find posterior probabilities of each state in our data setCopy the code

 

So we can see that we now have the probability of each state and the highest probability category.

Let’s see what we found:

Probability of each state:

We can see that state 3 is usually a period of high volatility and large volatility, state 2 is characterized by moderate volatility, and state 1 is characterized by low volatility.

Hidden Markov models are powerful tools that can give you insight into changing market conditions.

Other questions? Contact us!

 


Most welcome insight

1. Use R language to simulate the mixed queuing random service queuing system

2. Queuing theory is used in R language to predict waiting time

3. Realize markov chain Monte Carlo MCMC model in R language

4. Markov regime switching model in R language

5. Matlab Bayesian hidden Markov HMM model

6. Use R language to simulate the mixed queuing random service queuing system

7. Portfolio optimization in Python based on particle swarm optimization

8. Research on accident prediction of traffic casualties by R Language Markov Transformation model

9. Identifying changing Stock Market Conditions with Machine learning: Application of Hidden Markov Models