[Returnanalytics-commits] r3990 - pkg/Dowd/R

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Mon Aug 31 23:50:25 CEST 2015


Author: dacharya
Date: 2015-08-31 23:50:24 +0200 (Mon, 31 Aug 2015)
New Revision: 3990

Modified:
   pkg/Dowd/R/CdfOfSumUsingGaussianCopula.R
   pkg/Dowd/R/CdfOfSumUsingGumbelCopula.R
   pkg/Dowd/R/GaussianCopulaVaR.R
   pkg/Dowd/R/GumbelCopulaVaR.R
Log:
Functions modified to reduce run time.

Modified: pkg/Dowd/R/CdfOfSumUsingGaussianCopula.R
===================================================================
--- pkg/Dowd/R/CdfOfSumUsingGaussianCopula.R	2015-08-31 21:46:47 UTC (rev 3989)
+++ pkg/Dowd/R/CdfOfSumUsingGaussianCopula.R	2015-08-31 21:50:24 UTC (rev 3990)
@@ -1,4 +1,4 @@
-#' Derives prob ( X + Y < quantile) using Gumbel copula
+#' Derives prob ( X + Y < quantile) using Gaussian copula
 #' 
 #' If X and Y are position P/Ls, then the VaR is equal to minus quantile. In
 #' such cases, we insert the negative of the VaR as the quantile, and the
@@ -30,9 +30,9 @@
 CdfOfSumUsingGaussianCopula <- function(quantile, mu1, mu2, sigma1, sigma2, rho, number.steps.in.copula){
   
   # Define w variable
-  w.min <- 0.001
-  w.max <- 0.999 # Specify min and max of w
-  dw <- 0.001 # Specify incremental change in w
+  w.min <- 0.01
+  w.max <- 0.99 # Specify min and max of w
+  dw <- 0.01 # Specify incremental change in w
   w <- seq(w.min, w.max, dw) # Define w-variable going from min to max in units of size dw
   
   # Obtain 'first' and 'second' sets of copula values corresponding to 

Modified: pkg/Dowd/R/CdfOfSumUsingGumbelCopula.R
===================================================================
--- pkg/Dowd/R/CdfOfSumUsingGumbelCopula.R	2015-08-31 21:46:47 UTC (rev 3989)
+++ pkg/Dowd/R/CdfOfSumUsingGumbelCopula.R	2015-08-31 21:50:24 UTC (rev 3990)
@@ -35,7 +35,8 @@
   # Define w variable
   w.min <- 0.001
   w.max <- 0.999 # Specify min and max of w
-  dw <- 0.001 # Specify incremental change in w
+  dw <- 0.001 # Specify incremental change in w. Note that this is different than in Dowd's
+  # original code (dw=0.001). It was necessary to reduce run time for examples.
   w <- seq(w.min, w.max, dw) # Define w-variable going from min to max in units of size dw
   
   # Obtain 'first' and 'second' sets of copula values corresponding to 

Modified: pkg/Dowd/R/GaussianCopulaVaR.R
===================================================================
--- pkg/Dowd/R/GaussianCopulaVaR.R	2015-08-31 21:46:47 UTC (rev 3989)
+++ pkg/Dowd/R/GaussianCopulaVaR.R	2015-08-31 21:50:24 UTC (rev 3990)
@@ -20,7 +20,7 @@
 #' @author Dinesh Acharya
 #' @examples
 #' 
-#'    # VaR using bivariate Gumbel for X and Y with given parameters:
+#'    # VaR using bivariate Gaussian for X and Y with given parameters:
 #'    GaussianCopulaVaR(2.3, 4.1, 1.2, 1.5, .6, 10, .95)
 #'
 #' @export
@@ -50,7 +50,7 @@
   }
   
   # Bisection Algorithm
-  tol <- 0.0001 # Tolerance level (NM: change manually if desired)
+  tol <- 0.001 # Tolerance level (NM: change manually if desired)
   while (U - L > tol){
     x <- (L + U) / 2 # Bisection carried out in terms of P/L quantiles or minus VaR
     cum.prob <- CdfOfSumUsingGaussianCopula(x, mu1, mu2, sigma1, sigma2, rho, 

Modified: pkg/Dowd/R/GumbelCopulaVaR.R
===================================================================
--- pkg/Dowd/R/GumbelCopulaVaR.R	2015-08-31 21:46:47 UTC (rev 3989)
+++ pkg/Dowd/R/GumbelCopulaVaR.R	2015-08-31 21:50:24 UTC (rev 3990)
@@ -20,7 +20,7 @@
 #' @examples
 #' 
 #'    # VaR using bivariate Gumbel for X and Y with given parameters:
-#'    GumbelCopulaVaR(2.3, 4.1, 1.2, 1.5, 1.2, .95)
+#'    GumbelCopulaVaR(1.1, 3.1, 1.2, 1.5, 1.1, .95)
 #'
 #' @export
 GumbelCopulaVaR <- function(mu1, mu2, sigma1, sigma2, beta, cl){
@@ -50,7 +50,9 @@
   }
   
   # Bisection Algorithm
-  tol <- 0.0001 # Tolerance level (NM: change manually if desired)
+  # The tolerance level in Dowd's original code was 0.0001. It was changed for test case
+  # to take less time.
+  tol <- 0.001 # Tolerance level (NM: change manually if desired)
   while (U - L > tol){
     x <- (L + U) / 2 # Bisection carried out in terms of P/L quantiles or minus VaR
     cum.prob <- CdfOfSumUsingGumbelCopula(x, mu1, mu2, sigma1, sigma2, beta)
@@ -64,5 +66,5 @@
     }
   }
   y <- -x # VaR is negative of terminal x-value or P/L quantile
-  
+  return(y)
 }
\ No newline at end of file



More information about the Returnanalytics-commits mailing list