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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Thu Sep 12 19:46:42 CEST 2013


Author: braverock
Date: 2013-09-12 19:46:41 +0200 (Thu, 12 Sep 2013)
New Revision: 3069

Added:
   pkg/PerformanceAnalytics/R/CAPM.dynamic.R
   pkg/PerformanceAnalytics/R/MarketTiming.R
   pkg/PerformanceAnalytics/R/Modigliani.R
   pkg/PerformanceAnalytics/man/CAPM.dynamic.Rd
   pkg/PerformanceAnalytics/man/MarketTiming.Rd
   pkg/PerformanceAnalytics/man/Modigliani.Rd
Removed:
   pkg/PortfolioAttribution/R/CAPM.dynamic.R
   pkg/PortfolioAttribution/R/MarketTiming.R
   pkg/PortfolioAttribution/R/Modigliani.R
   pkg/PortfolioAttribution/man/CAPM.dynamic.Rd
   pkg/PortfolioAttribution/man/MarketTiming.Rd
   pkg/PortfolioAttribution/man/Modigliani.Rd
Modified:
   pkg/PortfolioAttribution/NAMESPACE
Log:
- move CAPM.dynamic, MarketTiming, and Modigliani fns from PortfolioAttribution to PerformanceAnalytics


Copied: pkg/PerformanceAnalytics/R/CAPM.dynamic.R (from rev 3067, pkg/PortfolioAttribution/R/CAPM.dynamic.R)
===================================================================
--- pkg/PerformanceAnalytics/R/CAPM.dynamic.R	                        (rev 0)
+++ pkg/PerformanceAnalytics/R/CAPM.dynamic.R	2013-09-12 17:46:41 UTC (rev 3069)
@@ -0,0 +1,101 @@
+#' Time-varying conditional beta
+#' 
+#' CAPM is estimated assuming that betas and alphas change over time. It is 
+#' assumed that the market prices of securities fully reflect readily available
+#' and public information. A matrix of market information variables, \eqn{Z}
+#' measures this information. Possible variables in \eqn{Z} could be the
+#' divident yield, Tresaury yield, etc. The betas of stocks and managed
+#' portfolios are allowed to change with market conditions:
+#' \deqn{\beta_{p}(z_{t})=b_{0p}+B_{p}'z_{t}}{beta(zt) = b0 + Bp'zt}
+#' where \eqn{z_{t}=Z_{t}-E[Z]}{zt = Zt - E[Z]} - a normalized vector of the 
+#' deviations of \eqn{Z_{t}}{Zt}, \eqn{B_{p}}{Bp} - a vector with the same 
+#' dimension as \eqn{Z_{t}}{Zt}. The coefficient \eqn{b_{0p}}{b0} can be 
+#' interpreted as the "average beta" or the beta when all infromation variables
+#' are at their means. The elements of \eqn{B_{p}}{Bp} measure the sensitivity 
+#' of the conditional beta to the deviations of the \eqn{Z_{t}}{Zt} from their
+#' means. 
+#' In the similar way the time-varying conditional alpha is modeled:
+#' \deqn{\alpha_{pt}=\alpha_{p}(z_{t})=\alpha_{0p}+A_{p}'z_{t}}{alpha(zt) = 
+#' a0 + Ap'zt}
+#' The modified regression is therefore:
+#' \deqn{r_{pt+1}=\alpha_{0p}+A_{p}'z_{t}+b_{0p}r_{bt+1}+B_{p}'[z_{t}r_{bt+1}]+
+#' \mu_{pt+1}}
+#' 
+#' @param Ra an xts, vector, matrix, data frame, timeSeries or zoo object of
+#' the asset returns
+#' @param Rb an xts, vector, matrix, data frame, timeSeries or zoo object of 
+#' the benchmark asset return
+#' @param Rf risk free rate, in same period as your returns
+#' @param Z an xts, vector, matrix, data frame, timeSeries or zoo object of 
+#' k variables that reflect public information
+#' @param lags number of lags before the current period on which the alpha and
+#' beta are conditioned
+#' @param \dots any other passthrough parameters
+#' @author Andrii Babii
+#' @seealso \code{\link{CAPM.beta}}
+#' @references J. Christopherson, D. Carino, W. Ferson. \emph{Portfolio 
+#' Performance Measurement and Benchmarking}. 2009. McGraw-Hill. Chapter 12. 
+#' \cr Wayne E. Ferson and Rudi Schadt, "Measuring Fund Strategy and 
+#' Performance in Changing Economic Conditions," \emph{Journal of Finance}, 
+#' vol. 51, 1996, pp.425-462 \cr
+#' @examples
+#' 
+#' data(managers)
+#' CAPM.dynamic(managers[,1,drop=FALSE], managers[,8,drop=FALSE], Rf=.035/12, Z=managers[, 9:10])
+#' CAPM.dynamic(managers[80:120,1:6], managers[80:120,7,drop=FALSE], Rf=managers[80:120,10,drop=FALSE], Z=managers[80:120, 9:10])
+#' CAPM.dynamic(managers[80:120,1:6], managers[80:120,8:7], managers[80:120,10,drop=FALSE], Z=managers[80:120, 9:10])
+#'
+#' @export
+CAPM.dynamic <- function (Ra, Rb, Rf = 0, Z, lags = 1, ...)
+{ # @author Andrii Babii
+    
+    # FUNCTION
+  
+    Ra = checkData(Ra)
+    Rb = checkData(Rb)
+    Z = checkData(Z)
+    Z = na.omit(Z)
+    if (!is.null(dim(Rf))) 
+      Rf = checkData(Rf)
+    Ra.ncols = NCOL(Ra)
+    Rb.ncols = NCOL(Rb)
+    pairs = expand.grid(1:Ra.ncols)
+    
+    xRa = Return.excess(Ra, Rf)[1:(nrow(Ra) - 1)]
+    xRb = Return.excess(Rb, Rf)[1:(nrow(Rb) - 1)]
+    z = Z - matrix(rep(mean(Z), nrow(Z)), nrow(Z), ncol(Z), byrow = TRUE)
+    # Construct the matrix with information regressors (lagged values)
+    inform = lag(z)
+    if (lags > 1){
+      for (i in 2:lags) {
+        inform = cbind(inform, lag(z, i))
+      }
+    }
+    z = inform[(lags + 1):nrow(z), ]
+        
+    dynamic <- function (xRa, xRb, z){
+      y = xRa[1:nrow(z)]
+      X = cbind(z, coredata(xRb[1:nrow(z)]), z * matrix(rep(xRb[1:nrow(z)], ncol(z)), nrow(z), ncol(z)))
+      X.df = as.data.frame(X)
+      model = lm(xRa[1:nrow(z)] ~ 1 + ., data = X.df)
+      return(coef(model))
+    }
+    result = apply(pairs, 1, FUN = function(n, xRa, xRb, z) 
+      dynamic(xRa[, n[1]], xRb[, 1], z), xRa = xRa, xRb = xRb, z = z)
+    result = t(result)
+    
+    if (ncol(Rb) > 1){
+      for (i in 2:ncol(xRb)){
+        res = apply(pairs, 1, FUN = function(n, xRa, xRb, z) 
+          dynamic(xRa[, n[1]], xRb[, i], z), xRa = xRa, xRb = xRb, z = z)
+        res = t(res)
+        result = rbind(result, res)
+      }
+    }
+    
+    a = paste(rep(colnames(Z), lags), "alpha at t -", expand.grid(1:ncol(Z), 1:lags)[, 2])
+    b = paste(rep(colnames(Z), lags), "beta at t -", expand.grid(1:ncol(Z), 1:lags)[, 2])
+    colnames(result) = c("Average alpha", a, "Average beta", b)
+    rownames(result) = paste(rep(colnames(Ra), ncol(Rb)), "to",  rep(colnames(Rb), each = ncol(Ra)))
+    return(result)
+}
\ No newline at end of file

Copied: pkg/PerformanceAnalytics/R/MarketTiming.R (from rev 3067, pkg/PortfolioAttribution/R/MarketTiming.R)
===================================================================
--- pkg/PerformanceAnalytics/R/MarketTiming.R	                        (rev 0)
+++ pkg/PerformanceAnalytics/R/MarketTiming.R	2013-09-12 17:46:41 UTC (rev 3069)
@@ -0,0 +1,96 @@
+#' Market timing models
+#' 
+#' Allows to estimate Treynor-Mazuy or Merton-Henriksson market timing model.
+#' The Treynor-Mazuy model is essentially a quadratic extension of the basic
+#' CAPM. It is estimated using a multiple regression. The second term in the
+#' regression is the value of excess return squared. If the gamma coefficient
+#' in the regression is positive, then the estimated equation describes a 
+#' convex upward-sloping regression "line". The quadratic regression is:
+#' \deqn{R_{p}-R_{f}=\alpha+\beta (R_{b} - R_{f})+\gamma (R_{b}-R_{f})^2+
+#' \varepsilon_{p}}{Rp - Rf = alpha + beta(Rb -Rf) + gamma(Rb - Rf)^2 + 
+#' epsilonp}
+#' \eqn{\gamma}{gamma} is a measure of the curvature of the regression line.
+#' If \eqn{\gamma}{gamma} is positive, this would indicate that the manager's
+#' investment strategy demonstrates market timing ability.
+#' 
+#' The basic idea of the Merton-Henriksson test is to perform a multiple 
+#' regression in which the dependent variable (portfolio excess return and a 
+#' second variable that mimics the payoff to an option). This second variable 
+#' is zero when the market excess return is at or below zero and is 1 when it 
+#' is above zero:
+#' \deqn{R_{p}-R_{f}=\alpha+\beta (R_{b}-R_{f})+\gamma D+\varepsilon_{p}}{Rp - 
+#' Rf = alpha + beta * (Rb - Rf) + gamma * D + epsilonp}
+#' where all variables are familiar from the CAPM model, except for the 
+#' up-market return \eqn{D=max(0,R_{b}-R_{f})}{D = max(0, Rb - Rf)} and market 
+#' timing abilities \eqn{\gamma}{gamma}
+#' @param Ra an xts, vector, matrix, data frame, timeSeries or zoo object of
+#' the asset returns
+#' @param Rb an xts, vector, matrix, data frame, timeSeries or zoo object of 
+#' the benchmark asset return
+#' @param Rf risk free rate, in same period as your returns
+#' @param method used to select between Treynor-Mazuy and Henriksson-Merton
+#' models. May be any of: \itemize{ \item TM - Treynor-Mazuy model, 
+#' \item HM - Henriksson-Merton model} By default Treynor-Mazuy is selected
+#' @param \dots any other passthrough parameters
+#' @author Andrii Babii, Peter Carl
+#' @seealso \code{\link{CAPM.beta}}
+#' @references J. Christopherson, D. Carino, W. Ferson. \emph{Portfolio 
+#' Performance Measurement and Benchmarking}. 2009. McGraw-Hill, p. 127-133.
+#' \cr J. L. Treynor and K. Mazuy, "Can Mutual Funds Outguess the Market?" 
+#' \emph{Harvard Business Review}, vol44, 1966, pp. 131-136 
+#' \cr Roy D. Henriksson and Robert C. Merton, "On Market Timing and Investment
+#' Performance. II. Statistical Procedures for Evaluating Forecast Skills," 
+#' \emph{Journal of Business}, vol.54, October 1981, pp.513-533 \cr
+#' @examples
+#' 
+#' data(managers)
+#' MarketTiming(managers[,1,drop=FALSE], managers[,8,drop=FALSE], Rf=.035/12, method = "HM")
+#' MarketTiming(managers[80:120,1:6], managers[80:120,7,drop=FALSE], managers[80:120,10,drop=FALSE])
+#' MarketTiming(managers[80:120,1:6], managers[80:120,8:7], managers[80:120,10,drop=FALSE], method = "TM")
+#'
+#' @export
+MarketTiming <- function (Ra, Rb, Rf = 0, method = c("TM", "HM"))
+{ # @author Andrii Babii, Peter Carl
+  
+    # FUNCTION
+  
+    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)
+    method = method[1]
+    xRa = Return.excess(Ra, Rf)
+    xRb = Return.excess(Rb, Rf)
+
+    mt <- function (xRa, xRb)
+    {
+      switch(method,
+             "HM" = { S = xRb > 0 },
+             "TM" = { S = xRb }
+      )
+      R = merge(xRa, xRb, xRb*S)
+      R.df = as.data.frame(R)
+      model = lm(R.df[, 1] ~ 1 + ., data = R.df[, -1])
+      return(coef(model))
+    }
+  
+    result = apply(pairs, 1, FUN = function(n, xRa, xRb) 
+      mt(xRa[, n[1]], xRb[, 1]), xRa = xRa, xRb = xRb)
+    result = t(result)
+    
+    if (ncol(Rb) > 1){
+      for (i in 2:ncol(xRb)){
+        res = apply(pairs, 1, FUN = function(n, xRa, xRb) 
+          mt(xRa[, n[1]], xRb[, i]), xRa = xRa, xRb = xRb)
+        res = t(res)
+        result = rbind(result, res)
+      }
+    }
+  
+    rownames(result) = paste(rep(colnames(Ra), ncol(Rb)), "to",  rep(colnames(Rb), each = ncol(Ra)))
+    colnames(result) = c("Alpha", "Beta", "Gamma")
+    return(result)
+}
\ No newline at end of file

Copied: pkg/PerformanceAnalytics/R/Modigliani.R (from rev 3067, pkg/PortfolioAttribution/R/Modigliani.R)
===================================================================
--- pkg/PerformanceAnalytics/R/Modigliani.R	                        (rev 0)
+++ pkg/PerformanceAnalytics/R/Modigliani.R	2013-09-12 17:46:41 UTC (rev 3069)
@@ -0,0 +1,60 @@
+#' 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.
+#' \deqn{MM_{p}=\frac{E[R_{p} - R_{f}]}{\sigma_{p}}=SR_{p} * \sigma_{b} + 
+#' E[R_{f}]}{MMp = SRp * sigmab + E[Rf]}
+#' where \eqn{SR_{p}}{SRp} - Sharpe ratio, \eqn{\sigma_{b}}{sigmab} - benchmark
+#' standard deviation
+#' 
+#' 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. \emph{Portfolio 
+#' Performance Measurement and Benchmarking}. 2009. McGraw-Hill, p. 97-99. \cr
+#' Franco Modigliani and Leah Modigliani, "Risk-Adjusted Performance: How to 
+#' Measure It and Why," \emph{Journal of Portfolio Management}, vol.23, no., 
+#' Winter 1997, pp.45-54 \cr
+#' @seealso \code{\link{SharpeRatio}}, \code{\link{TreynorRatio}}
+#' @examples
+#' 
+#' data(managers)
+#' Modigliani(managers[,1,drop=FALSE], managers[,8,drop=FALSE], Rf=.035/12)
+#' Modigliani(managers[,1:6], managers[,8,drop=FALSE], managers[,8,drop=FALSE])
+#' Modigliani(managers[,1:6], managers[,8:7], managers[,8,drop=FALSE])
+#' 
+#' @export
+Modigliani <- function (Ra, Rb, Rf=0, ...)
+{ # @author Andrii Babii, Brian G. Peterson
+    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) + mean(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/PerformanceAnalytics/man/CAPM.dynamic.Rd (from rev 3067, pkg/PortfolioAttribution/man/CAPM.dynamic.Rd)
===================================================================
--- pkg/PerformanceAnalytics/man/CAPM.dynamic.Rd	                        (rev 0)
+++ pkg/PerformanceAnalytics/man/CAPM.dynamic.Rd	2013-09-12 17:46:41 UTC (rev 3069)
@@ -0,0 +1,70 @@
+\name{CAPM.dynamic}
+\alias{CAPM.dynamic}
+\title{Time-varying conditional beta}
+\usage{
+  CAPM.dynamic(Ra, Rb, Rf = 0, Z, lags = 1, ...)
+}
+\arguments{
+  \item{Ra}{an xts, vector, matrix, data frame, timeSeries
+  or zoo object of the asset returns}
+
+  \item{Rb}{an xts, vector, matrix, data frame, timeSeries
+  or zoo object of the benchmark asset return}
+
+  \item{Rf}{risk free rate, in same period as your returns}
+
+  \item{Z}{an xts, vector, matrix, data frame, timeSeries
+  or zoo object of k variables that reflect public
+  information}
+
+  \item{lags}{number of lags before the current period on
+  which the alpha and beta are conditioned}
+
+  \item{\dots}{any other passthrough parameters}
+}
+\description{
+  CAPM is estimated assuming that betas and alphas change
+  over time. It is assumed that the market prices of
+  securities fully reflect readily available and public
+  information. A matrix of market information variables,
+  \eqn{Z} measures this information. Possible variables in
+  \eqn{Z} could be the divident yield, Tresaury yield, etc.
+  The betas of stocks and managed portfolios are allowed to
+  change with market conditions:
+  \deqn{\beta_{p}(z_{t})=b_{0p}+B_{p}'z_{t}}{beta(zt) = b0
+  + Bp'zt} where \eqn{z_{t}=Z_{t}-E[Z]}{zt = Zt - E[Z]} - a
+  normalized vector of the deviations of \eqn{Z_{t}}{Zt},
+  \eqn{B_{p}}{Bp} - a vector with the same dimension as
+  \eqn{Z_{t}}{Zt}. The coefficient \eqn{b_{0p}}{b0} can be
+  interpreted as the "average beta" or the beta when all
+  infromation variables are at their means. The elements of
+  \eqn{B_{p}}{Bp} measure the sensitivity of the
+  conditional beta to the deviations of the \eqn{Z_{t}}{Zt}
+  from their means. In the similar way the time-varying
+  conditional alpha is modeled:
+  \deqn{\alpha_{pt}=\alpha_{p}(z_{t})=\alpha_{0p}+A_{p}'z_{t}}{alpha(zt)
+  = a0 + Ap'zt} The modified regression is therefore:
+  \deqn{r_{pt+1}=\alpha_{0p}+A_{p}'z_{t}+b_{0p}r_{bt+1}+B_{p}'[z_{t}r_{bt+1}]+
+  \mu_{pt+1}}
+}
+\examples{
+data(managers)
+CAPM.dynamic(managers[,1,drop=FALSE], managers[,8,drop=FALSE], Rf=.035/12, Z=managers[, 9:10])
+CAPM.dynamic(managers[80:120,1:6], managers[80:120,7,drop=FALSE], Rf=managers[80:120,10,drop=FALSE], Z=managers[80:120, 9:10])
+CAPM.dynamic(managers[80:120,1:6], managers[80:120,8:7], managers[80:120,10,drop=FALSE], Z=managers[80:120, 9:10])
+}
+\author{
+  Andrii Babii
+}
+\references{
+  J. Christopherson, D. Carino, W. Ferson. \emph{Portfolio
+  Performance Measurement and Benchmarking}. 2009.
+  McGraw-Hill. Chapter 12. \cr Wayne E. Ferson and Rudi
+  Schadt, "Measuring Fund Strategy and Performance in
+  Changing Economic Conditions," \emph{Journal of Finance},
+  vol. 51, 1996, pp.425-462 \cr
+}
+\seealso{
+  \code{\link{CAPM.beta}}
+}
+

Copied: pkg/PerformanceAnalytics/man/MarketTiming.Rd (from rev 3067, pkg/PortfolioAttribution/man/MarketTiming.Rd)
===================================================================
--- pkg/PerformanceAnalytics/man/MarketTiming.Rd	                        (rev 0)
+++ pkg/PerformanceAnalytics/man/MarketTiming.Rd	2013-09-12 17:46:41 UTC (rev 3069)
@@ -0,0 +1,77 @@
+\name{MarketTiming}
+\alias{MarketTiming}
+\title{Market timing models}
+\usage{
+  MarketTiming(Ra, Rb, Rf = 0, method = c("TM", "HM"))
+}
+\arguments{
+  \item{Ra}{an xts, vector, matrix, data frame, timeSeries
+  or zoo object of the asset returns}
+
+  \item{Rb}{an xts, vector, matrix, data frame, timeSeries
+  or zoo object of the benchmark asset return}
+
+  \item{Rf}{risk free rate, in same period as your returns}
+
+  \item{method}{used to select between Treynor-Mazuy and
+  Henriksson-Merton models. May be any of: \itemize{ \item
+  TM - Treynor-Mazuy model, \item HM - Henriksson-Merton
+  model} By default Treynor-Mazuy is selected}
+
+  \item{\dots}{any other passthrough parameters}
+}
+\description{
+  Allows to estimate Treynor-Mazuy or Merton-Henriksson
+  market timing model. The Treynor-Mazuy model is
+  essentially a quadratic extension of the basic CAPM. It
+  is estimated using a multiple regression. The second term
+  in the regression is the value of excess return squared.
+  If the gamma coefficient in the regression is positive,
+  then the estimated equation describes a convex
+  upward-sloping regression "line". The quadratic
+  regression is: \deqn{R_{p}-R_{f}=\alpha+\beta (R_{b} -
+  R_{f})+\gamma (R_{b}-R_{f})^2+ \varepsilon_{p}}{Rp - Rf =
+  alpha + beta(Rb -Rf) + gamma(Rb - Rf)^2 + epsilonp}
+  \eqn{\gamma}{gamma} is a measure of the curvature of the
+  regression line. If \eqn{\gamma}{gamma} is positive, this
+  would indicate that the manager's investment strategy
+  demonstrates market timing ability.
+}
+\details{
+  The basic idea of the Merton-Henriksson test is to
+  perform a multiple regression in which the dependent
+  variable (portfolio excess return and a second variable
+  that mimics the payoff to an option). This second
+  variable is zero when the market excess return is at or
+  below zero and is 1 when it is above zero:
+  \deqn{R_{p}-R_{f}=\alpha+\beta (R_{b}-R_{f})+\gamma
+  D+\varepsilon_{p}}{Rp - Rf = alpha + beta * (Rb - Rf) +
+  gamma * D + epsilonp} where all variables are familiar
+  from the CAPM model, except for the up-market return
+  \eqn{D=max(0,R_{b}-R_{f})}{D = max(0, Rb - Rf)} and
+  market timing abilities \eqn{\gamma}{gamma}
+}
+\examples{
+data(managers)
+MarketTiming(managers[,1,drop=FALSE], managers[,8,drop=FALSE], Rf=.035/12, method = "HM")
+MarketTiming(managers[80:120,1:6], managers[80:120,7,drop=FALSE], managers[80:120,10,drop=FALSE])
+MarketTiming(managers[80:120,1:6], managers[80:120,8:7], managers[80:120,10,drop=FALSE], method = "TM")
+}
+\author{
+  Andrii Babii, Peter Carl
+}
+\references{
+  J. Christopherson, D. Carino, W. Ferson. \emph{Portfolio
+  Performance Measurement and Benchmarking}. 2009.
+  McGraw-Hill, p. 127-133. \cr J. L. Treynor and K. Mazuy,
+  "Can Mutual Funds Outguess the Market?" \emph{Harvard
+  Business Review}, vol44, 1966, pp. 131-136 \cr Roy D.
+  Henriksson and Robert C. Merton, "On Market Timing and
+  Investment Performance. II. Statistical Procedures for
+  Evaluating Forecast Skills," \emph{Journal of Business},
+  vol.54, October 1981, pp.513-533 \cr
+}
+\seealso{
+  \code{\link{CAPM.beta}}
+}
+

Copied: pkg/PerformanceAnalytics/man/Modigliani.Rd (from rev 3067, pkg/PortfolioAttribution/man/Modigliani.Rd)
===================================================================
--- pkg/PerformanceAnalytics/man/Modigliani.Rd	                        (rev 0)
+++ pkg/PerformanceAnalytics/man/Modigliani.Rd	2013-09-12 17:46:41 UTC (rev 3069)
@@ -0,0 +1,54 @@
+\name{Modigliani}
+\alias{Modigliani}
+\title{Modigliani-Modigliani measure}
+\usage{
+  Modigliani(Ra, Rb, Rf = 0, ...)
+}
+\arguments{
+  \item{Ra}{an xts, vector, matrix, data frame, timeSeries
+  or zoo object of asset returns}
+
+  \item{Rb}{return vector of the benchmark asset}
+
+  \item{Rf}{risk free rate, in same period as your returns}
+
+  \item{\dots}{any other passthrough parameters}
+}
+\description{
+  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. \deqn{MM_{p}=\frac{E[R_{p} -
+  R_{f}]}{\sigma_{p}}=SR_{p} * \sigma_{b} + E[R_{f}]}{MMp =
+  SRp * sigmab + E[Rf]} where \eqn{SR_{p}}{SRp} - Sharpe
+  ratio, \eqn{\sigma_{b}}{sigmab} - benchmark standard
+  deviation
+}
+\details{
+  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.
+}
+\examples{
+data(managers)
+Modigliani(managers[,1,drop=FALSE], managers[,8,drop=FALSE], Rf=.035/12)
+Modigliani(managers[,1:6], managers[,8,drop=FALSE], managers[,8,drop=FALSE])
+Modigliani(managers[,1:6], managers[,8:7], managers[,8,drop=FALSE])
+}
+\author{
+  Andrii Babii, Brian G. Peterson
+}
+\references{
+  J. Christopherson, D. Carino, W. Ferson. \emph{Portfolio
+  Performance Measurement and Benchmarking}. 2009.
+  McGraw-Hill, p. 97-99. \cr Franco Modigliani and Leah
+  Modigliani, "Risk-Adjusted Performance: How to Measure It
+  and Why," \emph{Journal of Portfolio Management}, vol.23,
+  no., Winter 1997, pp.45-54 \cr
+}
+\seealso{
+  \code{\link{SharpeRatio}}, \code{\link{TreynorRatio}}
+}
+

Modified: pkg/PortfolioAttribution/NAMESPACE
===================================================================
--- pkg/PortfolioAttribution/NAMESPACE	2013-09-12 17:43:38 UTC (rev 3068)
+++ pkg/PortfolioAttribution/NAMESPACE	2013-09-12 17:46:41 UTC (rev 3069)
@@ -2,16 +2,13 @@
 export(AttributionFixedIncome)
 export(Attribution.geometric)
 export(Attribution.levels)
-export(CAPM.dynamic)
 export(Carino)
 export(Conv.option)
 export(DaviesLaker)
 export(Frongello)
 export(Grap)
 export(HierarchyQuintiles)
-export(MarketTiming)
 export(Menchero)
-export(Modigliani)
 export(Return.annualized.excess)
 export(Return.level)
 export(Weight.level)

Deleted: pkg/PortfolioAttribution/R/CAPM.dynamic.R
===================================================================
--- pkg/PortfolioAttribution/R/CAPM.dynamic.R	2013-09-12 17:43:38 UTC (rev 3068)
+++ pkg/PortfolioAttribution/R/CAPM.dynamic.R	2013-09-12 17:46:41 UTC (rev 3069)
@@ -1,101 +0,0 @@
-#' Time-varying conditional beta
-#' 
-#' CAPM is estimated assuming that betas and alphas change over time. It is 
-#' assumed that the market prices of securities fully reflect readily available
-#' and public information. A matrix of market information variables, \eqn{Z}
-#' measures this information. Possible variables in \eqn{Z} could be the
-#' divident yield, Tresaury yield, etc. The betas of stocks and managed
-#' portfolios are allowed to change with market conditions:
-#' \deqn{\beta_{p}(z_{t})=b_{0p}+B_{p}'z_{t}}{beta(zt) = b0 + Bp'zt}
-#' where \eqn{z_{t}=Z_{t}-E[Z]}{zt = Zt - E[Z]} - a normalized vector of the 
-#' deviations of \eqn{Z_{t}}{Zt}, \eqn{B_{p}}{Bp} - a vector with the same 
-#' dimension as \eqn{Z_{t}}{Zt}. The coefficient \eqn{b_{0p}}{b0} can be 
-#' interpreted as the "average beta" or the beta when all infromation variables
-#' are at their means. The elements of \eqn{B_{p}}{Bp} measure the sensitivity 
-#' of the conditional beta to the deviations of the \eqn{Z_{t}}{Zt} from their
-#' means. 
-#' In the similar way the time-varying conditional alpha is modeled:
-#' \deqn{\alpha_{pt}=\alpha_{p}(z_{t})=\alpha_{0p}+A_{p}'z_{t}}{alpha(zt) = 
-#' a0 + Ap'zt}
-#' The modified regression is therefore:
-#' \deqn{r_{pt+1}=\alpha_{0p}+A_{p}'z_{t}+b_{0p}r_{bt+1}+B_{p}'[z_{t}r_{bt+1}]+
-#' \mu_{pt+1}}
-#' 
-#' @param Ra an xts, vector, matrix, data frame, timeSeries or zoo object of
-#' the asset returns
-#' @param Rb an xts, vector, matrix, data frame, timeSeries or zoo object of 
-#' the benchmark asset return
-#' @param Rf risk free rate, in same period as your returns
-#' @param Z an xts, vector, matrix, data frame, timeSeries or zoo object of 
-#' k variables that reflect public information
-#' @param lags number of lags before the current period on which the alpha and
-#' beta are conditioned
-#' @param \dots any other passthrough parameters
-#' @author Andrii Babii
-#' @seealso \code{\link{CAPM.beta}}
-#' @references J. Christopherson, D. Carino, W. Ferson. \emph{Portfolio 
-#' Performance Measurement and Benchmarking}. 2009. McGraw-Hill. Chapter 12. 
-#' \cr Wayne E. Ferson and Rudi Schadt, "Measuring Fund Strategy and 
-#' Performance in Changing Economic Conditions," \emph{Journal of Finance}, 
-#' vol. 51, 1996, pp.425-462 \cr
-#' @examples
-#' 
-#' data(managers)
-#' CAPM.dynamic(managers[,1,drop=FALSE], managers[,8,drop=FALSE], Rf=.035/12, Z=managers[, 9:10])
-#' CAPM.dynamic(managers[80:120,1:6], managers[80:120,7,drop=FALSE], Rf=managers[80:120,10,drop=FALSE], Z=managers[80:120, 9:10])
-#' CAPM.dynamic(managers[80:120,1:6], managers[80:120,8:7], managers[80:120,10,drop=FALSE], Z=managers[80:120, 9:10])
-#'
-#' @export
-CAPM.dynamic <- function (Ra, Rb, Rf = 0, Z, lags = 1, ...)
-{ # @author Andrii Babii
-    
-    # FUNCTION
-  
-    Ra = checkData(Ra)
-    Rb = checkData(Rb)
-    Z = checkData(Z)
-    Z = na.omit(Z)
-    if (!is.null(dim(Rf))) 
-      Rf = checkData(Rf)
-    Ra.ncols = NCOL(Ra)
-    Rb.ncols = NCOL(Rb)
-    pairs = expand.grid(1:Ra.ncols)
-    
-    xRa = Return.excess(Ra, Rf)[1:(nrow(Ra) - 1)]
-    xRb = Return.excess(Rb, Rf)[1:(nrow(Rb) - 1)]
-    z = Z - matrix(rep(mean(Z), nrow(Z)), nrow(Z), ncol(Z), byrow = TRUE)
-    # Construct the matrix with information regressors (lagged values)
-    inform = lag(z)
-    if (lags > 1){
-      for (i in 2:lags) {
-        inform = cbind(inform, lag(z, i))
-      }
-    }
-    z = inform[(lags + 1):nrow(z), ]
-        
-    dynamic <- function (xRa, xRb, z){
-      y = xRa[1:nrow(z)]
-      X = cbind(z, coredata(xRb[1:nrow(z)]), z * matrix(rep(xRb[1:nrow(z)], ncol(z)), nrow(z), ncol(z)))
-      X.df = as.data.frame(X)
-      model = lm(xRa[1:nrow(z)] ~ 1 + ., data = X.df)
-      return(coef(model))
-    }
-    result = apply(pairs, 1, FUN = function(n, xRa, xRb, z) 
-      dynamic(xRa[, n[1]], xRb[, 1], z), xRa = xRa, xRb = xRb, z = z)
-    result = t(result)
-    
-    if (ncol(Rb) > 1){
-      for (i in 2:ncol(xRb)){
-        res = apply(pairs, 1, FUN = function(n, xRa, xRb, z) 
-          dynamic(xRa[, n[1]], xRb[, i], z), xRa = xRa, xRb = xRb, z = z)
-        res = t(res)
-        result = rbind(result, res)
-      }
-    }
-    
-    a = paste(rep(colnames(Z), lags), "alpha at t -", expand.grid(1:ncol(Z), 1:lags)[, 2])
-    b = paste(rep(colnames(Z), lags), "beta at t -", expand.grid(1:ncol(Z), 1:lags)[, 2])
-    colnames(result) = c("Average alpha", a, "Average beta", b)
-    rownames(result) = paste(rep(colnames(Ra), ncol(Rb)), "to",  rep(colnames(Rb), each = ncol(Ra)))
-    return(result)
-}
\ No newline at end of file

Deleted: pkg/PortfolioAttribution/R/MarketTiming.R
===================================================================
--- pkg/PortfolioAttribution/R/MarketTiming.R	2013-09-12 17:43:38 UTC (rev 3068)
+++ pkg/PortfolioAttribution/R/MarketTiming.R	2013-09-12 17:46:41 UTC (rev 3069)
@@ -1,96 +0,0 @@
-#' Market timing models
-#' 
-#' Allows to estimate Treynor-Mazuy or Merton-Henriksson market timing model.
-#' The Treynor-Mazuy model is essentially a quadratic extension of the basic
-#' CAPM. It is estimated using a multiple regression. The second term in the
-#' regression is the value of excess return squared. If the gamma coefficient
-#' in the regression is positive, then the estimated equation describes a 
-#' convex upward-sloping regression "line". The quadratic regression is:
-#' \deqn{R_{p}-R_{f}=\alpha+\beta (R_{b} - R_{f})+\gamma (R_{b}-R_{f})^2+
-#' \varepsilon_{p}}{Rp - Rf = alpha + beta(Rb -Rf) + gamma(Rb - Rf)^2 + 
-#' epsilonp}
-#' \eqn{\gamma}{gamma} is a measure of the curvature of the regression line.
-#' If \eqn{\gamma}{gamma} is positive, this would indicate that the manager's
-#' investment strategy demonstrates market timing ability.
-#' 
-#' The basic idea of the Merton-Henriksson test is to perform a multiple 
-#' regression in which the dependent variable (portfolio excess return and a 
-#' second variable that mimics the payoff to an option). This second variable 
-#' is zero when the market excess return is at or below zero and is 1 when it 
-#' is above zero:
-#' \deqn{R_{p}-R_{f}=\alpha+\beta (R_{b}-R_{f})+\gamma D+\varepsilon_{p}}{Rp - 
-#' Rf = alpha + beta * (Rb - Rf) + gamma * D + epsilonp}
-#' where all variables are familiar from the CAPM model, except for the 
-#' up-market return \eqn{D=max(0,R_{b}-R_{f})}{D = max(0, Rb - Rf)} and market 
-#' timing abilities \eqn{\gamma}{gamma}
-#' @param Ra an xts, vector, matrix, data frame, timeSeries or zoo object of
-#' the asset returns
-#' @param Rb an xts, vector, matrix, data frame, timeSeries or zoo object of 
-#' the benchmark asset return
-#' @param Rf risk free rate, in same period as your returns
-#' @param method used to select between Treynor-Mazuy and Henriksson-Merton
-#' models. May be any of: \itemize{ \item TM - Treynor-Mazuy model, 
-#' \item HM - Henriksson-Merton model} By default Treynor-Mazuy is selected
-#' @param \dots any other passthrough parameters
-#' @author Andrii Babii, Peter Carl
-#' @seealso \code{\link{CAPM.beta}}
-#' @references J. Christopherson, D. Carino, W. Ferson. \emph{Portfolio 
-#' Performance Measurement and Benchmarking}. 2009. McGraw-Hill, p. 127-133.
-#' \cr J. L. Treynor and K. Mazuy, "Can Mutual Funds Outguess the Market?" 
-#' \emph{Harvard Business Review}, vol44, 1966, pp. 131-136 
-#' \cr Roy D. Henriksson and Robert C. Merton, "On Market Timing and Investment
-#' Performance. II. Statistical Procedures for Evaluating Forecast Skills," 
-#' \emph{Journal of Business}, vol.54, October 1981, pp.513-533 \cr
-#' @examples
-#' 
-#' data(managers)
-#' MarketTiming(managers[,1,drop=FALSE], managers[,8,drop=FALSE], Rf=.035/12, method = "HM")
-#' MarketTiming(managers[80:120,1:6], managers[80:120,7,drop=FALSE], managers[80:120,10,drop=FALSE])
-#' MarketTiming(managers[80:120,1:6], managers[80:120,8:7], managers[80:120,10,drop=FALSE], method = "TM")
-#'
-#' @export
-MarketTiming <- function (Ra, Rb, Rf = 0, method = c("TM", "HM"))
-{ # @author Andrii Babii, Peter Carl
-  
-    # FUNCTION
-  
-    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)
-    method = method[1]
-    xRa = Return.excess(Ra, Rf)
-    xRb = Return.excess(Rb, Rf)
-
-    mt <- function (xRa, xRb)
-    {
-      switch(method,
-             "HM" = { S = xRb > 0 },
-             "TM" = { S = xRb }
-      )
-      R = merge(xRa, xRb, xRb*S)
-      R.df = as.data.frame(R)
-      model = lm(R.df[, 1] ~ 1 + ., data = R.df[, -1])
-      return(coef(model))
-    }
-  
-    result = apply(pairs, 1, FUN = function(n, xRa, xRb) 
-      mt(xRa[, n[1]], xRb[, 1]), xRa = xRa, xRb = xRb)
-    result = t(result)
-    
-    if (ncol(Rb) > 1){
-      for (i in 2:ncol(xRb)){
-        res = apply(pairs, 1, FUN = function(n, xRa, xRb) 
-          mt(xRa[, n[1]], xRb[, i]), xRa = xRa, xRb = xRb)
-        res = t(res)
-        result = rbind(result, res)
-      }
-    }
-  
-    rownames(result) = paste(rep(colnames(Ra), ncol(Rb)), "to",  rep(colnames(Rb), each = ncol(Ra)))
-    colnames(result) = c("Alpha", "Beta", "Gamma")
-    return(result)
-}
\ No newline at end of file

Deleted: pkg/PortfolioAttribution/R/Modigliani.R
===================================================================
--- pkg/PortfolioAttribution/R/Modigliani.R	2013-09-12 17:43:38 UTC (rev 3068)
+++ pkg/PortfolioAttribution/R/Modigliani.R	2013-09-12 17:46:41 UTC (rev 3069)
@@ -1,60 +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.
-#' \deqn{MM_{p}=\frac{E[R_{p} - R_{f}]}{\sigma_{p}}=SR_{p} * \sigma_{b} + 
-#' E[R_{f}]}{MMp = SRp * sigmab + E[Rf]}
-#' where \eqn{SR_{p}}{SRp} - Sharpe ratio, \eqn{\sigma_{b}}{sigmab} - benchmark
-#' standard deviation
-#' 
-#' 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. \emph{Portfolio 
-#' Performance Measurement and Benchmarking}. 2009. McGraw-Hill, p. 97-99. \cr
-#' Franco Modigliani and Leah Modigliani, "Risk-Adjusted Performance: How to 
-#' Measure It and Why," \emph{Journal of Portfolio Management}, vol.23, no., 
-#' Winter 1997, pp.45-54 \cr
-#' @seealso \code{\link{SharpeRatio}}, \code{\link{TreynorRatio}}
-#' @examples
-#' 
-#' data(managers)
-#' Modigliani(managers[,1,drop=FALSE], managers[,8,drop=FALSE], Rf=.035/12)
[TRUNCATED]

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


More information about the Returnanalytics-commits mailing list