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

Voss, Kent VOSSK at kochind.com
Fri Mar 13 00:11:46 CET 2009


Any suggestions as to how to do this?  I've tried to be specific and
provide a reproducible example and any help would be greatly
appreciated.

Thanks,

Kent

-----Original Message-----
From: Voss, Kent 
Sent: Tuesday, March 03, 2009 5:06 PM
To: r-sig-finance at stat.math.ethz.ch
Subject: [R-SIG-Finance] Specifying an expected mu and Sigma for
fPortfolio

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.  

Thanks,

Kent

#### 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
months # 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 solution.
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
cov # 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,
but # 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
  return(list(mu=expectedAssetReturns,Sigma=assetCov))
}

# 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
input # 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 =
c(1,1,1,1))
frontierPlot(frontier1)
frontierPlot(frontier2)

# 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\ c...{{dropped:22}}



More information about the R-SIG-Finance mailing list