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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Thu Aug 4 14:55:43 CEST 2016


Author: pragnya
Date: 2016-08-04 14:55:43 +0200 (Thu, 04 Aug 2016)
New Revision: 4025

Modified:
   pkg/FactorAnalytics/DESCRIPTION
   pkg/FactorAnalytics/R/fmCov.R
   pkg/FactorAnalytics/R/fmSdDecomp.R
   pkg/FactorAnalytics/man/fmCov.Rd
   pkg/FactorAnalytics/man/fmSdDecomp.Rd
Log:
Option for user specified factor cov in fmCov and fmSdDecomp

Modified: pkg/FactorAnalytics/DESCRIPTION
===================================================================
--- pkg/FactorAnalytics/DESCRIPTION	2016-08-04 12:36:18 UTC (rev 4024)
+++ pkg/FactorAnalytics/DESCRIPTION	2016-08-04 12:55:43 UTC (rev 4025)
@@ -1,7 +1,7 @@
 Package: factorAnalytics
 Type: Package
 Title: Factor Analytics
-Version: 2.0.34
+Version: 2.0.35
 Date: 2016-08-04
 Author: Eric Zivot, Sangeetha Srinivasan and Yi-An Chen
 Maintainer: Sangeetha Srinivasan <sangee at uw.edu>

Modified: pkg/FactorAnalytics/R/fmCov.R
===================================================================
--- pkg/FactorAnalytics/R/fmCov.R	2016-08-04 12:36:18 UTC (rev 4024)
+++ pkg/FactorAnalytics/R/fmCov.R	2016-08-04 12:55:43 UTC (rev 4025)
@@ -19,13 +19,19 @@
 #' where, B is the \code{N x K} matrix of factor betas and \code{D} is a 
 #' diagonal matrix with \code{sig(i)^2} along the diagonal.
 #' 
-#' The method for computing covariance can be specified via the \dots 
+#' For the time series factor model, the user can specify a factor covariance 
+#' matrix; otherwise the default is to use the sample covariance from factor 
+#' returns. The method for computing covariance can be specified via the \dots 
 #' argument. Note that the default of \code{use="pairwise.complete.obs"} for 
 #' handling NAs restricts the method to "pearson".
 #' 
+#' For the statistical and fundamental factor model, the factor model 
+#' covariances already computed via the model fitting functions are simply 
+#' recalled by this method for user convenience.
+#' 
 #' @param object fit object of class \code{tsfm}, \code{sfm} or \code{ffm}.
-#' @param factor.cov factor covariance matrix (optional); defaults to the 
-#' sample covariance matrix.
+#' @param factor.cov optional user specified factor covariance matrix with 
+#' named columns; defaults to the sample covariance matrix.
 #' @param use method for computing covariances in the presence of missing 
 #' values; one of "everything", "all.obs", "complete.obs", "na.or.complete", or 
 #' "pairwise.complete.obs". Default is "pairwise.complete.obs".
@@ -92,7 +98,10 @@
   if (missing(factor.cov)) {
     factor.cov = cov(factor, use=use, ...) 
   } else {
-    identical(dim(factor.cov), as.integer(c(ncol(factor), ncol(factor))))
+    if (!identical(dim(factor.cov), as.integer(c(ncol(factor), ncol(factor))))) {
+      stop("Dimensions of user specified factor covariance matrix are not 
+           compatible with the number of factors in the fitTsfm object")
+    }
   }
   
   # residual covariance matrix D
@@ -115,7 +124,7 @@
 #' @method fmCov sfm
 #' @export
 
-fmCov.sfm <- function(object, use="pairwise.complete.obs", ...) {
+fmCov.sfm <- function(object, ...) {
   
   # already computed via fitSfm function
   return(object$Omega)
@@ -125,7 +134,7 @@
 #' @method fmCov ffm
 #' @export
 
-fmCov.ffm <- function(object, use="pairwise.complete.obs", ...) {
+fmCov.ffm <- function(object, ...) {
   
   # already computed via fitFfm function
   return(object$return.cov)

Modified: pkg/FactorAnalytics/R/fmSdDecomp.R
===================================================================
--- pkg/FactorAnalytics/R/fmSdDecomp.R	2016-08-04 12:36:18 UTC (rev 4024)
+++ pkg/FactorAnalytics/R/fmSdDecomp.R	2016-08-04 12:55:43 UTC (rev 4025)
@@ -19,11 +19,11 @@
 #' \code{mSd = cov(F.star)beta.star / Sd.fm}
 #' 
 #' @param object fit object of class \code{tsfm}, \code{sfm} or \code{ffm}.
-#' @param use an optional character string giving a method for computing 
-#' covariances in the presence of missing values. This must be (an 
-#' abbreviation of) one of the strings "everything", "all.obs", 
-#' "complete.obs", "na.or.complete", or "pairwise.complete.obs". Default is 
-#' "pairwise.complete.obs".
+#' @param factor.cov optional user specified factor covariance matrix with 
+#' named columns; defaults to the sample covariance matrix.
+#' @param use method for computing covariances in the presence of missing 
+#' values; one of "everything", "all.obs", "complete.obs", "na.or.complete", or 
+#' "pairwise.complete.obs". Default is "pairwise.complete.obs".
 #' @param ... optional arguments passed to \code{\link[stats]{cov}}.
 #' 
 #' @return A list containing 
@@ -33,7 +33,7 @@
 #' \item{pcSd}{N x (K+1) matrix of percentage component contributions to SD.}
 #' Where, \code{K} is the number of factors and N is the number of assets.
 #' 
-#' @author Eric Zivot, Sangeetha Srinivasan and Yi-An Chen
+#' @author Eric Zivot, Yi-An Chen and Sangeetha Srinivasan
 #' 
 #' @references 
 #' Hallerback (2003). Decomposing Portfolio Value-at-Risk: A General Analysis. 
@@ -95,7 +95,8 @@
 #' @method fmSdDecomp tsfm
 #' @export
 
-fmSdDecomp.tsfm <- function(object, use="pairwise.complete.obs", ...) {
+fmSdDecomp.tsfm <- function(object, factor.cov, 
+                            use="pairwise.complete.obs", ...) {
   
   # get beta.star: N x (K+1)
   beta <- object$beta
@@ -105,7 +106,14 @@
   
   # get cov(F): K x K
   factor <- as.matrix(object$data[, object$factor.names])
-  factor.cov = cov(factor, use=use, ...)
+  if (missing(factor.cov)) {
+    factor.cov = cov(factor, use=use, ...) 
+  } else {
+    if (!identical(dim(factor.cov), as.integer(c(ncol(factor), ncol(factor))))) {
+      stop("Dimensions of user specified factor covariance matrix are not 
+           compatible with the number of factors in the fitTsfm object")
+    }
+  }
   
   # get cov(F.star): (K+1) x (K+1)
   K <- ncol(object$beta)
@@ -132,7 +140,8 @@
 #' @method fmSdDecomp sfm
 #' @export
 
-fmSdDecomp.sfm <- function(object, use="pairwise.complete.obs", ...) {
+fmSdDecomp.sfm <- function(object, factor.cov,
+                           use="pairwise.complete.obs", ...) {
   
   # get beta.star: N x (K+1)
   beta <- object$loadings
@@ -142,7 +151,14 @@
   
   # get cov(F): K x K
   factor <- as.matrix(object$factors)
-  factor.cov = cov(factor, use=use, ...)
+  if (missing(factor.cov)) {
+    factor.cov = cov(factor, use=use, ...) 
+  } else {
+    if (!identical(dim(factor.cov), as.integer(c(ncol(factor), ncol(factor))))) {
+      stop("Dimensions of user specified factor covariance matrix are not 
+           compatible with the number of factors in the fitSfm object")
+    }
+  }
   
   # get cov(F.star): (K+1) x (K+1)
   K <- object$k
@@ -169,7 +185,7 @@
 #' @method fmSdDecomp ffm
 #' @export
 
-fmSdDecomp.ffm <- function(object, ...) {
+fmSdDecomp.ffm <- function(object, factor.cov, ...) {
   
   # get beta.star: N x (K+1)
   beta <- object$beta
@@ -177,7 +193,15 @@
   colnames(beta.star)[dim(beta.star)[2]] <- "residual"
   
   # get cov(F): K x K
-  factor.cov = object$factor.cov
+  if (missing(factor.cov)) {
+    factor.cov = object$factor.cov
+  } else {
+    if (!identical(dim(factor.cov), dim(object$factor.cov))) {
+      stop("Dimensions of user specified factor covariance matrix are not 
+           compatible with the number of factors (including dummies) in the 
+           fitFfm object")
+    }
+  }
   
   # get cov(F.star): (K+1) x (K+1)
   K <- ncol(object$beta)

Modified: pkg/FactorAnalytics/man/fmCov.Rd
===================================================================
--- pkg/FactorAnalytics/man/fmCov.Rd	2016-08-04 12:36:18 UTC (rev 4024)
+++ pkg/FactorAnalytics/man/fmCov.Rd	2016-08-04 12:55:43 UTC (rev 4025)
@@ -11,17 +11,17 @@
 
 \method{fmCov}{tsfm}(object, factor.cov, use = "pairwise.complete.obs", ...)
 
-\method{fmCov}{sfm}(object, use = "pairwise.complete.obs", ...)
+\method{fmCov}{sfm}(object, ...)
 
-\method{fmCov}{ffm}(object, use = "pairwise.complete.obs", ...)
+\method{fmCov}{ffm}(object, ...)
 }
 \arguments{
 \item{object}{fit object of class \code{tsfm}, \code{sfm} or \code{ffm}.}
 
 \item{...}{optional arguments passed to \code{\link[stats]{cov}}.}
 
-\item{factor.cov}{factor covariance matrix (optional); defaults to the 
-sample covariance matrix.}
+\item{factor.cov}{optional user specified factor covariance matrix with 
+named columns; defaults to the sample covariance matrix.}
 
 \item{use}{method for computing covariances in the presence of missing 
 values; one of "everything", "all.obs", "complete.obs", "na.or.complete", or 
@@ -52,9 +52,15 @@
 where, B is the \code{N x K} matrix of factor betas and \code{D} is a 
 diagonal matrix with \code{sig(i)^2} along the diagonal.
 
-The method for computing covariance can be specified via the \dots 
+For the time series factor model, the user can specify a factor covariance 
+matrix; otherwise the default is to use the sample covariance from factor 
+returns. The method for computing covariance can be specified via the \dots 
 argument. Note that the default of \code{use="pairwise.complete.obs"} for 
 handling NAs restricts the method to "pearson".
+
+For the statistical and fundamental factor model, the factor model 
+covariances already computed via the model fitting functions are simply 
+recalled by this method for user convenience.
 }
 \examples{
 # Time Series Factor model

Modified: pkg/FactorAnalytics/man/fmSdDecomp.Rd
===================================================================
--- pkg/FactorAnalytics/man/fmSdDecomp.Rd	2016-08-04 12:36:18 UTC (rev 4024)
+++ pkg/FactorAnalytics/man/fmSdDecomp.Rd	2016-08-04 12:55:43 UTC (rev 4025)
@@ -9,22 +9,25 @@
 \usage{
 fmSdDecomp(object, ...)
 
-\method{fmSdDecomp}{tsfm}(object, use = "pairwise.complete.obs", ...)
+\method{fmSdDecomp}{tsfm}(object, factor.cov, use = "pairwise.complete.obs",
+  ...)
 
-\method{fmSdDecomp}{sfm}(object, use = "pairwise.complete.obs", ...)
+\method{fmSdDecomp}{sfm}(object, factor.cov, use = "pairwise.complete.obs",
+  ...)
 
-\method{fmSdDecomp}{ffm}(object, ...)
+\method{fmSdDecomp}{ffm}(object, factor.cov, ...)
 }
 \arguments{
 \item{object}{fit object of class \code{tsfm}, \code{sfm} or \code{ffm}.}
 
 \item{...}{optional arguments passed to \code{\link[stats]{cov}}.}
 
-\item{use}{an optional character string giving a method for computing 
-covariances in the presence of missing values. This must be (an 
-abbreviation of) one of the strings "everything", "all.obs", 
-"complete.obs", "na.or.complete", or "pairwise.complete.obs". Default is 
-"pairwise.complete.obs".}
+\item{factor.cov}{optional user specified factor covariance matrix with 
+named columns; defaults to the sample covariance matrix.}
+
+\item{use}{method for computing covariances in the presence of missing 
+values; one of "everything", "all.obs", "complete.obs", "na.or.complete", or 
+"pairwise.complete.obs". Default is "pairwise.complete.obs".}
 }
 \value{
 A list containing 
@@ -72,7 +75,7 @@
  
 }
 \author{
-Eric Zivot, Sangeetha Srinivasan and Yi-An Chen
+Eric Zivot, Yi-An Chen and Sangeetha Srinivasan
 }
 \references{
 Hallerback (2003). Decomposing Portfolio Value-at-Risk: A General Analysis. 



More information about the Returnanalytics-commits mailing list