Given an input array of initial weights and returns for a porfolio, I'm looking to constrain the number of transactions realised during the optimisation (optimisation of overall return for example).
import cvxpy as cp
weights = cp.variable(n)
init_weights = df.initial_weights.values
return = mu.T@weights
# I'm looking to constrain a variable 'nb_transactions'
nb_transactions = cp.sum(cp.abs(weights - init_weights) >= 0.00001)
prob = cp.Problem(cp.maximize(return), [nb_transactions <= 30])
prob.solve()
Any ideas on how I could solve this? Thanks
Work with integer buy and sell indicator variables.
Max number of holdings constraint:
Setting constraint variables:
Note, that this problem is a mixed integer problem. The ECOS BB solver can deal with that, if the problem remains small. Otherwise, you will need a commercial grade optimizer.