Professional Documents
Culture Documents
Lecture 9
Time Series Filters
Please note that for interactive manipulation you need Mathematica 6 version of this .pdf. Mathematica 6 is available at all Lab's Computers at IES
http://staff.utia.cas.cz/barunik
Jozef Barunik ( barunik @ utia. cas . cz )
¢ | £
2 Lecture8.nb
Outline
Why Filters? - they has its very interesting area of use in analysis of time series
Linear Filters
Filters in Practice
Problems with Filters
¢ | £
Lecture8.nb 3
of course this is very tricky, as we have to choose to what extent we want to "filter" the series
(Do we really filter only noise? Or some important infomration? How do we know?)
¢ | £
4 Lecture8.nb
Linear filter simply converts a time series xt into another time series yt by a linear transformation
xt Ø FILTER Ø yt
yt = ڦ
i=-¶ wi xt-i
This might be a problem, as future realizations are needed, thus we may restrict convolution to:
yt = ڦ
i=0 wi xt-i , where only past is utilized (Casual or physically realizable filter)
¢ | £
Lecture8.nb 5
if the impulse response of filter is finite, we have finite impulse response filter - FIR filter
¢ | £
6 Lecture8.nb
does it look familiar to you?? But it does not have solution without previous information about
yt
by recursive substitution ( y1 = a y0 + x1, y2 = a y1 + x2 ... ) we get general solution
yt = a t y0 + ⁄t-1 i
i=0 a xt-i
¢ | £
Lecture8.nb 7
M
yt = ⁄i=-N wi xt-i ,
where filter processes M future and M past values as well as the current value of the input.
thus filter is noncausual
¢ | £
8 Lecture8.nb
YES !
CONVOLUTION
w * xt
¢ | £
Lecture8.nb 9
¢ | £
10 Lecture8.nb
General form migh be reduced to causal filter by imposing the restriction N=0.
Future values will be ignored by filter, which is inevitable for applications like forecasting
M
yt = ⁄i=0 wi xt-i ,
This form of FIR filter is more common, consider for example Simple Moving Average (SMA):
1 M
yt = M+1 ⁄i=0 xt-i
¢ | £
Lecture8.nb 11
Of course we can upgrade SMA to have i.e. linearly declining weights, example of SMA(6):
2
yt = H6L H7L H6 xt + 5 xt-1 + 4 xt-2 + 3 xt-3 + 2 xt-4 + xt-5L
Exponential Moving Average (EMA) brings idea of weighting lagged observations exponentially.
yt = a xt-1 + H1 - aL yt-1,
2
where a is smoothing factor a = N+1 , N number of lags included, xt is observation in time, and yt
is EMA in time.
alternativelly, EMAt = EMAt-1 + aHprice - EMAt-1L
BUT these filters has quite large lag (see next slide for example)
¢ | £
12 Lecture8.nb
EMA2HML 50
35
30
25
20
2004 2005 2006 2007 2008
from - to 1
¢ | £
Lecture8.nb 13
Well SMA/EMA filters do not use future values, they are casual, but in cost of quite large lag,
thus they react very slowly as you can see from demonstration.
Comparison of Zero-Lag and EMA filter (choose number of lags to include in filter again)
M 50
35
30
25
20
2004 2005 2006 2007 2008
from - to 1
¢ | £
Lecture8.nb 15
let's draw attention to frequencies (in the Fourier space) of time series instead of quantities
the idea is very simple: each time series can be decomposed into a weighted sum of much
simpler sinusoidal components
thus we are approaching time series as a weighted sum of harmonic functions (sines and cosines)
¢ | £
16 Lecture8.nb
Frequency, Period
T = 1 ê f - period
¢ | £
Lecture8.nb 17
Sampling
The process of converting a signal into a numeric sequence (in other words, continuous time or
space to discrete time or space)
The Nyquist frequency is the highest frequency that can be measured in a signal
¢ | £
18 Lecture8.nb
Consider signal with frequency f = 7kHz, and use sampling rate of fs = 8 kHz
This is an undersampled signal
sinH2 p f tL
sampling rate
Ê
Ê
fs 8 kHz 16 kHz 48 kHz
Ê
Ê
Ê
Ê
Ê Ê
Ê
0.0000 0.0002 0.0004 0.0006 0.0008 0.0010
tHsL
Sampling cont.
(Again try to use the interactive example from previous slide to see this)
¢ | £
20 Lecture8.nb
A transform takes one function (or signal) and turns it into another function (signal)
Anyone remember how the functions sin(x) and cos(x) are defined ?
¢ | £
Lecture8.nb 21
Definitions are following (these has very nice property, that they are infinite):
x3 x5 x7 ¶ H-1Ln x 2 n+1
sin HxL = x - 3! + 5! - 7! + ... = ⁄n=0 H2 n+1L!
x2 x4 x6 ¶ H-1Ln x 2 n
cos HxL = 1 - 2! + 4! - 6! + ... = ⁄n=0 H2 nL!
xn x2 x3
ex = ڦ
n=0 n! =1+x + 2! + 3! + ...
¢ | £
22 Lecture8.nb
The complex exponential ei x is defined to be the complex variable whose real and imaginary
parts are cos(x) and sin(x): Also known as Euler relationship:
ei x = cosHxL + i sinHxL
¢ | £
Lecture8.nb 23
Fourier Transform
XH f L = ڦ
t=-¶ xt e
-i2p f t
where xt are fourier coefficients and can be obtained from the inverse Fourier transfrom:
1 p
xt = 2 p -p XH f
Ÿ L ei 2 p f t „ f ,
¢ | £
24 Lecture8.nb
Nice example of approximation of five different periodic functions by Fourier Series conver-
gence
See how Fourier series approximate continuous function vs. "step" function
function step sawtooth parabola cubic half-wave rectifier
number of terms 17
x range 2p
1.0
0.5
-6 -4 -2 2 4 6
-0.5
-1.0
0.08
0.06
0.04
0.02
0.00
1980 1990 2000
¢ | £
Lecture8.nb 27
HP filter was developed basically fo business cycles analysis, but can also be used to other series.
The standard (unvariate) HP filter finds a smoothed series based only on the time series proper-
ties of the original data. It does so by finding the values of t that minimise the function:
L = ⁄Tt=1 H yt - tt L2 + l ⁄T-1
t=2 HHtt+1 - tt L - Htt - tt-1LL
2
l 2162
25
24
23
22
21
20
19
Jan Jul Jan
from - to 1
¢ | £
Lecture8.nb 29
filters are very good tool for extraction of certain features, i.e. cyclical parts, etc.
denoising - it is often difficult to find "the best" treshold, we never now what kind of informa-
tion we can lose if we extract what appears to be "noise"
¢ | £
30 Lecture8.nb
Further Readings
Gencay R., Selcuk F., Whitcher B. : An Introduction to Wavelets and Other Filtering Methods
in Finance and Economics, Academic Press, ISBN 0122796705
Percival D.B., Walden A.T. : Wavelet Methods for Time Series Analysis, Cambridge University
Press, ISBN 0521685087
¢ | £
Lecture8.nb 31
Questions
¢ | £