Hidden Markov Model - Probability Cone

The Hidden Markov Model - Probability Cone Indicator employs Hidden Markov Models (HMMs) for forecasting future price movements in financial markets. HMMs are statistical tools that predict transitions between hidden states, such as different market regimes, based on observed data. This makes them valuable for understanding market behaviours and projecting future price trajectories. As discussed in the Hidden Markov Model indicator, HMMs predict future states and their associated outputs based on the current state and model parameters.
The probability cone indicator therefore uses the knowledge about the current identified "state" or "regime" and with the help of transition probabilities, emission probabilities and initial probabilities generate a probabilistic forecast of the expected future price movements. To better understand the behind the Probability Cone we encourage you to use and learn about our free version of the Probability Cone as well as for even deeper understanding the Probability Cone Pro.
WHAT ARE REGIME DEPENDENT FORECASTS
As mentioned above the indicator creates probabilistic forecasts of future price movements dependent on the current identified "state" or market "regime" via the Hidden Markov Model. In the image below we can see an example.
In this example we can see 3 different probability cones forecasting a 70% and 90% probability range (15% and 5% quantiles respectively). What you may notice is that the 3 probability cones look vastly different, despite using the same probability ranges as well as being generated from the same model trained on virtually the same data. What allows for this difference in the forecast is conditioning the forecast on the current most likely identified state by the HMM.
The first most wide cone is generating a forecast taking into account that the model identified the current market condition to be a very volatile which is a characteristic of the state identified by the orange coloured posterior probability. The second cone is significantly more narrow as that state identified by the purple posterior probability is characterised by lower volatility. Nevertheless, the last probability cone is generated from the state that is characterised by the lowest volatility, we can also see the light blue posterior probability to be the highest at that time.
The indicator also allows you to specify whether you wish to display probability based labels at the edges of the cone or whether you would prefer to display percent change based labels. With percent change labels you get the exact percentage value of the probabilistic increase or decrease of the price. See the example below
BARS BACK OFFSET vs DATE BASED OFFSET
The cones position can be offset by specifying the number of bars we wish to move it back similarly as with the rest of probability cone indicators. This indicator has however an additional, date based offset implemented. A user can therefore specify the position of the cone by specifying a date in the settings. The advantage of using the date based offset is that once it is turned on the user can also slide the cone up and down the chart with their mouse without having to manually adjust the date in the settings.
DIFFICULTIES WITH GENERATING FORECASTS (advanced):
The estimation of the probability cone, gets more difficult the more complex the model gets. A simple normal distribution probability cone can scale the distribution over time by simply multiplying the drift by the number of time steps and the volatility by the square root of time steps we wish to forecast for. More complex distributions often have to rely on mode advanced methods like convolutions, monte carlo or other kinds of approximations.
To estimate the probability cone forecast for the Hidden Markov Model, the indicator integrates two primary methodologies: Gaussian approximation and importance sampling. The Gaussian approximation is utilized for estimating the central 90% of future prices. This method provides a quick and efficient estimation within this central range, capturing the most likely price movements. The gaussian approximation will result in a forecast with an equal mean and variance as the true forecast, it will however not accurately reflect higher moments like skewness and kurtosis. For that reason the tail quantiles, which represent extreme price movements beyond the central range (90%), are estimated via importance sampling. This approach ensures a more accurate estimation of the skewness and kurtosis associated with extreme scenarios. While impoortance sampling leverages the flexibility of monte carlo as well as attempts to increase its efficiency by sampling from more precise areas of the distribution, the importance sampling may still underestimate most extreme quantiles associated with the lowest probabilties which is an inherent limitation of the indicator.
Example of gaussian approximation cone for probabilities above 5% (90% range):
Example of importance sampling cone for tail probabilities lower than 5% (beyond 90% range):
WARNING!
As per usual understand that the probabilities are estimations and best guesses based on the historical data and the patterns identified by the model and do not represent the true probability which is unknown in reality.
Settings:
- Source: Data source used for the model
- Forecast Period: Number of bars ahead for generating forecasts.
- Simulation Number: Number of Monte Carlo simulations to run in the case of importance sampling
-Body Probability: Specifies the inner range of the probability cone. The probability specifies the ammount of observations that are expected to fall outside of this range
- Tail Probability: Specifies the outter range of the probability cone. When this probability is under 5%, importance sampling will turn on
- Lock Cone: When ticked on, the cone will be locked at its current position.
- Offset Cone Based on Date: When ticked on, the position of the cone will be determined by the selected date.
- Offset: When "Offset Cone Based on Date" is turned off, you can use offset setting to specify the position of the cone projection.
- Date: When "Offset Cone Based on Date" is turned on, you can use the date setting to specify the date from which the forecast starts.
- Reestimate Model Every N Bars: This is especially useful if you wish to use the indicator on lower timeframes where model estimation might take longer than for the new datapoint to arrive. In that case you can specify after how many bars the model should be reestimated.
- Training Period: Length of historical data used to train the HMM.
- Expectation Maximization Iterations: Number of iterations for the EM algorithm.
- Cone Colors: Customizable colors for the probability cone, when approximation is on and when importance sampling is on
Skrypt tylko na zaproszenie
Dostęp do tego skryptu mają wyłącznie użytkownicy zatwierdzeni przez autora. Aby z niego korzystać, należy poprosić o zgodę i ją uzyskać. Zgoda jest zazwyczaj udzielana po dokonaniu płatności. Więcej informacji można znaleźć w instrukcjach autora poniżej lub kontaktując się bezpośrednio z Motgench.
TradingView NIE zaleca płacenia za skrypt ani korzystania z niego, jeśli nie ma pełnego zaufania do jego autora i nie rozumie się zasad jego działania. Można również znaleźć darmowe, otwartoźródłowe alternatywy w skryptach społeczności.
Instrukcje autora
Wyłączenie odpowiedzialności
Skrypt tylko na zaproszenie
Dostęp do tego skryptu mają wyłącznie użytkownicy zatwierdzeni przez autora. Aby z niego korzystać, należy poprosić o zgodę i ją uzyskać. Zgoda jest zazwyczaj udzielana po dokonaniu płatności. Więcej informacji można znaleźć w instrukcjach autora poniżej lub kontaktując się bezpośrednio z Motgench.
TradingView NIE zaleca płacenia za skrypt ani korzystania z niego, jeśli nie ma pełnego zaufania do jego autora i nie rozumie się zasad jego działania. Można również znaleźć darmowe, otwartoźródłowe alternatywy w skryptach społeczności.