[Returnanalytics-commits] r3107 - in pkg/PortfolioAnalytics: R man

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sun Sep 15 02:04:44 CEST 2013


Author: rossbennett34
Date: 2013-09-15 02:04:44 +0200 (Sun, 15 Sep 2013)
New Revision: 3107

Modified:
   pkg/PortfolioAnalytics/R/extract.efficient.frontier.R
   pkg/PortfolioAnalytics/R/generics.R
   pkg/PortfolioAnalytics/R/objectiveFUN.R
   pkg/PortfolioAnalytics/R/random_portfolios.R
   pkg/PortfolioAnalytics/man/random_portfolios.Rd
Log:
Added group names to Groups_HHI output. Added category labels to print method for portfolio objects. Fixed bug in meanvar.efficient.frontier to allow more then 2 objectives. Fixed documentation for random_portfolios.

Modified: pkg/PortfolioAnalytics/R/extract.efficient.frontier.R
===================================================================
--- pkg/PortfolioAnalytics/R/extract.efficient.frontier.R	2013-09-14 17:26:06 UTC (rev 3106)
+++ pkg/PortfolioAnalytics/R/extract.efficient.frontier.R	2013-09-15 00:04:44 UTC (rev 3107)
@@ -131,7 +131,7 @@
   }
   
   # for a mean-var efficient frontier, there must be two objectives 1) "mean" and 2) "var"
-  if(!((length(objnames) == 2) & ("var" %in% objnames) & ("mean" %in% objnames))){
+  if(!((length(objnames) >= 2) & ("var" %in% objnames) & ("mean" %in% objnames))){
     stop("The portfolio object must have both 'mean' and 'var' specified as objectives")
   }
   

Modified: pkg/PortfolioAnalytics/R/generics.R
===================================================================
--- pkg/PortfolioAnalytics/R/generics.R	2013-09-14 17:26:06 UTC (rev 3106)
+++ pkg/PortfolioAnalytics/R/generics.R	2013-09-15 00:04:44 UTC (rev 3107)
@@ -70,6 +70,21 @@
     cat("More than 10 assets, only printing the first 10\n")
   }
   
+  # Category labels
+  if(!is.null(x$category_labels)){
+    cat("\nCategory Labels\n")
+    cat_labels <- x$category_labels
+    for(i in 1:min(10, length(cat_labels))){
+      cat(names(cat_labels)[i],": ")
+      tmp <- names(x$assets[cat_labels[[i]]])
+      cat(tmp, "\n")
+    }
+    if(length(cat_labels) > 10){
+      cat("More than 10 categories, only printing the first 10\n")
+    }
+    cat("\n")
+  }
+  
   # Constraints
   cat("\nConstraints\n")
   nconstraints <- length(x$constraints)
@@ -263,16 +278,16 @@
   names(tmp_obj) <- names(objective_measures)
   cat("Objective Measure:\n")
   for(i in 1:length(objective_measures)){
-    print(tmp_obj[i], digits=4)
+    print(tmp_obj[i], digits=digits)
     cat("\n")
     if(length(objective_measures[[i]]) > 1){
       # This will be the case for any objective measures with HHI for QP problems
       for(j in 2:length(objective_measures[[i]])){
         tmpl <- objective_measures[[i]][j]
-        cat(names(tmpl), ":\n")
+        cat(names(tmpl), "\n")
         tmpv <- unlist(tmpl)
-        # names(tmpv) <- names(x$weights)
-        print(tmpv)
+        names(tmpv) <- gsub(paste(names(tmpl), ".", sep=""), "", names(tmpv))
+        print.default(round(tmpv, digits=digits), digits=digits)
         cat("\n")
       }
     }

Modified: pkg/PortfolioAnalytics/R/objectiveFUN.R
===================================================================
--- pkg/PortfolioAnalytics/R/objectiveFUN.R	2013-09-14 17:26:06 UTC (rev 3106)
+++ pkg/PortfolioAnalytics/R/objectiveFUN.R	2013-09-15 00:04:44 UTC (rev 3107)
@@ -54,10 +54,11 @@
   if(!is.null(groups)){
     ngroups <- length(groups)
     group_hhi <- rep(0, ngroups)
+    if(!is.null((names(groups)))) names(group_hhi) <- names(groups)
     for(i in 1:ngroups){
       group_hhi[i] <- sum(weights[groups[[i]]]^2)
     }
-    return(list(hhi=hhi, group_hhi=group_hhi))
+    return(list(HHI=hhi, Groups_HHI=group_hhi))
   } else {
     return(hhi)
   }

Modified: pkg/PortfolioAnalytics/R/random_portfolios.R
===================================================================
--- pkg/PortfolioAnalytics/R/random_portfolios.R	2013-09-14 17:26:06 UTC (rev 3106)
+++ pkg/PortfolioAnalytics/R/random_portfolios.R	2013-09-15 00:04:44 UTC (rev 3107)
@@ -334,7 +334,7 @@
 #'   limit constraints will be handled by elimination. If the constraints are 
 #'   very restrictive, this may result in very few feasible portfolios remaining.}
 #'   \item{grid: }{The 'grid' method to generate random portfolios is based on
-#'   the \code(gridSearch} function in package 'NMOF'. The grid search method 
+#'   the \code{gridSearch} function in package 'NMOF'. The grid search method 
 #'   only satisfies the \code{min} and \code{max} box constraints. The 
 #'   \code{min_sum} and \code{max_sum} leverage constraints will likely be 
 #'   violated and the weights in the random portfolios should be normalized. 

Modified: pkg/PortfolioAnalytics/man/random_portfolios.Rd
===================================================================
--- pkg/PortfolioAnalytics/man/random_portfolios.Rd	2013-09-14 17:26:06 UTC (rev 3106)
+++ pkg/PortfolioAnalytics/man/random_portfolios.Rd	2013-09-15 00:04:44 UTC (rev 3107)
@@ -48,7 +48,7 @@
   very restrictive, this may result in very few feasible
   portfolios remaining.} \item{grid: }{The 'grid' method to
   generate random portfolios is based on the
-  \code(gridSearch} function in package 'NMOF'. The grid
+  \code{gridSearch} function in package 'NMOF'. The grid
   search method only satisfies the \code{min} and
   \code{max} box constraints. The \code{min_sum} and
   \code{max_sum} leverage constraints will likely be



More information about the Returnanalytics-commits mailing list