Pages

06 January 2013

Providing a statistical framework for DMI, MACD and RSI

After 16,000+ page views in the last year, I'd like to take advantage of this opportunity to thank all of my visitors and followers for their continued interest and support. And while today is the Twelfth Night or Epiphany it's also just in time for wishing everyone a profitable, prosperous and healthy New Year.

Now over to the subject of this posting. In 2010 a former software engineer at Intel Corporation by the name of Michael Gutmann published an article on "A Statistical Approach to Technical Indicators". Gutmann also wrote a book titled "The Very Latest E-Mini Trading: Using Market Anticipation to Trade Electronic Futures."

In his article Gutmann illustrates a method of converting technical indicator outputs from asset-specific values to statistical measures of price extension and compression. He stated that the results of such indicators can be used across markets without modification.

Gutmann explains that standard deviation is the most common method of estimating the spread, or dispersion, of a data set:
The data’s mean, or average, referred to with the Greek letter μ (“mu”), is first calculated. The data’s standard deviation is then calculated as the average distance of the data set from its mean. The standard deviation, referred to with the Greek letter σ (“sigma”), is easy to work with because it takes values that are the same units as the original, underlying data.
The science of statistics has determined that for many naturally occurring populations (population height, weight, test score, etc.), data is “normally” distributed about its mean. This is the well-known bell curve of population distribution. Interestingly, bell curves are completely defined by their mean and standard deviation. This allows one to say that a normal distribution has approximately 70% of its data contained with one standard deviation of its mean and 95% within two standard deviations, regardless of the values computed for the data’s mean and standard deviation.
 

Based on the work of Gutmann it is possible to rebuild well known technical indicators like DMI, MACD and RSI to their so-called z-scored versions. Gutmann elaborated this concept as follows:

Making use of standard deviation with market price and, in particular, bar charts, is straightforward. The standard deviation of recent price history is first calculated using some number of previous bar prices. Picking a history length is similar to selecting the length for a moving average indicator. Then a standard deviation relative position of recent price can be determined. Specifically, the current price, x, is said to be at “(x – μ)/σ standard deviations”; that is, the current price, x, is some number of standard deviations displaced from the mean.
The value (x – μ)/σ may at first seem obscure. But consider the meaning of any fraction or ratio, for example, the fraction one-third. An interpretation of the fraction is, How many 3s are there in 1? In the same way, the ratio (x – μ)/σ asks, How many standard deviations are there in x – μ, the distance of the current price from market mean price? The technical term for the ratio (x – μ)/σ is “z-score.” By converting indicator output values to z-scores we are able to move technical indicators to a statistical basis.



As an example let's take a look at the z-scored MACD or MACD_Z. All three components are painted in units of their respective standard deviation. Bearing the statistical concept of "normal distribution" in mind one is capable of a making a probabilistic statement on the direction of the indicator and thus of the instrument it is measuring. When MACD_Z is i.e. at or near the -3 standard deviation line, there is a 99.7% change MACD_Z will snap back (if only for some time). Next to exposing prices extremes z-scored indicators also have this ability to confirm a continuation pattern. Notice how MACD_Z finds itself on more than a few occasions confined between +/- 1 or 2 standard deviations, by repetition the standard deviation seems to repel the indicator curve. The last feature I'd like to mention is showing divergences.

In his conclusion Gutmann states:
Moving technical indicators to a statistically valued format retains the properties of the original indicator while making the new statistical indicators robust and portable. The statistical indicator often eliminates the need for time-consuming and error-prone modifications. This sort of simple statistical technique isn’t rocket science but it is very useful.

Finally I'll only demonstrate charts with the other two z-scored indicators DMI_Z and RSI_Z, because the concept stays the same.


The thinkscript study codes are available in the comment section below this posting. Please take a look at the study headers where credit is given to Louis Sparks, whose script of his standardized MACD version was shared in the Yahoo thinkscript group. The other z-scored studies are derived from Louis' version.  Enjoy!