I have a large dataset, 10,000 investments I am trying to create an optimized portfolio for. The portfolio has 3 restrictions. Long Only, Only 50 assets can be selected and every invested asset has the same weight. I would like to find the max sharpe portfolio and the minSD portfolio for a given return.
> funds = colnames(dfxts)
> returns = dfxts
> df.con = portfolio.spec(assets = funds)
> df.con = add.constraint(portfolio = df.con, type = "long_only")
> df.con = add.constraint(portfolio = df.con, type = "box", min = (1/n - .01/n), max = (1/n + .01/n))
>
> df.con = add.constraint(portfolio = df.con, type = "position_limit", max_pos = n)
>
> df.con = add.constraint(portfolio = df.con, type = "return", return_targe = r)
>
> df.con = add.constraint(portfolio = df.con, type = "weight_sum_constraint", min_sum = .99, max_sum = 1.01)
> minSDdf <- add.objective(portfolio=df.con,
+ type="risk",
+ name="StdDev")
opt = optimize.portfolio(R = returns, portfolio = df.con, optimize_method = "DEoptim", trace = TRUE)
This is taking over 10 hours to optimize. How can I change the constraints or optimizer to make this faster? I would like it to be under 10 minutes if possible. Thanks,
Not sure if this is working correctly. I edited the objective function in the vignette,
> OF2 <- function(x, Data) {
+ w <- 1/sum(x)
+ -(sum(r*w))/(sum(w * w * Data$Sigma[x, x]))
+ }
The objective function should return a negative value, but it keeps giving me a positive value? Why is this happending