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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Mon Aug 26 20:23:58 CEST 2013


Author: rossbennett34
Date: 2013-08-26 20:23:57 +0200 (Mon, 26 Aug 2013)
New Revision: 2894

Modified:
   pkg/PortfolioAnalytics/R/optFUN.R
Log:
modifying functions in optFUN to construct the group matrix for Amat constraints matrix

Modified: pkg/PortfolioAnalytics/R/optFUN.R
===================================================================
--- pkg/PortfolioAnalytics/R/optFUN.R	2013-08-26 18:12:59 UTC (rev 2893)
+++ pkg/PortfolioAnalytics/R/optFUN.R	2013-08-26 18:23:57 UTC (rev 2894)
@@ -29,13 +29,8 @@
   if(try(!is.null(constraints$groups), silent=TRUE)){
     n.groups <- length(constraints$groups)
     Amat.group <- matrix(0, nrow=n.groups, ncol=N)
-    k <- 1
-    l <- 0
     for(i in 1:n.groups){
-      j <- constraints$groups[i] 
-      Amat.group[i, k:(l+j)] <- 1
-      k <- l + j + 1
-      l <- k - 1
+      Amat.group[i, groups[[i]]] <- 1
     }
     if(is.null(constraints$cLO)) cLO <- rep(-Inf, n.groups)
     if(is.null(constraints$cUP)) cUP <- rep(Inf, n.groups)
@@ -94,13 +89,8 @@
   if(try(!is.null(constraints$groups), silent=TRUE)){
     n.groups <- length(constraints$groups)
     Amat.group <- matrix(0, nrow=n.groups, ncol=N)
-    k <- 1
-    l <- 0
     for(i in 1:n.groups){
-      j <- constraints$groups[i] 
-      Amat.group[i, k:(l+j)] <- 1
-      k <- l + j + 1
-      l <- k - 1
+      Amat.group[i, groups[[i]]] <- 1
     }
     if(is.null(constraints$cLO)) cLO <- rep(-Inf, n.groups)
     if(is.null(constraints$cUP)) cUP <- rep(Inf, n.groups)
@@ -184,13 +174,8 @@
   if(try(!is.null(constraints$groups), silent=TRUE)){
     n.groups <- length(constraints$groups)
     Amat.group <- matrix(0, nrow=n.groups, ncol=N)
-    k <- 1
-    l <- 0
     for(i in 1:n.groups){
-      j <- constraints$groups[i] 
-      Amat.group[i, k:(l+j)] <- 1
-      k <- l + j + 1
-      l <- k - 1
+      Amat.group[i, groups[[i]]] <- 1
     }
     if(is.null(constraints$cLO)) cLO <- rep(-Inf, n.groups)
     if(is.null(constraints$cUP)) cUP <- rep(Inf, n.groups)
@@ -257,13 +242,8 @@
   if(try(!is.null(constraints$groups), silent=TRUE)){
     n.groups <- length(constraints$groups)
     Amat.group <- matrix(0, nrow=n.groups, ncol=N)
-    k <- 1
-    l <- 0
     for(i in 1:n.groups){
-      j <- constraints$groups[i] 
-      Amat.group[i, k:(l+j)] <- 1
-      k <- l + j + 1
-      l <- k - 1
+      Amat.group[i, groups[[i]]] <- 1
     }
     if(is.null(constraints$cLO)) cLO <- rep(-Inf, n.groups)
     if(is.null(constraints$cUP)) cUP <- rep(Inf, n.groups)
@@ -362,13 +342,8 @@
   if(try(!is.null(constraints$groups), silent=TRUE)){
     n.groups <- length(constraints$groups)
     Amat.group <- matrix(0, nrow=n.groups, ncol=m)
-    k <- 1
-    l <- 0
     for(i in 1:n.groups){
-      j <- constraints$groups[i] 
-      Amat.group[i, k:(l+j)] <- 1
-      k <- l + j + 1
-      l <- k - 1
+      Amat.group[i, groups[[i]]] <- 1
     }
     if(is.null(constraints$cLO)) cLO <- rep(-Inf, n.groups)
     if(is.null(constraints$cUP)) cUP <- rep(Inf, n.groups)



More information about the Returnanalytics-commits mailing list