Skip to content

Commit

Permalink
Added some additional methods to the multi_estimate class.
Browse files Browse the repository at this point in the history
  • Loading branch information
alexiosg committed Jul 2, 2024
1 parent ecf3ff5 commit 85e1436
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 23 deletions.
3 changes: 3 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ S3method(estfun,tsgarch.estimate)
S3method(estimate,tsgarch.multispec)
S3method(estimate,tsgarch.spec)
S3method(fitted,tsgarch.estimate)
S3method(fitted,tsgarch.multi_estimate)
S3method(halflife,tsgarch.estimate)
S3method(logLik,tsgarch.estimate)
S3method(newsimpact,tsgarch.estimate)
Expand All @@ -28,7 +29,9 @@ S3method(predict,tsgarch.estimate)
S3method(print,summary.tsgarch.estimate)
S3method(print,summary.tsgarch.profile)
S3method(residuals,tsgarch.estimate)
S3method(residuals,tsgarch.multi_estimate)
S3method(sigma,tsgarch.estimate)
S3method(sigma,tsgarch.multi_estimate)
S3method(simulate,tsgarch.spec)
S3method(summary,tsgarch.estimate)
S3method(summary,tsgarch.profile)
Expand Down
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ hessian calculation.
multi-specification object which can then be estimated in parallel. This
is required for 2-stage multivariate GARCH models. A separate to_multi_estimate
function is also added to instead convert a list of estimated objects to
a validated multi_estimate class.
a validated multi_estimate class. Extractors include fitted, residuals and sigma.
* Removed RcppArmadillo dependency and converted code to RcppEigen since it
is already in use by TMB.
* Switched to using simulate for the parametric simulation for the predict method.
Expand Down
75 changes: 64 additions & 11 deletions R/methods.R
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,13 @@ coef.tsgarch.estimate <- function(object, ...)
#' Extract Volatility (Conditional Standard Deviation)
#'
#' @description Extract the conditional standard deviation from a GARCH model.
#' @param object an object of class \dQuote{tsgarch.estimate}, \dQuote{tsgarch.predict}
#' or \dQuote{tsgarch.simulate}.
#' @param object an object of class \dQuote{tsgarch.estimate}, \dQuote{tsgarch.predict},
#' \dQuote{tsgarch.simulate} or a \dQuote{tsgarch.multi_estimate}.
#' @param ... not currently used.
#' @returns An xts vector of the conditional volatility.
#' @returns An xts vector of the conditional volatility for the univariate type
#' objects. In the case of a multi-estimate object, a list of xts vectors is
#' returned if the individual univariate objects have unequal indices, else an
#' xts matrix is returned.
#' @aliases sigma
#' @method sigma tsgarch.estimate
#' @rdname sigma
Expand All @@ -106,14 +109,32 @@ sigma.tsgarch.estimate <- function(object, ...)
return(out)
}

#' @method sigma tsgarch.multi_estimate
#' @rdname sigma
#' @export
#'
sigma.tsgarch.multi_estimate <- function(object, ...)
{
out <- lapply(object, sigma)
if (attr(object, "index_match") == TRUE) {
out <- do.call(cbind, out)
colnames(out) <- names(object)
} else {
names(out) <- names(object)
}
return(out)
}

#' Extract Model Fitted Values
#'
#' @description Extract the fitted values of the estimated model.
#' @param object an object of class \dQuote{tsgarch.estimate}.
#' @param object an object of class \dQuote{tsgarch.estimate} or
#' \dQuote{tsgarch.multi_estimate}.
#' @param ... not currently used.
#' @returns An xts vector of the fitted values. Since only a constant is supported
#' in the conditional mean equation this is either a vector with a constant else
#' a vector with zeros.
#' @returns An xts vector of the fitted values for the univariate type
#' objects. In the case of a multi-estimate object, a list of xts vectors is
#' returned if the individual univariate objects have unequal indices, else an
#' xts matrix is returned.
#' @aliases fitted
#' @method fitted tsgarch.estimate
#' @rdname fitted
Expand All @@ -130,16 +151,34 @@ fitted.tsgarch.estimate <- function(object, ...)
return(f)
}


#' @method fitted tsgarch.multi_estimate
#' @rdname fitted
#' @export
#'
#'
fitted.tsgarch.multi_estimate <- function(object, ...)
{
out <- do.call(cbind, lapply(object, fitted))
colnames(out) <- names(object)
return(out)
}


#' Extract Model Residuals
#'
#' @description Extract the residuals of the estimated model.
#' @param object an object of class \dQuote{tsgarch.estimate}.
#' @param object an object of class \dQuote{tsgarch.estimate} or
#' \dQuote{tsgarch.multi_estimate}.
#' @param standardize logical. Whether to standardize the residuals by the
#' conditional volatility.
#' @param ... not currently used.
#' @returns An xts vector of the residuals. If the model had no constant in
#' the conditional mean equation then this just returns the original data (which
#' is assumed to be zero mean noise).
#' @returns An xts vector of the model residuals for the univariate type
#' objects. In the case of a multi-estimate object, a list of xts vectors is
#' returned if the individual univariate objects have unequal indices, else an
#' xts matrix is returned.
#' Note that If the model had no constant in the conditional mean equation then this
#' just returns the original data (which is assumed to be zero mean noise).
#' @aliases residuals
#' @method residuals tsgarch.estimate
#' @rdname residuals
Expand All @@ -158,6 +197,20 @@ residuals.tsgarch.estimate <- function(object, standardize = FALSE, ...)
return(res)
}


#' @method residuals tsgarch.multi_estimate
#' @rdname residuals
#' @export
#'
#'
residuals.tsgarch.multi_estimate <- function(object, standardize = FALSE, ...)
{
out <- do.call(cbind, lapply(object, residuals, standardize = standardize))
colnames(out) <- names(object)
return(out)
}


#' The Covariance Matrix of the Estimated Parameters
#'
#' @param object an object of class tsgarch.estimate.
Expand Down
13 changes: 9 additions & 4 deletions man/fitted.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 11 additions & 4 deletions man/residuals.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 9 additions & 3 deletions man/sigma.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 85e1436

Please sign in to comment.