[Returnanalytics-commits] r3564 - / pkg/FactorAnalytics pkg/FactorAnalytics/R pkg/FactorAnalytics/man pkg/FactorAnalytics/vignettes

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Tue Dec 2 07:42:48 CET 2014


Author: pragnya
Date: 2014-12-02 07:42:48 +0100 (Tue, 02 Dec 2014)
New Revision: 3564

Added:
   returnanalytics.Rproj
Modified:
   pkg/FactorAnalytics/DESCRIPTION
   pkg/FactorAnalytics/R/fitTsfm.R
   pkg/FactorAnalytics/R/fmEsDecomp.R
   pkg/FactorAnalytics/R/plot.tsfm.r
   pkg/FactorAnalytics/R/print.tsfm.r
   pkg/FactorAnalytics/R/summary.tsfm.r
   pkg/FactorAnalytics/man/fitSfm.Rd
   pkg/FactorAnalytics/man/fitTsfm.Rd
   pkg/FactorAnalytics/man/fmEsDecomp.Rd
   pkg/FactorAnalytics/man/plot.tsfm.Rd
   pkg/FactorAnalytics/man/summary.tsfm.Rd
   pkg/FactorAnalytics/vignettes/FA.bib
   pkg/FactorAnalytics/vignettes/fitTsfm_vignette.R
   pkg/FactorAnalytics/vignettes/fitTsfm_vignette.Rnw
   pkg/FactorAnalytics/vignettes/fitTsfm_vignette.pdf
Log:
Minor edits to fitTsfm print, plot, summary and vignette

Modified: pkg/FactorAnalytics/DESCRIPTION
===================================================================
--- pkg/FactorAnalytics/DESCRIPTION	2014-11-25 23:37:06 UTC (rev 3563)
+++ pkg/FactorAnalytics/DESCRIPTION	2014-12-02 06:42:48 UTC (rev 3564)
@@ -1,9 +1,9 @@
 Package: factorAnalytics
 Type: Package
 Title: Factor Analytics
-Version: 2.0.2
-Date: 2014-11-23
-Author: Eric Zivot, Yi-An Chen and Sangeetha Srinivasan
+Version: 2.0.3
+Date: 2014-12-01
+Author: Eric Zivot, Sangeetha Srinivasan and Yi-An Chen
 Maintainer: Sangeetha Srinivasan <sangee at uw.edu>
 Description: An R package for the estimation and risk analysis of linear factor
     models for asset returns and portfolios. It contains model fitting methods

Modified: pkg/FactorAnalytics/R/fitTsfm.R
===================================================================
--- pkg/FactorAnalytics/R/fitTsfm.R	2014-11-25 23:37:06 UTC (rev 3563)
+++ pkg/FactorAnalytics/R/fitTsfm.R	2014-12-02 06:42:48 UTC (rev 3564)
@@ -17,31 +17,35 @@
 #' squares with exponentially declining weights that sum to unity), and, 
 #' "Robust" is robust regression (using \code{\link[robust]{lmRob}}). 
 #' 
-#' If \code{variable.selection="none"}, all chosen factors are used in the 
-#' factor model. Whereas, "stepwise" performs traditional forward/backward 
-#' stepwise OLS regression (using \code{\link[stats]{step}} or 
+#' If \code{variable.selection="none"}, uses all the factors and performs no 
+#' variable selection. Whereas, "stepwise" performs traditional stepwise 
+#' LS or Robust regression (using \code{\link[stats]{step}} or 
 #' \code{\link[robust]{step.lmRob}}), that starts from the initial set of 
-#' factors and adds factors only if the regression fit, as measured by the 
-#' Bayesian Information Criterion (BIC) or Akaike Information Criterion (AIC), 
-#' improves. And, "subsets" enables subsets selection using 
+#' factors and adds/subtracts factors only if the regression fit, as measured 
+#' by the Bayesian Information Criterion (BIC) or Akaike Information Criterion 
+#' (AIC), improves. And, "subsets" enables subsets selection using 
 #' \code{\link[leaps]{regsubsets}}; chooses the best performing subset of any 
-#' given size or within a range of subset sizes. See 
-#' \code{\link{fitTsfm.control}} for more details on the control arguments. 
+#' given size or within a range of subset sizes. Different methods such as 
+#' exhaustive search (default), forward or backward stepwise, or sequential 
+#' replacement can be employed.See \code{\link{fitTsfm.control}} for more 
+#' details on the control arguments.
+#'  
 #' \code{variable.selection="lars"} corresponds to least angle regression 
-#' using \code{\link[lars]{lars}} with variants "lasso", "lar", "stepwise" or 
-#' "forward.stagewise". Note: If \code{variable.selection="lars"}, 
+#' using \code{\link[lars]{lars}} with variants "lasso" (default), "lar", 
+#' "stepwise" or "forward.stagewise". Note: If \code{variable.selection="lars"}, 
 #' \code{fit.method} will be ignored.
 #' 
 #' Arguments \code{mkt.name} and \code{mkt.timing} allow for market-timing 
 #' factors to be added to any of the above methods. Market timing accounts for 
 #' the price movement of the general stock market relative to fixed income 
-#' securities. "HM" follows Henriksson & Merton (1981) and 
-#' \code{up.market=max(0,Rm-Rf)}, is added to the regression. The coefficient 
-#' of this up-market factor can be interpreted as the number of free put 
-#' options. Similarly, "TM" follows Treynor-Mazuy (1966), to account for market
-#' timing with respect to volatility, and \code{market.sqd=(Rm-Rf)^2} is added
-#' as a factor in the regression. Option "both" (default) adds both of these 
-#' factors.
+#' securities. Specifying \code{mkt.timing="HM"}, includes 
+#' $up.market = max(0, R_m-R_f)$ as a factor, followinhg Henriksson & Merton 
+#' (1981). The coefficient of this up-market factor can be interpreted as the 
+#' number of free put options. Similarly, to account for market timing with 
+#' respect to volatility, one can specify \code{mkt.timing="TM"}. Following 
+#' \citet{treynor1966can}, $market.sqd = (R_m-R_f)^2$ is added as a factor. To 
+#' include both these market-timing factors in the model, one can specify 
+#' \code{mkt.timing=c("HM","TM")}. 
 #' 
 #' \subsection{Data Processing}{
 #' 
@@ -70,7 +74,7 @@
 #' See details. Default is "OLS". 
 #' @param variable.selection the variable selection method, one of "none", 
 #' "stepwise","subsets","lars". See details. Default is "none".
-#' @param mkt.timing one of "HM", "TM" or "both" (default). See Details.
+#' @param mkt.timing one of "HM", "TM" or "both". See Details. Default is NULL.
 #' \code{mkt.name} is required if any of these options are to be implemented.
 #' @param control list of control parameters. The default is constructed by 
 #' the function \code{\link{fitTsfm.control}}. See the documentation for 
@@ -177,7 +181,7 @@
 fitTsfm <- function(asset.names, factor.names, mkt.name=NULL, rf.name=NULL, 
                     data=data, fit.method=c("OLS","DLS","Robust"), 
                     variable.selection=c("none","stepwise","subsets","lars"), 
-                    mkt.timing="both", control=fitTsfm.control(...), ...) {
+                    mkt.timing=NULL, control=fitTsfm.control(...), ...) {
   
   # record the call as an element to be returned
   call <- match.call()
@@ -196,6 +200,10 @@
     factor.names <- NULL
   }
   
+  if (is.null(mkt.name) && !is.null(mkt.timing)) {
+    stop("Missing argument: mkt.name is necessary to add market timing factors")
+  }
+  
   # extract arguments to pass to different fit and variable selection functions
   decay <- control$decay
   nvmin <- control$nvmin
@@ -237,21 +245,19 @@
   }
   
   # opt add mkt-timing factors: up.market=max(0,Rm-Rf), market.sqd=(Rm-Rf)^2
-  if (!is.null(mkt.name)) {
-    if(mkt.timing=="HM" || mkt.timing=="both") {
-      up.market <- data.xts[,mkt.name]
-      up.market [up.market < 0] <- 0
-      dat.xts <- merge.xts(dat.xts,up.market)
-      colnames(dat.xts)[dim(dat.xts)[2]] <- "up.market"
-      factor.names <- c(factor.names, "up.market")
-    }
-    if(mkt.timing=="TM" || mkt.timing=="both") {
-      market.sqd <- data.xts[,mkt.name]^2   
-      dat.xts <- merge(dat.xts, market.sqd)
-      colnames(dat.xts)[dim(dat.xts)[2]] <- "market.sqd"
-      factor.names <- c(factor.names, "market.sqd")
-    }
+  if("HM" %in% mkt.timing) {
+    up.market <- data.xts[,mkt.name]
+    up.market [up.market < 0] <- 0
+    dat.xts <- merge.xts(dat.xts,up.market)
+    colnames(dat.xts)[dim(dat.xts)[2]] <- "up.market"
+    factor.names <- c(factor.names, "up.market")
   }
+  if("TM" %in% mkt.timing) {
+    market.sqd <- data.xts[,mkt.name]^2   
+    dat.xts <- merge(dat.xts, market.sqd)
+    colnames(dat.xts)[dim(dat.xts)[2]] <- "market.sqd"
+    factor.names <- c(factor.names, "market.sqd")
+  }
   
   # spaces get converted to periods in colnames of xts object after merge
   asset.names <- gsub(" ",".", asset.names, fixed=TRUE)

Modified: pkg/FactorAnalytics/R/fmEsDecomp.R
===================================================================
--- pkg/FactorAnalytics/R/fmEsDecomp.R	2014-11-25 23:37:06 UTC (rev 3563)
+++ pkg/FactorAnalytics/R/fmEsDecomp.R	2014-12-02 06:42:48 UTC (rev 3564)
@@ -35,11 +35,10 @@
 #' \code{\link[PerformanceAnalytics]{VaR}}.
 #' 
 #' @return A list containing 
-#' \item{VaR.fm}{length-N vector of factor model VaRs of N-asset returns.}
+#' \item{ES.fm}{length-N vector of factor model ES of N-asset returns.}
 #' \item{n.exceed}{length-N vector of number of observations beyond VaR for 
 #' each asset.}
 #' \item{idx.exceed}{list of numeric vector of index values of exceedances.}
-#' \item{ES.fm}{length-N vector of factor model ES of N-asset returns.}
 #' \item{mES}{N x (K+1) matrix of marginal contributions to VaR.}
 #' \item{cES}{N x (K+1) matrix of component contributions to VaR.}
 #' \item{pcES}{N x (K+1) matrix of percentage component contributions to VaR.}
@@ -173,8 +172,8 @@
     pcES[i,] <- 100* cES[i,] / ES.fm[i]
   }
   
-  fm.ES.decomp <- list(VaR.fm=VaR.fm, n.exceed=n.exceed, idx.exceed=idx.exceed, 
-                       ES.fm=ES.fm, mES=mES, cES=cES, pcES=pcES)
+  fm.ES.decomp <- list(ES.fm=ES.fm, n.exceed=n.exceed, idx.exceed=idx.exceed, 
+                       mES=mES, cES=cES, pcES=pcES)
   
   return(fm.ES.decomp)
 }
@@ -258,8 +257,8 @@
     pcES[i,] <- 100* cES[i,] / ES.fm[i]
   }
   
-  fm.ES.decomp <- list(VaR.fm=VaR.fm, n.exceed=n.exceed, idx.exceed=idx.exceed, 
-                       ES.fm=ES.fm, mES=mES, cES=cES, pcES=pcES)
+  fm.ES.decomp <- list(ES.fm=ES.fm, n.exceed=n.exceed, idx.exceed=idx.exceed, 
+                       mES=mES, cES=cES, pcES=pcES)
   
   return(fm.ES.decomp)
 }

Modified: pkg/FactorAnalytics/R/plot.tsfm.r
===================================================================
--- pkg/FactorAnalytics/R/plot.tsfm.r	2014-11-25 23:37:06 UTC (rev 3563)
+++ pkg/FactorAnalytics/R/plot.tsfm.r	2014-12-02 06:42:48 UTC (rev 3564)
@@ -14,7 +14,7 @@
 #' For group plots (the default), the first \code{max.show} assets are plotted.
 #' For individual plots, \code{asset.name} is necessary if multiple assets 
 #' were modeled in \code{x} and \code{plot.single=TRUE}. However, if the 
-#' \code{fitTsfm} object \code{x} only contains one asset's factor model fit, 
+#' \code{fitTsfm} object contains only one asset's factor model fit, 
 #' \code{plot.tsfm} can infer this automatically, without user input. 
 #' 
 #' CUSUM plots (individual asset plot options 10, 11 and 12) are applicable 

Modified: pkg/FactorAnalytics/R/print.tsfm.r
===================================================================
--- pkg/FactorAnalytics/R/print.tsfm.r	2014-11-25 23:37:06 UTC (rev 3563)
+++ pkg/FactorAnalytics/R/print.tsfm.r	2014-12-02 06:42:48 UTC (rev 3564)
@@ -36,7 +36,9 @@
   cat("\nRegression Alphas:\n")
   print(t(x$alpha), digits=digits, ...)
   cat("\nFactor Betas:\n")
-  print(x$beta, digits=digits, ...)
+  B <- as.matrix(t(x$beta))
+  if (x$variable.selection=="lars") { B[B==0] <- NA }
+  print(B, digits=digits, na.print="-", ...)
   cat("\nR-squared values:\n")
   print(x$r2, digits=digits, ...)
   cat("\nResidual Volatilities:\n")

Modified: pkg/FactorAnalytics/R/summary.tsfm.r
===================================================================
--- pkg/FactorAnalytics/R/summary.tsfm.r	2014-11-25 23:37:06 UTC (rev 3563)
+++ pkg/FactorAnalytics/R/summary.tsfm.r	2014-12-02 06:42:48 UTC (rev 3564)
@@ -9,8 +9,11 @@
 #' heteroskedasticity-consistent (HC) or 
 #' heteroskedasticity-autocorrelation-consistent (HAC) standard errors and 
 #' t-statistics using \code{\link[lmtest]{coeftest}}. This option is meaningful 
-#' only if \code{fit.method = "OLS" or "DLS"}. HC/HAC errors are currently not 
-#' available for \code{variable.selection = "lars"}.
+#' only if \code{fit.method = "OLS" or "DLS"}.
+#' Standard errors are currently not available for 
+#' \code{variable.selection="lars"} as there seems to be no consensus on a 
+#' statistically valid method of calculating standard errors for the lasso 
+#' predictions.
 #'  
 #' @param object an object of class \code{tsfm} returned by \code{fitTsfm}.
 #' @param se.type one of "Default", "HC" or "HAC"; option for computing 
@@ -65,7 +68,7 @@
     stop("Invalid 'tsfm' object")
   }
   # note: fit.method=NULL for "lars" objects
-  if (!(object$fit.method %in% c("OLS","DLS")) && se.type!="Default") {
+  if (object$fit.method=="Robust" && se.type!="Default") {
     stop("Invalid argument: HC/HAC standard errors are applicable only if 
          fit.method = 'OLS' or 'DLS'")
   }
@@ -117,11 +120,15 @@
   n <- length(x)
   for (i in 3:n) {
     options(digits = digits)  
-    cat("\nAsset", i-2, ": ", names(x[i]), "\n(",x$se.type,
-        " Standard Errors & T-stats)\n\n", sep = "")  
+    if (dim(x[[i]]$coefficients)[2] > 1) {
+      cat("\nAsset", i-2, ": ", names(x[i]), "\n(", x$se.type, 
+          " Standard Errors & T-stats)\n\n", sep="")  
+    } else {
+      cat("\nAsset", i-2, ": ", names(x[i]), "\n\n", sep="")  
+    }
     table.coef <- x[[i]]$coefficients
-    print(table.coef, digits = digits, ...)
+    printCoefmat(table.coef, digits=digits, ...)
     cat("\nR-squared: ", x[[i]]$r.squared,", Residual Volatility: "
-        , x[[i]]$sigma,"\n", sep = "")
+        , x[[i]]$sigma,"\n", sep="")
   }
 }

Modified: pkg/FactorAnalytics/man/fitSfm.Rd
===================================================================
--- pkg/FactorAnalytics/man/fitSfm.Rd	2014-11-25 23:37:06 UTC (rev 3563)
+++ pkg/FactorAnalytics/man/fitSfm.Rd	2014-12-02 06:42:48 UTC (rev 3564)
@@ -118,23 +118,23 @@
 
 # pca
 args(fitSfm)
-sfm.pca.fit <- fitSfm(sfm.dat, k=2)
-class(sfm.pca.fit)
-names(sfm.pca.fit)
-head(sfm.pca.fit$factors)
-head(sfm.pca.fit$loadings)
-sfm.pca.fit$r2
-sfm.pca.fit$resid.sd
-sfm.pca.fit$mimic
+fit.pca <- fitSfm(sfm.dat, k=2)
+class(fit.pca)
+names(fit.pca)
+head(fit.pca$factors)
+head(fit.pca$loadings)
+fit.pca$r2
+fit.pca$resid.sd
+fit.pca$mimic
 
 # apca with number of factors, k=15
-sfm.apca.fit <- fitSfm(sfm.apca.dat, k=15, refine=TRUE)
+fit.apca <- fitSfm(sfm.apca.dat, k=15, refine=TRUE)
 
 # apca with the Bai & Ng method
-sfm.apca.fit.bn <- fitSfm(sfm.apca.dat, k="bn")
+fit.apca.bn <- fitSfm(sfm.apca.dat, k="bn")
 
 # apca with the Connor-Korajczyk method
-sfm.apca.fit.ck <- fitSfm(sfm.apca.dat, k="ck")
+fit.apca.ck <- fitSfm(sfm.apca.dat, k="ck")
 }
 \author{
 Eric Zivot, Sangeetha Srinivasan and Yi-An Chen

Modified: pkg/FactorAnalytics/man/fitTsfm.Rd
===================================================================
--- pkg/FactorAnalytics/man/fitTsfm.Rd	2014-11-25 23:37:06 UTC (rev 3563)
+++ pkg/FactorAnalytics/man/fitTsfm.Rd	2014-12-02 06:42:48 UTC (rev 3564)
@@ -9,7 +9,7 @@
 fitTsfm(asset.names, factor.names, mkt.name = NULL, rf.name = NULL,
   data = data, fit.method = c("OLS", "DLS", "Robust"),
   variable.selection = c("none", "stepwise", "subsets", "lars"),
-  mkt.timing = "both", control = fitTsfm.control(...), ...)
+  mkt.timing = NULL, control = fitTsfm.control(...), ...)
 
 \method{coef}{tsfm}(object, ...)
 
@@ -40,7 +40,7 @@
 \item{variable.selection}{the variable selection method, one of "none",
 "stepwise","subsets","lars". See details. Default is "none".}
 
-\item{mkt.timing}{one of "HM", "TM" or "both" (default). See Details.
+\item{mkt.timing}{one of "HM", "TM" or "both". See Details. Default is NULL.
 \code{mkt.name} is required if any of these options are to be implemented.}
 
 \item{control}{list of control parameters. The default is constructed by
@@ -100,31 +100,35 @@
 squares with exponentially declining weights that sum to unity), and,
 "Robust" is robust regression (using \code{\link[robust]{lmRob}}).
 
-If \code{variable.selection="none"}, all chosen factors are used in the
-factor model. Whereas, "stepwise" performs traditional forward/backward
-stepwise OLS regression (using \code{\link[stats]{step}} or
+If \code{variable.selection="none"}, uses all the factors and performs no
+variable selection. Whereas, "stepwise" performs traditional stepwise
+LS or Robust regression (using \code{\link[stats]{step}} or
 \code{\link[robust]{step.lmRob}}), that starts from the initial set of
-factors and adds factors only if the regression fit, as measured by the
-Bayesian Information Criterion (BIC) or Akaike Information Criterion (AIC),
-improves. And, "subsets" enables subsets selection using
+factors and adds/subtracts factors only if the regression fit, as measured
+by the Bayesian Information Criterion (BIC) or Akaike Information Criterion
+(AIC), improves. And, "subsets" enables subsets selection using
 \code{\link[leaps]{regsubsets}}; chooses the best performing subset of any
-given size or within a range of subset sizes. See
-\code{\link{fitTsfm.control}} for more details on the control arguments.
+given size or within a range of subset sizes. Different methods such as
+exhaustive search (default), forward or backward stepwise, or sequential
+replacement can be employed.See \code{\link{fitTsfm.control}} for more
+details on the control arguments.
+
 \code{variable.selection="lars"} corresponds to least angle regression
-using \code{\link[lars]{lars}} with variants "lasso", "lar", "stepwise" or
-"forward.stagewise". Note: If \code{variable.selection="lars"},
+using \code{\link[lars]{lars}} with variants "lasso" (default), "lar",
+"stepwise" or "forward.stagewise". Note: If \code{variable.selection="lars"},
 \code{fit.method} will be ignored.
 
 Arguments \code{mkt.name} and \code{mkt.timing} allow for market-timing
 factors to be added to any of the above methods. Market timing accounts for
 the price movement of the general stock market relative to fixed income
-securities. "HM" follows Henriksson & Merton (1981) and
-\code{up.market=max(0,Rm-Rf)}, is added to the regression. The coefficient
-of this up-market factor can be interpreted as the number of free put
-options. Similarly, "TM" follows Treynor-Mazuy (1966), to account for market
-timing with respect to volatility, and \code{market.sqd=(Rm-Rf)^2} is added
-as a factor in the regression. Option "both" (default) adds both of these
-factors.
+securities. Specifying \code{mkt.timing="HM"}, includes
+$up.market = max(0, R_m-R_f)$ as a factor, followinhg Henriksson & Merton
+(1981). The coefficient of this up-market factor can be interpreted as the
+number of free put options. Similarly, to account for market timing with
+respect to volatility, one can specify \code{mkt.timing="TM"}. Following
+\citet{treynor1966can}, $market.sqd = (R_m-R_f)^2$ is added as a factor. To
+include both these market-timing factors in the model, one can specify
+\code{mkt.timing=c("HM","TM")}.
 
 \subsection{Data Processing}{
 

Modified: pkg/FactorAnalytics/man/fmEsDecomp.Rd
===================================================================
--- pkg/FactorAnalytics/man/fmEsDecomp.Rd	2014-11-25 23:37:06 UTC (rev 3563)
+++ pkg/FactorAnalytics/man/fmEsDecomp.Rd	2014-12-02 06:42:48 UTC (rev 3564)
@@ -29,11 +29,10 @@
 }
 \value{
 A list containing
-\item{VaR.fm}{length-N vector of factor model VaRs of N-asset returns.}
+\item{ES.fm}{length-N vector of factor model ES of N-asset returns.}
 \item{n.exceed}{length-N vector of number of observations beyond VaR for
 each asset.}
 \item{idx.exceed}{list of numeric vector of index values of exceedances.}
-\item{ES.fm}{length-N vector of factor model ES of N-asset returns.}
 \item{mES}{N x (K+1) matrix of marginal contributions to VaR.}
 \item{cES}{N x (K+1) matrix of component contributions to VaR.}
 \item{pcES}{N x (K+1) matrix of percentage component contributions to VaR.}

Modified: pkg/FactorAnalytics/man/plot.tsfm.Rd
===================================================================
--- pkg/FactorAnalytics/man/plot.tsfm.Rd	2014-11-25 23:37:06 UTC (rev 3563)
+++ pkg/FactorAnalytics/man/plot.tsfm.Rd	2014-12-02 06:42:48 UTC (rev 3564)
@@ -87,7 +87,7 @@
 For group plots (the default), the first \code{max.show} assets are plotted.
 For individual plots, \code{asset.name} is necessary if multiple assets
 were modeled in \code{x} and \code{plot.single=TRUE}. However, if the
-\code{fitTsfm} object \code{x} only contains one asset's factor model fit,
+\code{fitTsfm} object contains only one asset's factor model fit,
 \code{plot.tsfm} can infer this automatically, without user input.
 
 CUSUM plots (individual asset plot options 10, 11 and 12) are applicable

Modified: pkg/FactorAnalytics/man/summary.tsfm.Rd
===================================================================
--- pkg/FactorAnalytics/man/summary.tsfm.Rd	2014-11-25 23:37:06 UTC (rev 3563)
+++ pkg/FactorAnalytics/man/summary.tsfm.Rd	2014-12-02 06:42:48 UTC (rev 3564)
@@ -44,8 +44,11 @@
 heteroskedasticity-consistent (HC) or
 heteroskedasticity-autocorrelation-consistent (HAC) standard errors and
 t-statistics using \code{\link[lmtest]{coeftest}}. This option is meaningful
-only if \code{fit.method = "OLS" or "DLS"}. HC/HAC errors are currently not
-available for \code{variable.selection = "lars"}.
+only if \code{fit.method = "OLS" or "DLS"}.
+Standard errors are currently not available for
+\code{variable.selection="lars"} as there seems to be no consensus on a
+statistically valid method of calculating standard errors for the lasso
+predictions.
 }
 \note{
 For a more detailed printed summary for each asset, refer to

Modified: pkg/FactorAnalytics/vignettes/FA.bib
===================================================================
--- pkg/FactorAnalytics/vignettes/FA.bib	2014-11-25 23:37:06 UTC (rev 3563)
+++ pkg/FactorAnalytics/vignettes/FA.bib	2014-12-02 06:42:48 UTC (rev 3564)
@@ -116,12 +116,15 @@
   publisher={RISK MAGAZINE LIMITED}
 }
 
- at book{sharpe1970portfolio,
-  title={Portfolio theory and capital markets},
-  author={Sharpe, William F and Sharpe, WF},
-  volume={217},
-  year={1970},
-  publisher={McGraw-Hill New York}
+ at article{sharpe1964capital,
+  title={Capital asset prices: A theory of market equilibrium under conditions of risk*},
+  author={Sharpe, William F},
+  journal={The journal of finance},
+  volume={19},
+  number={3},
+  pages={425--442},
+  year={1964},
+  publisher={Wiley Online Library}
 }
 
 @article{treynor1966can,

Modified: pkg/FactorAnalytics/vignettes/fitTsfm_vignette.R
===================================================================
--- pkg/FactorAnalytics/vignettes/fitTsfm_vignette.R	2014-11-25 23:37:06 UTC (rev 3563)
+++ pkg/FactorAnalytics/vignettes/fitTsfm_vignette.R	2014-12-02 06:42:48 UTC (rev 3564)
@@ -1,6 +1,7 @@
 
 ## ----message=FALSE-------------------------------------------------------
 library(factorAnalytics)
+options(digits=3)
 
 
 ## ------------------------------------------------------------------------
@@ -27,66 +28,77 @@
 
 
 ## ------------------------------------------------------------------------
-fit.Sharpe <- fitTsfm(asset.names=asset.names, factor.names="SP500 TR", 
-                      rf.name="US 3m TR", data=managers)
-names(fit.Sharpe)
-fit.Sharpe
+# Single Index Model using SP500
+fit.singleIndex <- fitTsfm(asset.names=asset.names, factor.names="SP500 TR", 
+                           rf.name="US 3m TR", data=managers)
 
 
 ## ------------------------------------------------------------------------
-# adding up-market timing factor ("HM") to the model 
-fit1 <- fitTsfm(asset.names=asset.names, factor.names=factor.names, 
-                mkt.name="SP500 TR", mkt.timing="HM", data=managers)
-fit1$beta
-fit1$r2
-fit1$resid.sd
+class(fit.singleIndex)
+names(fit.singleIndex)
 
 
 ## ------------------------------------------------------------------------
-fit2 <- fitTsfm(asset.names=asset.names, factor.names=factor.names, 
-                mkt.name="SP500 TR", data=managers, fit.method="Robust")
-fit2$beta
-fit2$r2
-fit2$resid.sd
+fit.singleIndex # print the fitted "tsfm" object
 
 
-## ----fig.cap="HAM3 Returns: fit1-OLS (top) vs fit2-Robust (bottom)", fig.show='hold'----
+## ------------------------------------------------------------------------
+# Henriksson-Merton's market timing model
+fit.mktTiming <- fitTsfm(asset.names=asset.names, rf.name="US 3m TR", 
+                         mkt.name="SP500 TR", mkt.timing="HM", data=managers)
+fit.mktTiming
+
+
+## ------------------------------------------------------------------------
+fit.ols <- fitTsfm(asset.names=asset.names, factor.names=factor.names, 
+                    rf.name="US 3m TR", data=managers)
+fit.ols$beta
+fit.ols$r2
+fit.ols$resid.sd
+
+
+## ------------------------------------------------------------------------
+fit.robust <- fitTsfm(asset.names=asset.names, factor.names=factor.names, 
+                       rf.name="US 3m TR", data=managers, fit.method="Robust")
+fit.robust$beta
+fit.robust$r2
+fit.robust$resid.sd
+
+
+## ----fig.cap="HAM3 Returns: OLS (top) vs Robust (bottom)", fig.show='hold'----
 par(mfrow=c(2,1))
-plot(fit1, plot.single=TRUE, which.plot.single=1, asset.name="HAM3", loop=FALSE)
-plot(fit2, plot.single=TRUE, which.plot.single=1, asset.name="HAM3", loop=FALSE)
+plot(fit.ols, plot.single=TRUE, which.plot.single=1, asset.name="HAM3", loop=FALSE)
+mtext("OLS", side=3)
+plot(fit.robust, plot.single=TRUE, which.plot.single=1, asset.name="HAM3", loop=FALSE)
+mtext("Robust", side=3)
 
 
-## ----fig.cap="Residual vol: fit1-OLS (left) vs fit2-Robust (right)", fig.width=3, fig.height=2.5, out.width='.49\\linewidth', fig.show='hold'----
+## ----fig.cap="Residual vol: OLS (left) vs Robust (right)", fig.width=3, fig.height=2.5, out.width='.49\\linewidth', fig.show='hold'----
 par(mfrow=c(1,2))
-plot(fit1, which.plot.group=5, loop=FALSE, xlim=c(0,0.043))
-plot(fit2, which.plot.group=5, loop=FALSE, xlim=c(0,0.043))
+plot(fit.ols, which.plot.group=5, loop=FALSE, xlim=c(0,0.043), sub="OLS")
+plot(fit.robust, which.plot.group=5, loop=FALSE, xlim=c(0,0.043), sub="Robust")
 
 
-## ------------------------------------------------------------------------
-fit.lars <- fitTsfm(asset.names=colnames(managers[,(1:6)]), 
-                    factor.names=colnames(managers[,(7:9)]), data=managers, 
-                    rf.name="US 3m TR", mkt.name="SP500 TR")
-fit.lars$beta
-fit.lars$r2
+## ----fig.show='hide'-----------------------------------------------------
+fit.lars <- fitTsfm(asset.names=asset.names, factor.names=factor.names, 
+                    data=managers, rf.name="US 3m TR", 
+                    variable.selection="lars")
+fit.lars
 
-fit.sub <- fitTsfm(asset.names=colnames(managers[,(1:6)]), 
-                   factor.names=colnames(managers[,(7:9)]), data=managers, 
-                   rf.name="US 3m TR", mkt.name="SP500 TR", 
-                   variable.selection="subsets", subset.size=4)
-fit.sub$beta
-fit.sub$r2
 
+## ------------------------------------------------------------------------
+fit.sub <- fitTsfm(asset.names=asset.names, factor.names=factor.names, 
+                   data=managers, rf.name="US 3m TR", 
+                   variable.selection="subsets", nvmin=2, nvmax=2)
+fit.sub
 
-## ----fig.cap="Factor betas: fit.lars", fig.show='hold'-------------------
-plot(fit.lars, which.plot.group=2, loop=FALSE)
 
-
 ## ----fig.cap="Factor betas: fit.sub", fig.show='hold'--------------------
 plot(fit.sub, which.plot.group=2, loop=FALSE)
 
 
-## ----tidy=TRUE-----------------------------------------------------------
-args(fitTsfm.control)
+## ----fig.cap="Factor betas: fit.lars", fig.show='hold'-------------------
+plot(fit.lars, which.plot.group=2, loop=FALSE)
 
 
 ## ------------------------------------------------------------------------
@@ -94,18 +106,19 @@
 
 
 ## ------------------------------------------------------------------------
-coef(fit.sub)
-tail(fitted(fit.sub))
-tail(residuals(fit.sub))
+# all estimated coefficients from the OLS fit using all 3 factors
+coef(fit.ols)
 
-# comparing data, fitted and residual values for HAM1
-tail(merge(fit.sub$data[,1], fitted(fit.sub)[,1], residuals(fit.sub)[,1]))
+# compare returns data with fitted and residual values for HAM1 from fit.lars
+HAM1.ts <- merge(fit.lars$data[,1], fitted(fit.lars)[,1], 
+                      residuals(fit.lars)[,1])
+colnames(HAM1.ts) <- c("HAM1.return","HAM1.fitted","HAM1.residual")
+tail(HAM1.ts)
 
-# printed summary for the time series factor model
+# summary for fit.sub computing HAC standard erros
 summary(fit.sub, se.type="HAC")
 
 
-
 ## ----fig.cap="Factor model return correlation (pairwise complete obs)"----
 fmCov(fit.sub)
 # return correlation plot; Angular Order of the Eigenvectors
@@ -115,6 +128,7 @@
 
 ## ----fig.cap="Percentage factor contribution to SD"----------------------
 decomp <- fmSdDecomp(fit.sub)
+names(decomp)
 # get the factor model standard deviation for all assets
 decomp$Sd.fm
 # get the component contributions to Sd
@@ -128,24 +142,22 @@
 
 
 ## ----fig.cap="Percentage factor contribution to VaR"---------------------
-decomp2 <- fmVaRDecomp(fit.sub)
+decomp1 <- fmVaRDecomp(fit.sub)
+names(decomp1)
 # get the factor model value-at-risk for all assets
-decomp2$VaR.fm
-# get the component contributions to VaR
-decomp2$cVaR
-# get the marginal factor contributions to VaR
-decomp2$mVaR
+decomp1$VaR.fm
 # get the percentage component contributions to VaR
-decomp2$pcVaR
+decomp1$pcVaR
 # plot the percentage component contributions to VaR
 plot(fit.sub, which.plot.group=10, loop=FALSE)
 
 
 ## ----fig.cap="Percentage factor contribution to ES"----------------------
 decomp2 <- fmEsDecomp(fit.sub, method="historical")
+names(decomp2)
 # get the factor model expected shortfall for all assets
 decomp2$ES.fm
-# get the component contributions to ES
+# get the component contributions to Sd
 decomp2$cES
 # get the marginal factor contributions to ES
 decomp2$mES
@@ -156,7 +168,7 @@
 
 
 ## ----eval=FALSE----------------------------------------------------------
-## ## S3 method for class 'tsfm'
+## ## S3 method for class "tsfm"
 ## plot(x, which.plot.group=NULL, max.show=6, plot.single=FALSE, asset.name,
 ##      which.plot.single=NULL, colorset=(1:12), legend.loc="topleft", las=1,
 ##      VaR.method="historical", loop=TRUE, ...)

Modified: pkg/FactorAnalytics/vignettes/fitTsfm_vignette.Rnw
===================================================================
--- pkg/FactorAnalytics/vignettes/fitTsfm_vignette.Rnw	2014-11-25 23:37:06 UTC (rev 3563)
+++ pkg/FactorAnalytics/vignettes/fitTsfm_vignette.Rnw	2014-12-02 06:42:48 UTC (rev 3564)
@@ -33,6 +33,7 @@
 \tableofcontents
 \bigskip
 
+\newpage
 \section{Overview}
 
 \subsection{Load Package}
@@ -52,35 +53,33 @@
 
 \begin{itemize}
 
-\item \verb"fitTsfm(asset.names, factor.names, data, fit.method, variable.selection)": Fits a time series (a.k.a. macroeconomic) factor model for one or more asset returns or excess returns using time series regression. Ordinary least squares-OLS, discounted least squares-DLS and robust regression fitting are possible. Variable selection methods include Step-wise, Subsets and Lars. An object of class \code{"tsfm"} containing the fitted objects, model coefficients, R-squared and residual volatility are returned.
+\item \verb"fitTsfm(asset.names, factor.names, data, fit.method, variable.selection)": Fits a time series (a.k.a. macroeconomic) factor model for one or more asset returns or excess returns using time series regression. Ordinary least squares (OLS), discounted least squares (DLS) and robust regression fitting are possible. Variable selection methods include "stepwise", "subsets" and "lars". An object of class "tsfm" containing the fitted objects, model coefficients, R-squared and residual volatility are returned.
 
-\item \verb"coef(object)": Extracts the coefficient matrix (intercept and factor betas) for all assets fit by the \code{tsfm} object.
+\item \verb"coef(object)": Extracts the coefficient matrix (intercept and factor betas) for all assets fit by the "tsfm" object.
 
-\item \verb"fitted(object)": Returns an \code{xts} data object of fitted asset returns from the factor model for all assets.
+\item \verb"fitted(object)": Returns an "xts" data object of fitted asset returns from the factor model for all assets.
 
-\item \verb"residuals(object)": Returns an \code{xts} data object of residuals from the fitted factor model for all assets.
+\item \verb"residuals(object)": Returns an "xts" data object of residuals from the fitted factor model for all assets.
 
-\item \verb"fmCov(object, use)": Returns the \code{N x N} symmetric covariance matrix for asset returns based on the fitted factor model. \code{use} specifies how missing values are to be handled.
+\item \verb"fmCov(object, use)": Returns the \code{N x N} symmetric covariance matrix for asset returns based on the fitted factor model. \code{"use"} specifies how missing values are to be handled.
 
-\item \verb"fmSdDecomp(object)": Returns a list containing the standard deviation of asset returns based on the fitted factor model and the marginal, component and percentage component factor contributions estimated from the given sample. \code{use} specifies how missing values are to be handled.
+\item \verb"fmSdDecomp(object, use)": Returns a list containing the standard deviation of asset returns based on the fitted factor model and the marginal, component and percentage component factor contributions estimated from the given sample. \code{"use"} specifies how missing values are to be handled.
 
-\item \verb"fmVaRDecomp(object, p, method, invert)": Returns a list containing the value-at-risk for asset returns based on the fitted factor model and the marginal, component and percentage component factor contributions estimated from the given sample. \code{p} and \code{method} specify the confidence level and method to calculate  VaR. \code{invert} allows the VaR value to be expressed as a loss (vs. fund's return/profit).
[TRUNCATED]

To get the complete diff run:
    svnlook diff /svnroot/returnanalytics -r 3564


More information about the Returnanalytics-commits mailing list