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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Tue Jun 26 15:43:13 CEST 2012


Author: matthieu_lestel
Date: 2012-06-26 15:43:12 +0200 (Tue, 26 Jun 2012)
New Revision: 2081

Added:
   pkg/PerformanceAnalytics/R/SystematicRisk.R
   pkg/PerformanceAnalytics/man/SystematicRisk.Rd
Modified:
   pkg/PerformanceAnalytics/R/CAPM.jensenAlpha.R
   pkg/PerformanceAnalytics/man/CAPM.jensenAlpha.Rd
Log:
Systematic risk with exemples and documentation

Modified: pkg/PerformanceAnalytics/R/CAPM.jensenAlpha.R
===================================================================
--- pkg/PerformanceAnalytics/R/CAPM.jensenAlpha.R	2012-06-26 09:59:03 UTC (rev 2080)
+++ pkg/PerformanceAnalytics/R/CAPM.jensenAlpha.R	2012-06-26 13:43:12 UTC (rev 2081)
@@ -6,10 +6,10 @@
 #' \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,
+#' where \eqn{r_f} is the risk free rate, \eqn{\beta_r} is the regression beta,
 #' \eqn{r_p} is the portfolio return and b is the benchmark return
 #'
-#' @aliases Regression epsilon
+#' @aliases Jensen's alpha
 #' @param Ra an xts, vector, matrix, data frame, timeSeries or zoo object of
 #' asset returns
 #' @param Rb return vector of the benchmark asset

Added: pkg/PerformanceAnalytics/R/SystematicRisk.R
===================================================================
--- pkg/PerformanceAnalytics/R/SystematicRisk.R	                        (rev 0)
+++ pkg/PerformanceAnalytics/R/SystematicRisk.R	2012-06-26 13:43:12 UTC (rev 2081)
@@ -0,0 +1,66 @@
+#' Systematic risk of the return distribution
+#'
+#' Systematic risk as defined by Bacon(2008) is the product of beta by market 
+#' risk. Be careful ! It's not the same definition as the one given by Michael
+#' Jensen. Market risk is the standard deviation of the benchmark.
+#'
+#' \deqn{\sigma_s = \beta * \sigma_m} 
+#' {systematic risk = beta * market risk}
+#'
+#' where \eqn{\sigma_s} is the systematic risk, \eqn{\beta} is the regression beta,
+#' and \eqn{\sigma_m} is the market risk
+#'
+#' @aliases systematic risk
+#' @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.75
+#' 
+#' @keywords ts multivariate distribution models
+#' @examples
+#'
+#' data(portfolio_bacon)
+#' print(SystematicRisk(portfolio_bacon[,1], portfolio_bacon[,2])) #expected 3.75
+#'
+#' data(managers)
+#' print(SystematicRisk(managers['1996',1], managers['1996',8]))
+#' print(SystematicRisk(managers['1996',1:5], managers['1996',8]))
+#'
+#' @export 
+
+SystematicRisk <-
+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)) {
+    
+     for (i in (1:length(Ra))) {
+     	 if (!is.na(Ra[i])) {
+     	    calcul = TRUE
+	 }
+      }
+
+     if (calcul) {
+        result = CAPM.beta(Ra,Rb,Rf) * sqrt(sum((Rb-mean(Rb))^2)/length(Rb))
+     }    
+     else {
+        result = NA
+     }
+      return(result)
+    }
+    else {
+        Ra = checkData(Ra)
+        result = apply(Ra, MARGIN = 2, SystematicRisk, Rb = Rb, Rf = Rf, ...)
+        result<-t(result)
+        colnames(result) = colnames(Ra)
+        rownames(result) = paste("Systematic Risk (Risk free = ",Rf,")", sep="")
+        return(result)
+    }
+}

Modified: pkg/PerformanceAnalytics/man/CAPM.jensenAlpha.Rd
===================================================================
--- pkg/PerformanceAnalytics/man/CAPM.jensenAlpha.Rd	2012-06-26 09:59:03 UTC (rev 2080)
+++ pkg/PerformanceAnalytics/man/CAPM.jensenAlpha.Rd	2012-06-26 13:43:12 UTC (rev 2081)
@@ -1,7 +1,7 @@
 \name{CAPM.jensenAlpha}
+\alias{alpha}
 \alias{CAPM.jensenAlpha}
-\alias{epsilon}
-\alias{Regression}
+\alias{Jensen's}
 \title{Jensen's alpha of the return distribution}
 \usage{
   CAPM.jensenAlpha(Ra, Rb, Rf = 0, ...)
@@ -25,7 +25,7 @@
   \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
+  where \eqn{r_f} is the risk free rate, \eqn{\beta_r} is
   the regression beta, \eqn{r_p} is the portfolio return
   and b is the benchmark return
 }

Added: pkg/PerformanceAnalytics/man/SystematicRisk.Rd
===================================================================
--- pkg/PerformanceAnalytics/man/SystematicRisk.Rd	                        (rev 0)
+++ pkg/PerformanceAnalytics/man/SystematicRisk.Rd	2012-06-26 13:43:12 UTC (rev 2081)
@@ -0,0 +1,52 @@
+\name{SystematicRisk}
+\alias{risk}
+\alias{systematic}
+\alias{SystematicRisk}
+\title{Systematic risk of the return distribution}
+\usage{
+  SystematicRisk(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{
+  Systematic risk as defined by Bacon(2008) is the product
+  of beta by market risk. Be careful ! It's not the same
+  definition as the one given by Michael Jensen. Market
+  risk is the standard deviation of the benchmark.
+}
+\details{
+  \deqn{\sigma_s = \beta * \sigma_m} {systematic risk =
+  beta * market risk}
+
+  where \eqn{\sigma_s} is the systematic risk, \eqn{\beta}
+  is the regression beta, and \eqn{\sigma_m} is the market
+  risk
+}
+\examples{
+data(portfolio_bacon)
+print(SystematicRisk(portfolio_bacon[,1], portfolio_bacon[,2])) #expected 3.75
+
+data(managers)
+print(SystematicRisk(managers['1996',1], managers['1996',8]))
+print(SystematicRisk(managers['1996',1:5], managers['1996',8]))
+}
+\author{
+  Matthieu Lestel
+}
+\references{
+  Carl Bacon, \emph{Practical portfolio performance
+  measurement and attribution}, second edition 2008 p.75
+}
+\keyword{distribution}
+\keyword{models}
+\keyword{multivariate}
+\keyword{ts}
+



More information about the Returnanalytics-commits mailing list