cvxportfolio
cvxportfolio copied to clipboard
Can not set attribute Error in get_trades when adding terminal_weights constraint in MPO example
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?
@kch382001 A better title for the issue would be "Can't set attribute error when adding constraint in get_trades"
self.constraints is a property. You can use direct reference self._constraints to resolve the problem.
Sent from my iPhone
On Sep 9, 2019, at 7:38 PM, Jose Ortiz [email protected] wrote:
A better title for the issue would be "Can't set attribute error when adding constraint in get_trades"
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.