1 | mathWtsEfrontRisky(returns, mu.efront, bar.ylim = c(0, 1), display.wts = T, digits = NULL)
|
returns |
|
mu.efront |
|
bar.ylim |
|
display.wts |
|
digits |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | ##---- Should be DIRECTLY executable !! ----
##-- ==> Define data, use random,
##-- or do help(data=index) for the standard data sets.
## The function is currently defined as
function (returns, mu.efront, bar.ylim = c(0, 1), display.wts = T,
digits = NULL)
{
V = var(returns)
mu = apply(returns, 2, mean)
one = rep(1, nrow(V))
z1 = solve(V, one)
a = as.numeric(t(mu) %*% z1)
cc = as.numeric(t(one) %*% z1)
z2 = solve(V, mu)
b = as.numeric(t(mu) %*% z2)
d = b * cc - a^2
g1 = as.matrix((b * z1 - a * z2)/d, ncol = 1)
g2 = as.matrix((cc * z2 - a * z1)/d, ncol = 1)
n = length(mu.efront)
a1 = matrix(rep(g1, n), ncol = n)
a2 = g2 %*% mu.efront
wts.efront = a1 + a2
MU.EFRONT = mu.efront
VOL.EFRONT = (1/cc + (cc/d) * (mu.efront - a/cc)^2)^0.5
if (display.wts) {
barplot.wts(wts.efront, legend.text = T, col = topo.colors(10),
ylab = "WEIGHTS", xlab = "VOL", bar.ylim = c(-2,
6))
}
if (is.null(digits)) {
out = list(mu = MU.EFRONT, vol = VOL.EFRONT, wts = wts.efront)
}
else {
out = rbind(MU.EFRONT, VOL.EFRONT, wts.efront)
out = as.data.frame(round(out, digits = digits))
names(out) = paste("PORT", 1:n, sep = "")
}
out
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.