% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/04_algo_bhp.R
\name{bhp_filter}
\alias{bhp_filter}
\title{Boosted HP Filter}
\usage{
bhp_filter(
  x,
  lambda = NULL,
  iter_max = 100L,
  stopping = c("bic", "adf", "fixed"),
  sig_level = 0.05,
  freq = NULL
)
}
\arguments{
\item{x}{Numeric vector, \code{ts}, \code{xts}, or \code{zoo} object.}

\item{lambda}{Smoothing parameter.
If \code{NULL} (default), it is auto-detected using the Ravn-Uhlig rule
(\code{6.25 * freq^4}).}

\item{iter_max}{Integer.
Maximum number of boosting iterations (default 100).}

\item{stopping}{Character.
Stopping rule: \code{"bic"} (default), \code{"adf"}, or \code{"fixed"}.}

\item{sig_level}{Numeric.
Significance level for the ADF test when \code{stopping = "adf"}
(default 0.05).}

\item{freq}{Numeric frequency override (1 = annual, 4 = quarterly,
12 = monthly). Used only when \code{lambda} is \code{NULL} and the frequency cannot
be inferred from \code{x}.}
}
\value{
A \code{macrofilter} object with \code{trend}, \code{cycle}, \code{data}, and \code{meta}
components.  The \code{meta} list contains \code{method = "bHP"}, \code{lambda},
\code{iterations}, \code{stopping_rule}, and \code{compute_time}.
}
\description{
Iteratively applies the Hodrick-Prescott filter on residuals to better
capture stochastic trends.  At each iteration the HP smoother is applied to
the current residual and the resulting trend increment is added to the
cumulative trend estimate.  Iteration stops according to one of three rules:
BIC minimisation (default), ADF stationarity test on residuals, or a fixed
number of iterations.
}
\details{
The boosted HP filter starts from the standard HP solution and then
re-applies the same HP smoother to the residual (cycle) component.  The
trend increment from each pass is accumulated, and the procedure stops
when one of the following criteria is met:

\describe{
\item{\code{"bic"}}{Schwarz information criterion computed as
\eqn{n \log(\hat\sigma^2) + \log(n)\,\mathrm{tr}(S^m)},
where \eqn{S^m} is the iterated smoother.  Iteration stops when the BIC
increases relative to the previous best.}
\item{\code{"adf"}}{Augmented Dickey-Fuller test on the residual.  Iteration
stops when the residual is stationary at level \code{sig_level}.}
\item{\code{"fixed"}}{Runs exactly \code{iter_max} iterations.}
}
}
\examples{
# Quarterly GDP-like series
y <- ts(cumsum(rnorm(200)), start = c(2000, 1), frequency = 4)
result <- bhp_filter(y)
print(result)
}
\references{
Phillips, P.C.B. and Shi, Z. (2021). Boosting: Why You Can Use the HP
Filter. \emph{International Economic Review}, 62(2), 521--570.
}
