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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Mon Sep 21 08:57:49 CEST 2015


Author: pragnya
Date: 2015-09-21 08:57:48 +0200 (Mon, 21 Sep 2015)
New Revision: 3997

Added:
   pkg/FactorAnalytics/R/print.ffm.R
   pkg/FactorAnalytics/man/print.ffm.Rd
Modified:
   pkg/FactorAnalytics/DESCRIPTION
   pkg/FactorAnalytics/NAMESPACE
   pkg/FactorAnalytics/R/fitFfm.R
   pkg/FactorAnalytics/R/print.sfm.r
   pkg/FactorAnalytics/R/print.tsfm.r
   pkg/FactorAnalytics/man/fitFfm.Rd
   pkg/FactorAnalytics/man/print.sfm.Rd
   pkg/FactorAnalytics/man/print.tsfm.Rd
Log:
Add print method for fitFfm; Fixed bug in the weighted regression method

Modified: pkg/FactorAnalytics/DESCRIPTION
===================================================================
--- pkg/FactorAnalytics/DESCRIPTION	2015-09-16 13:23:29 UTC (rev 3996)
+++ pkg/FactorAnalytics/DESCRIPTION	2015-09-21 06:57:48 UTC (rev 3997)
@@ -1,8 +1,8 @@
 Package: factorAnalytics
 Type: Package
 Title: Factor Analytics
-Version: 2.0.27
-Date: 2015-09-16
+Version: 2.0.28
+Date: 2015-09-21
 Author: Eric Zivot, Sangeetha Srinivasan and Yi-An Chen
 Maintainer: Sangeetha Srinivasan <sangee at uw.edu>
 Description: Linear factor model fitting for asset returns (three major types- 
@@ -16,7 +16,7 @@
     R (>= 3.0.0),
     xts (>= 0.9),
     foreach (>= 1.4),
-    rrcov
+    rrcov (>= 1.3)
 Imports: 
     PerformanceAnalytics(>= 1.4),
     zoo,

Modified: pkg/FactorAnalytics/NAMESPACE
===================================================================
--- pkg/FactorAnalytics/NAMESPACE	2015-09-16 13:23:29 UTC (rev 3996)
+++ pkg/FactorAnalytics/NAMESPACE	2015-09-21 06:57:48 UTC (rev 3997)
@@ -21,6 +21,7 @@
 S3method(predict,sfm)
 S3method(predict,tsfm)
 S3method(predict,tsfmUpDn)
+S3method(print,ffm)
 S3method(print,pafm)
 S3method(print,sfm)
 S3method(print,summary.sfm)

Modified: pkg/FactorAnalytics/R/fitFfm.R
===================================================================
--- pkg/FactorAnalytics/R/fitFfm.R	2015-09-16 13:23:29 UTC (rev 3996)
+++ pkg/FactorAnalytics/R/fitFfm.R	2015-09-21 06:57:48 UTC (rev 3997)
@@ -14,20 +14,27 @@
 #' of the residual variances from LS regression as weights (feasible GLS). 
 #' Similarly, "W-Rob" is weighted robust regression.
 #' 
-#' \code{weight.var} specifies the variable (e.g. market-cap) used to weight 
-#' the exposures before converting them to z-scores in each time period. Default 
-#' option equally weights exposures of different assets each period.
+#' Standardizing style factor exposures: The exposures can be standardized into
+#' z-scores using regular or robust (see \code{rob.stats}) measures of location 
+#' and scale. Further, \code{weight.var}, a variable such as market-cap, can be 
+#' used to compute the weighted mean exposure, and an equal-weighted standard 
+#' deviation of the exposures about the weighted mean. This may help avoid an 
+#' ill-conditioned covariance matrix. Default option equally weights exposures 
+#' of different assets each period. 
 #' 
-#' If \code{rob.scale=TRUE}, \code{\link[robust]{covRob}} is used to compute a 
+#' If \code{rob.stats=TRUE}, \code{\link[robust]{covRob}} is used to compute a 
 #' robust estimate of the factor covariance/correlation matrix, and, 
-#' \code{\link[robustbase]{scaleTau2}} is used to compute robust tau-estimates of 
-#' univariate scale for residuals during "WLS" or "W-Rob" regressions and for 
-#' standardizing numeric factor exposures into z-scores.
+#' \code{\link[robustbase]{scaleTau2}} is used to compute robust tau-estimates 
+#' of univariate scale for residuals during "WLS" or "W-Rob" regressions. When 
+#' standardizing style exposures, the \code{\link[stats]{median}} and 
+#' \code{\link[stats]{mad}} are used for location and scale respectively.
 #' 
-#' At this time, the regression can contain only one character exposure 
-#' (industry, sector, country etc.), otherwise the exposure matrix will become
-#' singular. Same is true of an intercept term. We hope to expand the function 
-#' to allow more than one dummy variable in the future.
+#' At this time, the regression can contain only one dummy exposure (one of 
+#' industry, sector, country etc.) or intercept term, otherwise the exposure 
+#' matrix will become singular. We plan to expand the function to allow 
+#' specifying more than one dummy variable, and, dummy variable(s) in 
+#' combination with an intercept term in the future. (Ex: Country + Sector + 
+#' Intercept)
 #' 
 #' The original function was designed by Doug Martin and initially implemented
 #' in S-PLUS by a number of University of Washington Ph.D. students:
@@ -45,19 +52,19 @@
 #' @param exposure.vars vector; names of the variables containing the 
 #' fundamental factor exposures.
 #' @param weight.var character; name of the variable containing the weights 
-#' used when standarizing factor exposures (converting exposures to z-scores). 
-#' Default is \code{NULL}. See Details.
+#' used when standarizing style factor exposures. Default is \code{NULL}. See 
+#' Details.
 #' @param fit.method method for estimating factor returns; one of "LS", "WLS" 
 #' "Rob" or "W-Rob". See details. Default is "LS".
-#' @param rob.scale logical; If \code{TRUE}, robust estimates of covariance, 
-#' correlation and univariate scale are computed as appropriate (see Details). 
-#' Default is \code{FALSE}.
+#' @param rob.stats logical; If \code{TRUE}, robust estimates of covariance, 
+#' correlation, location and univariate scale are computed as appropriate (see 
+#' Details). Default is \code{FALSE}.
 #' @param full.resid.cov logical; If \code{TRUE}, a full residual covariance 
 #' matrix is estimated. Otherwise, a diagonal residual covariance matrix is 
 #' estimated. Default is \code{FALSE}.
-#' @param z.score logical; If \code{TRUE}, exposures will be converted to 
+#' @param z.score logical; If \code{TRUE}, style exposures will be converted to 
 #' z-scores; weights given by \code{weight.var}. Default is \code{FALSE}.
-#' @param ... other arguments passed
+#' @param ... potentially further arguments passed.
 #' 
 #' @return \code{fitFfm} returns an object of class \code{"ffm"} for which 
 #' \code{print}, \code{plot}, \code{predict} and \code{summary} methods exist. 
@@ -94,8 +101,9 @@
 #' \item{fit.method}{fit.method as input.}
 #' \item{asset.names}{length-N vector of asset names.}
 #' \item{factor.names}{length-K vector of factor.names.}
+#' \item{time.periods}{length-T vector of dates.}
 #' Where N is the number of assets, K is the number of factors (including the 
-#' intercept or dummy variables) and T is the number of time periods.
+#' intercept or dummy variables) and T is the number of unique time periods.
 #'
 #' @author Guy Yollin, Yi-An Chen and Sangeetha Srinivasan
 #'
@@ -132,10 +140,10 @@
 #' exposure.vars <- c("GICS.SECTOR")
 #' fit1 <- fitFfm(data=stock, asset.var="TICKER", ret.var="RETURN", 
 #'                date.var="DATE", exposure.vars=exposure.vars, 
-#'                fit.method="Rob", rob.scale=TRUE)
+#'                fit.method="Rob", rob.stats=TRUE)
 #' 
-#' # example with industry dummy included
-#' exposure.vars <- c("BOOK2MARKET", "LOG.MARKETCAP", "GICS.INDUSTRY")
+#' # example with sector dummy included
+#' exposure.vars <- c("BOOK2MARKET", "LOG.MARKETCAP", "GICS.SECTOR")
 #' fit2 <- fitFfm(data=stock, asset.var="TICKER", ret.var="RETURN", 
 #'               date.var="DATE", exposure.vars=exposure.vars)
 #'
@@ -143,7 +151,7 @@
 
 fitFfm <- function(data, asset.var, ret.var, date.var, exposure.vars, 
                    weight.var=NULL, fit.method=c("LS","WLS","Rob","W-Rob"), 
-                   rob.scale=FALSE, full.resid.cov=FALSE, z.score=FALSE, ...) {
+                   rob.stats=FALSE, full.resid.cov=FALSE, z.score=FALSE, ...) {
   
   # record the call as an element to be returned
   this.call <- match.call()
@@ -174,8 +182,8 @@
   if (!is.null(weight.var) && !is.character(weight.var)) {
     stop("Invalid args: weight.var must be a character string")
   }
-  if (!is.logical(rob.scale) || length(rob.scale) != 1) {
-    stop("Invalid args: control parameter 'rob.scale' must be logical")
+  if (!is.logical(rob.stats) || length(rob.stats) != 1) {
+    stop("Invalid args: control parameter 'rob.stats' must be logical")
   }
   if (!is.logical(full.resid.cov) || length(full.resid.cov) != 1) {
     stop("Invalid args: control parameter 'full.resid.cov' must be logical")
@@ -218,18 +226,10 @@
     } else {
       w <- rep(1, nrow(data))
     }
-    # function to calculate z-scores for numeric exposures using weights w
-    z.score <- function (x, i, w, rob.scale) {
-      if (rob.scale) {
-        (x[[i]] - mean(w*x[[i]]))*1/scaleTau2(w*x[[i]])
-      } else {
-        (x[[i]] - mean(w*x[[i]]))*1/sd(w*x[[i]])
-      }
-    }
     # calculate z-scores looping through all numeric exposures
     for (i in exposures.num) {
       std.expo.num <- by(data=data, INDICES=data[[date.var]], FUN=z.score,
-                         i=i, w=w, rob.scale=rob.scale)
+                         i=i, w=w, rob.stats=rob.stats)
       data[[i]] <- unlist(std.expo.num)
     }
   }
@@ -262,23 +262,30 @@
   
   # compute residual variance for all assets for weighted regression
   if (grepl("W",fit.method)) {
-    if (rob.scale) {
+    if (rob.stats) {
       resid.var <- apply(sapply(reg.list, residuals), 1, scaleTau2)^2
     } else {
       resid.var <- apply(sapply(reg.list, residuals), 1, var)
     }
+    # add column of weights to data replicating resid.var for each period
+    data <- cbind(data, W=resid.var)
   }
   
   # estimate factor returns using WLS or weighted-Robust regression
   # returns a list of the fitted lm or lmRob objects for each time period
   if (fit.method=="WLS") {
-    reg.list <- by(data=data, INDICES=data[[date.var]], FUN=lm, 
-                   formula=fm.formula, contrasts=contrasts.list, 
-                   na.action=na.fail, w=resid.var)
+    reg.list <- by(data=data, INDICES=data[[date.var]], 
+                   FUN=function(x) {
+                     lm(data=x, formula=fm.formula, contrasts=contrasts.list, 
+                        na.action=na.fail, weights=~W)
+                   })
   } else if (fit.method=="W-Rob") {
-    reg.list <- by(data=data, INDICES=data[[date.var]], FUN=lmRob, 
-                   formula=fm.formula, contrasts=contrasts.list, 
-                   mxr=200, mxf=200, mxs=200, na.action=na.fail, w=resid.var)
+    reg.list <- by(data=data, INDICES=data[[date.var]], 
+                   FUN=function(x) {
+                     lmRob(data=x, formula=fm.formula, contrasts=contrasts.list, 
+                           na.action=na.fail, weights=~W, 
+                           mxr=200, mxf=200, mxs=200)
+                   })
   }
   
   ## Compute or Extract objects to be returned
@@ -293,7 +300,7 @@
   K <- length(factor.names)
   
   # exposure matrix B or beta for the last time period - N x K
-  DATE=NULL # to avoid R CMD check NOTE about no visible binding for global var
+  DATE=NULL # to avoid R CMD check's NOTE: no visible binding for global var
   beta <- model.matrix(fm.formula, data=subset(data, DATE==time.periods[TP]))
   rownames(beta) <- asset.names
   
@@ -301,6 +308,10 @@
   factor.returns <- sapply(reg.list, function(x) {
     temp <- coef(x) 
     temp[match(factor.names, names(temp))]})
+  # simplify factor.names for dummy variables
+  if (length(exposures.char)) {
+    factor.names <- c(exposures.num, levels(data[,exposures.char]))
+  }
   rownames(factor.returns) <- factor.names
   factor.returns <- checkData(t(factor.returns)) # T x K
   
@@ -312,7 +323,7 @@
   r2 <- sapply(reg.list, function(x) summary(x)$r.squared)
   
   # factor and residual covariances
-  if (rob.scale) {
+  if (rob.stats) {
     if (kappa(na.exclude(coredata(factor.returns))) < 1e+10) {
       factor.cov <- covRob(coredata(factor.returns), estim="pairwiseGK", 
                            distance=FALSE, na.action=na.omit)$cov
@@ -356,13 +367,31 @@
                  data=data, date.var=date.var, ret.var=ret.var, 
                  asset.var=asset.var, exposure.vars=exposure.vars, 
                  weight.var=weight.var, fit.method=fit.method, 
-                 asset.names=asset.names, factor.names=factor.names)
+                 asset.names=asset.names, factor.names=factor.names,
+                 time.periods=time.periods)
   
   class(result) <- "ffm"
   return(result)
 }
 
 
+### function to calculate z-scores for numeric exposure i using weights w
+## x is a data.frame object, i is a character string and w has same length as x 
+# rob.stats is a logical argument to compute robust location and scale
+
+z.score <- function (x, i, w, rob.stats) {
+  if (rob.stats) {
+    x_bar <- median(w*x[[i]])
+    (x[[i]] - x_bar)/mad(x[[i]], center=x_bar)
+  } else {
+    x_bar <- mean(w*x[[i]]) 
+    n <- length(x[[i]])
+    # use equal weighted squared deviation about the weighted mean
+    (x[[i]] - x_bar)/sqrt((x[[i]]-x_bar)^2/(n-1))
+  }
+}
+
+
 #' @param object a fit object of class \code{ffm} which is returned by 
 #' \code{fitFfm}
 

Added: pkg/FactorAnalytics/R/print.ffm.R
===================================================================
--- pkg/FactorAnalytics/R/print.ffm.R	                        (rev 0)
+++ pkg/FactorAnalytics/R/print.ffm.R	2015-09-21 06:57:48 UTC (rev 3997)
@@ -0,0 +1,43 @@
+#' @title Prints a fitted fundamental factor model
+#' 
+#' @description S3 \code{print} method for object of class \code{ffm}. Prints 
+#' the call, factor model dimension and summary statistics for the estimated
+#' factor returns, cross-sectional r-squared values and residual variances 
+#' from the fitted object. 
+#' 
+#' @param x an object of class \code{ffm} produced by \code{fitFfm}.
+#' @param digits an integer value, to indicate the required number of 
+#' significant digits. Default is 3.
+#' @param ... optional arguments passed to the \code{print} method.
+#'    
+#' @author Yi-An Chen and Sangeetha Srinivasan
+#' 
+#' @seealso \code{\link{fitFfm}}, \code{\link{summary.ffm}}
+#' 
+#' @examples
+#' data(Stock.df)
+#' exposure.vars <- c("BOOK2MARKET", "LOG.MARKETCAP")
+#' fit <- fitFfm(data=stock, asset.var="TICKER", ret.var="RETURN", 
+#'               date.var="DATE", exposure.vars=exposure.vars)
+#' print(fit)
+#' 
+#' @method print ffm
+#' @export
+#' 
+
+print.ffm <- function(x, digits=max(3, .Options$digits - 3), ...){
+  if(!is.null(cl <- x$call)){
+    cat("\nCall:\n")
+    dput(cl)
+  }
+  cat("\nModel dimensions:\n")
+  tmp <- c(dim(t(x$beta)), length(x$time.periods))
+  names(tmp) <- c("Factors", "Assets", "Periods")
+  print(tmp)
+  cat("\nFactor returns across periods:\n")
+  print(summary(coredata(x$factor.returns)), digits=digits, ...)
+  cat("\nR-squared values across periods:\n")
+  print(summary(x$r2), digits=digits, ...)
+  cat("\nResidual Variances across assets:\n")
+  print(summary(x$resid.var), digits=digits, ...)
+}

Modified: pkg/FactorAnalytics/R/print.sfm.r
===================================================================
--- pkg/FactorAnalytics/R/print.sfm.r	2015-09-16 13:23:29 UTC (rev 3996)
+++ pkg/FactorAnalytics/R/print.sfm.r	2015-09-21 06:57:48 UTC (rev 3997)
@@ -1,8 +1,9 @@
-#' @title Prints out a fitted statictical factor model object
+#' @title Prints a fitted statistical factor model
 #' 
 #' @description S3 \code{print} method for object of class \code{sfm}. Prints 
-#' the call, factor model dimension, factor loadings, r-squared and residual 
-#' volatilities from the fitted object. 
+#' the call, factor model dimensions and summary statistics for the estimated 
+#' factor loadings, r-squared values and residual volatilities from the fitted 
+#' object. 
 #' 
 #' @param x an object of class \code{sfm} produced by \code{fitSfm}.
 #' @param digits an integer value, to indicate the required number of 

Modified: pkg/FactorAnalytics/R/print.tsfm.r
===================================================================
--- pkg/FactorAnalytics/R/print.tsfm.r	2015-09-16 13:23:29 UTC (rev 3996)
+++ pkg/FactorAnalytics/R/print.tsfm.r	2015-09-21 06:57:48 UTC (rev 3997)
@@ -1,46 +1,46 @@
-#' @title Prints out a fitted time series factor model object
-#' 
-#' @description S3 \code{print} method for object of class \code{tsfm}. Prints 
-#' the call, factor model dimension, regression coefficients, r-squared and 
-#' residual volatilities from the fitted object. 
-#' 
-#' @param x an object of class \code{tsfm} produced by \code{fitTsfm}.
-#' @param digits an integer value, to indicate the required number of 
-#' significant digits. Default is 3.
-#' @param ... optional arguments passed to the \code{print} method.
-#'    
-#' @author Yi-An Chen and Sangeetha Srinivasan
-#' 
-#' @seealso \code{\link{fitTsfm}}, \code{\link{summary.tsfm}}
-#' 
-#' @examples
-#' data(managers)
-#' fit <- fitTsfm(asset.names=colnames(managers[,(1:6)]),
-#'                factor.names=colnames(managers[,7:9]), 
-#'                mkt.name="SP500.TR", data=managers)
-#' print(fit)
-#' 
-#' @method print tsfm
-#' @export
-#' 
-
-print.tsfm <- function(x, digits=max(3, .Options$digits - 3), ...){
-  if(!is.null(cl <- x$call)){
-    cat("\nCall:\n")
-    dput(cl)
-  }
-  cat("\nModel dimensions:\n")
-  tmp <- c(dim(t(x$beta)), nrow(x$data))
-  names(tmp) <- c("Factors", "Assets", "Periods")
-  print(tmp)
-  cat("\nRegression Alphas:\n")
-  print(t(x$alpha), digits=digits, ...)
-  cat("\nFactor Betas:\n")
-  B <- as.matrix(t(x$beta))
-  if (x$variable.selection=="lars") { B[B==0] <- NA }
-  print(B, digits=digits, na.print=".", ...)
-  cat("\nR-squared values:\n")
-  print(x$r2, digits=digits, ...)
-  cat("\nResidual Volatilities:\n")
-  print(x$resid.sd, digits=digits, ...)
-}
+#' @title Prints a fitted time series factor model
+#' 
+#' @description S3 \code{print} method for object of class \code{tsfm}. Prints 
+#' the call, factor model dimension, regression coefficients, r-squared and 
+#' residual volatilities from the fitted object. 
+#' 
+#' @param x an object of class \code{tsfm} produced by \code{fitTsfm}.
+#' @param digits an integer value, to indicate the required number of 
+#' significant digits. Default is 3.
+#' @param ... optional arguments passed to the \code{print} method.
+#'    
+#' @author Yi-An Chen and Sangeetha Srinivasan
+#' 
+#' @seealso \code{\link{fitTsfm}}, \code{\link{summary.tsfm}}
+#' 
+#' @examples
+#' data(managers)
+#' fit <- fitTsfm(asset.names=colnames(managers[,(1:6)]),
+#'                factor.names=colnames(managers[,7:9]), 
+#'                mkt.name="SP500.TR", data=managers)
+#' print(fit)
+#' 
+#' @method print tsfm
+#' @export
+#' 
+
+print.tsfm <- function(x, digits=max(3, .Options$digits - 3), ...){
+  if(!is.null(cl <- x$call)){
+    cat("\nCall:\n")
+    dput(cl)
+  }
+  cat("\nModel dimensions:\n")
+  tmp <- c(dim(t(x$beta)), nrow(x$data))
+  names(tmp) <- c("Factors", "Assets", "Periods")
+  print(tmp)
+  cat("\nRegression Alphas:\n")
+  print(t(x$alpha), digits=digits, ...)
+  cat("\nFactor Betas:\n")
+  B <- as.matrix(t(x$beta))
+  if (x$variable.selection=="lars") { B[B==0] <- NA }
+  print(B, digits=digits, na.print=".", ...)
+  cat("\nR-squared values:\n")
+  print(x$r2, digits=digits, ...)
+  cat("\nResidual Volatilities:\n")
+  print(x$resid.sd, digits=digits, ...)
+}

Modified: pkg/FactorAnalytics/man/fitFfm.Rd
===================================================================
--- pkg/FactorAnalytics/man/fitFfm.Rd	2015-09-16 13:23:29 UTC (rev 3996)
+++ pkg/FactorAnalytics/man/fitFfm.Rd	2015-09-21 06:57:48 UTC (rev 3997)
@@ -8,7 +8,7 @@
 \title{Fit a fundamental factor model using cross-sectional regression}
 \usage{
 fitFfm(data, asset.var, ret.var, date.var, exposure.vars, weight.var = NULL,
-  fit.method = c("LS", "WLS", "Rob", "W-Rob"), rob.scale = FALSE,
+  fit.method = c("LS", "WLS", "Rob", "W-Rob"), rob.stats = FALSE,
   full.resid.cov = FALSE, z.score = FALSE, ...)
 
 \method{coef}{ffm}(object, ...)
@@ -33,24 +33,24 @@
 fundamental factor exposures.}
 
 \item{weight.var}{character; name of the variable containing the weights
-used when standarizing factor exposures (converting exposures to z-scores).
-Default is \code{NULL}. See Details.}
+used when standarizing style factor exposures. Default is \code{NULL}. See
+Details.}
 
 \item{fit.method}{method for estimating factor returns; one of "LS", "WLS"
 "Rob" or "W-Rob". See details. Default is "LS".}
 
-\item{rob.scale}{logical; If \code{TRUE}, robust estimates of covariance,
-correlation and univariate scale are computed as appropriate (see Details).
-Default is \code{FALSE}.}
+\item{rob.stats}{logical; If \code{TRUE}, robust estimates of covariance,
+correlation, location and univariate scale are computed as appropriate (see
+Details). Default is \code{FALSE}.}
 
 \item{full.resid.cov}{logical; If \code{TRUE}, a full residual covariance
 matrix is estimated. Otherwise, a diagonal residual covariance matrix is
 estimated. Default is \code{FALSE}.}
 
-\item{z.score}{logical; If \code{TRUE}, exposures will be converted to
+\item{z.score}{logical; If \code{TRUE}, style exposures will be converted to
 z-scores; weights given by \code{weight.var}. Default is \code{FALSE}.}
 
-\item{...}{other arguments passed}
+\item{...}{potentially further arguments passed.}
 
 \item{object}{a fit object of class \code{ffm} which is returned by
 \code{fitFfm}}
@@ -91,8 +91,9 @@
 \item{fit.method}{fit.method as input.}
 \item{asset.names}{length-N vector of asset names.}
 \item{factor.names}{length-K vector of factor.names.}
+\item{time.periods}{length-T vector of dates.}
 Where N is the number of assets, K is the number of factors (including the
-intercept or dummy variables) and T is the number of time periods.
+intercept or dummy variables) and T is the number of unique time periods.
 }
 \description{
 Fit a fundamental (cross-sectional) factor model using ordinary
@@ -109,20 +110,27 @@
 of the residual variances from LS regression as weights (feasible GLS).
 Similarly, "W-Rob" is weighted robust regression.
 
-\code{weight.var} specifies the variable (e.g. market-cap) used to weight
-the exposures before converting them to z-scores in each time period. Default
-option equally weights exposures of different assets each period.
+Standardizing style factor exposures: The exposures can be standardized into
+z-scores using regular or robust (see \code{rob.stats}) measures of location
+and scale. Further, \code{weight.var}, a variable such as market-cap, can be
+used to compute the weighted mean exposure, and an equal-weighted standard
+deviation of the exposures about the weighted mean. This may help avoid an
+ill-conditioned covariance matrix. Default option equally weights exposures
+of different assets each period.
 
-If \code{rob.scale=TRUE}, \code{\link[robust]{covRob}} is used to compute a
+If \code{rob.stats=TRUE}, \code{\link[robust]{covRob}} is used to compute a
 robust estimate of the factor covariance/correlation matrix, and,
-\code{\link[robustbase]{scaleTau2}} is used to compute robust tau-estimates of
-univariate scale for residuals during "WLS" or "W-Rob" regressions and for
-standardizing numeric factor exposures into z-scores.
+\code{\link[robustbase]{scaleTau2}} is used to compute robust tau-estimates
+of univariate scale for residuals during "WLS" or "W-Rob" regressions. When
+standardizing style exposures, the \code{\link[stats]{median}} and
+\code{\link[stats]{mad}} are used for location and scale respectively.
 
-At this time, the regression can contain only one character exposure
-(industry, sector, country etc.), otherwise the exposure matrix will become
-singular. Same is true of an intercept term. We hope to expand the function
-to allow more than one dummy variable in the future.
+At this time, the regression can contain only one dummy exposure (one of
+industry, sector, country etc.) or intercept term, otherwise the exposure
+matrix will become singular. We plan to expand the function to allow
+specifying more than one dummy variable, and, dummy variable(s) in
+combination with an intercept term in the future. (Ex: Country + Sector +
+Intercept)
 
 The original function was designed by Doug Martin and initially implemented
 in S-PLUS by a number of University of Washington Ph.D. students:
@@ -144,10 +152,10 @@
 exposure.vars <- c("GICS.SECTOR")
 fit1 <- fitFfm(data=stock, asset.var="TICKER", ret.var="RETURN",
                date.var="DATE", exposure.vars=exposure.vars,
-               fit.method="Rob", rob.scale=TRUE)
+               fit.method="Rob", rob.stats=TRUE)
 
-# example with industry dummy included
-exposure.vars <- c("BOOK2MARKET", "LOG.MARKETCAP", "GICS.INDUSTRY")
+# example with sector dummy included
+exposure.vars <- c("BOOK2MARKET", "LOG.MARKETCAP", "GICS.SECTOR")
 fit2 <- fitFfm(data=stock, asset.var="TICKER", ret.var="RETURN",
               date.var="DATE", exposure.vars=exposure.vars)
 }

Added: pkg/FactorAnalytics/man/print.ffm.Rd
===================================================================
--- pkg/FactorAnalytics/man/print.ffm.Rd	                        (rev 0)
+++ pkg/FactorAnalytics/man/print.ffm.Rd	2015-09-21 06:57:48 UTC (rev 3997)
@@ -0,0 +1,36 @@
+% Generated by roxygen2 (4.1.1): do not edit by hand
+% Please edit documentation in R/print.ffm.R
+\name{print.ffm}
+\alias{print.ffm}
+\title{Prints a fitted fundamental factor model}
+\usage{
+\method{print}{ffm}(x, digits = max(3, .Options$digits - 3), ...)
+}
+\arguments{
+\item{x}{an object of class \code{ffm} produced by \code{fitFfm}.}
+
+\item{digits}{an integer value, to indicate the required number of
+significant digits. Default is 3.}
+
+\item{...}{optional arguments passed to the \code{print} method.}
+}
+\description{
+S3 \code{print} method for object of class \code{ffm}. Prints
+the call, factor model dimension and summary statistics for the estimated
+factor returns, cross-sectional r-squared values and residual variances
+from the fitted object.
+}
+\examples{
+data(Stock.df)
+exposure.vars <- c("BOOK2MARKET", "LOG.MARKETCAP")
+fit <- fitFfm(data=stock, asset.var="TICKER", ret.var="RETURN",
+              date.var="DATE", exposure.vars=exposure.vars)
+print(fit)
+}
+\author{
+Yi-An Chen and Sangeetha Srinivasan
+}
+\seealso{
+\code{\link{fitFfm}}, \code{\link{summary.ffm}}
+}
+

Modified: pkg/FactorAnalytics/man/print.sfm.Rd
===================================================================
--- pkg/FactorAnalytics/man/print.sfm.Rd	2015-09-16 13:23:29 UTC (rev 3996)
+++ pkg/FactorAnalytics/man/print.sfm.Rd	2015-09-21 06:57:48 UTC (rev 3997)
@@ -2,7 +2,7 @@
 % Please edit documentation in R/print.sfm.r
 \name{print.sfm}
 \alias{print.sfm}
-\title{Prints out a fitted statictical factor model object}
+\title{Prints a fitted statistical factor model}
 \usage{
 \method{print}{sfm}(x, digits = max(3, .Options$digits - 3), ...)
 }
@@ -16,8 +16,9 @@
 }
 \description{
 S3 \code{print} method for object of class \code{sfm}. Prints
-the call, factor model dimension, factor loadings, r-squared and residual
-volatilities from the fitted object.
+the call, factor model dimensions and summary statistics for the estimated
+factor loadings, r-squared values and residual volatilities from the fitted
+object.
 }
 \examples{
 data(StockReturns)

Modified: pkg/FactorAnalytics/man/print.tsfm.Rd
===================================================================
--- pkg/FactorAnalytics/man/print.tsfm.Rd	2015-09-16 13:23:29 UTC (rev 3996)
+++ pkg/FactorAnalytics/man/print.tsfm.Rd	2015-09-21 06:57:48 UTC (rev 3997)
@@ -2,7 +2,7 @@
 % Please edit documentation in R/print.tsfm.r
 \name{print.tsfm}
 \alias{print.tsfm}
-\title{Prints out a fitted time series factor model object}
+\title{Prints a fitted time series factor model}
 \usage{
 \method{print}{tsfm}(x, digits = max(3, .Options$digits - 3), ...)
 }



More information about the Returnanalytics-commits mailing list