Digital signal processing (DSP), specifically the use of digital filters, is embedded in many indicators used by technical analysts to study and make trading decisions using time series of stock, bond, currency, commodity, and other financial asset prices. This analysis takes a look at several of the most commonly-used indicators from a DSP perspective to illustrate their properties and limitations.

1. Financial Asset Prices and Time Series

Financial assets, such as stocks, bonds, currencies, and commodities, are priced as the result of trades made between buyers and sellers on exchanges, electronic trading systems, over the phone, etc. Prices are established and quoted when the buyer and seller agree on the value of the asset and execute a trade. Prices fluctuate in response to changes in supply and demand for the asset, market conditions, economic conditions, and other factors.

Trades are discrete events that can occur at different rates of time, depending on the type of asset, the type of market, etc. While trade-by-trade prices are available for many types of assets, primarily to institutional investors, technical analysts typically study price histories that are structured as data that is sampled at a uniform time interval, e.g., hourly, daily, weekly, or monthly. Data in this form are called discrete-time time series.

Characteristics of Financial Time Series

Financial time series by their nature are challenging to analyze because, in general, they display:

  • volatility – financial time series tend to be “noisy”, i.e., with many rapid short-term fluctuations and jumps, making identifying the underlying trends and cycles difficult in real-time
  • non-normality – the mean and standard deviation of financial time series returns (i.e., the change in price over a specified period of time) do not conform to a normal probability distribution, e.g., observed return distributions are peaked with negative skewedness (skewness < 0) and “fat tails” (kurtosis > 3)
  • non-stationarity – financial time series return probability distributions are not invariant under time shift, i.e., their means and variances change over time and cycles and trends do not persist.
Histogram of S&P 500 monthly returns from 1950 to the present overlaid with a normal distribution (red line) and boundaries for two standard deviations (vertical blue lines). The returns do not fall into a normal distribution, are negatively skewed (more negative observations), and are fat-tailed (more observations outside the red line at the ends of the graph). There are more observations below negative two standard deviations and fewer observations above positive two standard deviations. Source: OSM (https://osm.netlify.app/post/mean-expectations/)

The results are hypothetical results and are NOT an indicator of future results and do NOT represent returns that any investor actually attained. Indexes are unmanaged, do not reflect management or trading fees, and one cannot invest directly in an index.

2.    Digital Filtering in Technical Analysis

Digital filtering is widely used in electrical engineering, telecommunications, and other fields to process digital signals, e.g., to alter the features of the input signal in a particular way, which appears in the filter output.

Since financial time series data are digital by nature, various digital filtering techniques, such as moving averages and time series momentum (TSMOM), are used by technical analysts to transform and analyze them, e.g., to attenuate noise and identify trading opportunities presented by trends and cycles.

This section presents some basic concepts to aid in understanding how digital filters are designed and operate. Since, in the electrical engineering world, digital filters are categorized and viewed in terms of their effect on the frequencies of the signal passing through them, the concepts of time domain and frequency domain are described.

The terms “filtering” and “smoothing” are often used interchangeably but are actually somewhat different. Assuming observations of the input are contaminated with noise:

  • filtering – uses past and current observations to estimate the current state (i.e., casual)
  • smoothing – uses past and current observations to estimate previous states (i.e., non-causal)
  • prediction – uses past and current observations to forecast future states

Frequency Measurement

For discrete-time signals containing cycles (i.e., sinusoidal-like patterns or waves), several different measurement conventions can be used:

  • Frequency – the number of cycles completed per time sample
    Two common frequency measurements are:
    • f = the number of cycles per time sample (normalized frequency)
    • w = the number of radians per time sample where 2*(pi) radians = 360o = 1 cycle (normalized angular frequency)
      Relationships:
  • Period – the number of time samples to complete one cycle.
    • P = The number of time samples to complete one cycle (normalized period)
      Relationships:

Measuring cycles using period, where the sampling rate can be hourly, daily, weekly, monthly, etc., is commonly used by and most familiar to technical analysts.

Time Domain and Frequency Domain

Financial time series that are structured as data sampled at a uniform time interval are referred to as being in the “time domain”. A graph in the time domain, such as a price chart, displays the time series value at each time sample. Technical analysts generally study data in the time domain, and the output of most technical analysis indicators is also calculated and displayed in the time domain.

The Fourier theorem states that a general function, however complicated, may be expressed as the sum of a potentially infinite number of sinusoidal functions, each of which has a specific amplitude (a measure of maximum displacement from equilibrium) and phase (a measure of angular offset). While Fourier analysis was originally developed for continuous-time functions (e.g., analog signals), it is also applicable in a modified form to discrete-time functions (e.g., digital signals). Data represented in this way is referred to as being in the “frequency domain”.

Discrete-time time series can be converted from the time domain to the frequency domain using the Discrete Fourier Transform (DFT). The output of the Discrete Fourier Transform is the “frequency spectrum” of the time series, which is the amplitude and phase of each frequency component of the time series. Time series can be converted from the frequency domain to the time domain using the related Inverse Discrete Fourier Transform (IDFT).

Example: a 10 time-sample period discrete-time sine wave represented in the time domain and in the frequency domain

Types of Filters

There are four basic types of filters:

  • low pass – passes low frequencies and attenuates high frequencies
  • high pass – passes high frequencies and attenuates low frequencies
  • bandpass – passes frequencies within a low and high cutoff frequency band and attenuates the others
  • bandstop – attenuates frequencies within a low and high cutoff frequency band and passes the others

Since noise is associated with high frequencies (short periods), low pass filters are used in many technical analysis indicators. Bandpass filters are used to identify cycles in a particular frequency range.

Some other types of filters used with financial time series are:

  • differentiator – the filter output is proportional to the rate of change (i.e., time derivative) of the input
  • target tracking – used to calculate the position, velocity, and acceleration of a moving target; includes alpha-beta, alpha-beta-gamma, and Kalman filters

Cutoff Frequency

One technique used to understand and/or control the behavior of a filter is by knowing and/or setting the filter cutoff frequency. The cutoff frequency is the frequency at which the power of the filter output is reduced by a certain amount, relative to the power of the input.

A commonly-used cutoff frequency is one where the output power is one-half the input power:

  • input power = input amplitude2 (i.e., input amplitude squared)
  • output power = output amplitude2 (i.e., output amplitude squared)
  • output power at one-half the input power:
    • output power = ½*input power
    • output amplitude = √½*input amplitude
    • output magnitude = (output amplitude / input amplitude) = √½ = 0.7071
  • conversion to decibels (dB): 20*log(0.7071) = -3.0104 dB

Cutoff frequency is commonly denoted as wc or fc. Cutoff period is denoted as Pc.

generic low pass filter frequency response with -3 dB cutoff frequency c

FIR and IIR Digital Filters

Digital filters can be implemented in two ways:

  • finite impulse response (FIR) – The filter does not use feedback. The filter difference equation (also called the input-output equation) is non-recursive, i.e., it uses only current and past input values.
    • general FIR difference equation: yt = b0*xn + b1*xn-1 + b2*xn-2 + …
note: the z-1 blocks represent a unit (i.e., one time sample) delay and the triangular blocks indicate multiplication
  • infinite impulse response (IIR) – The filter uses feedback. The filter difference equation is recursive, i.e., it uses current and past input values as well as past output values.
    • general IIR difference equation: yt = b0*xn + b1*xn-1 + b2*xn-2 + … + a1*yn-1 + a2*yn-2 + …

The behavior of a filter, specifically its frequency response, is determined by the type of filter and the ai and bi filter coefficient values.

Filter Frequency Response

Frequency response measures the magnitude and phase of the filter output in response to a sinusoidal input of a given frequency w.

There are two components of frequency response:

  • magnitude response |H(w)| – the ratio of the amplitude of the filter output to the amplitude of the filter input at a given frequency w
  • phase response f(w) – the angular shift (i.e., time delay) of the filter output relative to the filter input at a given frequency w, measured in radians or degrees

The response of a filter to a unit pulse input is called the “unit pulse response”. The unit pulse is denoted by d(t), the Kronecker delta function, where:

The filter unit pulse response is denoted by h(t) for integer time t = 0, 1, 2, …. The unit pulse response completely defines the filter, both its transient behavior and frequency response, since a unit pulse contains all frequencies.

In the time domain, a filter operates on the input by multiplying the filter unit pulse response with the values of the input at each corresponding point in time, a procedure called “convolution”. In the frequency domain, the frequency spectrum of the filter output is obtained by multiplying the frequency spectrum of the input by the frequency response of the filter.

3. Notes on the Indicator Example Graphs

This article graphically illustrates the unit pulse response (i.e., time domain) and the associated magnitude and phase spectrum (i.e., frequency domain) for several different types of indicators, using common examples.

The unit pulse response graphs show the unit pulse response h(t) on the integer time scale t = 0, 1, 2, …. The appendices show the h(t) equation for each indicator. The coefficients of a FIR filter correspond to the time-reversed order of h(t).

The magnitude and phase spectrum graphs display the frequency response over the range 0 <= f <= 0.5 cycles per time sample on the horizontal scale. The lower limit f = 0 can be thought of as a wave of infinite length or as a steady direct current (DC) level. The upper limit f = 0.5 is called the “Nyquist frequency”, which is the highest frequency of a signal that can be recorded per time sample for the signal to be accurately reconstructable in the time domain.

Graphs showing the frequency response in terms of the period on the horizontal scale are also included since the period is the measurement that is most commonly used by and familiar to technical analysts. The period graphs have a lower limit of 2 time samples, since the Nyquist frequency f = 0.5 corresponds to a period of P = 1/f = 2 time samples per cycle.

4. S&P 500 Time Domain and Frequency Domain for 2018-2019

Time Domain Representation

In this article, examples of the time domain output of the various indicators are shown using price charts of the daily S&P 500 stock index closing values for 2018 and 2019, which includes 503 trading days.

Below left is a chart of the daily S&P 500 index closing values and below right is a chart of the daily natural log (i.e., continuously compounded) index returns rt  = ln(xt/xt-1) where xt is the index value at integer time t corresponding to the date. The natural log returns are used to calculate the frequency spectrum.

The results are hypothetical results and are NOT an indicator of future results and do NOT represent returns that any investor actually attained. Indexes are unmanaged, do not reflect management or trading fees, and one cannot invest directly in an index.

Frequency Domain Representation

Below upper left is a graph of the frequency spectrum magnitude of the S&P 500 daily natural log returns and below upper right is a graph of the frequency spectrum phase in degrees (please see the note regarding “phase wrap” in the “Moving Average Filter Frequency Response” section).

Below the lower left is a graph of the period spectrum magnitude of the natural log-returns and below lower right is a graph of the period spectrum phase in degrees. The period spectrum magnitude graph shows a number of short-cycle periods of up to approximately 55 days and two longer cycle periods of 95 and 169 days.

The results are hypothetical results and are NOT an indicator of future results and do NOT represent returns that any investor actually attained. Indexes are unmanaged, do not reflect management or trading fees, and one cannot invest directly in an index.

5. Moving Average (MA)

The moving average (MA) filter difference equation is:

MAt(N) = (xt + xt-1 + … + xt-N-1) / N

              = (1/N)*xt + (1/N)*xt-1 + … + (1/N)*xt-N-1

where N is the number of input data points included in the average, i.e., the moving average length (N > 1), and xt represents the price at integer time t. Moving average filter coefficients have equal value 1/N. The filter coefficients sum to 1.0.

A moving average is a low pass FIR filter, i.e., it passes frequencies below the cutoff frequency and attenuates frequencies above the cutoff frequency. (See Appendix 1 for additional details.) The value of the moving average length N determines the frequency response of the filter. The cutoff frequency fc is inversely proportional to N (the cutoff period Pc is proportional to N).

MA can be calculated recursively in IIR form (requires proper initialization):

A commonly-used trading signal is generated when the current price crosses above (buy) or below (sell) the low pass moving average.

Moving Average Filter Frequency Response (N = 10)

Example: Moving average filter with length N = 10

MAt(10) = (xt + xt-1 + xt-2 + xt-3 + xt-4 + xt-5 + xt-6 + xt-7 + xt-8 + xt-9) / 10

               = 0.1*xt + 0.1*xt-1 + 0.1*xt-2 + 0.1*xt-3 + 0.1*xt-4 + 0.1*xt-5 + 0.1*xt-6 + 0.1*xt-7 + 0.1*xt-8 + 0.1*xt-9

Passes frequencies below the -3 dB cutoff frequency fc of approximately 0.044, which corresponds to a cutoff period Pc of approximately 22.5 time samples.

As can be seen in the frequency magnitude graph, a moving average filter of length N = 10 completely suppresses frequencies of 0.1, 0.2, 0.3, 0.4, and 0.5, which correspond to periods of 10, 5, 3.333, 2.5, and 2-time samples, respectively. Suppression occurs because, for example, the average value of a 10 time-sample period sine wave over 10-time samples is zero, the average value of two 5 time-sample period sine waves over 10-time samples is zero, etc.

Note: In the filter phase graphs in this article, phase values are constrained to the range of -180 degrees to +180 degrees. When the actual phase value is outside this range, the phase value is increased or decreased by a multiple of 360 degrees to put the phase value back within the -/+ 180-degree range. This is called “phase wrap” and results in the appearance of a zig-zag line, but each zig-zag line segment is actually a continuation of the previous line segment.

Moving Average Filter Frequency Response (N = 200)

Example: Moving average filter with N = 200, which is a popular moving average length used with daily data.

Passes frequencies below the -3 dB cutoff frequency fc of approximately 0.002, which corresponds to a cutoff period Pc of approximately 451.5 time samples.

6. Price Minus Moving Average (P – MA)

Subtracting a moving average, which is a low pass FIR filter, from the price results in a high pass FIR filter, i.e., frequencies above the cutoff frequency are passed and frequencies below the cutoff frequency are attenuated.

The high pass moving average (HPMA) filter difference equation is:

HPMAt(N) = xt – MAt(N)

The high pass moving average crosses above (below) zero at the same time as the current price crosses above (below) the low pass moving average.

Example: High pass moving average filter with length N = 10 (note: the filter coefficients sum to 0.0)

HPMAt(10) = xt – (xt + xt-1 + xt-2 + xt-3 + xt-4 + xt-5 + xt-6 + xt-7 + xt-8 + xt-9) / 10

                     = 0.9*xt – 0.1*xt-1 – 0.1*xt-2 – 0.1*xt-3 – 0.1*xt-4 – 0.1*xt-5 – 0.1*xt-6 – 0.1*xt-7 – 0.1*xt-8 – 0.1*xt-9

Passes frequencies above the -3 dB cutoff frequency fc of approximately 0.027, which corresponds to a cutoff period Pc of approximately 37.2 time samples.

Low Pass MA vs High Pass MA (N = 10)

7. Linear Weighted Moving Average (LWMA)

The linear weighted moving average (LWMA) filter difference equation is:

LWMAt(N) = [2/(N*(N + 1))] * [N*xt + (N – 1)*xt-1 + (N – 2)*xt-2 + … + xt-N+1]

where N is the number of input data points included in the average, i.e., the moving average length (N > 1). The filter coefficients are linearly weighted with the greatest weights placed on the most recent input values. The filter coefficients sum to 1.0.

A linear weighted moving average is a low pass FIR filter, i.e., it passes frequencies below the cutoff frequency and attenuates frequencies above the cutoff frequency. (See Appendix 2 for additional details.) The value of the linear weighted moving average length N determines the frequency response of the filter. The cutoff frequency fc is inversely proportional to N (the cutoff period Pc is proportional to N).

LWMA can be calculated recursively in IIR form (requires proper initialization):

A commonly-used trading signal is generated when the current price crosses above (buy) or below (sell) the low pass linear weighted moving average.

LWMA Filter Frequency Response (N = 10)

Example: Linear weighted moving average filter with length N = 10 (note: coefficients shown are rounded)

LWMAt(10) = 0.1818*xt + 0.1636*xt-1 + 0.1455xt-2 + 0.1273*xt-3 + 0.1091*xt-4 + 0.0909*xt-5 + 0.0727*xt-6 + 0.0545*xt-7 + 0.0364*xt-8 + 0.0182*xt-9

Passes frequencies below the -3 dB cutoff frequency fc of approximately 0.053, which corresponds to a cutoff period Pc of approximately 18.8 time samples.

8. Price Minus Linear Weighted Moving Average (P – LWMA)

Subtracting a linear weighted moving average from the price results in a high pass FIR filter, i.e., frequencies above the cutoff frequency are passed and frequencies below the cutoff frequency are attenuated.

The high pass linear weighted moving average (HPLWMA) filter difference equation is:

HPLWMAt(N) = xt – LWMAt(N)

The high pass linear weighted moving average crosses above (below) zero at the same time as the current price crosses above (below) the low pass linear weighted moving average.

Example: High pass linear weighted moving average filter with length N = 10 (note: coefficients shown are rounded)

HPLWMAt(10) = xt – (0.1818*xt + 0.1636*xt-1 + 0.1455xt-2 + 0.1273*xt-3 + 0.1091*xt-4 + 0.0909*xt-5 + 0.0727*xt-6 + 0.0545*xt-7 + 0.0364*xt-8 + 0.0182*xt-9)

= 0.8182*xt – 0.1636*xt-1 – 0.1455xt-2 – 0.1273*xt-3 – 0.1091*xt-4 – 0.0909*xt-5 – 0.0727*xt-6 – 0.0545*xt-7 – 0.0364*xt-8 – 0.0182*xt-9

Passes frequencies above the -3 dB cutoff frequency fc of approximately 0.043, which corresponds to a cutoff period Pc of approximately 23.3 time samples.

The results are hypothetical results and are NOT an indicator of future results and do NOT represent returns that any investor actually attained. Indexes are unmanaged, do not reflect management or trading fees, and one cannot invest directly in an index.

9. Exponential Smoothing (ES)

The exponential smoothing (ES) filter difference equation is:

ESt(a) = a*xt + (1 – a)*ESt-1(a)

where a is the smoothing constant (0 <= a <= 1). The filter smoothing constant a is applied to the current input value and (1 – a) is applied to the previous filter output value. The filter coefficients sum to 1.0.

Exponential smoothing is a low pass IIR filter, i.e., it passes frequencies below the cutoff frequency and attenuates frequencies above the cutoff frequency. (See Appendix 3 for additional details.) The value of the smoothing constant a determines the frequency response of the filter. The cutoff frequency fc is proportional to a (the cutoff period Pc is inversely proportional to a).

ES can be calculated non-recursively in FIR form:

A commonly-used trading signal is generated when the current price crosses above (buy) or below (sell) the low pass exponential smoothing.

Exponential Smoothing Filter Frequency Response (a = 0.2425)

Example: exponential smoothing filter with smoothing constant a = 0.2425

ESt(0.2425) =  0.2425*xt + 0.7575*ESt-1(0.2425)

Passes frequencies below the -3 dB cutoff frequency fc of approximately 0.044 (i.e., the same cutoff frequency as a moving average filter of length N = 10), which corresponds to a cutoff period Pc of approximately 22.5 time samples.

10. Price Minus Exponential Smoothing (P – ES)

Subtracting an exponential smoothing from the price results in a high pass IIR filter, i.e., frequencies above the cutoff frequency are passed and frequencies below the cutoff frequency are attenuated.

The high pass exponential smoothing (HPES) filter difference equation is:

HPESt(a) = xt – ESt(a) = (1 – a)*xt – (1 – a)*xt-1 + (1 – a)*HPESt-1(a)

The gain can be adjusted so that the maximum magnitude frequency response of the filter is 1.0 (0 dB), resulting in the difference equation:

HPESt(a) = (1 – a/2)*xt – (1 – a/2)*xt-1 + (1 – a)*HPESt-1(a)

The high pass exponential smoothing crosses above (below) zero at the same time as the current price crosses above (below) the low pass exponential smoothing.

Example: High pass exponential smoothing filter with a = 0.2425

HPESt(0.2425) = 0.87875*xt – 0.87875*xt-1 + 0.7575*HPESt-1(a)

Passes frequencies above the -3 dB cutoff frequency fc of approximately 0.044, which corresponds to a cutoff period Pc of approximately 22.5 time samples.

The results are hypothetical results and are NOT an indicator of future results and do NOT represent returns that any investor actually attained. Indexes are unmanaged, do not reflect management or trading fees, and one cannot invest directly in an index.

11. Properties of MA, LWMA and ES Filters

Underlying Process Model

Moving average, linear weighted moving average, and exponential smoothing filters are low pass filters, which are modeled on the assumption that the underlying process has a locally constant mean or position value (i.e., with no trend or cycle) which is contaminated with normally distributed random noise et where et ~ N(0, se2):

                                first order model – mean/position a:     xt = a + et 

Low pass filters are designed to estimate the mean value a by attenuating the random noise.

Low Pass Filter Lag

Since financial time series typically contain trends and cycles, the output of a low pass filter will lag the input since the filter is designed to estimate mean values, not model trends and cycles.

Lag can be calculated as the sum of the time-weighted unit pulse response coefficients of the filter:

Lag can also be defined as the weighted average age of the data included in the filter calculation.

The amount of lag is proportional to the length N of MA and LWMA filters and inversely proportional to the smoothing constant a of ES filters (see Appendices 1, 2, and 3 for the respective calculations for each filter):

  • lagMA = (NMA – 1) / 2
  • lagLWMA = (NLWMA – 1) / 3
  • lagES = (1 – aES) / aES

The lag of low pass filters can be used as a way to “sidestep” some of the noise and short-term fluctuations during a trend or cycle but at the cost of delayed response once the trend or cycle begins or ends.

Low Pass Filters with Equivalent Lag

Lag can be used as a means to calculate equivalent low pass filter N and a values, i.e., the N and a values that produce the same lag for each type of filter. This method is the one most commonly used in the technical analysis literature. It equates filters at their corresponding -6 dB (quarter power) cutoff frequency.

For example, for a moving average filter with length NMA, the equivalent LWMA N and ES a are:

NLWMA = [(3*NMA – 1)/2] where […] denotes the integer function

aES = 2/(NMA + 1)

Low Pass Filter Noise Reduction vs Lag

For time series containing random noise, the noise variance reduction ratio (VRR) of a filter is calculated by summing the squares of the unit pulse response coefficients of the filter (see Appendices 1, 2, and 3 for the respective calculation for each filter). The smaller the ratio, the greater the noise reduction.

The graphs below illustrate the tradeoff between the noise variance reduction ratio and lag for MA, LWMA, and ES filters.

In general, the larger the length N or the smaller the smoothing constant a used in a filter, the smaller the noise variance reduction ratio but the greater the lag.

12. Time Series Momentum (TSMOM)

The time series momentum (TSMOM) filter difference equation is:

TSMOMt(L) = G*xt – G*xt-L

where L is the integer time sample lookback (L > 0) and G is the filter gain adjustment (G > 0). TSMOM calculates the difference between two data points that are separated by the lookback, which is a fixed number of integer time samples. The filter coefficients sum to 0.0.

TSMOM is a simple FIR differentiator, often called a “comb” filter for reasons that can be seen in the filter frequency magnitude graph. (See Appendix 4 for additional details.) When used with monthly financial time series, for example, the lookback is typically set to 10 or 12 months. The filter gain adjustment G is often just set to 1.0 but should be set to 0.5 so that the maximum magnitude frequency response of the filter is 1.0 (0 dB).

A commonly-used trading signal is generated when TSMOM changes sign, i.e., crosses above (buy) or below (sell) zero.

TSMOM Filter Frequency Response (L = 10)

Example: TSMOM filter with lookback L = 10

TSMOMt(10) = 0.5*xt – 0.5*xt-10

Completely passes frequencies of 0.05, 0.15, 0.25, 0.35, and 0.45, which correspond to periods of 20, 6.667, 4, 2.857, and 2.222 time samples, respectively. Completely suppresses frequencies of 0.1, 0.2, 0.3, 0.4, and 0.5, which correspond to periods of 10, 5, 3.333, 2.5, and 2 time samples, respectively, and are the same as a moving average filter of length N = 10, except that TSMOM also suppresses f = 0.0, which is characteristic of a differentiator.

The results are hypothetical results and are NOT an indicator of future results and do NOT represent returns that any investor actually attained. Indexes are unmanaged, do not reflect management or trading fees, and one cannot invest directly in an index.

Mathematical Relationship Between MA and TSMOM

MA and TSMOM filters have different behaviors but are mathematically related. If the TSMOM lookback L is set equal to the moving average filter length N so that L = N:

Comments on TSMOM

TSMOM is the simplest FIR differentiator, using only two input time samples. TSMOM changes sign when the comparable MA passes an inflection point, i.e., the MA changes direction. Price can potentially cross the MA before the MA itself changes direction, so price crossing can sometimes give earlier trading signals than TSMOM but, as a consequence, also generate more “whipsaw” trades that produce losses.

13.    Averaged TSMOM Filters (ATSMOM)

Some TSMOM-based systems use an average of several TSMOM filters with different lookbacks. This type of filter can be analyzed by averaging the coefficients of each filter. The gain adjustment G can be used to normalize the resulting averaged TSMOM (ATSMOM) filter coefficients so that the maximum magnitude frequency response of the filter is 1.0 (0 dB).

Example: average of four TSMOM filters with 3, 6, 9, and 12 time sample lookbacks

L = 3:                                      TSMOMt(3) = xt – xt-3

L = 6:                                      TSMOMt(6) = xt – xt-6

L = 9:                                      TSMOMt(9) = xt – xt-9

L = 12:                                   TSMOMt(12) = xt – xt-12

gain-adjusted average:  ATSMOMt(3, 6, 9, 12) = G*(4*xt – xt-3 – xt-6 – xt-9 – xt-12)/4

                                                                                            = G*(xt – 0.25*xt-3 – 0.25*xt-6 – 0.25*xt-9 – 0.25*xt-12)

ATSMOM Filter Frequency Response (L = 3, 6, 9 & 12)

Example: ATSMOM filter with lookbacks L = 3, 6, 9 and 12. The gain adjustment is set to G = 0.7043 so that the maximum magnitude frequency response of the filter is 1.0 (0 dB).

ATSMOMt(3, 6, 9, 12) = 0.7043*(xt – 0.25*xt-3 – 0.25*xt-6 – 0.25*xt-9 – 0.25*xt-12)

                                          = 0.7043*xt – 0.176075*xt-3 – 0.176075*xt-6 – 0.176075*xt-9 – 0.176075*xt-12

Completely passes frequencies of approximately 0.05, 0.29, and 0.385, which correspond to periods of approximately 20, 3.45, and 2.6 time samples, respectively.

The results are hypothetical results and are NOT an indicator of future results and do NOT represent returns that any investor actually attained. Indexes are unmanaged, do not reflect management or trading fees, and one cannot invest directly in an index.

Comments on ATSMOM

Various technical analysts use different lookback combinations, such as 3 and 6; 1, 3, 6 and 12; 1, 3, 6, 9 and 12; 3, 6, 9 and 12; and even 1 through 12. The smaller lookbacks are included to capture shorter-term movements, whereas the larger lookbacks are included to capture long-term momentum.

The frequency response of an ATSMOM filter can vary widely, depending on the number and corresponding lookbacks of the individual filters included. However, the ones listed above produce similar-looking outputs since they include similar lookbacks.

The results are hypothetical results and are NOT an indicator of future results and do NOT represent returns that any investor actually attained. Indexes are unmanaged, do not reflect management or trading fees, and one cannot invest directly in an index.

14. Moving Average Crossover (MAC)

Moving average crossover (MAC) uses the difference between two moving averages. One moving average has a short length Ns and the other a longer length Nl:

MACt(Ns, Nl) = MAt(Ns) – MAt(Nl) where 1 < Ns < Nl

Moving average crossover is a type of bandpass FIR filter, passing frequencies between low (fL) and high (fH) cutoff frequencies, called the bandwidth (Df = fH – fL). The filter has a center (also called “resonant”) frequency (f0) located between the two cutoffs, which the filter passes at maximum power. The bandwidth and center frequency are determined by the two moving average lengths Ns and Nl. The filter coefficients sum to 0.0.

MAC illustrates that a bandpass filter can be implemented by subtracting a low pass filter with a lower cutoff frequency from a low pass filter with a higher cutoff frequency. (Note that, as was shown earlier, subtracting a low pass filter from a signal results in a high pass filter.)

MAC can be calculated recursively in IIR form (requires proper initialization):

A commonly-used trading signal is generated when the short moving average MAt(Ns) crosses above (buy) or below (sell) the long moving average MAt(Nl).

MAC Frequency Response (Ns = 50 & Nl = 200)

A popular moving average crossover uses short MA length Ns = 50 days and long MA length Nl = 200 days. The “Golden Cross”, used to identify a bull market, occurs when the 50-day MA moves above the 200-day MA. The “Death Cross”, used to identify a bear market, occurs when the 50-day MA moves below the 200-day MA.

Example: Moving average crossover filter where Ns = 50 and Nl = 200:

MACt(50, 200) = MAt(50) – MAt(200)

The -3 dB short cutoff period Pcs is approximately 166 time samples, the -3 dB long cutoff period Pcl is approximately 604 time samples, and the center (resonant) period P0 is approximately 279 time samples.

The results are hypothetical results and are NOT an indicator of future results and do NOT represent returns that any investor actually attained. Indexes are unmanaged, do not reflect management or trading fees, and one cannot invest directly in an index.

15. Moving Average Convergence-Divergence (MACD)

The term “moving average convergence-divergence” is a bit of a misnomer, since it is actually calculated using the difference between two exponential smoothing filters, not moving averages. As a result of this convention, MACD parameters are usually specified using moving average lengths. The result is one exponential smoothing using a large smoothing constant al (i.e., based on the short MA length Ns) and the other using a smaller smoothing constant as (i.e., based on the long MA length Nl):

MACDt(Ns, Nl) = ESt(al) – ESt(as)   where 1 < Ns < Nl and, consequently, 0 <= as < al <= 1

MACD is a type of bandpass IIR filter, passing frequencies between low (fL) and high (fH) cutoff frequencies, called the bandwidth (Df = fH – fL). The filter has a center (also called “resonant”) frequency (f0), which the filter passes at maximum power. The bandwidth and center frequency are determined by the two smoothing constants al and as.

MACD can also be calculated in the form (requires proper initialization):

MACD can be interpreted in several ways. One type of MACD trading signal is generated when ESt(al) crosses above (buy) or below (sell) ESt(as). Another type of MACD trading signal uses the difference between the two exponential smoothing filters (called the “MACD line”) and additionally smoothing the result using another exponential smoothing filter to generate a “signal line”. The trading signal is generated when the MACD line crosses above (buy) or below (sell) the signal line.

MACD Frequency Response (al = 0.2067 & as = 0.1015)

A popular MACD configuration is to set al equivalent to a moving average length of 12 days and as equivalent to a moving average length of 26 days.

Example: Moving average convergence-divergence filter where MA Ns = 12 and MA Nl = 26

Note: The formula a = 2/(N + 1) is usually used to convert a MA length N to the equivalent ES smoothing constant a. This formula actually equates the two at their corresponding -6 dB (quarter power) cutoff frequencies. To maintain consistency with the other examples, smoothing constants that specify the -3 dB cutoff frequency are used here instead: Ns = 12 —-> al = 0.2067 and Nl = 26 —-> as = 0.1015.

Setting the gain adjustment G = 0.2863 so that the maximum frequency magnitude response of the filter is 1.0 (0 dB) at the center frequency of approximately 40-time samples, the -3 dB short cutoff period Pcs is approximately 15-time samples and the -3 dB long cutoff period Pcl is approximately 101-time samples.

The results are hypothetical results and are NOT an indicator of future results and do NOT represent returns that any investor actually attained. Indexes are unmanaged, do not reflect management or trading fees, and one cannot invest directly in an index.

Comments on MACD

Since MACD is a bandpass filter, it is “tuned” to a specific center (resonant) frequency or period, based on the filter coefficients, and has an associated phase response. As a result, if the input time series cycle period is less than the center period of the filter, the filter output will peak (trough) after the input time series cycle peak (trough). (See the graph below left where MACD(0.2067, 0.1015) with center period 40 is plotted against a 15-period sine wave, which is the lower -3 dB cutoff period.) Conversely, if the input time series cycle period is greater than the center period, the filter output will peak (trough) before the input time series peak (trough). (See the graph below right where MACD(0.2067, 0.1015) is plotted against a 101-period sine wave, which is the upper -3 dB cutoff period.)

A mismatch between the phases of the filter input and output due to the phase response of the filter produces what technical analysts call “divergence”, where the direction of the price “diverges” from the direction of the MACD line. Divergence is often interpreted as a predictive signal but is actually just an artifact of the filter phase response.

16. General Comments on Using Digital Filters

Pros and cons of FIR versus IIR filters:

  • FIR filters generally have a more linear phase response, but the filter calculation can be more complex, e.g., due to requiring memory of the previous input values.
  • IIR filters have non-linear phase response, which can cause output distortion, but the filter calculation is usually simpler, e.g., not requiring as much memory of the previous input values.

Since financial time series contain trends, it is more appropriate to use filters which are designed to model underlying processes that contain trends and are contaminated with random normally distributed noise et ~ N(0, se2):

  • second order model – mean/position a and linear trend/velocity b:   xt = a + b*t + et
  • third order model – mean/position a, linear trend/velocity b, and quadratic/acceleration c:   xt = a + b*t + ½*c*t2 + et

Examples of such filters include double and triple moving average, double and triple exponential smoothing, and alpha-beta and alpha-beta-gamma tracking filters. These filters are sometimes referred to as “zero lag” filters, although they only reduce but do not totally eliminate lag.

Since financial time series are non-stationary with means and variances that change over time, the use of filters with fixed parameters will not perform well at all times for trading purposes. As a result, filter coefficients that are “fitted” to a particular portion of a time series history will not generally produce good results in the future. Some types of filters, called “adaptive filters”, employ techniques to modify the filter coefficient values over time in response to changes in the characteristics of the input.

17. Forecasting Accuracy

When using MA, LWMA, or ES filters to estimate current values or forecast future values of a process, large N and small a values give more accurate estimates, assuming that the underlying process mean is stable, whereas small N and large a values give more responsive estimates if the underlying process mean changes.

One measure that can be used to evaluate an appropriate N or a value to use with a particular time series is to calculate the root mean square error (RMSE) of the filter forecasts over a sample of observations. For low pass filters, the forecast is the previous filter output value. The forecast error is the difference between the current input value and the forecast.

In general, the N or a value that produces the minimum RMSE can be helpful in determining a useful setting. However, since there is lag when using a low pass filter with time series that contains a trend, the minimum RMSE value, in that case, will generally occur for N = 2 and a = 1.0 and will increase as N increases and as a decreases. RMSE can be used with more complex filters that are designed for time series containing trends.

Acknowledgements

I would like to thank Larry Stabile for reviewing this article and providing many helpful comments and suggestions.

Appendix 1 – Low Pass Moving Average Equations

Appendix 2 – Low Pass Linear Weighted Moving Average Equations

Appendix 3 – Low Pass Exponential Smoothing Equations

Appendix 4 – TSMOM Differentiator Equations

Appendix 5 – Bandpass MAC and MACD Equations

Print Friendly, PDF & Email