cvxportfolio icon indicating copy to clipboard operation
cvxportfolio copied to clipboard

trying the hello world program - python errors

Open andrewcz opened this issue 5 years ago • 9 comments

Hi ! Really love the framework and planning to get involved. was wanting to expand for a masters project. i am trying to run the hello world program and getting the following -

risk_model = cp.FullSigma(Sigma_hat) gamma_risk, gamma_trade, gamma_hold = 5., 1., 1. leverage_limit = cp.LeverageLimit(3)

spo_policy = cp.SinglePeriodOpt(return_forecast=r_hat, costs=[gamma_riskrisk_model, gamma_tradetcost_model, gamma_holdhcost_model], constraints=[leverage_limit]) risk_model = cp.FullSigma(Sigma_hat) gamma_risk, gamma_trade, gamma_hold = 5., 1., 1. leverage_limit = cp.LeverageLimit(3) ​ spo_policy = cp.SinglePeriodOpt(return_forecast=r_hat, costs=[gamma_riskrisk_model, gamma_tradetcost_model, gamma_holdhcost_model], constraints=[leverage_limit])

ValueError Traceback (most recent call last) in () 5 spo_policy = cp.SinglePeriodOpt(return_forecast=r_hat, 6 costs=[gamma_riskrisk_model, gamma_tradetcost_model, gamma_hold*hcost_model], ----> 7 constraints=[leverage_limit])

~/cvxportfolio/cvxportfolio/policies.py in init(self, return_forecast, costs, constraints, solver, solver_opts) 217 218 if not isinstance(return_forecast, BaseReturnsModel): --> 219 null_checker(return_forecast) 220 self.return_forecast = return_forecast 221

~/cvxportfolio/cvxportfolio/utils/data_management.py in null_checker(obj) 27 isinstance(obj, pd.DataFrame) or 28 isinstance(obj, pd.Series)): ---> 29 if np.any(pd.isnull(obj)): 30 raise ValueError('Data object contains NaN values', obj) 31 elif np.isscalar(obj):

~/tutorial-env2/lib/python3.6/site-packages/pandas/core/generic.py in nonzero(self) 1571 raise ValueError("The truth value of a {0} is ambiguous. " 1572 "Use a.empty, a.bool(), a.item(), a.any() or a.all()." -> 1573 .format(self.class.name)) 1574 1575 bool = nonzero

ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().

was wondering if you could assist. Best, Andrew

andrewcz avatar Aug 19 '18 11:08 andrewcz

it looks like there are NaN values in the return forecast, could you inspect it? it could be an issue with the data source...

ghost avatar Aug 20 '18 02:08 ghost

screenshot_2018-08-20_20-25-21

andrewcz avatar Aug 20 '18 10:08 andrewcz

not sure whats going on.

andrewcz avatar Aug 20 '18 10:08 andrewcz

so interesting, r_hat.all() seems to have worked? I'm not sure why and to be honest I am not sure if this is mathematically correct. How would could I find out? Best, Andrew

andrewcz avatar Aug 20 '18 10:08 andrewcz

sorry but i can reproduce your error and i don't have enough information for understanding what's wrong. can you isolate the error in a (short) python script and post it here?

ghost avatar Aug 20 '18 21:08 ghost

Hi Enzo, Champion! Its probably my mistake. Will try it again tonight with updated packages. Many thanks Best, Andrew

andrewcz avatar Aug 20 '18 22:08 andrewcz

Hi Enzo! So i have updated pandas and everything looks like its working. however, on the real-time optimization example, I get the following error -

screenshot_2018-08-22_20-55-59

Best, Andrew

andrewcz avatar Aug 22 '18 10:08 andrewcz

screenshot_2018-08-22_21-29-41

andrewcz avatar Aug 22 '18 11:08 andrewcz

(1) take away the .shift(…) method, it’s not important (and maybe got broken by a pandas update)

(2) AlphaSource was the old name of ReturnForecast, please double check (it’s possible that the solutiontime example hasn’t been updated in a long time)

good luck!

On 22 Aug 2018, at 04:29, andrewcz [email protected] wrote:

https://user-images.githubusercontent.com/2296335/44460959-71b4bf00-a652-11e8-9b37-3dd665225f08.png — You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/cvxgrp/cvxportfolio/issues/20#issuecomment-415000933, or mute the thread https://github.com/notifications/unsubscribe-auth/AGPwy4WlshRUeKGAgcGC7cJX4Yor6E6gks5uTUCygaJpZM4WC7ZX.

ghost avatar Aug 28 '18 16:08 ghost