Page 1 of 1

Code for a smoothing Filter (Hodrick Prescot Filter)

Posted: Wed Mar 16, 2011 1:00 pm
by MT_MANC
Im trying to trace the explicit (model) code required to manually create a smoothed series (ideally HP Filter) from some raw (quarterly) data on GDP_c

I have a simple model (actually solved externally in WinSolve) that contains a smoothed GDP variable over the data period (produced using WinSolve’s own Hodrick-Prescott Table transformation on the raw GDP data)
But I then need to (dynamically) forecast this Hodrick-Prescott smoothing/filter series (or something similar) over a forecast period; so I need an explicit expression that I can code up in the model in order to produce such a HP smoothed forecast.

Is anyone aware of any "extracted" smoothing code in order to specify such an expression "manually" ( I realise Eviews
has internal "black box" routines to calculate such a smoothing transformation -but I need some explicit coding that I can use in WinSolve)

My simple example starting point is a modified MA(8) smoothing expression (with shift adjustment):

Code: Select all

* GDPtr_c = ( +8/36*(GDP_c(-1)) +7/36*(GDP_c(-2)) +6/36*(GDP_c(-3) ) +5/36*(GDP_c(-4) ) +4/36*(GDP_c(-5)) +3/36*(GDP_c(-6)) +2/36*(GDP_c(-7) ) +1/36*(GDP_c(-8) ) /8 ) -0.25*( (GDPtr_c(-1)-GDP_c(-1))+(GDPtr_c(-2)-GDP_c(-2))+(GDPtr_c(-3)-GDP_c(-3))+(GDPtr_c(-4)-GDP_c(-4)) +(GDPtr_c(-5)-GDP_c(-5))+(GDPtr_c(-6)-GDP_c(-6))+(GDPtr_c(-7)-GDP_c(-7))+(GDPtr_c(-8)-GDP_c(-8)) ) ;


..but this does not replicate HP filter over the data period !!!

Most Kind

Re: Code for a smoothing Filter (Hodrick Prescot Filter)

Posted: Thu Mar 17, 2011 1:47 am
by trubador
HP filter can be formulated as a minimization problem and the solution can be written in matrix form as follows:

Code: Select all

'Pass your arguments to the program %name =yourseries.@name !nobs = {%name}.@obs !lambda = 1600 'This is the actual part that computes HP filtered series. matrix(!nobs,!nobs) z = 0 rowvector(3) v v(1) = 1 v(2) = -2 v(3) = 1 for !i=1 to !nobs-2 matplace(z,v,!i,!i) next vector hpvec = @inverse(@identity(!nobs)+!lambda*@transpose(z)*z)*{%name} 'Transform the vector into series mtos(hpvec,{%name}_hp) 'Compare the results with EViews' HP command {%name}.hpf(!lambda) EViews_HP plot {%name}_hp EViews_HP 'Delete the temporary files if you like delete z v hpvec