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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed Apr 9 02:29:45 CEST 2014


Author: chenyian
Date: 2014-04-09 02:29:45 +0200 (Wed, 09 Apr 2014)
New Revision: 3357

Modified:
   pkg/FactorAnalytics/R/fitFundamentalFactorModel.R
   pkg/FactorAnalytics/R/predict.FundamentalFactorModel.r
   pkg/FactorAnalytics/man/fitFundamentalFactorModel.Rd
Log:
1. correct typo in fitFundamentalFactorModel.Rd
2. debug in predict.FundamentalFactorModel.r 

Modified: pkg/FactorAnalytics/R/fitFundamentalFactorModel.R
===================================================================
--- pkg/FactorAnalytics/R/fitFundamentalFactorModel.R	2014-04-08 19:23:40 UTC (rev 3356)
+++ pkg/FactorAnalytics/R/fitFundamentalFactorModel.R	2014-04-09 00:29:45 UTC (rev 3357)
@@ -39,7 +39,7 @@
 #' the data.
 #' @param assetvar A character string gives the name of the asset variable in
 #' the data.
-#' @param standardized.factor.exposure logical flag. Factor exposure will be standarized 
+#' @param standardized.factor.exposure logical flag. Factor exposure will be standardized 
 #' to regression weighted mean 0 and standardized deviation to 1 if \code{TRUE}. 
 #' Default is \code{FALSE}. See Detail. 
 #' @param weight.var A character strping gives the name of the weight used for standarizing factor exposures. 

Modified: pkg/FactorAnalytics/R/predict.FundamentalFactorModel.r
===================================================================
--- pkg/FactorAnalytics/R/predict.FundamentalFactorModel.r	2014-04-08 19:23:40 UTC (rev 3356)
+++ pkg/FactorAnalytics/R/predict.FundamentalFactorModel.r	2014-04-09 00:29:45 UTC (rev 3357)
@@ -45,7 +45,7 @@
   numAssets <- length(assets)
   
   f <-  object$factor.returns # T X 3 
-  
+  factor.names <- colnames(f) 
  
   predictor <- function(data) {
     fitted <- rep(NA,numAssets)
@@ -62,16 +62,22 @@
   
   predictor.new <- function(data,datevar,assetvar) {
   
+  
   beta.all <- data[,c(datevar,assetvar,exposure.names)] #  (N * T ) X 4
   names(beta.all)[1:2] <- c("time","assets.names")  
   
+  if (factor.names[1] == "Intercept") {
+  beta.all$Intercept  <- rep(1,numTimePoints*numAssets) 
+  }
+  
   ### calculated fitted values
    
   fitted <- rep(NA,numAssets)
   for (i in 1:numTimePoints) {
-    beta <- subset(beta.all, time == index(f)[i] & assets.names == assets)[,exposure.names]
-    beta <- as.matrix(cbind(rep(1,numAssets),beta))
-    fit.tmp <- beta %*% t(f[i,])
+    beta <- subset(beta.all, time == index(f)[i] & assets.names %in% assets)[,factor.names]
+#     beta <- as.matrix(cbind(rep(1,numAssets),beta))
+   beta <- as.matrix(beta)    
+fit.tmp <- beta %*% t(f[i,])
     fitted <- rbind(fitted,t(fit.tmp))
   }
   fitted <- fitted[-1,]

Modified: pkg/FactorAnalytics/man/fitFundamentalFactorModel.Rd
===================================================================
--- pkg/FactorAnalytics/man/fitFundamentalFactorModel.Rd	2014-04-08 19:23:40 UTC (rev 3356)
+++ pkg/FactorAnalytics/man/fitFundamentalFactorModel.Rd	2014-04-09 00:29:45 UTC (rev 3357)
@@ -46,7 +46,7 @@
   asset variable in the data.}
 
   \item{standardized.factor.exposure}{logical flag. Factor
-  exposure will be standarized to regression weighted mean
+  exposure will be standardized to regression weighted mean
   0 and standardized deviation to 1 if \code{TRUE}. Default
   is \code{FALSE}. See Detail.}
 



More information about the Returnanalytics-commits mailing list