wotan
wotan copied to clipboard
Add Hodrick–Prescott filter
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)
Boosted: https://github.com/chenyang45/BoostedHP