library(CVXR)
auxiliary_function <- function(x) {
# here whatever code
}
portfolio_fun <- function(prices) {
X <- diff(log(prices))[-1] # compute log returns
mu <- colMeans(X) # compute mean vector
Sigma <- cov(X) # compute the SCM
# design mean-variance portfolio
w <- Variable(nrow(Sigma))
prob <- Problem(Maximize(t(mu) %*% w - 0.5*quad_form(w, Sigma)),
constraints = list(w >= 0, sum(w) == 1))
result <- solve(prob)
return(as.vector(result$getValue(w)))
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.