[Returnanalytics-commits] r2053 - pkg/PortfolioAnalytics/sandbox/attribution/R

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sun Jun 24 19:05:36 CEST 2012


Author: ababii
Date: 2012-06-24 19:05:36 +0200 (Sun, 24 Jun 2012)
New Revision: 2053

Modified:
   pkg/PortfolioAnalytics/sandbox/attribution/R/Carino.R
   pkg/PortfolioAnalytics/sandbox/attribution/R/Frongello.R
   pkg/PortfolioAnalytics/sandbox/attribution/R/Grap.R
   pkg/PortfolioAnalytics/sandbox/attribution/R/Menchero.R
Log:
- adjusted/unadjusted effects

Modified: pkg/PortfolioAnalytics/sandbox/attribution/R/Carino.R
===================================================================
--- pkg/PortfolioAnalytics/sandbox/attribution/R/Carino.R	2012-06-24 17:04:32 UTC (rev 2052)
+++ pkg/PortfolioAnalytics/sandbox/attribution/R/Carino.R	2012-06-24 17:05:36 UTC (rev 2053)
@@ -1,4 +1,4 @@
-#' calculates total attribution effects using logarithmic linking 
+#' calculates total attribution effects using logarithmic smoothing 
 #' 
 #' Calculates total attribution effects over multiple periods using 
 #' logarithmic linking method. Used internally by the \code{\link{Attribution}} 
@@ -25,6 +25,10 @@
 #' @param rp xts of portfolio returns
 #' @param rb xts of benchmark returns
 #' @param attributions  xts with attribution effects
+#' @return returns a data frame with original attribution effects and total 
+#' attribution effects over multiple periods
+#' @param adjusted TRUE/FALSE, whether to show original or smoothed attribution
+#' effects for each period
 #' @author Andrii Babii
 #' @seealso  \code{\link{Attribution}} \cr \code{\link{Menchero}} \cr 
 #' \code{\link{Grap}} \cr \code{\link{Frongello}} \cr
@@ -42,11 +46,11 @@
 #' @examples
 #' 
 #' data(attrib)
-#' Carino(rp, rb, allocation)
+#' Carino(rp, rb, allocation, adjusted = FALSE)
 #' 
 #' @export
 Carino <- 
-function(rp, rb, attributions)
+function(rp, rb, attributions, adjusted)
 {   # @author Andrii Babii
   
     # DESCRIPTION:
@@ -75,8 +79,14 @@
       }
     }
     kt = matrix(rep(kt, ncol(attributions)), nrow(attributions), ncol(attributions), byrow = FALSE)
-    total = colSums(attributions * kt / k)
-    attributions = rbind(as.data.frame(attributions), total)
+    adj = attributions * kt / k 
+    total = colSums(adj)
+    if (adjusted == FALSE){
+        attributions = rbind(as.data.frame(attributions), total)
+    } else{
+        attributions = rbind(as.data.frame(adj), total)
+    }
     rownames(attributions)[nrow(attributions)] = "Total"
+    
     return(attributions)
 }
\ No newline at end of file

Modified: pkg/PortfolioAnalytics/sandbox/attribution/R/Frongello.R
===================================================================
--- pkg/PortfolioAnalytics/sandbox/attribution/R/Frongello.R	2012-06-24 17:04:32 UTC (rev 2052)
+++ pkg/PortfolioAnalytics/sandbox/attribution/R/Frongello.R	2012-06-24 17:05:36 UTC (rev 2053)
@@ -1,9 +1,9 @@
-#' calculates total attribution effects using Frongello linking 
+#' calculates total attribution effects using Frongello smoothing 
 #' 
 #' Calculates total attribution effects over multiple periods using 
-#' logarithmic linking method. Used internally by the \code{\link{Attribution}} 
+#' Frongello linking method. Used internally by the \code{\link{Attribution}} 
 #' function. Arithmetic attribution effects do not naturally link over time. 
-#' This function uses logarithmic smoothing algorithms to adjust
+#' This function uses Frongello smoothing algorithm to adjust
 #' attribution effects so that they can be summed up over multiple periods
 #' Adjusted attribution effect at period t are:
 #' \deqn{A_{t}' = A_{t}\times\overset{t-1}{\underset{i=1}{\prod}}(1+r_{i})+b_{t}\times\overset{t-1}{\underset{i=1}{\sum}}A_{i}'}
@@ -19,28 +19,28 @@
 #' @param rp xts of portfolio returns
 #' @param rb xts of benchmark returns
 #' @param attributions  xts with attribution effects
+#' @param adjusted TRUE/FALSE, whether to show original or smoothed attribution
+#' effects for each period
+#' @return returns a data frame with original attribution effects and total 
+#' attribution effects over multiple periods
 #' @author Andrii Babii
 #' @seealso  \code{\link{Attribution}} \cr \code{\link{Menchero}} \cr 
 #' \code{\link{Grap}} \cr \code{\link{Carino}} \cr
 #' \code{\link{Attribution.geometric}}
-#' @references Christopherson, Jon A., Carino, David R., Ferson, Wayne E.  
-#' \emph{Portfolio Performance Measurement and Benchmarking}. McGraw-Hill. 2009. 
-#' Chapter 19
-#' 
-#' Bacon, C. \emph{Practical Portfolio Performance Measurement and
+#' @references Bacon, C. \emph{Practical Portfolio Performance Measurement and
 #' Attribution}. Wiley. 2004. p. 199-201
 #' 
 #' Frongello, A. (2002) \emph{Linking single period attribution results}.
 #' Journal of Performance Measurement. Spring, 10–22.
-#' @keywords attribution, Frongello linking
+#' @keywords arithmetic attribution, Frongello linking
 #' @examples
 #' 
 #' data(attrib)
-#' Frongello(rp, rb, allocation)
+#' Frongello(rp, rb, allocation, adjusted = FALSE)
 #' 
 #' @export
 Frongello <-
-function(rp, rb, attributions)
+function(rp, rb, attributions, adjusted)
 {   # @author Andrii Babii
   
     # DESCRIPTION:
@@ -57,17 +57,21 @@
     # and total attribution effects over multiple periods
     
     # FUNCTION:
-    attr = attributions
+    adj = attributions
     if (nrow(rp) > 1){
-        attr[2, ] = coredata(attr[2, ]) * drop((1 + rp[1, 1])) + drop(rb[2, 1]) * coredata(attr[1, ])
+        adj[2, ] = coredata(adj[2, ]) * drop((1 + rp[1, 1])) + drop(rb[2, 1]) * coredata(adj[1, ])
     }
     if (nrow(rp) > 2){
         for(i in 3:nrow(rp)){
-            attr[i, ] = coredata(attr[i, ]) * drop(prod(1 + rp[1:(i-1), 1])) + drop(rb[i, ]) * coredata(colSums(attr[1:(i-1), ]))
+            adj[i, ] = coredata(adj[i, ]) * drop(prod(1 + rp[1:(i-1), 1])) + drop(rb[i, ]) * coredata(colSums(adj[1:(i-1), ]))
         }
     }
-    total = colSums(attr)
-    attributions = rbind(as.data.frame(attributions), total)
+    total = colSums(adj)
+    if (adjusted == FALSE){
+      attributions = rbind(as.data.frame(attributions), total)
+    } else{
+      attributions = rbind(as.data.frame(adj), total)
+    }
     rownames(attributions)[nrow(attributions)] = "Total"
     return(attributions)
 }

Modified: pkg/PortfolioAnalytics/sandbox/attribution/R/Grap.R
===================================================================
--- pkg/PortfolioAnalytics/sandbox/attribution/R/Grap.R	2012-06-24 17:04:32 UTC (rev 2052)
+++ pkg/PortfolioAnalytics/sandbox/attribution/R/Grap.R	2012-06-24 17:05:36 UTC (rev 2053)
@@ -1,10 +1,10 @@
-#' calculates total attribution effects using GRAP linking 
+#' calculates total attribution effects using GRAP smoothing 
 #' 
 #' Calculates total attribution effects over multiple periods using 
-#' logarithmic linking method. Used internally by the \code{\link{Attribution}} 
+#' GEAP linking method. Used internally by the \code{\link{Attribution}} 
 #' function. Arithmetic attribution effects do not naturally link over time. 
-#' This function uses GRAP smoothing algorithms to adjust
-#' attribution effects so that they can be summed up over multiple periods
+#' This function uses GRAP smoothing algorithm to adjust attribution effects 
+#' so that they can be summed up over multiple periods
 #' Attribution effect are multiplied by the adjustment factor 
 #' \deqn{A_{t}' = A_{t} \times G_{t}}, where 
 #' \deqn{G_{t}=\overset{t-1}{\underset{i=1}{\prod}}(1+r_{i})\times\overset{n}{\underset{i=t+1}{\prod}}(1+b_{i})}
@@ -23,6 +23,10 @@
 #' @param rp xts of portfolio returns
 #' @param rb xts of benchmark returns
 #' @param attributions  xts with attribution effects
+#' @param adjusted TRUE/FALSE, whether to show original or smoothed attribution
+#' effects for each period
+#' @return returns a data frame with original attribution effects and total 
+#' attribution effects over multiple periods
 #' @author Andrii Babii
 #' @seealso  \code{\link{Attribution}} \cr \code{\link{Menchero}} \cr 
 #' \code{\link{Carino}} \cr \code{\link{Frongello}} \cr
@@ -32,15 +36,15 @@
 #' 
 #' GRAP (Groupe de Recherche en Attribution de Performance) (1997) 
 #' \emph{Synthese des modeles d’attribution de performance}. Paris, Mars.
-#' @keywords attribution, GRAP linking
+#' @keywords arithmetic attribution, GRAP linking
 #' @examples
 #' 
 #' data(attrib)
-#' Grap(rp, rb, allocation)
+#' Grap(rp, rb, allocation, adjusted = FALSE)
 #' 
 #' @export
 Grap <-
-function(rp, rb, attributions)
+function(rp, rb, attributions, adjusted)
 {   # @author Andrii Babii
   
   
@@ -75,8 +79,13 @@
         }
     }
     g = matrix(rep(G, ncol(attributions)), nrow(attributions), ncol(attributions), byrow = FALSE)
-    total = colSums(attributions * g)
-    attributions = rbind(as.data.frame(attributions), total)
+    adj = attributions * g
+    total = colSums(adj)
+    if (adjusted == FALSE){
+      attributions = rbind(as.data.frame(attributions), total)
+    } else{
+      attributions = rbind(as.data.frame(adj), total)
+    }
     rownames(attributions)[nrow(attributions)] = "Total"
     return(attributions)
 }
\ No newline at end of file

Modified: pkg/PortfolioAnalytics/sandbox/attribution/R/Menchero.R
===================================================================
--- pkg/PortfolioAnalytics/sandbox/attribution/R/Menchero.R	2012-06-24 17:04:32 UTC (rev 2052)
+++ pkg/PortfolioAnalytics/sandbox/attribution/R/Menchero.R	2012-06-24 17:05:36 UTC (rev 2053)
@@ -1,9 +1,9 @@
-#' calculates total attribution effects using Menchero linking 
+#' calculates total attribution effects using Menchero smoothing 
 #' 
 #' Calculates total attribution effects over multiple periods using 
 #' Menchero linking method. Used internally by the \code{\link{Attribution}} 
 #' function. Arithmetic attribution effects do not naturally link over time. 
-#' This function uses Menchero smoothing algorithms to adjust
+#' This function uses Menchero smoothing algorithm to adjust
 #' attribution effects so that they can be summed up over multiple periods
 #' Attribution effect are multiplied by the adjustment factor 
 #' \deqn{A_{t}' = A_{t} \times (M +a_{t})},
@@ -26,6 +26,10 @@
 #' @param rp xts of portfolio returns
 #' @param rb xts of benchmark returns
 #' @param attributions  xts with attribution effects
+#' @param adjusted TRUE/FALSE, whether to show original or smoothed attribution
+#' effects for each period
+#' @return returns a data frame with original attribution effects and total 
+#' attribution effects over multiple periods
 #' @author Andrii Babii
 #' @seealso  \code{\link{Attribution}} \cr \code{\link{Carino}} \cr 
 #' \code{\link{Grap}} \cr \code{\link{Frongello}} \cr
@@ -39,11 +43,11 @@
 #' @examples
 #' 
 #' data(attrib)
-#' Menchero(rp, rb, allocation)
+#' Menchero(rp, rb, allocation, adjusted = FALSE)
 #' 
 #' @export
 Menchero <-
-function(rp, rb, attributions)
+function(rp, rb, attributions, adjusted)
 {   # @author Andrii Babii
     
     # DESCRIPTION:
@@ -71,8 +75,13 @@
         at = (rp.a - rb.a - M * sum(rp - rb)) * (rp - rb) / sum((rp - rb)^2)
     }
     m = matrix(rep(M + at, ncol(attributions)), nrow(attributions), ncol(attributions), byrow = FALSE)
-    total = colSums(attributions * m)
-    attributions = rbind(as.data.frame(attributions), total)
+    adj = attributions * m
+    total = colSums(adj)
+    if (adjusted == FALSE){
+      attributions = rbind(as.data.frame(attributions), total)
+    } else{
+      attributions = rbind(as.data.frame(adj), total)
+    }
     rownames(attributions)[nrow(attributions)] = "Total"
     return(attributions)
 }
\ No newline at end of file



More information about the Returnanalytics-commits mailing list