[R-SIG-Finance] How to feed minvariancePortfolio with ones own covariance matrix (sigma) and means (mu)

R. Vince rvince99 at earthlink.net
Sat Aug 15 19:41:09 CEST 2009

 I too have been trying to use some of the efficient frontier functions (in 
package fPortfolio). I must be doing something very stupd. Working from the 
example (from the help file page, included herein below), when I go to 
create the Data object, I get:

> Data = Data[, c("GOOG", "MSFT", "JNJ")]
Error: subscript out of bounds

I'm truly at a loss here. Can someone please point me in the right direction 
as to how to create the Data Object? I think there must be a mistake in the 
help file, or I'm just very confused about it. Thanks, RVince

------ Help File Page I am working from:------------------

efficientPortfolio(fPortfolio) R Documentation

Efficient Portfolios
Returns efficient portfolios.

efficientPortfolio(data, spec = portfolioSpec(), constraints = "LongOnly")

maxratioPortfolio(data, spec = portfolioSpec(), constraints = "LongOnly")
tangencyPortfolio(data, spec = portfolioSpec(), constraints = "LongOnly")

minriskPortfolio(data, spec = portfolioSpec(), constraints = "LongOnly")
minvariancePortfolio(data, spec = portfolioSpec(), constraints = "LongOnly")

maxreturnPortfolio(data, spec = portfolioSpec(), constraints = "LongOnly")

constraints a character string vector, containing the constraints of the 
"minW[asset]=percentage" for box constraints resp.
"maxsumW[assets]=percentage" for sector constraints.
data a multivariate time series described by an S4 object of class 
timeSeries. If your timeSerie is not a timeSeries object, consult the 
generic function as.timeSeries to convert your time series.
spec an S4 object of class fPFOLIOSPEC as returned by the function 

Efficient Portfolio:

An efficient portfolio is a portfolio which lies on the efficient frontier. 
The efficientPortfolio function returns the properties of the efficient 
portfolio as an S4 object of class fPORTFOLIO.

Minumum Risk or Tangency Portfolio:

The function tangencyPortfolio returns the portfolio with the highest 
return/risk ratio on the efficient frontier. For the Markowitz portfolio 
this is the same as the Sharpe ratio. To find this point on the frontier the 
return/risk ratio calculated from the target return and target risk returned 
by the function efficientPortfolio.

Global minimum risk or Minimum Variance Portfolio:

The function minvariancePortfolio returns the portfolio with the minimal 
risk on the efficient frontier. To find the minimal risk point the target 
risk returned by the function efficientPortfolio is minimized.

Maximum Return Portfolio:

The function maxreturnPortfolio returns the portfolio with the maximal 
return for a fixed target risk.

returns an S4 object of class "fPORTFOLIO".

Wuertz, D., Chalabi, Y., Chen W., Ellis A. (2009); Portfolio Optimization 
with R/Rmetrics, Rmetrics eBook, Rmetrics Association and Finance Online, 

## data -
   Data = Data[, c("BKE", "GG", "GYMB", "KRON")]

## spec -
   Spec = portfolioSpec()
   setTargetReturn(Spec) = mean(colMeans(Data))

## constraints -
   Constraints = "LongOnly"

## efficientPortfolio -
   efficientPortfolio(Data, Spec, Constraints)

## tangency Portfolio -
   tangencyPortfolio(Data, Spec, Constraints)

## minvariancePortfolio -
   minvariancePortfolio(Data, Spec, Constraints)

More information about the R-SIG-Finance mailing list