Reputation: 305
What I need: I want to create a 10 size vector with random weights. The sum of weights should be equal to 1.
Why I need that: I want to finally calculate the returns of stocks of a randomly diversified portfolio of assets.
Mock Solution: [0.01 0.02 0.07 0.10 0.10 0.05 0.05 .......]. Sum of all elements is 1.
Upvotes: 0
Views: 710
Reputation: 84529
The Dirichlet distribution exactly does what you want.
igraph::sample_dirichlet(1, alpha = rep(1, 10L))
Upvotes: 2