R/RcppExports.R

Defines functions sigma_estim_lwnl_cpp sigma_estim_lwcc_cpp sigma_estim_lwone_cpp sigma_estim_lwident_cpp

Documented in sigma_estim_lwcc_cpp sigma_estim_lwident_cpp sigma_estim_lwnl_cpp sigma_estim_lwone_cpp

# Generated by using Rcpp::compileAttributes() -> do not edit by hand
# Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393

#' Ledoit-Wolf Linear Shrinkage Covariance Estimation I (CPP)
#'
#' Computes the Ledoit-Wolf linear shrinkage estimator of the covariance matrix towards the identity matrix.
#'
#' @param data an nxp data matrix.
#' @param shrink_int a double, indicating the shrinkage intensity. Default is the optimal shrinkage intensity as in \insertCite{ledoit2003identity;textual}{CovEstim}.
#' @param zeromean_log a logical, indicating whether the data matrix has zero means (TRUE) or not (FALSE). Default value is FALSE.
#' @return a list with the following entries
#'  \itemize{
#'  \item a pxp estimated covariance matrix.
#'  \item an estimation specific tuning parameter, here the shrinkage intensity.
#'  }
#'
#' @details The Ledoit-Wolf linear shrinkage estimator of the covariance matrix towards the identity matrix is calculated with the following formula:
#' \deqn{\hat{\Sigma}= s\Sigma_{T} + (1-s)\Sigma,}
#' where \eqn{\Sigma} is the sample covariance matrix, s is the user-supplied or optimal shrinkage intensity and \eqn{\Sigma_{T}} is a pxp identity matrix.
#' This covariance estimator assumes a zero correlation and variances of one as the underlying covariance structure of the data.
#' A corresponding MATLAB code for the estimator can be accessed under \url{https://www.econ.uzh.ch/en/people/faculty/wolf/publications.html}.
#'
#' @examples
#' data(sp200)
#' sp_rets <- sp200[,-1]
#' sigma_lwident <- sigma_estim_lwident_cpp(as.matrix(sp_rets))
#'
#' @importFrom Rcpp evalCpp
#' @useDynLib CovEstim
#' @importFrom Rdpack reprompt
#' @references
#'\insertAllCited
#'
#' @export sigma_estim_lwident_cpp
#'
sigma_estim_lwident_cpp <- function(data, shrink_int = -1, zeromean_log = FALSE) {
    .Call('_CovEstim_sigma_estim_lwident_cpp', PACKAGE = 'CovEstim', data, shrink_int, zeromean_log)
}

#' Ledoit-Wolf Linear Shrinkage Covariance Estimation II (CPP)
#'
#' Computes the Ledoit-Wolf linear shrinkage estimator of the covariance matrix towards the one-parameter matrix.
#'
#' @param data an nxp data matrix.
#' @param shrink_int a double, indicating the shrinkage intensity. Default is the optimal shrinkage intensity as in \insertCite{ledoit2004oneparam;textual}{CovEstim}.
#' @param zeromean_log a logical, indicating whether the data matrix has zero means (TRUE) or not (FALSE). Default value is FALSE.
#' @return a list with the following entries
#'  \itemize{
#'  \item a pxp estimated covariance matrix.
#'  \item an estimation specific tuning parameter, here the shrinkage intensity.
#'  }
#'
#' @details The Ledoit-Wolf linear shrinkage estimator of the covariance matrix towards the diagonal matrix of equal variances is calculated with the following formula:
#' \deqn{\hat{\Sigma}= s\Sigma_{T} + (1-s)\Sigma,}
#' where \eqn{\Sigma} is the sample covariance matrix, s is the user-supplied or optimal shrinkage intensity and
#' \eqn{\Sigma_{T}} is a diagonal matrix with the average sample variance \eqn{\bar{\sigma}^2} on the diagonal.
#' This covariance estimator assumes a zero correlation and equal variances as the underlying covariance structure of the data.
#' A corresponding MATLAB code for the estimator can be accessed under \url{https://www.econ.uzh.ch/en/people/faculty/wolf/publications.html}.
#'
#' @examples
#' data(sp200)
#' sp_rets <- sp200[,-1]
#' sigma_lwone <- sigma_estim_lwone_cpp(as.matrix(sp_rets))
#'
#' @importFrom Rcpp evalCpp
#' @useDynLib CovEstim
#' @importFrom Rdpack reprompt
#' @references
#'\insertAllCited
#'
#' @export sigma_estim_lwone_cpp
#'
sigma_estim_lwone_cpp <- function(data, shrink_int = -1, zeromean_log = FALSE) {
    .Call('_CovEstim_sigma_estim_lwone_cpp', PACKAGE = 'CovEstim', data, shrink_int, zeromean_log)
}

#' Ledoit-Wolf Linear Shrinkage Covariance Estimation III (CPP)
#'
#' Computes the Ledoit-Wolf linear shrinkage estimator of the covariance matrix towards the constant correlation covariance matrix.
#'
#' @param data an nxp data matrix.
#' @param shrink_int a double, indicating the shrinkage intensity. Default is the optimal shrinkage intensity as in \insertCite{ledoit2004cc;textual}{CovEstim}.
#' @param zeromean_log a logical, indicating whether the data matrix has zero means (TRUE) or not (FALSE). Default value is FALSE.
#' @return a list with the following entries
#'  \itemize{
#'  \item a pxp estimated covariance matrix.
#'  \item an estimation specific tuning parameter, here the shrinkage intensity.
#'  }
#'
#' @details The Ledoit-Wolf linear shrinkage estimator of the covariance matrix towards the constant correlation covariance matrix is calculated with the following formula:
#' \deqn{\hat{\Sigma}= s\Sigma_{T} + (1-s)\Sigma,}
#' where \eqn{\Sigma} is the sample covariance matrix, s is the user-supplied or optimal shrinkage intensity and
#' \eqn{\Sigma_{T}} is the constant correlation covariance matrix.
#' This covariance estimator assumes a constant correlation and individual variances as the underlying covariance structure of the data.
#' A corresponding MATLAB code for the estimator can be accessed under \url{https://www.econ.uzh.ch/en/people/faculty/wolf/publications.html}.
#'
#' @examples
#' data(sp200)
#' sp_rets <- sp200[,-1]
#' sigma_lwcc <- sigma_estim_lwcc_cpp(as.matrix(sp_rets))
#'
#' @importFrom Rcpp evalCpp
#' @useDynLib CovEstim
#' @importFrom Rdpack reprompt
#' @references
#'\insertAllCited
#'
#' @export sigma_estim_lwcc_cpp
#'
sigma_estim_lwcc_cpp <- function(data, shrink_int = -1, zeromean_log = FALSE) {
    .Call('_CovEstim_sigma_estim_lwcc_cpp', PACKAGE = 'CovEstim', data, shrink_int, zeromean_log)
}

#' Ledoit-Wolf Covariance Estimation (Nonlinear Shrinkage) (CPP)
#'
#' Computes the analytical Ledoit-Wolf nonlinear shrinkage estimator of the covariance matrix.
#'
#' @param data an nxp data matrix.
#' @param bandwidth_speed a double, indicating the speed at which the bandwidth vanishes in the number of variables p.
#' Default value is -1/3.
#' @param zeromean_log a logical, indicating whether the data matrix has zero means (TRUE) or not (FALSE). Default value is FALSE.
#' @return a list with the following entries
#'  \itemize{
#'  \item a pxp estimated covariance matrix.
#'  \item an estimation specific tuning parameter, here the bandwidth speed.
#'  }
#'
#' @details The Ledoit-Wolf nonlinear shrinkage estimator of the covariance matrix is computed according to \insertCite{ledoit2018analytical;textual}{CovEstim}
#' with the following formula:
#' \deqn{\hat{\Sigma}=\Delta\hat{\Lambda}\Delta',}
#' where \eqn{\Delta} is the matrix with the sample eigenvectors of the data matrix and \eqn{\hat{\Lambda}} is a diagonal matrix with the sample eigenvalues, shrunk in a nonlinear way.
#' The optimal solution is achieved using a nonparametric variable bandwidth kernel estimation of the limiting spectral density of the sample eigenvalues and its Hilbert transform.
#' The speed at which the bandwidth vanishes in the number of assets is set to -1/3.
#' A corresponding MATLAB code for the estimator can be accessed under \url{https://www.econ.uzh.ch/en/people/faculty/wolf/publications.html}.
#'
#' @examples
#' data(sp200)
#' sp_rets <- sp200[,-1]
#' sigma_lwnl <- sigma_estim_lwnl_cpp(as.matrix(sp_rets))
#'
#' @import Rcpp
#' @importFrom Rcpp evalCpp
#' @useDynLib CovEstim
#' @importFrom Rdpack reprompt
#' @references
#'\insertAllCited
#'
#' @export sigma_estim_lwnl_cpp
#'
sigma_estim_lwnl_cpp <- function(data, bandwidth_speed = -1, zeromean_log = FALSE) {
    .Call('_CovEstim_sigma_estim_lwnl_cpp', PACKAGE = 'CovEstim', data, bandwidth_speed, zeromean_log)
}
antshi/CovEstim documentation built on Nov. 13, 2020, 2:25 p.m.