[Returnanalytics-commits] r2162 - pkg/PerformanceAnalytics/R

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sun Jul 15 17:30:39 CEST 2012


Author: matthieu_lestel
Date: 2012-07-15 17:30:38 +0200 (Sun, 15 Jul 2012)
New Revision: 2162

Modified:
   pkg/PerformanceAnalytics/R/AdjustedSharpeRatio.R
   pkg/PerformanceAnalytics/R/BurkeRatio.R
   pkg/PerformanceAnalytics/R/CAPM.epsilon.R
   pkg/PerformanceAnalytics/R/CAPM.jensenAlpha.R
   pkg/PerformanceAnalytics/R/TreynorRatio.R
Log:
modification of the method of calcul for return to match Bacon(2008) in some functions

Modified: pkg/PerformanceAnalytics/R/AdjustedSharpeRatio.R
===================================================================
--- pkg/PerformanceAnalytics/R/AdjustedSharpeRatio.R	2012-07-15 15:06:13 UTC (rev 2161)
+++ pkg/PerformanceAnalytics/R/AdjustedSharpeRatio.R	2012-07-15 15:30:38 UTC (rev 2162)
@@ -38,7 +38,7 @@
     if (ncol(R)==1 || is.null(R) || is.vector(R)) {
        R = na.omit(R)
        n = length(R)
-       Rp = period/n*sum(R)
+      Rp = (prod(1+R/100)^(period/length(R))-1)*100
        Sigp = sqrt(sum((R-mean(R))^2)/n)*sqrt(period)
        SR = (Rp - Rf) / Sigp
        K = kurtosis(R, method = "moment")

Modified: pkg/PerformanceAnalytics/R/BurkeRatio.R
===================================================================
--- pkg/PerformanceAnalytics/R/BurkeRatio.R	2012-07-15 15:06:13 UTC (rev 2161)
+++ pkg/PerformanceAnalytics/R/BurkeRatio.R	2012-07-15 15:30:38 UTC (rev 2162)
@@ -27,7 +27,7 @@
 #' @keywords ts multivariate distribution models
 #' @examples
 #' data(portfolio_bacon)
-#' print(BurkeRatio(portfolio_bacon[,1])) #expected 0.79
+#' print(BurkeRatio(portfolio_bacon[,1])) #expected 0.76
 #' print(BurkeRatio(portfolio_bacon[,1], modified = TRUE)) #expected 3.86
 #'
 #' data(managers)
@@ -102,11 +102,9 @@
 		in_drawdown = FALSE
 	    }
 
-	    print(drawdown)
 	    D = Drawdowns(R)
-	    print(D)
 
-       Rp = period/n*sum(R)
+       Rp = (prod(1+R/100)^(period/length(R))-1)*100
        result = (Rp - Rf)/sqrt(sum(drawdown^2))
        if(modified)
        {

Modified: pkg/PerformanceAnalytics/R/CAPM.epsilon.R
===================================================================
--- pkg/PerformanceAnalytics/R/CAPM.epsilon.R	2012-07-15 15:06:13 UTC (rev 2161)
+++ pkg/PerformanceAnalytics/R/CAPM.epsilon.R	2012-07-15 15:30:38 UTC (rev 2162)
@@ -14,6 +14,7 @@
 #' asset returns
 #' @param Rb return vector of the benchmark asset
 #' @param Rf risk free rate, in same period as your returns
+#' @param period number of periods in a year monthly scale = 12, quarterly = 4)
 #' @param \dots any other passthru parameters
 #' @author Matthieu Lestel
 #' @references Carl Bacon, \emph{Practical portfolio performance measurement 
@@ -23,7 +24,7 @@
 #' @examples
 #'
 #' data(portfolio_bacon)
-#' print(CAPM.epsilon(portfolio_bacon[,1], portfolio_bacon[,2])) #expected -3.046
+#' print(CAPM.epsilon(portfolio_bacon[,1], portfolio_bacon[,2])) #expected -1.31
 #'
 #' data(managers)
 #' print(CAPM.epsilon(managers['1996',1], managers['1996',8]))
@@ -32,16 +33,15 @@
 #' @export 
 
 CAPM.epsilon <-
-function (Ra, Rb, Rf = 0, ...)
+function (Ra, Rb, Rf = 0, period=12, ...)
 {
     calcul = FALSE
     Ra = checkData(Ra, method="matrix")
     Rb = checkData(Rb, method="matrix")
 
     if (ncol(Ra)==1 || is.null(Ra) || is.vector(Ra)) {
-    
-       Rp = (prod(0.01*Ra+1)-1)*100 #portfolio total return
-       Rpb = (prod(0.01*Rb+1)-1)*100 #benchmark total return
+     Rp = (prod(1+Ra/100)^(period/length(Ra))-1)*100
+     Rpb =  (prod(1+Rb/100)^(period/length(Rb))-1)*100 #benchmark total return
        for (i in (1:length(Ra))) {
           if (!is.na(Ra[i])) {
              calcul = TRUE

Modified: pkg/PerformanceAnalytics/R/CAPM.jensenAlpha.R
===================================================================
--- pkg/PerformanceAnalytics/R/CAPM.jensenAlpha.R	2012-07-15 15:06:13 UTC (rev 2161)
+++ pkg/PerformanceAnalytics/R/CAPM.jensenAlpha.R	2012-07-15 15:30:38 UTC (rev 2162)
@@ -14,6 +14,7 @@
 #' asset returns
 #' @param Rb return vector of the benchmark asset
 #' @param Rf risk free rate, in same period as your returns
+#' @param period number of periods in a year monthly scale = 12, quarterly = 4)
 #' @param \dots any other passthru parameters
 #' @author Matthieu Lestel
 #' @references Carl Bacon, \emph{Practical portfolio performance measurement 
@@ -23,7 +24,7 @@
 #' @examples
 #'
 #' data(portfolio_bacon)
-#' print(CAPM.jensenAlpha(portfolio_bacon[,1], portfolio_bacon[,2])) #expected -3.14938
+#' print(CAPM.jensenAlpha(portfolio_bacon[,1], portfolio_bacon[,2])) #expected -1.41
 #'
 #' data(managers)
 #' print(CAPM.jensenAlpha(managers['1996',1], managers['1996',8]))
@@ -32,7 +33,7 @@
 #' @export 
 
 CAPM.jensenAlpha <-
-function (Ra, Rb, Rf = 0, ...)
+function (Ra, Rb, Rf = 0, period = 12, ...)
 {
     calcul = FALSE
     Ra = checkData(Ra, method="matrix")
@@ -40,8 +41,8 @@
 
     if (ncol(Ra)==1 || is.null(Ra) || is.vector(Ra)) {
     
-     Rp = (prod(0.01*Ra+1)-1)*100 #portfolio total return
-     Rpb = (prod(0.01*Rb+1)-1)*100 #benchmark total return
+     Rp = (prod(1+Ra/100)^(period/length(Ra))-1)*100
+     Rpb =  (prod(1+Rb/100)^(period/length(Rb))-1)*100 #benchmark total return
      for (i in (1:length(Ra))) {
      	 if (!is.na(Ra[i])) {
      	    calcul = TRUE

Modified: pkg/PerformanceAnalytics/R/TreynorRatio.R
===================================================================
--- pkg/PerformanceAnalytics/R/TreynorRatio.R	2012-07-15 15:06:13 UTC (rev 2161)
+++ pkg/PerformanceAnalytics/R/TreynorRatio.R	2012-07-15 15:30:38 UTC (rev 2162)
@@ -45,15 +45,28 @@
 #' 
 
 ModifiedTreynorRatio <-
-function (Ra, Rb, Rf = 0)
+function (Ra, Rb, Rf = 0, scale = NA)
 {
+    		if(is.na(scale)) {
+        	    freq = periodicity(Ra)
+        	    switch(freq$scale,
+            	    minute = {stop("Data periodicity too high")},
+            	    hourly = {stop("Data periodicity too high")},
+            	    daily = {scale = 252},
+            	    weekly = {scale = 52},
+            	    monthly = {scale = 12},
+            	    quarterly = {scale = 4},
+            	    yearly = {scale = 1}
+        	    )
+          }
+
     calcul = FALSE
     Ra = checkData(Ra, method="matrix")
     Rb = checkData(Rb, method="matrix")
 
     if (ncol(Ra)==1 || is.null(Ra) || is.vector(Ra)) {
     
-     Rp = (prod(0.01*Ra+1)-1)*100 #portfolio total return
+     Rp = (prod(1+R/100)^(scale/length(R))-1)*100
      for (i in (1:length(Ra))) {
      	 if (!is.na(Ra[i])) {
      	    calcul = TRUE
@@ -84,7 +97,7 @@
 
     if(modified)
     {
-        ModifiedTreynorRatio(Ra, Rb, Rf)
+        ModifiedTreynorRatio(Ra, Rb, Rf, scale)
     }
     else
     {



More information about the Returnanalytics-commits mailing list