[R-SIG-Finance] Specifying an expected mu and Sigma for fPortfolio

Voss, Kent VOSSK at kochind.com
Wed Mar 4 01:06:10 CET 2009

I've read the other post on this topic that suggests specifying a custom
estimator, but I cannot seem to even get that to work as I had expected.

Below is the code to replicate my issue and illustrates what I'm trying
to do.  Essentially I am trying to override the calculation of the mu
and Sigma in the Estimator and replace it with static data.  This should
yield the same optimization results regardless of what data I send to
the estimator (since I'm overriding it), but it does not appear to work
for me that way.  Please see the code below for details.  Any help at
all would be greatly appreciated.  



#### OBJECTIVE:  Specify an expected return and covariance matrix for
use in the optimization

# Define the data to be used in the example
Data <- as.timeSeries(data(smallcap.ts))
Data <- Data[,1:3]

# Create an expected return and covariance matrix based on the first 12
# It could be anything, but just to create a static expected return and
cov matrix
# In reality the expected returns are not generated from the historical
data, and so
# feeding the estimator a paricular slice of data is not a workable
ExpRet <- apply(head(Data,12), 2, mean)
ExpCov <- cov(head(Data,12))

# Now what I would like to do is to just feed the expected return and
# matrix to one of the fPorfolio functions like "portfolioFrontier"

# The only way I can think to do that based on what I've found is to
# specify a custom Estimator, that just disregards what's passed to it
# and sends back the expected return and covariance matrix.
# This seems a silly way to do it, and I'm sure there's a better way,
# in a pinch, I had hoped this would work.  But it doesn't appear to.

# Specify the custom estimator
myEstimator <- function(x, Spec=NULL) {

  # Just get the specified return and cov from the environment
  expectedAssetReturns <- get("ExpRet")
  assetCov <- get("ExpCov")

  # Ignore the inputted data, and send back the expected returns

# Now create a portfolio Spec using the custom estimator defined above.
Spec = portfolioSpec()
setTargetReturn(Spec) = .05
setEstimator(Spec) <- "myEstimator"

# Subset out some of the data and calculate the portfolio frontier.
# I subset out a piece of the data, so that I can change the data set
# which should have no effect if I'm specifying the mu and cov, but
# for some reason it does, and hence my dilemma.

Data1 <- Data[20:40,]
frontier1 <- portfolioFrontier(Data1,Spec,"LongOnly")

Data2 <- Data[41:60,]
frontier2 <- portfolioFrontier(Data2,Spec,"LongOnly")

# Now I thought that frontier1 would look identical to frontier2 since
I'm overriding
# the inputs with the specified mu and Sigma in the "myEstimator", the
frontier1 and
# frontier2 look different.
op <- par(mfrow = c(2,1),mar = c(3,3,3,3),mgp=c(1.5,0.6,0),oma =

# I'm clearly doing something wrong, and I'm sure it's some
misunderstanding on my part
# but I can't for the life of me figure it out.  Any help would be
greatly appreciated.

"EMF <kochind.com>" made the following annotations.
The information in this e-mail and any attachments is co...{{dropped:14}}

More information about the R-SIG-Finance mailing list