0
votes

I'm creating an optimization function with PuLP to optimize a portfolio. I have a list of assets that each have one of the following Liquidity Levels [1, 2, 3].

I am attempting to create a constraint that at least 20% of the portfolio needs to have Level 1 liquidity.

I have created a dictionary (liquidity) that has saved the {'Asset':Level} and am attempting to create the constraint with this and the asset variable (asset_vars), which is a LpVariable.

asset_vars = pl.LpVariable.dicts("Assets", asset_list,lowBound=0, upBound=1, cat='Integer')

prob += pl.lpSum([liquidity[f] * asset_vars[f] for f in asset_vars]) >= ?

I know my setup now is not close to what I would need to do, however, I am having difficulty finding / coming up with a solution.

1

1 Answers

0
votes

Given your assets, you already know the liquidity level for each of them. You just need to make sure that at least 20% of the portfolio is made by assets of liquidity level 1.
You can do it with the following constraint.

prob += pl.lpSum(asset_vars[f] for f in asset_vars if liquidity[f]==1) >= 0.2 * pl.lpSum(asset_vars[f] for f in asset_vars)

Assume you have 6 assets, x1,x2,x3,x4,x5,x6, where x1 is the only one associated to an asset with liquidity level 1. The constraint would be:

x1 >= 0.2*(x1 + x2 + x3 + x4 + x5 + x6)
0.8*x1 >= 0.2*(x2 + x3 + x4 + x5 + x6)

which essentially means: for each asset with liquidity level 1 I take, I cannot take more than 4 assets with liquidity level different than 1.