[Returnanalytics-commits] r2669 - pkg/FactorAnalytics/R

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Mon Jul 29 18:52:01 CEST 2013


Author: chenyian
Date: 2013-07-29 18:52:00 +0200 (Mon, 29 Jul 2013)
New Revision: 2669

Modified:
   pkg/FactorAnalytics/R/plot.FundamentalFactorModel.r
   pkg/FactorAnalytics/R/plot.StatFactorModel.r
   pkg/FactorAnalytics/R/plot.TimeSeriesFactorModel.r
   pkg/FactorAnalytics/R/predict.FundamentalFactorModel.r
Log:
change bar plot colors. 

Modified: pkg/FactorAnalytics/R/plot.FundamentalFactorModel.r
===================================================================
--- pkg/FactorAnalytics/R/plot.FundamentalFactorModel.r	2013-07-29 16:49:31 UTC (rev 2668)
+++ pkg/FactorAnalytics/R/plot.FundamentalFactorModel.r	2013-07-29 16:52:00 UTC (rev 2669)
@@ -91,9 +91,9 @@
            #       "time series plot of actual and fitted values",
          
            plot(actual.z[,asset.name], main=asset.name, ylab="Monthly performance", lwd=2, col="black")
-           lines(fitted.z[,asset.name], lwd=2, col="blue")
+           lines(fitted.z[,asset.name], lwd=2, col="red")
            abline(h=0)
-           legend(x="bottomleft", legend=c("Actual", "Fitted"), lwd=2, col=c("black","blue"))
+           legend(x="bottomleft", legend=c("Actual", "Fitted"), lwd=2, col=c("black","red"))
          },
          "2L"={    
            #       "time series plot of residuals with standard error bands"
@@ -164,12 +164,12 @@
     switch(which.plot,
            
            "1L" = {
-            factor.names <- colnames(fit.fund$factors)
+            factor.names <- colnames(fit.fund$factor.returns)
 #             nn <- length(factor.names)
             par(mfrow=c(n,1))
             options(show.error.messages=FALSE) 
             for (i in factor.names[1:n]) {
-            plot(fit.fund$factors[,i],main=paste(i," Factor Returns",sep="") )
+            plot(fit.fund$factor.returns[,i],main=paste(i," Factor Returns",sep="") )
             }
             par(mfrow=c(1,1))
            }, 
@@ -193,7 +193,7 @@
              plotcorr(ordered.cor.fm[c(1:n),c(1:n)], col=cm.colors(11)[5*ordered.cor.fm + 6])
            },
            "5L" = {
-             cov.factors = var(fit.fund$factors)
+             cov.factors = var(fit.fund$factor.returns)
              names = fit.fund$asset.names
              factor.sd.decomp.list = list()
              for (i in names) {
@@ -207,11 +207,11 @@
              }
              # extract contributions to SD from list
              cr.sd = sapply(factor.sd.decomp.list, getCSD)
-             rownames(cr.sd) = c(colnames(fit.fund$factors), "residual")
-             # create stacked barchart
-             barplot(cr.sd[,(1:max.show)], main="Factor Contributions to SD",
-                     legend.text=legend.txt, args.legend=list(x="topleft"),
-                     col=c(1:50),...)
+             rownames(cr.sd) = c(colnames(fit.fund$factor.returns), "residual")
+             # create stacked barchart 
+             # discard intercept 
+             barplot(cr.sd[-1,(1:max.show)], main="Factor Contributions to SD",
+                     legend.text=legend.txt, args.legend=list(x="topleft"),...)
            } ,
            "6L" = {
            factor.es.decomp.list = list()
@@ -221,7 +221,7 @@
 #             idx = which(!is.na(fit.fund$data[,i]))
              idx <- fit.fund$data[,fit.fund$assetvar]  == i  
              asset.ret <- fit.fund$data[idx,fit.fund$returnsvar]
-             tmpData = cbind(asset.ret, fit.fund$factors,
+             tmpData = cbind(asset.ret, fit.fund$factor.returns,
                              fit.fund$residuals[,i]/sqrt(fit.fund$resid.variance[i]) )
              colnames(tmpData)[c(1,length(tmpData[1,]))] = c(i, "residual")
              factor.es.decomp.list[[i]] = 
@@ -236,10 +236,9 @@
            }
            # report as positive number
            cr.etl = sapply(factor.es.decomp.list, getCETL)
-           rownames(cr.etl) = c(colnames(fit.fund$factors), "residual")
-           barplot(cr.etl[,(1:max.show)], main="Factor Contributions to ES",
-                   legend.text=legend.txt, args.legend=list(x="topleft"),
-                   col=c(1:50),...)
+           rownames(cr.etl) = c(colnames(fit.fund$factor.returns), "residual")
+           barplot(cr.etl[-1,(1:max.show)], main="Factor Contributions to ES",
+                   legend.text=legend.txt, args.legend=list(x="topleft"),...)
            },
            "7L" =  {
              factor.VaR.decomp.list = list()
@@ -249,7 +248,7 @@
                #             idx = which(!is.na(fit.fund$data[,i]))
                idx <- fit.fund$data[,fit.fund$assetvar]  == i  
                asset.ret <- fit.fund$data[idx,fit.fund$returnsvar]
-               tmpData = cbind(asset.ret, fit.fund$factors,
+               tmpData = cbind(asset.ret, fit.fund$factor.returns,
                                fit.fund$residuals[,i]/sqrt(fit.fund$resid.variance[i]) )
                colnames(tmpData)[c(1,length(tmpData[1,]))] = c(i, "residual")
                factor.VaR.decomp.list[[i]] = 
@@ -265,10 +264,9 @@
              }
              # report as positive number
              cr.var = sapply(factor.VaR.decomp.list, getCVaR)
-             rownames(cr.var) = c(colnames(fit.fund$factors), "residual")
-             barplot(cr.var[,(1:max.show)], main="Factor Contributions to VaR",
-                     legend.text=legend.txt, args.legend=list(x="topleft"),
-                     col=c(1:50),...)
+             rownames(cr.var) = c(colnames(fit.fund$factor.returns), "residual")
+             barplot(cr.var[-1,(1:max.show)], main="Factor Contributions to VaR",
+                     legend.text=legend.txt, args.legend=list(x="topleft"),...)
            },
            invisible()       
     )         

Modified: pkg/FactorAnalytics/R/plot.StatFactorModel.r
===================================================================
--- pkg/FactorAnalytics/R/plot.StatFactorModel.r	2013-07-29 16:49:31 UTC (rev 2668)
+++ pkg/FactorAnalytics/R/plot.StatFactorModel.r	2013-07-29 16:52:00 UTC (rev 2669)
@@ -166,9 +166,9 @@
            "1L" =  {
              ##  time series plot of actual and fitted values
              plot(actual.z, main=asset.name, ylab="Monthly performance", lwd=2, col="black")
-             lines(fitted.z, lwd=2, col="blue")
+             lines(fitted.z, lwd=2, col="red")
              abline(h=0)
-             legend(x="bottomleft", legend=c("Actual", "Fitted"), lwd=2, col=c("black","blue"))
+             legend(x="bottomleft", legend=c("Actual", "Fitted"), lwd=2, col=c("black","red"))
            }, 
            
            "2L" = {
@@ -270,9 +270,9 @@
 #       "time series plot of actual and fitted values",
        
        plot(actual.z[,asset.name], main=asset.name, ylab="Monthly performance", lwd=2, col="black")
-       lines(fitted.z[,asset.name], lwd=2, col="blue")
+       lines(fitted.z[,asset.name], lwd=2, col="red")
        abline(h=0)
-       legend(x="bottomleft", legend=c("Actual", "Fitted"), lwd=2, col=c("black","blue"))
+       legend(x="bottomleft", legend=c("Actual", "Fitted"), lwd=2, col=c("black","red"))
              },
           "2L"={    
 #       "time series plot of residuals with standard error bands"
@@ -397,8 +397,7 @@
       rownames(cr.sd) = c(colnames(fit.stat$factors), "residual")
       # create stacked barchart
       barplot(cr.sd[,(1:max.show)], main="Factor Contributions to SD",
-              legend.text=T, args.legend=list(x="topleft"),
-              col=c(1:50) )
+              legend.text=T, args.legend=list(x="topleft"))
     } ,
     "7L" ={
       factor.es.decomp.list = list()
@@ -424,8 +423,7 @@
              cr.etl = sapply(factor.es.decomp.list, getCETL)
              rownames(cr.etl) = c(colnames(fit.stat$factors), "residual")
              barplot(cr.etl[,(1:max.show)], main="Factor Contributions to ES",
-                     legend.text=T, args.legend=list(x="topleft"),
-                     col=c(1:50) )
+                     legend.text=T, args.legend=list(x="topleft") )
     },
       "8L" =  {
              factor.VaR.decomp.list = list()
@@ -451,8 +449,7 @@
              cr.var = sapply(factor.VaR.decomp.list, getCVaR)
              rownames(cr.var) = c(colnames(fit.stat$factors), "residual")
              barplot(cr.var[,(1:max.show)], main="Factor Contributions to VaR",
-                     legend.text=T, args.legend=list(x="topleft"),
-                     col=c(1:50) )
+                     legend.text=T, args.legend=list(x="topleft"))
       }, invisible()
                  
      )

Modified: pkg/FactorAnalytics/R/plot.TimeSeriesFactorModel.r
===================================================================
--- pkg/FactorAnalytics/R/plot.TimeSeriesFactorModel.r	2013-07-29 16:49:31 UTC (rev 2668)
+++ pkg/FactorAnalytics/R/plot.TimeSeriesFactorModel.r	2013-07-29 16:52:00 UTC (rev 2669)
@@ -370,8 +370,7 @@
        rownames(cr.sd) = c(factor.names, "residual")
       # create stacked barchart
        barplot(cr.sd, main="Factor Contributions to SD",
-                 legend.text=T, args.legend=list(x="topleft"),
-                 col=c(1:50) )
+                 legend.text=T, args.legend=list(x="topleft"))
       
     },
      "6L"={
@@ -416,8 +415,7 @@
        cr.etl = sapply(factor.es.decomp.list, getCETL)
        rownames(cr.etl) = c(factor.names, "residual")
        barplot(cr.etl, main="Factor Contributions to ES",
-               legend.text=T, args.legend=list(x="topleft"),
-               col=c(1:50) ) 
+               legend.text=T, args.legend=list(x="topleft")) 
      },
     "7L" ={
       
@@ -463,8 +461,7 @@
       cr.VaR = sapply(factor.VaR.decomp.list, getCVaR)
       rownames(cr.VaR) = c(factor.names, "residual")
       barplot(cr.VaR, main="Factor Contributions to VaR",
-              legend.text=T, args.legend=list(x="topleft"),
-              col=c(1:50) )
+              legend.text=T, args.legend=list(x="topleft"))
     },
     invisible()       
     )         

Modified: pkg/FactorAnalytics/R/predict.FundamentalFactorModel.r
===================================================================
--- pkg/FactorAnalytics/R/predict.FundamentalFactorModel.r	2013-07-29 16:49:31 UTC (rev 2668)
+++ pkg/FactorAnalytics/R/predict.FundamentalFactorModel.r	2013-07-29 16:52:00 UTC (rev 2669)
@@ -27,7 +27,7 @@
   numExposures <- length(exposure.names)
   numAssets <- length(assets)
   
-  f <-  fit.fund$factors # T X 3 
+  f <-  fit.fund$factor.returns # T X 3 
   
  
   predictor <- function(data) {



More information about the Returnanalytics-commits mailing list