« Return to Thread: Flexible inputs fPortfolio possible?

Re: [R-sig-finance] Flexible inputs fPortfolio possible?

by R@Nabble :: Rate this Message:

Reply to Author | View in Thread

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@N



Yohan Chalabi wrote:
>>>> "R" == "R@Nabble" <vlanschot@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@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@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.

 « Return to Thread: Flexible inputs fPortfolio possible?

LightInTheBox - Buy quality products at wholesale price!