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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Thu Jun 21 16:19:45 CEST 2012


Author: matthieu_lestel
Date: 2012-06-21 16:19:44 +0200 (Thu, 21 Jun 2012)
New Revision: 2045

Added:
   pkg/PerformanceAnalytics/R/DRatio.R
   pkg/PerformanceAnalytics/man/DRatio.Rd
Modified:
   pkg/PerformanceAnalytics/man/BernardoLedoitratio.Rd
   pkg/PerformanceAnalytics/man/DownsideDeviation.Rd
   pkg/PerformanceAnalytics/man/DownsideFrequency.Rd
   pkg/PerformanceAnalytics/man/UpsideFrequency.Rd
   pkg/PerformanceAnalytics/man/UpsideRisk.Rd
Log:
d ratio with exemples and documentation

Added: pkg/PerformanceAnalytics/R/DRatio.R
===================================================================
--- pkg/PerformanceAnalytics/R/DRatio.R	                        (rev 0)
+++ pkg/PerformanceAnalytics/R/DRatio.R	2012-06-21 14:19:44 UTC (rev 2045)
@@ -0,0 +1,61 @@
+#' d ratio of the return distribution
+#'
+#' The d ratio is similar to the Bernado Ledoit ratio but inverted and
+#' taking into account the frequency of positive and negative returns.
+#'
+#' It has values between zero and infinity. It can be used to rank the 
+#' performance of portfolios. The lower the d ratio the better the 
+#' performance, a value of zero indicating there are no returns less than
+#' zero and a value of infinity indicating there are no returns greater than zero.
+#'
+#' \deqn{DRatio(R) = \frac{n_{d}*\sum^{n}_{t=1}{max(-R_{t},0)}}{n_{u}*\sum^{n}_{t=1}
+#' {max(R_{t},0)}}}{BernadoLedoitratio(R) = nd*sum
+#' (t=1..n)(max(-R(t),0)) / nu*sum(t=1..n)(max(R(t),0))}
+#'
+#' where \eqn{n} is the number of observations of the entire series,
+#'       \eqn{n_{d}} is the number of observations less than zero,
+#'       \eqn{n_{u}} is the number of observations greater than zero
+#' 
+#' @aliases DRatio
+#' @param R an xts, vector, matrix, data frame, timeSeries or zoo object of
+#' asset returns
+#' @param \dots any other passthru parameters
+#' @author Matthieu Lestel
+#' @references Carl Bacon, \emph{Practical portfolio performance measurement 
+#' and attribution}, second edition 2008 p.95
+#' 
+#' @keywords ts multivariate distribution models
+#' @examples
+#' data(portfolio_bacon)
+#' print(DRatio(portfolio_bacon)) #expected 0.401
+#'
+#' data(managers)
+#' print(DRatio(managers['1996']))
+#' print(DRatio(managers['1996',1])) #expected 0.0725
+#'
+#' @export 
+
+DRatio <- function (R, ...)
+{
+    R0 <- R
+    R = checkData(R, method="matrix")
+
+    if (ncol(R)==1 || is.null(R) || is.vector(R)) {
+       R = na.omit(R)
+       r1 = subset(R, R > 0)
+       r2 = subset(R, R < 0)
+       nd = length(r2)
+       nu = length(r1)
+       result = (-nd*sum(r2))/(nu*sum(r1))    
+       reclass(result, R0)
+       return(result)
+    }  
+    else {
+        R = checkData(R)
+        result = apply(R, MARGIN = 2, DRatio, ...)
+        result<-t(result)
+        colnames(result) = colnames(R)
+        rownames(result) = paste("d ratio", sep="")
+        return(result)
+    }
+}
\ No newline at end of file

Modified: pkg/PerformanceAnalytics/man/BernardoLedoitratio.Rd
===================================================================
--- pkg/PerformanceAnalytics/man/BernardoLedoitratio.Rd	2012-06-20 16:03:56 UTC (rev 2044)
+++ pkg/PerformanceAnalytics/man/BernardoLedoitratio.Rd	2012-06-21 14:19:44 UTC (rev 2045)
@@ -28,7 +28,7 @@
 }
 \examples{
 data(portfolio_bacon)
-print(BernadoLedoitratio(portfolio_return)) #expected 1.78
+print(BernadoLedoitratio(portfolio_bacon)) #expected 1.78
 
 data(managers)
 print(BernadoLedoitratio(managers['1996']))

Added: pkg/PerformanceAnalytics/man/DRatio.Rd
===================================================================
--- pkg/PerformanceAnalytics/man/DRatio.Rd	                        (rev 0)
+++ pkg/PerformanceAnalytics/man/DRatio.Rd	2012-06-21 14:19:44 UTC (rev 2045)
@@ -0,0 +1,55 @@
+\name{DRatio}
+\alias{DRatio}
+\title{d ratio of the return distribution}
+\usage{
+  DRatio(R, ...)
+}
+\arguments{
+  \item{R}{an xts, vector, matrix, data frame, timeSeries
+  or zoo object of asset returns}
+
+  \item{\dots}{any other passthru parameters}
+}
+\description{
+  The d ratio is similar to the Bernado Ledoit ratio but
+  inverted and taking into account the frequency of
+  positive and negative returns.
+}
+\details{
+  It has values between zero and infinity. It can be used
+  to rank the performance of portfolios. The lower the d
+  ratio the better the performance, a value of zero
+  indicating there are no returns less than zero and a
+  value of infinity indicating there are no returns greater
+  than zero.
+
+  \deqn{DRatio(R) =
+  \frac{n_{d}*\sum^{n}_{t=1}{max(-R_{t},0)}}{n_{u}*\sum^{n}_{t=1}
+  {max(R_{t},0)}}}{BernadoLedoitratio(R) = nd*sum
+  (t=1..n)(max(-R(t),0)) / nu*sum(t=1..n)(max(R(t),0))}
+
+  where \eqn{n} is the number of observations of the entire
+  series \\ \eqn{n_{d}} is the number of observations less
+  than zero \\ \eqn{n_{u}} is the number of observations
+  greater than zero \\
+}
+\examples{
+data(portfolio_bacon)
+print(DRatio(portfolio_bacon)) #expected 0.401
+
+data(managers)
+print(DRatio(managers['1996']))
+print(DRatio(managers['1996',1])) #expected 0.0725
+}
+\author{
+  Matthieu Lestel
+}
+\references{
+  Carl Bacon, \emph{Practical portfolio performance
+  measurement and attribution}, second edition 2008 p.95
+}
+\keyword{distribution}
+\keyword{models}
+\keyword{multivariate}
+\keyword{ts}
+

Modified: pkg/PerformanceAnalytics/man/DownsideDeviation.Rd
===================================================================
--- pkg/PerformanceAnalytics/man/DownsideDeviation.Rd	2012-06-20 16:03:56 UTC (rev 2044)
+++ pkg/PerformanceAnalytics/man/DownsideDeviation.Rd	2012-06-21 14:19:44 UTC (rev 2045)
@@ -126,11 +126,10 @@
 \examples{
 #with data used in Bacon 2008
 
-portfolio_return <- c(0.3,2.6,1.1,-1.0,1.5,2.5,1.6,6.7,-1.4,4.0,-0.5,8.1,4.0,-3.7,
--6.1,1.7,-4.9,-2.2,7.0,5.8,-6.5,2.4,-0.5,-0.9)
+data(portfolio_bacon)
 MAR = 0.5
-DownsideDeviation(portfolio_return, MAR) #expected 2.55
-DownsidePotential(portfolio_return, MAR) #expected 1.37
+DownsideDeviation(portfolio_bacon, MAR) #expected 2.55
+DownsidePotential(portfolio_bacon, MAR) #expected 1.37
 
 #with data of managers
 

Modified: pkg/PerformanceAnalytics/man/DownsideFrequency.Rd
===================================================================
--- pkg/PerformanceAnalytics/man/DownsideFrequency.Rd	2012-06-20 16:03:56 UTC (rev 2044)
+++ pkg/PerformanceAnalytics/man/DownsideFrequency.Rd	2012-06-21 14:19:44 UTC (rev 2045)
@@ -31,7 +31,7 @@
 \examples{
 data(portfolio_bacon)
 MAR = 0.5
-print(DownsideFrequency(portfolio_return, MAR)) #expected 0.458
+print(DownsideFrequency(portfolio_bacon, MAR)) #expected 0.458
 
 data(managers)
 print(DownsideFrequency(managers['1996']))

Modified: pkg/PerformanceAnalytics/man/UpsideFrequency.Rd
===================================================================
--- pkg/PerformanceAnalytics/man/UpsideFrequency.Rd	2012-06-20 16:03:56 UTC (rev 2044)
+++ pkg/PerformanceAnalytics/man/UpsideFrequency.Rd	2012-06-21 14:19:44 UTC (rev 2045)
@@ -31,7 +31,7 @@
 \examples{
 data(portfolio_bacon)
 MAR = 0.5
-print(UpsideFrequency(portfolio_return, MAR)) #expected 0.542
+print(UpsideFrequency(portfolio_bacon, MAR)) #expected 0.542
 
 data(managers)
 print(UpsideFrequency(managers['1996']))

Modified: pkg/PerformanceAnalytics/man/UpsideRisk.Rd
===================================================================
--- pkg/PerformanceAnalytics/man/UpsideRisk.Rd	2012-06-20 16:03:56 UTC (rev 2044)
+++ pkg/PerformanceAnalytics/man/UpsideRisk.Rd	2012-06-21 14:19:44 UTC (rev 2045)
@@ -53,12 +53,16 @@
   of the series falling below the MAR.
 }
 \examples{
-portfolio_return <- c(0.3,2.6,1.1,-1.0,1.5,2.5,1.6,6.7,-1.4,4.0,-0.5,8.1,4.0
-,-3.7,-6.1,1.7,-4.9,-2.2,7.0,5.8,-6.5,2.4,-0.5,-0.9)
+data(portfolio_bacon)
 MAR = 0.5
-print(UpsideRisk(portfolio_return, MAR, stat="risk")) #expected 2.937
-print(UpsideRisk(portfolio_return, MAR, stat="variance")) #expected 8.628
-print(UpsideRisk(portfolio_return, MAR, stat="potential")) #expected 1.771
+print(UpsideRisk(portfolio_bacon, MAR, stat="risk")) #expected 2.937
+print(UpsideRisk(portfolio_bacon, MAR, stat="variance")) #expected 8.628
+print(UpsideRisk(portfolio_bacon, MAR, stat="potential")) #expected 1.771
+
+MAR = 0
+data(managers)
+print(UpsideRisk(managers['1996'], MAR, stat="risk"))
+print(UpsideRisk(managers['1996',1], MAR, stat="risk")) #expected 1.820
 }
 \author{
   Matthieu Lestel



More information about the Returnanalytics-commits mailing list