I expect this is a very well-known problem, but I don't think I know its name.
Consider n investments in n stocks, for example:
$40 in stock A
$100 in stock B
$230 in stock C
$18 in stock D
The desired ratios of the stocks are as follows:
15% stock A
20% stock B
55% stock C
10% stock D
An additional contribution, say \$60, is to be distributed over these stocks. If the desired ratio were achieved, this would result in the following investments after the new contribution:
$67.20 in stock A
$89.60 in stock B
$246.40 in stock C
$44.80 in stock D
That would imply the following contributions, summing to \$60:
$27.20 to stock A
$-10.40 to stock B
$16.40 to stock C
$26.80 to stock D
However, in this problem, stock cannot be sold, so the contributions must all be positive or zero.
In the example above, stock B (\$100) is higher than the ideal allocation (\$89.60) even before the new contribution is invested. Stock B should therefore have zero contribution. The contributions to the other funds should yield a new allocation across the stocks that in some sense minimizes the deviation from the desired ratios, while still summing to the desired total contribution (\$60). More precisely, if the problem is iterated (with repeated investments), the allocation of the investments across the stocks should converge on the desired ratios.
What is an algorithm to compute an optimal allocation subject to these kinds of constraints?
I approached this naively by a one-shot setting of contributions to zero in cases like that of stock B above, followed by normalizing the remaining desired ratios to compute the rest of the contributions. However, I find that that still results, in some cases, in violating the constraints (I get a negative contribution to a fund).
Perhaps I should just iterate the naive algorithm I described above, but I suspect there is a better way. This seems like some sort of mathematical programming problem, but I'm not sure how to formulate the constraints in the simplest way that captures the problem. In particular, I suspect this could be represented as a problem in linear programming or some closely related problem space, but I haven't yet succeeded in doing that.
I am not claiming that I have the optimal strategy. After all, the word optimal depends on which metric we are adopting. One question that we need to address is suppose you have two allocations. how would you measure which is closer to your target allocations? Should I use $KL$-divergence or some $p$-norm?
Since linear programming is mentioned, let me formulate a linear programming formulation that minimizes $L-1$ norm.
Suppose my target distribution is $p_1, \ldots, p_n$.
Suppose the existing investment is $x_1, \ldots, x_n$. Let $\sum_{i=1}^n x_i = X$.
Suppose we have a new funding of $y$ and we intend to allocate them to distinct investment in the ratio of $q_1, \ldots, q_n$.
My optimization problem is
$$\min_q \sum_{i=1}^n \left| \frac{x_i+yq_i}{X+y} - p_i\right|$$
subject to $$\sum_{i=1}^n q_i=1$$ $$q_i \geq 0, \forall i \in \{ 1, \ldots, n\}$$
The objective function is equivalent to
$$\min_q \sum_{i=1}^n \left| yq_i+x_i-p_i(X+y)\right|$$
It is also equivalent to
$$\min_q \sum_{i=1}^n \left| q_i-\frac{p_i(X+y)-x_i}{y}\right|$$
We let $t_i = \frac{p_i(X+y)-x_i}{y}$, note that this quantity can be computed. $p_i(X+y)$ is the ideal allocation according to the targeted distribution.
Hence along with the constraint, we have
$$\min_q \sum_{i=1}^n \left| q_i-t_i\right|$$
subject to $$\sum_{i=1}^n q_i=1$$ $$q_i \geq 0, \forall i \in \{ 1, \ldots, n\}$$
This can be rewritten as
$$\min_{q,r} \sum_{i=1}^n r_i$$
subject to $$r_i \geq q_i-t_i, \forall i \in \{ 1, \ldots, n\}$$ $$r_i \geq -(q_i-t_i), \forall i \in \{ 1, \ldots, n\}$$ $$\sum_{i=1}^n q_i=1$$ $$q_i \geq 0, \forall i \in \{ 1, \ldots, n\}$$
which is a linear program.