# Getting no solution from CQM solver for optimizing quadratic formulation of portfolio optimization with Sharpe ratio.

Using CQM, we can only have integer values in the solution, so weights will be in the range from 0 to 100. So we need to have the constraint as mu^T y = 100. Also, since weights must add to 100, sum_{i}y_i = 100k. I tried the following using CQM as:

rf = 0.02

cqm = ConstrainedQuadraticModel()

y = {} # Transformed weight variable

for asset in assets:

y[asset] = Integer(label = f'y_{asset}',lower_bound=0)

cqm.add_constraint(y[asset] >= 0 ,label = f'y_constraint_{asset}')

k = Integer(label= 'k',lower_bound= 0)

cqm.add_constraint(k >= 0 ,label = 'k_constraint')

y_values = np.array(list(y.values()))

sum_ys = sum(y_values)

cqm.add_constraint(sum_ys - 100*k == 0, label = 'sum_ys')

ret = 0

for a in assets:

ret += (mu[asset] - rf)*y[asset]

cqm.add_constraint(ret == 100,label = 'returns_constraint') #transformed returns constraint

# Setting objective

variance = 0

for a1,a2 in itertools.combinations_with_replacement(assets,2):

variance += y[a1]*sigma[a1][a2]*y[a2]

cqm.set_objective(variance)

When solving it using CQM, I'm not getting any solution as it tells that the sample_set is empty. I need help in this as I'm unable to figure out the logical error in the code, though I'm sure that the quadratic formulation of maximizing Sharpe ratio is correct.

## Comments

Nicholas T(Report)Would it be possible to use a Real variable type in the solution instead of integer to allow the solution to include floats?

David J(Report)Hello,

Are you able to provide a minimal code example that reproduces the issue you are seeing?

Please give a small code example with import statements and simple input variables so it can be copied and pasted into a python interpreter and run.

This tends to be the easiest way to pinpoint what the problem is that you are seeing.

The above code example doesn't instantiate or call a solver, it just formulates the problem, so that could be the issue, or it could be something else not included.

David J(Report)Real variables can be used in the CQM, but only with Linear terms, not with Quadratic terms. Take a look at our documentation for more details.

Nicholas T(Report)I have been working on a rust library for basic mathematical operations that relies on Boolean vectors instead of packaged float data types that might help to circumvent this issue. If you might like to collaborate on how to overcome the constraint noted in the documentation please let me know.

- Nicholas Teague

Please sign in to leave a comment.