From the November 2013 issue of Futures Magazine • Subscribe!

# The profitable, hidden and Markovian couple of Swiss and gold

Ask anyone on Wall Street, “What is the state of the market?” and chances are you’ll get one of three answers: Bull, bear or sideways. To the casual trader, these terms paint a rough picture of where the market is moving. But to a certain concept in mathematics, these terms precisely describe where prices are heading.

This concept is hidden Markov models (HMM). It was developed by Harvard Ph.D. mathematician Leonard E. Baum and his co-workers. The premise of the model is that the market is in one of five states — super bear, bear, sideways, bull or super bull — at any given time and transitions between states obey the Markov property. That is, transitions are dependent only on what the market’s state was one time interval before and not any earlier. How the market switches between the five states is indicated by transition probabilities that tell us the probabilities of one state transitioning to another.

The assumption that the market obeyed the Markov property occasionally was thought of as a good one because it removes the problem of lag. This occurs when a current calculation holds little value because it is based on price action much further in the past. The further back you go, the less of an effect price action should have on current trading decisions.

Just as how we know a bear and a bull market behave differently, each state is given a different probabilistic distribution of the observations it can output. Observations are any form of physical quantity we can measure from the market, namely price and indicators. Their uses are two-fold. One, if we know that the market is in a certain state, we can infer from that state’s distribution what the next observation could be. Two, a sequence of observations can be used to figure out the state of the market (see “State transitions,” below).

Over the last decade, HMMs have been creeping into the arsenals of some hedge funds. Because of their logically sound modeling process and subtle application of the Markov property, quants have found good use of HMMs in generating profitable trading signals.

However, HMMs showed their limitations when the time came to incorporate the next wave of trading techniques. Hedge funds experienced a gradual realization that more than one dimension of data was needed to outwit the market. Multi-time frame trading techniques in which two time frames were studied together were explored. Pairs trading in which prices of two assets were analyzed at the same time was the emphasis. Intermarket analysis in which the forecasting of an asset in one market considering the dynamics of another asset in another market was developed. The early form of HMMs weren’t conducive to integrating these new ideas and needed to be extended to allow for this possibility. Thus, the coupled hidden Markov model (CHMM) was born.

Unlike Baum’s original HMM, which is standard literature in applied mathematics, the CHMM is new research starting around the mid-2000s and doesn’t have a canonical formulation. While the CHMMs developed by researchers from different universities vary in their specifications, all of them share a common underlying theme: To take two HMMs and couple them by way of their transition probabilities.

Let’s start by giving our two HMMs names. HMM1 will model the currency market, and HMM2 will model the commodity market. Both of them make up our CHMM. Just as before, as time progresses, the state of each market will switch to another state with certain probabilities. Unlike before, this probability now depends on that market’s and the other market’s current states. Therein lies the coupling between both markets (see “Two HMMs coupled,” below).

With the two markets represented in our model, we also need two observations to track, namely the price or indicators of our currency and of our commodity. We feed both observation sequences into our CHMM to have it reconfigure itself to best represent each market.

The result is a model with the predictive power to forecast the next observation for both the currency and the commodity markets. Throughout coupling the two HMMs, we have not removed the Markov property when switching between states. The positives of HMMs are retained, the problem of lag kept buried and the possibility of incorporating another dimension of data made available. Quants were quick to explore pairs of assets to couple for the CHMM.

For us to capitalize on the predictive powers of a CHMM, it is best to use it to model two either strongly correlated or strongly uncorrelated assets.

The fundamental relationship between gold and the Swiss franc helps us choose these markets. One, it is believed that during times of economic unrest, investors tend to dump the dollar in favor of gold. Because gold maintains its intrinsic value, it implies a negative correlation between the dollar and itself. Two, following a gold-selling program, the Swiss National Bank held 1,290 tonnes of gold in reserves, which amounted to 20% of Switzerland’s assets. Therefore, the Swiss franc and gold should move in opposite directions. Both of these relationships has us believe that USD/CHF and gold are negatively correlated; the rise in one implies a fall in the other (see “USD/CHF vs. Gold,” below).

We now devise a trading strategy involving USD/CHF and gold coupled with a CHMM. First, we define the observable quantity. This would be the physical measure of the asset used in the rules when generating trading signals. If we are trading the tails of a distribution, it would be the CCI indicator. If we are riding a trend, it would be the ADX indicator. In line with our strategy, we define the observable quantity to be the RSI indicator. Thus, the dynamics of USD/CHF and gold will be represented by their RSIs.

Second, we need to construct our strategy. With our goal being to illustrate the features of the CHMM, we’ll use a simple four-period 10-minutes RSI, buying when it crosses over 20% (oversold) and selling when it crosses under 80% (overbought).

We’ll use the CHMM’s forecasted USD/CHF’s RSI value instead of the actual RSI. While it seems we need to decide on a filtering rule when incorporating gold’s RSI, we don’t. The beauty of the CHMM is the theory behind state switching nurtures this relationship: The coupling between USD/CHF and gold. By periodically loading the four-period RSI values of USD/CHF and gold into the CHMM, it’ll reconfigure itself during each load, figuring the relationship between USD/CHF and CHMM that best makes sense. Any prediction made for USD/CHF will then take into account both the dynamics of USD/CHF and gold.

Finally, we set a one-to-three risk-to-reward ratio using two-times and six-times the 12-period average true range for the stop loss and profit target, respectively. Furthermore, we’ll run our strategy first with fixed sizing and then with dynamic sizing where the size is defined as a fixed amount multiplied by the probability at which the CHMM switches states. Basically, we are aligning our confidence in each trade with the model’s confidence in predicting the next state (see “State switches and RSI values,” below).

The measure of success of our CHMM strategy is based on whether it is more profitable when trading based on the CHMM’s forecasted RSI values than on actual RSI values. Such a comparison will be made.

With the interest of investigating the robustness in the CHMM model accurately forecasting values, we will use the model to trade on another setup, one that uses the Commodity Channel Index (CCI) indicator. For space reasons, we won’t go into the details of the CCI strategy, but it has been optimized over a test period to perform well using actual CCI values. The goal then is for the CHMM model to register an improvement in profits when trading the same already profitable strategy, but using its forecasted CCI values.

We compare the performances of the standard RSI and CCI systems with those enhanced by the four variants of the CHMM—namely predictions made by a Viterbi algorithm and a non-Viterbi algorithm, each using fixed or dynamic sizing. The test period is 10-minute price bars over the first four months of 2013. (Viterbi and non-Viterbi algorithms are basically two different ways to get the next most probable state.)

Trading based on the CHMM forecasted RSI and CCI values performed better than the standard systems. The performance difference is pronounced for the RSI setup where implementing the CHMM turned a losing system of –4.55% to 5.51% returns for Viterbi with fixed sizing. The CHMM’s performances trace standard’s fairly closely in the first month, after which they start to make gains while the standard RSI starts to record losses (see “CHMM RSI system,” below). The Sharpe Ratio has improved to between +1.670 to +1.923 among all four variants.

Running our comparison for the CCI setup, we see that returns improved across all four CHMM variants. The CCI standard pulled in a return of 0.35%. The returns for CHMMs are 0.36% to 0.49% (see “CHMM CCI system,” below). Further, comparing the Sharpe Ratio between fixed sizing and dynamic sizing across CHMM variants, we see an improvement of about +0.2 for the RSI and +0.03 for the CCI. This hints to us that there’s even value in the model’s confidence in the prediction of the next state.

Having witnessed the CHMM’s ability to generate a profitable trading strategy by coupling the USD/CHF with gold, we are left to wonder what other assets the CHMM can couple to make money.

If we stick to the general rule that the coupled assets either need to be strongly correlated or uncorrelated, the CHMM should preserve its profitability. The theory behind the CHMM and HMM is robust enough to decode the relationship between two assets and also deduce how the transition probabilities in either market affect the other. Be it equities in the same sector, rates and indexes, cross yen currencies, currencies and commodities, bonds and economic indexes, or even macro and micro price movements, there are a number of possibilities. It boils down to choosing the assets and defining the observations.

Can the CHMM combine three assets together? Of course it can. But just as it takes two to tango but three is a tangle, combining three assets becomes a messier mathematical sight.

Donny Lee is a quantitative developer at a hedge fund trading forex in Singapore. He currently is refining trading strategies largely centered on Markov models. You can download the technical and supplementary code, as well as data sets, from www.financeberry.com/chmm.html. Reach Donny at quantdonny@yahoo.com.

Page 1 of 5