cvxportfolio icon indicating copy to clipboard operation
cvxportfolio copied to clipboard

Exception: Invalid dimensions for arguments.

Open CharlesGuan opened this issue 4 years ago • 1 comments

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,)

CharlesGuan avatar Apr 17 '20 03:04 CharlesGuan

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!

thayes75 avatar Apr 20 '20 15:04 thayes75