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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Mon Aug 12 23:44:10 CEST 2013


Author: chenyian
Date: 2013-08-12 23:44:10 +0200 (Mon, 12 Aug 2013)
New Revision: 2769

Modified:
   pkg/FactorAnalytics/R/fitFundamentalFactorModel.R
   pkg/FactorAnalytics/vignettes/fundamentalFM.Rnw
Log:
edit vignettes/fundamentalFM.Rnw

Modified: pkg/FactorAnalytics/R/fitFundamentalFactorModel.R
===================================================================
--- pkg/FactorAnalytics/R/fitFundamentalFactorModel.R	2013-08-12 21:09:34 UTC (rev 2768)
+++ pkg/FactorAnalytics/R/fitFundamentalFactorModel.R	2013-08-12 21:44:10 UTC (rev 2769)
@@ -352,7 +352,7 @@
     
     # create matrix for fit
     FE.hat.mat <- matrix(NA, ncol = ncols, nrow = numTimePoints, 
-                         dimnames = list(as.character(timedates),cnames))
+                         dimnames = list(as.character(timedates), cnames))
     # give each element t names 
     for (i in 1:length(FE.hat)) {
       names(FE.hat[[i]])[1] <- "numCoefs"
@@ -410,14 +410,13 @@
     B.final[, match("(Intercept)", colnames, 0)] <- 1
     numeric.columns <- match(exposures.numeric, colnames, 0)
     # only take the latest beta to compute FM covariance
-    B.final[, numeric.columns] <- as.matrix(data[ (as.numeric(data[[datevar]]) == 
-                                                     timedates[numTimePoints]), exposures.numeric])
+    B.final[, numeric.columns] <- as.matrix(data[ (data[[datevar]] == timedates[numTimePoints]), exposures.numeric])
     rownames(B.final) = assets
     colnames(B.final) = colnames(f.hat)
     
     if (length(exposures.factor)) {
       B.final[, grep(exposures.factor, x = colnames)][cbind(seq(numAssets), 
-                                                            as.numeric(data[ data[[datevar]] == timedates[numTimePoints], 
+                                                            (data[ data[[datevar]] == timedates[numTimePoints], 
                                                                             exposures.factor]))] <- 1
     }
     

Modified: pkg/FactorAnalytics/vignettes/fundamentalFM.Rnw
===================================================================
--- pkg/FactorAnalytics/vignettes/fundamentalFM.Rnw	2013-08-12 21:09:34 UTC (rev 2768)
+++ pkg/FactorAnalytics/vignettes/fundamentalFM.Rnw	2013-08-12 21:44:10 UTC (rev 2769)
@@ -6,7 +6,7 @@
 \begin{document}
 \SweaveOpts{concordance=TRUE}
 
-\title{factorAnalytics: fundamental factor model}
+\title{factorAnalytics: Fundamental Factor Model}
 \author{Yi-An Chen}
 \maketitle
 
@@ -160,5 +160,31 @@
 @
 One can also use generic function to do plot, summary...
 
+\verb at fitFundamentalFactorModel()@ support industry/country dummy factor exposures and style factor exposures together. Try 
+<<mixted,results=hide>>=
+fit.mix <- fitFundamentalFactorModel(exposure.names=c("BM","MV","SPCINDCD"),
+                                     datevar="yearqtr",returnsvar ="RET",
+                                     assetvar="tic",wls=FALSE,data=equity)
+@
 
+
+\section{Standardizing Factor Exposure}
+It is common to standardize factor exposure to have weight mean 0 and standard deviation equal to 1. The weight are often taken as proportional to square root of market capitalization, although other weighting schemes are possible. 
+
+We will try example 1 but with stardarized factor exposure with square root of market capitalization. First we create a weighting variable.
+
+<<standardized.fund>>=
+equity$weight <- sqrt(exp(equity$MV)) # we take log for MV before.
+@
+We can choose \verb at standardized.factor.exposure@ to be \verb at TRUE@ and \verb at weight.var@ equal to weighting variabel. 
+<<s.fit>>=
+fit.fund2 <- fitFundamentalFactorModel(exposure.names=c("BM","MV"),
+                                     datevar="yearqtr",returnsvar ="RET",
+                                     assetvar="tic",wls=TRUE,data=equity,
+                                     standardized.factor.exposure = TRUE,
+                                       weight.var = "weight"  )
+@
+
+
+
 \end{document}
\ No newline at end of file



More information about the Returnanalytics-commits mailing list