[Returnanalytics-commits] r2381 - in pkg/PerformanceAnalytics/sandbox: . Shubhankit

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed Jun 19 19:51:09 CEST 2013


Author: shubhanm
Date: 2013-06-19 19:51:09 +0200 (Wed, 19 Jun 2013)
New Revision: 2381

Added:
   pkg/PerformanceAnalytics/sandbox/Shubhankit/
   pkg/PerformanceAnalytics/sandbox/Shubhankit/LoSharpeRatio.R
Log:


Added: pkg/PerformanceAnalytics/sandbox/Shubhankit/LoSharpeRatio.R
===================================================================
--- pkg/PerformanceAnalytics/sandbox/Shubhankit/LoSharpeRatio.R	                        (rev 0)
+++ pkg/PerformanceAnalytics/sandbox/Shubhankit/LoSharpeRatio.R	2013-06-19 17:51:09 UTC (rev 2381)
@@ -0,0 +1,71 @@
+LoSharpeRatio<-
+  function(R = NULL,Rf=0.,q = 0., ...)
+  {
+columns = 1
+columnnames = NULL
+#Error handling if R is not NULL
+if(!is.null(R)){
+  x = checkData(R)
+  columns = ncol(x)
+  n = nrow(x)
+  
+  if(q==0){
+    stop("AutoCorrelation Coefficient Should be greater than 0")
+    
+  }
+  else{
+    # A potfolio is constructed by applying the weights
+    
+    count = q
+    x=edhec
+    columns = ncol(x)
+    columnnames = colnames(x)
+    
+    # Calculate AutoCorrelation Coefficient
+    for(column in 1:columns) { # for each asset passed in as R
+      y = checkData(edhec[,column], method="vector", na.rm = TRUE)
+      
+      acflag6 = acf(y,plot=FALSE,lag.max=6)[[1]][2:7]
+      LjungBox =  Box.test(y,type="Ljung-Box",lag=q)
+      values = c(acflag6, LjungBox$p.value)
+      # values = base::round(as.numeric(values),digits)
+      
+      if(column == 1) {
+        result.df = data.frame(Value = values)
+        colnames(result.df) = columnnames[column]
+      }
+      else {
+        nextcol = data.frame(Value = values)
+        colnames(nextcol) = columnnames[column]
+        result.df = cbind(result.df, nextcol)
+      }
+    }
+    # Calculate Neta's
+    for(column in 1:columns) {
+      sum = 0
+      z = checkData(edhec[,column], method="vector", na.rm = TRUE)
+    for(q in 1:(q-1) )
+    {
+      sum = sum + (count-q)*result.df[column,q]
+    
+    }
+      
+      netaq = count/(sqrt(count+2*sum))
+      if(column == 1) {
+        netacol = data.frame(Value = netaq)
+        colnames(netacol) = columnnames[column]
+      }
+      else {
+          nextcol = data.frame(Value = netaq)
+        colnames(nextcol) = columnnames[column]
+        netacol = cbind(netacol, nextcol)
+      }
+      
+    }
+    shrp = SharpeRatio(x, Rf, FUN="VaR" , method="gaussian")
+    results = Shrp*netacol
+    colnames(results) = colnames(x)
+    return(results)
+  }
+  }  
+}
\ No newline at end of file



More information about the Returnanalytics-commits mailing list