[Uwgarp-commits] r131 - in pkg/GARPFRM: R demo man sandbox

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Mon Mar 24 06:11:14 CET 2014


Author: rossbennett34
Date: 2014-03-24 06:11:14 +0100 (Mon, 24 Mar 2014)
New Revision: 131

Added:
   pkg/GARPFRM/demo/bootstrap.R
Modified:
   pkg/GARPFRM/R/boot.R
   pkg/GARPFRM/demo/00Index.txt
   pkg/GARPFRM/man/bootCor.Rd
   pkg/GARPFRM/man/bootCov.Rd
   pkg/GARPFRM/man/bootES.Rd
   pkg/GARPFRM/man/bootFUN.Rd
   pkg/GARPFRM/man/bootMean.Rd
   pkg/GARPFRM/man/bootSD.Rd
   pkg/GARPFRM/man/bootSimpleVolatility.Rd
   pkg/GARPFRM/man/bootStdDev.Rd
   pkg/GARPFRM/man/bootVaR.Rd
   pkg/GARPFRM/sandbox/test_boot.R
Log:
Adding bootstrap demo. Adding examples to bootstrap man files. Adding standard error estimates for bootstrap functions

Modified: pkg/GARPFRM/R/boot.R
===================================================================
--- pkg/GARPFRM/R/boot.R	2014-03-23 17:38:40 UTC (rev 130)
+++ pkg/GARPFRM/R/boot.R	2014-03-24 05:11:14 UTC (rev 131)
@@ -6,7 +6,11 @@
 #' @details
 #' \code{R} is the data passed to \code{FUN}. \code{FUN} must have \code{x} or
 #' \code{R} as arguments for the data. For example, see the functions linked to
-#' in the 'See Also' section.
+#' in the 'See Also' section. Care must be taken when using \code{bootFUN} on
+#' multivariate data. This function is designed to only accept univariate 
+#' (i.e. ncol(R) = 1) data, however is made to work with bivariate data for
+#' \code{bootCor} and \code{bootCov}. For multivariate data, a wrapper function
+#' should be written to apply the bootstrap function to each column of data.
 #' 
 #' To run the bootstrap in parallael, this function uses the \code{foreach}
 #' pacakge. From the \code{\link[foreach]{foreach}} documentation, the 
@@ -85,7 +89,10 @@
     }
   }
   # compute the expected value of the statistic on resampled data
-  mean(out)
+  estimate <- mean(out)
+  # compute the standard error of the bootstrap estimate
+  std.err <- sd(out)
+  matrix(c(estimate, std.err), nrow=2, ncol=1, dimnames=list(c(FUN, "std.err")))
 }
 
 .bootMean <- function(R, ..., replications=1000, parallel=FALSE){
@@ -102,20 +109,28 @@
 #' @param replications number of bootstrap replications.
 #' @param parallel TRUE/FALSE (default FALSE) to compute the bootstrap in parallel. 
 #' @author Ross Bennett
+#' @examples
+#' data(crsp_weekly)
+#' R <- largecap_weekly[,1:4]
+#' bootMean(R[,1])
+#' bootMean(R)
 #' @export
 bootMean <- function(R, ..., replications=1000, parallel=FALSE){
   if(!is.matrix(R) | !is.xts(R)) stop("R must be an xts or matrix")
   
   if(ncol(R) == 1){
-    tmp <- .bootMean(R=R, ...=..., replications=replications, parallel=parallel)
+    out <- .bootMean(R=R, ...=..., replications=replications, parallel=parallel)
   } else {
-    tmp <- vector("numeric", ncol(R))
     for(i in 1:ncol(R)){
-      tmp[i] <- .bootMean(R=R[,i], ...=..., replications=replications, parallel=parallel)
+      if(i == 1){
+        out <- .bootMean(R=R[,i], ...=..., replications=replications, parallel=parallel)
+      } else {
+        out <- cbind(out, .bootMean(R=R[,i], ...=..., replications=replications, parallel=parallel))
+      }
     }
   }
-  out <- matrix(tmp, nrow=1, ncol=ncol(R))
-  rownames(out) <- "mean"
+  #out <- matrix(tmp, nrow=1, ncol=ncol(R))
+  rownames(out) <- c("mean", "std.err")
   colnames(out) <- colnames(R)
   return(out)
 }
@@ -134,20 +149,27 @@
 #' @param replications number of bootstrap replications.
 #' @param parallel TRUE/FALSE (default FALSE) to compute the bootstrap in parallel. 
 #' @author Ross Bennett
+#' @examples
+#' data(crsp_weekly)
+#' R <- largecap_weekly[,1:4]
+#' bootSD(R[,1])
+#' bootSD(R)
 #' @export
 bootSD <- function(R, ..., replications=1000, parallel=FALSE){
   if(!is.matrix(R) | !is.xts(R)) stop("R must be an xts or matrix")
   
   if(ncol(R) == 1){
-    tmp <- .bootSD(R=R, ...=..., replications=replications, parallel=parallel)
+    out <- .bootSD(R=R, ...=..., replications=replications, parallel=parallel)
   } else {
-    tmp <- vector("numeric", ncol(R))
     for(i in 1:ncol(R)){
-      tmp[i] <- .bootSD(R=R[,i], ...=..., replications=replications, parallel=parallel)
+      if(i == 1){
+        out <- .bootSD(R=R[,i], ...=..., replications=replications, parallel=parallel)
+      } else {
+        out <- cbind(out, .bootSD(R=R[,i], ...=..., replications=replications, parallel=parallel))
+      }
     }
   }
-  out <- matrix(tmp, nrow=1, ncol=ncol(R))
-  rownames(out) <- "sd"
+  rownames(out) <- c("sd", "std.err")
   colnames(out) <- colnames(R)
   return(out)
 }
@@ -166,20 +188,27 @@
 #' @param replications number of bootstrap replications.
 #' @param parallel TRUE/FALSE (default FALSE) to compute the bootstrap in parallel. 
 #' @author Ross Bennett
+#' @examples
+#' data(crsp_weekly)
+#' R <- largecap_weekly[,1:4]
+#' bootStdDev(R[,1])
+#' bootStdDev(R)
 #' @export
 bootStdDev <- function(R, ..., replications=1000, parallel=FALSE){
   if(!is.matrix(R) | !is.xts(R)) stop("R must be an xts or matrix")
   
   if(ncol(R) == 1){
-    tmp <- .bootStdDev(R=R, ...=..., replications=replications, parallel=parallel)
+    out <- .bootStdDev(R=R, ...=..., replications=replications, parallel=parallel)
   } else {
-    tmp <- vector("numeric", ncol(R))
     for(i in 1:ncol(R)){
-      tmp[i] <- .bootStdDev(R=R[,i], ...=..., replications=replications, parallel=parallel)
+      if(i == 1){
+        out <- .bootStdDev(R=R[,i], ...=..., replications=replications, parallel=parallel)
+      } else {
+        out <- cbind(out, .bootStdDev(R=R[,i], ...=..., replications=replications, parallel=parallel))
+      }
     }
   }
-  out <- matrix(tmp, nrow=1, ncol=ncol(R))
-  rownames(out) <- "StdDev"
+  rownames(out) <- c("StdDev", "std.err")
   colnames(out) <- colnames(R)
   return(out)
 }
@@ -198,27 +227,35 @@
 #' @param replications number of bootstrap replications.
 #' @param parallel TRUE/FALSE (default FALSE) to compute the bootstrap in parallel. 
 #' @author Ross Bennett
+#' @examples
+#' data(crsp_weekly)
+#' R <- largecap_weekly[,1:4]
+#' bootSimpleVolatility(R[,1])
+#' bootSimpleVolatility(R)
 #' @export
 bootSimpleVolatility <- function(R, ..., replications=1000, parallel=FALSE){
   if(!is.matrix(R) | !is.xts(R)) stop("R must be an xts or matrix")
   
   if(ncol(R) == 1){
-    tmp <- .bootSimpleVolatility(R=R, ...=..., replications=replications, parallel=parallel)
+    out <- .bootSimpleVolatility(R=R, ...=..., replications=replications, parallel=parallel)
   } else {
     tmp <- vector("numeric", ncol(R))
     for(i in 1:ncol(R)){
-      tmp[i] <- .bootSimpleVolatility(R=R[,i], ...=..., replications=replications, parallel=parallel)
+      if(i == 1){
+        out <- .bootSimpleVolatility(R=R[,i], ...=..., replications=replications, parallel=parallel)
+      } else {
+        out <- cbind(out, .bootSimpleVolatility(R=R[,i], ...=..., replications=replications, parallel=parallel))
+      }
     }
   }
-  out <- matrix(tmp, nrow=1, ncol=ncol(R))
-  rownames(out) <- "SimpleVolatility"
+  rownames(out) <- c("SimpleVolatility", "std.err")
   colnames(out) <- colnames(R)
   return(out)
 }
 
 tmpCor <- function(R, ...){
   # R should be a bivariate xts object
-  cor(x=R[,1], y=R[,2], ...=...)
+  cor(x=R[,1], y=R[,2], ...)
 }
 
 .bootCor <- function(R, ..., replications=1000, parallel=FALSE){
@@ -235,6 +272,12 @@
 #' @param replications number of bootstrap replications.
 #' @param parallel TRUE/FALSE (default FALSE) to compute the bootstrap in parallel. 
 #' @author Ross Bennett
+#' @examples
+#' data(crsp_weekly)
+#' R <- largecap_weekly[,1:4]
+#' bootCor(R[,1:2])
+#' bootCor(R[,1:2], method="kendall")
+#' bootCor(R)
 #' @export
 bootCor <- function(R, ..., replications=1000, parallel=FALSE){
   if(!is.matrix(R) | !is.xts(R)) stop("R must be an xts or matrix")
@@ -242,32 +285,33 @@
   if(ncol(R) < 2) stop("R must have 2 or more columns of asset returns")
   cnames <- colnames(R)
   if(ncol(R) == 2){
-    tmp <- .bootCor(R=R, ...=..., replications=replications, parallel=parallel)
+    out <- .bootCor(R=R, ...=..., replications=replications, parallel=parallel)
     out_names <- paste(cnames[1], cnames[2], sep=".")
     num_col <- 1
   } else {
-    tmp <- vector("numeric", choose(ncol(R), 2))
-    out_names <- vector("numeric", length(tmp))
-    num_col <- length(tmp)
+    out_names <- vector("numeric", choose(ncol(R), 2))
+    num_col <- length(out_names)
     k <- 1
     for(i in 1:(ncol(R)-1)){
       for(j in (i+1):ncol(R)){
-        tmp[k] <- .bootCor(R=cbind(R[,i], R[,j]), ...=..., replications=replications, parallel=parallel)
+        if(k == 1){
+          out <- .bootCor(R=cbind(R[,i], R[,j]), ...=..., replications=replications, parallel=parallel)
+        } else {
+          out <- cbind(out, .bootCor(R=cbind(R[,i], R[,j]), ...=..., replications=replications, parallel=parallel))
+        }
         out_names[k] <- paste(cnames[i], cnames[j], sep=".")
         k <- k + 1
       }
     }
   }
-  # out <- matrix(tmp, nrow=1, ncol=ncol(R))
-  out <- matrix(tmp, nrow=1, ncol=num_col)
-  rownames(out) <- "cor"
+  rownames(out) <- c("cor", "std.err")
   colnames(out) <- out_names
   return(out)
 }
 
 tmpCov <- function(R, ...){
   # R should be a bivariate xts object
-  cov(x=R[,1], y=R[,2], ...=...)
+  cov(x=R[,1], y=R[,2], ...)
 }
 
 .bootCov <- function(R, ..., replications=1000, parallel=FALSE){
@@ -284,31 +328,37 @@
 #' @param replications number of bootstrap replications.
 #' @param parallel TRUE/FALSE (default FALSE) to compute the bootstrap in parallel. 
 #' @author Ross Bennett
+#' @examples
+#' data(crsp_weekly)
+#' R <- largecap_weekly[,1:4]
+#' bootCov(R[,1:2])
+#' bootCov(R)
 #' @export
 bootCov <- function(R, ..., replications=1000, parallel=FALSE){
   if(!is.matrix(R) | !is.xts(R)) stop("R must be an xts or matrix")
   
   cnames <- colnames(R)
   if(ncol(R) == 2){
-    tmp <- .bootCov(R=R, ...=..., replications=replications, parallel=parallel)
+    out <- .bootCov(R=R, ...=..., replications=replications, parallel=parallel)
     out_names <- paste(cnames[1], cnames[2], sep=".")
     num_col <- 1
   } else {
-    tmp <- vector("numeric", choose(ncol(R), 2))
-    out_names <- vector("numeric", length(tmp))
-    num_col <- length(tmp)
+    out_names <- vector("numeric", choose(ncol(R), 2))
+    num_col <- length(out_names)
     k <- 1
     for(i in 1:(ncol(R)-1)){
       for(j in (i+1):ncol(R)){
-        tmp[k] <- .bootCov(R=cbind(R[,i], R[,j]), ...=..., replications=replications, parallel=parallel)
+        if(k == 1){
+          out <- .bootCov(R=cbind(R[,i], R[,j]), ...=..., replications=replications, parallel=parallel)
+        } else {
+          out <- cbind(out, .bootCov(R=cbind(R[,i], R[,j]), ...=..., replications=replications, parallel=parallel))
+        }
         out_names[k] <- paste(cnames[i], cnames[j], sep=".")
         k <- k + 1
       }
     }
   }
-  # out <- matrix(tmp, nrow=1, ncol=ncol(R))
-  out <- matrix(tmp, nrow=1, ncol=num_col)
-  rownames(out) <- "cov"
+  rownames(out) <- c("cov", "std.err")
   colnames(out) <- out_names
   return(out)
 }
@@ -327,20 +377,28 @@
 #' @param replications number of bootstrap replications.
 #' @param parallel TRUE/FALSE (default FALSE) to compute the bootstrap in parallel. 
 #' @author Ross Bennett
+#' @examples
+#' data(crsp_weekly)
+#' R <- largecap_weekly[,1:4]
+#' bootVaR(R[,1], p=0.9, method="historical")
+#' bootVaR(R[,1], p=0.9, method="gaussian")
+#' bootVaR(R, p=0.9, method="historical", invert=FALSE)
 #' @export
 bootVaR <- function(R, ..., replications=1000, parallel=FALSE){
   if(!is.matrix(R) | !is.xts(R)) stop("R must be an xts or matrix")
   
   if(ncol(R) == 1){
-    tmp <- .bootVaR(R=R, ...=..., replications=replications, parallel=parallel)
+    out <- .bootVaR(R=R, ...=..., replications=replications, parallel=parallel)
   } else {
-    tmp <- vector("numeric", ncol(R))
     for(i in 1:ncol(R)){
-      tmp[i] <- .bootVaR(R=R[,i], ...=..., replications=replications, parallel=parallel)
+      if(i == 1){
+        out <- .bootVaR(R=R[,i], ...=..., replications=replications, parallel=parallel)
+      } else {
+        out <- cbind(out, .bootVaR(R=R[,i], ...=..., replications=replications, parallel=parallel))
+      }
     }
   }
-  out <- matrix(tmp, nrow=1, ncol=ncol(R))
-  rownames(out) <- "VaR"
+  rownames(out) <- c("VaR", "std.err")
   colnames(out) <- colnames(R)
   return(out)
 }
@@ -359,20 +417,28 @@
 #' @param replications number of bootstrap replications.
 #' @param parallel TRUE/FALSE (default FALSE) to compute the bootstrap in parallel. 
 #' @author Ross Bennett
+#' @examples
+#' data(crsp_weekly)
+#' R <- largecap_weekly[,1:4]
+#' bootVaR(R[,1], p=0.9, method="historical")
+#' bootVaR(R[,1], p=0.9, method="gaussian")
+#' bootVaR(R, p=0.9, method="historical", invert=FALSE)
 #' @export
 bootES <- function(R, ..., replications=1000, parallel=FALSE){
   if(!is.matrix(R) | !is.xts(R)) stop("R must be an xts or matrix")
   
   if(ncol(R) == 1){
-    tmp <- .bootES(R=R, ...=..., replications=replications, parallel=parallel)
+    out <- .bootES(R=R, ...=..., replications=replications, parallel=parallel)
   } else {
-    tmp <- vector("numeric", ncol(R))
     for(i in 1:ncol(R)){
-      tmp[i] <- .bootES(R=R[,i], ...=..., replications=replications, parallel=parallel)
+      if(i == 1){
+        out <- .bootES(R=R[,i], ...=..., replications=replications, parallel=parallel)
+      } else {
+        out <- cbind(out, .bootES(R=R[,i], ...=..., replications=replications, parallel=parallel))
+      }
     }
   }
-  out <- matrix(tmp, nrow=1, ncol=ncol(R))
-  rownames(out) <- "ES"
+  rownames(out) <- c("ES", "std.err")
   colnames(out) <- colnames(R)
   return(out)
 }

Modified: pkg/GARPFRM/demo/00Index.txt
===================================================================
--- pkg/GARPFRM/demo/00Index.txt	2014-03-23 17:38:40 UTC (rev 130)
+++ pkg/GARPFRM/demo/00Index.txt	2014-03-24 05:11:14 UTC (rev 131)
@@ -0,0 +1,6 @@
+bootstrap.R demonstrates using bootstrap method to estimate various statistics
+demo_CAPM.R demonstrate Capital Asset Pricing Model functions
+demo_EWMA_GARCH11.R demonstrate exponentially weighted moving average and GARCH models
+EWMA.R demonstrate exponentially weighted moving average model
+monte_carlo.R demonstrate monte carlo method to simulate asset price paths
+univariate_GARCH.R demonstrate fitting a GARCH model to a univariate data set
\ No newline at end of file

Added: pkg/GARPFRM/demo/bootstrap.R
===================================================================
--- pkg/GARPFRM/demo/bootstrap.R	                        (rev 0)
+++ pkg/GARPFRM/demo/bootstrap.R	2014-03-24 05:11:14 UTC (rev 131)
@@ -0,0 +1,53 @@
+# bootstrap
+library(GARPFRM)
+data(crsp_weekly)
+R <- largecap_weekly[,1:4]
+
+# function to calculate the annualized return using the most recent n periods
+foo <- function(R, n){
+  Return.annualized(tail(R, n), geometric=TRUE)
+}
+
+bootFUN(R[,1], FUN="foo", n=104, replications=100)
+
+# Bootstrap various statistics
+
+# Bootstrap mean estimate.
+bootMean(R[,1])
+bootMean(R)
+
+# Bootstrap standard deviation estimate.
+bootSD(R[,1])
+bootSD(R)
+
+# Bootstrap standard deviation estimate using the StdDev function from
+# PerformanceAnalytics.
+bootStdDev(R[,1])
+bootStdDev(R)
+
+# Bootstrap simpleVolatility estimate.
+bootSimpleVolatility(R[,1])
+bootSimpleVolatility(R)
+
+# Bootstrap correlation estimate.
+bootCor(R[,1:2])
+bootCor(R[,1:2], method="kendall")
+bootCor(R)
+
+# Bootstrap covariance estimate.
+bootCov(R[,1:2])
+bootCov(R)
+
+# Bootstrap Value-at-Risk (VaR) estimate using the VaR function from
+# PerformanceAnalytics.
+bootVaR(R[,1], p=0.9, method="historical")
+bootVaR(R[,1], p=0.9, method="gaussian")
+bootVaR(R, p=0.9, method="historical", invert=FALSE)
+
+# Bootstrap Expected Shortfall (ES) estimate using the ES function from
+# PerformanceAnalytics. Also known as Conditional Value-at-Risk (CVaR) and 
+# Expected Tail Loss (ETL).
+bootES(R[,1], p=0.9, method="gaussian")
+bootES(R[,1], p=0.92, method="historical", invert=FALSE)
+bootES(R, p=0.9, method="historical")
+

Modified: pkg/GARPFRM/man/bootCor.Rd
===================================================================
--- pkg/GARPFRM/man/bootCor.Rd	2014-03-23 17:38:40 UTC (rev 130)
+++ pkg/GARPFRM/man/bootCor.Rd	2014-03-24 05:11:14 UTC (rev 131)
@@ -16,9 +16,16 @@
   bootstrap in parallel.}
 }
 \description{
-  Bootstrap the correlation of an xts object of asset
-  returns
+  Bootstrap the correlation of an xts object or matrix of
+  asset returns
 }
+\examples{
+data(crsp_weekly)
+R <- largecap_weekly[,1:4]
+bootCor(R[,1:2])
+bootCor(R[,1:2], method="kendall")
+bootCor(R)
+}
 \author{
   Ross Bennett
 }

Modified: pkg/GARPFRM/man/bootCov.Rd
===================================================================
--- pkg/GARPFRM/man/bootCov.Rd	2014-03-23 17:38:40 UTC (rev 130)
+++ pkg/GARPFRM/man/bootCov.Rd	2014-03-24 05:11:14 UTC (rev 131)
@@ -16,9 +16,15 @@
   bootstrap in parallel.}
 }
 \description{
-  Bootstrap the covariance of an xts object of asset
-  returns
+  Bootstrap the covariance of an xts object or matrix of
+  asset returns
 }
+\examples{
+data(crsp_weekly)
+R <- largecap_weekly[,1:4]
+bootCov(R[,1:2])
+bootCov(R)
+}
 \author{
   Ross Bennett
 }

Modified: pkg/GARPFRM/man/bootES.Rd
===================================================================
--- pkg/GARPFRM/man/bootES.Rd	2014-03-23 17:38:40 UTC (rev 130)
+++ pkg/GARPFRM/man/bootES.Rd	2014-03-24 05:11:14 UTC (rev 131)
@@ -16,9 +16,16 @@
   bootstrap in parallel.}
 }
 \description{
-  Bootstrap the Expected Shortfall (ES) of an xts object of
-  asset returns
+  Bootstrap the Expected Shortfall (ES) of an xts object or
+  matrix of asset returns
 }
+\examples{
+data(crsp_weekly)
+R <- largecap_weekly[,1:4]
+bootVaR(R[,1], p=0.9, method="historical")
+bootVaR(R[,1], p=0.9, method="gaussian")
+bootVaR(R, p=0.9, method="historical", invert=FALSE)
+}
 \author{
   Ross Bennett
 }

Modified: pkg/GARPFRM/man/bootFUN.Rd
===================================================================
--- pkg/GARPFRM/man/bootFUN.Rd	2014-03-23 17:38:40 UTC (rev 130)
+++ pkg/GARPFRM/man/bootFUN.Rd	2014-03-24 05:11:14 UTC (rev 131)
@@ -25,7 +25,13 @@
   \code{R} is the data passed to \code{FUN}. \code{FUN}
   must have \code{x} or \code{R} as arguments for the data.
   For example, see the functions linked to in the 'See
-  Also' section.
+  Also' section. Care must be taken when using
+  \code{bootFUN} on multivariate data. This function is
+  designed to only accept univariate (i.e. ncol(R) = 1)
+  data, however is made to work with bivariate data for
+  \code{bootCor} and \code{bootCov}. For multivariate data,
+  a wrapper function should be written to apply the
+  bootstrap function to each column of data.
 
   To run the bootstrap in parallael, this function uses the
   \code{foreach} pacakge. From the

Modified: pkg/GARPFRM/man/bootMean.Rd
===================================================================
--- pkg/GARPFRM/man/bootMean.Rd	2014-03-23 17:38:40 UTC (rev 130)
+++ pkg/GARPFRM/man/bootMean.Rd	2014-03-24 05:11:14 UTC (rev 131)
@@ -16,8 +16,15 @@
   bootstrap in parallel.}
 }
 \description{
-  Bootstrap the mean of an xts object of asset returns
+  Bootstrap the mean of an xts object or matrix of asset
+  returns
 }
+\examples{
+data(crsp_weekly)
+R <- largecap_weekly[,1:4]
+bootMean(R[,1])
+bootMean(R)
+}
 \author{
   Ross Bennett
 }

Modified: pkg/GARPFRM/man/bootSD.Rd
===================================================================
--- pkg/GARPFRM/man/bootSD.Rd	2014-03-23 17:38:40 UTC (rev 130)
+++ pkg/GARPFRM/man/bootSD.Rd	2014-03-24 05:11:14 UTC (rev 131)
@@ -16,9 +16,15 @@
   bootstrap in parallel.}
 }
 \description{
-  Bootstrap the standard deviation of an xts object of
-  asset returns
+  Bootstrap the standard deviation of an xts object or
+  matrix of asset returns
 }
+\examples{
+data(crsp_weekly)
+R <- largecap_weekly[,1:4]
+bootSD(R[,1])
+bootSD(R)
+}
 \author{
   Ross Bennett
 }

Modified: pkg/GARPFRM/man/bootSimpleVolatility.Rd
===================================================================
--- pkg/GARPFRM/man/bootSimpleVolatility.Rd	2014-03-23 17:38:40 UTC (rev 130)
+++ pkg/GARPFRM/man/bootSimpleVolatility.Rd	2014-03-24 05:11:14 UTC (rev 131)
@@ -20,6 +20,12 @@
   Bootstrap the simple volatility of an xts object or
   matrix of asset returns
 }
+\examples{
+data(crsp_weekly)
+R <- largecap_weekly[,1:4]
+bootSimpleVolatility(R[,1])
+bootSimpleVolatility(R)
+}
 \author{
   Ross Bennett
 }

Modified: pkg/GARPFRM/man/bootStdDev.Rd
===================================================================
--- pkg/GARPFRM/man/bootStdDev.Rd	2014-03-23 17:38:40 UTC (rev 130)
+++ pkg/GARPFRM/man/bootStdDev.Rd	2014-03-24 05:11:14 UTC (rev 131)
@@ -16,8 +16,15 @@
   bootstrap in parallel.}
 }
 \description{
-  Bootstrap the StdDev of an xts object of asset returns
+  Bootstrap the StdDev of an xts object or matrix of asset
+  returns
 }
+\examples{
+data(crsp_weekly)
+R <- largecap_weekly[,1:4]
+bootStdDev(R[,1])
+bootStdDev(R)
+}
 \author{
   Ross Bennett
 }

Modified: pkg/GARPFRM/man/bootVaR.Rd
===================================================================
--- pkg/GARPFRM/man/bootVaR.Rd	2014-03-23 17:38:40 UTC (rev 130)
+++ pkg/GARPFRM/man/bootVaR.Rd	2014-03-24 05:11:14 UTC (rev 131)
@@ -16,9 +16,16 @@
   bootstrap in parallel.}
 }
 \description{
-  Bootstrap the Value at Risk (VaR) of an xts object of
-  asset returns
+  Bootstrap the Value at Risk (VaR) of an xts object or
+  matrix of asset returns
 }
+\examples{
+data(crsp_weekly)
+R <- largecap_weekly[,1:4]
+bootVaR(R[,1], p=0.9, method="historical")
+bootVaR(R[,1], p=0.9, method="gaussian")
+bootVaR(R, p=0.9, method="historical", invert=FALSE)
+}
 \author{
   Ross Bennett
 }

Modified: pkg/GARPFRM/sandbox/test_boot.R
===================================================================
--- pkg/GARPFRM/sandbox/test_boot.R	2014-03-23 17:38:40 UTC (rev 130)
+++ pkg/GARPFRM/sandbox/test_boot.R	2014-03-24 05:11:14 UTC (rev 131)
@@ -1,54 +1,60 @@
 # bootstrap
-
+library(GARPFRM)
 data(crsp_weekly)
 R <- largecap_weekly[,1:4]
-R1 <- R[1:100,1]
 
 set.seed(123)
-bootFUN(R1, FUN="mean", replications=10000, parallel=FALSE)
+bootFUN(R[,1], FUN="mean", replications=500, parallel=FALSE)
+
+# library(doMC)
+# registerDoMC(2)
 set.seed(123)
-bootFUN(R1, FUN="mean", replications=10000, parallel=TRUE)
+bootFUN(R[,1], FUN="mean", replications=500, parallel=TRUE)
 
-# arbitrary function 
+# function to calculate the annualized return using the most recent n periods
 foo <- function(R, n){
-  R <- tail(R, n)
-  Return.annualized(R, geometric=TRUE)
+  Return.annualized(tail(R, n), geometric=TRUE)
 }
 
-bootFUN(R1, FUN="foo", n=100, replications=100)
+bootFUN(R[,1], FUN="foo", n=104, replications=100)
 
-# bootstrap various statistics
-# mean
+# Bootstrap various statistics
+
+# Bootstrap mean estimate.
 bootMean(R[,1])
 bootMean(R)
 
-# sd
+# Bootstrap standard deviation estimate.
 bootSD(R[,1])
 bootSD(R)
 
-# StdDev
+# Bootstrap standard deviation estimate using the StdDev function from
+# PerformanceAnalytics.
 bootStdDev(R[,1])
 bootStdDev(R)
 
-# simpleVolatility
+# Bootstrap simpleVolatility estimate.
 bootSimpleVolatility(R[,1])
 bootSimpleVolatility(R)
 
-# cor
+# Bootstrap correlation estimate.
 bootCor(R[,1:2])
 bootCor(R[,1:2], method="kendall")
 bootCor(R)
 
-# cov
+# Bootstrap covariance estimate.
 bootCov(R[,1:2])
 bootCov(R)
 
-# VaR
+# Bootstrap Value-at-Risk (VaR) estimate using the VaR function from
+# PerformanceAnalytics.
 bootVaR(R[,1], p=0.9, method="historical")
 bootVaR(R[,1], p=0.9, method="gaussian")
 bootVaR(R, p=0.9, method="historical", invert=FALSE)
 
-# ES
+# Bootstrap Expected Shortfall (ES) estimate using the ES function from
+# PerformanceAnalytics. Also known as Conditional Value-at-Risk (CVaR) and 
+# Expected Tail Loss (ETL).
 bootES(R[,1], p=0.9, method="gaussian")
 bootES(R[,1], p=0.92, method="historical", invert=FALSE)
 bootES(R, p=0.9, method="historical")



More information about the Uwgarp-commits mailing list