[Returnanalytics-commits] r2649 - in pkg/FactorAnalytics: R data man
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Fri Jul 26 20:08:20 CEST 2013
Author: chenyian
Date: 2013-07-26 20:08:20 +0200 (Fri, 26 Jul 2013)
New Revision: 2649
Modified:
pkg/FactorAnalytics/R/fitStatisticalFactorModel.R
pkg/FactorAnalytics/R/fitTimeSeriesFactorModel.R
pkg/FactorAnalytics/R/summary.StatFactorModel.r
pkg/FactorAnalytics/R/summary.TimeSeriesFactorModel.r
pkg/FactorAnalytics/data/stock.RDATA
pkg/FactorAnalytics/man/fitStatisticalFactorModel.Rd
pkg/FactorAnalytics/man/fitTimeseriesFactorModel.Rd
pkg/FactorAnalytics/man/summary.StatFactorModel.Rd
pkg/FactorAnalytics/man/summary.TimeSeriesFactorModel.Rd
Log:
add summary.StatFactorModel.Rd and summary.StatFactorModel.r
Modified: pkg/FactorAnalytics/R/fitStatisticalFactorModel.R
===================================================================
--- pkg/FactorAnalytics/R/fitStatisticalFactorModel.R 2013-07-26 15:25:01 UTC (rev 2648)
+++ pkg/FactorAnalytics/R/fitStatisticalFactorModel.R 2013-07-26 18:08:20 UTC (rev 2649)
@@ -5,7 +5,7 @@
#'
#'
#' @param data a vector, matrix, data.frame, xts, timeSeries or zoo object with asset returns
-#' and factors retunrs rownames
+#' and factors retunrs names
#' @param k numbers of factors if it is scalar or method of choosing optimal
#' number of factors. "bn" represents Bai and Ng (2002) method and "ck"
#' represents Connor and korajczyk (1993) method. Default is k = 1.
@@ -393,6 +393,7 @@
ans$resid.variance <- apply(ans$residuals,2,var)
ans$call <- call
ans$data <- data
+ ans$assets.names <- colnames(data)
class(ans) <- "StatFactorModel"
return(ans)
}
Modified: pkg/FactorAnalytics/R/fitTimeSeriesFactorModel.R
===================================================================
--- pkg/FactorAnalytics/R/fitTimeSeriesFactorModel.R 2013-07-26 15:25:01 UTC (rev 2648)
+++ pkg/FactorAnalytics/R/fitTimeSeriesFactorModel.R 2013-07-26 18:08:20 UTC (rev 2649)
@@ -66,7 +66,7 @@
#' chart.TimeSeries(dataToPlot, main="FM fit for HAM1",
#' colorset=c("black","blue"), legend.loc="bottomleft")
#' }
-fitTimeseriesFactorModel <-
+fitTimeSeriesFactorModel <-
function(assets.names, factors.names, data=data, num.factor.subset = 1,
fit.method=c("OLS","DLS","Robust"),
variable.selection="none",
Modified: pkg/FactorAnalytics/R/summary.StatFactorModel.r
===================================================================
--- pkg/FactorAnalytics/R/summary.StatFactorModel.r 2013-07-26 15:25:01 UTC (rev 2648)
+++ pkg/FactorAnalytics/R/summary.StatFactorModel.r 2013-07-26 18:08:20 UTC (rev 2649)
@@ -1,24 +1,38 @@
#' summary method for StatFactorModel object.
#'
-#' Generic function of summary method for fitStatisticalFactorModel. It utilizes
-#' function \code{summary.lm}.
+#' Generic function of summary method for fitStatisticalFactorModel.
#'
-#' @param fit "StatFactorModel" object created by fitStatisticalFactorModel.
-#' @param newdata An optional data frame in which to look for variables with which to predict.
-#' If omitted, the fitted values are used.
-#' @param ... Any other arguments used in \code{summary.lm}
+#'
+#' @param fit.stat fit.stat object created by fitStatisticalFactorModel.
+#' @param digits Integer indicating the number of decimal places. Default is 3.
+#' @param ... other option used in \code{summary.lm}
#' @author Yi-An Chen.
-#' '
#' @examples
-#' data(stat.fm.data)
-#'.fit <- fitStatisticalFactorModel(sfm.dat,k=2,
-# ckeckData.method="data.frame")
#'
+#' # load data from the database
+#' data(managers.df)
+#' # fit the factor model with OLS
+#' fit <- fitStatisticalFactorModel(fitStatisticalFactorModel(sfm.dat,k=2,
+#' ckeckData.method="data.frame"))
#' summary(fit)
+#'
#' @export
#'
+summary.StatFactorModel <- function(fit.stat,digits=3){
+ if(!is.null(cl <- fit.stat$call)) {
+ cat("\nCall:\n")
+ dput(cl)
+ }
+ cat("\nFactor Betas\n")
+ n <- length(fit.stat$assets.names)
+ for (i in 1:n) {
+ options(digits = digits)
+ cat("\n", fit.stat$assets.names[i], "\n")
+ table.macro <- t(summary(fit.stat$asset.fit[[i]])$coefficients)
+ colnames(table.macro)[1] <- "alpha"
+ print(table.macro,digits = digits)
+ cat("\nR-square =", fit.stat$r2[i] ,",residual variance ="
+ , fit.stat$resid.variance[i],"\n")
+ }
+}
-
-summary.StatFactorModel <- function(fit,...){
- lapply(fit$asset.fit, summary,...)
-}
\ No newline at end of file
Modified: pkg/FactorAnalytics/R/summary.TimeSeriesFactorModel.r
===================================================================
--- pkg/FactorAnalytics/R/summary.TimeSeriesFactorModel.r 2013-07-26 15:25:01 UTC (rev 2648)
+++ pkg/FactorAnalytics/R/summary.TimeSeriesFactorModel.r 2013-07-26 18:08:20 UTC (rev 2649)
@@ -1,10 +1,10 @@
#' summary method for TimeSeriesModel object.
#'
#' Generic function of summary method for fitTimeSeriesFactorModel.
-#' It utilizes \code{summary.lm}
#'
#'
-#' @param fit fit object created by fitTimeSeiresFactorModel.
+#' @param fit.macro fit.macro object created by fitTimeSeiresFactorModel.
+#' @param digits Integer indicating the number of decimal places. Default is 3.
#' @param ... other option used in \code{summary.lm}
#' @author Yi-An Chen.
#' @examples
@@ -19,7 +19,7 @@
#'
#' @export
#'
-summary.TimeSeriesFactorModel <- function(fit,digits=3){
+summary.TimeSeriesFactorModel <- function(fit.macro,digits=3){
if(!is.null(cl <- fit.macro$call)) {
cat("\nCall:\n")
dput(cl)
Modified: pkg/FactorAnalytics/data/stock.RDATA
===================================================================
(Binary files differ)
Modified: pkg/FactorAnalytics/man/fitStatisticalFactorModel.Rd
===================================================================
--- pkg/FactorAnalytics/man/fitStatisticalFactorModel.Rd 2013-07-26 15:25:01 UTC (rev 2648)
+++ pkg/FactorAnalytics/man/fitStatisticalFactorModel.Rd 2013-07-26 18:08:20 UTC (rev 2649)
@@ -9,7 +9,7 @@
\arguments{
\item{data}{a vector, matrix, data.frame, xts, timeSeries
or zoo object with asset returns and factors retunrs
- rownames}
+ names}
\item{k}{numbers of factors if it is scalar or method of
choosing optimal number of factors. "bn" represents Bai
Modified: pkg/FactorAnalytics/man/fitTimeseriesFactorModel.Rd
===================================================================
--- pkg/FactorAnalytics/man/fitTimeseriesFactorModel.Rd 2013-07-26 15:25:01 UTC (rev 2648)
+++ pkg/FactorAnalytics/man/fitTimeseriesFactorModel.Rd 2013-07-26 18:08:20 UTC (rev 2649)
@@ -1,8 +1,8 @@
-\name{fitTimeseriesFactorModel}
-\alias{fitTimeseriesFactorModel}
+\name{fitTimeSeriesFactorModel}
+\alias{fitTimeSeriesFactorModel}
\title{Fit time series factor model by time series regression techniques.}
\usage{
- fitTimeseriesFactorModel(assets.names, factors.names,
+ fitTimeSeriesFactorModel(assets.names, factors.names,
data = data, num.factor.subset = 1,
fit.method = c("OLS", "DLS", "Robust"),
variable.selection = "none", decay.factor = 0.95,
Modified: pkg/FactorAnalytics/man/summary.StatFactorModel.Rd
===================================================================
--- pkg/FactorAnalytics/man/summary.StatFactorModel.Rd 2013-07-26 15:25:01 UTC (rev 2648)
+++ pkg/FactorAnalytics/man/summary.StatFactorModel.Rd 2013-07-26 18:08:20 UTC (rev 2649)
@@ -2,30 +2,30 @@
\alias{summary.StatFactorModel}
\title{summary method for StatFactorModel object.}
\usage{
- summary.StatFactorModel(fit, ...)
+ summary.StatFactorModel(fit.stat, digits = 3)
}
\arguments{
- \item{fit}{"StatFactorModel" object created by
+ \item{fit.stat}{fit.stat object created by
fitStatisticalFactorModel.}
- \item{newdata}{An optional data frame in which to look
- for variables with which to predict. If omitted, the
- fitted values are used.}
+ \item{digits}{Integer indicating the number of decimal
+ places. Default is 3.}
- \item{...}{Any other arguments used in \code{summary.lm}}
+ \item{...}{other option used in \code{summary.lm}}
}
\description{
Generic function of summary method for
- fitStatisticalFactorModel. It utilizes function
- \code{summary.lm}.
+ fitStatisticalFactorModel.
}
\examples{
-data(stat.fm.data)
-.fit <- fitStatisticalFactorModel(sfm.dat,k=2,
-
+# load data from the database
+data(managers.df)
+# fit the factor model with OLS
+fit <- fitStatisticalFactorModel(fitStatisticalFactorModel(sfm.dat,k=2,
+ ckeckData.method="data.frame"))
summary(fit)
}
\author{
- Yi-An Chen. '
+ Yi-An Chen.
}
Modified: pkg/FactorAnalytics/man/summary.TimeSeriesFactorModel.Rd
===================================================================
--- pkg/FactorAnalytics/man/summary.TimeSeriesFactorModel.Rd 2013-07-26 15:25:01 UTC (rev 2648)
+++ pkg/FactorAnalytics/man/summary.TimeSeriesFactorModel.Rd 2013-07-26 18:08:20 UTC (rev 2649)
@@ -2,23 +2,24 @@
\alias{summary.TimeSeriesFactorModel}
\title{summary method for TimeSeriesModel object.}
\usage{
- summary.TimeSeriesFactorModel(fit, ...)
+ summary.TimeSeriesFactorModel(fit.macro, digits = 3)
}
\arguments{
- \item{fit}{fit object created by
+ \item{fit.macro}{fit.macro object created by
fitTimeSeiresFactorModel.}
+ \item{digits}{Integer indicating the number of decimal
+ places. Default is 3.}
+
\item{...}{other option used in \code{summary.lm}}
}
\description{
Generic function of summary method for
- fitTimeSeriesFactorModel. It utilizes \code{summary.lm}
+ fitTimeSeriesFactorModel.
}
\examples{
# load data from the database
data(managers.df)
-ret.assets = managers.df[,(1:6)]
-factors = managers.df[,(7:9)]
# fit the factor model with OLS
fit <- fitTimeSeriesFactorModel(assets.names=colnames(managers.df[,(1:6)]),
factors.names=c("EDHEC.LS.EQ","SP500.TR"),
More information about the Returnanalytics-commits
mailing list