[Returnanalytics-commits] r3031 - pkg/PerformanceAnalytics/sandbox/pulkit/R

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Mon Sep 9 15:41:14 CEST 2013


Author: pulkit
Date: 2013-09-09 15:41:14 +0200 (Mon, 09 Sep 2013)
New Revision: 3031

Modified:
   pkg/PerformanceAnalytics/sandbox/pulkit/R/CdaR.R
   pkg/PerformanceAnalytics/sandbox/pulkit/R/DrawdownBeta.R
   pkg/PerformanceAnalytics/sandbox/pulkit/R/Drawdownalpha.R
Log:
NA values and error handling in Drawdown Beta and Alpha

Modified: pkg/PerformanceAnalytics/sandbox/pulkit/R/CdaR.R
===================================================================
--- pkg/PerformanceAnalytics/sandbox/pulkit/R/CdaR.R	2013-09-09 12:42:37 UTC (rev 3030)
+++ pkg/PerformanceAnalytics/sandbox/pulkit/R/CdaR.R	2013-09-09 13:41:14 UTC (rev 3031)
@@ -42,7 +42,6 @@
     if((p*nr) %% 1 == 0){
     drawdowns = -Drawdowns(R)
     drawdowns = drawdowns[order(drawdowns),increasing = TRUE]
-    print(drawdowns)
     # average of the drawdowns greater the (1-alpha).100% largest drawdowns 
     result = -(1/((1-p)*nr))*sum(drawdowns[((p)*nr):nr])
     }

Modified: pkg/PerformanceAnalytics/sandbox/pulkit/R/DrawdownBeta.R
===================================================================
--- pkg/PerformanceAnalytics/sandbox/pulkit/R/DrawdownBeta.R	2013-09-09 12:42:37 UTC (rev 3030)
+++ pkg/PerformanceAnalytics/sandbox/pulkit/R/DrawdownBeta.R	2013-09-09 13:41:14 UTC (rev 3031)
@@ -69,8 +69,13 @@
     # The Drawdown beta is given as the output.   
 
 
+    R = na.omit(R)
+    Rm = na.omit(Rm)
     x = checkData(R)
     xm = checkData(Rm)
+    if(nrow(x) != nrow(xm)){
+        stop("The number of rows of the return series and the optimal portfolio should be equal")
+    }
     columnnames = colnames(R)
     columns = ncol(R)
     drawdowns_m = Drawdowns(Rm)
@@ -95,7 +100,6 @@
     DDbeta<-function(x){
         q = NULL
         q_quantile = quantile(drawdowns_m,1-p)
-        print(drawdowns_m)
         for(i in 1:nrow(Rm)){
 
             if(drawdowns_m[i]<q_quantile){

Modified: pkg/PerformanceAnalytics/sandbox/pulkit/R/Drawdownalpha.R
===================================================================
--- pkg/PerformanceAnalytics/sandbox/pulkit/R/Drawdownalpha.R	2013-09-09 12:42:37 UTC (rev 3030)
+++ pkg/PerformanceAnalytics/sandbox/pulkit/R/Drawdownalpha.R	2013-09-09 13:41:14 UTC (rev 3031)
@@ -59,11 +59,13 @@
 
 
     # TODO  ERROR HANDLING
-    if(ncol(R) != ncol(Rm)){
-        stop("The number of columns in R and Rm should be equal")
-    }
+    R = na.omit(R)
+    Rm = na.omit(Rm)
     x = checkData(R)
     xm = checkData(Rm)
+    if(nrow(x) != nrow(xm)){
+        stop("The number of rows of the return series and the optimal portfolio should be equal")
+    }
     beta = BetaDrawdown(R,Rm,p = p,weights=weights,geometric=geometric,type=type,...)
     if(!is.null(weights)){
         x = Return.portfolio(R,weights)



More information about the Returnanalytics-commits mailing list