samedi 16 avril 2022

python random_sample minimum value

I am currently using random_sample to generate weightage allocation for 3 stocks where each row values add up to 1.

for portfolio in range (10):
    weights = np.random.random_sample(3)
    weights  = weights/ np.sum(weights)
    print (weights)

[0.39055438 0.44055996 0.16888567]
[0.22401792 0.26961926 0.50636282]
[0.67856154 0.21523207 0.10620639]
[0.33449127 0.36491387 0.30059486]
[0.55274192 0.23291811 0.21433997]
[0.20980909 0.38639029 0.40380063]
[0.24600751 0.199761   0.5542315 ]
[0.50743661 0.26633377 0.22622962]
[0.1154567  0.36803903 0.51650427]
[0.29092731 0.34675988 0.36231281]

I am able to do it but is there any way to ensure that the minimum weightage allocation is greater than 0.05? Meaning that the minimum weight allocation could only be something like [0.05 0.9 0.05]




Aucun commentaire:

Enregistrer un commentaire