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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Mon Sep 9 01:37:27 CEST 2013


Author: pulkit
Date: 2013-09-09 01:37:26 +0200 (Mon, 09 Sep 2013)
New Revision: 3028

Modified:
   pkg/PerformanceAnalytics/sandbox/pulkit/R/REM.R
   pkg/PerformanceAnalytics/sandbox/pulkit/R/chart.SharpeEfficient.R
   pkg/PerformanceAnalytics/sandbox/pulkit/R/redd.R
Log:
Error handling in redd and REM and some progress in Sharpe Efficient Frontier

Modified: pkg/PerformanceAnalytics/sandbox/pulkit/R/REM.R
===================================================================
--- pkg/PerformanceAnalytics/sandbox/pulkit/R/REM.R	2013-09-08 19:08:29 UTC (rev 3027)
+++ pkg/PerformanceAnalytics/sandbox/pulkit/R/REM.R	2013-09-08 23:37:26 UTC (rev 3028)
@@ -46,7 +46,21 @@
   if(nr != 1 && nr != n ){
     stop("The number of rows of the returns and the risk free rate do not match")
   }
-  
+
+   index = NULL
+    #ERROR handling for cases when lookback period is greater than the number of rows
+   for(i in 1:ncol(x)){
+       if(length(na.omit(x[,i]))<h){
+           warning(paste("The lookback Period greater than rows eliminating series",columnnames[i]))
+           index = c(index,i)
+           columns = columns -1
+       }
+   }
+    x = x[,-index]
+    rf = rf[-index]
+    columnnames = columnnames[-index]
+
+ 
   REM<-function(x,geometric){
     if(geometric)
       Return.cumulative = cumprod(1+x)

Modified: pkg/PerformanceAnalytics/sandbox/pulkit/R/chart.SharpeEfficient.R
===================================================================
--- pkg/PerformanceAnalytics/sandbox/pulkit/R/chart.SharpeEfficient.R	2013-09-08 19:08:29 UTC (rev 3027)
+++ pkg/PerformanceAnalytics/sandbox/pulkit/R/chart.SharpeEfficient.R	2013-09-08 23:37:26 UTC (rev 3028)
@@ -1,23 +1,27 @@
 chart.SharpeEfficientFrontier<-function(R){
 
     x = checkData(R)
+    x = na.omit(x)
     columns = ncol(x)
+    weights<-matrix(ncol=ncol(x))
+    for(i in 1:20000){
+       weights<-rbind(weights,sample(1:ncol(x))/ncol(x))
+    }
+    y_axis<-NULL
+    x_axis<-NULL
+    print(weights)
+    for(i in 1:20000){
+        x_portfolio = Return.portfolio(x,weights[i,])
+        print(x_portfolio)
+        sr<-SharpeRatio(x_portfolio,FUN="StdDev")
+        sk<-skewness(x_portfolio)
+        kr<-kurtosis(x_portfolio)
+        sd<-StdDev(x_portfolio)
+        sigma_sr<-((1-sk*sr+(sr^2)*(kr-1)/4)/(length(x_portfolio)-1))^0.5
+        y_axis<-c(y_axis,as.vector(sr))
+        x_axis<-c(x_axis,as.vector(sigma_sr))
+    }
+    plot(x_axis,y_axis)
 
-    mat<-NULL
-    subset_sum<-function(numbers,target,partial){
-        s = sum(partial)
-        print(s)
-        if(s==target){
-            mat = rbind(mat,partial)
-        }
-      
-        x<-NULL
-        for(i in 1:length(numbers)){
-            n = numbers[i]
-            remaining = numbers[(i+1):length(numbers)]
-            subset_sum(remaining,target,c(partial,n))
-        }
-    }
-    subset_sum(c(1:10),10,0)
 }
     

Modified: pkg/PerformanceAnalytics/sandbox/pulkit/R/redd.R
===================================================================
--- pkg/PerformanceAnalytics/sandbox/pulkit/R/redd.R	2013-09-08 19:08:29 UTC (rev 3027)
+++ pkg/PerformanceAnalytics/sandbox/pulkit/R/redd.R	2013-09-08 23:37:26 UTC (rev 3028)
@@ -45,10 +45,23 @@
     columnnames = colnames(x)
     rf = checkData(Rf)
     nr = length(Rf)
+    x_check = x
     if(nr != 1 && nr != n ){
       stop("The number of rows of the returns and the risk free rate do not match")
     }
-    
+    index = NULL
+    # ERROR Handling for cases in which lookback period is greater than the number of rows
+    for(i in 1:ncol(x)){
+        if(length(na.omit(x[,i]))<h){
+            warning(paste("The lookback Period greater than rows eliminating series",columnnames[i]))
+            index = c(index,i)
+            columns = columns -1
+        }
+    }
+    x = x[,-index]
+    rf = rf[-index]
+    columnnames = columnnames[-index]
+
     REDD<-function(xh,geometric){
         if(geometric)
             Return.cumulative = cumprod(1+xh)



More information about the Returnanalytics-commits mailing list