I am trying to create a calculator that allows users to specify asset classes (e.g. 500 in fund1, 500 in fund2, etc.) and the desired fraction of the total portfolio per asset class (e.g. 70% in fund1, 30% in fund2). The equation should determine how much to buy or sell per asset class (instead of move).
I have the following formula for when only 1 fund changes, where $X_1$ is before, $X_2$ is after, and $dX$ is their difference. The same applies to the second fund $Y$. $a$ is the desired fraction of $X$.
if $X_2 = a (X_2 + Y)$ and $X_2 = dX + X1$ is true, then $dX + X_1 = a (X_2 + Y)$. Rewriting that gave me: $$ dX = \frac{aX_1 - X_1 + aY}{1-a} $$
With $X_1 = 50$, $a = 0.70$, and $Y = 50$; $dX$ will be $66.5$.
Now imagine a situation where users can enter multiple funds and the corresponding desired fraction at will. Now, whenever I calculate the amount to buy in one fund, the total changes, and any previous calculations need to be redone. It seems like I need a way to combine these equations.
Is there a name for this type of problem? Can anyone point me in the right direction? My apologies for the possible lack of proper tagging or wording, it has been a while since I did maths... Thanks!
The normal way to do this is to calculate the current value $P$ of the complete portfolio. Then for each fund $i$ multiply it by the target fraction $a_i$ for that fund. This gives the target holding $X_i$ in fund $i$. Then $dX_i$ is the difference between between the target holding and the current holding in fund $i$.
This allows you to calculate the needed changes for all funds at once.