Hidden Markov Models & Regime Change: DARWINs vs. S&P500

In this post, we will employ a statistical time series approach using Hidden Markov Models (HMM), to firstly obtain visual evidence of regime change in the S&P500. We will then compare the index’ performance to a DARWIN Portfolio, between June 2014 and March 2017.

Detecting significant, unforeseen changes in underlying market conditions (termed “market regimes“) is one of the greatest challenges faced by algorithmic traders today. It is therefore critical that traders account for shifts in these market regimes during trading strategy development.

They are hence a suitable technique for detecting regime change, enabling algorithmic traders to optimize entries/exits and risk management accordingly.

We will make use of the depmixS4 package in R to analyse regime change in the S&P500 Index, and subsequently compare its performance during those states to a DARWIN Portfolio over the same time period.

Hidden Markov Model – State Space Model (Source: StackExchange)

With any state-space modelling effort in quantitative finance, there are usually three main types of problems to address:

Prediction – forecasting future states of the market

Filtering – estimating the present state of the market

Smoothing – estimating the past states of the market

We will be using the Filtering approach.

Additionally, we will assume that since DARWIN Portfolio or S&P500 returns are continuous, the probability of seeing a particular return R in time t, with market regime M being in state m, where the model used has parameter-set P, is described by a multivariate normal distribution with mean μ and standard deviation σ [1].

Mathematically, this can be expressed as:

\(p(R_t | M_t = m, P) = N(R_t | μ_m, σ_m)\)

As noted earlier, we will utilize the Dependent Mixture Models package in R (depmixS4) for the purposes of:

Fitting a Hidden Markov Model to S&P500 returns data.

Determining posterior probabilities of being in one of three market states (bullish, bearish or unknown), at any given time.

We will then use the plotly R graphing library to plot both the S&P500 returns, and the market states the index was estimated to have been in over time.

Once these steps are complete, we’ll compare the risk adjusted performance of the S&P500 to that of a DARWIN Portfolio over the same time period.

You may replicate the following R source code to conduct this analysis on the S&P500.

S&P500 Market Regime Probabilities
(June 2014 to March 2017)

Interpretation: In any one “market regime”, the corresponding line/curve will “cluster” towards the top of the y-axis (i.e. near a probability of 100%).

For example, during a brief bullish run starting on 01 June 2014, the blueline/curve clustered near y-axis value 1.0. This correlates as you can see, with movement in the S&P500 (black line/curve). The same applies to bearishand “unknown” market states.

An interesting insight one can draw from this graphic, is how the Hidden Markov Model successfully reveals high volatility in the market between June 2014 and March 2015 (constantly changing states between bullish, bearish and unknown).

With all our analysis work complete, we can now compare risk adjusted returns’ performance of the S&P500 and a DARWIN Portfolio over the same time period (June 2014 to March 2017).

Good traders know that no more than between 5:1 and 10:1 D leverage is required to achieve 20% to 60% returns per annum, at 10% VaR. Background In a recent Spanish podcast episode, Darwinex CEO Juan Colón shed light on behaviours of successful DARWIN providers (traders) at Darwinex. Insights shared were as a result of […]

This post sheds light on the new Capacity Management tool, designed from the ground up to give traders more control over the capital invested in their DARWINs, while offering total transparency to investors. What does a Trader need to make a living off his passion? There is no easily applicable magic formula to achieve this, […]

Let’s continue where we left off in our last post on tick data collection. If you missed it, it’s important that you familiarise yourself with its contents first. Here’s the link again: https://blog.darwinex.com/download-tick-data-metatrader/ Therein, we promised a follow-up post that would discuss an approach for retail traders to automate tick data collection with the R […]

This is the second post in the MetaTrader Expert Advisor [EAS] series we’ve begun recently. In case you missed it, here’s a link to the first post: Commercial Expert Advisors: everything that glitters is not gold. If you’re wondering what “set & forget” means, it’s a common catch phrase used widely by many commercial MetaTrader […]

Subscribe to our newsletter to stay up to date with Darwinex news, we promise we won’t spam you!

Email

The Darwinex® trademark and the www.darwinex.com domain are owned by
Tradeslide Trading Tech Limited, a company duly authorised and regulated by the Financial Conduct Authority
(FCA) in the United Kingdom with FRN 586466. Our Company number is 08061368 and our registered office is Acre
House, 11-15 William Road, London NW1 3ER, UK.

This website stores cookies on your computer. These cookies are used to collect information about how you interact with our website and allow us to remember you. We use this information in order to improve and customize your browsing experience and for analytics and metrics about our visitors both on this website and other media. To find out more about the cookies we use, see our
Privacy Policy.

If you decline, your information won't be tracked when you visit this website. A single cookie will be used in your browser to remember your preference not to be tracked

CFDs are complex instruments and come with a high risk of losing money rapidly due to leverage.
77 % of retail investor accounts lose money when trading CFDs with this provider. You should consider whether
you understand how CFDs work and whether you can afford to take the high risk of losing your money.