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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Thu Jul 25 20:18:00 CEST 2013


Author: chenyian
Date: 2013-07-25 20:18:00 +0200 (Thu, 25 Jul 2013)
New Revision: 2644

Modified:
   pkg/FactorAnalytics/R/print.TimeSeriesFactorModel.r
   pkg/FactorAnalytics/man/print.TimeSeriesFactorModel.Rd
Log:
create print.TimeSeriesFactorModel.r and print.TimeSeriesFactorModel.Rd

Modified: pkg/FactorAnalytics/R/print.TimeSeriesFactorModel.r
===================================================================
--- pkg/FactorAnalytics/R/print.TimeSeriesFactorModel.r	2013-07-25 16:56:45 UTC (rev 2643)
+++ pkg/FactorAnalytics/R/print.TimeSeriesFactorModel.r	2013-07-25 18:18:00 UTC (rev 2644)
@@ -4,20 +4,26 @@
 #' 
 #' 
 #' @param fit.macro fit object created by fitTimeSeriesFactorModel.
+#' @param digits. integer indicating the number of decimal places.  
 #' @author Eric Zivot and Yi-An Chen.
 #' @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.macro <- fitTimeSeriesFactorModel(ret.assets,factors,fit.method="OLS",
-#'                                  variable.selection="all subsets")
+#' fit.macro <- fitTimeseriesFactorModel(assets.names=colnames(managers.df[,(1:6)]),
+#'                                       factors.names=c("EDHEC.LS.EQ","SP500.TR"),
+#'                                       data=managers.df,fit.method="OLS")
 #' print(fit.macro)
 #' 
-#' 
-print.TimeSeriesFactorModel <-
-  function(fit.macro) {
-    lapply(fit.macro[[1]], print)
-  }
+#' @export
+print.TimeSeriesFactorModel <- function(fit.macro,digits=3){
+n <- length(fit.macro$beta)
+table.macro <-  as.matrix(fit.macro$alpha,nrow=n[1])
+table.macro <- cbind(table.macro,fit.macro$beta,fit.macro$r2,fit.macro$resid.variance)
+beta.names <- colnames(fit.macro$beta)
+for (i in 1:length(beta.names)) {
+beta.names[i] <- paste("beta.",beta.names[i],sep="")
+}
+colnames(table.macro) <- c("alpha",beta.names,"r2","resid.var")
+print(round(table.macro,digits=digits))
+}

Modified: pkg/FactorAnalytics/man/print.TimeSeriesFactorModel.Rd
===================================================================
--- pkg/FactorAnalytics/man/print.TimeSeriesFactorModel.Rd	2013-07-25 16:56:45 UTC (rev 2643)
+++ pkg/FactorAnalytics/man/print.TimeSeriesFactorModel.Rd	2013-07-25 18:18:00 UTC (rev 2644)
@@ -2,11 +2,14 @@
 \alias{print.TimeSeriesFactorModel}
 \title{print TimeSeriesfactorModel object}
 \usage{
-  print.TimeSeriesFactorModel(fit.macro)
+  print.TimeSeriesFactorModel(fit.macro, digits = 3)
 }
 \arguments{
   \item{fit.macro}{fit object created by
   fitTimeSeriesFactorModel.}
+
+  \item{digits.}{integer indicating the number of decimal
+  places.}
 }
 \description{
   Generic function of print method for
@@ -15,11 +18,9 @@
 \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.macro <- fitTimeSeriesFactorModel(ret.assets,factors,fit.method="OLS",
-                                 variable.selection="all subsets")
+fit.macro <- fitTimeseriesFactorModel(assets.names=colnames(managers.df[,(1:6)]),
+                                      factors.names=c("EDHEC.LS.EQ","SP500.TR"),
+                                      data=managers.df,fit.method="OLS")
 print(fit.macro)
 }
 \author{



More information about the Returnanalytics-commits mailing list