[Returnanalytics-commits] r3547 - in pkg/FactorAnalytics: . R man
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Mon Nov 3 23:39:10 CET 2014
Author: pragnya
Date: 2014-11-03 23:39:10 +0100 (Mon, 03 Nov 2014)
New Revision: 3547
Modified:
pkg/FactorAnalytics/DESCRIPTION
pkg/FactorAnalytics/R/fitFundamentalFactorModel.R
pkg/FactorAnalytics/R/fitTsfm.R
pkg/FactorAnalytics/man/fitFundamentalFactorModel.Rd
pkg/FactorAnalytics/man/fitTsfm.Rd
Log:
Minor fix in fitTsfm, edits to description of fitFfm
Modified: pkg/FactorAnalytics/DESCRIPTION
===================================================================
--- pkg/FactorAnalytics/DESCRIPTION 2014-10-16 02:16:08 UTC (rev 3546)
+++ pkg/FactorAnalytics/DESCRIPTION 2014-11-03 22:39:10 UTC (rev 3547)
@@ -1,8 +1,8 @@
Package: factorAnalytics
Type: Package
Title: Factor Analytics
-Version: 2.0.0.99
-Date: 2014-07-30
+Version: 2.0.1
+Date: 2014-11-03
Author: Eric Zivot, Yi-An Chen and Sangeetha Srinivasan
Maintainer: Sangeetha Srinivasan <sangee at uw.edu>
Description: An R package for the estimation and risk analysis of linear factor
Modified: pkg/FactorAnalytics/R/fitFundamentalFactorModel.R
===================================================================
--- pkg/FactorAnalytics/R/fitFundamentalFactorModel.R 2014-10-16 02:16:08 UTC (rev 3546)
+++ pkg/FactorAnalytics/R/fitFundamentalFactorModel.R 2014-11-03 22:39:10 UTC (rev 3547)
@@ -1,27 +1,32 @@
-#' fit fundamental factor model by classic OLS or Robust regression technique
+#' @title Fit a fundamental factor model using classic OLS or Robust regression
#'
-#' fit fundamental factor model or cross-sectional factor model by
-#' classic OLS or Robust regression. Fundamental factor models use
+#' @description Fit a fundamental (cross-sectional) factor model using Ordinary
+#' Least Squares (OLS) or Robust regression. Fundamental factor models use
#' observable asset specific characteristics (fundamentals) like industry
#' classification, market capitalization, style classification (value, growth)
-#' etc. to calculate the common risk factors. The function creates the class
-#' "FundamentalFactorModel".
+#' etc. to calculate the common risk factors. An object of class \code{"ffm"}
+#' is returned.
#'
#' @details
-#' If style factor exposure is standardized to regression-weighted mean zero, this makes
-#' style factors orthogonal to the world factor (intercept term), which in turn facilitted
-#' interpretation of the style factor returns. See Menchero 2010.
+#' If style factor exposure is standardized to have a regression-weighted mean
+#' of zero, style factors become orthogonal to the world factor (intercept
+#' term), which in turn facilitates the interpretation of the style factor
+#' returns. See Menchero (2010).
#'
-#' The original function was designed by Doug Martin and originally implemented
-#' in S-PLUS by a number of UW Ph.D. students: Christopher Green, Eric Aldrich,
-#' and Yindeng Jiang. Guy Yullen re-implemented the function in R. Yi-An Chen from
-#' University of Washington re-writes the codes and finalizes the function.
+#' The original function was designed by Doug Martin and initially implemented
+#' in S-PLUS by a number of University of Washington Ph.D. students:
+#' Christopher Green, Eric Aldrich, and Yindeng Jiang. Guy Yollin
+#' re-implemented the function in R. Yi-An Chen and Sangeetha Srinivasan
+#' (UW PhD students; as part of Google Summer of Code 2013 & 2014 respectively)
+#' further updated the code.
#'
#'
-#' @param data data.frame, data must have \emph{assetvar}, \emph{returnvar}, \emph{datevar}
-#' , and exposure.names. Generally, data has to look like panel data. It needs firm variabales
-#' and time variables. Data has to be a balanced panel.
-#' @param exposure.names a character vector of exposure names for the factor model
+#' @param data data.frame, data must have \emph{assetvar}, \emph{returnvar},
+#' \emph{datevar}, and exposure.names. Generally, data has to look like panel
+#' data. It needs firm variabales and time variables. Data has to be a balanced
+#' panel.
+#' @param exposure.names a character vector of exposure names for the factor
+#' model
#' @param wls logical flag, TRUE for weighted least squares, FALSE for ordinary
#' least squares
#' @param regression A character string, "robust" for regression via lmRob,
@@ -39,47 +44,49 @@
#' the data.
#' @param assetvar A character string gives the name of the asset variable in
#' the data.
-#' @param standardized.factor.exposure logical flag. Factor exposure will be standardized
-#' to regression weighted mean 0 and standardized deviation to 1 if \code{TRUE}.
-#' Default is \code{FALSE}. See Detail.
-#' @param weight.var A character strping gives the name of the weight used for standarizing factor exposures.
-#' @return an S3 object containing
-#' \itemize{
-#' \item returns.cov A "list" object contains covariance information for
-#' asset returns, includes covariance, mean and eigenvalus. Beta of taken as latest
-#' date input.
-#' \item factor.cov An object of class "cov" or "covRob" which
-#' contains the covariance matrix of the factor returns (including intercept).
-#' \item resids.cov An object of class "cov" or "covRob" which contains
+#' @param standardized.factor.exposure logical flag. Factor exposure will be
+#' standardized to regression weighted mean 0 and standardized deviation to 1
+#' if \code{TRUE}. Default is \code{FALSE}. See Details.
+#' @param weight.var A character strping gives the name of the weight used for
+#' standarizing factor exposures.
+#'
+#' @return An object of class \code{"ffm"} is a list containing the following
+#' components:
+#' \item{returns.cov}{A "list" object contains covariance information for
+#' asset returns, includes covariance, mean and eigenvalus. Beta of taken as
+#' latest date input.}
+#' \item{factor.cov}{An object of class "cov" or "covRob" which contains the
+#' covariance matrix of the factor returns (including intercept).}
+#' \item{resids.cov}{An object of class "cov" or "covRob" which contains
#' the covariance matrix of the residuals, if "full.resid.cov" is TRUE. NULL
-#' if "full.resid.cov" is FALSE.
-#' \item returns.corr Correlation matrix of assets returns.
-#' \item factor.corr An object of class "cov" or "covRob" which
-#' contains the correlation matrix of the factor returns (including intercept).
-#' \item resids.corr Correlation matrix of returns returns.
-#' \item resid.variance A vector of variances estimated from the OLS
+#' if "full.resid.cov" is FALSE.}
+#' \item{returns.corr}{Correlation matrix of assets returns.}
+#' \item{factor.corr}{An object of class "cov" or "covRob" which contains the
+#' correlation matrix of the factor returns (including intercept).}
+#' \item{resids.corr}{Correlation matrix of returns returns.}
+#' \item{resid.variance}{A vector of variances estimated from the OLS
#' residuals for each asset. If "wls" is TRUE, these are the weights used in
#' the weighted least squares regressions. If "cov = robust" these values are
-#' computed with "scale.tau". Otherwise they are computed with "var".
-#' \item factor.returns A "xts" object containing the times series of
-#' estimated factor returns and intercepts.
-#' \item residuals A "xts" object containing the time series of residuals
-#' for each asset.
-#' \item tstats A "xts" object containing the time series of t-statistics
-#' for each exposure.
-#' \item call function call
-#' \item exposure.names A character string giving the name of the exposure variable in
-#' the data.
-#' }
-#' @author Guy Yullen and Yi-An Chen
+#' computed with "scale.tau". Otherwise they are computed with "var".}
+#' \item{factor.returns}{A "xts" object containing the times series of
+#' estimated factor returns and intercepts.}
+#' \item{residuals}{A "xts" object containing the time series of residuals for
+#' each asset.}
+#' \item{tstats}{A "xts" object containing the time series of t-statistics
+#' for each exposure.}
+#' \item{call}{function call}
+#' \item{exposure.names}{A character string giving the name of the exposure
+#' variable in the data.}
+#'
+#' @author Guy Yollin, Yi-An Chen and Sangeetha Srinivasan
+#'
#' @references
-#' \itemize{
-#' \item "The Characteristics of Factor Portfolios", Fall 2010, MENCHERO Jose,
-#' Journal of Performance Measurement.
-#' \item Grinold,R and Kahn R, \emph{Active Portfolio Management}.
-#' }
+#' Menchero, J. (2010). The Characteristics of Factor Portfolios. Journal of
+#' Performance Measurement, 15(1), 52-62.
#'
-#' @export
+#' Grinold, R. C., & Kahn, R. N. (2000). Active portfolio management (Second
+#' Ed.). New York: McGraw-Hill.
+#'
#' @examples
#'
#' # BARRA type factor model
@@ -125,20 +132,16 @@
#' test.fit2$tstats
#' test.fit2$call
#'
-#'
-#'
-#'
+#' @export
-
-
-fitFundamentalFactorModel <-
- function(data,exposure.names, datevar, returnsvar, assetvar,
- wls = TRUE, regression = "classic",
- covariance = "classic", full.resid.cov = FALSE, robust.scale = FALSE,
- standardized.factor.exposure = FALSE, weight.var) {
+fitFundamentalFactorModel <- function(data, exposure.names, datevar,
+ returnsvar, assetvar, wls=TRUE,
+ regression="classic",
+ covariance="classic",
+ full.resid.cov=FALSE, robust.scale=FALSE,
+ standardized.factor.exposure=FALSE,
+ weight.var) {
-
-
assets = unique(data[[assetvar]])
timedates = as.Date(unique(data[[datevar]]))
data[[datevar]] <- as.Date(data[[datevar]])
Modified: pkg/FactorAnalytics/R/fitTsfm.R
===================================================================
--- pkg/FactorAnalytics/R/fitTsfm.R 2014-10-16 02:16:08 UTC (rev 3546)
+++ pkg/FactorAnalytics/R/fitTsfm.R 2014-11-03 22:39:10 UTC (rev 3547)
@@ -5,7 +5,7 @@
#' Users can choose between ordinary least squares-OLS, discounted least
#' squares-DLS (or) robust regression. Several variable selection options
#' including Stepwise, Subsets, Lars are available as well. An object of class
-#' \code{tsfm} is returned.
+#' \code{"tsfm"} is returned.
#'
#' @details
#' Typically, factor models are fit using excess returns. \code{rf.name} gives
@@ -76,7 +76,7 @@
#' \code{\link{fitTsfm.control}} for details.
#' @param ... arguments passed to \code{\link{fitTsfm.control}}
#'
-#' @return fitTsfm returns an object of class \code{tsfm} for which
+#' @return fitTsfm returns an object of class \code{"tsfm"} for which
#' \code{print}, \code{plot}, \code{predict} and \code{summary} methods exist.
#'
#' The generic accessor functions \code{coef}, \code{fitted} and
@@ -84,7 +84,7 @@
#' Additionally, \code{fmCov} computes the covariance matrix for asset returns
#' based on the fitted factor model
#'
-#' An object of class \code{tsfm} is a list containing the following
+#' An object of class \code{"tsfm"} is a list containing the following
#' components:
#' \item{asset.fit}{list of fitted objects for each asset. Each object is of
#' class \code{lm} if \code{fit.method="OLS" or "DLS"}, class \code{lmRob} if
@@ -186,6 +186,9 @@
stop("Invalid argument: variable.selection must be either 'none',
'stepwise','subsets' or 'lars'")
}
+ if (missing(factor.names) && !is.null(mkt.name)) {
+ factor.names <- NULL
+ }
# extract arguments to pass to different fit and variable selection functions
decay <- control$decay
Modified: pkg/FactorAnalytics/man/fitFundamentalFactorModel.Rd
===================================================================
--- pkg/FactorAnalytics/man/fitFundamentalFactorModel.Rd 2014-10-16 02:16:08 UTC (rev 3546)
+++ pkg/FactorAnalytics/man/fitFundamentalFactorModel.Rd 2014-11-03 22:39:10 UTC (rev 3547)
@@ -1,7 +1,7 @@
% Generated by roxygen2 (4.0.1): do not edit by hand
\name{fitFundamentalFactorModel}
\alias{fitFundamentalFactorModel}
-\title{fit fundamental factor model by classic OLS or Robust regression technique}
+\title{Fit a fundamental factor model using classic OLS or Robust regression}
\usage{
fitFundamentalFactorModel(data, exposure.names, datevar, returnsvar, assetvar,
wls = TRUE, regression = "classic", covariance = "classic",
@@ -9,11 +9,13 @@
standardized.factor.exposure = FALSE, weight.var)
}
\arguments{
-\item{data}{data.frame, data must have \emph{assetvar}, \emph{returnvar}, \emph{datevar}
-, and exposure.names. Generally, data has to look like panel data. It needs firm variabales
-and time variables. Data has to be a balanced panel.}
+\item{data}{data.frame, data must have \emph{assetvar}, \emph{returnvar},
+\emph{datevar}, and exposure.names. Generally, data has to look like panel
+data. It needs firm variabales and time variables. Data has to be a balanced
+panel.}
-\item{exposure.names}{a character vector of exposure names for the factor model}
+\item{exposure.names}{a character vector of exposure names for the factor
+model}
\item{wls}{logical flag, TRUE for weighted least squares, FALSE for ordinary
least squares}
@@ -40,59 +42,62 @@
\item{assetvar}{A character string gives the name of the asset variable in
the data.}
-\item{standardized.factor.exposure}{logical flag. Factor exposure will be standardized
-to regression weighted mean 0 and standardized deviation to 1 if \code{TRUE}.
-Default is \code{FALSE}. See Detail.}
+\item{standardized.factor.exposure}{logical flag. Factor exposure will be
+standardized to regression weighted mean 0 and standardized deviation to 1
+if \code{TRUE}. Default is \code{FALSE}. See Details.}
-\item{weight.var}{A character strping gives the name of the weight used for standarizing factor exposures.}
+\item{weight.var}{A character strping gives the name of the weight used for
+standarizing factor exposures.}
}
\value{
-an S3 object containing
-\itemize{
-\item returns.cov A "list" object contains covariance information for
-asset returns, includes covariance, mean and eigenvalus. Beta of taken as latest
-date input.
-\item factor.cov An object of class "cov" or "covRob" which
-contains the covariance matrix of the factor returns (including intercept).
-\item resids.cov An object of class "cov" or "covRob" which contains
+An object of class \code{"ffm"} is a list containing the following
+components:
+\item{returns.cov}{A "list" object contains covariance information for
+asset returns, includes covariance, mean and eigenvalus. Beta of taken as
+latest date input.}
+\item{factor.cov}{An object of class "cov" or "covRob" which contains the
+covariance matrix of the factor returns (including intercept).}
+\item{resids.cov}{An object of class "cov" or "covRob" which contains
the covariance matrix of the residuals, if "full.resid.cov" is TRUE. NULL
-if "full.resid.cov" is FALSE.
-\item returns.corr Correlation matrix of assets returns.
-\item factor.corr An object of class "cov" or "covRob" which
-contains the correlation matrix of the factor returns (including intercept).
-\item resids.corr Correlation matrix of returns returns.
-\item resid.variance A vector of variances estimated from the OLS
+if "full.resid.cov" is FALSE.}
+\item{returns.corr}{Correlation matrix of assets returns.}
+\item{factor.corr}{An object of class "cov" or "covRob" which contains the
+correlation matrix of the factor returns (including intercept).}
+\item{resids.corr}{Correlation matrix of returns returns.}
+\item{resid.variance}{A vector of variances estimated from the OLS
residuals for each asset. If "wls" is TRUE, these are the weights used in
the weighted least squares regressions. If "cov = robust" these values are
-computed with "scale.tau". Otherwise they are computed with "var".
-\item factor.returns A "xts" object containing the times series of
-estimated factor returns and intercepts.
-\item residuals A "xts" object containing the time series of residuals
-for each asset.
-\item tstats A "xts" object containing the time series of t-statistics
-for each exposure.
-\item call function call
-\item exposure.names A character string giving the name of the exposure variable in
-the data.
+computed with "scale.tau". Otherwise they are computed with "var".}
+\item{factor.returns}{A "xts" object containing the times series of
+estimated factor returns and intercepts.}
+\item{residuals}{A "xts" object containing the time series of residuals for
+each asset.}
+\item{tstats}{A "xts" object containing the time series of t-statistics
+for each exposure.}
+\item{call}{function call}
+\item{exposure.names}{A character string giving the name of the exposure
+variable in the data.}
}
-}
\description{
-fit fundamental factor model or cross-sectional factor model by
-classic OLS or Robust regression. Fundamental factor models use
+Fit a fundamental (cross-sectional) factor model using Ordinary
+Least Squares (OLS) or Robust regression. Fundamental factor models use
observable asset specific characteristics (fundamentals) like industry
classification, market capitalization, style classification (value, growth)
-etc. to calculate the common risk factors. The function creates the class
-"FundamentalFactorModel".
+etc. to calculate the common risk factors. An object of class \code{"ffm"}
+is returned.
}
\details{
-If style factor exposure is standardized to regression-weighted mean zero, this makes
-style factors orthogonal to the world factor (intercept term), which in turn facilitted
-interpretation of the style factor returns. See Menchero 2010.
+If style factor exposure is standardized to have a regression-weighted mean
+of zero, style factors become orthogonal to the world factor (intercept
+term), which in turn facilitates the interpretation of the style factor
+returns. See Menchero (2010).
-The original function was designed by Doug Martin and originally implemented
-in S-PLUS by a number of UW Ph.D. students: Christopher Green, Eric Aldrich,
-and Yindeng Jiang. Guy Yullen re-implemented the function in R. Yi-An Chen from
-University of Washington re-writes the codes and finalizes the function.
+The original function was designed by Doug Martin and initially implemented
+in S-PLUS by a number of University of Washington Ph.D. students:
+Christopher Green, Eric Aldrich, and Yindeng Jiang. Guy Yollin
+re-implemented the function in R. Yi-An Chen and Sangeetha Srinivasan
+(UW PhD students; as part of Google Summer of Code 2013 & 2014 respectively)
+further updated the code.
}
\examples{
# BARRA type factor model
@@ -139,13 +144,13 @@
test.fit2$call
}
\author{
-Guy Yullen and Yi-An Chen
+Guy Yollin, Yi-An Chen and Sangeetha Srinivasan
}
\references{
-\itemize{
-\item "The Characteristics of Factor Portfolios", Fall 2010, MENCHERO Jose,
-Journal of Performance Measurement.
-\item Grinold,R and Kahn R, \emph{Active Portfolio Management}.
+Menchero, J. (2010). The Characteristics of Factor Portfolios. Journal of
+Performance Measurement, 15(1), 52-62.
+
+Grinold, R. C., & Kahn, R. N. (2000). Active portfolio management (Second
+Ed.). New York: McGraw-Hill.
}
-}
Modified: pkg/FactorAnalytics/man/fitTsfm.Rd
===================================================================
--- pkg/FactorAnalytics/man/fitTsfm.Rd 2014-10-16 02:16:08 UTC (rev 3546)
+++ pkg/FactorAnalytics/man/fitTsfm.Rd 2014-11-03 22:39:10 UTC (rev 3547)
@@ -53,7 +53,7 @@
\code{fitTsfm}}
}
\value{
-fitTsfm returns an object of class \code{tsfm} for which
+fitTsfm returns an object of class \code{"tsfm"} for which
\code{print}, \code{plot}, \code{predict} and \code{summary} methods exist.
The generic accessor functions \code{coef}, \code{fitted} and
@@ -61,7 +61,7 @@
Additionally, \code{fmCov} computes the covariance matrix for asset returns
based on the fitted factor model
-An object of class \code{tsfm} is a list containing the following
+An object of class \code{"tsfm"} is a list containing the following
components:
\item{asset.fit}{list of fitted objects for each asset. Each object is of
class \code{lm} if \code{fit.method="OLS" or "DLS"}, class \code{lmRob} if
@@ -88,7 +88,7 @@
Users can choose between ordinary least squares-OLS, discounted least
squares-DLS (or) robust regression. Several variable selection options
including Stepwise, Subsets, Lars are available as well. An object of class
-\code{tsfm} is returned.
+\code{"tsfm"} is returned.
}
\details{
Typically, factor models are fit using excess returns. \code{rf.name} gives
More information about the Returnanalytics-commits
mailing list