[Uwgarp-commits] r64 - pkg/GARPFRM/R

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sat Feb 8 03:26:47 CET 2014


Author: tfillebeen
Date: 2014-02-08 03:26:46 +0100 (Sat, 08 Feb 2014)
New Revision: 64

Modified:
   pkg/GARPFRM/R/EWMA.R
Log:
Changes EWMA, corr pending

Modified: pkg/GARPFRM/R/EWMA.R
===================================================================
--- pkg/GARPFRM/R/EWMA.R	2014-02-08 00:38:44 UTC (rev 63)
+++ pkg/GARPFRM/R/EWMA.R	2014-02-08 02:26:46 UTC (rev 64)
@@ -92,6 +92,7 @@
 getCov.EWMACovar <- function(object, asset1, asset2){
   if(!inherits(object, "EWMACovar")) stop("object must be of class EWMACovar")
     # Check if asset is a character 
+  object[[length(object)]] = NULL
     if(is.character(asset1) & is.character(asset2)){
       idx1 = grep(asset1, colnames(object[[1]]))
       if(length(idx1) == 0) stop("name for asset1 not in object")
@@ -102,7 +103,7 @@
       idx1 = asset1
       idx2 = asset2
     }
-    out = xts(unlist(lapply(object, function(object) object[idx1, idx2])), as.Date(index(object)))
+    out = xts(unlist(lapply(object, function(object) object[idx1, idx2])), as.Date(names(object)))
     colnames(out) = paste(asset1, asset2, sep=".")
     return(out)
 }
@@ -111,7 +112,8 @@
 #' @S3method getCov EWMAVar
 getCov.EWMAVar <- function(object, asset1){
   if(!inherits(object, "EWMAVar")) stop("object must be of class EWMAVar")
-  # Check if asset is a character 
+  # Check if asset is a character
+  object[[length(object)]] = NULL
   if(is.character(asset1)){
     idx1 = grep(asset1, colnames(object[[1]]))
     if(length(idx1) == 0) stop("name for asset1 not in object")
@@ -119,7 +121,7 @@
     # Then dimensions are enough to find covar
     idx1 = asset1
   }
-  out = xts(unlist(lapply(object, function(object) object[idx1])), as.Date(index(object)))
+  out = xts(unlist(lapply(object, function(object) object[idx1])), as.Date(names(object)))
   colnames(out) = paste(asset1, sep=".")
   return(out)
 }
@@ -128,11 +130,22 @@
 # EWMA plotting for covar
 #' @export
 plot.EWMACovar <- function(object, asset1, asset2){
+  # Check if asset is a character 
+  if(is.character(asset1) & is.character(asset2)){
+    idx1 = grep(asset1, colnames(object[[1]]))
+    if(length(idx1) == 0) stop("name for asset1 not in object")
+    idx2 = grep(asset2, colnames(object[[1]]))
+    if(length(idx2) == 0) stop("name for asset2 not in object")
+  } else {
+    # Then dimensions are enough to find covar
+    idx1 = asset1
+    idx2 = asset2
+  }
   tmp = getCov(object,asset1, asset2)
-  plot(y=tmp, type="l", xlab="Time", ylab="Covar", lwd=2, col="blue",
+  plot(x=time(as.zoo(tmp)), y=tmp, type="l", xlab="Time", ylab="Covar", lwd=2, col="blue",
        main="EWMA Covar");
   grid()
-  abline(h=var(object$y_data)[1,2], lwd=2, col="red")
+  abline(h=var(object$y_data)[idx1,idx2], lwd=2, col="red")
   }
 
 # EWMA plotting for var



More information about the Uwgarp-commits mailing list