Upload
others
View
1
Download
0
Embed Size (px)
Citation preview
Applied Econometrics
Lecture 9Time 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/barunikJozef Barunik ( barunik @ utia. cas . cz )
¢ | £
Outline
Why Filters? - they has its very interesting area of use in analysis of time series
Linear Filters
Time Domain Filters Infinite Impulse Response (IIR)Finite Impulse Response (FIR): MA, EWMA, Zero-LagFilter
Frequency Domain FiltersFrequency, Period, SamplingFourier Transforms
Filters in PracticeProblems with Filters
¢ | £
2 Lecture8.nb
Linear Filters - Motivation
A discrete time series as a sequence of observations ordered by a time t, 8xt<t=-¶¶
we apply filter to extract certain features from time series xt :trendseasonalitiesbusiness cyclesnoise
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?)
¢ | £
Lecture8.nb 3
Linear Filters in Time Domain
Linear filter simply converts a time series xt into another time series yt by a linear transformation
xt Ø FILTER Ø yt
The output yt is result of convolution of the input xt with a coefficient vector wt : Hwt are also called filter coefficients)
yt =⁄i=-¶¶ wi xt-i
where convolution is formally defined asw *xt =⁄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)
¢ | £
4 Lecture8.nb
Linear Filters in Time Domain cont.
We classify linear filters according to their response to an impulse signal
if the impulse response of filter is finite, we have finite impulse response filter - FIR filter
if the impulse response of filter is infinite, we have IIR filter
¢ | £
Lecture8.nb 5
Infinite Impulse Response (IIR) Filters
Consider a form of constant coefficient linear difference equation:
yt =⁄i=1L ai yt-i +⁄i=0
M wi xt-i,where the current value of the output is determined by L lagged values of output yt and Mlagged values of input xt , as well as current input value.
Consider this first-order difference equation: yt = a yt-1 + xt .
does it look familiar to you?? But it does not have solution without previous information aboutytby recursive substitution ( y1 = a y0 + x1, y2 = a y1 + x2 ... ) we get general solutionyt = at y0 +⁄i=0
t-1 ai xt-i
¢ | £
6 Lecture8.nb
Finite Impulse Response (FIR) Filters
General form of an FIR filter is:
yt =⁄i=-NM 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
Anyone remember how is this equation called?
¢ | £
Lecture8.nb 7
Finite Impulse Response (FIR) Filters cont.
YES !
CONVOLUTION
w *xt¢ | £
8 Lecture8.nb
Finite Impulse Response (FIR) Filters cont.
very common example is Simple Centered Moving Average:
yt = 1M+N+1 Hxt-M + ... + xt-1 + xt + xt+1 + ... + xt+NL
The impulse response of this filter is finite:
wi = :1
M+N+1 ,
0
if i = -N , ..., -1, 0, 1, ..., Motherwise
¢ | £
Lecture8.nb 9
Finite Impulse Response (FIR) Filters cont. - SMA
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
yt =⁄i=0M wi xt-i,
This form of FIR filter is more common, consider for example Simple Moving Average (SMA):
yt = 1M+1 ⁄i=0
M xt-i
¢ | £
10 Lecture8.nb
Finite Impulse Response (FIR) Filters cont. - EMA
Of course we can upgrade SMA to have i.e. linearly declining weights, example of SMA(6):
yt = 2H6L 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,
where a is smoothing factor a = 2N+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)
¢ | £
Lecture8.nb 11
Finite Impulse Response (FIR) Filters cont. - SMA vs. EMAComparison of Simple Moving Average and Exponential Moving Average
MA1HML 50
EMA2HML 50
zoom interval Hin daysL 1130
Show whole period
2004 2005 2006 2007 200820
25
30
35
from - to 1
¢ | £
12 Lecture8.nb
Finite Impulse Response (FIR) Filters cont. - Zero Lag Filters
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.
Solution might be simple idea of differencing 2 EMA:
EMAHML = 2µEMAHML- EMAH2 M - 1L,where M is the period of EMA.
Of course there are many other possibilities¢ | £
Lecture8.nb 13
Finite Impulse Response (FIR) Filters cont. - Zero Lag Filters
Comparison of Zero-Lag and EMA filter (choose number of lags to include in filter again)
M 50
zoom interval Hin daysL 1130
Show whole period
2004 2005 2006 2007 200820
25
30
35
from - to 1
¢ | £
14 Lecture8.nb
Linear Filters in Frequency Domain
until now, we discussed filters with time domain only
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 muchsimpler sinusoidal components
thus we are approaching time series as a weighted sum of harmonic functions (sines and cosines)
¢ | £
Lecture8.nb 15
Frequency, Period
f is frequency of cycles per second, (c.p.s., Hz)
w = 2 p f - angular frequency (radians per second)
T = 1 ê f - period
¢ | £
16 Lecture8.nb
Sampling
The process of converting a signal into a numeric sequence (in other words, continuous time orspace to discrete time or space)
The Nyquist frequency is equal to one-half of the sampling frequency
wNYQUIST =T-12
The Nyquist frequency is the highest frequency that can be measured in a signal
¢ | £
Lecture8.nb 17
Sampling - An Undersampled Signal
sinH2 p f tL
Consider signal with frequency f = 7kHz, and use sampling rate of fs = 8 kHzThis is an undersampled signal
Use following interactive example to sample your own signal:
frequency
f @HzD 6877
sampling rate
fs 8 kHz 16 kHz 48 kHz
Ê
ÊÊ
Ê
Ê
ÊÊ
Ê
Ê
0.0000 0.0002 0.0004 0.0006 0.0008 0.0010
tHsL
sinH2 p f tL
Author: Carsten RoppelSource: http://demonstrations.wolfram.com/SamplingTheorem/
¢ | £
18 Lecture8.nb
Sampling cont.
According to the sampling theorem, following may occur:
f § fs ê 2: the samples uniquely represent the sine wave of frequency f .
f > fs ê 2: aliasing occurs, because the replicated spectra begin to overlap.
0 § f § fs ê 2: a spectral line appears at the frequency f - fs .
(Again try to use the interactive example from previous slide to see this)¢ | £
Lecture8.nb 19
Fourier Theory - Mathematical Prerequisities First
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 ?
¢ | £
20 Lecture8.nb
Fourier Theory - Mathematical Prerequisities First
Definitions are following (these has very nice property, that they are infinite):
sin HxL = x - x33! +
x55! -
x77! + ... =⁄n=0
¶ H-1Ln x2 n+1H2 n+1L!
cos HxL = 1 - x22! +
x44! -
x66! + ... =⁄n=0
¶ H-1Ln x2 nH2 nL!
now consider definition of ex:
ex =⁄n=0¶ xn
n! = 1 + x + x22! +
x33! + ...
¢ | £
Lecture8.nb 21
Fourier Theory - The Complex Exponential
The complex exponential ei x is defined to be the complex variable whose real and imaginaryparts are cos(x) and sin(x): Also known as Euler relationship:
ei x = cosHxL+ i sinHxL¢ | £
22 Lecture8.nb
Fourier Transform
Any infinite sequence xt may be viewed as a combination of an infinite number of sinusoidswith different amplitudes and phases
Discrete Fourier Transform (DFT) is defined as:
XH f L =⁄t=-¶¶ xt e-i2p f t
where xt are fourier coefficients and can be obtained from the inverse Fourier transfrom:
xt = 12 p Ÿ-p
p XH f L ei 2 p f t „ f ,
¢ | £
Lecture8.nb 23
Fourier Series at Work
Nice example of approximation of five different periodic functions by Fourier Series conver-genceSee how Fourier series approximate continuous function vs. "step" function
function step sawtooth parabola cubic half-wave rectifier
number of terms 17
x range 2 p
-6 -4 -2 2 4 6
-1.0
-0.5
0.5
1.0
Author : Alain GorielySource : http : // demonstrations.wolfram.com/FourierSeriesOfSimpleFunctions/
¢ | £
24 Lecture8.nb
¢ | £Lecture8.nb 25
Filters in Practice - EMA Volatility Estimation
EMA filter plays important role in the risk management
l
S&P standard deviation estimate with EMA Hl=0.9L
1980 1990 20000.00
0.02
0.04
0.06
0.08
¢ | £
26 Lecture8.nb
Filters in Practice - Hodrick-Prescott (HP) Filters
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 = ⁄t=1T H yt - ttL2 + l⁄t=2
T-1 HHtt+1 - ttL- Htt - tt-1LL2
where the weight on smoothness (l).
main drawback of HP filter is that it ¢ | £
Lecture8.nb 27
Filters in Practice - Hodrick-Prescott (HP) Filters
l 2162
zoom interval Hin daysL 347
Show whole period
Jan Jul Jan19
20
21
22
23
24
25
from - to 1
¢ | £
28 Lecture8.nb
Problems with Filters
filters are very good tool for extraction of certain features, i.e. cyclical parts, etc.
they can not be used for forecasting ! (look at the construction)
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"
¢ | £
Lecture8.nb 29
Further Readings
Other type of powerfull Nonlinear filters is Wavelets
students interested in filters are adviced to use following literature:
Gencay R., Selcuk F., Whitcher B. : An Introduction to Wavelets and Other Filtering Methodsin Finance and Economics, Academic Press, ISBN 0122796705
Percival D.B., Walden A.T. : Wavelet Methods for Time Series Analysis, Cambridge UniversityPress, ISBN 0521685087
¢ | £
30 Lecture8.nb
Questions
Other examples during seminar
THANK YOU FOR ATTENTION !
¢ | £
Lecture8.nb 31