## Trend extraction and Detrending

Filters may be applied to a time series for a variety of reasons. Suppose that a time series consists of a long-term movement, a trend, upon which is superimposed an irregular component. A moving average filter will smooth the series revealing the trend more clearly.

Assume that $m_{t}$ is the filtered version of the $y_{t}$ series. Then

$m_{t} = M_{n}(L)y_{t} =\sum_{j=-r}^{j=r} w_{j}y_{t-j}$

The weights of a moving average filters add up to one i.e.  $M_{n}(L)=1$. The simplest such filter is the uniform moving average for which:

$w_{j} = \frac{1}{n} \; \; \; \; j=-r,...,r$

The gain of such filter is

$M_{n}(e^{-i \lambda}) = \left| \sum_{j=-r}^{r} \frac{1}{n} e^{-ij\lambda} \right| = \left| \frac{1}{n} \left( 1+2 \sum_{j=1}^{r} cos \lambda_{j} \right) \right| = \left| \frac{sin (n \lambda /2)}{n sin (\lambda /2)} \right|$

Gain of uniform moving average filter

The uniform moving average filter (applied on artificial data)

The Moving Average filter removes a cycle of period n together with its harmonics.

The corresponding detrended series is

$\boxed{y_{t}^{*}=y_{t}-M_{n}(L)y_{t}=[1-M_{n}(L)]y_{t}=M_{n}^{*}(L)y_{t}}$

Hence

$w_{0}^{*}=1-w_{0}$ , $w_{j}^{*}=-w_{j}$$j = \pm 1, ..., \pm r$

The weights sum up to zero ($M_{n}^{*}(1)=0)$ thus

$\boxed{w_{0}^{*}=-2\sum_{j=1}^{r}w_{j}^{*} }$

and

$\begin{array} {lcl} M_{n}^{*}(L) & = & w_{0}+\sum_{j=1}^{r}w_{j}^{*}(L^{j}+L^{-j}) \\ &=& -2\sum_{j=1}^{r}w_{j}^{*} + \sum_{j=1}^{r}w_{j}^{*}(L^{j}+L^{-j})\\ &=& - \sum_{j=1}^{r}w_{j}^{*}(2-L^{j}-L^{-j}) \end{array}$

Bear also in mint that

$2-L^{j}-L^{-j}=(1-L^{j})(1-L^{-j})$ and $1-L^{j} = (1-L)S_{j}(L)$

where

$S_{j}(L) = 1+L+...+L^{j-1}$

is the seasonal weight function.

Hence

$\begin{array} {lcl} M_{n}^{*}(L)&=& -(1-L)(1-L^{-1}) \sum_{j=1}^{r} w_{j}^{*}S_{j}(L)S_{j}(-L) \\ &=& \boxed{\underbrace{ -(1-L)(1-L^{-1})}_{-|1-L|^{2}} \sum_{j=1}^{r} w_{j}^{*} \sum_{h=-(j-1)}^{j-1} (j-|h|)L^{h}}\end{array}$

If $y_{t}$ is an $I(d)$ process with $d=0,1,2$ the a.c.g.f. of $y_{t}^{*}$ is given by

$\begin{array} {lcl} g^{*}(L) &=& \left| M_{n}^{*}(L) \right| ^{2} \left| 1-L \right| ^{-2d} g_{y}^{(d)}(L) \\ &=& \left| 1-L \right|^{2 \times 2} \left| 1-L \right|^{-2d} \left| \sum_{j=1}^{r} w_{j}^{*} \sum_{h=-(j-1)}^{j-1} (j-|h|)L^{h} \right| g_{y}^{(d)}(L) \\ & =& \boxed{ \left| 1-L \right|^{-2(d-2)} \left| \sum_{j=1}^{r} w_{j}^{*} \sum_{h=-(j-1)}^{j-1} (j-|h|)L^{h} \right| g_{y}^{(d)}(L)} \end{array}$

with Spectrum

$\begin{array} {lcl} f_{n}(\lambda)&=&g^{*}(e^{-i \lambda}) \\ &=& |1-e^{-i \lambda}|^{-2(d-2)}\left| \sum_{j=1}^{r} w_{j}^{*} \sum_{h=-(j-1)}^{j-1} (j-|h|)e^{-i \lambda h} \right| f_{y}^{(d)}(L) \\ &=& \boxed{(2-2cos \lambda)^{2-d} \left| \sum_{j=1}^{r} w_{j}^{*}j+ 2 \sum_{j=1}^{r} w_{j}^{*}\sum_{h=1}^{j-1} (j-h)cos \lambda h \right|^{2} f_{y}^{(d)}(L)} \end{array}$

where $f_{y}^{(d)}(L)$ is the spectrum of $\Delta ^{d} y_{t}$

and thus we can show that

$\begin{array} {lcl} M_{n}^{*}(\lambda ; d) &=& - (2-2cos \lambda)^{1-d/2} \left( \sum_{j=1}^{r} w_{j}^{*}j+ 2 \sum_{j=1}^{r} w_{j}^{*}\sum_{h=1}^{j-1} (j-h)cos \lambda h \right) \end{array}$

which for the complement of a simple moving average filter equals

$M_{n}^{*}(\lambda ; d) = \boxed{ \frac{nsin( \lambda /2)-sin(n \lambda /2)}{2^{d}n[\sin (\lambda/2)]^{d+1}}}$

Gain for stationary series with MA and Detrending filter (n=13)

Example: Detrended Random Walk

$\begin{array} {lcl} f_{y}^{*}(\lambda) &=& |M_{n}^{*}(\lambda ; 1)|^{2} \underbrace{f^{1}_{y}(\lambda)}_{f_{\epsilon}(\lambda)} \\ &=& \left[ \frac{nsin( \lambda /2)-sin(n \lambda /2)}{2n[\sin^{2} (\lambda/2)]}\right] ^{2} \frac{\sigma^{2}_{\epsilon}}{2 \pi} \end{array}$