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

Can not set attribute Error in get_trades when adding terminal_weights constraint in MPO example #35

Open
kch382001 opened this issue Sep 9, 2019 · 2 comments

Comments

@kch382001
Copy link

The terminal_weights setup in MultiPeriodOpt example seems to fail when calling run_backtest function.
python 3.6 + cvxportfolio 0.05 + cvxpy 1.0.25 + numpy 1.17.1 + pandas 0.22.0.

terminal_weights = pd.Series(index=returns.columns, data=0)
terminal_weights['USDOLLAR'] = 1

policy = \
      cp.MultiPeriodOpt(return_forecast=returns_forecast,
                        costs=[gamma_risk*risk_model, gamma_tcost*simulated_tcost, optimization_hcost],
                        constraints=[cp.LeverageLimit(3)],
                        trading_times=list(returns.index[(returns.index>=start_t)&(returns.index<=end_t)]),
                        lookahead_periods=lookahead_periods,
                        terminal_weights=terminal_weights)
    
...
result = simulator.run_backtest(w_b*1e8, start_time = start_t, end_time=end_t, policy=policy)

It error out in policies.py file:

if self.terminal_weights is not None:
            prob_arr[-1].constraints += [wplus == self.terminal_weights.values]  # <-- Error Out

The error message is:

File "/home/kec/.local/lib/python3.6/site-packages/cvxportfolio/policies.py", line 374, in get_trades
    prob_arr[-1].constraints += [wplus == self.terminal_weights.values]
AttributeError: can't set attribute

anyone knows how to fix this problem?

@joseortiz3
Copy link

joseortiz3 commented Sep 9, 2019

@kch382001 A better title for the issue would be "Can't set attribute error when adding constraint in get_trades"

@kch382001
Copy link
Author

kch382001 commented Sep 10, 2019 via email

@kch382001 kch382001 changed the title Error out on MPO example terminal_weights Can not set attribute Error in get_trades when adding terminal_weights constraint in MPO example Sep 10, 2019
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

2 participants