[Gretl-devel] RFC: time-series filter (long, I'm afraid)

Riccardo (Jack) Lucchetti r.lucchetti at univpm.it
Fri Feb 15 07:42:08 EST 2008


Hi everyone,

I wanted to surprise you all with a clever trick, but at the moments I'm 
not quite sure I'm heading in the right direction, so I'm asking for your 
help.

I'd like to implement some mechanism for "arma-like" filtering of a time 
series, that is, given a time series x_t, compute y_t that satisfies

y_t = C(L)/A(L) x_t

This can be useful in many time-series related contexts: computation of 
fancy moving averages, computation of Wold representations, simulation of 
arma processes, and the list may continue.

I have an initial implementation of this, that you can test by applying 
the attached diff file to current CVS[*]: attached you'll also find an 
example script.

As you can see from the attached sample script, at present the above is 
implemented via a function called "filter", which takes 3 arguments: the 
series x and 2 matrices, containing the coefficients of A(L) and C(L).

These A and C matrices must have 2 columns, or be empty: the rows of A and 
C must contain the coefficients for the powers other than 0 (assumed 1), 
with the exponents on column one and the corresponding coefficient on 
column two. For example, the matrix corresponding to the polynomial C(L) = 
1 - 0.75 L^2 should be given as { 2, -0.75 }; negative exponents (leads) 
are allowed. If you want the "constant" coefficient to be other than 1, 
insert a row with 0 as the first element and the desired "correction" as 
second element (see the moving average example in the attached script).

As you can see, this is a bit cumbersome, so my first question is: how 
can the syntax be improved?

Another problem is the choice of starting values: in practice, the 
computation is carried out by re-casting the above equation as

A(L) y_t = C(L) x_t

At present, the solution I found is quite involved (look at the source to 
see what really happens), but basically pre-sample values of x and y are 
treated as zero.

This is, in some contexts, rather unsatisfactory. However, I see no easy 
way out. Ideally, one should be able to indicate what pre-sample values 
for x and y should be. I'm a bit wary of adding 2 extra parameter to a 
function, so we mat want to turn this functionality into a command, 
something like

filter x A C ; y0 x0

and receive output via some dollar accessor. But OTOH it's nice from a 
programming viewpoint to use all the genr infrastructure.

Another issue is computational: there may be some advantage in using 
Fourier transforms for this. However, I'm no expert here and if any of you 
can give me any hint of the pros and cons, I'd be most grateful.

Your opinions? (Sorry for the long message)



[*] For those not familiar with how to apply patches, just go to the base 
directory of your gretl source tree, do a cvs update and then type the 
command

patch -p0 < ~/filter.diff

assuming you put the diff file in your home dir. Then run make/make 
install as usual.

Riccardo (Jack) Lucchetti
Dipartimento di Economia
Università Politecnica delle Marche

r.lucchetti at univpm.it
http://www.econ.univpm.it/lucchetti
-------------- next part --------------
A non-text attachment was scrubbed...
Name: filter.diff
Type: text/x-diff
Size: 8081 bytes
Desc: 
Url : http://lists.wfu.edu/pipermail/gretl-devel/attachments/20080215/c4c9a0db/filter-0002.bin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: filter.inp
Type: chemical/x-gamess-input
Size: 899 bytes
Desc: 
Url : http://lists.wfu.edu/pipermail/gretl-devel/attachments/20080215/c4c9a0db/filter-0003.bin


More information about the Gretl-devel mailing list