[Returnanalytics-commits] r2225 - in pkg/PerformanceAnalytics: . R man

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Thu Aug 9 10:15:01 CEST 2012


Author: matthieu_lestel
Date: 2012-08-09 10:15:01 +0200 (Thu, 09 Aug 2012)
New Revision: 2225

Added:
   pkg/PerformanceAnalytics/R/SpecificRisk.R
   pkg/PerformanceAnalytics/R/table.Distributions.R
   pkg/PerformanceAnalytics/R/table.DownsideRiskRatio.R
   pkg/PerformanceAnalytics/R/table.DrawdownsRatio.R
   pkg/PerformanceAnalytics/R/table.InformationRatio.R
   pkg/PerformanceAnalytics/R/table.SpecificRisk.R
   pkg/PerformanceAnalytics/R/table.Variability.R
   pkg/PerformanceAnalytics/man/SpecificRisk.Rd
   pkg/PerformanceAnalytics/man/UlcerIndex.Rd
   pkg/PerformanceAnalytics/man/table.Distributions.Rd
   pkg/PerformanceAnalytics/man/table.DownsideRiskRatio.Rd
   pkg/PerformanceAnalytics/man/table.DrawdownsRatio.Rd
   pkg/PerformanceAnalytics/man/table.InformationRatio.Rd
   pkg/PerformanceAnalytics/man/table.SpecificRisk.Rd
   pkg/PerformanceAnalytics/man/table.Variability.Rd
Modified:
   pkg/PerformanceAnalytics/NAMESPACE
   pkg/PerformanceAnalytics/R/SkewnessKurtosisRatio.R
   pkg/PerformanceAnalytics/R/SystematicRisk.R
   pkg/PerformanceAnalytics/R/TotalRisk.R
   pkg/PerformanceAnalytics/man/SystematicRisk.Rd
   pkg/PerformanceAnalytics/man/TotalRisk.Rd
Log:
addition of SpecificRisk, table.Variability, table.SpecificRisk, table.InformationRisk, table.Distributions, table.DrawdownsRatio, table.DownsideRiskRatio with documentation + doc of Ulcer Index + minor modifications

Modified: pkg/PerformanceAnalytics/NAMESPACE
===================================================================
--- pkg/PerformanceAnalytics/NAMESPACE	2012-08-08 23:52:10 UTC (rev 2224)
+++ pkg/PerformanceAnalytics/NAMESPACE	2012-08-09 08:15:01 UTC (rev 2225)
@@ -98,6 +98,7 @@
     SmoothingIndex,
     sortDrawdowns,
     SortinoRatio,
+    SpecificRisk,
     StdDev,
     StdDev.annualized,
     SterlingRatio,
@@ -126,14 +127,20 @@
     table.CAPM,
     table.CaptureRatios,
     table.Correlation,
+    table.Distributions,
     table.DownsideRisk,
+    table.DownsideRiskRatio,
     table.Drawdowns,
+    table.DrawdownsRatio,
     table.HigherMoments,
+    table.InformationRatio,
     table.Returns,
+    table.SpecificRisk,
     table.Stats,
     table.TrailingPeriods,
     table.TrailingPeriodsRel,
-    table.UpDownRatios
+    table.UpDownRatios,
+    table.Variability
 )
 
 ## Charts

Modified: pkg/PerformanceAnalytics/R/SkewnessKurtosisRatio.R
===================================================================
--- pkg/PerformanceAnalytics/R/SkewnessKurtosisRatio.R	2012-08-08 23:52:10 UTC (rev 2224)
+++ pkg/PerformanceAnalytics/R/SkewnessKurtosisRatio.R	2012-08-09 08:15:01 UTC (rev 2225)
@@ -45,7 +45,7 @@
 	  result = NA
 	}
 	else {
-	     result = skewness(R) / kurtosis(R, method = "moment")
+	     result = skewness(R, method = "moment") / kurtosis(R, method = "moment")
 	}
         return(result)
     }

Added: pkg/PerformanceAnalytics/R/SpecificRisk.R
===================================================================
--- pkg/PerformanceAnalytics/R/SpecificRisk.R	                        (rev 0)
+++ pkg/PerformanceAnalytics/R/SpecificRisk.R	2012-08-09 08:15:01 UTC (rev 2225)
@@ -0,0 +1,60 @@
+#' Specific risk of the return distribution
+#'
+#' Specific risk is the standard deviation of the error term in the
+#' regression equation.
+#'
+#' @aliases SpecificRisk
+#' @param Ra an xts, vector, matrix, data frame, timeSeries or zoo object of
+#' asset returns
+#' @param Rb return vector of the benchmark asset
+#' @param Rf risk free rate, in same period as your returns
+#' @param \dots any other passthru parameters
+#' @author Matthieu Lestel
+#' @references Carl Bacon, \emph{Practical portfolio performance measurement 
+#' and attribution}, second edition 2008 p.75
+#' 
+#' @keywords ts multivariate distribution models
+#' @examples
+#'
+#' data(portfolio_bacon)
+#' print(SpecificRisk(portfolio_bacon[,1], portfolio_bacon[,2])) #expected 0.0329
+#'
+#' data(managers)
+#' print(SpecificRisk(managers['1996',1], managers['1996',8]))
+#' print(SpecificRisk(managers['1996',1:5], managers['1996',8]))
+#'
+#' @export 
+SpecificRisk <-
+function (Ra, Rb, Rf = 0,  ...)
+{
+    calcul = FALSE
+    Ra = checkData(Ra, method="matrix")
+    Rb = checkData(Rb, method="matrix")
+
+    if (ncol(Ra)==1 || is.null(Ra) || is.vector(Ra)) {
+    
+     for (i in (1:length(Ra))) {
+     	 if (!is.na(Ra[i])) {
+     	    calcul = TRUE
+	 }
+      }
+
+     if (calcul) {
+     	Period = Frequency(Ra)
+     	epsilon = Ra - Rb * CAPM.beta(Ra,Rb,Rf) - CAPM.alpha(Ra,Rb,Rf)
+	result = sqrt(sum((epsilon - mean(epsilon))^2)/length(epsilon))*sqrt(Period)
+     }    
+     else {
+        result = NA
+     }
+      return(result)
+    }
+    else {
+        Ra = checkData(Ra)
+        result = apply(Ra, MARGIN = 2, SpecificRisk, Rb = Rb, Rf = Rf, ...)
+        result<-t(result)
+        colnames(result) = colnames(Ra)
+        rownames(result) = paste("Specific Risk = ", sep="")
+        return(result)
+    }
+}

Modified: pkg/PerformanceAnalytics/R/SystematicRisk.R
===================================================================
--- pkg/PerformanceAnalytics/R/SystematicRisk.R	2012-08-08 23:52:10 UTC (rev 2224)
+++ pkg/PerformanceAnalytics/R/SystematicRisk.R	2012-08-09 08:15:01 UTC (rev 2225)
@@ -15,7 +15,6 @@
 #' asset returns
 #' @param Rb return vector of the benchmark asset 
 #' @param Rf risk free rate, in same period as your returns
-#' @param Period the number of return in a year in the asset return 
 #' @param \dots any other passthru parameters
 #' @author Matthieu Lestel
 #' @references Carl Bacon, \emph{Practical portfolio performance measurement 
@@ -25,7 +24,7 @@
 #' @examples
 #'
 #' data(portfolio_bacon)
-#' print(SystematicRisk(portfolio_bacon[,1], portfolio_bacon[,2])) #expected 13.00
+#' print(SystematicRisk(portfolio_bacon[,1], portfolio_bacon[,2])) #expected 0.013
 #'
 #' data(managers)
 #' print(SystematicRisk(managers['1996',1], managers['1996',8]))
@@ -33,7 +32,7 @@
 #'
 #' @export 
 SystematicRisk <-
-function (Ra, Rb, Rf = 0, Period = 12, ...)
+function (Ra, Rb, Rf = 0, ...)
 {
     calcul = FALSE
     Ra = checkData(Ra, method="matrix")
@@ -48,6 +47,7 @@
       }
 
      if (calcul) {
+     	Period = Frequency(Ra)
         result = CAPM.beta(Ra,Rb,Rf) * sqrt(sum((Rb-mean(Rb))^2)/length(Rb))*sqrt(Period)
      }    
      else {

Modified: pkg/PerformanceAnalytics/R/TotalRisk.R
===================================================================
--- pkg/PerformanceAnalytics/R/TotalRisk.R	2012-08-08 23:52:10 UTC (rev 2224)
+++ pkg/PerformanceAnalytics/R/TotalRisk.R	2012-08-09 08:15:01 UTC (rev 2225)
@@ -11,8 +11,6 @@
 #' asset returns
 #' @param Rb return vector of the benchmark asset
 #' @param Rf risk free rate, in same period as your returns
-#' @param Period the number of return in a year in the asset return 
-#' (i.e. 12 for monthly returns, 4 for quarterly returns)
 #' @param \dots any other passthru parameters
 #' @author Matthieu Lestel
 #' @references Carl Bacon, \emph{Practical portfolio performance measurement 
@@ -30,7 +28,7 @@
 #'
 #' @export 
 TotalRisk <-
-function (Ra, Rb, Rf = 0, Period = 12,  ...)
+function (Ra, Rb, Rf = 0,  ...)
 {
     calcul = FALSE
     Ra = checkData(Ra, method="matrix")
@@ -45,6 +43,7 @@
       }
 
      if (calcul) {
+     	Period = Frequency(Ra)
      	epsilon = Ra - Rb * CAPM.beta(Ra,Rb,Rf) - CAPM.alpha(Ra,Rb,Rf)
 	specifikRisk = sqrt(sum((epsilon - mean(epsilon))^2)/length(epsilon))*sqrt(Period)
         result = sqrt((SystematicRisk(Ra,Rb,Rf))^2 + specifikRisk^2)

Added: pkg/PerformanceAnalytics/R/table.Distributions.R
===================================================================
--- pkg/PerformanceAnalytics/R/table.Distributions.R	                        (rev 0)
+++ pkg/PerformanceAnalytics/R/table.Distributions.R	2012-08-09 08:15:01 UTC (rev 2225)
@@ -0,0 +1,75 @@
+#' Distributions Summary: Statistics and Stylized Facts
+#' 
+#' Table of Monthly standard deviation, Skewness, Sample standard deviation,
+#' Kurtosis, Excess kurtosis, Sample Skweness and Sample excess kurtosis 
+#' 
+#' @param R an xts, vector, matrix, data frame, timeSeries or zoo object of
+#' asset returns
+#' @param scale number of periods in a year (daily scale = 252, monthly scale =
+#' 12, quarterly scale = 4)
+#' @param digits number of digits to round results to
+#' @author Matthieu Lestel
+#' @references Carl Bacon, \emph{Practical portfolio performance measurement 
+#' and attribution}, second edition 2008 p.87
+#' @seealso \code{\link{StdDev.annualized}} \cr \code{\link{skewness}} \cr
+#' \code{\link{kurtosis}}
+#' @keywords ts multivariate distribution models
+#' @examples
+#' 
+#' data(managers)
+#' table.Distributions(managers[,1:8])
+#' 
+#' require("Hmisc")
+#' result = t(table.Distributions(managers[,1:8]))
+#' 
+#' textplot(format.df(result, na.blank=TRUE, numeric.dollar=FALSE, cdec=c(3,3,1)),
+#' rmar = 0.8, cmar = 2,  max.cex=.9, halign = "center", valign = "top",
+#' row.valign="center", wrap.rownames=20, wrap.colnames=10,
+#' col.rownames=c("red", rep("darkgray",5), rep("orange",2)), mar = c(0,0,3,0)+0.1)
+#' title(main="Portfolio Distributions statistics")
+#' 
+#' @export
+table.Distributions <-
+function (R, scale = NA, digits = 4)
+{
+    y = checkData(R)
+
+    # Set up dimensions and labels
+    columns = ncol(y)
+    #rows = nrow(y)
+    columnnames = colnames(y)
+    #rownames = rownames(y)
+
+    #set up frequency
+    if(is.na(scale)) {
+        freq = periodicity(R)
+        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}
+        )
+    }
+
+    # for each column, do the following:
+    for(column in 1:columns) {
+        z = c(StdDev.annualized(y[,column,drop=FALSE])/sqrt(scale), skewness(y[,column,drop=FALSE], method = "moment"), kurtosis(y[,column,drop=FALSE], method = "moment"), kurtosis(y[,column,drop=FALSE], method = "excess"), skewness(y[,column,drop=FALSE], method = "sample"), kurtosis(y[,column,drop=FALSE], method = "sample_excess"))
+
+        znames = c("Monthly Std Dev", "Skewness",  "Kurtosis", "Excess kurtosis", "Sample skewness", "Sample excess kurtosis")
+
+
+        if(column == 1) {
+            resultingtable = data.frame(Value = z, row.names = znames)
+        }
+        else {
+            nextcolumn = data.frame(Value = z, row.names = znames) 
+            resultingtable = cbind(resultingtable, nextcolumn)
+        }
+    }
+    colnames(resultingtable) = columnnames
+    ans = base::round(resultingtable, digits)
+    ans
+}
\ No newline at end of file

Added: pkg/PerformanceAnalytics/R/table.DownsideRiskRatio.R
===================================================================
--- pkg/PerformanceAnalytics/R/table.DownsideRiskRatio.R	                        (rev 0)
+++ pkg/PerformanceAnalytics/R/table.DownsideRiskRatio.R	2012-08-09 08:15:01 UTC (rev 2225)
@@ -0,0 +1,76 @@
+#' Downside Summary: Statistics and ratios
+#' 
+#' Table of Monthly downside risk, Annualised downside risk, Downside potential,
+#' Omega, Sortino ratio, Upside potential, Upside potential ratio and
+#' Omega-Sharpe ratio
+#' 
+#' @param R an xts, vector, matrix, data frame, timeSeries or zoo object of
+#' asset returns
+#' @param MAR Minimum Acceptable Return, in the same periodicity as your
+#' returns
+#' @param scale number of periods in a year (daily scale = 252, monthly scale =
+#' @param digits number of digits to round results to
+#' @author Matthieu Lestel
+#' @references Carl Bacon, \emph{Practical portfolio performance measurement 
+#' and attribution}, second edition 2008 p.98
+#' @seealso \code{\link{CalmarRatio}} \cr \code{\link{BurkeRatio}}
+#' \cr \code{\link{PainIndex}} \cr \code{\link{UlcerIndex}} \cr 
+#' \code{\link{PainRatio}} \cr \code{\link{MartinRatio}}
+#' @keywords ts multivariate distribution models
+#' @examples
+#' 
+#' data(managers)
+#' table.DownsideRiskRatio(managers[,1:8])
+#' 
+#' require("Hmisc")
+#' result = t(table.DownsideRiskRatio(managers[,1:8]))
+#' 
+#' textplot(format.df(result, na.blank=TRUE, numeric.dollar=FALSE, cdec=c(3,3,1)),
+#' rmar = 0.8, cmar = 2,  max.cex=.9, halign = "center", valign = "top",
+#' row.valign="center", wrap.rownames=20, wrap.colnames=10,
+#' col.rownames=c("red", rep("darkgray",5), rep("orange",2)), mar = c(0,0,3,0)+0.1)
+#' title(main="Downside risk statistics")
+#' 
+#' @export
+table.DownsideRiskRatio <-
+function (R, MAR = 0, scale = NA, digits = 4)
+{
+    y = checkData(R)
+
+    # Set up dimensions and labels
+    columns = ncol(y)
+    #rows = nrow(y)
+    columnnames = colnames(y)
+    #rownames = rownames(y)
+
+    #set up frequency
+    if(is.na(scale)) {
+        freq = periodicity(R)
+        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}
+        )
+    }
+
+    # for each column, do the following:
+    for(column in 1:columns) {
+        z = c(DownsideDeviation(y[,column,drop=FALSE], MAR = MAR), DownsideDeviation(y[,column,drop=FALSE], MAR = MAR)*sqrt(scale), DownsidePotential(y[,column,drop=FALSE], MAR = MAR), UpsideRisk(y[,column,drop=FALSE], MAR = MAR, stat = "potential")/DownsidePotential(y[,column,drop=FALSE], MAR = MAR), SortinoRatio(y[,column,drop=FALSE], MAR = MAR), UpsideRisk(y[,column,drop=FALSE], MAR = MAR, stat = "potential"), UpsidePotentialRatio(y[,column,drop=FALSE], MAR = MAR), OmegaSharpeRatio(y[,column,drop=FALSE], MAR = MAR))
+
+        znames = c("Monthly downside risk", "Annualised downside risk", "Downside potential", "Omega", "Sortino ratio", "Upside potential", "Upside potential ratio", "Omega-sharpe ratio")
+        if(column == 1) {
+            resultingtable = data.frame(Value = z, row.names = znames)
+        }
+        else {
+            nextcolumn = data.frame(Value = z, row.names = znames) 
+            resultingtable = cbind(resultingtable, nextcolumn)
+        }
+    }
+    colnames(resultingtable) = columnnames
+    ans = base::round(resultingtable, digits)
+    ans
+}
\ No newline at end of file

Added: pkg/PerformanceAnalytics/R/table.DrawdownsRatio.R
===================================================================
--- pkg/PerformanceAnalytics/R/table.DrawdownsRatio.R	                        (rev 0)
+++ pkg/PerformanceAnalytics/R/table.DrawdownsRatio.R	2012-08-09 08:15:01 UTC (rev 2225)
@@ -0,0 +1,75 @@
+#' Drawdowns Summary: Statistics and ratios
+#' 
+#' Table of Calmar ratio, Sterling ratio, Burke ratio, Pain index, Ulcer index, 
+#' Pain ratio and Martin ratio
+#' 
+#' @param R an xts, vector, matrix, data frame, timeSeries or zoo object of
+#' asset returns
+#' @param Rf risk free rate, in same period as your returns
+#' @param scale number of periods in a year (daily scale = 252, monthly scale =
+#' 12, quarterly scale = 4)
+#' @param digits number of digits to round results to
+#' @author Matthieu Lestel
+#' @references Carl Bacon, \emph{Practical portfolio performance measurement 
+#' and attribution}, second edition 2008 p.93
+#' @seealso \code{\link{CalmarRatio}} \cr \code{\link{BurkeRatio}}
+#' \cr \code{\link{PainIndex}} \cr \code{\link{UlcerIndex}} \cr 
+#' \code{\link{PainRatio}} \cr \code{\link{MartinRatio}}
+#' @keywords ts multivariate distribution models
+#' @examples
+#' 
+#' data(managers)
+#' table.DrawdownsRatio(managers[,1:8])
+#' 
+#' require("Hmisc")
+#' result = t(table.DrawdownsRatio(managers[,1:8], Rf=.04/12))
+#' 
+#' textplot(format.df(result, na.blank=TRUE, numeric.dollar=FALSE, cdec=c(3,3,1)),
+#' rmar = 0.8, cmar = 2,  max.cex=.9, halign = "center", valign = "top",
+#' row.valign="center", wrap.rownames=20, wrap.colnames=10,
+#' col.rownames=c("red", rep("darkgray",5), rep("orange",2)), mar = c(0,0,3,0)+0.1)
+#' title(main="Drawdowns ratio statistics")
+#' 
+#' @export
+table.DrawdownsRatio <-
+function (R, Rf = 0, scale = NA, digits = 4)
+{
+    y = checkData(R)
+
+    # Set up dimensions and labels
+    columns = ncol(y)
+    #rows = nrow(y)
+    columnnames = colnames(y)
+    #rownames = rownames(y)
+
+    #set up frequency
+    if(is.na(scale)) {
+        freq = periodicity(R)
+        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}
+        )
+    }
+
+    # for each column, do the following:
+    for(column in 1:columns) {
+        z = c(SterlingRatio(y[,column,drop=FALSE]), CalmarRatio(y[,column,drop=FALSE]), BurkeRatio(y[,column,drop=FALSE], Rf = Rf, period = scale), PainIndex(y[,column,drop=FALSE]), UlcerIndex(y[,column,drop=FALSE]), PainRatio(y[,column,drop=FALSE], Rf = Rf, period = scale), MartinRatio(y[,column,drop=FALSE], Rf = Rf))
+
+        znames = c("Sterling ratio", "Calmar ratio", "Burke ratio", "Pain index", "Ulcer index", "Pain ratio", "Martin ratio")
+        if(column == 1) {
+            resultingtable = data.frame(Value = z, row.names = znames)
+        }
+        else {
+            nextcolumn = data.frame(Value = z, row.names = znames) 
+            resultingtable = cbind(resultingtable, nextcolumn)
+        }
+    }
+    colnames(resultingtable) = columnnames
+    ans = base::round(resultingtable, digits)
+    ans
+}
\ No newline at end of file

Added: pkg/PerformanceAnalytics/R/table.InformationRatio.R
===================================================================
--- pkg/PerformanceAnalytics/R/table.InformationRatio.R	                        (rev 0)
+++ pkg/PerformanceAnalytics/R/table.InformationRatio.R	2012-08-09 08:15:01 UTC (rev 2225)
@@ -0,0 +1,76 @@
+#' Information ratio Summary: Statistics and Stylized Facts
+#' 
+#' Table of Tracking error, Annualised tracking error and Information ratio
+#' 
+#' @param R an xts, vector, matrix, data frame, timeSeries or zoo object of
+#' asset returns
+#' @param Rb return vector of the benchmark asset
+#' @param scale number of periods in a year (daily scale = 252, monthly scale =
+#' 12, quarterly scale = 4)
+#' @param digits number of digits to round results to
+#' @author Matthieu Lestel
+#' @seealso \code{\link{InformationRatio}}
+#' \cr \code{\link{TrackingError}}
+#' @references Carl Bacon, \emph{Practical portfolio performance measurement 
+#' and attribution}, second edition 2008 p.81
+#' @keywords ts multivariate distribution models
+#' @examples
+#' 
+#' data(managers)
+#' table.InformationRatio(managers[,1:8], managers[,8])
+#' 
+#' require("Hmisc")
+#' result = t(table.InformationRatio(managers[,1:8], managers[,8]))
+#' 
+#' textplot(format.df(result, na.blank=TRUE, numeric.dollar=FALSE, cdec=c(3,3,1)),
+#' rmar = 0.8, cmar = 2,  max.cex=.9, halign = "center", valign = "top",
+#' row.valign="center", wrap.rownames=20, wrap.colnames=10,
+#' col.rownames=c("red", rep("darkgray",5), rep("orange",2)), mar = c(0,0,3,0)+0.1)
+#' title(main="Portfolio information ratio")
+#' 
+#' @export
+table.InformationRatio <-
+function (R, Rb, scale = NA, digits = 4)
+{
+    y = checkData(R)
+    Rb = checkData(Rb)
+
+    # Set up dimensions and labels
+    columns = ncol(y)
+    #rows = nrow(y)
+    columnnames = colnames(y)
+    #rownames = rownames(y)
+
+    #set up frequency
+    if(is.na(scale)) {
+        freq = periodicity(R)
+        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}
+        )
+    }
+
+    # for each column, do the following:
+    for(column in 1:columns) {
+        z = c(TrackingError(y[,column,drop=FALSE],Rb)/sqrt(scale), TrackingError(y[,column,drop=FALSE],Rb), InformationRatio(y[,column,drop=FALSE],Rb))
+
+        znames = c("Tracking Error", "Annualised Tracking Error", "Information Ratio")
+
+
+        if(column == 1) {
+            resultingtable = data.frame(Value = z, row.names = znames)
+        }
+        else {
+            nextcolumn = data.frame(Value = z, row.names = znames) 
+            resultingtable = cbind(resultingtable, nextcolumn)
+        }
+    }
+    colnames(resultingtable) = columnnames
+    ans = base::round(resultingtable, digits)
+    ans
+}
\ No newline at end of file

Added: pkg/PerformanceAnalytics/R/table.SpecificRisk.R
===================================================================
--- pkg/PerformanceAnalytics/R/table.SpecificRisk.R	                        (rev 0)
+++ pkg/PerformanceAnalytics/R/table.SpecificRisk.R	2012-08-09 08:15:01 UTC (rev 2225)
@@ -0,0 +1,64 @@
+#' Specific risk Summary: Statistics and Stylized Facts
+#' 
+#' Table of specific risk, systematic risk and total risk
+#' 
+#' @param Ra an xts, vector, matrix, data frame, timeSeries or zoo object of
+#' asset returns
+#' @param Rb return vector of the benchmark asset
+#' @param Rf risk free rate, in same period as your returns
+#' @param digits number of digits to round results to
+#' @author Matthieu Lestel
+#' @seealso \code{\link{SystematicRisk}} \cr \code{\link{SpecificRisk}}
+#' \cr \code{\link{TotalRisk}}
+#' @references Carl Bacon, \emph{Practical portfolio performance measurement 
+#' and attribution}, second edition 2008 p.76
+#' @keywords ts multivariate distribution models
+#' @examples
+#' 
+#' data(managers)
+#' table.SpecificRisk(managers[,1:8], managers[,8])
+#' 
+#' require("Hmisc")
+#' result = t(table.SpecificRisk(managers[,1:8], managers[,8], Rf=.04/12))
+#' 
+#' textplot(format.df(result, na.blank=TRUE, numeric.dollar=FALSE, cdec=c(3,3,1)),
+#' rmar = 0.8, cmar = 2,  max.cex=.9, halign = "center", valign = "top", 
+#' row.valign="center", wrap.rownames=20, wrap.colnames=10, 
+#' col.rownames=c("red", rep("darkgray",5), rep("orange",2)), mar = c(0,0,3,0)+0.1)
+#' title(main="Portfolio specific, systematic and total risk")
+#' 
+#' @export
+table.SpecificRisk <-
+function (Ra, Rb, Rf = 0, digits = 4)
+{
+    y = checkData(Ra)
+    Rb = checkData(Rb)
+
+    # Set up dimensions and labels
+    columns = ncol(y)
+    #rows = nrow(y)
+    columnnames = colnames(y)
+    #rownames = rownames(y)
+
+    #set up frequency
+    scale = Frequency(Ra)
+
+    # for each column, do the following:
+    for(column in 1:columns) {
+        z = c(SpecificRisk(y[,column,drop=FALSE], Rb = Rb, Rf = Rf, Period = scale), SystematicRisk(y[,column,drop=FALSE], Rb = Rb, Rf = Rf, Period = scale), TotalRisk(y[,column,drop=FALSE], Rb = Rb, Rf = Rf, Period = scale))
+
+        znames = c("Specific Risk", "Systematic Risk", "Total Risk")
+
+
+        if(column == 1) {
+            resultingtable = data.frame(Value = z, row.names = znames)
+        }
+        else {
+            nextcolumn = data.frame(Value = z, row.names = znames) 
+            resultingtable = cbind(resultingtable, nextcolumn)
+        }
+    }
+    colnames(resultingtable) = columnnames
+    ans = base::round(resultingtable, digits)
+    ans
+}
\ No newline at end of file

Added: pkg/PerformanceAnalytics/R/table.Variability.R
===================================================================
--- pkg/PerformanceAnalytics/R/table.Variability.R	                        (rev 0)
+++ pkg/PerformanceAnalytics/R/table.Variability.R	2012-08-09 08:15:01 UTC (rev 2225)
@@ -0,0 +1,78 @@
+#' Variability Summary: Statistics and Stylized Facts
+#' 
+#' Table of Mean absolute difference, Monthly standard deviation and annualised
+#' standard deviation
+#' 
+#' 
+#' @param R an xts, vector, matrix, data frame, timeSeries or zoo object of
+#' asset returns
+#' @param geometric generate geometric (TRUE) or simple (FALSE) returns,
+#' default TRUE
+#' @param scale number of periods in a year (daily scale = 252, monthly scale =
+#' 12, quarterly scale = 4)
+#' @param digits number of digits to round results to
+#' @author Matthieu Lestel
+#' @references Carl Bacon, \emph{Practical portfolio performance measurement 
+#' and attribution}, second edition 2008 p.65
+#' @seealso \code{\link{StdDev.annualized}}
+#' \cr \code{\link{MeanAbsoluteDeviation}}
+#' @keywords ts multivariate distribution models
+#' @examples
+#' 
+#' data(managers)
+#' table.Variability(managers[,1:8])
+#' 
+#' require("Hmisc")
+#' result = t(table.Variability(managers[,1:8]))
+#' 
+#' textplot(format.df(result, na.blank=TRUE, numeric.dollar=FALSE, cdec=c(3,3,1)),
+#' rmar = 0.8, cmar = 2,  max.cex=.9, halign = "center", valign = "top",
+#' row.valign="center", wrap.rownames=20, wrap.colnames=10,
+#' col.rownames=c("red", rep("darkgray",5), rep("orange",2)), mar = c(0,0,3,0)+0.1)
+#' title(main="Portfolio variability")
+#' 
+#' @export
+table.Variability <-
+function (R, scale = NA, geometric = TRUE, digits = 4)
+{
+    y = checkData(R)
+
+    # Set up dimensions and labels
+    columns = ncol(y)
+    #rows = nrow(y)
+    columnnames = colnames(y)
+    #rownames = rownames(y)
+
+    #set up frequency
+    if(is.na(scale)) {
+        freq = periodicity(R)
+        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}
+        )
+    }
+
+    # for each column, do the following:
+    for(column in 1:columns) {
+        z = c(MeanAbsoluteDeviation(y[,column,drop=FALSE]), StdDev.annualized(y[,column,drop=FALSE], scale = scale)/sqrt(scale), StdDev.annualized(y[,column,drop=FALSE], scale = scale))
+
+        znames = c("Mean Absolute deviation", "Monthly Std Dev", "Annualized Std Dev")
+
+
+        if(column == 1) {
+            resultingtable = data.frame(Value = z, row.names = znames)
+        }
+        else {
+            nextcolumn = data.frame(Value = z, row.names = znames) 
+            resultingtable = cbind(resultingtable, nextcolumn)
+        }
+    }
+    colnames(resultingtable) = columnnames
+    ans = base::round(resultingtable, digits)
+    ans
+}
\ No newline at end of file

Added: pkg/PerformanceAnalytics/man/SpecificRisk.Rd
===================================================================
--- pkg/PerformanceAnalytics/man/SpecificRisk.Rd	                        (rev 0)
+++ pkg/PerformanceAnalytics/man/SpecificRisk.Rd	2012-08-09 08:15:01 UTC (rev 2225)
@@ -0,0 +1,40 @@
+\name{SpecificRisk}
+\alias{SpecificRisk}
+\title{Specific risk of the return distribution}
+\usage{
+  SpecificRisk(Ra, Rb, Rf = 0, ...)
+}
+\arguments{
+  \item{Ra}{an xts, vector, matrix, data frame, timeSeries
+  or zoo object of asset returns}
+
+  \item{Rb}{return vector of the benchmark asset}
+
+  \item{Rf}{risk free rate, in same period as your returns}
+
+  \item{\dots}{any other passthru parameters}
+}
+\description{
+  Specific risk is the standard deviation of the error term
+  in the regression equation.
+}
+\examples{
+data(portfolio_bacon)
+print(SpecificRisk(portfolio_bacon[,1], portfolio_bacon[,2])) #expected 0.0329
+
+data(managers)
+print(SpecificRisk(managers['1996',1], managers['1996',8]))
+print(SpecificRisk(managers['1996',1:5], managers['1996',8]))
+}
+\author{
+  Matthieu Lestel
+}
+\references{
+  Carl Bacon, \emph{Practical portfolio performance
+  measurement and attribution}, second edition 2008 p.75
+}
+\keyword{distribution}
+\keyword{models}
+\keyword{multivariate}
+\keyword{ts}
+

Modified: pkg/PerformanceAnalytics/man/SystematicRisk.Rd
===================================================================
--- pkg/PerformanceAnalytics/man/SystematicRisk.Rd	2012-08-08 23:52:10 UTC (rev 2224)
+++ pkg/PerformanceAnalytics/man/SystematicRisk.Rd	2012-08-09 08:15:01 UTC (rev 2225)
@@ -2,7 +2,7 @@
 \alias{SystematicRisk}
 \title{Systematic risk of the return distribution}
 \usage{
-  SystematicRisk(Ra, Rb, Rf = 0, Period = 12, ...)
+  SystematicRisk(Ra, Rb, Rf = 0, ...)
 }
 \arguments{
   \item{Ra}{an xts, vector, matrix, data frame, timeSeries
@@ -12,9 +12,6 @@
 
   \item{Rf}{risk free rate, in same period as your returns}
 
-  \item{Period}{the number of return in a year in the asset
-  return}
-
   \item{\dots}{any other passthru parameters}
 }
 \description{
@@ -34,7 +31,7 @@
 }
 \examples{
 data(portfolio_bacon)
-print(SystematicRisk(portfolio_bacon[,1], portfolio_bacon[,2])) #expected 13.00
+print(SystematicRisk(portfolio_bacon[,1], portfolio_bacon[,2])) #expected 0.013
 
 data(managers)
 print(SystematicRisk(managers['1996',1], managers['1996',8]))

Modified: pkg/PerformanceAnalytics/man/TotalRisk.Rd
===================================================================
--- pkg/PerformanceAnalytics/man/TotalRisk.Rd	2012-08-08 23:52:10 UTC (rev 2224)
+++ pkg/PerformanceAnalytics/man/TotalRisk.Rd	2012-08-09 08:15:01 UTC (rev 2225)
@@ -2,7 +2,7 @@
 \alias{TotalRisk}
 \title{Total risk of the return distribution}
 \usage{
-  TotalRisk(Ra, Rb, Rf = 0, Period = 12, ...)
+  TotalRisk(Ra, Rb, Rf = 0, ...)
 }
 \arguments{
   \item{Ra}{an xts, vector, matrix, data frame, timeSeries
@@ -12,10 +12,6 @@
 
   \item{Rf}{risk free rate, in same period as your returns}
 
-  \item{Period}{the number of return in a year in the asset
-  return (i.e. 12 for monthly returns, 4 for quarterly
-  returns)}
-
   \item{\dots}{any other passthru parameters}
 }
 \description{

Added: pkg/PerformanceAnalytics/man/UlcerIndex.Rd
===================================================================
--- pkg/PerformanceAnalytics/man/UlcerIndex.Rd	                        (rev 0)
+++ pkg/PerformanceAnalytics/man/UlcerIndex.Rd	2012-08-09 08:15:01 UTC (rev 2225)
@@ -0,0 +1,44 @@
+\name{UlcerIndex}
+\alias{UlcerIndex}
+\title{calculate the Ulcer Index}
+\usage{
+  UlcerIndex(R, ...)
+}
+\arguments{
+  \item{R}{a vector, matrix, data frame, timeSeries or zoo
+  object of asset returns}
+
+  \item{\dots}{any other passthru parameters}
+}
+\description{
+  Developed by Peter G. Martin in 1987 (Martin and McCann,
+  1987) and named for the worry caused to the portfolio
+  manager or investor.  This is similar to drawdown
+  deviation except that the impact of the duration of
+  drawdowns is incorporated by selecting the negative
+  return for each period below the previous peak or high
+  water mark.  The impact of long, deep drawdowns will have
+  significant impact because the underperformance since the
+  last peak is squared.
+}
+\details{
+  UI = sqrt(sum[i=1,2,...,n](D'_i^2/n)) where D'_i =
+  drawdown since previous peak in period i
+
+  DETAILS: This approach is sensitive to the frequency of
+  the time periods involved and penalizes managers that
+  take time to recover to previous highs.
+
+  REFERENCES: Martin, P. and McCann, B. (1989) The
+  investor's Guide to Fidelity Funds: Winning Strategies
+  for Mutual Fund Investors.  John Wiley & Sons, Inc. Peter
+  Martin's web page on UI:
+  http://www.tangotools.com/ui/ui.htm
+
+  ## Test against spreadsheet at:
+  http://www.tangotools.com/ui/UlcerIndex.xls
+}
+\author{
+  Matthieu Lestel
+}
+

Added: pkg/PerformanceAnalytics/man/table.Distributions.Rd
===================================================================
--- pkg/PerformanceAnalytics/man/table.Distributions.Rd	                        (rev 0)
+++ pkg/PerformanceAnalytics/man/table.Distributions.Rd	2012-08-09 08:15:01 UTC (rev 2225)
@@ -0,0 +1,49 @@
+\name{table.Distributions}
+\alias{table.Distributions}
+\title{Distributions Summary: Statistics and Stylized Facts}
+\usage{
+  table.Distributions(R, scale = NA, digits = 4)
+}
+\arguments{
+  \item{R}{an xts, vector, matrix, data frame, timeSeries
+  or zoo object of asset returns}
+
+  \item{scale}{number of periods in a year (daily scale =
+  252, monthly scale = 12, quarterly scale = 4)}
+
+  \item{digits}{number of digits to round results to}
+}
+\description{
+  Table of Monthly standard deviation, Skewness, Sample
+  standard deviation, Kurtosis, Excess kurtosis, Sample
+  Skweness and Sample excess kurtosis
+}
+\examples{
+data(managers)
+table.Distributions(managers[,1:8])
+
+require("Hmisc")
+result = t(table.Distributions(managers[,1:8]))
+
+textplot(format.df(result, na.blank=TRUE, numeric.dollar=FALSE, cdec=c(3,3,1)),
+rmar = 0.8, cmar = 2,  max.cex=.9, halign = "center", valign = "top",
+row.valign="center", wrap.rownames=20, wrap.colnames=10,
+col.rownames=c("red", rep("darkgray",5), rep("orange",2)), mar = c(0,0,3,0)+0.1)
+title(main="Portfolio Distributions statistics")
+}
+\author{
+  Matthieu Lestel
+}
+\references{
+  Carl Bacon, \emph{Practical portfolio performance
+  measurement and attribution}, second edition 2008 p.87
+}
+\seealso{
+  \code{\link{StdDev.annualized}} \cr
+  \code{\link{skewness}} \cr \code{\link{kurtosis}}
+}
+\keyword{distribution}
+\keyword{models}
+\keyword{multivariate}
+\keyword{ts}
+

Added: pkg/PerformanceAnalytics/man/table.DownsideRiskRatio.Rd
===================================================================
--- pkg/PerformanceAnalytics/man/table.DownsideRiskRatio.Rd	                        (rev 0)
+++ pkg/PerformanceAnalytics/man/table.DownsideRiskRatio.Rd	2012-08-09 08:15:01 UTC (rev 2225)
@@ -0,0 +1,54 @@
+\name{table.DownsideRiskRatio}
+\alias{table.DownsideRiskRatio}
+\title{Downside Summary: Statistics and ratios}
+\usage{
+  table.DownsideRiskRatio(R, MAR = 0, scale = NA,
+    digits = 4)
+}
+\arguments{
+  \item{R}{an xts, vector, matrix, data frame, timeSeries
+  or zoo object of asset returns}
+
+  \item{MAR}{Minimum Acceptable Return, in the same
+  periodicity as your returns}
+
+  \item{scale}{number of periods in a year (daily scale =
+  252, monthly scale =}
+
+  \item{digits}{number of digits to round results to}
+}
+\description{
+  Table of Monthly downside risk, Annualised downside risk,
+  Downside potential, Omega, Sortino ratio, Upside
+  potential, Upside potential ratio and Omega-Sharpe ratio
+}
+\examples{
+data(managers)
+table.DownsideRiskRatio(managers[,1:8])
+
+require("Hmisc")
+result = t(table.DownsideRiskRatio(managers[,1:8]))
+
+textplot(format.df(result, na.blank=TRUE, numeric.dollar=FALSE, cdec=c(3,3,1)),
+rmar = 0.8, cmar = 2,  max.cex=.9, halign = "center", valign = "top",
+row.valign="center", wrap.rownames=20, wrap.colnames=10,
+col.rownames=c("red", rep("darkgray",5), rep("orange",2)), mar = c(0,0,3,0)+0.1)
+title(main="Downside risk statistics")
+}
+\author{
+  Matthieu Lestel
+}
+\references{
+  Carl Bacon, \emph{Practical portfolio performance
+  measurement and attribution}, second edition 2008 p.98
+}
+\seealso{
+  \code{\link{CalmarRatio}} \cr \code{\link{BurkeRatio}}
[TRUNCATED]

To get the complete diff run:
    svnlook diff /svnroot/returnanalytics -r 2225


More information about the Returnanalytics-commits mailing list