[Returnanalytics-commits] r2301 - pkg/PerformanceAnalytics/R

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Tue Nov 27 19:11:12 CET 2012


Author: braverock
Date: 2012-11-27 19:11:12 +0100 (Tue, 27 Nov 2012)
New Revision: 2301

Modified:
   pkg/PerformanceAnalytics/R/StdDev.annualized.R
Log:
- refactor to remove need for sd.xts

Modified: pkg/PerformanceAnalytics/R/StdDev.annualized.R
===================================================================
--- pkg/PerformanceAnalytics/R/StdDev.annualized.R	2012-11-27 18:03:09 UTC (rev 2300)
+++ pkg/PerformanceAnalytics/R/StdDev.annualized.R	2012-11-27 18:11:12 UTC (rev 2301)
@@ -51,24 +51,26 @@
 {
     if (is.vector(x)) {
         #scale standard deviation by multiplying by the square root of the number of periods to scale by
+        sqrt(scale)*sd(x, na.rm=TRUE)
+    } else { 
         if(!xtsible(x) & is.na(scale))
             stop("'x' needs to be timeBased or xtsible, or scale must be specified." )
         x = checkData (x)
         if(is.na(scale)) {
             freq = periodicity(x)
             switch(freq$scale,
-                minute = {stop("Data periodicity too high")},
-                hourly = {stop("Data periodicity too high")},
-                daily = {scale = 252},
-                weekly = {scale = 52},
-                monthly = {scale = 12},
-                quarterly = {scale = 4},
-                yearly = {scale = 1}
+                    minute = {stop("Data periodicity too high")},
+                    hourly = {stop("Data periodicity too high")},
+                    daily = {scale = 252},
+                    weekly = {scale = 52},
+                    monthly = {scale = 12},
+                    quarterly = {scale = 4},
+                    yearly = {scale = 1}
             )
-        }
-        sqrt(scale)*xts:::sd.xts(x, na.rm=TRUE)
-    } else { 
+        }        
+        
         result = apply(x, 2, sd.multiperiod, scale=scale)
+        
         dim(result) = c(1,NCOL(x))
         colnames(result) = colnames(x)
         rownames(result) = "Annualized Standard Deviation"



More information about the Returnanalytics-commits mailing list