[Returnanalytics-commits] r3002 - in pkg/PortfolioAnalytics: R sandbox

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Thu Sep 5 20:08:13 CEST 2013


Author: rossbennett34
Date: 2013-09-05 20:08:13 +0200 (Thu, 05 Sep 2013)
New Revision: 3002

Modified:
   pkg/PortfolioAnalytics/R/charts.groups.R
   pkg/PortfolioAnalytics/sandbox/testing_weight_conc.R
Log:
Modifying barplotGroupWeights and testing script for weight concentration averision

Modified: pkg/PortfolioAnalytics/R/charts.groups.R
===================================================================
--- pkg/PortfolioAnalytics/R/charts.groups.R	2013-09-05 17:12:44 UTC (rev 3001)
+++ pkg/PortfolioAnalytics/R/charts.groups.R	2013-09-05 18:08:13 UTC (rev 3002)
@@ -116,7 +116,6 @@
   
   constraints <- get_constraints(object$portfolio)
   tmp <- extractGroups(object)
-  grouping <- "groups"
   
   if(grouping == "groups"){
     weights <- tmp$group_weights

Modified: pkg/PortfolioAnalytics/sandbox/testing_weight_conc.R
===================================================================
--- pkg/PortfolioAnalytics/sandbox/testing_weight_conc.R	2013-09-05 17:12:44 UTC (rev 3001)
+++ pkg/PortfolioAnalytics/sandbox/testing_weight_conc.R	2013-09-05 18:08:13 UTC (rev 3002)
@@ -39,12 +39,23 @@
 opt2
 all.equal(opt1$weights, opt2$weights)
 
-# Now change the conc_aversion values to give highest penalty to small cap stocks
-conc$objectives[[2]]$conc_aversion <- c(0.05, 1, 0.1, 0)
+# From the chart we can see that the allocation to MGF is very high.
+chart.Weights(opt2)
+
+# MGF is part of the SMALL group
+# Now change the conc_aversion values
+conc$objectives[[2]]$conc_aversion <- c(0.1, 0.05, 0.1, 0)
 opt3 <- optimize.portfolio(R=R, portfolio=conc, optimize_method="ROI", trace=TRUE)
 opt3
 
+chart.Weights(opt3)
+
+# We do not have a group constraint, but we can plot the groups based on
+# category labels in the portfolio object
+chart.GroupWeights(opt3, grouping="category", plot.type="barplot", col=bluemono)
+
 # If all the conc_aversion values are very high, this should result in an equal weight portfolio
 conc$objectives[[2]]$conc_aversion <- rep(1e6, 4)
 opt4 <- optimize.portfolio(R=R, portfolio=conc, optimize_method="ROI", trace=TRUE)
 opt4
+chart.Weights(opt4)



More information about the Returnanalytics-commits mailing list