Quick Background:
So there are 5 randomly generated numbers from 0 to 1, and we want to normalize them, meaning the sum of the 5 numbers should be equal to 1.
My algorithm is concerned with asset allocations and there are 3 constraints that should be implemented in the normalization. Denote the following:
y - contains the list of asset allocations in the current period
x - contains the list of asset allocations in the previous period
H - set of assets to be Held in the current period
- this means that the current allocation for an asset in this set should be equal to the previous allocation
B - set of assets to be Bought in the current period- this means that the current allocation for an asset in this set should be more than or equal to the previous asset allocation
S - set of assets to be Sold in the current period- this means that the current allocation for an asset in this set should be less than or equal to the previous asset allocation
Simplified code:
https://paste.pythondiscord.com/6ZKA
Concern:
The code above will normalize an initialized asset allocations. However, I have noticed that the normalized allocations sometimes do not follow the three constraints. I addressed this problem using the following algorithm:
- Don't include the H assets in the "sum_x" value in the Normalize function and subtract them to the "totalCapital" value.
- Continue the normalization procedure for the B assets and S assets
- If the asset index is in H then its previous allocation will be copied into the current allocation.
- The allocation for the asset indeces in B and S will be the result of the normalization procedure in Step 2.
This algorithm however only enforces the Hold constraint successfully, and not the Buy and Sell constraints. Is there a way to normalize with some terms having a minimum and maximum value?