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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed Jun 27 12:26:07 CEST 2012


Author: ababii
Date: 2012-06-27 12:26:07 +0200 (Wed, 27 Jun 2012)
New Revision: 2083

Modified:
   pkg/PortfolioAnalytics/sandbox/attribution/R/Attribution.geometric.R
   pkg/PortfolioAnalytics/sandbox/attribution/R/attribution.R
Log:
- Multi-currency geometric attribution

Modified: pkg/PortfolioAnalytics/sandbox/attribution/R/Attribution.geometric.R
===================================================================
--- pkg/PortfolioAnalytics/sandbox/attribution/R/Attribution.geometric.R	2012-06-26 21:52:36 UTC (rev 2082)
+++ pkg/PortfolioAnalytics/sandbox/attribution/R/Attribution.geometric.R	2012-06-27 10:26:07 UTC (rev 2083)
@@ -8,23 +8,51 @@
 #' , where
 #' \deqn{A_{t}^{G}} - total allocation effect at time t
 #' \deqn{S_{t}^{G}} - total selection effect at time t
-#' \deqn{A_{t}^{G}=\frac{1+b_{s}}{1+b_{t}}-1}
-#' \deqn{S_{t}^{G}=\frac{1+r_{t}}{1+b_{s}}-1}
-#' \deqn{b_{s}=\overset{n}{\underset{i=1}{\sum}}wp_{i}\times rb_{i}}
-#' \deqn{b_{s}} - semi-notional fund
-#' \deqn{wp_{t}} - portfolio weights at time t
-#' \deqn{wb_{t}} - benchmark weights at time t
+#' \deqn{A_{t}^{G}=\frac{1+b_{S}}{1+b_{t}}-1}
+#' \deqn{S_{t}^{G}=\frac{1+r_{t}}{1+b_{S}}-1}
+#' \deqn{b_{S}=\overset{n}{\underset{i=1}{\sum}}wp_{i}\times rb_{i}}
+#' \deqn{b_{S}} - semi-notional fund
+#' \deqn{w_{pt}} - portfolio weights at time t
+#' \deqn{w_{bt}} - benchmark weights at time t
 #' \deqn{r_{t}} - portfolio returns at time t
 #' \deqn{b_{t}} - benchmark returns at time t
 #' \deqn{r} - total portfolio returns
 #' \deqn{b} - total benchmark returns
 #' \deqn{n} - number of periods
-#'
+#' The multi-currency geometric attribution is handled following the Appendix A
+#' (Bacon, 2004). 
+#' 
+#' The individual selection effects are computed using:
+#' \deqn{w_{pi}\times\left(\frac{1+R_{pLi}}{1+R_{bLi}}-1\right)\times\left(\frac{1+R_{bLi}}{1+b_{SL}}\right)}
+#' The individual allocation effects are computed using:
+#' \deqn{(w_{pi}-w_{bi})\times\left(\frac{1+R_{bHi}}{1+b_{L}}-1\right)}
+#' where
+#' \deqn{b_{SH} = \underset{i}{\sum}((w_{pi} - w_{bi})R_{bHi} + w_{bi}R_{bLi})}
+#' - total semi-notional return hedged into the base currency 
+#' \deqn{b_{SL} = \underset{i}{\sum}w_{pi}R_{bLi}} - total semi-notional return
+#' in the local currency
+#' \deqn{w_{pi}} - portfolio weights of asset i
+#' \deqn{w_{bi}} - benchmark weights of asset i
+#' \deqn{R_{pLi}} - portfolio returns in the local currency
+#' \deqn{R_{bLi}}} - benchmark returns in the local currency
+#' \deqn{R_{bHi}} - benchmark returns hendged into the base currency
+#' \deqn{b_{L}} - total benchmark returns in the local currency
+#' \deqn{r_{L}} - total portfolio returns in the local currency
+#' The total excess returns are decomposed into:
+#' \deqn{\frac{(1+r)}{1+b}-1=\frac{1+r_{L}}{1+b_{SL}}\times\frac{1+b_{SH}}{1+b_{L}}\times\frac{1+b_{SL}}{1+b_{SH}}\times\frac{1+r}{1+r_{L}}\times\frac{1+b_{L}}{1+b}-1}
+#' where the first term corresponds to the selection, second to the allocation,
+#' third to the hedging cost transferred and the last two to the naive currency
+#' attribution
+#' 
 #' @aliases Attribution.geometric
 #' @param Rp xts of portfolio returns
 #' @param wp xts of portfolio weights
 #' @param Rb xts of benchmark returns
 #' @param wb xts of benchmark weights
+#' @param Rpl xts, data frame or matrix of portfolio returns in local currency
+#' @param Rbl xts, data frame or matrix of benchmark returns in local currency
+#' @param Rbh xts, data frame or matrix of benchmark returns hedged into the
+#' base currency
 #' @return This function returns the list with attribution effects (allocation
 #' or selection effect) including total multi-period  attribution effects
 #' @author Andrii Babii
@@ -34,7 +62,7 @@
 #' 2009. Chapter 18-19
 #' 
 #' Bacon, C. \emph{Practical Portfolio Performance Measurement and
-#' Attribution}. Wiley. 2004. Chapter 5, 8
+#' Attribution}. Wiley. 2004. Chapter 5, 8, Appendix A
 #' @keywords attribution, geometric attribution, geometric linking
 #' @examples
 #' 
@@ -43,7 +71,7 @@
 #' 
 #' @export
 Attribution.geometric <-
-function(Rp, wp, Rb, wb)
+function(Rp, wp, Rb, wb, Rpl, Rbl, Rbh, currency = FALSE)
 {   # @author Andrii Babii
   
     # DESCRIPTION:
@@ -65,9 +93,29 @@
     names(rp) = "Total"                    
     names(rb) = "Total"                 
     bs = reclass(rowSums((wp * Rb[, 1:ncol(wp)])), rp) # Allocation notional fund returns
-    allocation = ((1 + Rb) / (1 + rep(rb, ncol(Rp))) - 1) * (wp - wb) # Geometric attribution effects for individual categories
-    selection = wp * (Rp - Rb) / (1 + rep(bs, ncol(Rp)))
-    allocation = cbind(allocation, rowSums(allocation)) # Total effects
+    if (!currency){
+        allocation = ((1 + Rb) / (1 + rep(rb, ncol(Rp))) - 1) * (wp - wb) # Geometric attribution effects for individual categories
+        selection = wp * (Rp - Rb) / (1 + rep(bs, ncol(Rp)))
+
+    } else{
+        Rpl = checkData(Rpl)
+        Rbl = checkData(Rbl)
+        Rbh = checkData(Rbh)
+        
+        bsl = reclass(rowSums(Rbl * wp), Rpl)
+        bsh = reclass(rowSums(((wp - wb) * Rbh + wb * Rbl)), Rpl)
+        rpl = reclass(rowSums(Rpl * wp), Rpl)
+        rbl = reclass(rowSums(Rbl * wp), Rpl)
+        allocation = (wp - wb) * ((1 + Rbh) / (1 + rep(rbl, ncol(Rbh))) - 1)
+        selection = wp * ((1 + Rpl) / (1 + Rbl) - 1) * ((1 + Rbl) / (1 + rep(bsl, ncol(Rbl))))
+        hedge = (1 + bsl) / (1 + bsh) - 1
+        currency.attr = (1 + rp) * (1 + rbl) / (1 + rpl) / (1 + rb) - 1
+        curr = cbind(hedge, currency.attr)
+        colnames(curr) = c("Hedging", "Currency attribution")
+    }
+    
+    # Total attribution effects are computed as a sum of individual effects
+    allocation = cbind(allocation, rowSums(allocation)) 
     selection = cbind(selection, rowSums(selection))
     colnames(allocation)[ncol(allocation)] = "Total"
     colnames(selection)[ncol(selection)] = "Total"
@@ -92,6 +140,12 @@
     result[[1]] = excess.returns
     result[[2]] = allocation
     result[[3]] = selection
-    names(result) = c("Excess returns", "Allocation", "Selection")
+    if (!currency){
+        names(result) = c("Excess returns", "Allocation", "Selection")
+    } else{
+        result[[4]] = curr
+        names(result) = c("Excess returns", "Allocation", "Selection", "Currency management")
+    }
+    
     return(result)
 }
\ No newline at end of file

Modified: pkg/PortfolioAnalytics/sandbox/attribution/R/attribution.R
===================================================================
--- pkg/PortfolioAnalytics/sandbox/attribution/R/attribution.R	2012-06-26 21:52:36 UTC (rev 2082)
+++ pkg/PortfolioAnalytics/sandbox/attribution/R/attribution.R	2012-06-27 10:26:07 UTC (rev 2083)
@@ -92,10 +92,14 @@
 #' currency forward contracts
 #' @param wbf vector, xts, data frame or matrix with benchmark weights of 
 #' currency forward contracts
-#' @param S (T+1) x n xts, data.frame or matrix with spot rates. The first date
+#' @param S (T+1) x n xts, data frame or matrix with spot rates. The first date
 #' should coincide with the first date of portfolio returns
-#' @param F (T+1) x n xts, data.frame or matrix with forward rates. The first
+#' @param F (T+1) x n xts, data frame or matrix with forward rates. The first
 #' date should coincide with the first date of portfolio returns
+#' @param Rpl xts, data frame or matrix of portfolio returns in local currency
+#' @param Rbl xts, data frame or matrix of benchmark returns in local currency
+#' @param Rbh xts, data frame or matrix of benchmark returns hedged into the
+#' base currency
 #' @param linking Used to select the linking method to present the multi-period 
 #' summary of arithmetic attribution effects. It is also used to select the 
 #' geometric attribution. May be any of: \itemize{ \item carino - logarithmic 
@@ -110,12 +114,12 @@
 #' annualized excess returns over all periods, attribution effects (allocation, 
 #' selection and interaction)
 #' @author Andrii Babii
-#' @seealso \code{\link{Attribution.levels}}
+#' @seealso \code{\link{Attribution.levels}}, \code{\link{Attribution.geometric}}
 #' @references Ankrim, E. and Hensel, C. \emph{Multi-currency performance
 #' attribution}.Russell Research Commentary.November 2002
 #' 
 #' Bacon, C. \emph{Practical Portfolio Performance Measurement and
-#' Attribution}. Wiley. 2004. Chapter 5, 8
+#' Attribution}. Wiley. 2004. Chapter 5, 6, 8
 #' 
 #' Christopherson, Jon A., Carino, David R., Ferson, Wayne E.  
 #' \emph{Portfolio Performance Measurement and Benchmarking}. McGraw-Hill. 2009. 
@@ -124,6 +128,10 @@
 #' Gary P. Brinson, L. Randolph Hood, and Gilbert L. Beebower, \emph{Determinants of 
 #' Portfolio Performance}, Financial Analysts Journal, vol. 42, no. 4, July/August 
 #' 1986, pp. 39–44.
+#' 
+#' Karnosky, D. and Singer, B. \emph{Global asset management and performance
+#' attribution.The Research Foundation of the Institute of Chartered Financial
+#' Analysts}. February 1994.
 #' @keywords attribution
 #' @examples
 #' 
@@ -134,7 +142,8 @@
 #' total effects for individual segments in Davies-Laker and Geometric
 #' @export
 Attribution <- 
-function (Rp, wp, Rb, wb, wpf = "none", wbf = "none", S = "none", F = "none", 
+function (Rp, wp, Rb, wb, wpf, wbf, S, F, Rpl, Rbl, Rbh, 
+          currency = FALSE,
           method = c("none", "top.down", "bottom.up"), 
           linking = c("carino", "menchero", "grap", "frongello", "davies.laker"),
           geometric = FALSE, adjusted = FALSE)
@@ -165,8 +174,7 @@
     }
     
     # Compute attribution effects (Brinson, Hood and Beebower model)
-    if (wpf == "none" & wbf == "none" & S == "none" & F =="none"){ 
-             # If portfolio is single-currency
+    if (!currency){ # If portfolio is single-currency
         Rc = 0
         L = 0
     } else{  # If multi-currency portfolio
@@ -280,10 +288,10 @@
     }
     
     # If multi-currency portfolio
-    if (!(wpf == "none" & wbf == "none" & S == "none" & F =="none")){
+    if (currency){
         result[[length(result) + 1]] = Cc
         result[[length(result) + 1]] = Df
-        names(result)[(length(result)-1):length(result)] = c("Contribution from currency", "Forward Premium")
+        names(result)[(length(result)-1):length(result)] = c("Currency management", "Forward Premium")
     }
     return(result)
 }
\ No newline at end of file



More information about the Returnanalytics-commits mailing list