I have a portfolio of 3 securities and I want to generate all possible permutations of securities weights. Single weight spans between 0 and 1.0 with increase of 0.1: (0, 0.1, 0.2, ..., 0.9, 1.0). Sum of all weights has to be equal 1 and all weights have to be nonnegative, for example if first weight is equal to 0.9 then either the second [0.9, 0.1, 0.0] or the third weight has to be 0.1 [0.9, 0.0, 0.1].
How can I define a mathematical formula to calculate number of all permutations with repetitions? Right now to calculate all valid permutations I first generate all permutations and then discard those with sum different than 1 but this approach won't work for portfolios with high number of securities.
Let's begin with your example of three types of securities with weights that are multiples of $0.1$. If we take $0.1$ as our unit, then we must distribute ten units among the three types of securities. Let $x_i$ be the number of units of the $i$th security. Then $$x_1 + x_2 + x_3 = 10 \tag{1}$$ is an equation in the nonnegative integers.
A particular solution of the equation corresponds to the placement of two addition signs in a row of ten ones. For instance, $$1 1 1 1 1 + 1 1 1 + 1 1$$ corresponds to the solution $x_1 = 5$, $x_2 = 3$, $x_3 = 2$ and the weights $0.5$ for the first security, $0.3$ for the second security, and $0.2$ for the third security, while $$1 1 1 1 1 1 1 1 + 1 1 +$$ corresponds to the solution $x_1 = 8$, $x_2 = 2$, $x_3 = 0$ and the weights $0.8$ for the first security, $0.2$ for the second security, and $0$ for the third security.
The number of solutions of equation 1 is the number of ways two addition signs can be placed in a row of ten ones, which is $$\binom{10 + 2}{2} = \binom{12}{2}$$ since we must select which two of the twelve positions required for ten ones and two addition signs will be filled with addition signs.
Generalization
Let's say that you instead are selecting $n$ types of securities, with weights that are multiples of $1/k$. In that case, we take $1/k$ as our unit, so we have a total of $k$ units. For instance, if $k = 10$, then each unit is $0.1$ as in your example. If $k = 100$, then each unit is $0.01$. If we let $x_i$, $1 \leq i \leq n$, be the number of units of the $i$th security, then $$x_1 + x_2 + x_3 + \cdots + x_n = k \tag{2}$$ is an equation in the nonnegative integers. A particular solution corresponds to the placement of $n - 1$ addition signs in a row of $k$ ones. The number of solutions of equation 2 in the nonnegative integers is $$\binom{k + n - 1}{n - 1}$$ since we must choose which $n - 1$ of the $n + k - 1$ positions required for $k$ ones and $n - 1$ addition signs will be filled with addition signs.