[Returnanalytics-commits] r3462 - in pkg/FactorAnalytics: R inst/tests man vignettes
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Thu Jul 3 16:09:02 CEST 2014
Author: pragnya
Date: 2014-07-03 16:09:01 +0200 (Thu, 03 Jul 2014)
New Revision: 3462
Modified:
pkg/FactorAnalytics/R/covFM.r
pkg/FactorAnalytics/R/factorModelEsDecomposition.R
pkg/FactorAnalytics/R/factorModelMonteCarlo.R
pkg/FactorAnalytics/R/factorModelVaRDecomposition.R
pkg/FactorAnalytics/R/fitTSFM.R
pkg/FactorAnalytics/R/paFM.r
pkg/FactorAnalytics/R/plot.pafm.r
pkg/FactorAnalytics/R/plot.tsfm.r
pkg/FactorAnalytics/R/predict.tsfm.r
pkg/FactorAnalytics/R/print.pafm.r
pkg/FactorAnalytics/R/print.tsfm.r
pkg/FactorAnalytics/R/summary.pafm.r
pkg/FactorAnalytics/R/summary.tsfm.r
pkg/FactorAnalytics/inst/tests/test-fitTSFM.r
pkg/FactorAnalytics/man/covFM.Rd
pkg/FactorAnalytics/man/factorModelEsDecomposition.Rd
pkg/FactorAnalytics/man/factorModelMonteCarlo.Rd
pkg/FactorAnalytics/man/factorModelVaRDecomposition.Rd
pkg/FactorAnalytics/man/fitTSFM.Rd
pkg/FactorAnalytics/man/paFM.Rd
pkg/FactorAnalytics/man/plot.pafm.Rd
pkg/FactorAnalytics/man/plot.tsfm.Rd
pkg/FactorAnalytics/man/predict.tsfm.Rd
pkg/FactorAnalytics/man/print.pafm.Rd
pkg/FactorAnalytics/man/print.tsfm.Rd
pkg/FactorAnalytics/man/summary.pafm.Rd
pkg/FactorAnalytics/man/summary.tsfm.Rd
pkg/FactorAnalytics/vignettes/fundamentalFM.Rnw
Log:
Market-timing factors made default for all methods in fitTSFM
Modified: pkg/FactorAnalytics/R/covFM.r
===================================================================
--- pkg/FactorAnalytics/R/covFM.r 2014-07-03 04:56:04 UTC (rev 3461)
+++ pkg/FactorAnalytics/R/covFM.r 2014-07-03 14:09:01 UTC (rev 3462)
@@ -41,7 +41,7 @@
#' factors = managers.df[, (7:9)]
#' fit <- fitTSFM(assets.names=colnames(managers.df[, (1:6)]),
#' factors.names=c("EDHEC.LS.EQ","SP500.TR"), data=managers.df,
-#' fit.method="OLS")
+#' add.up.market=FALSE, add.market.sqd=FALSE, fit.method="OLS")
#' covFM(fit)
#'
#' # Statistical Factor Model
Modified: pkg/FactorAnalytics/R/factorModelEsDecomposition.R
===================================================================
--- pkg/FactorAnalytics/R/factorModelEsDecomposition.R 2014-07-03 04:56:04 UTC (rev 3461)
+++ pkg/FactorAnalytics/R/factorModelEsDecomposition.R 2014-07-03 14:09:01 UTC (rev 3462)
@@ -50,6 +50,7 @@
#' fit.macro <- fitTSFM (asset.names=colnames(managers.df[,(1:6)]),
#' factor.names=c("EDHEC.LS.EQ","SP500.TR"),
#' data=managers.df, fit.method="OLS",
+#' add.up.market=FALSE, add.market.sqd=FALSE,
#' variable.selection="none")
#' # risk factor contribution to ETL
#' # combine fund returns, factor returns and residual returns for HAM1
Modified: pkg/FactorAnalytics/R/factorModelMonteCarlo.R
===================================================================
--- pkg/FactorAnalytics/R/factorModelMonteCarlo.R 2014-07-03 04:56:04 UTC (rev 3461)
+++ pkg/FactorAnalytics/R/factorModelMonteCarlo.R 2014-07-03 14:09:01 UTC (rev 3462)
@@ -53,8 +53,8 @@
#' data(managers.df)
#' fit <- fitTSFM(asset.names=colnames(managers.df[,(1:6)]),
#' factor.names=c("EDHEC.LS.EQ","SP500.TR"),
-#' data=managers.df,fit.method="OLS",
-#' variable.selection="none")
+#' data=managers.df, add.up.market=FALSE, add.market.sqd=FALSE,
+#' fit.method="OLS", variable.selection="none")
#' factorData= managers.df[,c("EDHEC.LS.EQ","SP500.TR")]
#' Beta.mat=fit$beta
#' residualData=as.matrix((fit$resid.sd)^2,1,6)
Modified: pkg/FactorAnalytics/R/factorModelVaRDecomposition.R
===================================================================
--- pkg/FactorAnalytics/R/factorModelVaRDecomposition.R 2014-07-03 04:56:04 UTC (rev 3461)
+++ pkg/FactorAnalytics/R/factorModelVaRDecomposition.R 2014-07-03 14:09:01 UTC (rev 3462)
@@ -45,7 +45,8 @@
#' data(managers.df)
#' fit.macro <- fitTSFM(asset.names=colnames(managers.df[,(1:6)]),
#' factor.names=c("EDHEC.LS.EQ","SP500.TR"),
-#' data=managers.df,fit.method="OLS",
+#' add.up.market=FALSE, add.market.sqd=FALSE,
+#' data=managers.df, fit.method="OLS",
#' variable.selection="none")
#' # risk factor contribution to VaR
#' # combine fund returns, factor returns and residual returns for HAM1
Modified: pkg/FactorAnalytics/R/fitTSFM.R
===================================================================
--- pkg/FactorAnalytics/R/fitTSFM.R 2014-07-03 04:56:04 UTC (rev 3461)
+++ pkg/FactorAnalytics/R/fitTSFM.R 2014-07-03 14:09:01 UTC (rev 3462)
@@ -22,21 +22,18 @@
#' using \code{\link[leaps]{regsubsets}} that chooses the n-best performing
#' subsets of any given size (specified as \code{num.factor.subsets} here).
#' "lar" and "lasso" correspond to variants of least angle regression using
-#' \code{\link[lars]{lars}}. If "lar" or "lasso" are chosen, \code{fit.method}
-#' will be ignored.
+#' \code{\link[lars]{lars}}.
#'
#' Note: If \code{variable.selection="lar" or "lasso"}, \code{fit.method}
-#' will be ignored. And, \code{fit.method="Robust"} is not truly available with
-#' \code{variable.selection="all subsets"}; instead,
-#' \code{variable.selection="none"} is used to include all factors.
+#' will be ignored.
#'
-#' If \code{add.up.market=TRUE}, \code{max(0, Rm-Rf)} is added as a factor in the
-#' regression, following Henriksson & Merton (1981), to account for market
+#' If \code{add.up.market=TRUE}, \code{max(0, Rm-Rf)} is added as a factor in
+#' the regression, following Henriksson & Merton (1981), to account for market
#' timing (price movement of the general stock market relative to fixed income
#' securities). The coefficient can be interpreted as the number of free put
-#' options. Similarly, if \code{add.market.sqd=TRUE}, \code{(Rm-Rf)^2} is added as
-#' a factor in the regression, following Treynor-Mazuy (1966), to account for
-#' market timing with respect to volatility.
+#' options. Similarly, if \code{add.market.sqd=TRUE}, \code{(Rm-Rf)^2} is added
+#' as a factor in the regression, following Treynor-Mazuy (1966), to account
+#' for market timing with respect to volatility.
#'
#' Finally, for both the "lar" and "lasso" methods, the "Cp" statistic
#' (defined in page 17 of Efron et al. (2002)) is calculated using
@@ -69,10 +66,10 @@
#' an option for "all subsets" variable selection. Default is 1.
#' Note: nvmax >= num.factors.subset >= length(force.in).
#' @param add.up.market logical; If \code{TRUE}, adds max(0, Rm-Rf) as a
-#' regressor and \code{market.name} is also required. Default is \code{FALSE}.
+#' regressor and \code{market.name} is also required. Default is \code{TRUE}.
#' See Details.
#' @param add.market.sqd logical; If \code{TRUE}, adds (Rm-Rf)^2 as a
-#' regressor and \code{market.name} is also required. Default is \code{FALSE}.
+#' regressor and \code{market.name} is also required. Default is \code{TRUE}.
#' @param decay a scalar in (0, 1] to specify the decay factor for
#' \code{fit.method="DLS"}. Default is 0.95.
#' @param lars.criterion an option to assess model selection for the "lar" or
@@ -148,6 +145,7 @@
#' data(managers.df)
#' fit <- fitTSFM(asset.names=colnames(managers.df[,(1:6)]),
#' factor.names=c("EDHEC.LS.EQ","SP500.TR"), data=managers.df,
+#' add.up.market=FALSE, add.market.sqd=FALSE,
#' fit.method="OLS", variable.selection="none")
#' # summary of HAM1
#' summary(fit$asset.fit$HAM1)
@@ -169,7 +167,7 @@
subsets.method = c("exhaustive", "backward", "forward",
"seqrep"),
nvmax=8, force.in=NULL, num.factors.subset=1,
- add.up.market=FALSE, add.market.sqd=FALSE,
+ add.up.market=TRUE, add.market.sqd=TRUE,
decay=0.95, lars.criterion="Cp", ...){
# get all the arguments specified by their full names
@@ -285,19 +283,12 @@
for (i in asset.names){
# completely remove NA cases
reg.xts <- na.omit(dat.xts[, c(i, factor.names)])
+ # optionally add factors: up.market=max(0,Rm-Rf), market.sqd=(Rm-Rf)^2
+ reg.xts <- MarketFactors(dat.xts, reg.xts, market.name,
+ add.up.market, add.market.sqd)
# formula to pass to lm or lmRob
fm.formula <- as.formula(paste(i," ~ ."))
- # optionally add factors: up.market=max(0,Rm-Rf), market.sqd=(Rm-Rf)^2
- if(fit.method=="Robust" && (add.up.market==TRUE | add.market.sqd==TRUE)) {
- stop("This function does not support add.up.market/add.market.sqd when
- variable.selection = 'stepwise' && fit.method = 'Robust'. Please
- choose a different combination of options.")
- } else {
- reg.xts <- MarketFactors(dat.xts, reg.xts, market.name,
- add.up.market, add.market.sqd)
- }
-
# fit based on time series regression method chosen
if (fit.method == "OLS") {
reg.list[[i]] <- step(lm(fm.formula, data=reg.xts), direction=direction,
@@ -332,49 +323,44 @@
# loop through and estimate model for each asset to allow unequal histories
for (i in asset.names){
- # formula to pass to lm or lmRob
- fm.formula <- as.formula(paste(i," ~ ."))
- # branch out based on time series regression method chosen
- if (fit.method == "Robust") {
- warning("'Robust' fit.method is not available with 'all subsets'
- variable.selection. Instead, results are shown for
- variable.selection='none' with fit.method='Robust' to include
- all factors.")
+ # choose best subset of factors depending on specified number of factors
+ if (num.factors.subset == length(force.in)) {
+ reg.xts <- na.omit(dat.xts[, c(i, force.in)])
+ } else if (num.factors.subset > length(force.in)) {
reg.xts <- na.omit(dat.xts[, c(i, factor.names)])
+ # optionally add factors: up.market=max(0,Rm-Rf), market.sqd=(Rm-Rf)^2
reg.xts <- MarketFactors(dat.xts, reg.xts, market.name,
add.up.market, add.market.sqd)
- asset.fit <- lmRob(fm.formula, data=reg.xts)
- }
- else if (fit.method == "OLS" | fit.method == "DLS") {
+ # formula to pass to lm or lmRob
+ fm.formula <- as.formula(paste(i," ~ ."))
+
+ if (fit.method != "DLS") {decay <- 1}
+ # do weighted least squares if "DLS"
+ w <- WeightsDLS(nrow(reg.xts), decay)
+
# use regsubsets to find the best model with a subset of factors of size
# num.factors.subset
-
- if (num.factors.subset == length(force.in)) {
- reg.xts <- na.omit(dat.xts[, c(i, force.in)])
- } else if (num.factors.subset > length(force.in)) {
- reg.xts <- na.omit(dat.xts[, c(i, factor.names)])
- if (fit.method != "DLS") {decay <- 1}
- # do weighted least squares if "DLS"
- w <- WeightsDLS(nrow(reg.xts), decay)
- fm.subsets <- regsubsets(fm.formula, data=reg.xts, nvmax=nvmax,
- force.in=force.in, method=subsets.method,
- weights=w)
- sum.sub <- summary(fm.subsets)
- reg.xts <- na.omit(dat.xts[,c(i,names(which(sum.sub$which[
- as.character(num.factors.subset),-1]==TRUE)))])
- } else {
- stop("Invalid Argument: num.factors.subset should be >=
+ fm.subsets <- regsubsets(fm.formula, data=reg.xts, nvmax=nvmax,
+ force.in=force.in, method=subsets.method,
+ weights=w)
+ sum.sub <- summary(fm.subsets)
+ reg.xts <- na.omit(dat.xts[,c(i,names(which(sum.sub$which[
+ as.character(num.factors.subset),-1]==TRUE)))])
+ } else {
+ stop("Invalid Argument: num.factors.subset should be >=
length(force.in)")
- }
-
- # optionally add factors: up.market=max(0,Rm-Rf), market.sqd=(Rm-Rf)^2
- reg.xts <- MarketFactors(dat.xts, reg.xts, market.name,
- add.up.market, add.market.sqd)
- # fit linear regression model for the factors chosen
- reg.list[[i]] <- lm(fm.formula, data=reg.xts, weights=w)
}
- else {
+
+ # fit based on time series regression method chosen
+ if (fit.method == "OLS") {
+ reg.list[[i]] <- lm(fm.formula, data=reg.xts)
+ } else if (fit.method == "DLS") {
+ w <- WeightsDLS(nrow(reg.xts), decay)
+ reg.list[[i]] <- lm(fm.formula, data=reg.xts, weights=w)
+ } else if (fit.method == "Robust") {
+ reg.list[[i]] <- lmRob(fm.formula, data=reg.xts)
+ } else {
stop("Invalid argument: fit.method must be 'OLS', 'DLS' or 'Robust'")
}
}
@@ -473,7 +459,7 @@
#
makePaddedDataFrame <- function(l){
DF <- do.call(rbind, lapply(lapply(l, unlist), "[",
- unique(unlist(c(sapply(l,names))))))
+ unique(unlist(c(sapply(l,names))))))
DF <- as.data.frame(DF)
names(DF) <- unique(unlist(c(sapply(l,names))))
# as.matrix(DF) # if matrix output needed
@@ -482,7 +468,7 @@
#' @param object a fit object of class \code{tsfm} which is returned by
#' \code{fitTSFM}
-
+
#' @rdname fitTSFM
#' @method coef tsfm
#' @export
@@ -550,9 +536,9 @@
cov.fm = beta %*% factor.cov %*% t(beta) + D.e
-# if (any(diag(chol(cov.fm)) == 0)) {
-# warning("Covariance matrix is not positive definite!")
-# }
+ # if (any(diag(chol(cov.fm)) == 0)) {
+ # warning("Covariance matrix is not positive definite!")
+ # }
return(cov.fm)
}
Modified: pkg/FactorAnalytics/R/paFM.r
===================================================================
--- pkg/FactorAnalytics/R/paFM.r 2014-07-03 04:56:04 UTC (rev 3461)
+++ pkg/FactorAnalytics/R/paFM.r 2014-07-03 14:09:01 UTC (rev 3462)
@@ -33,6 +33,7 @@
#' data(managers.df)
#' fit <- fitTSFM(asset.names=colnames(managers.df[, (1:6)]),
#' factor.names=c("EDHEC.LS.EQ","SP500.TR"), data=managers.df,
+#' add.up.market=FALSE, add.market.sqd=FALSE,
#' fit.method="OLS", variable.selection="none")
#' # without benchmark
#' fm.attr <- paFM(fit)
Modified: pkg/FactorAnalytics/R/plot.pafm.r
===================================================================
--- pkg/FactorAnalytics/R/plot.pafm.r 2014-07-03 04:56:04 UTC (rev 3461)
+++ pkg/FactorAnalytics/R/plot.pafm.r 2014-07-03 14:09:01 UTC (rev 3462)
@@ -29,6 +29,7 @@
#' data(managers.df)
#' fit <- fitTSFM(asset.names=colnames(managers.df[,(1:6)]),
#' factor.names=c("EDHEC.LS.EQ","SP500.TR"), data=managers.df,
+#' add.up.market=FALSE, add.market.sqd=FALSE,
#' fit.method="OLS", variable.selection="none")
#' fm.attr <- paFM(fit)
#' # plot all
Modified: pkg/FactorAnalytics/R/plot.tsfm.r
===================================================================
--- pkg/FactorAnalytics/R/plot.tsfm.r 2014-07-03 04:56:04 UTC (rev 3461)
+++ pkg/FactorAnalytics/R/plot.tsfm.r 2014-07-03 14:09:01 UTC (rev 3462)
@@ -59,6 +59,7 @@
#' fit.macro <- fitTSFM(asset.names=colnames(managers.df[,(1:6)]),
#' factor.names=c("EDHEC.LS.EQ","SP500.TR"),
#' data=managers.df, fit.method="OLS",
+#' add.up.market=FALSE, add.market.sqd=FALSE,
#' variable.selection="none")
#' # plot all assets and show only the first 4 assets.
#' plot(fit.macro,max.show=4)
Modified: pkg/FactorAnalytics/R/predict.tsfm.r
===================================================================
--- pkg/FactorAnalytics/R/predict.tsfm.r 2014-07-03 04:56:04 UTC (rev 3461)
+++ pkg/FactorAnalytics/R/predict.tsfm.r 2014-07-03 14:09:01 UTC (rev 3462)
@@ -25,6 +25,7 @@
#' # fit the factor model with OLS
#' fit <- fitTSFM(asset.names=colnames(managers.df[,(1:6)]),
#' factor.names=c("EDHEC.LS.EQ","SP500.TR"), data=managers.df,
+#' add.up.market=FALSE, add.market.sqd=FALSE,
#' fit.method="OLS", variable.selection="none")
#'
#' pred.fit <- predict(fit)
Modified: pkg/FactorAnalytics/R/print.pafm.r
===================================================================
--- pkg/FactorAnalytics/R/print.pafm.r 2014-07-03 04:56:04 UTC (rev 3461)
+++ pkg/FactorAnalytics/R/print.pafm.r 2014-07-03 14:09:01 UTC (rev 3462)
@@ -13,6 +13,7 @@
#' # fit the factor model with OLS
#' fit <- fitTSFM(asset.names=colnames(managers.df[,(1:6)]),
#' factor.names=c("EDHEC.LS.EQ","SP500.TR"), data=managers.df,
+#' add.up.market=FALSE, add.market.sqd=FALSE,
#' fit.method="OLS", variable.selection="none")
#' fm.attr <- paFM(fit)
#' print(fm.attr)
Modified: pkg/FactorAnalytics/R/print.tsfm.r
===================================================================
--- pkg/FactorAnalytics/R/print.tsfm.r 2014-07-03 04:56:04 UTC (rev 3461)
+++ pkg/FactorAnalytics/R/print.tsfm.r 2014-07-03 14:09:01 UTC (rev 3462)
@@ -17,9 +17,8 @@
#' data(managers.df)
#' fit <- fitTSFM(asset.names=colnames(managers.df[,(1:6)]),
#' factor.names=colnames(managers.df[,7:9]),
-#' market.name="SP500.TR",
-#' data=managers.df, fit.method="OLS", variable.selection="none",
-#' add.up.market=TRUE, add.market.sqd=TRUE)
+#' market.name="SP500.TR", data=managers.df,
+#' fit.method="OLS", variable.selection="none")
#' print(fit)
#'
#' @method print tsfm
Modified: pkg/FactorAnalytics/R/summary.pafm.r
===================================================================
--- pkg/FactorAnalytics/R/summary.pafm.r 2014-07-03 04:56:04 UTC (rev 3461)
+++ pkg/FactorAnalytics/R/summary.pafm.r 2014-07-03 14:09:01 UTC (rev 3462)
@@ -14,8 +14,8 @@
#' # fit the factor model with OLS
#' fit.ts <- fitTSFM(asset.names=colnames(managers.df[,(1:6)]),
#' factor.names=c("EDHEC.LS.EQ","SP500.TR"),
-#' data=managers.df, fit.method="OLS",
-#' variable.selection="none")
+#' market.name="SP500.TR", data=managers.df,
+#' fit.method="OLS", variable.selection="none")
#'
#' fm.attr <- paFM(fit.ts)
#' summary(fm.attr)
Modified: pkg/FactorAnalytics/R/summary.tsfm.r
===================================================================
--- pkg/FactorAnalytics/R/summary.tsfm.r 2014-07-03 04:56:04 UTC (rev 3461)
+++ pkg/FactorAnalytics/R/summary.tsfm.r 2014-07-03 14:09:01 UTC (rev 3462)
@@ -45,8 +45,8 @@
#' fit <- fitTSFM(asset.names=colnames(managers.df[,(1:6)]),
#' factor.names=colnames(managers.df[,7:9]),
#' market.name="SP500.TR", data=managers.df,
-#' fit.method="OLS", variable.selection="none",
-#' add.up.market=TRUE, add.market.sqd=TRUE)
+#' fit.method="OLS", variable.selection="none")
+#'
#' # summary of factor model fit for all assets
#' summary(fit, "HAC")
#'
Modified: pkg/FactorAnalytics/inst/tests/test-fitTSFM.r
===================================================================
--- pkg/FactorAnalytics/inst/tests/test-fitTSFM.r 2014-07-03 04:56:04 UTC (rev 3461)
+++ pkg/FactorAnalytics/inst/tests/test-fitTSFM.r 2014-07-03 14:09:01 UTC (rev 3462)
@@ -21,6 +21,7 @@
ff.mod <- fitTSFM(
asset.names = assets,
factor.names = c("mktrf","smb", "hml","umd"),
+ add.up.market=FALSE, add.market.sqd=FALSE,
data = cbind(ex.rets,carhart),
fit.method = "OLS",
variable.selection="none")
Modified: pkg/FactorAnalytics/man/covFM.Rd
===================================================================
--- pkg/FactorAnalytics/man/covFM.Rd 2014-07-03 04:56:04 UTC (rev 3461)
+++ pkg/FactorAnalytics/man/covFM.Rd 2014-07-03 14:09:01 UTC (rev 3462)
@@ -40,7 +40,7 @@
factors = managers.df[, (7:9)]
fit <- fitTSFM(assets.names=colnames(managers.df[, (1:6)]),
factors.names=c("EDHEC.LS.EQ","SP500.TR"), data=managers.df,
- fit.method="OLS")
+ add.up.market=FALSE, add.market.sqd=FALSE, fit.method="OLS")
covFM(fit)
# Statistical Factor Model
Modified: pkg/FactorAnalytics/man/factorModelEsDecomposition.Rd
===================================================================
--- pkg/FactorAnalytics/man/factorModelEsDecomposition.Rd 2014-07-03 04:56:04 UTC (rev 3461)
+++ pkg/FactorAnalytics/man/factorModelEsDecomposition.Rd 2014-07-03 14:09:01 UTC (rev 3462)
@@ -55,6 +55,7 @@
fit.macro <- fitTSFM (asset.names=colnames(managers.df[,(1:6)]),
factor.names=c("EDHEC.LS.EQ","SP500.TR"),
data=managers.df, fit.method="OLS",
+ add.up.market=FALSE, add.market.sqd=FALSE,
variable.selection="none")
# risk factor contribution to ETL
# combine fund returns, factor returns and residual returns for HAM1
Modified: pkg/FactorAnalytics/man/factorModelMonteCarlo.Rd
===================================================================
--- pkg/FactorAnalytics/man/factorModelMonteCarlo.Rd 2014-07-03 04:56:04 UTC (rev 3461)
+++ pkg/FactorAnalytics/man/factorModelMonteCarlo.Rd 2014-07-03 14:09:01 UTC (rev 3462)
@@ -72,8 +72,8 @@
data(managers.df)
fit <- fitTSFM(asset.names=colnames(managers.df[,(1:6)]),
factor.names=c("EDHEC.LS.EQ","SP500.TR"),
- data=managers.df,fit.method="OLS",
- variable.selection="none")
+ data=managers.df, add.up.market=FALSE, add.market.sqd=FALSE,
+ fit.method="OLS", variable.selection="none")
factorData= managers.df[,c("EDHEC.LS.EQ","SP500.TR")]
Beta.mat=fit$beta
residualData=as.matrix((fit$resid.sd)^2,1,6)
Modified: pkg/FactorAnalytics/man/factorModelVaRDecomposition.Rd
===================================================================
--- pkg/FactorAnalytics/man/factorModelVaRDecomposition.Rd 2014-07-03 04:56:04 UTC (rev 3461)
+++ pkg/FactorAnalytics/man/factorModelVaRDecomposition.Rd 2014-07-03 14:09:01 UTC (rev 3462)
@@ -52,7 +52,8 @@
data(managers.df)
fit.macro <- fitTSFM(asset.names=colnames(managers.df[,(1:6)]),
factor.names=c("EDHEC.LS.EQ","SP500.TR"),
- data=managers.df,fit.method="OLS",
+ add.up.market=FALSE, add.market.sqd=FALSE,
+ data=managers.df, fit.method="OLS",
variable.selection="none")
# risk factor contribution to VaR
# combine fund returns, factor returns and residual returns for HAM1
Modified: pkg/FactorAnalytics/man/fitTSFM.Rd
===================================================================
--- pkg/FactorAnalytics/man/fitTSFM.Rd 2014-07-03 04:56:04 UTC (rev 3461)
+++ pkg/FactorAnalytics/man/fitTSFM.Rd 2014-07-03 14:09:01 UTC (rev 3462)
@@ -11,7 +11,7 @@
fit.method = c("OLS", "DLS", "Robust"), variable.selection = c("none",
"stepwise", "all subsets", "lar", "lasso"), subsets.method = c("exhaustive",
"backward", "forward", "seqrep"), nvmax = 8, force.in = NULL,
- num.factors.subset = 1, add.up.market = FALSE, add.market.sqd = FALSE,
+ num.factors.subset = 1, add.up.market = TRUE, add.market.sqd = TRUE,
decay = 0.95, lars.criterion = "Cp", ...)
\method{coef}{tsfm}(object, ...)
@@ -58,11 +58,11 @@
Note: nvmax >= num.factors.subset >= length(force.in).}
\item{add.up.market}{logical; If \code{TRUE}, adds max(0, Rm-Rf) as a
-regressor and \code{market.name} is also required. Default is \code{FALSE}.
+regressor and \code{market.name} is also required. Default is \code{TRUE}.
See Details.}
\item{add.market.sqd}{logical; If \code{TRUE}, adds (Rm-Rf)^2 as a
-regressor and \code{market.name} is also required. Default is \code{FALSE}.}
+regressor and \code{market.name} is also required. Default is \code{TRUE}.}
\item{decay}{a scalar in (0, 1] to specify the decay factor for
\code{fit.method="DLS"}. Default is 0.95.}
@@ -134,21 +134,18 @@
using \code{\link[leaps]{regsubsets}} that chooses the n-best performing
subsets of any given size (specified as \code{num.factor.subsets} here).
"lar" and "lasso" correspond to variants of least angle regression using
-\code{\link[lars]{lars}}. If "lar" or "lasso" are chosen, \code{fit.method}
-will be ignored.
+\code{\link[lars]{lars}}.
Note: If \code{variable.selection="lar" or "lasso"}, \code{fit.method}
-will be ignored. And, \code{fit.method="Robust"} is not truly available with
-\code{variable.selection="all subsets"}; instead,
-\code{variable.selection="none"} is used to include all factors.
+will be ignored.
-If \code{add.up.market=TRUE}, \code{max(0, Rm-Rf)} is added as a factor in the
-regression, following Henriksson & Merton (1981), to account for market
+If \code{add.up.market=TRUE}, \code{max(0, Rm-Rf)} is added as a factor in
+the regression, following Henriksson & Merton (1981), to account for market
timing (price movement of the general stock market relative to fixed income
securities). The coefficient can be interpreted as the number of free put
-options. Similarly, if \code{add.market.sqd=TRUE}, \code{(Rm-Rf)^2} is added as
-a factor in the regression, following Treynor-Mazuy (1966), to account for
-market timing with respect to volatility.
+options. Similarly, if \code{add.market.sqd=TRUE}, \code{(Rm-Rf)^2} is added
+as a factor in the regression, following Treynor-Mazuy (1966), to account
+for market timing with respect to volatility.
Finally, for both the "lar" and "lasso" methods, the "Cp" statistic
(defined in page 17 of Efron et al. (2002)) is calculated using
@@ -161,6 +158,7 @@
data(managers.df)
fit <- fitTSFM(asset.names=colnames(managers.df[,(1:6)]),
factor.names=c("EDHEC.LS.EQ","SP500.TR"), data=managers.df,
+ add.up.market=FALSE, add.market.sqd=FALSE,
fit.method="OLS", variable.selection="none")
# summary of HAM1
summary(fit$asset.fit$HAM1)
Modified: pkg/FactorAnalytics/man/paFM.Rd
===================================================================
--- pkg/FactorAnalytics/man/paFM.Rd 2014-07-03 04:56:04 UTC (rev 3461)
+++ pkg/FactorAnalytics/man/paFM.Rd 2014-07-03 14:09:01 UTC (rev 3462)
@@ -36,6 +36,7 @@
data(managers.df)
fit <- fitTSFM(asset.names=colnames(managers.df[, (1:6)]),
factor.names=c("EDHEC.LS.EQ","SP500.TR"), data=managers.df,
+ add.up.market=FALSE, add.market.sqd=FALSE,
fit.method="OLS", variable.selection="none")
# without benchmark
fm.attr <- paFM(fit)
Modified: pkg/FactorAnalytics/man/plot.pafm.Rd
===================================================================
--- pkg/FactorAnalytics/man/plot.pafm.Rd 2014-07-03 04:56:04 UTC (rev 3461)
+++ pkg/FactorAnalytics/man/plot.pafm.Rd 2014-07-03 14:09:01 UTC (rev 3462)
@@ -44,6 +44,7 @@
data(managers.df)
fit <- fitTSFM(asset.names=colnames(managers.df[,(1:6)]),
factor.names=c("EDHEC.LS.EQ","SP500.TR"), data=managers.df,
+ add.up.market=FALSE, add.market.sqd=FALSE,
fit.method="OLS", variable.selection="none")
fm.attr <- paFM(fit)
# plot all
Modified: pkg/FactorAnalytics/man/plot.tsfm.Rd
===================================================================
--- pkg/FactorAnalytics/man/plot.tsfm.Rd 2014-07-03 04:56:04 UTC (rev 3461)
+++ pkg/FactorAnalytics/man/plot.tsfm.Rd 2014-07-03 14:09:01 UTC (rev 3462)
@@ -74,6 +74,7 @@
fit.macro <- fitTSFM(asset.names=colnames(managers.df[,(1:6)]),
factor.names=c("EDHEC.LS.EQ","SP500.TR"),
data=managers.df, fit.method="OLS",
+ add.up.market=FALSE, add.market.sqd=FALSE,
variable.selection="none")
# plot all assets and show only the first 4 assets.
plot(fit.macro,max.show=4)
Modified: pkg/FactorAnalytics/man/predict.tsfm.Rd
===================================================================
--- pkg/FactorAnalytics/man/predict.tsfm.Rd 2014-07-03 04:56:04 UTC (rev 3461)
+++ pkg/FactorAnalytics/man/predict.tsfm.Rd 2014-07-03 14:09:01 UTC (rev 3462)
@@ -30,6 +30,7 @@
# fit the factor model with OLS
fit <- fitTSFM(asset.names=colnames(managers.df[,(1:6)]),
factor.names=c("EDHEC.LS.EQ","SP500.TR"), data=managers.df,
+ add.up.market=FALSE, add.market.sqd=FALSE,
fit.method="OLS", variable.selection="none")
pred.fit <- predict(fit)
Modified: pkg/FactorAnalytics/man/print.pafm.Rd
===================================================================
--- pkg/FactorAnalytics/man/print.pafm.Rd 2014-07-03 04:56:04 UTC (rev 3461)
+++ pkg/FactorAnalytics/man/print.pafm.Rd 2014-07-03 14:09:01 UTC (rev 3462)
@@ -20,6 +20,7 @@
# fit the factor model with OLS
fit <- fitTSFM(asset.names=colnames(managers.df[,(1:6)]),
factor.names=c("EDHEC.LS.EQ","SP500.TR"), data=managers.df,
+ add.up.market=FALSE, add.market.sqd=FALSE,
fit.method="OLS", variable.selection="none")
fm.attr <- paFM(fit)
print(fm.attr)
Modified: pkg/FactorAnalytics/man/print.tsfm.Rd
===================================================================
--- pkg/FactorAnalytics/man/print.tsfm.Rd 2014-07-03 04:56:04 UTC (rev 3461)
+++ pkg/FactorAnalytics/man/print.tsfm.Rd 2014-07-03 14:09:01 UTC (rev 3462)
@@ -22,9 +22,8 @@
data(managers.df)
fit <- fitTSFM(asset.names=colnames(managers.df[,(1:6)]),
factor.names=colnames(managers.df[,7:9]),
- market.name="SP500.TR",
- data=managers.df, fit.method="OLS", variable.selection="none",
- add.up.market=TRUE, add.market.sqd=TRUE)
+ market.name="SP500.TR", data=managers.df,
+ fit.method="OLS", variable.selection="none")
print(fit)
}
\author{
Modified: pkg/FactorAnalytics/man/summary.pafm.Rd
===================================================================
--- pkg/FactorAnalytics/man/summary.pafm.Rd 2014-07-03 04:56:04 UTC (rev 3461)
+++ pkg/FactorAnalytics/man/summary.pafm.Rd 2014-07-03 14:09:01 UTC (rev 3462)
@@ -22,8 +22,8 @@
# fit the factor model with OLS
fit.ts <- fitTSFM(asset.names=colnames(managers.df[,(1:6)]),
factor.names=c("EDHEC.LS.EQ","SP500.TR"),
- data=managers.df, fit.method="OLS",
- variable.selection="none")
+ market.name="SP500.TR", data=managers.df,
+ fit.method="OLS", variable.selection="none")
fm.attr <- paFM(fit.ts)
summary(fm.attr)
Modified: pkg/FactorAnalytics/man/summary.tsfm.Rd
===================================================================
--- pkg/FactorAnalytics/man/summary.tsfm.Rd 2014-07-03 04:56:04 UTC (rev 3461)
+++ pkg/FactorAnalytics/man/summary.tsfm.Rd 2014-07-03 14:09:01 UTC (rev 3462)
@@ -58,8 +58,8 @@
fit <- fitTSFM(asset.names=colnames(managers.df[,(1:6)]),
factor.names=colnames(managers.df[,7:9]),
market.name="SP500.TR", data=managers.df,
- fit.method="OLS", variable.selection="none",
- add.up.market=TRUE, add.market.sqd=TRUE)
+ fit.method="OLS", variable.selection="none")
+
# summary of factor model fit for all assets
summary(fit, "HAC")
Modified: pkg/FactorAnalytics/vignettes/fundamentalFM.Rnw
===================================================================
--- pkg/FactorAnalytics/vignettes/fundamentalFM.Rnw 2014-07-03 04:56:04 UTC (rev 3461)
+++ pkg/FactorAnalytics/vignettes/fundamentalFM.Rnw 2014-07-03 14:09:01 UTC (rev 3462)
@@ -283,7 +283,7 @@
In this example, we will use SP500, 10 years and 3 months term spread and difference of VIX as our common factors.
<<fit.ts>>=
-fit.time <- fitTSFM (asset.names=tic,
+fit.time <- fitTSFM (asset.names=tic, market.name="SP500",
factor.names=c("SP500","Term.Spread","dVIX"),
data=ts.data, fit.method="OLS",
variable.selection="none")
@@ -299,7 +299,7 @@
<<fit.ts>>=
fit.time2 <- fitTSFM(asset.names=tic, factor.names=names(ts.factors),
- data=ts.data, fit.method="OLS",
+ data=ts.data, market.name="SP500", fit.method="OLS",
variable.selection = "stepwise")
@
There are 5 factors chosen for asset AA for example.
More information about the Returnanalytics-commits
mailing list