[Returnanalytics-commits] r3850 - in pkg/Dowd: R man

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Fri Jul 24 21:01:13 CEST 2015


Author: dacharya
Date: 2015-07-24 21:01:12 +0200 (Fri, 24 Jul 2015)
New Revision: 3850

Modified:
   pkg/Dowd/R/KernelESBoxKernel.R
   pkg/Dowd/R/KernelESEpanechinikovKernel.R
   pkg/Dowd/R/KernelESNormalKernel.R
   pkg/Dowd/R/KernelESTriangleKernel.R
   pkg/Dowd/R/KernelVaRBoxKernel.R
   pkg/Dowd/R/KernelVaREpanechinikovKernel.R
   pkg/Dowd/R/KernelVaRNormalKernel.R
   pkg/Dowd/R/KernelVaRTriangleKernel.R
   pkg/Dowd/man/GaussianCopulaVaR.Rd
   pkg/Dowd/man/KernelESEpanechinikovKernel.Rd
   pkg/Dowd/man/KernelVaRBoxKernel.Rd
   pkg/Dowd/man/KernelVaREpanechinikovKernel.Rd
   pkg/Dowd/man/KernelVaRNormalKernel.Rd
   pkg/Dowd/man/KernelVaRTriangleKernel.Rd
Log:
An additional conditional variable was introduced to avoid multiple plot while using KernelES* function.

Modified: pkg/Dowd/R/KernelESBoxKernel.R
===================================================================
--- pkg/Dowd/R/KernelESBoxKernel.R	2015-07-24 06:38:57 UTC (rev 3849)
+++ pkg/Dowd/R/KernelESBoxKernel.R	2015-07-24 19:01:12 UTC (rev 3850)
@@ -21,8 +21,13 @@
   delta.cl <- (1 - cl) / n
   VaR <- double(999)
   for (i in 1:(n - 1)) {
-    VaR[i] <- KernelVaRBoxKernel(PandL, cl + i * delta.cl)
+    if(i<(n-1)){
+      VaR[i] <- KernelVaRBoxKernel(PandL, cl + i * delta.cl, FALSE)
+    } else if (i == n-1) {
+      VaR[i] <- KernelVaRBoxKernel(PandL, cl + i * delta.cl, TRUE)
+    }
   }
+  
   ES <- mean(VaR)
   return(ES)
   

Modified: pkg/Dowd/R/KernelESEpanechinikovKernel.R
===================================================================
--- pkg/Dowd/R/KernelESEpanechinikovKernel.R	2015-07-24 06:38:57 UTC (rev 3849)
+++ pkg/Dowd/R/KernelESEpanechinikovKernel.R	2015-07-24 19:01:12 UTC (rev 3850)
@@ -4,6 +4,7 @@
 #' 
 #' @param Ra Profit and Loss data set
 #' @param cl ES confidence level
+#' @param plot Bool, plots cdf if true
 #' @return Scalar ES
 #' @references Dowd, K. Measuring Market Risk, Wiley, 2007.
 #'
@@ -15,13 +16,17 @@
 #'    KernelESEpanechinikovKernel(Ra, .95)
 #'
 #' @export
-KernelESEpanechinikovKernel <- function(Ra, cl){
+KernelESEpanechinikovKernel <- function(Ra, cl, plot = TRUE){
   PandL <- as.vector(Ra)
-  n <- 1000
+  n <- 200
   delta.cl <- (1 - cl) / n
-  VaR <- double(999)
+  VaR <- double(199)
   for (i in 1:(n - 1)) {
-    VaR[i] <- KernelVaREpanechinikovKernel(PandL, cl + i * delta.cl)
+    if(i<(n-1)){
+      VaR[i] <- KernelVaREpanechinikovKernel(PandL, cl + i * delta.cl, FALSE)
+    } else if (i == n-1) {
+      VaR[i] <- KernelVaREpanechinikovKernel(PandL, cl + i * delta.cl, TRUE)
+    }
   }
   ES <- mean(VaR)
   return(ES)

Modified: pkg/Dowd/R/KernelESNormalKernel.R
===================================================================
--- pkg/Dowd/R/KernelESNormalKernel.R	2015-07-24 06:38:57 UTC (rev 3849)
+++ pkg/Dowd/R/KernelESNormalKernel.R	2015-07-24 19:01:12 UTC (rev 3850)
@@ -21,7 +21,11 @@
   delta.cl <- (1 - cl) / n
   VaR <- double(999)
   for (i in 1:(n - 1)) {
-    VaR[i] <- KernelVaRNormalKernel(PandL, cl + i * delta.cl)
+    if(i<(n-1)){
+      VaR[i] <- KernelVaRNormalKernel(PandL, cl + i * delta.cl, FALSE)
+    } else if (i == n-1) {
+      VaR[i] <- KernelVaRNormalKernel(PandL, cl + i * delta.cl, TRUE)
+    }
   }
   ES <- mean(VaR)
   return(ES)

Modified: pkg/Dowd/R/KernelESTriangleKernel.R
===================================================================
--- pkg/Dowd/R/KernelESTriangleKernel.R	2015-07-24 06:38:57 UTC (rev 3849)
+++ pkg/Dowd/R/KernelESTriangleKernel.R	2015-07-24 19:01:12 UTC (rev 3850)
@@ -21,7 +21,11 @@
   delta.cl <- (1 - cl) / n
   VaR <- double(999)
   for (i in 1:(n - 1)) {
-    VaR[i] <- KernelVaRTriangleKernel(PandL, cl + i * delta.cl)
+    if(i<(n-1)){
+      VaR[i] <- KernelVaRTriangleKernel(PandL, cl + i * delta.cl, FALSE)
+    } else if (i == n-1) {
+      VaR[i] <- KernelVaRTriangleKernel(PandL, cl + i * delta.cl, TRUE)
+    }
   }
   ES <- mean(VaR)
   return(ES)

Modified: pkg/Dowd/R/KernelVaRBoxKernel.R
===================================================================
--- pkg/Dowd/R/KernelVaRBoxKernel.R	2015-07-24 06:38:57 UTC (rev 3849)
+++ pkg/Dowd/R/KernelVaRBoxKernel.R	2015-07-24 19:01:12 UTC (rev 3850)
@@ -4,6 +4,7 @@
 #' 
 #' @param Ra Profit and Loss data set
 #' @param cl VaR confidence level
+#' @param plot Bool which indicates whether the graph is plotted or not
 #' @return Scalar VaR
 #' @references Dowd, K. Measuring Market Risk, Wiley, 2007.
 #'
@@ -15,7 +16,7 @@
 #'    KernelVaRBoxKernel(Ra, .95)
 #'
 #' @export
-KernelVaRBoxKernel <- function(Ra, cl) {
+KernelVaRBoxKernel <- function(Ra, cl, plot=TRUE) {
   PandL <- as.vector(Ra)
   mu <- mean(PandL)
   sigma <- sd(PandL)
@@ -33,8 +34,9 @@
   for (i in 2:n) {
     cdf[i] <- kernel.pdf[i] * delta.x + cdf[i - 1]
   }
-  plot(x.values, kernel.pdf, type="l", main = "Constructed Pdf")
-  
+  if (plot == TRUE) {
+    plot(x.values, kernel.pdf, type="l", main = "Constructed Pdf")
+  }
   # Derivation of required percentile
   cdf.indices.less.than.prob <- which(cdf<cl)
   # Gives vector of indices for all cdf-values less than probability

Modified: pkg/Dowd/R/KernelVaREpanechinikovKernel.R
===================================================================
--- pkg/Dowd/R/KernelVaREpanechinikovKernel.R	2015-07-24 06:38:57 UTC (rev 3849)
+++ pkg/Dowd/R/KernelVaREpanechinikovKernel.R	2015-07-24 19:01:12 UTC (rev 3850)
@@ -4,6 +4,7 @@
 #' 
 #' @param Ra Profit and Loss data set
 #' @param cl VaR confidence level
+#' @param plot Bool, plots the cdf if true.
 #' @return Scalar VaR
 #' @references Dowd, K. Measuring Market Risk, Wiley, 2007.
 #'
@@ -15,7 +16,7 @@
 #'    KernelVaREpanechinikovKernel(Ra, .95)
 #'
 #' @export
-KernelVaREpanechinikovKernel <- function(Ra, cl) {
+KernelVaREpanechinikovKernel <- function(Ra, cl, plot=TRUE) {
   PandL <- as.vector(Ra)
   mu <- mean(PandL)
   sigma <- sd(PandL)
@@ -33,8 +34,11 @@
   for (i in 2:n) {
     cdf[i] <- kernel.pdf[i] * delta.x + cdf[i - 1]
   }
-  plot(x.values, kernel.pdf, type="l", main = "Constructed Pdf")
+  if (plot == TRUE) {
+    plot(x.values, kernel.pdf, type="l", main = "Constructed Pdf")
+  }
   
+  
   # Derivation of required percentile
   cdf.indices.less.than.prob <- which(cdf<cl)
   # Gives vector of indices for all cdf-values less than probability

Modified: pkg/Dowd/R/KernelVaRNormalKernel.R
===================================================================
--- pkg/Dowd/R/KernelVaRNormalKernel.R	2015-07-24 06:38:57 UTC (rev 3849)
+++ pkg/Dowd/R/KernelVaRNormalKernel.R	2015-07-24 19:01:12 UTC (rev 3850)
@@ -4,6 +4,7 @@
 #' 
 #' @param Ra Profit and Loss data set
 #' @param cl VaR confidence level
+#' @param plot Bool, plots cdf if true
 #' @return Scalar VaR
 #' @references Dowd, K. Measuring Market Risk, Wiley, 2007.
 #'
@@ -15,7 +16,7 @@
 #'    KernelVaRNormalKernel(Ra, .95)
 #'
 #' @export
-KernelVaRNormalKernel <- function(Ra, cl) {
+KernelVaRNormalKernel <- function(Ra, cl, plot =TRUE) {
   PandL <- as.vector(Ra)
   mu <- mean(PandL)
   sigma <- sd(PandL)
@@ -33,7 +34,9 @@
   for (i in 2:n) {
     cdf[i] <- kernel.pdf[i] * delta.x + cdf[i - 1]
   }
-  plot(x.values, kernel.pdf, type="l", main = "Constructed Pdf")
+  if (plot == TRUE) {
+    plot(x.values, kernel.pdf, type="l", main = "Constructed Pdf")
+  }
   
   # Derivation of required percentile
   cdf.indices.less.than.prob <- which(cdf<cl)

Modified: pkg/Dowd/R/KernelVaRTriangleKernel.R
===================================================================
--- pkg/Dowd/R/KernelVaRTriangleKernel.R	2015-07-24 06:38:57 UTC (rev 3849)
+++ pkg/Dowd/R/KernelVaRTriangleKernel.R	2015-07-24 19:01:12 UTC (rev 3850)
@@ -4,6 +4,7 @@
 #' 
 #' @param Ra Profit and Loss data set
 #' @param cl VaR confidence level
+#' @param plot Bool, plots cdf if true.
 #' @return Scalar VaR
 #' @references Dowd, K. Measuring Market Risk, Wiley, 2007.
 #'
@@ -15,7 +16,7 @@
 #'    KernelVaRTriangleKernel(Ra, .95)
 #'
 #' @export
-KernelVaRTriangleKernel <- function(Ra, cl) {
+KernelVaRTriangleKernel <- function(Ra, cl, plot=TRUE) {
   PandL <- as.vector(Ra)
   mu <- mean(PandL)
   sigma <- sd(PandL)
@@ -33,8 +34,11 @@
   for (i in 2:n) {
     cdf[i] <- kernel.pdf[i] * delta.x + cdf[i - 1]
   }
-  plot(x.values, kernel.pdf, type="l", main = "Constructed Pdf")
+  if(plot == TRUE) {
+    plot(x.values, kernel.pdf, type="l", main = "Constructed Pdf")
+  }
   
+  
   # Derivation of required percentile
   cdf.indices.less.than.prob <- which(cdf<cl)
   # Gives vector of indices for all cdf-values less than probability

Modified: pkg/Dowd/man/GaussianCopulaVaR.Rd
===================================================================
--- pkg/Dowd/man/GaussianCopulaVaR.Rd	2015-07-24 06:38:57 UTC (rev 3849)
+++ pkg/Dowd/man/GaussianCopulaVaR.Rd	2015-07-24 19:01:12 UTC (rev 3850)
@@ -31,7 +31,7 @@
 }
 \examples{
 # VaR using bivariate Gumbel for X and Y with given parameters:
-   GaussianCopulaVaR(2.3, 4.1, 1.2, 1.5, .6, 10, .95)
+   GaussianCopulaVaR(2.3, 4.1, 1.2, 1.5, .6, 6, .95)
 }
 \author{
 Dinesh Acharya

Modified: pkg/Dowd/man/KernelESEpanechinikovKernel.Rd
===================================================================
--- pkg/Dowd/man/KernelESEpanechinikovKernel.Rd	2015-07-24 06:38:57 UTC (rev 3849)
+++ pkg/Dowd/man/KernelESEpanechinikovKernel.Rd	2015-07-24 19:01:12 UTC (rev 3850)
@@ -4,12 +4,14 @@
 \alias{KernelESEpanechinikovKernel}
 \title{Calculates ES using Epanechinikov kernel approach}
 \usage{
-KernelESEpanechinikovKernel(Ra, cl)
+KernelESEpanechinikovKernel(Ra, cl, plot = TRUE)
 }
 \arguments{
 \item{Ra}{Profit and Loss data set}
 
 \item{cl}{ES confidence level}
+
+\item{plot}{Bool, plots cdf if true}
 }
 \value{
 Scalar ES

Modified: pkg/Dowd/man/KernelVaRBoxKernel.Rd
===================================================================
--- pkg/Dowd/man/KernelVaRBoxKernel.Rd	2015-07-24 06:38:57 UTC (rev 3849)
+++ pkg/Dowd/man/KernelVaRBoxKernel.Rd	2015-07-24 19:01:12 UTC (rev 3850)
@@ -4,12 +4,14 @@
 \alias{KernelVaRBoxKernel}
 \title{Calculates VaR using box kernel approach}
 \usage{
-KernelVaRBoxKernel(Ra, cl)
+KernelVaRBoxKernel(Ra, cl, plot = TRUE)
 }
 \arguments{
 \item{Ra}{Profit and Loss data set}
 
 \item{cl}{VaR confidence level}
+
+\item{plot}{Bool which indicates whether the graph is plotted or not}
 }
 \value{
 Scalar VaR

Modified: pkg/Dowd/man/KernelVaREpanechinikovKernel.Rd
===================================================================
--- pkg/Dowd/man/KernelVaREpanechinikovKernel.Rd	2015-07-24 06:38:57 UTC (rev 3849)
+++ pkg/Dowd/man/KernelVaREpanechinikovKernel.Rd	2015-07-24 19:01:12 UTC (rev 3850)
@@ -4,12 +4,14 @@
 \alias{KernelVaREpanechinikovKernel}
 \title{Calculates VaR using epanechinikov kernel approach}
 \usage{
-KernelVaREpanechinikovKernel(Ra, cl)
+KernelVaREpanechinikovKernel(Ra, cl, plot = TRUE)
 }
 \arguments{
 \item{Ra}{Profit and Loss data set}
 
 \item{cl}{VaR confidence level}
+
+\item{plot}{Bool, plots the cdf if true.}
 }
 \value{
 Scalar VaR

Modified: pkg/Dowd/man/KernelVaRNormalKernel.Rd
===================================================================
--- pkg/Dowd/man/KernelVaRNormalKernel.Rd	2015-07-24 06:38:57 UTC (rev 3849)
+++ pkg/Dowd/man/KernelVaRNormalKernel.Rd	2015-07-24 19:01:12 UTC (rev 3850)
@@ -4,12 +4,14 @@
 \alias{KernelVaRNormalKernel}
 \title{Calculates VaR using normal kernel approach}
 \usage{
-KernelVaRNormalKernel(Ra, cl)
+KernelVaRNormalKernel(Ra, cl, plot = TRUE)
 }
 \arguments{
 \item{Ra}{Profit and Loss data set}
 
 \item{cl}{VaR confidence level}
+
+\item{plot}{Bool, plots cdf if true}
 }
 \value{
 Scalar VaR

Modified: pkg/Dowd/man/KernelVaRTriangleKernel.Rd
===================================================================
--- pkg/Dowd/man/KernelVaRTriangleKernel.Rd	2015-07-24 06:38:57 UTC (rev 3849)
+++ pkg/Dowd/man/KernelVaRTriangleKernel.Rd	2015-07-24 19:01:12 UTC (rev 3850)
@@ -4,12 +4,14 @@
 \alias{KernelVaRTriangleKernel}
 \title{Calculates VaR using triangle kernel approach}
 \usage{
-KernelVaRTriangleKernel(Ra, cl)
+KernelVaRTriangleKernel(Ra, cl, plot = TRUE)
 }
 \arguments{
 \item{Ra}{Profit and Loss data set}
 
 \item{cl}{VaR confidence level}
+
+\item{plot}{Bool, plots cdf if true.}
 }
 \value{
 Scalar VaR



More information about the Returnanalytics-commits mailing list