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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Thu Jul 2 22:42:59 CEST 2015


Author: dacharya
Date: 2015-07-02 22:42:59 +0200 (Thu, 02 Jul 2015)
New Revision: 3771

Modified:
   pkg/Dowd/R/PCAES.R
Log:
Condition for the special case when number.of.principal.components is 1 was added. Additional unnecessary line was removed.

Modified: pkg/Dowd/R/PCAES.R
===================================================================
--- pkg/Dowd/R/PCAES.R	2015-07-02 18:24:24 UTC (rev 3770)
+++ pkg/Dowd/R/PCAES.R	2015-07-02 20:42:59 UTC (rev 3771)
@@ -39,9 +39,14 @@
   
   # Principal components estimation
   a <- svd(return.data)  # SVD; provides U and V
-  index <- n - number.of.principal.components # Establishes how many zero terms on diagonal of S matrix
   S.diag <- sort(a$d, decreasing = TRUE)[1:number.of.principal.components] # Creates diagonal for S matrix
-  S.diag <- diag(S.diag)
+  # Following condition for the fact that scalar argument to diag returns 
+  # identity matrix
+  if (length(S.diag) == 1) {
+    S.diag <- as.matrix(S.diag)
+  } else {
+    S.diag <- diag(S.diag)
+  }
   S <- matrix(0, min(m, n), min(m, n))
   S[1:number.of.principal.components,1:number.of.principal.components] <- S.diag # Creates S matrix with diagonal S.diag
   synthetic.PandL.data <- a$u %*% S %*% t(a$v) %*% position.data



More information about the Returnanalytics-commits mailing list