I'm developing a portfolio optimisation code with constraints using monte-carlo simulation. However, I have run into a problem. My problem is as follows:
I have a list of instruments ["Multi", "Equity 1", "Equity 2", "Equity 3", "FI", "Cash"]
And I would like to generate a list of random numbers for these instruments e.g.
weights (random numbers) = [xx, xx, xx, xx, xx, xx]
However, with multiple constraints such as :
- All weights between 0.05 and 0.20.
- Weight of say "Cash" must be between 0 and 0.10 (i.e. the 0<= weights[-1] <= 0.10)
- Weight of "Equity 1" has to be 0.15 (i.e. weights[1] = 0.15)
Is there anyway that I can generate random numbers that satisfy all these criteria? and of course the sum of all weights must be equal to one.
Thank you all for your help!
You can generate the numbers one by one, computing at each step the total sum of the weights you already got. I will use random.randint function for my demonstration.
So for the remaining weigths, you have to generate random values such that the last one wouldn't be larger than 0.2.
My output: