portfolio-optimization icon indicating copy to clipboard operation
portfolio-optimization copied to clipboard

Converting Stocks from Integer to Real

Open ab-jiteshlalwani opened this issue 1 year ago • 0 comments

We are working on an application that requires d-wave to return real values instead of integers, so we are trying to modify the code so that we can get stocks = 1.5 instead of 2. Here is what happens when we change the following code:

x = {s: dimod.Integer("%s" % s, lower_bound=0, upper_bound=self.max_num_shares[s]) for s in self.stocks}

to

x = {s: dimod.Real("%s" % s, lower_bound=0, upper_bound=self.max_num_shares[s]) for s in self.stocks}

Reference: https://github.com/dwave-examples/portfolio-optimization/blob/503640bf9ade08e6b7a46a6828f6b6bc5d8b33c0/single_period.py#L209

We are getting the below error:

ValueError: REAL variables (e.g. 'ACS.MC') cannot have interactions for line: risk = risk + coeff * x[s1] * x[s2]

Reference: https://github.com/dwave-examples/portfolio-optimization/blob/503640bf9ade08e6b7a46a6828f6b6bc5d8b33c0/single_period.py#L216

Is there any way to solve the error and get real values in output i.e. in decimals?

ab-jiteshlalwani avatar Sep 17 '22 12:09 ab-jiteshlalwani