{"id":3466,"date":"2022-04-26T09:28:09","date_gmt":"2022-04-26T01:28:09","guid":{"rendered":"https:\/\/fanyuzhao.com\/?p=3466"},"modified":"2022-04-26T10:55:20","modified_gmt":"2022-04-26T02:55:20","slug":"hodrick-prescott-filter","status":"publish","type":"post","link":"https:\/\/fanyuzhao.com\/?p=3466","title":{"rendered":"Hodrick Prescott Filter \/ HP Filter"},"content":{"rendered":"\n<p>We decompose a time series into two parts, one is the trend, and the other is the seasonality.<\/p>\n\n\n\n<p>$$ y_t=g_t+c_t $$<\/p>\n\n\n\n<p>, where \\(g_t\\) is the trend, and \\(c_t\\) represents seasonality. Or, one can understand those two components as a low-frequent part, and a high-frequent part.<\/p>\n\n\n\n<p>The filer tells that,<\/p>\n\n\n\n<p>$$\\min_{g} \\sum_i^N (y_i-g_i)^2+\\lambda \\sum_i^{N-1} (g_i^2-2g_{i+1}+g_{i+2}^2 )^2$$<\/p>\n\n\n\n<p>$$\\min_{g} \\sum_i^N (y_i-g_i)^2+\\lambda \\sum_i^{N-1} [(g_i-g_{i+1})-(g_{i+1}-g_{i+2}]^2$$<\/p>\n\n\n\n<p>,which can be also written as,<\/p>\n\n\n\n<p>$$\\min_{g} || y-g||^2+\\lambda||\\nabla^2 g||$$<\/p>\n\n\n\n<p>We can see the first term represents how far the trend term \\(g\\) is away from the original series \\(y\\), and the second term means to smooth the trend term \\(g\\).<\/p>\n\n\n\n<p>$$ g=argmin_g || y-g||^2+\\lambda||\\nabla^2 g||^2$$<\/p>\n\n\n\n<p>We replace \\( \\nabla^2 g \\) by \\(Dg\\).<\/p>\n\n\n\n<p>$$  || y-g||^2+\\lambda||D g||$$<\/p>\n\n\n\n<p>$$ (y-g)^T (y-g) +\\lambda (Dg)^T(Dg)$$<\/p>\n\n\n\n<p>We take the first gradient (f.o.c.) to solve for the trend term \\(g\\).<\/p>\n\n\n\n<p>$$ -(y-g)+\\lambda D^TDg =0$$<\/p>\n\n\n\n<p>Therefore,<\/p>\n\n\n\n<p>$$ y=(I+\\lambda D^T D)g $$<\/p>\n\n\n\n<p>and,<\/p>\n\n\n\n<p>$$ g=(I+\\lambda D^T D)^{-1}y $$<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Reference<\/h4>\n\n\n\n<p><a href=\"https:\/\/zhuanlan.zhihu.com\/p\/160243396\">https:\/\/zhuanlan.zhihu.com\/p\/160243396<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>We decompose a time series into two parts, one is the trend, and the other is the seasonality. $$ y_t=g_t+c_t $$ , where \\(g_t\\) is the trend, and \\(c_t\\) represents seasonality. Or, one can understand those two components as a low-frequent part, and a high-frequent part. The filer tells that, $$\\min_{g} \\sum_i^N (y_i-g_i)^2+\\lambda \\sum_i^{N-1} (g_i^2-2g_{i+1}+g_{i+2}^2 &hellip; <a href=\"https:\/\/fanyuzhao.com\/?p=3466\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Hodrick Prescott Filter \/ HP Filter<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6,18],"tags":[],"_links":{"self":[{"href":"https:\/\/fanyuzhao.com\/index.php?rest_route=\/wp\/v2\/posts\/3466"}],"collection":[{"href":"https:\/\/fanyuzhao.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fanyuzhao.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fanyuzhao.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fanyuzhao.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3466"}],"version-history":[{"count":25,"href":"https:\/\/fanyuzhao.com\/index.php?rest_route=\/wp\/v2\/posts\/3466\/revisions"}],"predecessor-version":[{"id":3504,"href":"https:\/\/fanyuzhao.com\/index.php?rest_route=\/wp\/v2\/posts\/3466\/revisions\/3504"}],"wp:attachment":[{"href":"https:\/\/fanyuzhao.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3466"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fanyuzhao.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3466"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fanyuzhao.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3466"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}