Nothing
#' Compute Bandwidth Parameter Using Silverman's Rule of Thumb
#'
#' This function calculates the bandwidth parameter for kernel functions using Silverman's rule of thumb,
#' which is commonly used in kernel density estimation to determine an appropriate bandwidth. The procedure is available either as a
#' stand-alone function or as a method in the `TVMVP` R6 class.
#'
#' @param returns A numeric matrix of asset returns with \eqn{T} rows (time periods) and \eqn{p} columns (assets).
#'
#' @return A numeric value representing the computed bandwidth parameter based on Silverman's rule.
#'
#' @details
#' Silverman's rule of thumb for bandwidth selection is given by:
#' \deqn{bandwidth = \frac{2.35}{\sqrt{12}} \times T^{-0.2} \times p^{-0.1}}
#' where \eqn{T} is the number of time periods and \eqn{p} is the number of assets.
#'
#' Two usage styles:
#'
#' \preformatted{
#' # Function interface
#' bw <- silverman(returns)
#'
#' # R6 method interface
#' tv <- TVMVP$new()
#' tv$set_data(returns)
#' tv$silverman()
#' }
#'
#' @examples
#' # Simulate data for 50 assets over 200 time periods
#' set.seed(123)
#' T <- 200
#' p <- 50
#' returns <- matrix(rnorm(T * p, mean = 0.001, sd = 0.02), ncol = p)
#'
#' # Compute bandwidth using Silverman's rule of thumb
#' bw <- silverman(returns)
#' print(bw)
#'
#' tv <- TVMVP$new()
#' tv$set_data(returns)
#' tv$silverman()
#'
#' @export
silverman <- function(returns){
ip <- ncol(returns)
iT <- nrow(returns)
bandwidth <- (2.35/sqrt(12)) * iT^(-0.2) * ip^(-0.1)
return(bandwidth)
}
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.