I have a problem: I need to generate weights of a portfolio of n assets, and the weight of each asset must be a multiple of 1%, and at most 25%. I use the function np.random.randint. Then I divide the weights by the sum of the generated numbers, and encounter a problem during rounding some weights become less than 1%, and some greater than 25%, which contradicts the initial conditions
I used such function:
min_weight= 1
max_weight = 25
for asset in assets_for_portfolio:
weight = np.random.randint(min_weight, max_weight)
portfolio_weights = weight
portfolio_weights /= portfolio_weights.sum()
But I encountered the problems I described
Aucun commentaire:
Enregistrer un commentaire