Main Page > Articles > Regime Detection > The Forward-Backward Algorithm: Calculating Smoothed State Probabilities for Robust Regime Identification

The Forward-Backward Algorithm: Calculating Smoothed State Probabilities for Robust Regime Identification

From TradingHabits, the trading encyclopedia · 7 min read · February 28, 2026
The Black Book of Day Trading Strategies
Free Book

The Black Book of Day Trading Strategies

1,000 complete strategies · 31 chapters · Full trade plans

Filtered vs. Smoothed Probabilities

When working with Hidden Markov Models (HMMs), we are often interested in inferring the sequence of hidden states that generated the observed data. There are two main ways to do this: filtering and smoothing. Filtering involves computing the probability of being in each state at time t, given the observations up to time t. Smoothing, on the other hand, involves computing the probability of being in each state at time t, given all the observations in the dataset. Smoothed probabilities are generally more accurate than filtered probabilities, as they use more information.

The Forward-Backward Algorithm

The Forward-Backward algorithm is a dynamic programming algorithm that is used to compute the smoothed state probabilities in an HMM. It consists of two passes: a forward pass and a backward pass.

  • Forward Pass: The forward pass computes the forward probabilities, which are the joint probability of being in each state at time t and observing the data up to time t. The forward probabilities are computed recursively, starting from the initial state probabilities.
  • Backward Pass: The backward pass computes the backward probabilities, which are the conditional probability of observing the data from time t+1 to the end, given that we are in a particular state at time t. The backward probabilities are also computed recursively, starting from the end of the data.

Once the forward and backward probabilities have been computed, the smoothed state probability for each state at each time t can be calculated by multiplying the forward and backward probabilities and normalizing.

The Importance of Smoothed Probabilities for Trading

For traders, using smoothed probabilities for regime identification has several advantages over using filtered probabilities. Filtered probabilities can be noisy and may lead to frequent and unnecessary changes in the identified regime. This can result in over-trading and poor performance. Smoothed probabilities, on the other hand, provide a more stable and accurate estimate of the hidden state sequence. This can lead to more reliable trading signals and improved performance.

For example, consider a regime-switching trading strategy that switches between a trend-following model and a mean-reversion model based on the identified market regime. If the regime identification is noisy, the strategy may switch between the two models too frequently, leading to whipsaws and losses. By using smoothed probabilities, the regime identification will be more stable, and the strategy will be more likely to stay in the correct model for longer periods of time.

Conclusion

The Forward-Backward algorithm is a fundamental tool for working with HMMs. By providing a way to compute smoothed state probabilities, it allows for a more accurate and robust identification of hidden market regimes. For traders who are using HMMs to develop their strategies, understanding and using the Forward-Backward algorithm is essential for success.