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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed Oct 23 15:00:52 CEST 2013


Author: rossbennett34
Date: 2013-10-23 15:00:51 +0200 (Wed, 23 Oct 2013)
New Revision: 3238

Modified:
   pkg/PortfolioAnalytics/R/optFUN.R
Log:
Fixing bug in gmv_opt_toc

Modified: pkg/PortfolioAnalytics/R/optFUN.R
===================================================================
--- pkg/PortfolioAnalytics/R/optFUN.R	2013-10-22 23:45:22 UTC (rev 3237)
+++ pkg/PortfolioAnalytics/R/optFUN.R	2013-10-23 13:00:51 UTC (rev 3238)
@@ -348,6 +348,13 @@
   bnds <- list(lower=list(ind=seq.int(1L, N), val=as.numeric(constraints$min)),
                upper=list(ind=seq.int(1L, N), val=as.numeric(constraints$max)))
   
+  # Add this check if mean is not an objective and return is a constraints
+  if(!is.na(target)){
+    if(all(moments$mean == 0)){
+      moments$mean <- colMeans(R)
+    }
+  }
+  
   Rmin <- ifelse(is.na(target), 0, target)
   
   Amat <- cbind(rbind(1, 1, moments$mean, coredata(R)), rbind(0, 0, 0, cbind(diag(T), 1))) 
@@ -636,7 +643,7 @@
   
   # Remove the rows of Amat and elements of rhs.vec where rhs is Inf or -Inf
   Amat <- Amat[!is.infinite(rhs), ]
-  rhs <- rhs.vec[!is.infinite(rhs)]
+  rhs <- rhs[!is.infinite(rhs)]
   
   qp.result <- try(solve.QP(Dmat=make.positive.definite(2*lambda*V), 
                             dvec=d, Amat=t(Amat), bvec=rhs, meq=meq), silent=TRUE)



More information about the Returnanalytics-commits mailing list