[Returnanalytics-commits] r2442 - in pkg/PerformanceAnalytics/sandbox/pulkit: . week1/code week1/vignette week2 week2/code

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed Jun 26 14:40:38 CEST 2013


Author: pulkit
Date: 2013-06-26 14:40:38 +0200 (Wed, 26 Jun 2013)
New Revision: 2442

Added:
   pkg/PerformanceAnalytics/sandbox/pulkit/week2/
   pkg/PerformanceAnalytics/sandbox/pulkit/week2/code/
   pkg/PerformanceAnalytics/sandbox/pulkit/week2/code/BenchmarkSR.R
   pkg/PerformanceAnalytics/sandbox/pulkit/week2/tests/
   pkg/PerformanceAnalytics/sandbox/pulkit/week2/vignette/
Removed:
   pkg/PerformanceAnalytics/sandbox/pulkit/ProbSharpeRatio.R
Modified:
   pkg/PerformanceAnalytics/sandbox/pulkit/week1/code/MinTRL.R
   pkg/PerformanceAnalytics/sandbox/pulkit/week1/code/ProbSharpeRatio.R
   pkg/PerformanceAnalytics/sandbox/pulkit/week1/code/chart.SharpeEfficient.R
   pkg/PerformanceAnalytics/sandbox/pulkit/week1/vignette/ProbSharpe.Rnw
   pkg/PerformanceAnalytics/sandbox/pulkit/week1/vignette/ProbSharpe.pdf
Log:
benchmarkSR file added

Deleted: pkg/PerformanceAnalytics/sandbox/pulkit/ProbSharpeRatio.R
===================================================================
--- pkg/PerformanceAnalytics/sandbox/pulkit/ProbSharpeRatio.R	2013-06-26 04:58:03 UTC (rev 2441)
+++ pkg/PerformanceAnalytics/sandbox/pulkit/ProbSharpeRatio.R	2013-06-26 12:40:38 UTC (rev 2442)
@@ -1,85 +0,0 @@
-#'@title Probabilistic Sharpe Ratio
-#'
-#'@description
-#'Given a predefined benchmark Sharpe ratio ,the observed Sharpe Ratio 
-#'can be expressed in probabilistic terms known as the Probabilistic Sharpe Ratio
-#'PSR takes higher moments  into account and delivers a corrected, atemporal 
-#'measure of performance expressed in terms of probability of skill.
-#'
-#'@aliases ProbSharpeRatio
-#'
-#'@param R the return series
-#'@param Rf the risk free rate of return
-#'@param refSR the reference Sharpe Ratio
-#'@param the confidence level
-#'@param weights the weights for the portfolio
-#'@param sr Sharpe Ratio
-#'@param sk Skewness
-#'@param kr Kurtosis
-#'
-#'@references Bailey, David H. and Lopez de Prado, Marcos, \emph{The Sharpe Ratio 
-#'Efficient Frontier} (July 1, 2012). Journal of Risk, Vol. 15, No. 2, Winter
-#' 2012/13
-#'
-#'@keywords ts multivariate distribution models
-#'
-#'@examples
-#'
-#'data(edhec)
-#'ProbSharpeRatio(edhec[,1],refSR = 0.28) 
-#'ProbSharpeRatio(edhec,reSR = 0.28,Rf = 0.06)
-
-
-ProbSharpeRatio<-
-function(R = NULL, refSR,Rf=0,p = 0.95, weights = NULL,n = NULL,sr = NULL,sk = NULL, kr = NULL, ...){
-    columns = 1
-    columnnames = NULL
-    #Error handling if R is not NULL
-    if(!is.null(R)){
-        x = checkData(R)
-        columns = ncol(x)
-        n = nrow(x)
-        #Checking if the weights are provided or not
-        if(!is.null(weights)){
-            if(length(weights)!=columns){
-                stop("number of items in weights is not equal to the number of columns in R")
-            }
-            else{
-                # A potfolio is constructed by applying the weights
-                x = Return.portfolio(R,weights)
-                sr = SharpeRatio(x, Rf, p, "StdDev")
-                sk = skewness(x)
-                kr = kurtosis(x)
-            }
-        }
-        else{
-            sr = SharpeRatio(x, Rf, p, "StdDev")
-            sk = skewness(x)
-            kr = kurtosis(x)
-        }
-
-    columnnames = colnames(x)
- 
-    }
-    # If R is passed as null checking for sharpe ratio , skewness and kurtosis 
-    else{
-
-        if(is.null(sr) | is.null(sk) | is.null(kr) | is.null(n)){
-             stop("You must either pass R or the Sharpe ratio, Skewness, Kurtosis,n etc")
-       }
-    }
-    #If weights are not taken into account a message is displayed
-    if(is.null(weights)){
-        message("no weights passed,will calculate Probability Sharpe Ratio for each column")
-    }
-   
-    if(!is.null(dim(Rf)))
-        Rf = checkData(Rf)
-    result = pnorm(((sr - refSR)*(n-1)^(0.5))/(1-sr*sk+sr^2*(kr-1)/4)^(0.5))
-    if(!is.null(dim(result))){ 
-        colnames(result) = columnnames
-        rownames(result) = paste("Probabilistic Sharpe Ratio(p=",round(p*100,1),"%):")
-    }
-    return(result)
-    
-}

Modified: pkg/PerformanceAnalytics/sandbox/pulkit/week1/code/MinTRL.R
===================================================================
--- pkg/PerformanceAnalytics/sandbox/pulkit/week1/code/MinTRL.R	2013-06-26 04:58:03 UTC (rev 2441)
+++ pkg/PerformanceAnalytics/sandbox/pulkit/week1/code/MinTRL.R	2013-06-26 12:40:38 UTC (rev 2442)
@@ -62,9 +62,9 @@
         }
     }
     #If weights are not taken into account a message is displayed
-    if(is.null(weights)){
-        message("no weights passed,will calculate Minimum Track Record Length for each column")
-    }
+    #if(is.null(weights)){
+     #   message("no weights passed,will calculate Minimum Track Record Length for each column")
+    #}
    
     if(!is.null(dim(Rf)))
         Rf = checkData(Rf)

Modified: pkg/PerformanceAnalytics/sandbox/pulkit/week1/code/ProbSharpeRatio.R
===================================================================
--- pkg/PerformanceAnalytics/sandbox/pulkit/week1/code/ProbSharpeRatio.R	2013-06-26 04:58:03 UTC (rev 2441)
+++ pkg/PerformanceAnalytics/sandbox/pulkit/week1/code/ProbSharpeRatio.R	2013-06-26 12:40:38 UTC (rev 2442)
@@ -69,9 +69,9 @@
        }
     }
     #If weights are not taken into account a message is displayed
-    if(is.null(weights)){
-        message("no weights passed,will calculate Probability Sharpe Ratio for each column")
-    }
+#    if(is.null(weights)){
+ #       message("no weights passed,will calculate Probability Sharpe Ratio for each column")
+  #  }
    
     if(!is.null(dim(Rf)))
         Rf = checkData(Rf)

Modified: pkg/PerformanceAnalytics/sandbox/pulkit/week1/code/chart.SharpeEfficient.R
===================================================================
--- pkg/PerformanceAnalytics/sandbox/pulkit/week1/code/chart.SharpeEfficient.R	2013-06-26 04:58:03 UTC (rev 2441)
+++ pkg/PerformanceAnalytics/sandbox/pulkit/week1/code/chart.SharpeEfficient.R	2013-06-26 12:40:38 UTC (rev 2442)
@@ -3,3 +3,17 @@
     x = checkData(R)
     columns = ncol(x)
     com
+    permutations<-function (n, r, v = 1:n) 
+    { 
+      if (r == 1) 
+        matrix(v, n, 1) 
+      else if (n == 1) 
+        matrix(v, 1, r) 
+      else { 
+        X <- NULL 
+        for (i in 1:n) X <- rbind(X, cbind(v[i], fn_perm_list(n - 
+                                                                1, r - 1, v[-i]))) 
+        X 
+      } 
+    } 
+    

Modified: pkg/PerformanceAnalytics/sandbox/pulkit/week1/vignette/ProbSharpe.Rnw
===================================================================
--- pkg/PerformanceAnalytics/sandbox/pulkit/week1/vignette/ProbSharpe.Rnw	2013-06-26 04:58:03 UTC (rev 2441)
+++ pkg/PerformanceAnalytics/sandbox/pulkit/week1/vignette/ProbSharpe.Rnw	2013-06-26 12:40:38 UTC (rev 2442)
@@ -37,15 +37,15 @@
 
 
 <<echo=FALSE>>=
-source("/home/pulkit/workspace/GSOC/PerformanceAnalytics/sandbox/pulkit/ProbSharpeRatio.R")
+source("/home/pulkit/workspace/GSOC/PerformanceAnalytics/sandbox/pulkit/week1/code/ProbSharpeRatio.R")
 @
 
 <<echo=FALSE>>=
-source("/home/pulkit/workspace/GSOC/PerformanceAnalytics/sandbox/pulkit/MinTRL.R")
+source("/home/pulkit/workspace/GSOC/PerformanceAnalytics/sandbox/pulkit/week1/code/MinTRL.R")
 @
 
 <<echo=FALSE>>=
-source("/home/pulkit/workspace/GSOC/PerformanceAnalytics/sandbox/pulkit/PSRopt.R")
+source("/home/pulkit/workspace/GSOC/PerformanceAnalytics/sandbox/pulkit/week1/code/PSRopt.R")
 @
 
 \section{Probabilistic Sharpe Ratio}
@@ -88,7 +88,8 @@
 where $\sigma = \sqrt{E[(r-\mu)^2]}$ ,its standard deviation.$\gamma_3=\frac{E\biggl[(r-\mu)^3\biggr]}{\sigma^3}$ its skewness,$\gamma_4=\frac{E\biggl[(r-\mu)^4\biggr]}{\sigma^4}$ its kurtosis and $SR = \frac{\mu}{\sigma}$ its Sharpe Ratio.
 
 Because $\hat{PSR}(SR^\ast)=Z[\hat{Z^\ast}]$ is a monotonic increasing function of 
-$\hat{Z^\ast}$. This optimal vector is invariant of the value adopted by the parameter $SR^\ast$. 
+$\hat{Z^\ast}$ ,it suffices to compute the vector that maximizes $\hat{Z^\ast}$
+ This optimal vector is invariant of the value adopted by the parameter $SR^\ast$. 
 
 
 <<>>=

Modified: pkg/PerformanceAnalytics/sandbox/pulkit/week1/vignette/ProbSharpe.pdf
===================================================================
(Binary files differ)

Added: pkg/PerformanceAnalytics/sandbox/pulkit/week2/code/BenchmarkSR.R
===================================================================
--- pkg/PerformanceAnalytics/sandbox/pulkit/week2/code/BenchmarkSR.R	                        (rev 0)
+++ pkg/PerformanceAnalytics/sandbox/pulkit/week2/code/BenchmarkSR.R	2013-06-26 12:40:38 UTC (rev 2442)
@@ -0,0 +1,33 @@
+#'@title 
+#'Benchmark Sharpe Ratio
+#'
+#'@description
+#'The benchmark SR is a linear function of the average
+#' SR of the individual strategies, and a decreasing
+#' convex function of the number of strategies and the 
+#' average pairwise correlation. The Returns are given as
+#' the input with the benchmark Sharpe Ratio as the output.
+#' 
+#'@aliases BenchmarkSR
+#'
+#'@param R a vector, matrix, data frame,timeseries or zoo object of asset returns
+#'
+#'@references
+#'
+#'@export
+BenchmanrkSR<-function(R){
+  
+  x = checkData(R)
+  columns = ncol(x)
+  SR = SharpeRatio(x)
+  sr_avg = mean(SR)
+  corr = table.Correlation(edhec,edhec)
+  corr_avg = 0
+  for(i in 1:columns){
+    for(j in i:columns){
+      corr_avg = corr_avg + corr[(i-1)*columns+j,]
+    }
+  }
+  SR_Benchmark = sr_avg*sqrt(columns/(1+(columns-1))*corr_avg[1,1])
+  return(SR_Benchmark)
+}
\ No newline at end of file



More information about the Returnanalytics-commits mailing list