Filter

With our FILTER function, you can duplicate any linear smoother imaginable.  The possibilities are infinite. (Or to be ridiculously precise:  any linear filter with a rational transfer function.)

Syntax: 'm1 m2 m3' filter [dataset]  

in which m1, m2 and m3 are smoothing coefficients.  Note that the smoothing coefficients are listed chronologically, from oldest to current.  That is, m3 is the smoothing coefficient applied to the latest data (e.g. today), with m2 being applied to the previous day, and m1 being applied to two days prior to today.

This function can be used to compute moving averages and weighted moving averages.   For instance, ‘.25 .25 .25 .25’ filter close qqqq will produce a dataset in which each of the last 4 days are weighted equally and then added together.  That request is identical to that produced by either 4 movave cl qqqq or 1 1 1 1 wtave cl qqqq. Likewise the request ‘-1 -1 -1 -1 -1 0 0 1 2 2’ filter cl djia will produce an oscillator that mimics the MACD indicator used by many traders. 

** N.B. The text of all commands is located at the end of this document.  That way you can simply copy them over to your own command set, should you wish to duplicate or modify the research.

Alternate syntax:  'm1 m2 m3; a1 a2 a3; i1 i2 i3' filter [dataset]  

in which a1, a2, and a3 are autoregressive coefficients, and i1, i2 and i3 are the autoregressive initial conditions.  That is:

 [moving average coefficients] ; [autoregressive coefficients] ; [initial values] ’  filter [dataset]

Note that the quotes and semicolons are required. 

The process of exponential smoothing requires that one take say 20% of the current price, and add that to 80% of the cumulative value calculated for the previous day.  For example:  ‘.2; .8’ filter close spx last 200  (equivalent to requesting .2 expave cl spx last 200 or 9 expave cl spx last 200) will result in a smoothing taking 20 percent of the current price of the close of the SPX, and adding it to 80 percent of the value calculated for the previous day. 

That’s fine, but what do you use for the previous day’s value when there is no previous day, such as when you are first starting out?  FDC solves that problem for you by using the first possible value of the dataset as the initial value.  But that potentially creates an adjustment problem if you have (by virtue of your smoothing) created values not close in scale to the original dataset.  That’s why we give you the opportunity to specify an initial value.  If you do not specify an initial value, FDC will use the default value.

In the example immediately above there is no change in scale, so FDC’s supplying of the initial value is perfect.  However, should you enter ‘.2; .6’ filter close spx last 200, the scale will be different from that of the price series, and you should supply an initial value.  '.2; .6; 600' filter close spx last 200 would be a good choice, but that’s up to you. 

A second example:  '.3 .2; .4 .1' filter close spx last 200 does the following:

It takes .2 of the current price added to .3 of yesterday’s price and then added to .1 of yesterday’s indicator and .4 of the prior day’s indicator.  That is, this is a 2-stage version of an exponential moving average.  The chart below shows that value when overlaid onto the SPX bar chart.  You may have as many versions of this as you wish.

A third example:  Should you specify '; 1 1 ; 1 1' filter date spx last 100, you will get an interesting response.  First, there are no moving average coefficients, so nothing actually gets done to the dataset [date spx last 100], such that the choice of the dataset is irrelevant.  But here’s what does happen:  For the initial values of 1 and 1, it continues to add the latest number to the previously determined value.  Here’s what the results look like:

   

The screenshot on the left is the beginning of the series, which many will recognize, and the one on the right is the end of the series (100 days later).  If you were then to request

, a 1-day rate of change of the series, you would get the following:

That is, when you create this series, and take the rate of change of each value to the previous value, the ratio converges to 0.618…., otherwise known as “phi” or the Golden Ratio.  We do not suggest that has any value, but use the process to illustrate functionality. 

You can see by the previous example that if the coefficients of the moving averages and auto-regressive factors add up to greater than 1, (in that case they add up to 2), you are going to get eventual values significantly larger than that of the dataset.  Likewise, if those coefficients add up to less than 1, the eventual values will be smaller than the dataset.  When they add up to 1, you will get values that approximate the dataset.  So if you use the filter function to smooth data, have your coefficients add up to 1.

Fourth example:  By mixing coefficients that produce smoothers together with coefficients that produce oscillators, you will get a chimera with characteristics of both.  If this were a biology experiment it might be boycotted by various groups, but here we are okay.  Try:  '.1 .1 .1 .1 .1 .2 .3; -.1 -.1 -.1 -.1 -.1 0 0 .1 .2 .2' filter cl spx last 100

This produces the following when graphed with the SPX dataset:

-------------------------------

'm1 m2 m3' filter [ds]  

‘.25 .25 .25 .25’ filter close qqqq

4 movave cl qqqq

1 1 1 1 wtave cl qqqq

‘-1 -1 -1 -1 -1 0 0 1 2 2’ filter cl djia

‘.2; .8’ filter close spx last 200

.2 expave cl spx last 200

9 expave cl spx last 200)

‘.2; .6’ filter close spx last 200

'.2; .6; 600' filter close spx last 200

'.3 .2; .4 .1' filter close spx last 200

reset

'; 1 1 ; 1 1' filter date spx last 100

1 roc temp1

'.1 .1 .1 .1 .1 .2 .3; -.1 -.1 -.1 -.1 -.1 0 0 .1 .2 .2' filter cl spx last 100

------------------------------------------------------------------------------