[Returnanalytics-commits] r2341 - in pkg/PerformanceAnalytics/sandbox: . pulkit

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Mon Jun 17 12:34:13 CEST 2013


Author: pulkit
Date: 2013-06-17 12:34:12 +0200 (Mon, 17 Jun 2013)
New Revision: 2341

Added:
   pkg/PerformanceAnalytics/sandbox/pulkit/
   pkg/PerformanceAnalytics/sandbox/pulkit/MinTRL.R
   pkg/PerformanceAnalytics/sandbox/pulkit/ProbSharpeRatio.R
   pkg/PerformanceAnalytics/sandbox/pulkit/chart.PSR.R
Log:
-PSR and MinTRL Initial commit

Added: pkg/PerformanceAnalytics/sandbox/pulkit/MinTRL.R
===================================================================
--- pkg/PerformanceAnalytics/sandbox/pulkit/MinTRL.R	                        (rev 0)
+++ pkg/PerformanceAnalytics/sandbox/pulkit/MinTRL.R	2013-06-17 10:34:12 UTC (rev 2341)
@@ -0,0 +1,34 @@
+#'@title Probabilistic Sharpe Ratio
+#'@description
+#'Given a predefined
+#'benchmark4 Sharpe ratio (), the observed Sharpe  Ratiô can be expressed
+#' in probabilistic
+#'
+#'@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
+
+MinTrackRecord<-function(x,Rf,refSR,p=0.95,...){
+
+mintrl <- function(x,Rf,p,refSR,...){
+    sk = skewness(x)
+    kr =kurtosis(x)
+    sr = SharpeRatio(x, Rf, p, "StdDev")
+    MinTRL = 1 + (1 - sk*sr + ((kr-1)/4)*sr^2)*(qnorm(p)/(sr-refSR))^2
+    return(MinTRL)
+
+}
+    for(column in 1:columns){
+      column.mintrack <- mintrl(x[,column],Rf,p,refSR)
+      if(column == 1){
+        mintrack = column.mintrack
+      }
+      else {
+        mintrack = merge(mintrack, column.mintrack)
+    }
+      
+    }
+}
+

Added: pkg/PerformanceAnalytics/sandbox/pulkit/ProbSharpeRatio.R
===================================================================
--- pkg/PerformanceAnalytics/sandbox/pulkit/ProbSharpeRatio.R	                        (rev 0)
+++ pkg/PerformanceAnalytics/sandbox/pulkit/ProbSharpeRatio.R	2013-06-17 10:34:12 UTC (rev 2341)
@@ -0,0 +1,66 @@
+#'@title Probabilistic Sharpe Ratio
+#'@description
+#'Given a predefined
+#'benchmark4 Sharpe ratio (), the observed Sharpe  Ratiô can be expressed
+#' in probabilistic
+#'
+#'@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
+
+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)) stop("You must either pass R or the Sharpe ratio, Skewness, Kurtosis,n etc")
+        if(is.null(sk)) stop("You must either pass R or the Sharpe ratio, Skewness, Kurtosis,n etc")
+        if(is.null(kr)) stop("You must either pass R or the Sharpe Ratio, Skewness, Kurtosis,n etc")
+        if(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)
+    
+}

Added: pkg/PerformanceAnalytics/sandbox/pulkit/chart.PSR.R
===================================================================
--- pkg/PerformanceAnalytics/sandbox/pulkit/chart.PSR.R	                        (rev 0)
+++ pkg/PerformanceAnalytics/sandbox/pulkit/chart.PSR.R	2013-06-17 10:34:12 UTC (rev 2341)
@@ -0,0 +1,35 @@
+#'@title Probabilistic Sharpe Ratio
+#'@description
+#'Given a predefined
+#'benchmark4 Sharpe ratio (), the observed Sharpe  Ratiô can be expressed
+#' in probabilistic
+#'
+#'@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
+chart.PSR<-function(x,Rf,refSR,p=0.95,...){
+    for(column in 1:columns){
+      column.probsharpe <- psr(x[,column],Rf,p,refSR)
+      column.mintrack <- mintrl(x[,column],Rf,p,refSR)
+      if(column == 1){
+        probsharpe = column.probsharpe
+        mintrack = column.mintrack
+      }
+      else {
+        probsharpe = merge(probsharpe, column.probsharpe)
+        mintrack = merge(mintrack, column.mintrack)
+    }
+      
+    }
+    
+    probsharpe = rbind(probsharpe,mintrack)
+    
+    colnames(probsharpe) = columnnames
+    probsharpe = reclass(probsharpe, x)
+    rownames(probsharpe)=c("PSR","MinTRL")
+    return(probsharpe)
+
+}
+



More information about the Returnanalytics-commits mailing list