0

My problem doesn't require the variables to be directly in the objetive function, only the related data. So if I don't put the variables in there, the objective function has no link to the variables and the model doesn't work properly, but if I do put it there the variable values interferes with my function. Is there a better way to do this?

This is my objective function: the sum of (r[i] * v[i]) with r[i] being the return value of a given variable x[i] and same goes for v[i], but instead of return it's variance

With r being returns and v variances.

The code I have so far:

model = Model()
x = model.continuous_var_dict(keys, name='invs')
model.maximize(model.sum(x[i] * (return_dict[i] / var_dict[i]) for i in x.keys()))

Any help is appreciated!

  • First: when you say that 'the model doesn't work properly' if you don't include the variables in the objective, what does happen? Do you get provably wrong answers or errors? Second: in what way does adding the variables into the objective 'interfere' with your function? If you aren't trying to maximise of minimise something, what are you trying to solve? – TimChippingtonDerrick Aug 31 '21 at 06:36
  • Could the example at https://towardsdatascience.com/stock-portfolio-optimization-d1dc66c7251 help ? – Alex Fleischer Aug 31 '21 at 08:08

0 Answers0