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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Tue Jan 27 09:34:39 CET 2015


Author: pragnya
Date: 2015-01-27 09:34:38 +0100 (Tue, 27 Jan 2015)
New Revision: 3586

Modified:
   pkg/FactorAnalytics/R/fitTsfm.R
   pkg/FactorAnalytics/man/fitTsfm.Rd
   pkg/FactorAnalytics/vignettes/fitTsfm_vignette.R
   pkg/FactorAnalytics/vignettes/fitTsfm_vignette.Rnw
   pkg/FactorAnalytics/vignettes/fitTsfm_vignette.pdf
Log:
Update to HM model in fitTsfm

Modified: pkg/FactorAnalytics/R/fitTsfm.R
===================================================================
--- pkg/FactorAnalytics/R/fitTsfm.R	2015-01-27 03:53:19 UTC (rev 3585)
+++ pkg/FactorAnalytics/R/fitTsfm.R	2015-01-27 08:34:38 UTC (rev 3586)
@@ -39,13 +39,14 @@
 #' 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. 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 
-#' Treynor & Mazuy (1966), $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")}. 
+#' $down.market = max(0, R_f-R_m)$ as a factor, following Henriksson & Merton 
+#' (1981). The coefficient of this down-market factor can be interpreted as the 
+#' number of "free" put options on the market provided by the manager's 
+#' market-timings kills. Similarly, to account for market timing with respect 
+#' to volatility, one can specify \code{mkt.timing="TM"}. Following 
+#' Treynor & Mazuy (1966), $market.sqd = (R_m-R_f)^2$ is added as a factor. 
+#' For example, as a test for market timing, either of these factors can be 
+#' added to the single index regression model.
 #' 
 #' \subsection{Data Processing}{
 #' 
@@ -74,7 +75,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". See Details. Default is NULL.
+#' @param mkt.timing one of "HM" or "TM". 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 
@@ -245,13 +246,13 @@
     warning("Excess returns were not computed.")
   }
   
-  # opt add mkt-timing factors: up.market=max(0,Rm-Rf), market.sqd=(Rm-Rf)^2
+  # opt add mkt-timing factors: down.market=max(0,Rf-Rm), market.sqd=(Rm-Rf)^2
   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")
+    down.market <- data.xts[,mkt.name]
+    down.market [down.market > 0] <- 0
+    dat.xts <- merge.xts(dat.xts,down.market)
+    colnames(dat.xts)[dim(dat.xts)[2]] <- "down.market"
+    factor.names <- c(factor.names, "down.market")
   }
   if("TM" %in% mkt.timing) {
     market.sqd <- data.xts[,mkt.name]^2   

Modified: pkg/FactorAnalytics/man/fitTsfm.Rd
===================================================================
--- pkg/FactorAnalytics/man/fitTsfm.Rd	2015-01-27 03:53:19 UTC (rev 3585)
+++ pkg/FactorAnalytics/man/fitTsfm.Rd	2015-01-27 08:34:38 UTC (rev 3586)
@@ -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". See Details. Default is NULL.
+\item{mkt.timing}{one of "HM" or "TM". 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
@@ -122,13 +122,14 @@
 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. 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
-Treynor & Mazuy (1966), $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")}.
+$down.market = max(0, R_f-R_m)$ as a factor, following Henriksson & Merton
+(1981). The coefficient of this down-market factor can be interpreted as the
+number of "free" put options on the market provided by the manager's
+market-timings kills. Similarly, to account for market timing with respect
+to volatility, one can specify \code{mkt.timing="TM"}. Following
+Treynor & Mazuy (1966), $market.sqd = (R_m-R_f)^2$ is added as a factor.
+For example, as a test for market timing, either of these factors can be
+added to the single index regression model.
 
 \subsection{Data Processing}{
 

Modified: pkg/FactorAnalytics/vignettes/fitTsfm_vignette.R
===================================================================
--- pkg/FactorAnalytics/vignettes/fitTsfm_vignette.R	2015-01-27 03:53:19 UTC (rev 3585)
+++ pkg/FactorAnalytics/vignettes/fitTsfm_vignette.R	2015-01-27 08:34:38 UTC (rev 3586)
@@ -44,9 +44,12 @@
 
 ## ------------------------------------------------------------------------
 # 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.mktTiming <- fitTsfm(asset.names=asset.names, factor.names="SP500 TR", 
+                         rf.name="US 3m TR", mkt.name="SP500 TR", 
+                         mkt.timing="HM", data=managers)
+fit.mktTiming$beta
+fit.mktTiming$r2
+fit.mktTiming$resid.sd
 
 
 ## ------------------------------------------------------------------------
@@ -193,7 +196,8 @@
 ## ## Selection:
 
 
-## ----fig.cap="Actual and fitted factor model returns for the 1st 4 assets"----
+## ----fig.cap="Actual and fitted factor model returns for the 1st 4 assets", fig.show='asis', fig.width=7, fig.height=6----
+# Example of a group plot: looping disabled & no. of assets displayed = 4.
 plot(fit.sub, which.plot.group=3, max.show=4, legend.loc=NULL, loop=FALSE)
 
 
@@ -219,17 +223,17 @@
 ## ## Selection:
 
 
-## ----fig.cap="Time series plot of residuals with standard error bands: HAM1", fig.show='hold'----
+## ----fig.cap="Time series plot of residuals with standard error bands: HAM1", fig.show='asis', fig.width=7, fig.height=4.5----
 plot(fit.sub, plot.single=TRUE, asset.name="HAM1", which.plot.single=2, 
      loop=FALSE)
 
 
-## ----fig.cap="SACF and PACF of absolute residuals: HAM1", fig.show='hold'----
+## ----fig.cap="SACF and PACF of absolute residuals: HAM1", fig.show='asis', fig.width=7, fig.height=4.5----
 plot(fit.sub, plot.single=TRUE, asset.name="HAM1", which.plot.single=7, 
      loop=FALSE)
 
 
-## ----fig.cap="Histogram of residuals with normal curve overlayed for HAM1", fig.show='hold'----
+## ----fig.cap="Histogram of residuals with normal curve overlayed for HAM1", fig.show='asis', fig.width=7, fig.height=4.5----
 plot(fit.sub, plot.single=TRUE, asset.name="HAM1", which.plot.single=8, 
      loop=FALSE)
 

Modified: pkg/FactorAnalytics/vignettes/fitTsfm_vignette.Rnw
===================================================================
--- pkg/FactorAnalytics/vignettes/fitTsfm_vignette.Rnw	2015-01-27 03:53:19 UTC (rev 3585)
+++ pkg/FactorAnalytics/vignettes/fitTsfm_vignette.Rnw	2015-01-27 08:34:38 UTC (rev 3586)
@@ -148,15 +148,18 @@
 
 \subsection{Market Timing Models}
 
-In the following example, we fit the \citet{henriksson1981market} market timing model, using the SP500 as the market. Market timing accounts for the price movement of the general stock market relative to fixed income securities. Specifying \code{mkt.timing="HM"}, includes $up.market = max(0, R_m-R_f)$ as a factor. 
+In the following example, we fit the \citet{henriksson1981market} market timing model, using the SP500 as the market. Market timing accounts for the price movement of the general stock market relative to fixed income securities. Specifying \code{mkt.timing="HM"}, includes $down.market = max(0, R_f-R_m)$ as a factor. To test market timing ability, this factor can be added to the single index model as shown below. The coefficient of this down-market factor can be interpreted as the number of "free" put options on the market provided by the manager's market-timings kills. That is, a negative value for the regression estimate would imply a negative value for market timing ability of the manager.
 <<>>=
 # 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.mktTiming <- fitTsfm(asset.names=asset.names, factor.names="SP500 TR", 
+                         rf.name="US 3m TR", mkt.name="SP500 TR", 
+                         mkt.timing="HM", data=managers)
+fit.mktTiming$beta
+fit.mktTiming$r2
+fit.mktTiming$resid.sd
 @
 
-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")}. 
+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. 
 
 Note that, the user needs to specify which of the columns in \code{data} corresponds to the market returns using argument \code{mkt.name}. In the above case, \code{factor.names} were left out from the argument list and a pure market-timing model was fit.
 
@@ -171,7 +174,7 @@
 fit.ols$resid.sd
 @ 
 
-Other options include discounted least squares (\code{"DLS"}) and robust regression (\code{"Robust"}). DLS is least squares regression using exponentially discounted weights and accounts for time variation in coefficients. Robust regression is resistant to outliers and heteroskedasticity. 
+Other options include discounted least squares (\code{"DLS"}) and robust regression (\code{"Robust"}). DLS is least squares regression using exponentially discounted weights and accounts for time variation in coefficients. Robust regression is resistant to outliers. 
 <<>>=
 fit.robust <- fitTsfm(asset.names=asset.names, factor.names=factor.names, 
                        rf.name="US 3m TR", data=managers, fit.method="Robust")

Modified: pkg/FactorAnalytics/vignettes/fitTsfm_vignette.pdf
===================================================================
(Binary files differ)



More information about the Returnanalytics-commits mailing list