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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Tue Jul 10 01:55:13 CEST 2012


Author: ababii
Date: 2012-07-10 01:55:13 +0200 (Tue, 10 Jul 2012)
New Revision: 2141

Modified:
   pkg/PortfolioAnalytics/sandbox/attribution/R/Attribution.geometric.R
   pkg/PortfolioAnalytics/sandbox/attribution/R/AttributionFixedIncome.R
   pkg/PortfolioAnalytics/sandbox/attribution/R/Carino.R
   pkg/PortfolioAnalytics/sandbox/attribution/R/Conv.option.R
   pkg/PortfolioAnalytics/sandbox/attribution/R/DaviesLaker.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/Return.annualized.excess.R
   pkg/PortfolioAnalytics/sandbox/attribution/R/Return.level.R
   pkg/PortfolioAnalytics/sandbox/attribution/R/attribution.R
   pkg/PortfolioAnalytics/sandbox/attribution/R/attribution.levels.R
Log:
- corrected mistakes in the documentation that prevented from the pdf conversion

Modified: pkg/PortfolioAnalytics/sandbox/attribution/R/Attribution.geometric.R
===================================================================
--- pkg/PortfolioAnalytics/sandbox/attribution/R/Attribution.geometric.R	2012-07-09 23:54:02 UTC (rev 2140)
+++ pkg/PortfolioAnalytics/sandbox/attribution/R/Attribution.geometric.R	2012-07-09 23:55:13 UTC (rev 2141)
@@ -4,23 +4,14 @@
 #' geometric attribution effects over multiple periods. Used internally by the
 #' \code{\link{Attribution}} function. Geometric attribution effects in the
 #' contrast 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}
+#' \deqn{\frac{(1+R_{p})}{1+R_{b}}-1=\prod^{n}_{t=1}(1+A_{t}^{G})\times\prod^{n}_{t=1}(1+S{}_{t}^{G})-1}
+#' Total allocation effect at time t:
+#' \deqn{A_{t}^{G}=\frac{1+b_{S}}{1+R_{bt}}-1}
+#' Total selection effect at time t:
+#' \deqn{S_{t}^{G}=\frac{1+R_{pt}}{1+b_{S}}-1}
+#' Semi-notional fund:
+#' \deqn{b_{S}=\sum^{n}_{i=1}w_{pi}\times R_{bi}}
 #' 
-#' 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{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). 
 #' 
@@ -30,21 +21,23 @@
 #' 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 hedged into the base currency
-#' \deqn{b_{L}} - total benchmark returns in the local currency
-#' \deqn{r_{L}} - total portfolio returns in the local currency
+#' Where the total semi-notional returns hedged into the base currency were
+#' used:
+#' \deqn{b_{SH} = \sum_{i}w_{pi}\times R_{bi}((w_{pi} - w_{bi})R_{bHi} + w_{bi}R_{bLi})}
+#' Total semi-notional returns in the local currency:
+#' \deqn{b_{SL} = \sum_{i}w_{pi}R_{bLi}}
+#' Portfolio returns in the local currency:
+#' \deqn{R_{pLi}}
+#' Benchmark returns in the local currency:
+#' \deqn{R_{bLi}}
+#' Benchmark returns hedged into the base currency:
+#' \deqn{R_{bHi}}
+#' Total benchmark returns in the local currency:
+#' \deqn{b_{L}}
+#' Total portfolio returns in the local currency:
+#' \deqn{r_{L}}
 #' 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}
+#' \deqn{\frac{(1+R_{p})}{1+R_{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_{p}}{1+r_{L}}\times\frac{1+b_{L}}{1+R_{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
@@ -65,10 +58,8 @@
 #' @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, Appendix A
+#' 2009. Chapter 18-19 \cr Bacon, C. \emph{Practical Portfolio Performance 
+#' Measurement and Attribution}. Wiley. 2004. Chapter 5, 8, Appendix A \cr
 #' @keywords attribution, geometric attribution, geometric linking
 #' @examples
 #' 

Modified: pkg/PortfolioAnalytics/sandbox/attribution/R/AttributionFixedIncome.R
===================================================================
--- pkg/PortfolioAnalytics/sandbox/attribution/R/AttributionFixedIncome.R	2012-07-09 23:54:02 UTC (rev 2140)
+++ pkg/PortfolioAnalytics/sandbox/attribution/R/AttributionFixedIncome.R	2012-07-09 23:55:13 UTC (rev 2141)
@@ -11,24 +11,21 @@
 #' The arithmetic attribution is handled using weighted duration approach
 #' (Van Breukelen, 2000). The allocation, selection and currency allocation 
 #' effects for category i are:
-#' \deqn{A_{i} = (D_{pi}\times w_{i}-D_{\beta}\times D_{bi}\times w_{pi})\times (-\Delta y_{bi} + \Delta y_{b})}
-#' \deqn{S_{i} = D_{i}\times w_{i}\times (-\Delta y_{ri} + \Delta y_{bi})}
+#' \deqn{A_{i} = (D_{pi}\times w_{pi}-D_{\beta}\times D_{bi}\times w_{pi})\times (-\Delta y_{bi} + \Delta y_{b})}
+#' \deqn{S_{i} = D_{i}\times w_{pi}\times (-\Delta y_{ri} + \Delta y_{bi})}
 #' \deqn{C_{i} = (w_{pi} - w_{bi})\times (c_{i} + R_{fi} - c')}
-#' where
-#' \deqn{w_{pi}} - portfolio weights
-#' \deqn{w_{bi}} - benchmark weights
-#' \deqn{D_{i}} - modified duration in bond category i
-#' \deqn{D_{\beta}=\frac{D_{r}}{D_{b}}} - duration beta
-#' \deqn{D_{r}} - portfolio duration
-#' \deqn{D_{b}} - benchmark duration
-#' \deqn{D_{bi}} - benchmark duration for category i
-#' \deqn{D_{pi}} - portfolio duration for category i
-#' \deqn{\Delta y_{ri}} - change in portfolio yield for category i
-#' \deqn{\Delta y_{bi}} - change in benchmark yield for category i
-#' \deqn{\Delta y_{b}} - change in benchmark yield
-#' \deqn{R_{ci} - currency returns for category i
-#' \deqn{R_{fi}} - risk-free rate in currency of asset i
-#' \deqn{c'= \underset{i}{\sum}w_{bi}\times(R_{ci}+R_{fi})}
+#' where w_pi - portfolio weights, w_bi - benchmark weights, D_i - modified 
+#' duration in bond category i.
+#' Duration beta:
+#' \deqn{D_{\beta}=\frac{D_{r}}{D_{b}}}
+#' D_r - portfolio duration, D_b - benchmark duration, D_bi - benchmark 
+#' duration for category i, D_pi - portfolio duration for category i, 
+#' Delta y_ri - change in portfolio yield for category i,
+#' Delta y_bi - change in benchmark yield for category i,
+#' Delta y_b - change in benchmark yield,
+#' R_ci- currency returns for category i,
+#' R_fi - risk-free rate in currency of asset i,
+#' \deqn{c'= \sum_{i}w_{bi}\times(R_{ci}+R_{fi})}
 #' The geometric attribution is adapted using Van Breukelen (2000) approach for
 #' the arithmetic attribution. The individual allocation and selection effects
 #' are computed as follows:
@@ -53,11 +50,9 @@
 #' (and currency effects)
 #' @author Andrii Babii
 #' @seealso \code{\link{Attribution.levels}}, \code{\link{Attribution.geometric}}
-#' @references Bacon, C. \emph{Practical Portfolio Performance Measurement and
-#' Attribution}. Wiley. 2004. Chapter 7
-#' 
-#' Van Breukelen, G. \emph{Fixed income attribution}. Journal of Performance 
-#' Measurement. Summer, 61–68. 2000
+#' @references   Bacon, C. \emph{Practical Portfolio Performance Measurement 
+#' and Attribution}. Wiley. 2004. Chapter 7 \cr Van Breukelen, G. \emph{Fixed 
+#' income attribution}. Journal of Performance Measurement. Sumer. p. 61-68. 2000 \cr
 #' @keywords attribution
 #' @examples
 #' 

Modified: pkg/PortfolioAnalytics/sandbox/attribution/R/Carino.R
===================================================================
--- pkg/PortfolioAnalytics/sandbox/attribution/R/Carino.R	2012-07-09 23:54:02 UTC (rev 2140)
+++ pkg/PortfolioAnalytics/sandbox/attribution/R/Carino.R	2012-07-09 23:55:13 UTC (rev 2141)
@@ -6,23 +6,18 @@
 #' 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}}. 
-#' 
+#' \deqn{A_{t}' = A_{t} \times \frac{k_{t}}{k}}
+#' where \deqn{k_{t} = \frac{log(1 + R_{pt}) - log(1 + R_{bt})}{R_{pt} - R_{bt}}}
+#' \deqn{k = \frac{log(1 + R_{p}) - log(1 + R_{b})}{R_{p} - 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
+#' \deqn{k_{t} = \frac{1}{1 + R_{pt}}}
+#' where A_t' - adjusted attribution effects at period t, A_t - unadjusted
+#' attribution effects at period t, R_pt - portfolio returns at period t, 
+#' R_bt - benchmark returns at period t, Rp - total portfolio returns, 
+#' Rb - total benchmark returns, 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)}
+#' \deqn{R_{p} - R_{b} = \sum^{n}_{t=1}\left(Allocation_{t}+Selection_{t}+Interaction_{t}\right)}
 #' 
 #' @aliases Carino
 #' @param rp xts of portfolio returns
@@ -36,15 +31,12 @@
 #' @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.
+#' @references Christopherson, Jon A., Carino, David R., Ferson, Wayne E. 
+#' \emph{Portfolio Performance Measurement and Benchmarking}. McGraw-Hill. 
+#' 2009. Chapter 19 \cr Bacon, C. \emph{Practical Portfolio Performance 
+#' Measurement and Attribution}. Wiley. 2004. p. 191-193 \cr Carino, D. (1999) 
+#' \emph{Combining attribution effects over time}. The Journal of Performance 
+#' Measurement. Summer. p. 5-14 \cr
 #' @keywords arithmetic attribution, Carino linking, logarithmic linking
 #' @examples
 #' 

Modified: pkg/PortfolioAnalytics/sandbox/attribution/R/Conv.option.R
===================================================================
--- pkg/PortfolioAnalytics/sandbox/attribution/R/Conv.option.R	2012-07-09 23:54:02 UTC (rev 2140)
+++ pkg/PortfolioAnalytics/sandbox/attribution/R/Conv.option.R	2012-07-09 23:55:13 UTC (rev 2141)
@@ -1,15 +1,16 @@
 #' convert information about options, warrants or convertible bonds to the
 #' equivalent of returns
 #' 
-#' The performance of option contracts are measured in exactly the same way as
+#' The performance of option contracts is measured in esactly the same way as
 #' any other asset but they also generate economic exposures. The key to 
-#' attribution analysis with options is to include the appropriate economic 
-#' exposure for which we can use the option’s delta. The option itself will 
-#' provide part of the valuation; the remainder of the option’s economic value 
-#' must be achieved again by using notional assets:
-#' \deqn{option economic exposure = \delta \times number of options \times strike price = option valuation + notional exposure}
+#' attribution analysis with options is to inclue the appropriate economic 
+#' exposure for which we can use the option's  delta. The option itself will
+#' provide part of the valuation. The remaindeer of the option's economic value
+#' must be achieved again by using notional assets: \emph{option economic 
+#' exposure = Delta x number of options x strike price = option valuation + 
+#' notional exposure}
 #' @aliases options attribution
-#' @param \code{n x 8} matrix containing option ID (as rownames), and columns
+#' @param \emph{nx8} matrix containing option ID (as rownames), and columns
 #' corresponding to (in particular order): strike price, number of options, 
 #' current option price, end option price, option's delta, returns on the 
 #' underlying
@@ -22,7 +23,8 @@
 #' @keywords derivatives attribution, option attribution
 #' @examples
 #' 
-#' option = matrix(c(1000, 1000, 1000, 300, 400, 10, 20, 30, 40, 50, 10, 11, 12, 13, 14, 12, 13, 14, 15, 16, 0.1, 0.2, 0.3, 0.4, 0.5, 0.1, 0.1, 0.2, 0.2, 0.3), 5, 6)
+#' option = matrix(c(1000, 1000, 1000, 300, 400, 10, 20, 30, 40, 50, 10, 11, 12, 13, 14, 12, 13,
+#' 14, 15, 16, 0.1, 0.2, 0.3, 0.4, 0.5, 0.1, 0.1, 0.2, 0.2, 0.3), 5, 6)
 #' colnames(option) = c("Strike", "Number", "Current option", "End option", "delta", "returns")
 #' rownames(option) = c("CVX", "XOM", "GE", "WMT", "FB")
 #' Conv.option(option)

Modified: pkg/PortfolioAnalytics/sandbox/attribution/R/DaviesLaker.R
===================================================================
--- pkg/PortfolioAnalytics/sandbox/attribution/R/DaviesLaker.R	2012-07-09 23:54:02 UTC (rev 2140)
+++ pkg/PortfolioAnalytics/sandbox/attribution/R/DaviesLaker.R	2012-07-09 23:55:13 UTC (rev 2141)
@@ -6,32 +6,29 @@
 #' naturally link over time. This function uses Davies and Laker linking method
 #' to compute total attribution effects. 
 #' Arithmetic excess returns are decomposed as follows:
-#' \deqn{r - b = Allocation + Selection + Interaction}
-#' \deqn{Allocation = \overset{T}{\underset{t=1}{\prod}}(1+bs_{t})-\overset{T}{\underset{t=1}{\prod}}(1+rb_{t})}
-#' \deqn{Selection = \overset{T}{\underset{t=1}{\prod}}(1+rs_{t})-\overset{T}{\underset{t=1}{\prod}}(1+rb_{t})}
-#' \deqn{Interaction = \overset{T}{\underset{t=1}{\prod}}(1+rp_{t})-\overset{T}{\underset{t=1}{\prod}}(1+rs_{t})-\overset{T}{\underset{t=1}{\prod}}(1+bs_{t})+\overset{T}{\underset{t=1}{\prod}}(1+rb_{t})}
-#' \deqn{rp_{i}} - portfolio returns at period \deqn{i}
-#' \deqn{rb_{i}} - benchmark returns at period \deqn{i}
-#' \deqn{rs_{i}} - selection notional fund returns at period \deqn{i}
-#' \deqn{bs_{i}} - allocation notional fund returns at period \deqn{i}
-#' \deqn{T} - number of periods
+#' \deqn{R_{p} - R_{b} = Allocation + Selection + Interaction}
+#' \deqn{Allocation = \prod^{T}_{t=1}(1+bs_{t})-\prod^{T}_{t=1}(1+R_{bt})}
+#' \deqn{Selection = \prod^{T}_{t=1}(1+rs_{t})-\prod^{T}_{t=1}(1+R_{bt})}
+#' \deqn{Interaction = \prod^{T}_{t=1}(1+R_{pt})-\prod^{T}_{t=1}(1+rs_{t})-\prod^{T}_{t=1}(1+bs_{t})+\prod^{T}_{t=1}(1+R_{bt})}
+#' R_pi - portfolio returns at period i, Rb_i - benchmark returns at period i,
+#' rs_i - selection notional fund returns at period i, bs_i - allocation 
+#' notional fund returns at period i, T - number of periods
 #' 
 #' @aliases DaviesLaker
 #' @param Rp xts of portfolio returns
 #' @param wp xts of portfolio weights
 #' @param Rb xts of benchmark returns
 #' @param wb xts of benchmark weights
-#' @return This function returns the data.frame with original attribution effects
-#' and total attribution effects over multiple periods
+#' @return This function returns the 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}} \cr \code{\link{Frongello}}
-#' @references Bacon, C. \emph{Practical Portfolio Performance Measurement and
-#' Attribution}. Wiley. 2004. p. 201-204
-#' 
-#' Davies, O. and Laker, D. (2001) Multiple-period performance attribution 
-#' using the brinson model.Journal of Performance MeasurementFall, 12–22.
+#' @references Bacon, C. \emph{Practical Portfolio Performance Measurement and 
+#' Attribution}. Wiley. 2004. p. 201-204 \cr Davies, O. and Laker, D. (2001) 
+#' \emph{Multiple-period performance attribution using the Brinson model}. 
+#' Journal of Performance Measurement. Fall. p. 12-22 \cr
 #' @keywords arithmetic attribution, Davies and Laker linking
 #' @examples
 #' 

Modified: pkg/PortfolioAnalytics/sandbox/attribution/R/Frongello.R
===================================================================
--- pkg/PortfolioAnalytics/sandbox/attribution/R/Frongello.R	2012-07-09 23:54:02 UTC (rev 2140)
+++ pkg/PortfolioAnalytics/sandbox/attribution/R/Frongello.R	2012-07-09 23:55:13 UTC (rev 2141)
@@ -6,14 +6,11 @@
 #' 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}'}
-#' \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
+#' \deqn{A_{t}' = A_{t}\times\prod^{t-1}_{i=1}(1+r_{pi})+R_{bt}\times\sum^{t-1}_{i=1}A_{i}'}
+#' A_t' - adjusted attribution effects at period t, A_t - unadjusted
+#' attribution effects at period t, R_pi - portfolio returns at period i,
+#' R_bi - benchmark returns at period , Rp - total portfolio returns,
+#' Rb - total benchmark returns, n - number of periods
 #' 
 #' @aliases Frongello
 #' @param rp xts of portfolio returns
@@ -28,10 +25,9 @@
 #' \code{\link{Grap}} \cr \code{\link{Carino}} \cr
 #' \code{\link{Attribution.geometric}}
 #' @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.
+#' Attribution}. Wiley. 2004. p. 199-201 \cr Frongello, A. (2002) \emph{Linking
+#' single period attribution results}. Journal of Performance Measurement. 
+#' Spring, p. 10-22. \cr
 #' @keywords arithmetic attribution, Frongello linking
 #' @examples
 #' 

Modified: pkg/PortfolioAnalytics/sandbox/attribution/R/Grap.R
===================================================================
--- pkg/PortfolioAnalytics/sandbox/attribution/R/Grap.R	2012-07-09 23:54:02 UTC (rev 2140)
+++ pkg/PortfolioAnalytics/sandbox/attribution/R/Grap.R	2012-07-09 23:55:13 UTC (rev 2141)
@@ -6,18 +6,15 @@
 #' 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})}
-#' \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
+#' \deqn{A_{t}' = A_{t} \times G_{t}} where 
+#' \deqn{G_{t}=\prod^{t-1}_{i=1}(1+R_{pi})\times\prod^{n}_{t+1}(1+R_{bi})}
+#' A_t' - adjusted attribution effects at period t, A_t - unadjusted
+#' attribution effects at period t, R_pi - portfolio returns at period i,
+#' R_bi - benchmark returns at period i, Rp - total portfolio returns, 
+#' Rb - total benchmark returns, 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)}
+#' \deqn{R_{p} - R_{b} = \sum^{n}_{t=1}\left(Allocation_{t}+Selection_{t}+Interaction_{t}\right)}
 #'
 #' @aliases Grap
 #' @param rp xts of portfolio returns
@@ -31,11 +28,10 @@
 #' @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.
+#' @references   Bacon, C. \emph{Practical Portfolio Performance Measurement
+#' and Attribution}. Wiley. 2004. p. 196-199 \cr GRAP (Groupe de Recherche en 
+#' Attribution de Performance) (1997) \emph{Synthese des modeles d'attribution
+#' de performance}. Paris, Mars.\cr
 #' @keywords arithmetic attribution, GRAP linking
 #' @examples
 #' 

Modified: pkg/PortfolioAnalytics/sandbox/attribution/R/Menchero.R
===================================================================
--- pkg/PortfolioAnalytics/sandbox/attribution/R/Menchero.R	2012-07-09 23:54:02 UTC (rev 2140)
+++ pkg/PortfolioAnalytics/sandbox/attribution/R/Menchero.R	2012-07-09 23:55:13 UTC (rev 2141)
@@ -6,21 +6,20 @@
 #' 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})},
-#' 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
+#' \deqn{A_{t}' = A_{t} \times (M +a_{t})} 
+#' where \deqn{M=\frac{\frac{1}{n}(R_{p}-R_{b})}{(1+R_{p})^{\frac{1}{n}}-(1+R_{b})^{\frac{1}{n}}}}
+#' \deqn{a_{t} = \left(\frac{R_{p}-R_{b}-M\times\sum^{n}_{t=1}(R_{pt}-R_{bt})}{\sum^{n}_{t=1}(R_{pt}-R_{bt})^{2}}\right)\times(R_{pt}-R_{bt})}
+#' In case if portfolio and benchmark returns are equal the limit of the
+#' above value is used:
+#' \deqn{M = (1 + r_{p})^\frac{n-1}{n}}
+#' A_t' - adjusted attribution effects at period t, A_t - unadjusted 
+#' attribution effects at period t, R_pt - portfolio returns at period t, 
+#' R_bt - benchmark returns at period t, Rp - total portfolio returns, 
+#' Rb - total benchmark returns, 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)}
+#' \deqn{R_{p} - R_{b} = \sum^{n}_{t=1}\left(Allocation_{t}+Selection_{t}+Interaction_{t}\right)}
 #'
 #' @aliases Menchero
 #' @param rp xts of portfolio returns
@@ -35,10 +34,9 @@
 #' \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.
+#' Attribution}. Wiley. 2004. p. 194-196 \cr Menchero, J. (2000) \emph{An 
+#' optimized approach to linking attribution effects over time}. Journal of 
+#' Performance Measurement. Fall. p. 36-42 \cr
 #' @keywords arithmetic attribution, Menchero linking
 #' @examples
 #' 

Modified: pkg/PortfolioAnalytics/sandbox/attribution/R/Return.annualized.excess.R
===================================================================
--- pkg/PortfolioAnalytics/sandbox/attribution/R/Return.annualized.excess.R	2012-07-09 23:54:02 UTC (rev 2140)
+++ pkg/PortfolioAnalytics/sandbox/attribution/R/Return.annualized.excess.R	2012-07-09 23:55:13 UTC (rev 2141)
@@ -1,7 +1,8 @@
-#' calculate an annualized excess return for comparing instruments with different
+#' calculates an annualized excess return for comparing instruments with different
 #' length history
 #' 
-#' An average annualized excess return is convenient for comparing returns.
+#' An average annualized excess return is convenient for comparing excess 
+#' returns.
 #' 
 #' Annualized returns are useful for comparing two assets. To do so, you must
 #' scale your observations to an annual scale by raising the compound return to

Modified: pkg/PortfolioAnalytics/sandbox/attribution/R/Return.level.R
===================================================================
--- pkg/PortfolioAnalytics/sandbox/attribution/R/Return.level.R	2012-07-09 23:54:02 UTC (rev 2140)
+++ pkg/PortfolioAnalytics/sandbox/attribution/R/Return.level.R	2012-07-09 23:55:13 UTC (rev 2141)
@@ -1,11 +1,11 @@
-#' aggregate portfolio returns and weights up to the chosen level from the 
+#' aggregates portfolio returns and weights up to the chosen level from the 
 #' hierarchy
 #' 
-#' Aggregate returns and weights up to the chosen level from the hierarchy.
-#' Hierarchy can be used from the buildHierarchy function or defined manually
-#' in the same way as the buildHierarchy's output. If for the selected level 
-#' the values in the hierarchy are numeric, the aggregation of returns or 
-#' weights is performed by quintiles.
+#' Aggregates returns and weights up to the chosen level from the hierarchy.
+#' Hierarchy can be used from the \code{buildHierarchy} function or 
+#' defined manually in the same way as the buildHierarchy's output. If for the
+#' selected level the values in the hierarchy are numeric, the aggregation of 
+#' returns or weights is performed by quintiles.
 #' \code{Weight.transform} makes transformation of weights to the xts object
 #' conformable with returns.
 #'
@@ -30,42 +30,6 @@
 #' Weight.level(wp, h, level = "Sector")
 #' 
 #' @export
-Weight.transform <- 
-function(wp, Rp)
-{   # @author Andrii Babii
-  
-    # DESCRIPTION:
-    # Function to transform weights to the xts object conformable with returns 
-    # used by aggregation and attribution functions
-    
-    # Inputs:
-    # wp      vector, xts, data frame or matrix of portfolio weights
-    # Rp      xts, data frame or matrix of portfolio returns
-  
-    # Outputs: 
-    # This function returns the xts object with weights conformable with returns
-  
-    # FUNCTION:
-    if (is.vector(wp)){
-      wp = as.xts(matrix(rep(wp, nrow(Rp)), nrow(Rp), ncol(Rp), byrow = TRUE), index(Rp))
-      colnames(wp) = colnames(Rp)
-    } else{
-      if(as.Date(last(index(Rp))) < (as.Date(index(wp[1,]))+1)){
-        stop(paste('last date in series',as.Date(last(index(Rp))),'occurs before beginning of first rebalancing period',as.Date(first(index(wp)))+1))
-      }
-      wp = checkData(wp, method = "xts")
-      wp = merge(wp, xts(, index(Rp)))
-      wp = na.locf(wp)
-      if(as.Date(first(index(Rp))) > (as.Date(index(wp[1,]))+1)) {
-        warning(paste('data series starts on',as.Date(first(index(Rp))),', which is after the first rebalancing period',as.Date(first(index(wp)))+1)) 
-        wp = wp
-      } else{
-        wp = wp[2:nrow(wp)]
-      }
-    }
-    return(wp)
-}
-
 Return.level <-
 function(Rp, wp, h, level = "Sector")
 {   # @author Andrii Babii
@@ -130,4 +94,40 @@
     }
     colnames(weights) = names(h)
     return(weights)
+}
+
+Weight.transform <- 
+  function(wp, Rp)
+  {   # @author Andrii Babii
+    
+    # DESCRIPTION:
+    # Function to transform weights to the xts object conformable with returns 
+    # used by aggregation and attribution functions
+    
+    # Inputs:
+    # wp      vector, xts, data frame or matrix of portfolio weights
+    # Rp      xts, data frame or matrix of portfolio returns
+    
+    # Outputs: 
+    # This function returns the xts object with weights conformable with returns
+    
+    # FUNCTION:
+    if (is.vector(wp)){
+      wp = as.xts(matrix(rep(wp, nrow(Rp)), nrow(Rp), ncol(Rp), byrow = TRUE), index(Rp))
+      colnames(wp) = colnames(Rp)
+    } else{
+      if(as.Date(last(index(Rp))) < (as.Date(index(wp[1,]))+1)){
+        stop(paste('last date in series',as.Date(last(index(Rp))),'occurs before beginning of first rebalancing period',as.Date(first(index(wp)))+1))
+      }
+      wp = checkData(wp, method = "xts")
+      wp = merge(wp, xts(, index(Rp)))
+      wp = na.locf(wp)
+      if(as.Date(first(index(Rp))) > (as.Date(index(wp[1,]))+1)) {
+        warning(paste('data series starts on',as.Date(first(index(Rp))),', which is after the first rebalancing period',as.Date(first(index(wp)))+1)) 
+        wp = wp
+      } else{
+        wp = wp[2:nrow(wp)]
+      }
+    }
+    return(wp)
 }
\ No newline at end of file

Modified: pkg/PortfolioAnalytics/sandbox/attribution/R/attribution.R
===================================================================
--- pkg/PortfolioAnalytics/sandbox/attribution/R/attribution.R	2012-07-09 23:54:02 UTC (rev 2140)
+++ pkg/PortfolioAnalytics/sandbox/attribution/R/attribution.R	2012-07-09 23:55:13 UTC (rev 2141)
@@ -17,21 +17,22 @@
 #' similarly to the portfolio and/or benchmark returns annualization. 
 #' 
 #' The arithmetic excess returns are decomposed into the sum of allocation, 
-#' selection and interaction effects across \deqn{n} sectors:
-#' \deqn{r-b=\overset{n}{\underset{i=1}{\sum}}\left(A_{i}+S_{i}+I_{i}\right)}
-#' The arithmetic attribution effects for the category \deqn{i} are computed
+#' selection and interaction effects across n sectors:
+#' \deqn{R_{p}-R_{b}=\sum^{n}_{i=1}\left(A_{i}+S_{i}+I_{i}\right)}
+#' The arithmetic attribution effects for the category i are computed
 #' as suggested in the Brinson, Hood and Beebower (1986):
-#' \deqn{A_{i}=(w_{pi}-w_{bi})\times R_{bi}} - allocation effect
-#' \deqn{S_{i}=w_{pi}\times(R_{pi}-R_{bi})} - selection effect
-#' \deqn{I_{i}=(w_{pi}-w_{bi})\times(r_{i}-b_{i})} - interaction effect
-#' \deqn{r} - total portfolio returns
-#' \deqn{b} - total benchmark returns
-#' \deqn{w_{pi}} - weights of the category \deqn{i} in the portfolio
-#' \deqn{w_{bi}} - weigths of the category \deqn{i} in the benchmark
-#' \deqn{R_{pi}} - returns of the portfolio category \deqn{i}
-#' \deqn{R_{bi}} - returns of the benchmark category \deqn{i}
+#' Allocation effect
+#' \deqn{A_{i}=(w_{pi}-w_{bi})\times R_{bi}}
+#' Selection effect
+#' \deqn{S_{i}=w_{pi}\times(R_{pi}-R_{bi})}
+#' Interaction effect
+#' \deqn{I_{i}=(w_{pi}-w_{bi})\times(R_{pi}-R_{bi})}
+#' r - total portfolio returns, b - total benchmark returns, w_pi - weights of
+#' the category i in the portfolio, w_bi - weigths of the category i in the 
+#' benchmark, R_pi - returns of the portfolio category i, R_bi - returns of the
+#'  benchmark category i.
 #' If Brinson and Fachler (1985) is selected the allocation effect differs:
-#' \deqn{A_{i}=(w_{pi}-w_{bi})\times (R_{bi} - b)}
+#' \deqn{A_{i}=(w_{pi}-w_{bi})\times (R_{bi} - R_{b})}
 #' Depending on goals we can give priority to the allocation or to 
 #' the selection effects. If the priority is given to the sector allocation
 #' the interaction term will be combined with the security selection effect
@@ -42,41 +43,40 @@
 #' attribution effects should be adjusted using linking methods. Adjusted
 #' arithmetic attribution effects can be summed up over time to provide the
 #' multi-period summary: 
-#' \deqn{r-b=\overset{T}{\underset{t=1}{\sum}}\left(A_{t}'+S_{t}'+I_{t}'\right)}
-#' , where \deqn{T} - number of periods; prime stands for the adjustment.
+#' \deqn{R_{p}-R_{b}=\sum^{T}_{t=1}\left(A_{t}'+S_{t}'+I_{t}'\right)}
+#' where T is the number of periods and prime stands for the adjustment.
 #' The geometric attribution effects do not suffer from the linking problem.
 #' Moreover we don't have the interaction term. For more details about the 
-#' geometric attribution see the documentation to 
-#' \code{link{Attribution.geometric}}
-#' Finally, arithmetic annualized excess returns are computed as the 
-#' arithmetic difference between annualised portfolio and benchmark returns:
-#' \deqn{AAER=r_{a}-b_{a}}; the geometric annualized excess returns are
+#' geometric attribution see the documentation to \code{Attribution.geometric}
+#' Finally, arithmetic annualized excess returns are computed as the arithmetic
+#' difference between annualised portfolio and benchmark returns:
+#' \deqn{AAER=r_{a}-b_{a}} the geometric annualized excess returns are
 #' computed as the geometric difference between annualized portfolio
[TRUNCATED]

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


More information about the Returnanalytics-commits mailing list