[R-SIG-Finance] [R-sig-finance] Flexible inputs fPortfolio possible?
Yohan Chalabi
chalabi at phys.ethz.ch
Tue May 27 18:01:43 CEST 2008
>>>> "R" == "R at Nabble" <vlanschot at yahoo.com>
>>>> on Tue, 27 May 2008 04:15:15 -0700 (PDT)
R> Hi,
R>
R> Is it possible yet to allow pre-specified mean-return and/or
R> covar-matrices
R> in fPortfolio? If so, where can I find instructions to
R> achieve this? I
R> remember reading somewhere that this would eventually become
R> available.
R>
R> Thx,
R>
R> R at N
Do you want to define your own estimators of the covariance matrix?
You can do it with the dev-version of fPortfolio available at r-forge.
a quick example :
##################
library(fPortfolio)
# only with development version of fPortfolio available on R-Forge
# now you can define your own estimator which must returns a list with a
# named list, with at least the following two entries '\$mu' and
# '\$Sigma', which represent estimators for the mean and covariance,
# respectively.
myEstimator <-
function(x, spec = NULL, ...) list(mu = colMeans(x), Sigma = cov(x))
Spec <- portfolioSpec() # default portfolio specification
setEstimator(Spec) <- "myEstimator" # new estimator
Spec
# Load Data and Convert to timeSeries Object:
Data = as.timeSeries(data(smallcap.ts))
Data = Data[, c("BKE", "GG", "GYMB", "KRON")]
Data
## Compute properties of Efficient Portfolio
frontier <- portfolioFrontier(Data, Spec, "LongOnly")
plot(frontier)
####################
hope this helps,
Yohan
--
PhD student
Swiss Federal Institute of Technology
Zurich
www.ethz.ch
www.rmetrics.org
NOTE:
Rmetrics Workshop: http://www.rmetrics.org/meielisalp.htm
June 29th - July 3rd Meielisalp, Lake Thune, Switzerland
More information about the R-SIG-Finance
mailing list