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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed Jun 20 17:42:55 CEST 2012


Author: matthieu_lestel
Date: 2012-06-20 17:42:55 +0200 (Wed, 20 Jun 2012)
New Revision: 2043

Added:
   pkg/PerformanceAnalytics/R/BernadoLedoitratio.R
   pkg/PerformanceAnalytics/man/BernardoLedoitratio.Rd
Log:
addition of Bernado and Ledoit ratio and its documentation

Added: pkg/PerformanceAnalytics/R/BernadoLedoitratio.R
===================================================================
--- pkg/PerformanceAnalytics/R/BernadoLedoitratio.R	                        (rev 0)
+++ pkg/PerformanceAnalytics/R/BernadoLedoitratio.R	2012-06-20 15:42:55 UTC (rev 2043)
@@ -0,0 +1,53 @@
+#' Bernardo and Ledoit ratio of the return distribution
+#'
+#' To calculate Bernado and Ledoit ratio we take the sum of the subset of
+#' returns that are above 0 and we divide it by the opposite of the sum of
+#' the subset of returns that are below 0
+#'
+#' \deqn{BernadoLedoitratio(R) = \frac{\frac{1}{n}\sum^{n}_{t=1}{max(R_{t},0)}}{\frac{1}{n}\sum^{n}_{t=1}
+#' {max(-R_{t},0)}}}{BernadoLedoitratio(R) = 1/n*sum
+#' (t=1..n)(max(R(t),0)) / 1/n*sum(t=1..n)(max(-R(t),0))}
+#'
+#' where \eqn{n} is the number of observations of the entire series
+#' 
+#' @aliases BernardoLedoitRatio
+#' @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(BernadoLedoitratio(portfolio_return)) #expected 1.78
+#'
+#' data(managers)
+#' print(BernadoLedoitratio(managers['1996']))
+#' print(BernadoLedoitratio(managers['1996',1])) #expected 4.598
+#'
+#' @export 
+
+BernardoLedoitratio <- 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)
+       result = sum(r1)/-sum(r2)    
+       reclass(result, R0)
+       return(result)
+    }  
+    else {
+        R = checkData(R)
+        result = apply(R, MARGIN = 2, BernardoLedoitratio, ...)
+        result<-t(result)
+        colnames(result) = colnames(R)
+        rownames(result) = paste("Bernardo and Ledoit ratio", sep="")
+        return(result)
+    }
+}
\ No newline at end of file

Added: pkg/PerformanceAnalytics/man/BernardoLedoitratio.Rd
===================================================================
--- pkg/PerformanceAnalytics/man/BernardoLedoitratio.Rd	                        (rev 0)
+++ pkg/PerformanceAnalytics/man/BernardoLedoitratio.Rd	2012-06-20 15:42:55 UTC (rev 2043)
@@ -0,0 +1,48 @@
+\name{BernardoLedoitratio}
+\alias{BernardoLedoitratio}
+\alias{BernardoLedoitRatio}
+\title{Bernardo and Ledoit ratio of the return distribution}
+\usage{
+  BernardoLedoitratio(R, ...)
+}
+\arguments{
+  \item{R}{an xts, vector, matrix, data frame, timeSeries
+  or zoo object of asset returns}
+
+  \item{\dots}{any other passthru parameters}
+}
+\description{
+  To calculate Bernado and Ledoit ratio we take the sum of
+  the subset of returns that are above 0 and we divide it
+  by the opposite of the sum of the subset of returns that
+  are below 0
+}
+\details{
+  \deqn{BernadoLedoitratio(R) =
+  \frac{\frac{1}{n}\sum^{n}_{t=1}{max(R_{t},0)}}{\frac{1}{n}\sum^{n}_{t=1}
+  {max(-R_{t},0)}}}{BernadoLedoitratio(R) = 1/n*sum
+  (t=1..n)(max(R(t),0)) / 1/n*sum(t=1..n)(max(-R(t),0))}
+
+  where \eqn{n} is the number of observations of the entire
+  series
+}
+\examples{
+data(portfolio_bacon)
+print(BernadoLedoitratio(portfolio_return)) #expected 1.78
+
+data(managers)
+print(BernadoLedoitratio(managers['1996']))
+print(BernadoLedoitratio(managers['1996',1])) #expected 4.598
+}
+\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}
+



More information about the Returnanalytics-commits mailing list