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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Mon Jun 25 18:34:57 CEST 2012


Author: matthieu_lestel
Date: 2012-06-25 18:34:57 +0200 (Mon, 25 Jun 2012)
New Revision: 2072

Added:
   pkg/PerformanceAnalytics/R/CAPM.jensenAlpha.R
   pkg/PerformanceAnalytics/man/CAPM.jensenAlpha.Rd
Modified:
   pkg/PerformanceAnalytics/R/CAPM.epsilon.R
   pkg/PerformanceAnalytics/man/CAPM.epsilon.Rd
Log:
jensen's alpha with exemples and documentation

Modified: pkg/PerformanceAnalytics/R/CAPM.epsilon.R
===================================================================
--- pkg/PerformanceAnalytics/R/CAPM.epsilon.R	2012-06-25 14:11:34 UTC (rev 2071)
+++ pkg/PerformanceAnalytics/R/CAPM.epsilon.R	2012-06-25 16:34:57 UTC (rev 2072)
@@ -7,7 +7,7 @@
 #' {epsilon_r = r_p - alpha_r - beta_r * b}
 #'
 #' where \eqn{\alpha_r} is the regression alpha, \eqn{\beta_r} is the regression beta,
-#' \eqn{r} is the portfolio return and b is the benchmark return
+#' \eqn{r_p} is the portfolio return and b is the benchmark return
 #'
 #' @aliases Regression epsilon
 #' @param Ra an xts, vector, matrix, data frame, timeSeries or zoo object of
@@ -40,21 +40,21 @@
 
     if (ncol(Ra)==1 || is.null(Ra) || is.vector(Ra)) {
     
-     Rp = (prod(0.01*Ra+1)-1)*100 #portfolio total return
-     Rpb = (prod(0.01*Rb+1)-1)*100 #benchmark total return
-     for (i in (1:length(Ra))) {
-     if (!is.na(Ra[i])) {
-     calcul = TRUE
-}
-}
+       Rp = (prod(0.01*Ra+1)-1)*100 #portfolio total return
+       Rpb = (prod(0.01*Rb+1)-1)*100 #benchmark total return
+       for (i in (1:length(Ra))) {
+          if (!is.na(Ra[i])) {
+             calcul = TRUE
+          }
+        }
 
-     if (calcul) {
-     result = Rf + Rp - CAPM.alpha(Ra,Rb,Rf) - (Rpb - Rf) * CAPM.beta(Ra,Rb,Rf) 
-}   
-    else {
-    result = NA
-}
-     return(result)
+        if (calcul) {
+           result = Rf + Rp - CAPM.alpha(Ra,Rb,Rf) - (Rpb - Rf) * CAPM.beta(Ra,Rb,Rf) 
+        }   
+        else {
+           result = NA
+        }
+        return(result)
     }
     else {
         Ra = checkData(Ra)

Added: pkg/PerformanceAnalytics/R/CAPM.jensenAlpha.R
===================================================================
--- pkg/PerformanceAnalytics/R/CAPM.jensenAlpha.R	                        (rev 0)
+++ pkg/PerformanceAnalytics/R/CAPM.jensenAlpha.R	2012-06-25 16:34:57 UTC (rev 2072)
@@ -0,0 +1,67 @@
+#' Jensen's alpha of the return distribution
+#'
+#' The Jensen's alpha is the intercept of the regression equation in the Capital
+#' Asset Pricing Model and is in effect the exess return adjusted for systematic risk.
+#'
+#' \deqn{\alpha = r_p - r_f - \beta_p * (b - r_f)} 
+#' {alpha = r_p - r_f - beta_p * (b - r_f)}
+#'
+#' where \eqn{r_f} is the systematic risk, \eqn{\beta_r} is the regression beta,
+#' \eqn{r_p} is the portfolio return and b is the benchmark return
+#'
+#' @aliases Regression epsilon
+#' @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.72
+#' 
+#' @keywords ts multivariate distribution models
+#' @examples
+#'
+#' data(portfolio_bacon)
+#' print(CAPM.jensenAlpha(portfolio_bacon[,1], portfolio_bacon[,2])) #expected -3.14938
+#'
+#' data(managers)
+#' print(CAPM.jensenAlpha(managers['1996',1], managers['1996',8]))
+#' print(CAPM.jensenAlpha(managers['1996',1:5], managers['1996',8]))
+#'
+#' @export 
+
+CAPM.jensenAlpha <-
+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)) {
+    
+     Rp = (prod(0.01*Ra+1)-1)*100 #portfolio total return
+     Rpb = (prod(0.01*Rb+1)-1)*100 #benchmark total return
+     for (i in (1:length(Ra))) {
+     	 if (!is.na(Ra[i])) {
+     	    calcul = TRUE
+	 }
+      }
+
+     if (calcul) {
+        result = Rp - Rf - CAPM.beta(Ra,Rb,Rf) * (Rpb - Rf) 
+     }    
+     else {
+        result = NA
+     }
+      return(result)
+    }
+    else {
+        Ra = checkData(Ra)
+        result = apply(Ra, MARGIN = 2, CAPM.jensenAlpha, Rb = Rb, Rf = Rf, ...)
+        result<-t(result)
+        colnames(result) = colnames(Ra)
+        rownames(result) = paste("Jensen's Alpha (Risk free = ",Rf,")", sep="")
+        return(result)
+    }
+}

Modified: pkg/PerformanceAnalytics/man/CAPM.epsilon.Rd
===================================================================
--- pkg/PerformanceAnalytics/man/CAPM.epsilon.Rd	2012-06-25 14:11:34 UTC (rev 2071)
+++ pkg/PerformanceAnalytics/man/CAPM.epsilon.Rd	2012-06-25 16:34:57 UTC (rev 2072)
@@ -26,7 +26,7 @@
   {epsilon_r = r_p - alpha_r - beta_r * b}
 
   where \eqn{\alpha_r} is the regression alpha,
-  \eqn{\beta_r} is the regression beta, \eqn{r} is the
+  \eqn{\beta_r} is the regression beta, \eqn{r_p} is the
   portfolio return and b is the benchmark return
 }
 \examples{

Added: pkg/PerformanceAnalytics/man/CAPM.jensenAlpha.Rd
===================================================================
--- pkg/PerformanceAnalytics/man/CAPM.jensenAlpha.Rd	                        (rev 0)
+++ pkg/PerformanceAnalytics/man/CAPM.jensenAlpha.Rd	2012-06-25 16:34:57 UTC (rev 2072)
@@ -0,0 +1,51 @@
+\name{CAPM.jensenAlpha}
+\alias{CAPM.jensenAlpha}
+\alias{epsilon}
+\alias{Regression}
+\title{Jensen's alpha of the return distribution}
+\usage{
+  CAPM.jensenAlpha(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{
+  The Jensen's alpha is the intercept of the regression
+  equation in the Capital Asset Pricing Model and is in
+  effect the exess return adjusted for systematic risk.
+}
+\details{
+  \deqn{\alpha = r_p - r_f - \beta_p * (b - r_f)} {alpha =
+  r_p - r_f - beta_p * (b - r_f)}
+
+  where \eqn{r_f} is the systematic risk, \eqn{\beta_r} is
+  the regression beta, \eqn{r_p} is the portfolio return
+  and b is the benchmark return
+}
+\examples{
+data(portfolio_bacon)
+print(CAPM.jensenAlpha(portfolio_bacon[,1], portfolio_bacon[,2])) #expected -3.14938
+
+data(managers)
+print(CAPM.jensenAlpha(managers['1996',1], managers['1996',8]))
+print(CAPM.jensenAlpha(managers['1996',1:5], managers['1996',8]))
+}
+\author{
+  Matthieu Lestel
+}
+\references{
+  Carl Bacon, \emph{Practical portfolio performance
+  measurement and attribution}, second edition 2008 p.72
+}
+\keyword{distribution}
+\keyword{models}
+\keyword{multivariate}
+\keyword{ts}
+



More information about the Returnanalytics-commits mailing list