Hi,
Is it possible yet to allow pre-specified mean-return and/or covar-matrices
in fPortfolio? If so, where can I find instructions to achieve this? I
remember reading somewhere that this would eventually become available.
Thx,
R at N
"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
Following your advice, I did the following:
PropEstimates<-function(x,Estmu=colMeans(x),Covar=cov(x)) list(mu=Estmu,
Sigma=Covar)
####### Efficient Frontier
Data <- as.timeSeries(MatR)
NAss=ncol(Data)
NAss
SpecDef <- portfolioSpec()
Rfree = 0.04/12
setRiskFreeRate(SpecDef)<- Rfree
TotUni<-PropEstimates(Data,colMeans(Data),cov(Data))
TotUni
This code results in the following (what looks like correct) results:
TotUni
$mu
. . . .
$Sigma
. . . .
However, if I then input this as follows:
setEstimator(SpecDef)<-TotUni
ConstrLO = "LongOnly"
frontierLO = portfolioFrontier(Data, SpecDef, ConstrLO)
I get the following error:
ERROR:
c("'structure(list(mu = structure(c(0.0025, 0.00369565217391304, ' is not
a function, character or symbol", "'0.00271739130434783,
0.00347826086956522, 0.00858695652173913, ' is not a function, character or
symbol", "'0.00119565217391304, 0.00141304347826087, -0.00282608695652174, '
is not a function, character or symbol", "'0.0101086956521739,
0.00315217391304348, 0.0197826086956522, ' is not a function, character or
symbol", "'0.0141304347826087), .Names = c(\"FTSE.All.Share\",
\"FTSE.All.Stock.Gilts\", ' is not a function, character or symbol",
Trying to correct it by literally applying your code, and using:
PropEstimates<-function(x, spec = NULL, ...) list(mu = colMeans(x), Sigma =
cov(x))
TotUni<-PropEstimates(Data,colMeans(Data),cov(Data))
setEstimator(SpecDef)<-"TotUni"
I get this error:
ERROR:
variable "TotUni" of mode "function" was not found
In fact, even the "old" way of doing things, for example by leaving out any
setEstimator, results in:
ERROR:
variable "covEstimator" of mode "function" was not found
Is this because I'm still using 2.6.2 ???
Thx for any further insights/guidance,
R at N
Yohan Chalabi wrote:
"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
_______________________________________________
R-SIG-Finance at stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-sig-finance
-- Subscriber-posting only.
-- If you want to post, subscribe first.
"R" == "R at Nabble" <vlanschot at yahoo.com>
on Thu, 29 May 2008 00:20:18 -0700 (PDT)
R> Following your advice, I did the following:
R>
R> PropEstimates<-function(x,Estmu=colMeans(x),Covar=cov(x))
R> list(mu=Estmu,
R> Sigma=Covar)
R> ####### Efficient Frontier
R> Data <- as.timeSeries(MatR)
R> NAss=ncol(Data)
R> NAss
R> SpecDef <- portfolioSpec()
R> Rfree = 0.04/12
R> setRiskFreeRate(SpecDef)<- Rfree
R> TotUni<-PropEstimates(Data,colMeans(Data),cov(Data))
R> TotUni
R> This code results in the following (what looks like correct)
R> results:
how do you expect this code to work?? I did not recommend you to do
that!
you should specify the name of your estimator function with
"setEstimator<-".
this means,
setEstimator(SpecDef) <- "PropEstimates"
in your example.
Please use the code I already posted with the
*dev-version* of fPortfolio available at *R-forge*.
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