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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sat Jun 30 18:04:02 CEST 2012


Author: matthieu_lestel
Date: 2012-06-30 18:04:02 +0200 (Sat, 30 Jun 2012)
New Revision: 2095

Added:
   pkg/PerformanceAnalytics/R/VolatilitySkewness.R
   pkg/PerformanceAnalytics/man/VolatilitySkewness.Rd
Modified:
   pkg/PerformanceAnalytics/R/DownsideDeviation.R
   pkg/PerformanceAnalytics/R/UpsideRisk.R
   pkg/PerformanceAnalytics/man/DownsideDeviation.Rd
   pkg/PerformanceAnalytics/man/UpsideRisk.Rd
Log:
Volatiliy and variability skewness with examples and documentation

Modified: pkg/PerformanceAnalytics/R/DownsideDeviation.R
===================================================================
--- pkg/PerformanceAnalytics/R/DownsideDeviation.R	2012-06-29 21:45:37 UTC (rev 2094)
+++ pkg/PerformanceAnalytics/R/DownsideDeviation.R	2012-06-30 16:04:02 UTC (rev 2095)
@@ -64,7 +64,7 @@
 #' returns
 #' @param method one of "full" or "subset", indicating whether to use the
 #' length of the full series or the length of the subset of the series below
-#' the MAR as the denominator, defaults to "subset"
+#' the MAR as the denominator, defaults to "full"
 #' @param \dots any other passthru parameters
 #' @param potential if TRUE, calculate downside potential instead, default
 #' FALSE

Modified: pkg/PerformanceAnalytics/R/UpsideRisk.R
===================================================================
--- pkg/PerformanceAnalytics/R/UpsideRisk.R	2012-06-29 21:45:37 UTC (rev 2094)
+++ pkg/PerformanceAnalytics/R/UpsideRisk.R	2012-06-30 16:04:02 UTC (rev 2095)
@@ -29,7 +29,7 @@
 #' returns
 #' @param method one of "full" or "subset", indicating whether to use the
 #' length of the full series or the length of the subset of the series below
-#' the MAR as the denominator, defaults to "subset"
+#' the MAR as the denominator, defaults to "full"
 #' @param method one of "risk", "variance" or "potential" indicating whether
 #' to return the Upside risk, variance or potential
 #' @param \dots any other passthru parameters

Added: pkg/PerformanceAnalytics/R/VolatilitySkewness.R
===================================================================
--- pkg/PerformanceAnalytics/R/VolatilitySkewness.R	                        (rev 0)
+++ pkg/PerformanceAnalytics/R/VolatilitySkewness.R	2012-06-30 16:04:02 UTC (rev 2095)
@@ -0,0 +1,79 @@
+#' Volatility and variability of the return distribution
+#'
+#' Volatility skewness is a similar measure to omega but using the second
+#' partial moment. It's the ratio of the upside variance compared to the
+#' downside variance. Variability skewness is the ratio of the upside risk
+#' compared to the downside risk.
+#'
+#' \deqn{ VolatilitySkewness(R , MAR) = \frac{\sigma_U^2}{\sigma_D^2}}
+#' {VolatilitySkewness(R, MAR) = UpsideVariance / DownsideVariance}
+#'
+#' \deqn{ VariabilitySkewness(R , MAR) = \frac{\sigma_U}{\sigma_D}}
+#' {VariabilitySkewness(R, MAR) = UpsideRisk / DownsideRisk}
+#'
+#' where \eqn{\sigma_U} is the Upside risk and \eqn{\sigma_D} is the Downside Risk
+#'
+#' @aliases VolatilitySkewness
+#' @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 method one of "volatility", "variability" indicating whether
+#' to return the volatility skewness or the variability skweness
+#' @param \dots any other passthru parameters
+#' @author Matthieu Lestel
+#' @references Carl Bacon, \emph{Practical portfolio performance measurement 
+#' and attribution}, second edition 2008 p.97-98
+#' 
+#' @keywords ts multivariate distribution models
+#' @examples
+#'
+#' data(portfolio_bacon)
+#' MAR = 0.5
+#' print(VolatilitySkewness(portfolio_bacon, MAR, stat="volatility")) #expected 1.32
+#' print(VolatilitySkewness(portfolio_bacon, MAR, stat="variability")) #expected 1.15
+#'
+#' MAR = 0
+#' data(managers)
+#' print(VolatilitySkewness(managers['1996'], MAR, stat="volatility"))
+#' print(VolatilitySkewness(managers['1996',1], MAR, stat="volatility"))
+#'
+#' @export 
+
+VolatilitySkewness <-
+function (R, MAR = 0, stat=c("volatility", "variability"), ...)
+{
+    stat = stat[1]
+
+    R0 <- R
+    R = checkData(R, method="matrix")
+
+    if (ncol(R)==1 || is.null(R) || is.vector(R)) {
+       R = na.omit(R)
+
+        if(!is.null(dim(MAR))){
+            if(is.timeBased(index(MAR))){
+                MAR <-MAR[index(r)] #subset to the same dates as the R data
+            } 
+	    else{
+                MAR = mean(checkData(MAR, method = "vector"))
+                # we have to assume that Ra and a vector of Rf passed in for MAR both cover the same time period
+            }
+        }
+        
+	switch(stat,
+	    volatility = {result = UpsideRisk(R, MAR, stat="variance")/DownsideDeviation(R,MAR)^2},
+	    variability = {result = UpsideRisk(R, MAR, stat="risk")/DownsideDeviation(R,MAR)},
+	    )
+	reclass(result, R0)
+        return(result)
+    }
+    else {
+        R = checkData(R)
+        result = apply(R, MARGIN = 2, VolatilitySkewness, MAR = MAR, stat = stat, ...)
+        result<-t(result)
+        colnames(result) = colnames(R)
+        rownames(result) = paste("VolatilitySkewness (MAR = ",MAR,"%, stat= ",stat,")", sep="")
+        return(result)
+    }
+}
\ No newline at end of file

Modified: pkg/PerformanceAnalytics/man/DownsideDeviation.Rd
===================================================================
--- pkg/PerformanceAnalytics/man/DownsideDeviation.Rd	2012-06-29 21:45:37 UTC (rev 2094)
+++ pkg/PerformanceAnalytics/man/DownsideDeviation.Rd	2012-06-30 16:04:02 UTC (rev 2095)
@@ -24,7 +24,7 @@
   \item{method}{one of "full" or "subset", indicating
   whether to use the length of the full series or the
   length of the subset of the series below the MAR as the
-  denominator, defaults to "subset"}
+  denominator, defaults to "full"}
 
   \item{\dots}{any other passthru parameters}
 

Modified: pkg/PerformanceAnalytics/man/UpsideRisk.Rd
===================================================================
--- pkg/PerformanceAnalytics/man/UpsideRisk.Rd	2012-06-29 21:45:37 UTC (rev 2094)
+++ pkg/PerformanceAnalytics/man/UpsideRisk.Rd	2012-06-30 16:04:02 UTC (rev 2095)
@@ -15,7 +15,7 @@
   \item{method}{one of "full" or "subset", indicating
   whether to use the length of the full series or the
   length of the subset of the series below the MAR as the
-  denominator, defaults to "subset"}
+  denominator, defaults to "full"}
 
   \item{method}{one of "risk", "variance" or "potential"
   indicating whether to return the Upside risk, variance or

Added: pkg/PerformanceAnalytics/man/VolatilitySkewness.Rd
===================================================================
--- pkg/PerformanceAnalytics/man/VolatilitySkewness.Rd	                        (rev 0)
+++ pkg/PerformanceAnalytics/man/VolatilitySkewness.Rd	2012-06-30 16:04:02 UTC (rev 2095)
@@ -0,0 +1,62 @@
+\name{VolatilitySkewness}
+\alias{VolatilitySkewness}
+\title{Volatility and variability of the return distribution}
+\usage{
+  VolatilitySkewness(R, MAR = 0,
+    stat = c("volatility", "variability"), ...)
+}
+\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{method}{one of "volatility", "variability"
+  indicating whether to return the volatility skewness or
+  the variability skweness}
+
+  \item{\dots}{any other passthru parameters}
+}
+\description{
+  Volatility skewness is a similar measure to omega but
+  using the second partial moment. It's the ratio of the
+  upside variance compared to the downside variance.
+  Variability skewness is the ratio of the upside risk
+  compared to the downside risk.
+}
+\details{
+  \deqn{ VolatilitySkewness(R , MAR) =
+  \frac{\sigma_U^2}{\sigma_D^2}} {VolatilitySkewness(R,
+  MAR) = UpsideVariance / DownsideVariance}
+
+  \deqn{ VariabilitySkewness(R , MAR) =
+  \frac{\sigma_U}{\sigma_D}} {VariabilitySkewness(R, MAR) =
+  UpsideRisk / DownsideRisk}
+
+  where \eqn{\sigma_U} is the Upside risk and
+  \eqn{\sigma_D} is the Downside Risk
+}
+\examples{
+data(portfolio_bacon)
+MAR = 0.5
+print(VolatilitySkewness(portfolio_bacon, MAR, stat="volatility")) #expected 1.32
+print(VolatilitySkewness(portfolio_bacon, MAR, stat="variability")) #expected 1.15
+
+MAR = 0
+data(managers)
+print(VolatilitySkewness(managers['1996'], MAR, stat="volatility"))
+print(VolatilitySkewness(managers['1996',1], MAR, stat="volatility"))
+}
+\author{
+  Matthieu Lestel
+}
+\references{
+  Carl Bacon, \emph{Practical portfolio performance
+  measurement and attribution}, second edition 2008 p.97-98
+}
+\keyword{distribution}
+\keyword{models}
+\keyword{multivariate}
+\keyword{ts}
+



More information about the Returnanalytics-commits mailing list