Hodrick-Prescott filter added

286 views
Skip to first unread message

Skipper Seabold

unread,
Apr 12, 2011, 1:06:51 PM4/12/11
to pystat...@googlegroups.com
More advertising noise. I just pushed a pure Python implementation
(using scipy.sparse) of the Hodrick-Prescott filter. It's not winning
any speed contests versus the wrapped Fortran version, but there
aren't any licensing issues (even though I was assured the Fortran
code was public domain) and it's easier to maintain. I don't expect
that the hpfilter would be mission critical anyway.

Python version

In [38]: timeit c,t = hpfilter(dta)
100 loops, best of 3: 2.17 ms per loop

Wrapped Ed Prescott's Fortran 90 version

In [39]: timeit c2,t2 = hpfilt(dta, np.empty((len(dta),3)),len(dta),1600,0)
10000 loops, best of 3: 26 us per loop

Usage

import scikits.statsmodels.api as sm
dta = sm.datasets.macrodata.load()
X = dta.data['realgdp']
c,t = sm.tsa.filters.hpfilter(X)
import matplotlib.pyplot as plt
plt.plot(t)
plt.plot(X)
plt.show()

Skipper

Alan G Isaac

unread,
Apr 13, 2011, 1:34:21 PM4/13/11
to pystat...@googlegroups.com
On 4/12/2011 1:06 PM, Skipper Seabold wrote:
> c,t = sm.tsa.filters.hpfilter(X)

How is the smoothing parameter chosen?
Is an implicit choice a good idea?

Skipper Seabold

unread,
Apr 13, 2011, 2:47:09 PM4/13/11
to pystat...@googlegroups.com

Right. Should've mentioned this. There's a keyword `lamb` set to 1600
by default for quarterly data with suggestions in the docs for annual
and monthly from Ravn and Uhlig (2002).

Patches for data-driven selection of lambda are welcome ;)

Alan G Isaac

unread,
Apr 13, 2011, 2:58:02 PM4/13/11
to pystat...@googlegroups.com
On 4/13/2011 2:47 PM, Skipper Seabold wrote:
> Patches for data-driven selection of lambda are welcome

Not today, but
http://ideas.repec.org/p/lmu/muenec/304.html

fwiw,
Alan

Reply all
Reply to author
Forward
0 new messages