[Returnanalytics-commits] r2016 - in pkg/PortfolioAnalytics/sandbox/attribution: . R data man

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Fri Jun 15 00:20:45 CEST 2012


Author: braverock
Date: 2012-06-15 00:20:45 +0200 (Fri, 15 Jun 2012)
New Revision: 2016

Added:
   pkg/PortfolioAnalytics/sandbox/attribution/R/
   pkg/PortfolioAnalytics/sandbox/attribution/R/Attribution.geometric.R
   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
   pkg/PortfolioAnalytics/sandbox/attribution/R/Modigliani.R
   pkg/PortfolioAnalytics/sandbox/attribution/R/Return.level.R
   pkg/PortfolioAnalytics/sandbox/attribution/R/attribution.R
   pkg/PortfolioAnalytics/sandbox/attribution/R/attribution.levels.R
   pkg/PortfolioAnalytics/sandbox/attribution/R/logLinking.R
   pkg/PortfolioAnalytics/sandbox/attribution/R/logLinkingZoo.R
   pkg/PortfolioAnalytics/sandbox/attribution/R/periodApplyEZ.R
   pkg/PortfolioAnalytics/sandbox/attribution/R/relativeAttribution.R
   pkg/PortfolioAnalytics/sandbox/attribution/R/relativeAttributionWithoutFactors.R
   pkg/PortfolioAnalytics/sandbox/attribution/data/
   pkg/PortfolioAnalytics/sandbox/attribution/data/attrib.RData
   pkg/PortfolioAnalytics/sandbox/attribution/man/
   pkg/PortfolioAnalytics/sandbox/attribution/man/Attribution.Rd
   pkg/PortfolioAnalytics/sandbox/attribution/man/Attribution.geometric.Rd
   pkg/PortfolioAnalytics/sandbox/attribution/man/Attribution.levels.Rd
   pkg/PortfolioAnalytics/sandbox/attribution/man/Carino.Rd
   pkg/PortfolioAnalytics/sandbox/attribution/man/Frongello.Rd
   pkg/PortfolioAnalytics/sandbox/attribution/man/Grap.Rd
   pkg/PortfolioAnalytics/sandbox/attribution/man/Menchero.Rd
   pkg/PortfolioAnalytics/sandbox/attribution/man/Modigliani.Rd
   pkg/PortfolioAnalytics/sandbox/attribution/man/Weight.transform.Rd
   pkg/PortfolioAnalytics/sandbox/attribution/man/logLinking.Rd
   pkg/PortfolioAnalytics/sandbox/attribution/man/logLinking.zoo.Rd
   pkg/PortfolioAnalytics/sandbox/attribution/man/period.apply.EZ.Rd
   pkg/PortfolioAnalytics/sandbox/attribution/man/relativeAttribution.Rd
   pkg/PortfolioAnalytics/sandbox/attribution/man/relativeAttributionWithoutFactors.Rd
Removed:
   pkg/PortfolioAnalytics/sandbox/attribution/Attribution.geometric.R
   pkg/PortfolioAnalytics/sandbox/attribution/Carino.R
   pkg/PortfolioAnalytics/sandbox/attribution/Frongello.R
   pkg/PortfolioAnalytics/sandbox/attribution/Grap.R
   pkg/PortfolioAnalytics/sandbox/attribution/Menchero.R
   pkg/PortfolioAnalytics/sandbox/attribution/Modigliani.R
   pkg/PortfolioAnalytics/sandbox/attribution/Return.level.R
   pkg/PortfolioAnalytics/sandbox/attribution/attrib.RData
   pkg/PortfolioAnalytics/sandbox/attribution/attribution.R
   pkg/PortfolioAnalytics/sandbox/attribution/attribution.levels.R
   pkg/PortfolioAnalytics/sandbox/attribution/logLinking.R
   pkg/PortfolioAnalytics/sandbox/attribution/logLinkingZoo.R
   pkg/PortfolioAnalytics/sandbox/attribution/periodApplyEZ.R
   pkg/PortfolioAnalytics/sandbox/attribution/relativeAttribution.R
   pkg/PortfolioAnalytics/sandbox/attribution/relativeAttributionWithoutFactors.R
Log:
- rearrange to allow compilation of rxygen docs
- call roxygenize('attribution', roclets='rd')
- add generated docs to repository


Deleted: pkg/PortfolioAnalytics/sandbox/attribution/Attribution.geometric.R
===================================================================
--- pkg/PortfolioAnalytics/sandbox/attribution/Attribution.geometric.R	2012-06-14 21:19:43 UTC (rev 2015)
+++ pkg/PortfolioAnalytics/sandbox/attribution/Attribution.geometric.R	2012-06-14 22:20:45 UTC (rev 2016)
@@ -1,87 +0,0 @@
-#' performs geometric attribution 
-#' 
-#' Performance attribution of geometric excess returns. Calculates total 
-#' geometric attribution effects over multiple periods. Used internally by the 
-#' \code{\link{Attribution}} function. Geometric attribution effects in the
-#' conrast with arithmetic do naturally link over time multiplicatively:
-#' \deqn{\frac{(1+r)}{1+b}-1=\overset{n}{\underset{t=1}{\prod}}(1+A_{t}^{G})\times\overset{n}{\underset{t=1}{\prod}}(1+S{}_{t}^{G})-1}
-#' , 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{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
-#'
-#' @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
-#' @author Andrii Babii
-#' @seealso  \code{\link{Attribution}}
-#' @references Christopherson, Jon A., Carino, David R., Ferson, Wayne E.  
-#' \emph{Portfolio Performance Measurement and Benchmarking}. McGraw-Hill. 2009. 
-#' Chapter 18-19
-#' 
-#' Bacon, C. \emph{Practical Portfolio Performance Measurement and
-#' Attribution}. Wiley. 2004. Chapter 5, 8
-#' @keywords attribution, geometric attribution, geometric linking
-#' @examples
-#' 
-#' data(attrib)
-#' Attribution.geometric(Rp, wp, Rb, wb)
-#' 
-#' @export
-Attribution.geometric <-
-function(Rp, wp, Rb, wb)
-{   # @author Andrii Babii
-  
-    # DESCRIPTION:
-    # Function to perform the geometric attribution analysis.
-  
-    # Inputs:
-    # Rp       xts, data frame or matrix of portfolio returns
-    # wp       vector, xts, data frame or matrix of portfolio weights
-    # Rb       xts, data frame or matrix of benchmark returns
-    # wb       vector, xts, data frame or matrix of benchmark weights
-  
-    # Outputs: 
-    # This function returns the list with attribution effects (allocation,
-    # selection and total effects) including total multi-period 
-    # attribution effects
-  
-    # FUNCTION:
-    rp = reclass(rowSums(Rp * wp), Rp)  
-    rb = reclass(rowSums(Rb * wb), Rb)  
-    names(rp) = "Total"                    
-    names(rb) = "Total"                 
-    rp.a = prod(1 + rp) - 1              
-    rb.a = prod(1 + rb) - 1
-    Rp = cbind(Rp, rp)
-    Rb = cbind(Rb, rb)
-    
-    bs = reclass(rowSums((wp * Rb[, 1:ncol(wp)])), rp) # Seminotional funds returns
-    allocation = ((1 + Rb) / (1 + rb.a) - 1) * cbind((wp - wb), rep(1, nrow(wp)))
-    selection = allocation
-    for (i in 1:ncol(wp)){
-      selection[, i] = ((Rp - Rb) * cbind(wp, rep(1, nrow(wp))))[, i] / (1 + bs)
-    }
-    allocation = rbind(as.data.frame(allocation), (apply(1 + allocation, 2, prod) - 1))
-    selection = rbind(as.data.frame(selection), (apply(1 + selection, 2, prod) - 1))
-    rownames(allocation)[nrow(allocation)] = "Total"
-    rownames(selection)[nrow(selection)] = "Total"
-    result = list()
-    result[[1]] = allocation
-    result[[2]] = selection
-    result[[3]] = allocation + selection
-    names(result) = c("Allocation", "Selection", "Total")
-    return(result)
-}
\ No newline at end of file

Deleted: pkg/PortfolioAnalytics/sandbox/attribution/Carino.R
===================================================================
--- pkg/PortfolioAnalytics/sandbox/attribution/Carino.R	2012-06-14 21:19:43 UTC (rev 2015)
+++ pkg/PortfolioAnalytics/sandbox/attribution/Carino.R	2012-06-14 22:20:45 UTC (rev 2016)
@@ -1,82 +0,0 @@
-#' calculates total attribution effects using logarithmic linking 
-#' 
-#' Calculates total attribution effects over multiple periods using 
-#' logarithmic linking method. Used internally by the \code{\link{Attribution}} 
-#' function. Arithmetic attribution effects do not naturally link over time. 
-#' This function uses logarithmic smoothing 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 \frac{k_{t}}{k}},
-#' where \deqn{k_{t} = \frac{log(1 + r_{t}) - log(1 + b_{t})}{r_{t} - b_{t}}}, 
-#' \deqn{k = \frac{log(1 + r) - log(1 + b)}{r - b}}. In case if portfolio and 
-#' benchmark returns are equal \deqn{k_{t} = \frac{1}{1 + r_{t}}. 
-#' \deqn{A_{t}}' - adjusted attribution effects at period \deqn{t}
-#' \deqn{A_{t}} - unadjusted attribution effects at period \deqn{t}
-#' \deqn{r_{t}} - portfolio returns at period \deqn{t}
-#' \deqn{b_{t}} - benchmark returns at period \deqn{t}
-#' \deqn{r} - total portfolio returns
-#' \deqn{b} - total benchmark returns
-#' \deqn{n} - number of periods
-#' The total arithmetic excess returns can be explained in terms of the sum 
-#' of adjusted attribution effects: 
-#' \deqn{r - b = \overset{n}{\underset{t=1}{\sum}}\left(Allocation_{t}+Selection_{t}+Interaction_{t}\right)}
-#' 
-#' @aliases Carino
-#' @param rp xts of portfolio returns
-#' @param rb xts of benchmark returns
-#' @param attributions  xts with attribution effects
-#' @author Andrii Babii
-#' @seealso  \code{\link{Attribution}} \cr \code{\link{Menchero}} \cr 
-#' \code{\link{Grap}} \cr \code{\link{Frongello}} \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
-#' Attribution}. Wiley. 2004. p. 191-193
-#' 
-#' Carino, D. (1999) \emph{Combining attribution effects over time}.
-#' The Journal of Performance Measurement. Summer, 5–14.
-#' @keywords arithmetic attribution, Carino linking, logarithmic linking
-#' @examples
-#' 
-#' data(attrib)
-#' Carino(rp, rb, allocation)
-#' 
-#' @export
-Carino <- 
-function(rp, rb, attributions)
-{   # @author Andrii Babii
-  
-    # DESCRIPTION:
-    # Function to provide multi-period summary of attribution effects using
-    # logarithmic linking. Used internally by the Attribution function
-  
-    # Inputs:
-    # rp            xts of portfolio returns
-    # rb            xts of benchmark returns
-    # attributions  attribution effects (e.g. allocation, selection, interaction)
-  
-    # Outputs: 
-    # This function returns the data.frame with original attribution effects
-    # and total attribution effects over multiple periods
-  
-    # FUNCTION:
-    rp.a = prod(1 + rp) - 1              
-    rb.a = prod(1 + rb) - 1
-    k = (log(1 + rp.a) - log(1 + rb.a)) / (rp.a - rb.a)
-    kt = rp
-    for (t in 1:nrow(kt)){
-      if (rp[t] == rb[t]){
-        kt[t] = 1 / (1 + rp[t]) # Carino factors if portfolio and benchmark returns are equal
-      } else{
-        kt[t] = (log(1 + rp[t]) - log(1 + rb[t])) / (rp[t] - rb[t]) # if different
-      }
-    }
-    kt = matrix(rep(kt, ncol(attributions)), nrow(attributions), ncol(attributions), byrow = FALSE)
-    total = colSums(attributions * kt / k)
-    attributions = rbind(as.data.frame(attributions), total)
-    rownames(attributions)[nrow(attributions)] = "Total"
-    return(attributions)
-}
\ No newline at end of file

Deleted: pkg/PortfolioAnalytics/sandbox/attribution/Frongello.R
===================================================================
--- pkg/PortfolioAnalytics/sandbox/attribution/Frongello.R	2012-06-14 21:19:43 UTC (rev 2015)
+++ pkg/PortfolioAnalytics/sandbox/attribution/Frongello.R	2012-06-14 22:20:45 UTC (rev 2016)
@@ -1,78 +0,0 @@
-#' calculates total attribution effects using Frongello linking 
-#' 
-#' Calculates total attribution effects over multiple periods using 
-#' logarithmic 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
-#' 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}'}
-#' \deqn{A_{t}}' - adjusted attribution effects at period \deqn{t}
-#' \deqn{A_{t}} - unadjusted attribution effects at period \deqn{t}
-#' \deqn{r_{i}} - portfolio returns at period \deqn{i}
-#' \deqn{b_{i}} - benchmark returns at period \deqn{i}
-#' \deqn{r} - total portfolio returns
-#' \deqn{b} - total benchmark returns
-#' \deqn{n} - number of periods
-#' 
-#' @aliases Frongello
-#' @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 attributions  xts with attribution effects
-#' @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
-#' 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
-#' @examples
-#' 
-#' data(attrib)
-#' Frongello(Rp, wp, Rb, wb, allocation)
-#' 
-#' @export
-Frongello <-
-function(Rp, wp, Rb, wb, attributions)
-{   # @author Andrii Babii
-  
-    # DESCRIPTION:
-    # Function to provide multi-period summary of attribution effects using
-    # Frongello linking. Used internally by the Attribution function
-  
-    # Inputs:
-    # Rp xts of portfolio returns
-    # wp xts of portfolio weights
-    # Rb xts of benchmark returns
-    # wb xts of benchmark weights
-    # attributions  attribution effects (e.g. allocation, selection, interaction)
-  
-    # Outputs: 
-    # This function returns the data.frame with original attribution effects
-    # and total attribution effects over multiple periods
-    
-    # FUNCTION:
-    rp = reclass(rowSums(Rp * wp), Rp)  
-    rb = reclass(rowSums(Rb * wb), Rb)
-    Rp = cbind(Rp, rp)
-    Rb = cbind(Rb, rb)
-    attr = attributions
-    attr[1, ] = attributions[1, ] + Rb[1, ]
-    
-    for(i in 2:nrow(rp)){
-        attr[i, ] = attr[i, ] * apply((1 + Rp[1:(i-1), ]), 2, prod) + Rb[i, ] * apply(attr[1:(i-1)], 2, sum)
-    }
-    total = colSums(attr)
-    attributions = rbind(as.data.frame(attributions), total)
-    rownames(attributions)[nrow(attributions)] = "Total"
-    return(attributions)
-}

Deleted: pkg/PortfolioAnalytics/sandbox/attribution/Grap.R
===================================================================
--- pkg/PortfolioAnalytics/sandbox/attribution/Grap.R	2012-06-14 21:19:43 UTC (rev 2015)
+++ pkg/PortfolioAnalytics/sandbox/attribution/Grap.R	2012-06-14 22:20:45 UTC (rev 2016)
@@ -1,82 +0,0 @@
-#' calculates total attribution effects using GRAP linking 
-#' 
-#' Calculates total attribution effects over multiple periods using 
-#' logarithmic 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
-#' 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})}
-#' \deqn{A_{t}}' - adjusted attribution effects at period \deqn{t}
-#' \deqn{A_{t}} - unadjusted attribution effects at period \deqn{t}
-#' \deqn{r_{i}} - portfolio returns at period \deqn{i}
-#' \deqn{b_{i}} - benchmark returns at period \deqn{i}
-#' \deqn{r} - total portfolio returns
-#' \deqn{b} - total benchmark returns
-#' \deqn{n} - number of periods
-#' The total arithmetic excess returns can be explained in terms of the sum 
-#' of adjusted attribution effects: 
-#' \deqn{r - b = \overset{n}{\underset{t=1}{\sum}}\left(Allocation_{t}+Selection_{t}+Interaction_{t}\right)}
-#'
-#' @aliases Grap
-#' @param rp xts of portfolio returns
-#' @param rb xts of benchmark returns
-#' @param attributions  xts with attribution effects
-#' @author Andrii Babii
-#' @seealso  \code{\link{Attribution}} \cr \code{\link{Menchero}} \cr 
-#' \code{\link{Carino}} \cr \code{\link{Frongello}} \cr
-#' \code{\link{Attribution.geometric}}
-#' @references Bacon, C. \emph{Practical Portfolio Performance Measurement and
-#' Attribution}. Wiley. 2004. p. 196-199
-#' 
-#' GRAP (Groupe de Recherche en Attribution de Performance) (1997) 
-#' \emph{Synthese des modeles d’attribution de performance}. Paris, Mars.
-#' @keywords attribution, GRAP linking
-#' @examples
-#' 
-#' data(attrib)
-#' Grap(rp, rb, allocation)
-#' 
-#' @export
-Grap <-
-function(rp, rb, attributions)
-{   # @author Andrii Babii
-  
-  
-    # DESCRIPTION:
-    # Function to provide multi-period summary of attribution effects using
-    # GRAP linking. Used internally by the Attribution function
-  
-    # Inputs:
-    # rp            xts of portfolio returns
-    # rb            xts of benchmark returns
-    # attributions  attribution effects (e.g. allocation, selection, interaction)
-  
-    # Outputs: 
-    # This function returns the data.frame with original attribution effects
-    # and total attribution effects over multiple periods
-  
-    # FUNCTION:
-    G = rp
-    T = nrow(rp)
-    G[1] = prod(1 + rb[2:T])           #GRAP factor for the first period
-    if (T == 2){
-        G[2] = (1 + rp[1])
-    }
-    if (T > 2){
-        G[T] = prod(1 + rp[1:(T - 1)]) #GRAP factor for the last period
-    }
-    if (T > 3){
-        for(i in 2:(T - 1)){
-            r = 1 + rp[1:(i-1)]
-            b = 1 + rb[(i+1):T]
-            G[i] = apply(r, 2, prod) * apply(b, 2, prod)
-        }
-    }
-    g = matrix(rep(G, ncol(attributions)), nrow(attributions), ncol(attributions), byrow = FALSE)
-    total = colSums(attributions * g)
-    attributions = rbind(as.data.frame(attributions), total)
-    rownames(attributions)[nrow(attributions)] = "Total"
-    return(attributions)
-}
\ No newline at end of file

Deleted: pkg/PortfolioAnalytics/sandbox/attribution/Menchero.R
===================================================================
--- pkg/PortfolioAnalytics/sandbox/attribution/Menchero.R	2012-06-14 21:19:43 UTC (rev 2015)
+++ pkg/PortfolioAnalytics/sandbox/attribution/Menchero.R	2012-06-14 22:20:45 UTC (rev 2016)
@@ -1,78 +0,0 @@
-#' calculates total attribution effects using Menchero linking 
-#' 
-#' 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
-#' 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})},
-#' where \deqn{M=\frac{\frac{1}{n}(r-b)}{(1+r)^{\frac{1}{n}}-(1+b)^{\frac{1}{n}}}}
-#' \deqn{a_{t} = \left(\frac{r-b-M\times\overset{n}{\underset{t=1}{\sum}}(r_{t}-b_{t})}{\overset{n}{\underset{t=1}{\sum}}(r_{t}-b_{t})^{2}}\right)\times(r_{t}-b_{t})}
-#' In case if portfolio and benchmark returns are equal 
-#' \deqn{M = (1 + r)^\frac{n-1}{n}}
-#' \deqn{A_{t}}' - adjusted attribution effects at period \deqn{t}
-#' \deqn{A_{t}} - unadjusted attribution effects at period \deqn{t}
-#' \deqn{r_{t}} - portfolio returns at period \deqn{t}
-#' \deqn{b_{t}} - benchmark returns at period \deqn{t}
-#' \deqn{r} - total portfolio returns
-#' \deqn{b} - total benchmark returns
-#' \deqn{n} - number of periods
-#' The total arithmetic excess returns can be explained in terms of the sum 
-#' of adjusted attribution effects: 
-#' \deqn{r - b = \overset{n}{\underset{t=1}{\sum}}\left(Allocation_{t}+Selection_{t}+Interaction_{t}\right)}
-#'
-#' @aliases Menchero
-#' @param rp xts of portfolio returns
-#' @param rb xts of benchmark returns
-#' @param attributions  xts with attribution effects
-#' @author Andrii Babii
-#' @seealso  \code{\link{Attribution}} \cr \code{\link{Carino}} \cr 
-#' \code{\link{Grap}} \cr \code{\link{Frongello}} \cr
-#' \code{\link{Attribution.geometric}}
-#' @references Bacon, C. \emph{Practical Portfolio Performance Measurement and
-#' Attribution}. Wiley. 2004. p. 194-196
-#' 
-#' Menchero, J. (2000) \emph{An optimized approach to linking attribution 
-#' effects over time}.Journal of Performance Measurement. Fall, 36–42.
-#' @keywords arithmetic attribution, Menchero linking
-#' @examples
-#' 
-#' data(attrib)
-#' Menchero(rp, rb, allocation)
-#' 
-#' @export
-Menchero <-
-function(rp, rb, attributions)
-{   # @author Andrii Babii
-    
-    # DESCRIPTION:
-    # Function to provide multi-period summary of attribution effects using
-    # Menchero linking. Used internally by the Attribution function
-  
-    # Inputs:
-    # rp            xts of portfolio returns
-    # rb            xts of benchmark returns
-    # attributions  attribution effects (e.g. allocation, selection, interaction)
-  
-    # Outputs: 
-    # This function returns the data.frame with original attribution effects
-    # and total attribution effects over multiple periods
-  
-    # FUNCTION:
-    rp.a = prod(1 + rp) - 1              
-    rb.a = prod(1 + rb) - 1
-    T = nrow(rp)
-    if (rp.a == rb.a){
-        M = (1 + rb.a)^((T - 1) / T)
-        at = 0
-    } else{
-        M = ((rp.a - rb.a) / T) / ((1 + rp.a)^(1 / T) - (1 + rb.a)^(1 / T))
-        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)
-    rownames(attributions)[nrow(attributions)] = "Total"
-    return(attributions)
-}
\ No newline at end of file

Deleted: pkg/PortfolioAnalytics/sandbox/attribution/Modigliani.R
===================================================================
--- pkg/PortfolioAnalytics/sandbox/attribution/Modigliani.R	2012-06-14 21:19:43 UTC (rev 2015)
+++ pkg/PortfolioAnalytics/sandbox/attribution/Modigliani.R	2012-06-14 22:20:45 UTC (rev 2016)
@@ -1,52 +0,0 @@
-#' Modigliani-Modigliani measure
-#' 
-#' The Modigliani-Modigliani measure is the portfolio return 
-#' adjusted upward or downward to match the benchmark's standard 
-#' deviation.  This puts the portfolio return and the benchmark
-#' return on 'equal footing' from a standard deviation perspective.
-#' 
-#' This is also analogous to some approaches to 'risk parity' 
-#' portfolios, which use (presumably costless) leverage
-#' to increase the portfolio standard deviation to some target.
-#' 
-#' @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 passthrough parameters 
-#' @author Andrii Babii, Brian G. Peterson
-#' @references  J. Christopherson, D. Carino, W. Ferson. 
-#' Portfolio Performance Measurement and Benchmarking. 2009. McGraw-Hill, 97-99.
-#' @seealso \code{\link{SharpeRatio}}, \code{\link{TreynorRatio}}
-#' @examples
-#' 
-#' data(managers)
-#' round(Modigliani(managers[,1,drop=FALSE], managers[,8,drop=FALSE], Rf=.035/12),4)
-#' round(Modigliani(managers[,1:6], managers[,8,drop=FALSE], Rf=.035/12),4)
-#' 
-#' @export
-Modigliani<-function (Ra, Rb, Rf=0, ...)
-{
-    Ra = checkData(Ra)
-    Rb = checkData(Rb)
-    if (!is.null(dim(Rf))) 
-        Rf = checkData(Rf)
-    Ra.ncols = NCOL(Ra)
-    Rb.ncols = NCOL(Rb)
-    pairs = expand.grid(1:Ra.ncols, 1:Rb.ncols)
-    mm<-function(Ra, Rb, Rf){
-        shr = SharpeRatio(Ra, Rf, FUN = "StdDev")
-        MM = shr*StdDev(Rb)+Rf
-        return(MM)
-    }
-    result = apply(pairs, 1, FUN = function(n, Ra, Rb, Rf) mm(Ra[, 
-        n[1]], Rb[, n[2]], Rf), Ra = Ra, Rb = Rb, Rf = Rf)
-    if (length(result) == 1) 
-        return(result)
-    else {
-        dim(result) = c(Ra.ncols, Rb.ncols)
-        colnames(result) = paste("Modigliani-Modigliani measure:", colnames(Rb))
-        rownames(result) = colnames(Ra)
-        return(t(result))
-    }
-}

Copied: pkg/PortfolioAnalytics/sandbox/attribution/R/Attribution.geometric.R (from rev 2015, pkg/PortfolioAnalytics/sandbox/attribution/Attribution.geometric.R)
===================================================================
--- pkg/PortfolioAnalytics/sandbox/attribution/R/Attribution.geometric.R	                        (rev 0)
+++ pkg/PortfolioAnalytics/sandbox/attribution/R/Attribution.geometric.R	2012-06-14 22:20:45 UTC (rev 2016)
@@ -0,0 +1,87 @@
+#' performs geometric attribution 
+#' 
+#' Performance attribution of geometric excess returns. Calculates total 
+#' geometric attribution effects over multiple periods. Used internally by the 
+#' \code{\link{Attribution}} function. Geometric attribution effects in the
+#' conrast with arithmetic do naturally link over time multiplicatively:
+#' \deqn{\frac{(1+r)}{1+b}-1=\overset{n}{\underset{t=1}{\prod}}(1+A_{t}^{G})\times\overset{n}{\underset{t=1}{\prod}}(1+S{}_{t}^{G})-1}
+#' , 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{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
+#'
+#' @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
+#' @author Andrii Babii
+#' @seealso  \code{\link{Attribution}}
+#' @references Christopherson, Jon A., Carino, David R., Ferson, Wayne E.  
+#' \emph{Portfolio Performance Measurement and Benchmarking}. McGraw-Hill. 2009. 
+#' Chapter 18-19
+#' 
+#' Bacon, C. \emph{Practical Portfolio Performance Measurement and
+#' Attribution}. Wiley. 2004. Chapter 5, 8
+#' @keywords attribution, geometric attribution, geometric linking
+#' @examples
+#' 
+#' data(attrib)
+#' Attribution.geometric(Rp, wp, Rb, wb)
+#' 
+#' @export
+Attribution.geometric <-
+function(Rp, wp, Rb, wb)
+{   # @author Andrii Babii
+  
+    # DESCRIPTION:
+    # Function to perform the geometric attribution analysis.
+  
+    # Inputs:
+    # Rp       xts, data frame or matrix of portfolio returns
+    # wp       vector, xts, data frame or matrix of portfolio weights
+    # Rb       xts, data frame or matrix of benchmark returns
+    # wb       vector, xts, data frame or matrix of benchmark weights
+  
+    # Outputs: 
+    # This function returns the list with attribution effects (allocation,
+    # selection and total effects) including total multi-period 
+    # attribution effects
+  
+    # FUNCTION:
+    rp = reclass(rowSums(Rp * wp), Rp)  
+    rb = reclass(rowSums(Rb * wb), Rb)  
+    names(rp) = "Total"                    
+    names(rb) = "Total"                 
+    rp.a = prod(1 + rp) - 1              
+    rb.a = prod(1 + rb) - 1
+    Rp = cbind(Rp, rp)
+    Rb = cbind(Rb, rb)
+    
+    bs = reclass(rowSums((wp * Rb[, 1:ncol(wp)])), rp) # Seminotional funds returns
+    allocation = ((1 + Rb) / (1 + rb.a) - 1) * cbind((wp - wb), rep(1, nrow(wp)))
+    selection = allocation
+    for (i in 1:ncol(wp)){
+      selection[, i] = ((Rp - Rb) * cbind(wp, rep(1, nrow(wp))))[, i] / (1 + bs)
+    }
+    allocation = rbind(as.data.frame(allocation), (apply(1 + allocation, 2, prod) - 1))
+    selection = rbind(as.data.frame(selection), (apply(1 + selection, 2, prod) - 1))
+    rownames(allocation)[nrow(allocation)] = "Total"
+    rownames(selection)[nrow(selection)] = "Total"
+    result = list()
+    result[[1]] = allocation
+    result[[2]] = selection
+    result[[3]] = allocation + selection
+    names(result) = c("Allocation", "Selection", "Total")
+    return(result)
+}
\ No newline at end of file

Copied: pkg/PortfolioAnalytics/sandbox/attribution/R/Carino.R (from rev 2015, pkg/PortfolioAnalytics/sandbox/attribution/Carino.R)
===================================================================
--- pkg/PortfolioAnalytics/sandbox/attribution/R/Carino.R	                        (rev 0)
+++ pkg/PortfolioAnalytics/sandbox/attribution/R/Carino.R	2012-06-14 22:20:45 UTC (rev 2016)
@@ -0,0 +1,82 @@
+#' calculates total attribution effects using logarithmic linking 
+#' 
+#' Calculates total attribution effects over multiple periods using 
+#' logarithmic linking method. Used internally by the \code{\link{Attribution}} 
+#' function. Arithmetic attribution effects do not naturally link over time. 
+#' This function uses logarithmic smoothing 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 \frac{k_{t}}{k}},
+#' where \deqn{k_{t} = \frac{log(1 + r_{t}) - log(1 + b_{t})}{r_{t} - b_{t}}}, 
+#' \deqn{k = \frac{log(1 + r) - log(1 + b)}{r - b}}. In case if portfolio and 
+#' benchmark returns are equal \deqn{k_{t} = \frac{1}{1 + r_{t}}. 
+#' \deqn{A_{t}}' - adjusted attribution effects at period \deqn{t}
+#' \deqn{A_{t}} - unadjusted attribution effects at period \deqn{t}
+#' \deqn{r_{t}} - portfolio returns at period \deqn{t}
+#' \deqn{b_{t}} - benchmark returns at period \deqn{t}
+#' \deqn{r} - total portfolio returns
+#' \deqn{b} - total benchmark returns
+#' \deqn{n} - number of periods
+#' The total arithmetic excess returns can be explained in terms of the sum 
+#' of adjusted attribution effects: 
+#' \deqn{r - b = \overset{n}{\underset{t=1}{\sum}}\left(Allocation_{t}+Selection_{t}+Interaction_{t}\right)}
+#' 
+#' @aliases Carino
+#' @param rp xts of portfolio returns
+#' @param rb xts of benchmark returns
+#' @param attributions  xts with attribution effects
+#' @author Andrii Babii
+#' @seealso  \code{\link{Attribution}} \cr \code{\link{Menchero}} \cr 
+#' \code{\link{Grap}} \cr \code{\link{Frongello}} \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
+#' Attribution}. Wiley. 2004. p. 191-193
+#' 
+#' Carino, D. (1999) \emph{Combining attribution effects over time}.
+#' The Journal of Performance Measurement. Summer, 5–14.
+#' @keywords arithmetic attribution, Carino linking, logarithmic linking
+#' @examples
+#' 
+#' data(attrib)
+#' Carino(rp, rb, allocation)
+#' 
+#' @export
+Carino <- 
+function(rp, rb, attributions)
+{   # @author Andrii Babii
+  
+    # DESCRIPTION:
+    # Function to provide multi-period summary of attribution effects using
+    # logarithmic linking. Used internally by the Attribution function
+  
+    # Inputs:
+    # rp            xts of portfolio returns
+    # rb            xts of benchmark returns
+    # attributions  attribution effects (e.g. allocation, selection, interaction)
+  
+    # Outputs: 
+    # This function returns the data.frame with original attribution effects
+    # and total attribution effects over multiple periods
+  
+    # FUNCTION:
+    rp.a = prod(1 + rp) - 1              
+    rb.a = prod(1 + rb) - 1
+    k = (log(1 + rp.a) - log(1 + rb.a)) / (rp.a - rb.a)
+    kt = rp
+    for (t in 1:nrow(kt)){
+      if (rp[t] == rb[t]){
+        kt[t] = 1 / (1 + rp[t]) # Carino factors if portfolio and benchmark returns are equal
+      } else{
+        kt[t] = (log(1 + rp[t]) - log(1 + rb[t])) / (rp[t] - rb[t]) # if different
+      }
+    }
+    kt = matrix(rep(kt, ncol(attributions)), nrow(attributions), ncol(attributions), byrow = FALSE)
+    total = colSums(attributions * kt / k)
+    attributions = rbind(as.data.frame(attributions), total)
+    rownames(attributions)[nrow(attributions)] = "Total"
+    return(attributions)
+}
\ No newline at end of file

Copied: pkg/PortfolioAnalytics/sandbox/attribution/R/Frongello.R (from rev 2015, pkg/PortfolioAnalytics/sandbox/attribution/Frongello.R)
===================================================================
--- pkg/PortfolioAnalytics/sandbox/attribution/R/Frongello.R	                        (rev 0)
+++ pkg/PortfolioAnalytics/sandbox/attribution/R/Frongello.R	2012-06-14 22:20:45 UTC (rev 2016)
@@ -0,0 +1,78 @@
+#' calculates total attribution effects using Frongello linking 
+#' 
+#' Calculates total attribution effects over multiple periods using 
+#' logarithmic 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
+#' 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}'}
+#' \deqn{A_{t}}' - adjusted attribution effects at period \deqn{t}
+#' \deqn{A_{t}} - unadjusted attribution effects at period \deqn{t}
+#' \deqn{r_{i}} - portfolio returns at period \deqn{i}
+#' \deqn{b_{i}} - benchmark returns at period \deqn{i}
+#' \deqn{r} - total portfolio returns
+#' \deqn{b} - total benchmark returns
+#' \deqn{n} - number of periods
+#' 
+#' @aliases Frongello
+#' @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 attributions  xts with attribution effects
+#' @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
+#' 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
+#' @examples
+#' 
+#' data(attrib)
+#' Frongello(Rp, wp, Rb, wb, allocation)
+#' 
+#' @export
+Frongello <-
+function(Rp, wp, Rb, wb, attributions)
+{   # @author Andrii Babii
+  
+    # DESCRIPTION:
+    # Function to provide multi-period summary of attribution effects using
+    # Frongello linking. Used internally by the Attribution function
+  
+    # Inputs:
+    # Rp xts of portfolio returns
+    # wp xts of portfolio weights
+    # Rb xts of benchmark returns
+    # wb xts of benchmark weights
+    # attributions  attribution effects (e.g. allocation, selection, interaction)
+  
+    # Outputs: 
+    # This function returns the data.frame with original attribution effects
+    # and total attribution effects over multiple periods
+    
+    # FUNCTION:
+    rp = reclass(rowSums(Rp * wp), Rp)  
+    rb = reclass(rowSums(Rb * wb), Rb)
+    Rp = cbind(Rp, rp)
+    Rb = cbind(Rb, rb)
+    attr = attributions
+    attr[1, ] = attributions[1, ] + Rb[1, ]
+    
+    for(i in 2:nrow(rp)){
+        attr[i, ] = attr[i, ] * apply((1 + Rp[1:(i-1), ]), 2, prod) + Rb[i, ] * apply(attr[1:(i-1)], 2, sum)
+    }
+    total = colSums(attr)
+    attributions = rbind(as.data.frame(attributions), total)
+    rownames(attributions)[nrow(attributions)] = "Total"
+    return(attributions)
+}

Copied: pkg/PortfolioAnalytics/sandbox/attribution/R/Grap.R (from rev 2015, pkg/PortfolioAnalytics/sandbox/attribution/Grap.R)
===================================================================
--- pkg/PortfolioAnalytics/sandbox/attribution/R/Grap.R	                        (rev 0)
+++ pkg/PortfolioAnalytics/sandbox/attribution/R/Grap.R	2012-06-14 22:20:45 UTC (rev 2016)
@@ -0,0 +1,82 @@
[TRUNCATED]

To get the complete diff run:
    svnlook diff /svnroot/returnanalytics -r 2016


More information about the Returnanalytics-commits mailing list