[Returnanalytics-commits] r2989 - in pkg/FactorAnalytics: R man

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed Sep 4 23:05:13 CEST 2013


Author: chenyian
Date: 2013-09-04 23:05:13 +0200 (Wed, 04 Sep 2013)
New Revision: 2989

Modified:
   pkg/FactorAnalytics/R/factorModelPerformanceAttribution.r
   pkg/FactorAnalytics/man/factorModelPerformanceAttribution.Rd
Log:
cancel benchmark function in factorModelPerformanceAttribution.r. I think it works better to use fit function then apply performance attribution analysis. 

Modified: pkg/FactorAnalytics/R/factorModelPerformanceAttribution.r
===================================================================
--- pkg/FactorAnalytics/R/factorModelPerformanceAttribution.r	2013-09-04 20:47:13 UTC (rev 2988)
+++ pkg/FactorAnalytics/R/factorModelPerformanceAttribution.r	2013-09-04 21:05:13 UTC (rev 2989)
@@ -10,16 +10,8 @@
 #' j. The returns attributed to factor j is \eqn{b_{j} * f_{jt}} and specific 
 #' returns is \eqn{u_t}. 
 #' 
-#' If benchmark is provided. active returns = total returns  - benchmark returns =
-#' active returns attributed to factors + specific returns. Specifically,  
-#' \eqn{R_t = \sum_j b_{j}^A * f_{jt} + u_t},t=1..T, \eqn{b_{j}^A} is \emph{active beta} to factor j 
-#' and \eqn{f_{jt}} is factor j. The active returns attributed to factor j is 
-#' \eqn{b_{j}^A * f_{jt}} specific returns is \eqn{u_t}, and \eqn{b_{j}^A = b_{j}-1} 
-#' 
 #' @param fit Class of "TimeSeriesFactorModel", "FundamentalFactorModel" or
 #' "statFactorModel".
-#' @param benchmark a xts, vector or data.frame provides benchmark time series
-#' returns. If benchmark is provided, active returns decomposition will be calculated.
 #' @param ...  Other controled variables for fit methods.
 #' @return an object of class \code{FM.attribution} containing
 #' \itemize{
@@ -46,7 +38,7 @@
 #' 
 #' 
 factorModelPerformanceAttribution <- 
-  function(fit,benchmark=NULL,...) {
+  function(fit,...) {
     
     require(PerformanceAnalytics)
     
@@ -76,9 +68,6 @@
         data <- checkData(fit$data)
         date <- index(na.omit(data[,k])) 
         actual.xts = xts(fit.lm$model[1], as.Date(date))
-        if (!is.null(benchmark)) {
-        benchmark.xts <- checkData(benchmark)[as.Date(date)]
-        }
         # attributed returns
         # active portfolio management p.512 17A.9 
         # top-down method
@@ -93,13 +82,8 @@
             cum.attr.ret[k,i] <- NA
             attr.ret.xts.all <- merge(attr.ret.xts.all,xts(rep(NA,length(date)),as.Date(date)))  
           } else {
-            if (!is.null(benchmark)) {
-              attr.ret.xts <- actual.xts - xts(as.matrix(benchmark.xts)%*%as.matrix(fit.lm$coef[i]-1),
-                                               as.Date(date))   
-            } else {
-              attr.ret.xts <- actual.xts - xts(as.matrix(fit.lm$model[i])%*%as.matrix(fit.lm$coef[i]),
+            attr.ret.xts <- actual.xts - xts(as.matrix(fit.lm$model[i])%*%as.matrix(fit.lm$coef[i]),
                                                as.Date(date))  
-            }
             cum.attr.ret[k,i] <- cum.ret - Return.cumulative(actual.xts-attr.ret.xts)  
             attr.ret.xts.all <- merge(attr.ret.xts.all,attr.ret.xts)
           }
@@ -119,10 +103,10 @@
     
     if (class(fit) =="FundamentalFactorModel" ) {
       # if benchmark is provided
-      
-      if (!is.null(benchmark)) {
-        stop("use fitFundamentalFactorModel instead")
-      }
+#       
+#       if (!is.null(benchmark)) {
+#         stop("use fitFundamentalFactorModel instead")
+#       }
       # return attributed to factors
       factor.returns <- fit$factor.returns[,-1]
       factor.names <- colnames(fit$beta)
@@ -188,13 +172,9 @@
           fit.lm = fit$asset.fit[[k]]
           
           ## extract information from lm object
-          date <- index(fit$data[,k])
+          date <- index(data[,k])
           # probably needs more general Date setting
           actual.xts = xts(fit.lm$model[1], as.Date(date))
-          if (!is.null(benchmark)) {
-            benchmark.xts <- checkData(benchmark)[as.Date(date)]
-          }
-          
           # attributed returns
           # active portfolio management p.512 17A.9 
           
@@ -202,13 +182,8 @@
           # setup initial value
           attr.ret.xts.all <- xts(, as.Date(date))
           for ( i in factorName ) {
-            if (!is.null(benchmark)) {
-              attr.ret.xts <- actual.xts - xts(as.matrix(benchmark.xts)%*%as.matrix(fit.lm$coef[i]-1),
-                                               as.Date(date))   
-            } else {
             attr.ret.xts <- actual.xts - xts(as.matrix(fit.lm$model[i])%*%as.matrix(fit.lm$coef[i]),
                                              as.Date(date))  
-            }
             cum.attr.ret[k,i] <- cum.ret - Return.cumulative(actual.xts-attr.ret.xts)  
             attr.ret.xts.all <- merge(attr.ret.xts.all,attr.ret.xts)
             
@@ -232,16 +207,8 @@
           attr.ret.xts.all <- xts(, as.Date(date))
           actual.xts <- xts(fit$asset.ret[,k],as.Date(date))
           cum.ret <-   Return.cumulative(actual.xts)
-          if (!is.null(benchmark)) {
-            benchmark.xts <- checkData(benchmark)[as.Date(date)]
-          }
           for (i in factorName) {
-            if (!is.null(benchmark)) {
-              attr.ret.xts <- actual.xts - xts(coredata(benchmark.xts)*(fit$loadings[i,k]-1),
-                                               as.Date(date))   
-            } else {
             attr.ret.xts <- xts(fit$factors[,i] * fit$loadings[i,k], as.Date(date) )
-            }
             attr.ret.xts.all <- merge(attr.ret.xts.all,attr.ret.xts)
             cum.attr.ret[k,i] <- cum.ret - Return.cumulative(actual.xts-attr.ret.xts)
           }
@@ -264,3 +231,10 @@
     class(ans) = "FM.attribution"      
     return(ans)
   }
+
+
+# If benchmark is provided, active return attribution will be calculated.
+#  active returns = total returns  - benchmark returns. Specifically,  
+# \eqn{R_t^A = \sum_j b_{j}^A * f_{jt} + u_t^A},t=1..T, \eqn{b_{j}^A} is \emph{active exposure} to factor j 
+# and \eqn{f_{jt}} is factor j. The active returns attributed to factor j is 
+# \eqn{b_{j}^A * f_{jt}} specific returns is \eqn{u_t^A} 

Modified: pkg/FactorAnalytics/man/factorModelPerformanceAttribution.Rd
===================================================================
--- pkg/FactorAnalytics/man/factorModelPerformanceAttribution.Rd	2013-09-04 20:47:13 UTC (rev 2988)
+++ pkg/FactorAnalytics/man/factorModelPerformanceAttribution.Rd	2013-09-04 21:05:13 UTC (rev 2989)
@@ -2,17 +2,12 @@
 \alias{factorModelPerformanceAttribution}
 \title{Compute performance attribution}
 \usage{
-  factorModelPerformanceAttribution(fit, benchmark = NULL,
-    ...)
+  factorModelPerformanceAttribution(fit, ...)
 }
 \arguments{
   \item{fit}{Class of "TimeSeriesFactorModel",
   "FundamentalFactorModel" or "statFactorModel".}
 
-  \item{benchmark}{a xts, vector or data.frame provides
-  benchmark time series returns. If benchmark is provided,
-  active returns decomposition will be calculated.}
-
   \item{...}{Other controled variables for fit methods.}
 }
 \value{
@@ -37,15 +32,6 @@
   j and \eqn{f_{jt}} is factor j. The returns attributed to
   factor j is \eqn{b_{j} * f_{jt}} and specific returns is
   \eqn{u_t}.
-
-  If benchmark is provided. active returns = total returns
-  - benchmark returns = active returns attributed to
-  factors + specific returns. Specifically, \eqn{R_t =
-  \sum_j b_{j}^A * f_{jt} + u_t},t=1..T, \eqn{b_{j}^A} is
-  \emph{active beta} to factor j and \eqn{f_{jt}} is factor
-  j. The active returns attributed to factor j is
-  \eqn{b_{j}^A * f_{jt}} specific returns is \eqn{u_t}, and
-  \eqn{b_{j}^A = b_{j}-1}
 }
 \examples{
 data(managers.df)



More information about the Returnanalytics-commits mailing list