## Thursday, August 18, 2016

### Systematic Trading: Getting Technical with Technical Indicators

There are few investors and traders who have never used a technical indicator. Some use them as part of their core trading strategies, others as confirmation or as a timing tool. I am reasonably certain even the most ardent value investors perhaps look at them in time of trials and tribulations. The set of these indicators are large (and ever increasing) as different ones developed over course of time, often from different markets and asset classes1. This is usually not a problem, as most practioner will settle down with one or two favorites.

However, most indicators have a lot in common among them. They are usually a function of past and present market data. They can be usually expressed as a function of returns of the underlying, and they tend to move in a range (though not always statistically stationary2).

Taking the example of a simple one - the moving average cross-over indicator. This is expressed as a difference of two moving averages (a short and a long ones). Mathematically, this can be represented as $mom=\sum_{i=0}^{n_1} a_i.P_i - \sum_{i=0}^{n_2} b_i.P_i$, where $n_1$ and $n_2$ are the short and long moving average periods, $a_i$s and $b_i$s are the weights (for simple moving average $a_i=1/n_1$ etc.) and $P_i$s are the prices. It can be shown that this can be converted from this price space to returns space, as $mom=\sum_{i=0}^{n} w_i.r_i$. Here $r_i=P_i - P_{i-1}$ (returns assuming log prices) and $n=n_2$ from above.

Similar treatment can be applied to other common indicators to convert them as a function of returns $r_i$s. A few example 3 below:
• Momentum cross-over = $\sum_{i=0}^{n} w_i.r_i$
• MACD Histogram = MACD line - signal line = $\sum_{i=0}^{n1} w_i^1.r_i$ - $\sum_{i=0}^{n2} w_i^2.r_i$ $\Rightarrow$ $\sum_{i=0}^{n} w_i.\Delta{r_i}$, Here $\Delta{r_i}=r_i - r_{i-1}$. This follows from logic similar to the momentum crossover above, and noting the difference of sum is in returns terms instead of prices.
• CCI = (Price - Average Price)/(0.15 x Mean Deviation) = $\frac{1}{\sigma}\sum (P_i - \bar P)$ $\Rightarrow$ $\frac{1}{n.\sigma}\sum (r^{n}+r^{n-1}+..+r)$ $\Rightarrow$ $\sum w_i.r_i$, where $r^k = r_i - r_{i-k}$
• Know Sure Thing = (RCMA1 x 0.1) + (RCMA2 x 0.2) + (RCMA3 x 0.3) + (RCMA4 x 0.4) = $a1.\sum w_1.r^{n_1} + a2.\sum w_2.r^{n_2} + a3.\sum w_3.r^{n_3} + a4.\sum w_3.r^{n_3}$ $\Rightarrow$ $\sum w_i.r_i$

Similarly most others can be expressed as a function of returns, although not all of them as linear (or even polynomial) as above. Broadly, we can divide all common technical indicators that can be expressed as function of returns in three different classes 4
• Indicators that are linear (or polynomial) combination of past returns in returns space ($f(r)$). Examples - the ones above. Under certain condition (stationarity) they can be modeled as Gaussian distribution
• Indicators that are functions of sign of the returns in signed returns space ($f(r^+, r^-)$). Examples - like RSI or Chande Momentum Oscillator. They can be analyzed using folded normal distribution
• Indicators that are function of returns in time space ($f(t(r))$). An examples is the Aroon indicator

One objective of analyzing commonality of technical indicators can be to choose the one that is best suited to a particular purpose (depending on the time series characteristics of the underlying and the trading strategy). Another, and perhaps more common, can be dimensionality reduction as part of inputs to advanced machine learning based trading systems.

Following figure shows the outcome of principal component analysis of different technical indicators run on different equity indices5 - showing the first two principal components. Interestingly, for most cases (both in real market data and simulations6) the first two components will explain close to 85% or more variance in the indicators. As we can see all indicators load similarly on the first component. This is the underlying momentum component. This component typically explain around 70% variance, and will probably be the choice of inputs in a support vector machine or neural network system incorporating technical indicators.

The second component is where the indicators differ a lot. This component captures the signature of the filtering carried out by the indicator. This signature has two parts, one is the intrinsic method of the filter computation. For example from the above formulate, we see MACD is a function of difference of returns and hence will tend to behave more like over-differenced series (assuming the returns are stationary). In contrast, KST will have a large component which is simply sum of returns, and hence will behave more like a non-stationary series in the limit. Indeed, for common parameters for these indicators (representing a look back of 20 days), the time series characteristics of these signals can be captured in the following (inverse) unit root circle plot (here roughly speaking, closer the plotted points, i.e. roots, towards the center of the circle, more mean-reverting is the series)

We can see from the PCA plot there are four major groups of indicators based on their time series characteristics - MACD, which is very much mean-reverting (i.e. suitable for short term trends), KST (which is quite the opposite) and then we have two groups - one consisting the first type of indicators noted above (function of returns) and the other group consists of the second and third types (function of signed returns and returns in time space). This is validated in the unit root plot as well, we see MACD has roots much closer to the center, KST almost on the circle perimeter, RSI quite close to it, and Bollinger bands closer to the center relatively.

Another way to appreciate how different indicators impact the momentum signal differently, is to look at how they filter the components of the underlying (returns in this case) at different frequencies - as seen in the AR spectral analysis chart below. Click on the indicators on the right hand side legend to turn them off or on.

A spectrum that has higher values towards zero frequency (like KST) means they will tend to filter out higher frequency in the data,whereas the ones that has a peak away from zero, or drop off slowly from peak at zero will tend to pick up faster components (in the extreme resembling high negative correlation of a over-differenced signal). Of course as we increase look back period, an indicator will tend to move away from the second kind and towards the first kind.

Using this insight, one can design an appropriate set of indicators to extract an "average" momentum signal, to be used in other strategy or as inputs to a neural networks or similar system.

For this purpose, the first PCA component is the one we seek to use as input as momentum signal, straight and simple. The usefulness of the second component is that it allows us to fine-tune the momentum signal for our purpose. A momentum signal depends on our time frame - a short period momentum can look like mean-reversion in longer time frame. To extract a consistent signal we need to tune the choice of the indicators and parameters. If we are looking to extract momentum signals averaged over different filtering methods, but not over time, we need to ensure all factor loadings on the second component are within acceptable limits. Whereas if we want to span as much frequency spectrum as possible we want the loadings to span much larger space. Depending on out choice we extract the kind of signal we want from the first component7.

Note, while I mention the first component as momentum signal, it is NOT same as what is known as the time series momentum factor. However, it can easily computed by back-testing trading PnL based on this momentum signal. As we have seen in general these signals can be expressed as $\sum w.r$, the PnL will be (using a linear sizing function) $\sum (w_i.r_i).r_j$, or (using a sign function) $sign(\sum (w_i.r_i)).r_j$. Of course we can approximate the signum function, and then in general, the PnL becomes a polynomial of auto-covariances of the underlying returns.

1. This is a useful place with good introductory materials on different indicators
2. In general an indicators will tend to become non-stationary at a given periodic frequency (e.g. daily) as we increase the look-back parameter
3. There is no guarantee the sum of weights adds up to one. Please feel free to notify me in comments if you spot any error.
4. Here we ignore the indicators that take volume as an input as well
5. All data from Yahoo Finance
6. Based on simulations assuming expected market behaviours, i.e. AR or ARMA type return characteristics.
7. One can design an algorithm for this purpose, that will maximize the explained variance by the first component of the PCA, by optimizing over the parameter space of the indicators within a pre-defined set.