13.08.2022 Views

advanced-algorithmic-trading

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

206

Figure 14.2: Hidden Markov Model: States and Observations

• Prediction - Forecasting subsequent values of the state

• Filtering - Estimating the current values of the state from past and current observations

• Smoothing - Estimating the past values of the state given the observations

Filtering and smoothing are similar but not identical. Smoothing is concerned with wanting

to understand what has happened to states in the past given current knowledge, whereas filtering

is concerned with what is happening with the state right now.

It is beyond the scope of this book to describe in detail the algorithms developed for filtering,

smoothing and prediction. The main goal of this chapter is to apply Hidden Markov Models to

Regime Detection. Hence the task at hand reduces to determining which "market regime state"

the world is currently in, utilising the asset returns available to date. This is a filtering problem.

Mathematically, the conditional probability of the state at time t given the sequence of

observations up to time t is the object of interest. This involves determining p(z t | x 1:T ). As

with the Kalman Filter it is possible to recursively apply Bayes’ Rule in order to achieve filtering

on a Hidden Markov Model.

14.3 Regime Detection with Hidden Markov Models

In this section Hidden Markov Models will be implemented using the R statistical language via

the Dependent Mixture Models depmixS4 package. HMM will be used to analyse when US

equities markets are currently experiencing various regime states. In a later chapter these regime

overlays will be used in a subclassed RiskManager module of QSTrader to adjust trade signal

suggestions in a systematic trend-following strategy.

Within the chapter a simulation of streamed market returns across two separate regimes–

"bullish" and "bearish"–will be carried out. A Hidden Markov Model will be fitted to the

returns stream to identify the posterior probability of being in a particular regime state.

Subsequent to outlining the procedure on simulated data the Hidden Markov Model will be

applied to US equities data in order to determine two- and three-state underlying regimes.

Acknowledgements: This chapter and code is heavily influenced by the article over at Systematic

Investor on Regime Detection[58]. Please take a look at the article and references therein

for additional discussion.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!