I realize this topic has been hashed to death but i think the multitude of
answers is confusing me.

I have mu,hat and cov.hat and a time series object of returns.
I want the minimum variance portfolio without short sales

Is there a basic function somewhere that does that? I'm finding
minvariancePortfolio in Fportfolio a little tricky to use.

I am trying the optimizeportfolio routine in PortfolioAnalytics. But the
results seem a bit odd.

I have some code from Eric Zivot's website to compute the global minimum
variance portfolio (see below).
When I run it on a simple 4 asset example, I don't get the same result as
optimize.portfolio, and in
fact the optimize.portfolio weights give a larger portfolio variance.

Here is the call for optimize.portoflio:

myconstr=constraint(assets=4, min_sum=1, max_sum=1, min=-100,
max=100,weight_seq=generatesequence())
optimize.portfolio(myrets,myconstr)

Has someone written a nice wrapper to easily get the min variance portfolio
wo short sales?
Any ideas why Eric's code (which I trust) gives a different answer from
opitimize.portfolio?

Thanks! Sorry for the cluelessness.

globalMin.portfolio <-
function(er, cov.mat)
{
  # Compute global minimum variance portfolio
  #
  # inputs:
  # er				N x 1 vector of expected returns
  # cov.mat		N x N return covariance matrix
  #
  # output is portfolio object with the following elements
  # call			original function call
  # er				portfolio expected return
  # sd				portfolio standard deviation
  # weights		N x 1 vector of portfolio weights
  call <- match.call()

  #
  # check for valid inputs
  #
  asset.names <- names(er)
  er <- as.vector(er)					# assign names if none exist
  cov.mat <- as.matrix(cov.mat)
  if(length(er) != nrow(cov.mat))
    stop("invalid inputs")
  if(any(diag(chol(cov.mat)) <= 0))
    stop("Covariance matrix not positive definite")
  # remark: could use generalized inverse if cov.mat is positive semi-definite

  #
  # compute global minimum portfolio
  #
  cov.mat.inv <- solve(cov.mat)
  one.vec <- rep(1,length(er))
#  w.gmin <- cov.mat.inv %*% one.vec/as.vector(one.vec %*% cov.mat.inv
%*% one.vec)
  w.gmin <- rowSums(cov.mat.inv) / sum(cov.mat.inv)
  w.gmin <- as.vector(w.gmin)
  names(w.gmin) <- asset.names
  er.gmin <- crossprod(w.gmin,er)
  sd.gmin <- sqrt(t(w.gmin) %*% cov.mat %*% w.gmin)
  gmin.port <- list("call" = call,
		    "er" = as.vector(er.gmin),
		    "sd" = as.vector(sd.gmin),
		    "weights" = w.gmin)
  class(gmin.port) <- "portfolio"
  gmin.port
}

	[[alternative HTML version deleted]]

