Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception: Invalid dimensions for arguments. #52

Closed
CharlesGuan opened this issue Apr 17, 2020 · 1 comment
Closed

Exception: Invalid dimensions for arguments. #52

CharlesGuan opened this issue Apr 17, 2020 · 1 comment

Comments

@CharlesGuan
Copy link

run "SinglePeriodOptimization.ipynb" and got the error:
ValueError: Cannot broadcast dimensions (60, 432) (432,)


RemoteTraceback Traceback (most recent call last)
RemoteTraceback:
"""
Traceback (most recent call last):
File "/Users/che.guan/opt/anaconda3/lib/python3.7/site-packages/multiprocess/pool.py", line 121, in worker
result = (True, func(*args, **kwds))
File "/Users/che.guan/opt/anaconda3/lib/python3.7/site-packages/multiprocess/pool.py", line 44, in mapstar
return list(map(args))
File "/Users/che.guan/cvxportfolio/cvxportfolio/simulator.py", line 147, in _run_backtest
policy, loglevel=loglevel)
File "/Users/che.guan/cvxportfolio/cvxportfolio/simulator.py", line 116, in run_backtest
u = policy.get_trades(h, t)
File "/Users/che.guan/cvxportfolio/cvxportfolio/policies.py", line 266, in get_trades
cost_expr, const_expr = cost.weight_expr(t, wplus, z, value)
File "/Users/che.guan/cvxportfolio/cvxportfolio/risks.py", line 58, in weight_expr
self.expression = self._estimate(t, w_plus - self.w_bench, z, value)
File "/Users/che.guan/cvxportfolio/cvxportfolio/risks.py", line 159, in _estimate
np.sqrt(values_in_time(self.idiosync, t)), wplus)) +
File "/Users/che.guan/opt/anaconda3/lib/python3.7/site-packages/cvxpy/atoms/affine/binary_operators.py", line 221, in init
super(multiply, self).init(lh_expr, rh_expr)
File "/Users/che.guan/opt/anaconda3/lib/python3.7/site-packages/cvxpy/atoms/affine/binary_operators.py", line 43, in init
super(BinaryOperator, self).init(lh_exp, rh_exp)
File "/Users/che.guan/opt/anaconda3/lib/python3.7/site-packages/cvxpy/atoms/atom.py", line 45, in init
self._shape = self.shape_from_args()
File "/Users/che.guan/opt/anaconda3/lib/python3.7/site-packages/cvxpy/atoms/affine/binary_operators.py", line 258, in shape_from_args
return u.shape.sum_shapes([arg.shape for arg in self.args])
File "/Users/che.guan/opt/anaconda3/lib/python3.7/site-packages/cvxpy/utilities/shape.py", line 49, in sum_shapes
len(shapes)
" %s" % tuple(shapes))
ValueError: Cannot broadcast dimensions (60, 432) (432,)
"""

The above exception was the direct cause of the following exception:

ValueError Traceback (most recent call last)
in
2 warnings.filterwarnings('ignore')
3 results.update(dict(zip(policies.keys(), simulator.run_multiple_backtest(1E8*w_b, start_time=start_t,end_time=end_t,
----> 4 policies=policies.values(), parallel=True))))

~/cvxportfolio/cvxportfolio/simulator.py in run_multiple_backtest(self, initial_portf, start_time, end_time, policies, loglevel, parallel)
150 if parallel:
151 workers = multiprocess.Pool(num_workers)
--> 152 results = workers.map(_run_backtest, policies)
153 workers.close()
154 return results

~/opt/anaconda3/lib/python3.7/site-packages/multiprocess/pool.py in map(self, func, iterable, chunksize)
266 in a list that is returned.
267 '''
--> 268 return self._map_async(func, iterable, mapstar, chunksize).get()
269
270 def starmap(self, func, iterable, chunksize=None):

~/opt/anaconda3/lib/python3.7/site-packages/multiprocess/pool.py in get(self, timeout)
655 return self._value
656 else:
--> 657 raise self._value
658
659 def _set(self, i, obj):

ValueError: Cannot broadcast dimensions (60, 432) (432,)

@thayes75
Copy link

thayes75 commented Apr 20, 2020

I'm also having issues trying to run a backtest with a FactorModelSigma bombing because of incompatible dimensions and the mul_shapes_promote code in cvxpy shapes.py using cvxpy 1.0.25.

Perhaps this is caused by the objects I'm passing in and their shapes. Can someone provide clear examples of the DataFrame dimensions for each of the componnts Exposures, FactorCov, Idyos?

Currently I have
Factor expoxsure Multiindex DataFrame
Index = date, ids
Columns = Factors

FactorCov Multiindex DataFrame (square in time)
Index = Date, facid
Columns = facid

Idyos Single Index DataFrame
Index = date
Columns = ids

Cheers!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants