I am trying to optimize the function "fun" for the weights (w_opt) but I get the following error:
Error in optim(par = par, fn = fun, method = "L-B