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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Mon Aug 5 22:34:55 CEST 2013


Author: chenyian
Date: 2013-08-05 22:34:55 +0200 (Mon, 05 Aug 2013)
New Revision: 2724

Modified:
   pkg/FactorAnalytics/R/factorModelMonteCarlo.R
   pkg/FactorAnalytics/R/predict.FundamentalFactorModel.r
   pkg/FactorAnalytics/R/predict.StatFactorModel.r
   pkg/FactorAnalytics/R/predict.TimeSeriesFactorModel.r
   pkg/FactorAnalytics/R/print.FundamentalFactorModel.r
   pkg/FactorAnalytics/R/print.TimeSeriesFactorModel.r
   pkg/FactorAnalytics/R/summary.FundamentalFactorModel.r
   pkg/FactorAnalytics/R/summary.StatFactorModel.r
   pkg/FactorAnalytics/man/Stock.df.Rd
   pkg/FactorAnalytics/man/factorModelMonteCarlo.Rd
   pkg/FactorAnalytics/man/fitTimeseriesFactorModel.Rd
   pkg/FactorAnalytics/man/predict.FundamentalFactorModel.Rd
   pkg/FactorAnalytics/man/predict.StatFactorModel.Rd
   pkg/FactorAnalytics/man/predict.TimeSeriesFactorModel.Rd
   pkg/FactorAnalytics/man/print.FundamentalFactorModel.Rd
   pkg/FactorAnalytics/man/print.TimeSeriesFactorModel.Rd
   pkg/FactorAnalytics/man/summary.FundamentalFactorModel.Rd
   pkg/FactorAnalytics/man/summary.StatFactorModel.Rd
Log:
debug examples. 

Modified: pkg/FactorAnalytics/R/factorModelMonteCarlo.R
===================================================================
--- pkg/FactorAnalytics/R/factorModelMonteCarlo.R	2013-08-05 19:22:22 UTC (rev 2723)
+++ pkg/FactorAnalytics/R/factorModelMonteCarlo.R	2013-08-05 20:34:55 UTC (rev 2724)
@@ -51,12 +51,12 @@
 #' 
 #' # load data from the database
 #' data(managers.df)
-#' fit <- fitTimeseriesFactorModel(assets.names=colnames(managers.df[,(1:6)]),
+#' fit <- fitTimeSeriesFactorModel(assets.names=colnames(managers.df[,(1:6)]),
 #'                                 factors.names=c("EDHEC.LS.EQ","SP500.TR"),
 #'                                 data=managers.df,fit.method="OLS")
-#' factorData=factors  
-#' Beta.mat=fit$beta.mat
-#' residualData=as.matrix(fit$residVars.vec,1,6) 
+#' factorData= managers.df[,c("EDHEC.LS.EQ","SP500.TR")]  
+#' Beta.mat=fit$beta
+#' residualData=as.matrix(fit$resid.variance,1,6) 
 #' n.boot=1000
 #' # bootstrap returns data from factor model with residuals sample from normal distribution
 #' bootData <- factorModelMonteCarlo(n.boot, factorData,Beta.mat, residual.dist="normal",

Modified: pkg/FactorAnalytics/R/predict.FundamentalFactorModel.r
===================================================================
--- pkg/FactorAnalytics/R/predict.FundamentalFactorModel.r	2013-08-05 19:22:22 UTC (rev 2723)
+++ pkg/FactorAnalytics/R/predict.FundamentalFactorModel.r	2013-08-05 20:34:55 UTC (rev 2724)
@@ -21,13 +21,13 @@
 #'                                      wls = TRUE, regression = "classic", 
 #'                                      covariance = "classic", full.resid.cov = FALSE)
 #' # If not specify anything, predict() will give fitted value
-#' predict(fit.fund)
+#' pred.fund <- predict(fit.fund)
 #' 
 #' # generate random data
-#' testdata <- data[,c("DATE","TICKER")]
+#' testdata <- stock[,c("DATE","TICKER")]
 #' testdata$BOOK2MARKET <- rnorm(n=42465)
 #' testdata$LOG.MARKETCAP <- rnorm(n=42465)
-#' predict(fit.fund,testdata,new.assetvar="TICKER",new.datevar="DATE")
+#' pred.fund2 <- predict(fit.fund,testdata,new.assetvar="TICKER",new.datevar="DATE")
 #' 
 #' 
 predict.FundamentalFactorModel <- function(object,newdata,new.assetvar,new.datevar){

Modified: pkg/FactorAnalytics/R/predict.StatFactorModel.r
===================================================================
--- pkg/FactorAnalytics/R/predict.StatFactorModel.r	2013-08-05 19:22:22 UTC (rev 2723)
+++ pkg/FactorAnalytics/R/predict.StatFactorModel.r	2013-08-05 20:34:55 UTC (rev 2724)
@@ -7,16 +7,13 @@
 #' @param newdata a vector, matrix, data.frame, xts, timeSeries or zoo object to be coerced.
 #' @param ... Any other arguments used in \code{predict.lm}. For example like newdata and fit.se. 
 #' @author Yi-An Chen.
-#' ' 
+#' @method predict StatFactorModel
+#' @export 
 #' @examples
 #' data(stat.fm.data)
-#'.fit <- fitStatisticalFactorModel(sfm.dat,k=2,
-#                                   ckeckData.method="data.frame")
+#' fit <- fitStatisticalFactorModel(sfm.dat,k=2)
+#' pred.stat <- predict(fit)
 #' 
-#' predict(fit)
-#' @method predict StatFactorModel
-#' @export
-#' 
 
 
 predict.StatFactorModel <- function(object,newdata = NULL,...){

Modified: pkg/FactorAnalytics/R/predict.TimeSeriesFactorModel.r
===================================================================
--- pkg/FactorAnalytics/R/predict.TimeSeriesFactorModel.r	2013-08-05 19:22:22 UTC (rev 2723)
+++ pkg/FactorAnalytics/R/predict.TimeSeriesFactorModel.r	2013-08-05 20:34:55 UTC (rev 2724)
@@ -14,12 +14,14 @@
 #' data(managers.df)
 #' ret.assets = managers.df[,(1:6)]
 #' # fit the factor model with OLS
-#' fit <- fitTimeseriesFactorModel(assets.names=colnames(managers.df[,(1:6)]),
+#' fit <- fitTimeSeriesFactorModel(assets.names=colnames(managers.df[,(1:6)]),
 #'                                factors.names=c("EDHEC.LS.EQ","SP500.TR"),
 #'                                data=managers.df,fit.method="OLS")
 #' 
-#' predict(fit)
-#' predict(fit,newdata,interval="confidence")
+#' pred.fit <- predict(fit)
+#' newdata <- data.frame(EDHEC.LS.EQ = rnorm(n=120), SP500.TR = rnorm(n=120) )
+#' rownames(newdata) <- rownames(fit$data)
+#' pred.fit2 <- predict(fit,newdata,interval="confidence")
 #' 
 #' @method predict TimeSeriesFactorModel
 #' @export

Modified: pkg/FactorAnalytics/R/print.FundamentalFactorModel.r
===================================================================
--- pkg/FactorAnalytics/R/print.FundamentalFactorModel.r	2013-08-05 19:22:22 UTC (rev 2723)
+++ pkg/FactorAnalytics/R/print.FundamentalFactorModel.r	2013-08-05 20:34:55 UTC (rev 2724)
@@ -7,12 +7,14 @@
 #' @param digits integer indicating the number of decimal places. Default is 3.
 #' @param ...  Other arguments for print methods.
 #' @author Yi-An Chen.
+#' @method print FundamentalFactorModel
+#' @export
 #' @examples
 #' 
 #' data(Stock.df)
 #' # there are 447 assets  
 #' exposure.names <- c("BOOK2MARKET", "LOG.MARKETCAP") 
-#' test.fit <- fitFundamentalFactorModel(data=data,exposure.names=exposure.names,
+#' test.fit <- fitFundamentalFactorModel(data=stock,exposure.names=exposure.names,
 #'                                        datevar = "DATE", returnsvar = "RETURN",
 #'                                        assetvar = "TICKER", wls = TRUE, 
 #'                                        regression = "classic", 
@@ -20,8 +22,7 @@
 #'                                        robust.scale = TRUE)
 #' 
 #' print(test.fit)
-#' @method print FundamentalFactorModel
-#' @export 
+#'  
 print.FundamentalFactorModel <-
   function(x, digits = max(3, .Options$digits - 3), ...)
   {

Modified: pkg/FactorAnalytics/R/print.TimeSeriesFactorModel.r
===================================================================
--- pkg/FactorAnalytics/R/print.TimeSeriesFactorModel.r	2013-08-05 19:22:22 UTC (rev 2723)
+++ pkg/FactorAnalytics/R/print.TimeSeriesFactorModel.r	2013-08-05 20:34:55 UTC (rev 2724)
@@ -7,16 +7,17 @@
 #' @param digits integer indicating the number of decimal places. Default is 3.
 #' @param ... arguments to be passed to print method.   
 #' @author Yi-An Chen.
+#' @method print TimeSeriesFactorModel
+#' @export
 #' @examples
 #' 
 #' # load data from the database
 #' data(managers.df)
-#' fit.macro <- fitTimeseriesFactorModel(assets.names=colnames(managers.df[,(1:6)]),
+#' 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)
-#' @method print TimeSeriesFactorModel
-#' @export
+#' 
 print.TimeSeriesFactorModel <- function(x,digits=max(3, .Options$digits - 3),...){
   if(!is.null(cl <- x$call)) {
     cat("\nCall:\n")

Modified: pkg/FactorAnalytics/R/summary.FundamentalFactorModel.r
===================================================================
--- pkg/FactorAnalytics/R/summary.FundamentalFactorModel.r	2013-08-05 19:22:22 UTC (rev 2723)
+++ pkg/FactorAnalytics/R/summary.FundamentalFactorModel.r	2013-08-05 20:34:55 UTC (rev 2724)
@@ -7,12 +7,14 @@
 #' @param digits integer indicating the number of decimal places. Default is 3.
 #' @param ...  Other arguments for print methods.
 #' @author Yi-An Chen.
+#' @method summary FundamentalFactorModel
+#' @export
 #' @examples
 #' 
 #' data(Stock.df)
 #' # there are 447 assets  
 #' exposure.names <- c("BOOK2MARKET", "LOG.MARKETCAP") 
-#' test.fit <- fitFundamentalFactorModel(data=data,exposure.names=exposure.names,
+#' test.fit <- fitFundamentalFactorModel(data=stock,exposure.names=exposure.names,
 #'                                        datevar = "DATE", returnsvar = "RETURN",
 #'                                        assetvar = "TICKER", wls = TRUE, 
 #'                                        regression = "classic", 
@@ -20,8 +22,7 @@
 #'                                        robust.scale = TRUE)
 #' 
 #' summary(test.fit)
-#' @method summary FundamentalFactorModel
-#' @export 
+#'  
 summary.FundamentalFactorModel <-
   function(object, digits = max(3, .Options$digits - 3), ...)
   {

Modified: pkg/FactorAnalytics/R/summary.StatFactorModel.r
===================================================================
--- pkg/FactorAnalytics/R/summary.StatFactorModel.r	2013-08-05 19:22:22 UTC (rev 2723)
+++ pkg/FactorAnalytics/R/summary.StatFactorModel.r	2013-08-05 20:34:55 UTC (rev 2724)
@@ -7,17 +7,17 @@
 #' @param digits Integer indicating the number of decimal places. Default is 3.
 #' @param ... other option used in \code{summary.lm}
 #' @author Yi-An Chen.
+#' @method summary StatFactorModel
+#' @export
 #' @examples
 #' 
 #' # load data from the database
-#' data(managers.df)
+#' data(stat.fm.data)
 #' # fit the factor model with OLS
-#' fit <- fitStatisticalFactorModel(fitStatisticalFactorModel(sfm.dat,k=2,
-#'                                   ckeckData.method="data.frame"))
+#' fit <- fitStatisticalFactorModel(sfm.dat,k=2)
 #' summary(fit)
-#' @method summary StatFactorModel
-#' @export
 #' 
+#' 
 summary.StatFactorModel <- function(object,digits=3){
   if(!is.null(cl <- object$call)) {
     cat("\nCall:\n")

Modified: pkg/FactorAnalytics/man/Stock.df.Rd
===================================================================
--- pkg/FactorAnalytics/man/Stock.df.Rd	2013-08-05 19:22:22 UTC (rev 2723)
+++ pkg/FactorAnalytics/man/Stock.df.Rd	2013-08-05 20:34:55 UTC (rev 2724)
@@ -1,7 +1,6 @@
 \docType{data}
 \name{Stock.df}
 \alias{Stock.df}
-\alias{stock}
 \title{constructed NYSE 447 assets from 1996-01-01 through 2003-12-31.}
 \description{
   constructed NYSE 447 assets from 1996-01-01 through

Modified: pkg/FactorAnalytics/man/factorModelMonteCarlo.Rd
===================================================================
--- pkg/FactorAnalytics/man/factorModelMonteCarlo.Rd	2013-08-05 19:22:22 UTC (rev 2723)
+++ pkg/FactorAnalytics/man/factorModelMonteCarlo.Rd	2013-08-05 20:34:55 UTC (rev 2724)
@@ -79,12 +79,12 @@
 \examples{
 # load data from the database
 data(managers.df)
-fit <- fitTimeseriesFactorModel(assets.names=colnames(managers.df[,(1:6)]),
+fit <- fitTimeSeriesFactorModel(assets.names=colnames(managers.df[,(1:6)]),
                                 factors.names=c("EDHEC.LS.EQ","SP500.TR"),
                                 data=managers.df,fit.method="OLS")
-factorData=factors
-Beta.mat=fit$beta.mat
-residualData=as.matrix(fit$residVars.vec,1,6)
+factorData= managers.df[,c("EDHEC.LS.EQ","SP500.TR")]
+Beta.mat=fit$beta
+residualData=as.matrix(fit$resid.variance,1,6)
 n.boot=1000
 # bootstrap returns data from factor model with residuals sample from normal distribution
 bootData <- factorModelMonteCarlo(n.boot, factorData,Beta.mat, residual.dist="normal",

Modified: pkg/FactorAnalytics/man/fitTimeseriesFactorModel.Rd
===================================================================
--- pkg/FactorAnalytics/man/fitTimeseriesFactorModel.Rd	2013-08-05 19:22:22 UTC (rev 2723)
+++ pkg/FactorAnalytics/man/fitTimeseriesFactorModel.Rd	2013-08-05 20:34:55 UTC (rev 2724)
@@ -105,7 +105,7 @@
 \dontrun{
 # load data from the database
 data(managers.df)
-fit <- fitTimeseriesFactorModel(assets.names=colnames(managers.df[,(1:6)]),
+fit <- fitTimeSeriesFactorModel(assets.names=colnames(managers.df[,(1:6)]),
                                 factors.names=c("EDHEC.LS.EQ","SP500.TR"),
                                 data=managers.df,fit.method="OLS")
 # summary of HAM1

Modified: pkg/FactorAnalytics/man/predict.FundamentalFactorModel.Rd
===================================================================
--- pkg/FactorAnalytics/man/predict.FundamentalFactorModel.Rd	2013-08-05 19:22:22 UTC (rev 2723)
+++ pkg/FactorAnalytics/man/predict.FundamentalFactorModel.Rd	2013-08-05 20:34:55 UTC (rev 2724)
@@ -35,13 +35,13 @@
                                      wls = TRUE, regression = "classic",
                                      covariance = "classic", full.resid.cov = FALSE)
 # If not specify anything, predict() will give fitted value
-predict(fit.fund)
+pred.fund <- predict(fit.fund)
 
 # generate random data
-testdata <- data[,c("DATE","TICKER")]
+testdata <- stock[,c("DATE","TICKER")]
 testdata$BOOK2MARKET <- rnorm(n=42465)
 testdata$LOG.MARKETCAP <- rnorm(n=42465)
-predict(fit.fund,testdata,new.assetvar="TICKER",new.datevar="DATE")
+pred.fund2 <- predict(fit.fund,testdata,new.assetvar="TICKER",new.datevar="DATE")
 }
 \author{
   Yi-An Chen

Modified: pkg/FactorAnalytics/man/predict.StatFactorModel.Rd
===================================================================
--- pkg/FactorAnalytics/man/predict.StatFactorModel.Rd	2013-08-05 19:22:22 UTC (rev 2723)
+++ pkg/FactorAnalytics/man/predict.StatFactorModel.Rd	2013-08-05 20:34:55 UTC (rev 2724)
@@ -22,11 +22,10 @@
 }
 \examples{
 data(stat.fm.data)
-.fit <- fitStatisticalFactorModel(sfm.dat,k=2,
-
-predict(fit)
+fit <- fitStatisticalFactorModel(sfm.dat,k=2)
+pred.stat <- predict(fit)
 }
 \author{
-  Yi-An Chen. '
+  Yi-An Chen.
 }
 

Modified: pkg/FactorAnalytics/man/predict.TimeSeriesFactorModel.Rd
===================================================================
--- pkg/FactorAnalytics/man/predict.TimeSeriesFactorModel.Rd	2013-08-05 19:22:22 UTC (rev 2723)
+++ pkg/FactorAnalytics/man/predict.TimeSeriesFactorModel.Rd	2013-08-05 20:34:55 UTC (rev 2724)
@@ -25,12 +25,14 @@
 data(managers.df)
 ret.assets = managers.df[,(1:6)]
 # fit the factor model with OLS
-fit <- fitTimeseriesFactorModel(assets.names=colnames(managers.df[,(1:6)]),
+fit <- fitTimeSeriesFactorModel(assets.names=colnames(managers.df[,(1:6)]),
                                factors.names=c("EDHEC.LS.EQ","SP500.TR"),
                                data=managers.df,fit.method="OLS")
 
-predict(fit)
-predict(fit,newdata,interval="confidence")
+pred.fit <- predict(fit)
+newdata <- data.frame(EDHEC.LS.EQ = rnorm(n=120), SP500.TR = rnorm(n=120) )
+rownames(newdata) <- rownames(fit$data)
+pred.fit2 <- predict(fit,newdata,interval="confidence")
 }
 \author{
   Yi-An Chen.

Modified: pkg/FactorAnalytics/man/print.FundamentalFactorModel.Rd
===================================================================
--- pkg/FactorAnalytics/man/print.FundamentalFactorModel.Rd	2013-08-05 19:22:22 UTC (rev 2723)
+++ pkg/FactorAnalytics/man/print.FundamentalFactorModel.Rd	2013-08-05 20:34:55 UTC (rev 2724)
@@ -22,7 +22,7 @@
 data(Stock.df)
 # there are 447 assets
 exposure.names <- c("BOOK2MARKET", "LOG.MARKETCAP")
-test.fit <- fitFundamentalFactorModel(data=data,exposure.names=exposure.names,
+test.fit <- fitFundamentalFactorModel(data=stock,exposure.names=exposure.names,
                                        datevar = "DATE", returnsvar = "RETURN",
                                        assetvar = "TICKER", wls = TRUE,
                                        regression = "classic",

Modified: pkg/FactorAnalytics/man/print.TimeSeriesFactorModel.Rd
===================================================================
--- pkg/FactorAnalytics/man/print.TimeSeriesFactorModel.Rd	2013-08-05 19:22:22 UTC (rev 2723)
+++ pkg/FactorAnalytics/man/print.TimeSeriesFactorModel.Rd	2013-08-05 20:34:55 UTC (rev 2724)
@@ -20,7 +20,7 @@
 \examples{
 # load data from the database
 data(managers.df)
-fit.macro <- fitTimeseriesFactorModel(assets.names=colnames(managers.df[,(1:6)]),
+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)

Modified: pkg/FactorAnalytics/man/summary.FundamentalFactorModel.Rd
===================================================================
--- pkg/FactorAnalytics/man/summary.FundamentalFactorModel.Rd	2013-08-05 19:22:22 UTC (rev 2723)
+++ pkg/FactorAnalytics/man/summary.FundamentalFactorModel.Rd	2013-08-05 20:34:55 UTC (rev 2724)
@@ -22,7 +22,7 @@
 data(Stock.df)
 # there are 447 assets
 exposure.names <- c("BOOK2MARKET", "LOG.MARKETCAP")
-test.fit <- fitFundamentalFactorModel(data=data,exposure.names=exposure.names,
+test.fit <- fitFundamentalFactorModel(data=stock,exposure.names=exposure.names,
                                        datevar = "DATE", returnsvar = "RETURN",
                                        assetvar = "TICKER", wls = TRUE,
                                        regression = "classic",

Modified: pkg/FactorAnalytics/man/summary.StatFactorModel.Rd
===================================================================
--- pkg/FactorAnalytics/man/summary.StatFactorModel.Rd	2013-08-05 19:22:22 UTC (rev 2723)
+++ pkg/FactorAnalytics/man/summary.StatFactorModel.Rd	2013-08-05 20:34:55 UTC (rev 2724)
@@ -19,10 +19,9 @@
 }
 \examples{
 # load data from the database
-data(managers.df)
+data(stat.fm.data)
 # fit the factor model with OLS
-fit <- fitStatisticalFactorModel(fitStatisticalFactorModel(sfm.dat,k=2,
-                                  ckeckData.method="data.frame"))
+fit <- fitStatisticalFactorModel(sfm.dat,k=2)
 summary(fit)
 }
 \author{



More information about the Returnanalytics-commits mailing list