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

  • $\begingroup$ the method of constraining weights to be within an epsilon of (1/n) does not seem a very efficient way to do it. $\endgroup$ – noob2 Dec 11 '15 at 15:09
  • $\begingroup$ your problem is discrete optimization rather than continuous $\endgroup$ – noob2 Dec 11 '15 at 15:15
  • $\begingroup$ Do you have any resource I can look into for discrete optimizations? $\endgroup$ – JB17 Dec 11 '15 at 20:15
  • $\begingroup$ quant.stackexchange.com/questions/22208/… Here is a sample of the dataset I am trying to optimize $\endgroup$ – JB17 Dec 11 '15 at 20:16
  • $\begingroup$ It seems your question is about computational efficiency. However, choosing a portfolio with ~10K free variables is unlikely to yield good future performance. Perhaps you can solve both problems by applying some domain knowledge about the 10K assets to reduce the problem size. $\endgroup$ – shabbychef Dec 14 '15 at 23:56

A problem very similar to yours is described -- including R code -- in a vignette of the NMOF package: http://cran.r-project.org/web/packages/NMOF/vignettes/LSselect.pdf For the Sharpe ratio, you simply need to write a new objective function.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.