Wednesday, December 03, 2008

Oscillator Time Scales

Most technical analysis indicators are some form of oscillator. An oscillator can be roughly defined as a numerical indicator that goes up and down in a somewhat fixed range. Non-oscillating indicators (like moving averages) are harder to use because they don't have many repeated values. But most non-oscillating indicators can be turned into oscillators by comparing relative values (for example, the ratio of two moving averages is an oscillator). So for the most part, numerical technical analysis is the art of finding oscillators with predictive value. Charting is an entirely separate practice.

For the most part, oscillators are either positively or negatively correlated with price: if the price goes up, the oscillator goes up/down, and if prices go down, the oscillator goes down/up. There are a few exceptions (mostly breadth-based indicators), but the vast majority of indicators follow this pattern. Inversion of an oscillator allows every oscillator to be turned into a positively correlated oscillator. So a simple analysis of postively correlated oscillators will cover most things that can be practically achieved with TA. Also, you can use just about any oscillator you want to, since they all tell you the same thing.

The main thing that will change from one oscillator to another is how the indicator accounts for past price changes. A fast indicator will mostly just use the last few bars of prices, while a slow indicator will use a larger number of bars. Different indicators will have varying weightings over the period they look at, so some indicators will do a better job of picking up net price movements in a choppy market than others will. But the speed ends up being the most important factor.

There are also two ways to trade the market: momentum and mean-reversion. Momentum trading is when you buy when prices have risen and sell when prices have fallen. Mean-reversion trading is when you sell when prices have risen and buy when prices have fallen. Both styles are profitable most of the time at some time scale. The key trick to trading profitably is to determine what time scale works best for mean-reversion and what time scale works best for momentum.

As an example, consider the RSI_ema indicator. The Matlab code for this indicator is
function [x] = rsi(price, period)

u(2:length(price))=max(0,diff(price));
d(2:length(price))=max(0,-diff(price));
us=ema(u,period);
ds=ema(d,period);
x=us./(us+ds);
x(1)=.5;

The u variable is the up movement in the price each day (0 if the price dropped). The d is the down movement (0 if price went up). us and ds are the ema's of the variables. Then you compute the fraction of the total price movement that is up movement. The standard RSI indicator uses sma's instead of ema's. Most people also multiply the value by 100 to get a range of 0-100 instead of 0-1.

The RSI_ema indicator is a simple, positively correlated oscillator. To trade in momentum mode, you buy when the indicator crosses above some threshold (somewhere between .7 and .95 normally) and sell when the indicator crosses below some other threshold (somewhere between .05 and .3 normally). you can stay in until the reverse signal is generated, or you can set a threshold closer to .5 for closing your trades. So you might go long when the indicator crosses above .9 and then close your position when it drops below .5 and go short when it crosses below .1 and then cover when it crosses above .5, or whatever values you have chosen. You can even use asymmetric values if you want to go long or short more easily. To trade in mean reversion mode, you take the opposite trades.

The test I am performing determines how RSI_ema responds to different oscillation rates in the market. For this test, I am using a sine wave plus a constant to generate the price signal. The market never moves in perfect patterns like sine waves, but this will demonstrate how indicator performance will vary based on market conditions.

The first test is to see how different values for the RSI_ema period perform at different market frequencies. I ran a sine wave with a period from 10 to 200 bars through the momentum trading strategy. For each RSI_ema period, the sell threshold was set to .1 plus the 20th percentile value of the indicator (to adjust the level somewhat based on what range the indicator actually moved in). The buy threshold was set to one minus the sell thrshold. The system is always in once it makes its first trade.

Here is the result of a very choppy market (sine wave period=10):


As you can see, the choppy market is moving too fast for most values of the RSI_ema indicator to even try trading it. The ones that do manage to trade it lose money. They would make money if they had been traded in mean reversion instead.

Slowing down the choppiness a bit:

The faster settings of RSI_ema start making money. The crossover seems to be around 1/3 of the sine wave period.

And slowing it down even more:

Here, the crossover can be seen better. Again, trying to trade a slow moving market with a fast momentum indicator works well. Trying to trade a slow market with a slow momentum indicator does not work. The slower settings should be used for mean reversion.

Now for one more graph. This one shows how the profitability changes with a fixed RSI_ema period of 4 as the sine wave period is varied:

Once again, for very fast markets, the indicator does not provide any signals. As the market slows down a little bit, the indicator makes money when used in mean-reversion mode (remember that mean-reversion trades opposite to momentum, so a momentum loss is a mean-reversion profit). As the market slows down even more, the indicator makes money in momentum mode. The odd spikes occur when the sine wave period is a multiple of the RSI_ema period and should be ignored.

Of course, no security is ever going to trade with a perfect sine wave (and if it does, you don't need an indicator to trade it). But, knowing how oscillators vary based on the market speed is useful for building an adaptive trading system. There is no single setting for any indicator that will always work. Sometimes the market is very choppy and you want a fast mean-reversion system to maximize your profits. Sometimes the market is moving in long trends and you want a momentum strategy. Looking at the recent performance of trading strategies based on a range of indicator speed settings will provide some guidance as to how fast the market has been changing directions recently. If you assume that this fundamental period will change slowly, then you can measure the recent value and use that to choose optimal indicator settings.

For example, RSI_ema crosses over from making money to losing money when the setting is about 1/3 of the sine wave period. If you plot the profitability of RSI_ema strategies over the revent past, you should see a graph moderately similar to the ones above. That will show you roughly where the crossover point is from mean-reversion to momentum. You can use this information to determine whether you should be trying to catch trends or watching for reversals. You could also do this with any other oscillator.

Note that in real markets, you won't get a nice clean drop-off like you do when trading a sine wave. Real markets have a balance between mean-reversion and momentum going on at all sorts of time scales. A graph of the profitability based on the time setting of the indicator is likely to cross zero several times as you pick up on various trends and reversals at different time scales. The trick is finding regions that are relatively stable on one side or the other (momentum or mean reversion).

This can also be used to determine the underlying characteristics of the market. The time scale-profit graph is one of the signatures of who is trading and how. Interpreting it correctly can provide an edge in trading.

Labels: ,