[Returnanalytics-commits] r2885 - pkg/PortfolioAnalytics/R

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sun Aug 25 19:49:32 CEST 2013


Author: rossbennett34
Date: 2013-08-25 19:49:32 +0200 (Sun, 25 Aug 2013)
New Revision: 2885

Modified:
   pkg/PortfolioAnalytics/R/charts.DE.R
   pkg/PortfolioAnalytics/R/charts.GenSA.R
   pkg/PortfolioAnalytics/R/charts.PSO.R
   pkg/PortfolioAnalytics/R/charts.ROI.R
   pkg/PortfolioAnalytics/R/charts.RP.R
Log:
Modified chart.Weights.* functions to plot negative weights and handle Inf or -Inf in box constraints.

Modified: pkg/PortfolioAnalytics/R/charts.DE.R
===================================================================
--- pkg/PortfolioAnalytics/R/charts.DE.R	2013-08-25 17:12:28 UTC (rev 2884)
+++ pkg/PortfolioAnalytics/R/charts.DE.R	2013-08-25 17:49:32 UTC (rev 2885)
@@ -38,9 +38,20 @@
     bottommargin = minmargin
   }
   par(mar = c(bottommargin, 4, topmargin, 2) +.1)
-  plot(object$weights, type="b", col="blue", axes=FALSE, xlab='', ylim=c(0,max(constraints$max)), ylab="Weights", main=main, pch=16, ...)
-  points(constraints$min, type="b", col="darkgray", lty="solid", lwd=2, pch=24)
-  points(constraints$max, type="b", col="darkgray", lty="solid", lwd=2, pch=25)
+  if(any(is.infinite(constraints$max)) | any(is.infinite(constraints$min))){
+    # set ylim based on weights if box constraints contain Inf or -Inf
+    ylim <- range(object$weights)
+  } else {
+    # set ylim based on the range of box constraints min and max
+    ylim <- range(c(constraints$min, constraints$max))
+  }
+  plot(object$weights, type="b", col="blue", axes=FALSE, xlab='', ylim=ylim, ylab="Weights", main=main, pch=16, ...)
+  if(!any(is.infinite(constraints$min))){
+    points(constraints$min, type="b", col="darkgray", lty="solid", lwd=2, pch=24)
+  }
+  if(!any(is.infinite(constraints$max))){
+    points(constraints$max, type="b", col="darkgray", lty="solid", lwd=2, pch=25)
+  }
   #     if(!is.null(neighbors)){ 
   #         if(is.vector(neighbors)){
   #             xtract=extractStats(object)

Modified: pkg/PortfolioAnalytics/R/charts.GenSA.R
===================================================================
--- pkg/PortfolioAnalytics/R/charts.GenSA.R	2013-08-25 17:12:28 UTC (rev 2884)
+++ pkg/PortfolioAnalytics/R/charts.GenSA.R	2013-08-25 17:49:32 UTC (rev 2885)
@@ -27,9 +27,20 @@
     bottommargin = minmargin
   }
   par(mar = c(bottommargin, 4, topmargin, 2) +.1)
-  plot(object$weights, type="b", col="blue", axes=FALSE, xlab='', ylim=c(0,max(constraints$max)), ylab="Weights", main=main, pch=16, ...)
-  points(constraints$min, type="b", col="darkgray", lty="solid", lwd=2, pch=24)
-  points(constraints$max, type="b", col="darkgray", lty="solid", lwd=2, pch=25)
+  if(any(is.infinite(constraints$max)) | any(is.infinite(constraints$min))){
+    # set ylim based on weights if box constraints contain Inf or -Inf
+    ylim <- range(object$weights)
+  } else {
+    # set ylim based on the range of box constraints min and max
+    ylim <- range(c(constraints$min, constraints$max))
+  }
+  plot(object$weights, type="b", col="blue", axes=FALSE, xlab='', ylim=ylim, ylab="Weights", main=main, pch=16, ...)
+  if(!any(is.infinite(constraints$min))){
+    points(constraints$min, type="b", col="darkgray", lty="solid", lwd=2, pch=24)
+  }
+  if(!any(is.infinite(constraints$max))){
+    points(constraints$max, type="b", col="darkgray", lty="solid", lwd=2, pch=25)
+  }
   #     if(!is.null(neighbors)){ 
   #         if(is.vector(neighbors)){
   #             xtract=extractStats(ROI)

Modified: pkg/PortfolioAnalytics/R/charts.PSO.R
===================================================================
--- pkg/PortfolioAnalytics/R/charts.PSO.R	2013-08-25 17:12:28 UTC (rev 2884)
+++ pkg/PortfolioAnalytics/R/charts.PSO.R	2013-08-25 17:49:32 UTC (rev 2885)
@@ -27,9 +27,20 @@
     bottommargin = minmargin
   }
   par(mar = c(bottommargin, 4, topmargin, 2) +.1)
-  plot(object$weights, type="b", col="blue", axes=FALSE, xlab='', ylim=c(0,max(constraints$max)), ylab="Weights", main=main, pch=16, ...)
-  points(constraints$min, type="b", col="darkgray", lty="solid", lwd=2, pch=24)
-  points(constraints$max, type="b", col="darkgray", lty="solid", lwd=2, pch=25)
+  if(any(is.infinite(constraints$max)) | any(is.infinite(constraints$min))){
+    # set ylim based on weights if box constraints contain Inf or -Inf
+    ylim <- range(object$weights)
+  } else {
+    # set ylim based on the range of box constraints min and max
+    ylim <- range(c(constraints$min, constraints$max))
+  }
+  plot(object$weights, type="b", col="blue", axes=FALSE, xlab='', ylim=ylim, ylab="Weights", main=main, pch=16, ...)
+  if(!any(is.infinite(constraints$min))){
+    points(constraints$min, type="b", col="darkgray", lty="solid", lwd=2, pch=24)
+  }
+  if(!any(is.infinite(constraints$max))){
+    points(constraints$max, type="b", col="darkgray", lty="solid", lwd=2, pch=25)
+  }
   #     if(!is.null(neighbors)){ 
   #         if(is.vector(neighbors)){
   #             xtract=extractStats(ROI)

Modified: pkg/PortfolioAnalytics/R/charts.ROI.R
===================================================================
--- pkg/PortfolioAnalytics/R/charts.ROI.R	2013-08-25 17:12:28 UTC (rev 2884)
+++ pkg/PortfolioAnalytics/R/charts.ROI.R	2013-08-25 17:49:32 UTC (rev 2885)
@@ -27,9 +27,20 @@
     bottommargin = minmargin
   }
   par(mar = c(bottommargin, 4, topmargin, 2) +.1)
-  plot(object$weights, type="b", col="blue", axes=FALSE, xlab='', ylim=c(0,max(constraints$max)), ylab="Weights", main=main, pch=16, ...)
-  points(constraints$min, type="b", col="darkgray", lty="solid", lwd=2, pch=24)
-  points(constraints$max, type="b", col="darkgray", lty="solid", lwd=2, pch=25)
+  if(any(is.infinite(constraints$max)) | any(is.infinite(constraints$min))){
+    # set ylim based on weights if box constraints contain Inf or -Inf
+    ylim <- range(object$weights)
+  } else {
+    # set ylim based on the range of box constraints min and max
+    ylim <- range(c(constraints$min, constraints$max))
+  }
+  plot(object$weights, type="b", col="blue", axes=FALSE, xlab='', ylim=ylim, ylab="Weights", main=main, pch=16, ...)
+  if(!any(is.infinite(constraints$min))){
+    points(constraints$min, type="b", col="darkgray", lty="solid", lwd=2, pch=24)
+  }
+  if(!any(is.infinite(constraints$max))){
+    points(constraints$max, type="b", col="darkgray", lty="solid", lwd=2, pch=25)
+  }
   #     if(!is.null(neighbors)){ 
   #         if(is.vector(neighbors)){
   #             xtract=extractStats(object)

Modified: pkg/PortfolioAnalytics/R/charts.RP.R
===================================================================
--- pkg/PortfolioAnalytics/R/charts.RP.R	2013-08-25 17:12:28 UTC (rev 2884)
+++ pkg/PortfolioAnalytics/R/charts.RP.R	2013-08-25 17:49:32 UTC (rev 2885)
@@ -41,9 +41,20 @@
     bottommargin = minmargin
   }
   par(mar = c(bottommargin, 4, topmargin, 2) +.1)
-  plot(object$random_portfolios[1,], type="b", col="orange", axes=FALSE, xlab='', ylim=c(0,max(constraints$max)), ylab="Weights", main=main, ...)
-  points(constraints$min, type="b", col="darkgray", lty="solid", lwd=2, pch=24)
-  points(constraints$max, type="b", col="darkgray", lty="solid", lwd=2, pch=25)
+  if(any(is.infinite(constraints$max)) | any(is.infinite(constraints$min))){
+    # set ylim based on weights if box constraints contain Inf or -Inf
+    ylim <- range(object$weights)
+  } else {
+    # set ylim based on the range of box constraints min and max
+    ylim <- range(c(constraints$min, constraints$max))
+  }
+  plot(object$random_portfolios[1,], type="b", col="orange", axes=FALSE, xlab='', ylim=ylim, ylab="Weights", main=main, ...)
+  if(!any(is.infinite(constraints$min))){
+    points(constraints$min, type="b", col="darkgray", lty="solid", lwd=2, pch=24)
+  }
+  if(!any(is.infinite(constraints$max))){
+    points(constraints$max, type="b", col="darkgray", lty="solid", lwd=2, pch=25)
+  }
   if(!is.null(neighbors)){ 
     if(is.vector(neighbors)){
       xtract=extractStats(object)



More information about the Returnanalytics-commits mailing list