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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Fri Aug 3 12:47:38 CEST 2012


Author: matthieu_lestel
Date: 2012-08-03 12:47:37 +0200 (Fri, 03 Aug 2012)
New Revision: 2220

Added:
   pkg/PerformanceAnalytics/R/MartinRatio.R
   pkg/PerformanceAnalytics/R/NetSelectivity.R
   pkg/PerformanceAnalytics/R/OmegaExcessReturn.R
   pkg/PerformanceAnalytics/man/MartinRatio.Rd
   pkg/PerformanceAnalytics/man/NetSelectivity.Rd
   pkg/PerformanceAnalytics/man/OmegaExcessReturn.Rd
Modified:
   pkg/PerformanceAnalytics/NAMESPACE
   pkg/PerformanceAnalytics/R/UlcerIndex.R
   pkg/PerformanceAnalytics/man/Selectivity.Rd
Log:
Net Selectivity, Omega excess return and Martin ratio with examples and documentation

Modified: pkg/PerformanceAnalytics/NAMESPACE
===================================================================
--- pkg/PerformanceAnalytics/NAMESPACE	2012-07-30 00:53:45 UTC (rev 2219)
+++ pkg/PerformanceAnalytics/NAMESPACE	2012-08-03 10:47:37 UTC (rev 2220)
@@ -58,6 +58,7 @@
     kurtosis,
     M2Sortino,
     maxDrawdown,
+    MartinRatio,
     MeanAbsoluteDeviation,
     mean.geometric,
     mean.LCL,
@@ -65,7 +66,9 @@
     mean.UCL,
     MSquared,
     MSquaredExcess,
+    NetSelectivity,
     Omega,
+    OmegaExcessReturn,
     OmegaSharpeRatio,
 #    pfolioReturn,
     PainIndex,

Added: pkg/PerformanceAnalytics/R/MartinRatio.R
===================================================================
--- pkg/PerformanceAnalytics/R/MartinRatio.R	                        (rev 0)
+++ pkg/PerformanceAnalytics/R/MartinRatio.R	2012-08-03 10:47:37 UTC (rev 2220)
@@ -0,0 +1,64 @@
+#' Martin ratio of the return distribution
+#'
+#' To calculate Martin ratio we divide the difference of the portfolio return
+#' and the risk free rate by the Ulcer index
+#'
+#' \deqn{Martin ratio = \frac{r_P - r_F}{\sqrt{\sum^{n}_{i=1} \frac{{D'_i}^2}{n}}}}{Martin ratio = (rp - rf) / Ulcer index}
+#'
+#' where \eqn{r_P} is the annualized portfolio return, \eqn{r_F} is the risk free
+#' rate, \eqn{n} is the number of observations of the entire series, \eqn{D'_i} is
+#' the drawdown since previous peak in period i
+#'
+#' @aliases MartinRatio
+#' @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 \dots any other passthru parameters
+#' @author Matthieu Lestel
+#' @references Carl Bacon, \emph{Practical portfolio performance measurement 
+#' and attribution}, second edition 2008 p.91
+#' 
+#' @keywords ts multivariate distribution models
+#' @examples
+#' data(portfolio_bacon)
+#' print(MartinRatio(portfolio_bacon[,1])) #expected 1.70
+#'
+#' data(managers)
+#' print(MartinRatio(managers['1996']))
+#' print(MartinRatio(managers['1996',1])) 
+#'
+#' @export 
+
+
+MartinRatio <- function (R, Rf = 0, ...) 
+{
+    R = checkData(R)
+
+    if (ncol(R)==1 || is.null(R) || is.vector(R)) {
+       calcul = FALSE
+        for (i in (1:length(R))) {
+     	     if (!is.na(R[i])) {
+     	    	calcul = TRUE
+	     }
+        }		      
+       period = Frequency(R)
+       UI = UlcerIndex(R)
+       R = na.omit(R)
+       n = length(R)
+       if(!calcul) {
+	  result = NA
+	}
+	else {
+       	   Rp = Return.annualized(R)
+       	   result = (Rp - Rf) / UI
+	}
+       return(result)
+    }
+    else {
+        result = apply(R, MARGIN = 2, MartinRatio, MAR = MAR, Rf = Rf, ...)
+        result<-t(result)
+        colnames(result) = colnames(R)
+        rownames(result) = paste("Martin Ratio (Rf = ",Rf,")", sep="")
+        return(result)
+    }
+}
\ No newline at end of file

Added: pkg/PerformanceAnalytics/R/NetSelectivity.R
===================================================================
--- pkg/PerformanceAnalytics/R/NetSelectivity.R	                        (rev 0)
+++ pkg/PerformanceAnalytics/R/NetSelectivity.R	2012-08-03 10:47:37 UTC (rev 2220)
@@ -0,0 +1,67 @@
+#' Net selectivity of the return distribution
+#'
+#' Net selectivity is the remaining selectivity after deducting the amount of return
+#' require to justify not being fully diversified
+#'
+#' If net selectivity is negative the portfolio manager has not justified the loss of
+#' diversification
+#'
+#' \deqn{Net selectivity = \alpha - d}{Net selectivity = Selectity - diversification}
+#'
+#' where \eqn{\alpha} is the selectivity and \eqn{d} is the diversification
+#'
+#' @aliases NetSelectivity
+#' @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.78
+#' 
+#' @keywords ts multivariate distribution models
+#' @examples
+#'
+#' data(portfolio_bacon)
+#' print(NetSelectivity(portfolio_bacon[,1], portfolio_bacon[,2])) #expected -1.41
+#'
+#' data(managers)
+#' print(NetSelectivity(managers['1996',1], managers['1996',8]))
+#' print(NetSelectivity(managers['1996',1:5], managers['1996',8]))
+#'
+#' @export 
+
+NetSelectivity <-
+function (Ra, Rb, Rf = 0, ...)
+{
+    Ra = checkData(Ra, method="matrix")
+    Rb = checkData(Rb, method="matrix")
+
+    if (ncol(Ra)==1 || is.null(Ra) || is.vector(Ra)) {
+    calcul = FALSE    
+    for (i in (1:length(Ra))) {
+     	 if (!is.na(Ra[i])) {
+     	    calcul = TRUE
+	 }
+      }
+
+     if (calcul) {
+     	b = Return.annualized(Rb)
+     	d = (FamaBeta(Ra,Rb)-CAPM.beta(Ra,Rb,Rf)) * (b - Rf)
+        result = Selectivity(Ra,Rb,Rf) - d 
+     }    
+     else {
+        result = NA
+     }
+      return(result)
+    }
+    else {
+        Ra = checkData(Ra)
+        result = apply(Ra, MARGIN = 2, NetSelectivity, Rb = Rb, Rf = Rf, ...)
+        result<-t(result)
+        colnames(result) = colnames(Ra)
+        rownames(result) = paste("Net Selectivity (Risk free = ",Rf,")", sep="")
+        return(result)
+    }
+}

Added: pkg/PerformanceAnalytics/R/OmegaExcessReturn.R
===================================================================
--- pkg/PerformanceAnalytics/R/OmegaExcessReturn.R	                        (rev 0)
+++ pkg/PerformanceAnalytics/R/OmegaExcessReturn.R	2012-08-03 10:47:37 UTC (rev 2220)
@@ -0,0 +1,70 @@
+#' Omega excess return of the return distribution
+#'
+#' Omega excess return is another form of downside risk-adjusted return. It is
+#' calculated by multiplying the downside variance of the style benchmark by 3
+#' times the style beta.
+#'
+#' \deqn{\omega = r_P - 3*\beta_S*\sigma_{MD}^2}{ OmegaExcessReturn = Portfolio return - 3*style beta*style benchmark variance squared}
+#'
+#' where \eqn{\omega} is omega excess return, \eqn{\beta_S} is style beta, \eqn{\sigma_D} 
+#' is the portfolio annualised downside risk and \eqn{\sigma_{MD}} is the benchmark annualised downside risk.
+#'
+#' @aliases OmegaExessReturn
+#' @param Ra an xts, vector, matrix, data frame, timeSeries or zoo object of
+#' asset returns
+#' @param Rb return vector of the benchmark asset
+#' @param MAR the minimum acceptable return
+#' @param \dots any other passthru parameters
+#' @author Matthieu Lestel
+#' @references Carl Bacon, \emph{Practical portfolio performance measurement 
+#' and attribution}, second edition 2008 p.103
+#' 
+#' @keywords ts multivariate distribution models
+#' @examples
+#'
+#' data(portfolio_bacon)
+#' MAR = 0.005
+#' print(OmegaExcessReturn(portfolio_bacon[,1], portfolio_bacon[,2], MAR)) #expected 0.0805
+#'
+#' data(managers)
+#' MAR = 0
+#' print(OmegaExcessReturn(managers['1996',1], managers['1996',8], MAR))
+#' print(OmegaExcessReturn(managers['1996',1:5], managers['1996',8], MAR))
+#'
+#' @export 
+
+OmegaExcessReturn <-
+function (Ra, Rb, MAR = 0, ...)
+{
+    Ra = checkData(Ra, method="matrix")
+    Rb = checkData(Rb, method="matrix")
+
+    if (ncol(Ra)==1 || is.null(Ra) || is.vector(Ra)) {
+    calcul = FALSE    
+    for (i in (1:length(Ra))) {
+     	 if (!is.na(Ra[i])) {
+     	    calcul = TRUE
+	 }
+      }
+
+     if (calcul) {
+     	Period = Frequency(Ra)
+	Rp = Return.annualized(Ra)
+	SigmaD = DownsideDeviation(Ra,MAR)*sqrt(Period)
+	SigmaDM = DownsideDeviation(Rb,MAR)*sqrt(Period)
+        result = Rp - 3 * SigmaD * SigmaDM 
+     }    
+     else {
+        result = NA
+     }
+      return(result)
+    }
+    else {
+        Ra = checkData(Ra)
+        result = apply(Ra, MARGIN = 2, OmegaExcessReturn, Rb = Rb, MAR = MAR, ...)
+        result<-t(result)
+        colnames(result) = colnames(Ra)
+        rownames(result) = paste("Omega Excess Return (MAR = ",MAR,")", sep="")
+        return(result)
+    }
+}

Modified: pkg/PerformanceAnalytics/R/UlcerIndex.R
===================================================================
--- pkg/PerformanceAnalytics/R/UlcerIndex.R	2012-07-30 00:53:45 UTC (rev 2219)
+++ pkg/PerformanceAnalytics/R/UlcerIndex.R	2012-08-03 10:47:37 UTC (rev 2220)
@@ -34,8 +34,9 @@
     R = checkData(R)
 
     ui <- function(R) {
+        result = sqrt(sum(DrawdownPeak(R)^2))
         R = na.omit(R)
-        result = sqrt(sum(Drawdowns(R)^2)/length(R))
+	result = result/sqrt(length(R))
         return(result)
     }
 

Added: pkg/PerformanceAnalytics/man/MartinRatio.Rd
===================================================================
--- pkg/PerformanceAnalytics/man/MartinRatio.Rd	                        (rev 0)
+++ pkg/PerformanceAnalytics/man/MartinRatio.Rd	2012-08-03 10:47:37 UTC (rev 2220)
@@ -0,0 +1,49 @@
+\name{MartinRatio}
+\alias{MartinRatio}
+\title{Martin ratio of the return distribution}
+\usage{
+  MartinRatio(R, Rf = 0, ...)
+}
+\arguments{
+  \item{R}{an xts, vector, matrix, data frame, timeSeries
+  or zoo object of asset returns}
+
+  \item{Rf}{risk free rate, in same period as your returns}
+
+  \item{\dots}{any other passthru parameters}
+}
+\description{
+  To calculate Martin ratio we divide the difference of the
+  portfolio return and the risk free rate by the Ulcer
+  index
+}
+\details{
+  \deqn{Martin ratio = \frac{r_P -
+  r_F}{\sqrt{\sum^{n}_{i=1} \frac{{D'_i}^2}{n}}}}{Martin
+  ratio = (rp - rf) / Ulcer index}
+
+  where \eqn{r_P} is the annualized portfolio return,
+  \eqn{r_F} is the risk free rate, \eqn{n} is the number of
+  observations of the entire series, \eqn{D'_i} is the
+  drawdown since previous peak in period i
+}
+\examples{
+data(portfolio_bacon)
+print(MartinRatio(portfolio_bacon[,1])) #expected 1.70
+
+data(managers)
+print(MartinRatio(managers['1996']))
+print(MartinRatio(managers['1996',1]))
+}
+\author{
+  Matthieu Lestel
+}
+\references{
+  Carl Bacon, \emph{Practical portfolio performance
+  measurement and attribution}, second edition 2008 p.91
+}
+\keyword{distribution}
+\keyword{models}
+\keyword{multivariate}
+\keyword{ts}
+

Added: pkg/PerformanceAnalytics/man/NetSelectivity.Rd
===================================================================
--- pkg/PerformanceAnalytics/man/NetSelectivity.Rd	                        (rev 0)
+++ pkg/PerformanceAnalytics/man/NetSelectivity.Rd	2012-08-03 10:47:37 UTC (rev 2220)
@@ -0,0 +1,51 @@
+\name{NetSelectivity}
+\alias{NetSelectivity}
+\title{Net selectivity of the return distribution}
+\usage{
+  NetSelectivity(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{
+  Net selectivity is the remaining selectivity after
+  deducting the amount of return require to justify not
+  being fully diversified
+}
+\details{
+  If net selectivity is negative the portfolio manager has
+  not justified the loss of diversification
+
+  \deqn{Net selectivity = \alpha - d}{Net selectivity =
+  Selectity - diversification}
+
+  where \eqn{\alpha} is the selectivity and \eqn{d} is the
+  diversification
+}
+\examples{
+data(portfolio_bacon)
+print(NetSelectivity(portfolio_bacon[,1], portfolio_bacon[,2])) #expected -1.41
+
+data(managers)
+print(NetSelectivity(managers['1996',1], managers['1996',8]))
+print(NetSelectivity(managers['1996',1:5], managers['1996',8]))
+}
+\author{
+  Matthieu Lestel
+}
+\references{
+  Carl Bacon, \emph{Practical portfolio performance
+  measurement and attribution}, second edition 2008 p.78
+}
+\keyword{distribution}
+\keyword{models}
+\keyword{multivariate}
+\keyword{ts}
+

Added: pkg/PerformanceAnalytics/man/OmegaExcessReturn.Rd
===================================================================
--- pkg/PerformanceAnalytics/man/OmegaExcessReturn.Rd	                        (rev 0)
+++ pkg/PerformanceAnalytics/man/OmegaExcessReturn.Rd	2012-08-03 10:47:37 UTC (rev 2220)
@@ -0,0 +1,55 @@
+\name{OmegaExcessReturn}
+\alias{OmegaExcessReturn}
+\alias{OmegaExessReturn}
+\title{Omega excess return of the return distribution}
+\usage{
+  OmegaExcessReturn(Ra, Rb, MAR = 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{MAR}{the minimum acceptable return}
+
+  \item{\dots}{any other passthru parameters}
+}
+\description{
+  Omega excess return is another form of downside
+  risk-adjusted return. It is calculated by multiplying the
+  downside variance of the style benchmark by 3 times the
+  style beta.
+}
+\details{
+  \deqn{\omega = r_P - 3*\beta_S*\sigma_{MD}^2}{
+  OmegaExcessReturn = Portfolio return - 3*style beta*style
+  benchmark variance squared}
+
+  where \eqn{\omega} is omega excess return, \eqn{\beta_S}
+  is style beta, \eqn{\sigma_D} is the portfolio annualised
+  downside risk and \eqn{\sigma_{MD}} is the benchmark
+  annualised downside risk.
+}
+\examples{
+data(portfolio_bacon)
+MAR = 0.005
+print(OmegaExcessReturn(portfolio_bacon[,1], portfolio_bacon[,2], MAR)) #expected 0.0805
+
+data(managers)
+MAR = 0
+print(OmegaExcessReturn(managers['1996',1], managers['1996',8], MAR))
+print(OmegaExcessReturn(managers['1996',1:5], managers['1996',8], MAR))
+}
+\author{
+  Matthieu Lestel
+}
+\references{
+  Carl Bacon, \emph{Practical portfolio performance
+  measurement and attribution}, second edition 2008 p.103
+}
+\keyword{distribution}
+\keyword{models}
+\keyword{multivariate}
+\keyword{ts}
+

Modified: pkg/PerformanceAnalytics/man/Selectivity.Rd
===================================================================
--- pkg/PerformanceAnalytics/man/Selectivity.Rd	2012-07-30 00:53:45 UTC (rev 2219)
+++ pkg/PerformanceAnalytics/man/Selectivity.Rd	2012-08-03 10:47:37 UTC (rev 2220)
@@ -2,7 +2,7 @@
 \alias{Selectivity}
 \title{Selectivity of the return distribution}
 \usage{
-  Selectivity(Ra, Rb, Rf = 0, period = 12, ...)
+  Selectivity(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}{number of periods in a year monthly scale =
-  12, quarterly = 4)}
-
   \item{\dots}{any other passthru parameters}
 }
 \description{



More information about the Returnanalytics-commits mailing list