wotan icon indicating copy to clipboard operation
wotan copied to clipboard

Add Hodrick–Prescott filter

Open hippke opened this issue 6 years ago • 1 comments

def hp_filter(x, lamb=1600):
    w = len(x)
    b = [[1]*w, [-2]*w, [1]*w]
    D = scipy.sparse.spdiags(b, [0, 1, 2], w-2, w)
    I = scipy.sparse.eye(w)
    B = (I + lamb*(D.transpose()*D))
    return scipy.sparse.linalg.dsolve.spsolve(B, x)

hippke avatar Aug 28 '19 18:08 hippke

Boosted: https://github.com/chenyang45/BoostedHP

hippke avatar Aug 28 '19 18:08 hippke