[Returnanalytics-commits] r2646 - in pkg/FactorAnalytics: R man
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Thu Jul 25 22:30:30 CEST 2013
Author: chenyian
Date: 2013-07-25 22:30:30 +0200 (Thu, 25 Jul 2013)
New Revision: 2646
Added:
pkg/FactorAnalytics/R/print.FundamentalFactorModel.r
pkg/FactorAnalytics/man/print.FundamentalFactorModel.Rd
Modified:
pkg/FactorAnalytics/R/fitFundamentalFactorModel.R
pkg/FactorAnalytics/R/plot.FundamentalFactorModel.r
pkg/FactorAnalytics/R/print.StatFactorModel.r
pkg/FactorAnalytics/R/print.TimeSeriesFactorModel.r
pkg/FactorAnalytics/man/fitFundamentalFactorModel.Rd
pkg/FactorAnalytics/man/plot.FundamentalFactorModel.Rd
pkg/FactorAnalytics/man/print.StatFactorModel.Rd
pkg/FactorAnalytics/man/print.TimeSeriesFactorModel.Rd
Log:
Add print.FundamentalFactorModel.Rd and print.FundamentalFactorModel.r
Modified: pkg/FactorAnalytics/R/fitFundamentalFactorModel.R
===================================================================
--- pkg/FactorAnalytics/R/fitFundamentalFactorModel.R 2013-07-25 18:50:32 UTC (rev 2645)
+++ pkg/FactorAnalytics/R/fitFundamentalFactorModel.R 2013-07-25 20:30:30 UTC (rev 2646)
@@ -51,7 +51,7 @@
#' 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 factors A "xts" object containing the times series of
+#' \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.
@@ -67,7 +67,7 @@
#' data(stock)
#' # there are 447 assets
#' exposure.names <- c("BOOK2MARKET", "LOG.MARKETCAP")
-#' ttest.fit <- fitFundamentalFactorModel(data=data,exposure.names=exposure.names,
+#' test.fit <- fitFundamentalFactorModel(data=data,exposure.names=exposure.names,
#' datevar = "DATE", returnsvar = "RETURN",
#' assetvar = "TICKER", wls = TRUE,
#' regression = "classic",
@@ -340,7 +340,7 @@
# give back the names of timedates
timedates <- as.Date(as.numeric(dimnames(FE.hat)[[1]]), origin = "1970-01-01")
coefs.names <- colnames(FE.hat.mat)[2:(1 + numCoefs)]
- # estimated factors ordered by time
+ # estimated factors returns ordered by time
f.hat <- xts(x = FE.hat.mat[, 2:(1 + numCoefs)], order.by = timedates)
# check for outlier
gomat <- apply(coredata(f.hat), 2, function(x) abs(x - median(x,
@@ -406,12 +406,18 @@
else {
Cov.resids <- NULL
}
+#
+# # r-square for each asset = 1 - SSE/SST
+# SSE <- apply(fit.fund$residuals^2,2,sum)
+# SST <- tapply(data[,returnsvar],data[,assetvar],function(x) sum((x-mean(x))^2))
+# r2 <- 1- SSE/SST
+
output <- list(returns.cov = Cov.returns,
factor.cov = Cov.factors,
resids.cov = Cov.resids,
resid.variance = resid.vars,
- factors = f.hat,
+ factor.returns = f.hat,
residuals = resids,
tstats = tstats,
call = this.call,
Modified: pkg/FactorAnalytics/R/plot.FundamentalFactorModel.r
===================================================================
--- pkg/FactorAnalytics/R/plot.FundamentalFactorModel.r 2013-07-25 18:50:32 UTC (rev 2645)
+++ pkg/FactorAnalytics/R/plot.FundamentalFactorModel.r 2013-07-25 20:30:30 UTC (rev 2646)
@@ -57,7 +57,7 @@
#' }
#'
plot.FundamentalFactorModel <-
-function(fit.fund,which.plot=c("none","1L","2L","3L","4L"),max.show=4,
+function(fit.fund,which.plot=c("none","1L","2L","3L","4L","5L","6L"),max.show=4,
plot.single=FALSE, asset.name,
which.plot.single=c("none","1L","2L","3L","4L","5L","6L",
"7L","8L","9L"),legend.txt=TRUE,...)
Added: pkg/FactorAnalytics/R/print.FundamentalFactorModel.r
===================================================================
--- pkg/FactorAnalytics/R/print.FundamentalFactorModel.r (rev 0)
+++ pkg/FactorAnalytics/R/print.FundamentalFactorModel.r 2013-07-25 20:30:30 UTC (rev 2646)
@@ -0,0 +1,40 @@
+#' print FundamentalFactorModel object
+#'
+#' Generic function of print method for fitFundamentalFactorModel.
+#'
+#'
+#' @param fit.fund fit object created by fitFundamentalFactorModel.
+#' @param digits integer indicating the number of decimal places. Default is 3.
+#' @param ... Other arguments for print methods.
+#' @author Yi-An Chen.
+#' @examples
+#'
+#' 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 = TRUE,
+#' robust.scale = TRUE)
+#'
+#' print(test.fit)
+#'
+#' @export
+print.FundamentalFactorModel <-
+ function(fit.fund, digits = max(3, .Options$digits - 3), ...)
+ {
+ if(!is.null(cl <- fit.fund$call)) {
+ cat("\nCall:\n")
+ dput(cl)
+ }
+ cat("\nFactor Model:\n")
+ tmp <- c(dim(fit.fund$beta)[2]-1,length(fit.fund$asset.names), nrow(fit.fund$factor.returns))
+ names(tmp) <- c("Exposures", "Variables", "Periods")
+ print(tmp)
+ cat("\nFactor Returns:\n")
+ print(fit.fund$factor.returns, digits = digits, ...)
+ cat("\nResidual Variance:\n")
+ print(fit.fund$resid.variance, digits = digits, ...)
+ }
Modified: pkg/FactorAnalytics/R/print.StatFactorModel.r
===================================================================
--- pkg/FactorAnalytics/R/print.StatFactorModel.r 2013-07-25 18:50:32 UTC (rev 2645)
+++ pkg/FactorAnalytics/R/print.StatFactorModel.r 2013-07-25 20:30:30 UTC (rev 2646)
@@ -3,7 +3,7 @@
#' Generic function of print method for fitStatFactorModel.
#'
#'
-#' @param fit.stat fit object created by fitMacroeconomicFactorModel.
+#' @param fit.stat fit object created by fitStatisticalFactorModel.
#' @param digits integer indicating the number of decimal places. Default is 3.
#' @param ... Other arguments for print methods.
#' @author Eric Zivot and Yi-An Chen.
@@ -17,7 +17,7 @@
#' sfm.pca.fit <- fitStatisticalFactorModel(sfm.dat,k=10)
#' print(sfm.pca.fit)
#'
-#'
+#' @export
print.StatFactorModel <-
function(fit.stat, digits = max(3, .Options$digits - 3), ...)
{
Modified: pkg/FactorAnalytics/R/print.TimeSeriesFactorModel.r
===================================================================
--- pkg/FactorAnalytics/R/print.TimeSeriesFactorModel.r 2013-07-25 18:50:32 UTC (rev 2645)
+++ pkg/FactorAnalytics/R/print.TimeSeriesFactorModel.r 2013-07-25 20:30:30 UTC (rev 2646)
@@ -6,7 +6,7 @@
#' @param fit.macro fit object created by fitTimeSeriesFactorModel.
#' @param digits. integer indicating the number of decimal places. Default is 3.
#' @param ... arguments to be passed to print method.
-#' @author Eric Zivot and Yi-An Chen.
+#' @author Yi-An Chen.
#' @examples
#'
#' # load data from the database
Modified: pkg/FactorAnalytics/man/fitFundamentalFactorModel.Rd
===================================================================
--- pkg/FactorAnalytics/man/fitFundamentalFactorModel.Rd 2013-07-25 18:50:32 UTC (rev 2645)
+++ pkg/FactorAnalytics/man/fitFundamentalFactorModel.Rd 2013-07-25 20:30:30 UTC (rev 2646)
@@ -61,12 +61,12 @@
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 factors 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 }
+ 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 }
}
\description{
fit fundamental factor model or cross-sectional time
@@ -93,7 +93,7 @@
data(stock)
# there are 447 assets
exposure.names <- c("BOOK2MARKET", "LOG.MARKETCAP")
-ttest.fit <- fitFundamentalFactorModel(data=data,exposure.names=exposure.names,
+test.fit <- fitFundamentalFactorModel(data=data,exposure.names=exposure.names,
datevar = "DATE", returnsvar = "RETURN",
assetvar = "TICKER", wls = TRUE,
regression = "classic",
Modified: pkg/FactorAnalytics/man/plot.FundamentalFactorModel.Rd
===================================================================
--- pkg/FactorAnalytics/man/plot.FundamentalFactorModel.Rd 2013-07-25 18:50:32 UTC (rev 2645)
+++ pkg/FactorAnalytics/man/plot.FundamentalFactorModel.Rd 2013-07-25 20:30:30 UTC (rev 2646)
@@ -3,7 +3,7 @@
\title{plot FundamentalFactorModel object.}
\usage{
plot.FundamentalFactorModel(fit.fund,
- which.plot = c("none", "1L", "2L", "3L", "4L"),
+ which.plot = c("none", "1L", "2L", "3L", "4L", "5L", "6L"),
max.show = 4, plot.single = FALSE, asset.name,
which.plot.single = c("none", "1L", "2L", "3L", "4L", "5L", "6L", "7L", "8L", "9L"),
legend.txt = TRUE, ...)
Added: pkg/FactorAnalytics/man/print.FundamentalFactorModel.Rd
===================================================================
--- pkg/FactorAnalytics/man/print.FundamentalFactorModel.Rd (rev 0)
+++ pkg/FactorAnalytics/man/print.FundamentalFactorModel.Rd 2013-07-25 20:30:30 UTC (rev 2646)
@@ -0,0 +1,37 @@
+\name{print.FundamentalFactorModel}
+\alias{print.FundamentalFactorModel}
+\title{print FundamentalFactorModel object}
+\usage{
+ print.FundamentalFactorModel(fit.fund,
+ digits = max(3, .Options$digits - 3), ...)
+}
+\arguments{
+ \item{fit.fund}{fit object created by
+ fitFundamentalFactorModel.}
+
+ \item{digits}{integer indicating the number of decimal
+ places. Default is 3.}
+
+ \item{...}{Other arguments for print methods.}
+}
+\description{
+ Generic function of print method for
+ fitFundamentalFactorModel.
+}
+\examples{
+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 = TRUE,
+ robust.scale = TRUE)
+
+print(test.fit)
+}
+\author{
+ Yi-An Chen.
+}
+
Modified: pkg/FactorAnalytics/man/print.StatFactorModel.Rd
===================================================================
--- pkg/FactorAnalytics/man/print.StatFactorModel.Rd 2013-07-25 18:50:32 UTC (rev 2645)
+++ pkg/FactorAnalytics/man/print.StatFactorModel.Rd 2013-07-25 20:30:30 UTC (rev 2646)
@@ -7,7 +7,7 @@
}
\arguments{
\item{fit.stat}{fit object created by
- fitMacroeconomicFactorModel.}
+ fitStatisticalFactorModel.}
\item{digits}{integer indicating the number of decimal
places. Default is 3.}
Modified: pkg/FactorAnalytics/man/print.TimeSeriesFactorModel.Rd
===================================================================
--- pkg/FactorAnalytics/man/print.TimeSeriesFactorModel.Rd 2013-07-25 18:50:32 UTC (rev 2645)
+++ pkg/FactorAnalytics/man/print.TimeSeriesFactorModel.Rd 2013-07-25 20:30:30 UTC (rev 2646)
@@ -27,6 +27,6 @@
print(fit.macro)
}
\author{
- Eric Zivot and Yi-An Chen.
+ Yi-An Chen.
}
More information about the Returnanalytics-commits
mailing list