Skip to content

Commit

Permalink
General updates.
Browse files Browse the repository at this point in the history
  • Loading branch information
robustport committed Dec 1, 2024
1 parent 10c9c82 commit 1c08c52
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 78 deletions.
68 changes: 33 additions & 35 deletions R/robGarch.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#' @importFrom stats median pnorm density nlminb
#' @importFrom graphics par
#' @title Robust GARCH(1,1) Model Estimated
#' @title Robust GARCH(1,1) Model Estimation
#'
#' @name robGarch
#'
Expand All @@ -14,6 +14,10 @@
#' location, scale,and degrees of freedom parameters.
#' CHECK IF (3) IS CORRECT.
#'
#' @references Muler, N. and Yohai, V. (2008). Robust estimates
#' for GARCH models. Journal of Statistical Planning and Inference,
#' 138, 2918-2940.
#'
#' @param data an xts object
#' @param fitMethod character valued name of fitting method,
#' one of "BM", "M" "QML" or "tMLE", with "BM" the default value.
Expand All @@ -23,12 +27,11 @@
#' "Rsolnp", "nloptr", "nlminb", with default "Rsolnp".
#' @param initialPars numeric user-defined initial parameters
#' c(gamma0, alpha0, beta0) for use by optimizer, with default
#' values c(0.0005, 0.2, 0.7).
#' values c(0.0005, 0.15, 0.75).
#' @param optControl list of arguments passed to optimizer, with
#' default \code{list(trace=0)}.
#' @param SEmethod character valued name of standard error method,
#' one of "numDeriv", "optim", "sandwich", with default "numDeriv".
#' using hessian from numDeriv
#'
#' @details The "BM" fit method delivers the highest robustness by
#' using a half-Huber psi function to bound the normal distribution
Expand All @@ -37,47 +40,42 @@
#' The "M" method is obtained by dropping the BM bounding of the
#' variance recursion, and is therefore less robust toward outliers.
#'
#' Echo or Dan, please provide details for optControl.
#'
#' ECHO OR DAN, PLEASE PROVIDE DETAILS FOR optControl.
#' For details of the list of control arguments, please refer to
#' \code{nloptr::nloptr}, \code{Rsolnp::solnp}, \code{nlminb}.
#' The SEmethod default "numDeriv" is based on the Hessian from the
#' optimization.
#'
#' @return
#' A \code{robustGARCH} object(S3), the components of the object are:
#' \item{data}{the input xts object}
#' \item{fitMethod}{the the fitMethod specified}
#' \item{robtunePars}{the robtunePars specified}
#' \item{optimizer}{the optimizer type specified}
#' \item{initialPars}{the initialPars specified}
#' \item{optControl}{the list of control values specified}
#' \item{optOutput}{a list of the optimizer output values returned}
#' \item{SEmethod}{the specidied of calculating standard errors}
#' \item{coefEstimates}{computed parameter estimates}
#' \item{sigma}{conditional standard deviation xts class time series}
#' \item{observedInfomat}{observed information matrix}
#' \item{objective}{the optimizer minimized objective function value}
#' \item{message}{optimizer convergence satus message}
#'
#' @details
#' The \code{robGarch} function fits a Garch(1, 1) model to a time series of log return data, using one of the two methods of robust extended M-Estimates with certain parameters specified by the user, with guidance and examples from the vignette. The user can also specify the optimizer used during optimization procesure, and the method used to calculate standard error for the fitted parameters.
#' A list object of class \dQuote{robustGarch} with components:
#' \item{data}{the input xts object}
#' \item{fitMethod}{the the fitMethod specified}
#' \item{robtunePars}{the robtunePars specified}
#' \item{initialPars}{the initialPars specified}
#' \item{optChoice}{the optimizer specified}
#' \item{coefEstimates}{computed parameter estimates}
#' \item{sigma}{conditional standard deviation xts class time series}
#' \item{SEmethod}{the specidied of calculating standard errors}
#' \item{observedInfoMat}{observed information matrix}
#' \item{optDetails}{a list containing the optimizer specified,
#' the control values specified, and the optimizer minimized
#' objective, and convergence status message}
#'
#' For details of the list of control arguments, please refer to \code{nloptr::nloptr}, \code{Rsolnp::solnp}, \code{nlminb}.
#'
#' @references Muler, Nora & Yohai, Victor. (2008). Robust estimates for GARCH models. Journal of Statistical Planning and Inference. 138. 2918-2940.
#' @rdname robustGARCH-robGarch
#' @export
#'
#' @examples
#'
#'
#' data("gspc")
#' fit <- robGarch(gspc[1:604], methods="BM", tuningPars = c(0.8, 3.0))
#'
#' fit <- robGarch(gspc[1:604], fitMethod = "BM")
#' summary(fit)
#'
#' @rdname robustGARCH-robGarch
#' @export
# Garch(1,1) model fit function
robGarch <- function(data, methods = c("BM", "M", "QML", "MLE"), turingPars = c(0.8, 3.0),
optimizer = c("Rsolnp", "nloptr", "nlminb"), optimizer_x0 = FALSE,
optimizer_control = list(trace=0), stdErr_method = c("numDeriv", "optim", "sandwich")){
robGarch <- function(data, fitMethod = c("BM", "M", "QML", "MLE"),
tuningPars = c(0.8, 3.0),
optChoice = c("Rsolnp", "nloptr", "nlminb"),
initialPars = c(0.0005, 0.15, 0.75),
SEmethod = c("numDeriv", "optim", "sandwich"),
optimizer = list(trace=0))
{

# if(!is.numeric(data) || length(data)==0)
# stop("Data must be a numeric vector of non-zero length")
Expand Down
81 changes: 38 additions & 43 deletions man/robustGARCH-robGarch.Rd

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

0 comments on commit 1c08c52

Please sign in to comment.