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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Mon Jul 6 20:04:46 CEST 2015


Author: dacharya
Date: 2015-07-06 20:04:46 +0200 (Mon, 06 Jul 2015)
New Revision: 3782

Modified:
   pkg/Dowd/R/PCAPrelim.R
   pkg/Dowd/man/PCAPrelim.Rd
Log:
PCAPrelim example edited.

Modified: pkg/Dowd/R/PCAPrelim.R
===================================================================
--- pkg/Dowd/R/PCAPrelim.R	2015-07-06 16:47:37 UTC (rev 3781)
+++ pkg/Dowd/R/PCAPrelim.R	2015-07-06 18:04:46 UTC (rev 3782)
@@ -5,7 +5,6 @@
 #' @param Ra Matrix return data set where each row is interpreted as a set of 
 #' daily observations, and each column as the returns to each position in a 
 #' portfolio
-#' @param position.data Position-size vector, giving amount invested in each 
 #' position
 #' @references Dowd, K. Measuring Market Risk, Wiley, 2007.
 #'
@@ -13,7 +12,11 @@
 #' @examples
 #' 
 #'    # Computes PCA Prelim
-#'    Ra <- matrix(rnorm(4*4), 4, 4)
+#'    # This code was based on Dowd's code and similar to Dowd's code,
+#'    # it is inconsistent for non-scalar data (Ra).
+#'    library(MASS)
+#'    library(expm)
+#'    Ra <- .15
 #'    PCAPrelim(Ra)
 #'
 #' @import expm MASS
@@ -41,8 +44,8 @@
                              rho%^%3, rho%^%2, rho%^%1, rho%^%0, rho%^%1),
                        cbind(rho%^%9, rho%^%8, rho%^%7, rho%^%6, rho%^%5,
                              rho%^%4, rho%^%3, rho%^%2, rho%^%1, rho%^%0))
-  mu <- double(10)
   sigma <- corr.matrix
+  mu <- double(dim(sigma)[1])
   # Random number generation
   returns <- mvrnorm(1000, mu, sigma)
   # Dowd code uses princomp in matlab. Similar function "princomp" is available 
@@ -59,10 +62,10 @@
   cum.variance <- double(length(variances))
   cum.variance[1] <- percent.explained[1]
   for (i in 2:length(variances)) {
-    cum.variances[i] <- percent.explained[i] + cum.variance[i-1]
+    cum.variance[i] <- percent.explained[i] + cum.variance[i-1]
   }
   t <- 0:10
-  plot(t, c(0, cum_variance), xlab = "Principal component", ylab = "%")
+  plot(t, c(0, cum.variance), xlab = "Principal component", ylab = "%", type="l")
   title("Explanatory Power of the Principal Components")
   
 }

Modified: pkg/Dowd/man/PCAPrelim.Rd
===================================================================
--- pkg/Dowd/man/PCAPrelim.Rd	2015-07-06 16:47:37 UTC (rev 3781)
+++ pkg/Dowd/man/PCAPrelim.Rd	2015-07-06 18:04:46 UTC (rev 3782)
@@ -9,9 +9,7 @@
 \arguments{
 \item{Ra}{Matrix return data set where each row is interpreted as a set of
 daily observations, and each column as the returns to each position in a
-portfolio}
-
-\item{position.data}{Position-size vector, giving amount invested in each
+portfolio
 position}
 }
 \description{
@@ -19,7 +17,11 @@
 }
 \examples{
 # Computes PCA Prelim
-   Ra <- matrix(rnorm(4*4), 4, 4)
+   # This code was based on Dowd's code and similar to Dowd's code,
+   # it is inconsistent for non-scalar data (Ra).
+   library(MASS)
+   library(expm)
+   Ra <- .15
    PCAPrelim(Ra)
 }
 \author{



More information about the Returnanalytics-commits mailing list