[Returnanalytics-commits] r3576 - pkg/PerformanceAnalytics/sandbox

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Thu Dec 11 20:23:22 CET 2014


Author: peter_carl
Date: 2014-12-11 20:23:22 +0100 (Thu, 11 Dec 2014)
New Revision: 3576

Modified:
   pkg/PerformanceAnalytics/sandbox/to.period.returns.R
Log:
- now preserves NA instead of zerofilling


Modified: pkg/PerformanceAnalytics/sandbox/to.period.returns.R
===================================================================
--- pkg/PerformanceAnalytics/sandbox/to.period.returns.R	2014-12-09 19:56:39 UTC (rev 3575)
+++ pkg/PerformanceAnalytics/sandbox/to.period.returns.R	2014-12-11 19:23:22 UTC (rev 3576)
@@ -41,9 +41,12 @@
   if(err) stop("Period specified is higher than data periodicity.  Specify a lower frequency instead.")
   
   # Calculate cumulative return for aggregation periods
-  period.apply(x, INDEX=endpoints(x, period), FUN=Return.cumulative, geometric=geometric)
-
-  return(period.ret)
+#   result=period.apply(x, INDEX=endpoints(x, period), FUN=Return.cumulative, geometric=geometric)
+  result=NULL
+  for(i in 1:NCOL(x)){
+    result = cbind(result,period.apply(x[,i], INDEX=endpoints(x, period), FUN=function(x, geometric) {ifelse(length(na.omit(x))==0, NA,  Return.cumulative(x, geometric) )}, geometric=geometric))
+  }
+  return(result)
   
 }
 #' @export



More information about the Returnanalytics-commits mailing list