[Returnanalytics-commits] r2589 - pkg/FactorAnalytics/R
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Wed Jul 17 20:30:39 CEST 2013
Author: chenyian
Date: 2013-07-17 20:30:39 +0200 (Wed, 17 Jul 2013)
New Revision: 2589
Modified:
pkg/FactorAnalytics/R/factorModelCovariance.r
pkg/FactorAnalytics/R/fitFundamentalFactorModel.R
Log:
1. modify Rd. file of fitFundamentalFactorModel.R
2. add function that factorModelCovariance.r can take fitFundamentalFactorModel.R
Modified: pkg/FactorAnalytics/R/factorModelCovariance.r
===================================================================
--- pkg/FactorAnalytics/R/factorModelCovariance.r 2013-07-17 12:17:59 UTC (rev 2588)
+++ pkg/FactorAnalytics/R/factorModelCovariance.r 2013-07-17 18:30:39 UTC (rev 2589)
@@ -45,6 +45,30 @@
#' factorModelCovariance(t(sfm.apca.fit$loadings),
#' var(sfm.apca.fit$factors),sfm.apca.fit$resid.variance)
#'
+#' # fundamental factor model example
+#'
+#'
+#' data(stock)
+#' # there are 447 assets
+#' exposure.names <- c("BOOK2MARKET", "LOG.MARKETCAP")
+#' test.fit <- fitFundamentalFactorModel(data=data,exposure.names=exposure.names,
+#' datevar = "DATE", returnsvar = "RETURN",
+#' assetvar = "TICKER", wls = TRUE,
+#' regression = "classic",
+#' covariance = "classic", full.resid.cov = FALSE,
+#' robust.scale = TRUE)
+#'
+#' # compute return covariance
+#' # take beta as latest date input
+#' beta.mat.fundm <- subset(data,DATE == "2003-12-31")[,exposure.names]
+#' beta.mat.fundm <- cbind(rep(1,447),beta.mat.fundm) # add intercept
+#' FM return covariance
+#' ret.cov.fundm <- factorModelCovariance(beta.mat.fundm,test.fit$factor.cov$cov,
+#' test.fit$resid.variance)
+#' # the result is exactly the same
+#' test.fit$returns.cov$cov == ret.cov.fundm
+#'
+
factorModelCovariance <-
function(beta.mat, factor.cov, residVars.vec) {
Modified: pkg/FactorAnalytics/R/fitFundamentalFactorModel.R
===================================================================
--- pkg/FactorAnalytics/R/fitFundamentalFactorModel.R 2013-07-17 12:17:59 UTC (rev 2588)
+++ pkg/FactorAnalytics/R/fitFundamentalFactorModel.R 2013-07-17 18:30:39 UTC (rev 2589)
@@ -37,11 +37,12 @@
#' the data.
#' @return an S3 object containing
#' \itemize{
-#' \item cov.returns A "list" object contains covariance information for
-#' asset returns, includes covariance, mean and eigenvalus.
-#' \item cov.factor Anobject of class "cov" or "covRob" which
+#' \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 cov.resids An object of class "cov" or "covRob" which contains
+#' \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 resid.variance A vector of variances estimated from the OLS
@@ -72,10 +73,10 @@
#' robust.scale = TRUE)
#'
#' names(test.fit)
-#' test.fit$cov.returns
-#' test.fit$cov.resids
+#' test.fit$returns.cov
+#' test.fit$resids.cov
#' names(test.fit$cov.factor)
-#' test.fit$cov.factor$cov
+#' test.fit$factor.cov$cov
#' test.fit$factor
#' test.fit$resid.variance
#' test.fit$resids
@@ -401,9 +402,9 @@
else {
Cov.resids <- NULL
}
- output <- list(cov.returns = Cov.returns,
- cov.factor = Cov.factors,
- cov.resids = Cov.resids,
+ output <- list(returns.cov = Cov.returns,
+ factor.cov = Cov.factors,
+ resids.cov = Cov.resids,
resid.variance = resid.vars,
factors = f.hat,
residuals = resids,
@@ -412,5 +413,4 @@
data = data)
class(output) <- "FundamentalFactorModel"
return(output)
-}
-
+}
\ No newline at end of file
More information about the Returnanalytics-commits
mailing list