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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Tue Sep 15 01:00:03 CEST 2015


Author: pragnya
Date: 2015-09-15 01:00:02 +0200 (Tue, 15 Sep 2015)
New Revision: 3993

Modified:
   pkg/FactorAnalytics/DESCRIPTION
   pkg/FactorAnalytics/R/fitTsfm.R
   pkg/FactorAnalytics/R/fitTsfm.control.R
   pkg/FactorAnalytics/man/Stock.df.Rd
Log:
Pass names instead of functions to do.call in fitTsfm; Updated Stock.df.Rd

Modified: pkg/FactorAnalytics/DESCRIPTION
===================================================================
--- pkg/FactorAnalytics/DESCRIPTION	2015-08-31 21:52:27 UTC (rev 3992)
+++ pkg/FactorAnalytics/DESCRIPTION	2015-09-14 23:00:02 UTC (rev 3993)
@@ -1,8 +1,8 @@
 Package: factorAnalytics
 Type: Package
 Title: Factor Analytics
-Version: 2.0.24
-Date: 2015-08-08
+Version: 2.0.25
+Date: 2015-09-14
 Author: Eric Zivot, Sangeetha Srinivasan and Yi-An Chen
 Maintainer: Sangeetha Srinivasan <sangee at uw.edu>
 Description: Linear factor model fitting for asset returns (three major types- 

Modified: pkg/FactorAnalytics/R/fitTsfm.R
===================================================================
--- pkg/FactorAnalytics/R/fitTsfm.R	2015-08-31 21:52:27 UTC (rev 3992)
+++ pkg/FactorAnalytics/R/fitTsfm.R	2015-09-14 23:00:02 UTC (rev 3993)
@@ -160,11 +160,11 @@
   # set defaults and check input vailidity
   fit.method = fit.method[1]
   if (!(fit.method %in% c("LS","DLS","Robust"))) {
-    stop("Invalid argument: fit.method must be 'LS', 'DLS' or 'Robust'")
+    stop("Invalid args: fit.method must be 'LS', 'DLS' or 'Robust'")
   }
   variable.selection = variable.selection[1]
   if (!(variable.selection %in% c("none","stepwise","subsets","lars"))) {
-    stop("Invalid argument: variable.selection must be either 'none',
+    stop("Invalid args: variable.selection must be either 'none',
          'stepwise','subsets' or 'lars'")
   }
   if (missing(factor.names) && !is.null(mkt.name)) {
@@ -215,8 +215,8 @@
   mkt.name <- gsub(" ",".", mkt.name, fixed=TRUE)
   rf.name <- gsub(" ",".", rf.name, fixed=TRUE)
   
-  # Selects regression procedure based on specified variable.selection method.
-  # Each method returns a list of fitted factor models for each asset.
+  # select procedure based on the variable.selection method
+  # returns a list of the fitted factor model for all assets
   if (variable.selection == "none") {
     reg.list <- NoVariableSelection(dat.xts, asset.names, factor.names, 
                                     fit.method, lm.args, lmRob.args, decay)
@@ -280,13 +280,12 @@
     
     # fit based on time series regression method chosen
     if (fit.method == "LS") {
-      reg.list[[i]] <- do.call(lm, c(list(fm.formula,data=reg.xts),lm.args))
+      reg.list[[i]] <- do.call("lm", c(list(fm.formula,data=quote(reg.xts)),lm.args))
     } else if (fit.method == "DLS") {
       lm.args$weights <- WeightsDLS(nrow(reg.xts), decay)
-      reg.list[[i]] <- do.call(lm, c(list(fm.formula,data=reg.xts),lm.args))
+      reg.list[[i]] <- do.call("lm", c(list(fm.formula,data=quote(reg.xts)),lm.args))
     } else if (fit.method == "Robust") {
-      reg.list[[i]] <- do.call(lmRob, c(list(fm.formula,data=reg.xts), 
-                                        lmRob.args))
+      reg.list[[i]] <- do.call("lmRob", c(list(fm.formula,data=quote(reg.xts)),lmRob.args))
     } 
   } 
   reg.list  
@@ -310,15 +309,15 @@
     
     # fit based on time series regression method chosen
     if (fit.method == "LS") {
-      lm.fit <- do.call(lm, c(list(fm.formula,data=reg.xts),lm.args))
-      reg.list[[i]] <- do.call(step, c(list(lm.fit),step.args))
+      lm.fit <- do.call("lm", c(list(fm.formula,data=quote(reg.xts)),lm.args))
+      reg.list[[i]] <- do.call("step", c(list(lm.fit),step.args))
     } else if (fit.method == "DLS") {
       lm.args$weights <- WeightsDLS(nrow(reg.xts), decay)
-      lm.fit <- do.call(lm, c(list(fm.formula,data=reg.xts),lm.args))
-      reg.list[[i]] <- do.call(step, c(list(lm.fit),step.args))
+      lm.fit <- do.call("lm", c(list(fm.formula,data=quote(reg.xts)),lm.args))
+      reg.list[[i]] <- do.call("step", c(list(lm.fit),step.args))
     } else if (fit.method == "Robust") {
-      lmRob.fit <- do.call(lmRob, c(list(fm.formula,data=reg.xts), lmRob.args))
-      reg.list[[i]] <- do.call(step.lmRob, c(list(lmRob.fit), step.args))
+      lmRob.fit <- do.call("lmRob", c(list(fm.formula,data=quote(reg.xts)),lmRob.args))
+      reg.list[[i]] <- do.call("step.lmRob", c(list(lmRob.fit),step.args))
     } 
   }
   reg.list
@@ -347,7 +346,7 @@
     }
     
     # choose best subset of factors depending on specified subset size
-    fm.subsets <- do.call(regsubsets, c(list(fm.formula,data=reg.xts), 
+    fm.subsets <- do.call("regsubsets", c(list(fm.formula,data=quote(reg.xts)), 
                                         regsubsets.args))
     sum.sub <- summary(fm.subsets)
     
@@ -363,13 +362,12 @@
     
     # fit based on time series regression method chosen
     if (fit.method == "LS") {
-      reg.list[[i]] <- do.call(lm, c(list(fm.formula,data=reg.xts),lm.args))
+      reg.list[[i]] <- do.call("lm", c(list(fm.formula,data=quote(reg.xts)),lm.args))
     } else if (fit.method == "DLS") {
       lm.args$weights <- WeightsDLS(nrow(reg.xts), decay)
-      reg.list[[i]] <- do.call(lm, c(list(fm.formula,data=reg.xts),lm.args))
+      reg.list[[i]] <- do.call("lm", c(list(fm.formula,data=quote(reg.xts)),lm.args))
     } else if (fit.method == "Robust") {
-      reg.list[[i]] <- do.call(lmRob, c(list(fm.formula,data=reg.xts), 
-                                        lmRob.args))
+      reg.list[[i]] <- do.call("lmRob", c(list(fm.formula,data=quote(reg.xts)),lmRob.args))
     } 
   }
   reg.list
@@ -399,9 +397,9 @@
     xmat <- as.matrix(reg.xts[,factor.names])
     yvec <- as.matrix(reg.xts)[,i]
     # fit lars regression model
-    lars.fit <- do.call(lars, c(list(x=xmat, y=yvec),lars.args))
+    lars.fit <- do.call("lars", c(list(x=quote(xmat),y=quote(yvec)),lars.args))
     lars.sum <- summary(lars.fit)
-    lars.cv <- do.call(cv.lars, c(list(x=xmat,y=yvec,mode="step"),cv.lars.args))
+    lars.cv <- do.call("cv.lars", c(list(x=quote(xmat),y=quote(yvec),mode="step"),cv.lars.args))
     
     # get the step that minimizes the "Cp" statistic or 
     # the K-fold "cv" mean-squared prediction error
@@ -428,7 +426,7 @@
     # according to summary.lars help files, $df is tricky for some models
   }
   if (length(asset.names)>1) {
-    fitted.xts <- do.call(merge, fitted.list) 
+    fitted.xts <- do.call("merge", fitted.list) 
   } else {
     fitted.xts <- fitted.list[[1]]
   }
@@ -454,7 +452,7 @@
 ## l = list of unequal vectors
 #
 makePaddedDataFrame <- function(l) {
-  DF <- do.call(rbind, lapply(lapply(l, unlist), "[", 
+  DF <- do.call("rbind", lapply(lapply(l, unlist), "[", 
                               unique(unlist(c(sapply(l,names))))))
   DF <- as.data.frame(DF)
   names(DF) <- unique(unlist(c(sapply(l,names))))
@@ -494,7 +492,7 @@
                            function(x) checkData(fitted(x)))
       # this is a list of xts objects, indexed by the asset name
       # merge the objects in the list into one xts object
-      fitted.xts <- do.call(merge, fitted.list) 
+      fitted.xts <- do.call("merge", fitted.list) 
     } else {
       fitted.xts <- checkData(fitted(object$asset.fit[[1]]))
       colnames(fitted.xts) <- object$asset.names
@@ -522,7 +520,7 @@
                               function(x) checkData(residuals(x)))
       # this is a list of xts objects, indexed by the asset name
       # merge the objects in the list into one xts object
-      residuals.xts <- do.call(merge, residuals.list) 
+      residuals.xts <- do.call("merge", residuals.list) 
     } else {
       residuals.xts <- checkData(residuals(object$asset.fit[[1]]))
       colnames(residuals.xts) <- object$asset.names

Modified: pkg/FactorAnalytics/R/fitTsfm.control.R
===================================================================
--- pkg/FactorAnalytics/R/fitTsfm.control.R	2015-08-31 21:52:27 UTC (rev 3992)
+++ pkg/FactorAnalytics/R/fitTsfm.control.R	2015-09-14 23:00:02 UTC (rev 3993)
@@ -162,41 +162,41 @@
   
   # check input validity for some of the arguments
   if (decay<=0 || decay>1) {
-    stop("Invalid argument: Decay factor should be in (0,1]")
+    stop("Invalid args: Decay factor should be in (0,1]")
   }
   if (!is.logical(model) || length(model) != 1) {
-    stop("Invalid argument: control parameter 'model' must be logical")
+    stop("Invalid args: control parameter 'model' must be logical")
   }
   if (!is.logical(x) || length(x) != 1) {
-    stop("Invalid argument: control parameter 'x' must be logical")
+    stop("Invalid args: control parameter 'x' must be logical")
   }
   if (!is.logical(y) || length(y) != 1) {
-    stop("Invalid argument: control parameter 'y' must be logical")
+    stop("Invalid args: control parameter 'y' must be logical")
   }
   if (!is.logical(qr) || length(qr) != 1) {
-    stop("Invalid argument: control parameter 'qr' must be logical")
+    stop("Invalid args: control parameter 'qr' must be logical")
   }
   if (!is.logical(really.big) || length(really.big) != 1) {
-    stop("Invalid argument: control parameter 'really.big' must be logical")
+    stop("Invalid args: control parameter 'really.big' must be logical")
   }
   if (!is.logical(normalize) || length(normalize) != 1) {
-    stop("Invalid argument: control parameter 'normalize' must be logical")
+    stop("Invalid args: control parameter 'normalize' must be logical")
   }
   if (!is.logical(plot.it) || length(plot.it) != 1) {
-    stop("Invalid argument: control parameter 'plot.it' must be logical")
+    stop("Invalid args: control parameter 'plot.it' must be logical")
   }
   if (nvmin <= 0 || round(nvmin) != nvmin) {
     stop("Control parameter 'nvmin' must be a positive integer")
   }
   if (nvmax < nvmin || nvmin < length(force.in)) {
-    stop("Invaid Argument: nvmax should be >= nvmin and nvmin 
+    stop("Invaid args: nvmax should be >= nvmin and nvmin 
            should be >= length(force.in)")
   }
   if (!is.logical(normalize) || length(normalize) != 1) {
-    stop("Invalid argument: control parameter 'normalize' must be logical")
+    stop("Invalid args: control parameter 'normalize' must be logical")
   }
   if (!(lars.criterion %in% c("Cp","cv"))) {
-    stop("Invalid argument: lars.criterion must be 'Cp' or 'cv'.")
+    stop("Invalid args: lars.criterion must be 'Cp' or 'cv'.")
   }
   
   # return list of arguments with defaults if they are unspecified

Modified: pkg/FactorAnalytics/man/Stock.df.Rd
===================================================================
--- pkg/FactorAnalytics/man/Stock.df.Rd	2015-08-31 21:52:27 UTC (rev 3992)
+++ pkg/FactorAnalytics/man/Stock.df.Rd	2015-09-14 23:00:02 UTC (rev 3993)
@@ -1,21 +1,32 @@
-\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
-  2003-12-31.
-}
-\details{
-  Continuous data: PRICE, RETURN, TICKER, VOLUME, SHARES.OUT,
-  MARKET.EQUITY,LTDEBT, NET.SALES, COMMON.EQUITY,
-  NET.INCOME, STOCKHOLDERS.EQUITY, LOG.MARKETCAP,
-  LOG.PRICE, BOOK2MARKET Categorical data: GICS,
-  GICS.INDUSTRY, GICS.SECTOR
-}
-\references{
-  Guy Yullen and Yi-An Chen
-}
-\keyword{datasets}
-
+\docType{data}
+\name{Stock.df}
+\alias{Stock.df}
+\alias{stock}
+\title{Fundamental and return data for 447 NYSE stocks}
+\description{
+  Fundamental and return data:
+  Assets: 447 stocks listed on the NYSE 
+  Frequency: Monthly 
+  Date range: 1996-02-29 through 2003-12-31
+}
+\details{
+  ID variables: DATE, TICKER
+  
+  Continuous variables: RETURN, PRICE, VOLUME, SHARES.OUT, MARKET.EQUITY, 
+  LTDEBT, NET.SALES, COMMON.EQUITY, NET.INCOME, STOCKHOLDERS.EQUITY, 
+  LOG.MARKETCAP, LOG.PRICE, BOOK2MARKET 
+  
+  Categorical variables: GICS, GICS.INDUSTRY, GICS.SECTOR
+}
+\usage{
+data(Stock.df)
+}
+\format{
+data.frame
+}
+\examples{
+data(Stock.df)
+str(stock)
+}
+\keyword{datasets}
+\keyword{data.frame}



More information about the Returnanalytics-commits mailing list