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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sat Dec 15 21:19:56 CET 2012


Author: bodanker
Date: 2012-12-15 21:19:56 +0100 (Sat, 15 Dec 2012)
New Revision: 2304

Modified:
   pkg/PerformanceAnalytics/R/CAPM.beta.R
Log:
- check for all NA sooner in CAPM.beta*


Modified: pkg/PerformanceAnalytics/R/CAPM.beta.R
===================================================================
--- pkg/PerformanceAnalytics/R/CAPM.beta.R	2012-12-15 19:02:01 UTC (rev 2303)
+++ pkg/PerformanceAnalytics/R/CAPM.beta.R	2012-12-15 20:19:56 UTC (rev 2304)
@@ -244,13 +244,14 @@
     # check columns
     if(NCOL(xRa)!=1L || NCOL(xRb)!=1L || NCOL(subset)!=1L)
         stop("all arguments must have only one column")
-    # merge, drop NA, add column names
+    # merge, drop NA
     merged <- as.data.frame(na.omit(cbind(xRa, xRb, subset)))
-    colnames(merged) <- c("xRa","xRb","subset")
-    merged$subset <- as.logical(merged$subset)
     # return NA if no non-NA values
     if(NROW(merged)==0)
         return(NA)
+    # add column names and convert subset back to logical
+    colnames(merged) <- c("xRa","xRb","subset")
+    merged$subset <- as.logical(merged$subset)
     # calculate beta
     model.lm = lm(xRa ~ xRb, data=merged, subset=merged$subset)
     beta = coef(model.lm)[[2]]



More information about the Returnanalytics-commits mailing list