[R-sig-finance] Baxter-King filtering?

Ajay Narottam Shah ajayshah at mayin.org
Fri Nov 25 02:33:40 CET 2005

A few weeks ago, Gabor showed this code for Hodrick Prescott

# See http://econ.ohio-state.edu/hwkim/hpfilter.pdf
# Maravall & del Rio (2001) recommend
#      Quarterly data         lambda=1600
#      Monthly                1e5<lambda<1.4e5
#      Annual                 6 < lambda < 14
hodrickprescott <- function(y, lambda) {
  eye <- diag(length(y))
  F <- crossprod(diff(eye, d=2))
  tau <- solve(lambda * F + eye, y)
  list(trend=tau, cycle=y-tau)

The literature seems to think that Baxter-King works better. The idea
is not hard: it's just a band pass filter at `business cycle
frequencies'. So the steps would be to do a fourier transform, zap out
power at all but the interesting frequencies, and then do an inverse
transform. The implementation is a bit harder because of short data
series and (I think) edge effects. I'm not fluent with spectral
analysis and am unable to hack this up. Has someone already done this?

I noticed that it's supported by `grocer' which runs under Scilab, so
GPL code is probably out there already.

Ajay Shah
ajayshah at mayin.org

More information about the R-sig-finance mailing list