Hi there,
I'm trying to avoid small transactions in the rebalancing of my portfolio.
The idea of the code is calculate the difference between the new optimal portfolio and my current portfolio positions and avoid the transaction if the difference is under the 5%.
weights = opt.calculate_optimal_portfolio(objective=objective, constraints=constraints)
for s, v in weights.iteritems():
position = context.portfolio.positions[s].amount
current_alloc = position * data.current(s, 'price') / context.portfolio.portfolio_value
diff = (p - current_alloc)
weights[s] = v if abs(diff) > 0.05 else current_alloc
objective = opt.TargetWeights(weights)
order_optimal_portfolio(objective=objective, constraints=constraints)
But it doesn't work.
TypeError: TargetWeights() expected a value of type dict or
pandas.core.series.Series for argument 'weights', but got
pandas.indexes.base.Index instead.
What would be the best way to solve this problem?
Thanks