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.
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.
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:
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.
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:
generic low pass filter frequency response with -3 dB cutoff frequency c
note: the z
The behavior of a filter, specifically its frequency response, is determined by the type of filter and the
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.
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.
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.
A commonly-used trading signal is generated when the current price crosses above (buy) or below (sell) the low pass moving average.
Passes frequencies below the -3 dB cutoff frequency f
A commonly-used trading signal is generated when the current price crosses above (buy) or below (sell) the low pass linear weighted moving average.
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.
A commonly-used trading signal is generated when the current price crosses above (buy) or below (sell) the low pass exponential smoothing.
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.
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):
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.
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.
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.
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.
MAC can be calculated recursively in IIR form (requires proper initialization):
A commonly-used trading signal is generated when the short moving average MA### MAC Frequency Response (N

A popular moving average crossover uses short MA length N
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.
MACD can be interpreted in several ways. One type of MACD trading signal is generated when ES### MACD Frequency Response (a

A popular MACD configuration is to set a
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.
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.

## 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.

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.- 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 = 360
^{o}= 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:

- P = The number of time samples to complete one cycle (normalized period)

### 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

- 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 amplitude
^{2}(i.e., input amplitude squared) - output power = output amplitude
^{2 }(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

_{c}or f_{c}. Cutoff period is denoted as P_{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: y
_{t}=*b**x_{0}_{n}+*b**x_{1}_{n-1}+*b**x_{2}_{n-2 }+ …

- general FIR difference equation: y

^{-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: y
_{t}=*b**x_{0}_{n}+*b**x_{1}_{n-1}+*b**x_{2}_{n-2 }+ … +*a**y_{1}_{n-1}+*a**y_{2}_{n-2 }+ …

- general IIR difference equation: y

*a*and_{i}*b*filter coefficient values._{i}### 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

## 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 r_{t }= ln(x_{t}/x_{t-1}) where x_{t}is the index value at integer time t corresponding to the date. The natural log returns are used to calculate the frequency spectrum.### 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.## 5. Moving Average (MA)

The moving average (MA) filter difference equation is: MA_{t}(N) = (x_{t}+ x_{t-1}+ … + x_{t-N-1}) / N = (1/N)*x_{t}+ (1/N)*x_{t-1}+ … + (1/N)*x_{t-N-1}where N is the number of input data points included in the average, i.e., the moving average length (N > 1), and x_{t}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 f_{c}is inversely proportional to N (the cutoff period P_{c}is proportional to N). MA can be calculated recursively in IIR form (requires proper initialization):### Moving Average Filter Frequency Response (N = 10)

**Example:**Moving average filter with length N = 10 MA_{t}(10) = (x_{t}+ x_{t-1 }+ x_{t-2 }+ x_{t-3 }+ x_{t-4 }+ x_{t-5 }+ x_{t-6 }+ x_{t-7 }+ x_{t-8 }+ x_{t-9}) / 10 = 0.1*x_{t}+ 0.1*x_{t-1 }+ 0.1*x_{t-2 }+ 0.1*x_{t-3 }+ 0.1*x_{t-4 }+ 0.1*x_{t-5 }+ 0.1*x_{t-6 }+ 0.1*x_{t-7 }+ 0.1*x_{t-8 }+ 0.1*x_{t-9}Passes frequencies below the -3 dB cutoff frequency f_{c}of approximately 0.044, which corresponds to a cutoff period P_{c}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._{c}of approximately 0.002, which corresponds to a cutoff period P_{c}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: HPMA_{t}(N) = x_{t}– MA_{t}(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) HPMA_{t}(10) = x_{t}– (x_{t}+ x_{t-1 }+ x_{t-2 }+ x_{t-3 }+ x_{t-4 }+ x_{t-5 }+ x_{t-6 }+ x_{t-7 }+ x_{t-8 }+ x_{t-9}) / 10 = 0.9*x_{t}– 0.1*x_{t-1}– 0.1*x_{t-2}– 0.1*x_{t-3}– 0.1*x_{t-4}– 0.1*x_{t-5}– 0.1*x_{t-6 }– 0.1*x_{t-7 }– 0.1*x_{t-8 }– 0.1*x_{t-9}Passes frequencies above the -3 dB cutoff frequency f_{c}of approximately 0.027, which corresponds to a cutoff period P_{c}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: LWMA_{t}(N) = [2/(N*(N + 1))] * [N*x_{t}+ (N – 1)*x_{t-1}+ (N – 2)*x_{t-2}+ … + x_{t-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 f_{c}is inversely proportional to N (the cutoff period P_{c}is proportional to N). LWMA can be calculated recursively in IIR form (requires proper initialization):### LWMA Filter Frequency Response (N = 10)

**Example:**Linear weighted moving average filter with length N = 10 (note*:*coefficients shown are rounded) LWMA_{t}(10) = 0.1818*x_{t}+ 0.1636*x_{t-1 }+ 0.1455x_{t-2 }+ 0.1273*x_{t-3 }+ 0.1091*x_{t-4 }+ 0.0909*x_{t-5 }+ 0.0727*x_{t-6 }+ 0.0545*x_{t-7 }+ 0.0364*x_{t-8 }+ 0.0182*x_{t-9}Passes frequencies below the -3 dB cutoff frequency f_{c}of approximately 0.053, which corresponds to a cutoff period P_{c}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: HPLWMA_{t}(N) = x_{t}– LWMA_{t}(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) HPLWMA_{t}(10) = x_{t}– (0.1818*x_{t}+ 0.1636*x_{t-1 }+ 0.1455x_{t-2 }+ 0.1273*x_{t-3 }+ 0.1091*x_{t-4 }+ 0.0909*x_{t-5 }+ 0.0727*x_{t-6 }+ 0.0545*x_{t-7 }+ 0.0364*x_{t-8 }+ 0.0182*x_{t-9}) = 0.8182*x_{t}– 0.1636*x_{t-1 }– 0.1455x_{t-2 }– 0.1273*x_{t-3 }– 0.1091*x_{t-4 }– 0.0909*x_{t-5 }– 0.0727*x_{t-6 }– 0.0545*x_{t-7 }– 0.0364*x_{t-8 }– 0.0182*x_{t-9}Passes frequencies above the -3 dB cutoff frequency f_{c}of approximately 0.043, which corresponds to a cutoff period P_{c}of approximately 23.3 time samples.## 9. Exponential Smoothing (ES)

The exponential smoothing (ES) filter difference equation is: ES_{t}(a) = a*x_{t}+ (1 – a)*ES_{t-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 f_{c}is proportional to a (the cutoff period P_{c}is inversely proportional to a). ES can be calculated non-recursively in FIR form:### Exponential Smoothing Filter Frequency Response (a = 0.2425)

**Example:**exponential smoothing filter with smoothing constant a = 0.2425 ES_{t}(0.2425) = 0.2425*x_{t}+ 0.7575*ES_{t-1}(0.2425) Passes frequencies below the -3 dB cutoff frequency f_{c}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 P_{c}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: HPES_{t}(a) = x_{t}– ES_{t}(a) = (1 – a)*x_{t}– (1 – a)*x_{t-1}+ (1 – a)*HPES_{t-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: HPES_{t}(a) = (1 – a/2)*x_{t}– (1 – a/2)*x_{t-1}+ (1 – a)*HPES_{t-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 HPES_{t}(0.2425) = 0.87875*x_{t}– 0.87875*x_{t-1}+ 0.7575*HPES_{t-1}(a) Passes frequencies above the -3 dB cutoff frequency f_{c}of approximately 0.044, which corresponds to a cutoff period P_{c}of approximately 22.5 time samples.## 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 e_{t}where e_{t}~ N(0, s_{e}^{2}): first order model – mean/position*a*: x_{t}=*a*+ e_{t}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
_{MA}= (N_{MA}– 1) / 2 - lag
_{LWMA}= (N_{LWMA}– 1) / 3 - lag
_{ES}= (1 – a_{ES}) / a_{ES}

### 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 N_{MA}, the equivalent LWMA N and ES a are: N_{LWMA}= [(3*N_{MA}– 1)/2] where […] denotes the integer function a_{ES}= 2/(N_{MA}+ 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.## 12. Time Series Momentum (TSMOM)

The time series momentum (TSMOM) filter difference equation is: TSMOM_{t}(L) = G*x_{t}– G*x_{t-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 TSMOM_{t}(10) = 0.5*x_{t}– 0.5*x_{t-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.### 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: TSMOM_{t}(3) = x_{t}– x_{t-3}L = 6: TSMOM_{t}(6) = x_{t}– x_{t-6}L = 9: TSMOM_{t}(9) = x_{t}– x_{t-9}L = 12: TSMOM_{t}(12) = x_{t}– x_{t-12}gain-adjusted average: ATSMOM_{t}(3, 6, 9, 12) = G*(4*x_{t }– x_{t-3}– x_{t-6 }– x_{t-9}– x_{t-12})/4 = G*(x_{t}– 0.25*x_{t-3}– 0.25*x_{t-6}– 0.25*x_{t-9}– 0.25*x_{t-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). ATSMOM_{t}(3, 6, 9, 12) = 0.7043*(x_{t}– 0.25*x_{t-3}– 0.25*x_{t-6}– 0.25*x_{t-9}– 0.25*x_{t-12}) = 0.7043*x_{t}– 0.176075*x_{t-3}– 0.176075*x_{t-6}– 0.176075*x_{t-9}– 0.176075*x_{t-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.### 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.## 14. Moving Average Crossover (MAC)

Moving average crossover (MAC) uses the difference between two moving averages. One moving average has a short length N_{s}and the other a longer length N_{l}: MAC_{t}(N_{s}, N_{l}) = MA_{t}(N_{s}) – MA_{t}(N_{l}) where 1 < N_{s}< N_{l}Moving average crossover is a type of bandpass FIR filter, passing frequencies between low (f_{L}) and high (f_{H}) cutoff frequencies, called the bandwidth (Df = f_{H}– f_{L}). The filter has a center (also called “resonant”) frequency (f_{0}) 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 N_{s }and N_{l}. 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.)_{t}(N_{s}) crosses above (buy) or below (sell) the long moving average MA_{t}(N_{l}).### MAC Frequency Response (N_{s} = 50 & N_{l} = 200)

A popular moving average crossover uses short MA length N_{s}= 50 days and long MA length N_{l }= 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 N_{s}= 50 and N_{l }= 200: MAC_{t}(50, 200) = MA_{t}(50) – MA_{t}(200) The -3 dB short cutoff period P_{cs}is approximately 166 time samples, the -3 dB long cutoff period P_{cl}is approximately 604 time samples, and the center (resonant) period P_{0}is approximately 279 time samples.## 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 a_{l}(i.e., based on the short MA length N_{s}) and the other using a smaller smoothing constant a_{s}(i.e., based on the long MA length N_{l}): MACD_{t}(N_{s}, N_{l}) = ES_{t}(a_{l}) – ES_{t}(a_{s}) where 1 < N_{s}< N_{l }and, consequently, 0 <= a_{s}< a_{l}<= 1 MACD is a type of bandpass IIR filter, passing frequencies between low (f_{L}) and high (f_{H}) cutoff frequencies, called the bandwidth (Df = f_{H}– f_{L}). The filter has a center (also called “resonant”) frequency (f_{0}), which the filter passes at maximum power. The bandwidth and center frequency are determined by the two smoothing constants a_{l }and a_{s}. MACD can also be calculated in the form (requires proper initialization):_{t}(a_{l}) crosses above (buy) or below (sell) ES_{t}(a_{s}). 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 (a_{l} = 0.2067 & a_{s }= 0.1015)

A popular MACD configuration is to set a_{l}equivalent to a moving average length of 12 days and a_{s }equivalent to a moving average length of 26 days.**Example:**Moving average convergence-divergence filter where MA N_{s}= 12 and MA N_{l}= 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: N_{s}= 12 —-> a_{l}= 0.2067 and N_{l}= 26 —-> a_{s }= 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 P_{cl}is approximately 101-time samples.### 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.

_{t}~ N(0, s_{e}^{2}):- second order model – mean/position
*a*and linear trend/velocity*b*: x_{t}=*a*+*b**t + e_{t} - third order model – mean/position
*a*, linear trend/velocity*b*, and quadratic/acceleration*c*: x_{t}=*a*+*b**t + ½**c**t^{2}+ e_{t}

## Follow Us and Learn