[R] portfolio.optim and assets with weigth equals to zero...
Alberto Santini
albertosantini at gmail.com
Thu Sep 4 00:13:00 CEST 2008
I tried with Rmetrics too, but the behaviour is the same. So I am missing
something...
Very interesting to understand why. :)
I think it's a numerical problem: maybe, zero is not zero, it's very near to
zero.
Regards,
Alberto Santini
-----------------------------
require(fPortfolio)
require(tseries)
assets <- c(
"F.MI",
"ENG.MI",
"TIS.MI",
"^SPMIB"
)
f.mi <- get.hist.quote("F.MI", start="2006-09-03", end="2008-09-03",
compression="w", quote="Close")
eng.mi <- get.hist.quote("ENG.MI", start="2006-09-03", end="2008-09-03",
compression="w", quote="Close")
tis.mi <- get.hist.quote("TIS.MI", start="2006-09-03", end="2008-09-03",
compression="w", quote="Close")
spmib <- get.hist.quote("^SPMIB", start="2006-09-03", end="2008-09-03",
compression="w", quote="Close")
X <- cbind(f.mi[1:(length(f.mi)-1)], eng.mi[1:(length(eng.mi)-1)],
tis.mi[1:(length(tis.mi)-1)], spmib[1:(length(spmib)-1)])
colnames(X) <- assets
R <- as.timeSeries(returns(X))
# Spec = portfolioSpec(model = list(type = c("MV"),
# estimator = c("mean", "cov"), tailRisk = list(), params = list()),
# portfolio = list(weights = NULL, targetReturn = 0,
# targetRisk = 0, targetAlpha = 0.05, riskFreeRate = NULL,
# nFrontierPoints = 50),
# solver = list(solver = c("quadprog"), trace = FALSE))
Spec = portfolioSpec()
frontier <- portfolioFrontier(R, Spec, c("minW[1:nAssets]=0"))
# weightsSlider(frontier)
ptf <-
frontier at portfolio$weights[which.min(getTargetRisk(frontier)[,1])+1,]*100
ptf
assets2 <- c(
"ENG.MI",
"^SPMIB"
)
X2 <- cbind(eng.mi[1:(length(eng.mi)-1)], spmib[1:(length(spmib)-1)])
colnames(X2) <- assets2
R2 <- as.timeSeries(returns(X2))
frontier <- portfolioFrontier(R2, Spec, c("minW[1:nAssets]=0"))
ptf <-
frontier at portfolio$weights[which.min(getTargetRisk(frontier)[,1])+1,]*100
ptf
--
View this message in context: http://www.nabble.com/portfolio.optim-and-assets-with-weigth-equals-to-zero...-tp19289567p19299309.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list