I'd like to have an investment portfolio with a few items, each having a target proportion (e.g. I want to have stocks of Apple and the total value of those should be 25% of my portfolio's total worth). I also would like to invest periodically. My question is: Is there some sort of formula/simulation that I can use to figure out each period how much to invest in each stock so that everything stays balanced? I tried working it out with an LP, but couldn't wrap my head around it.
A little example to make things a bit more clear:
Say that there's currently 3 stocks in my portfolio with the following info:
Stock name | S1 S2 S3
Current # of stock owned | 10 8 9
Current price | 10 9 11
Current size of portfolio | 36.9% 26.6% 36.5%
Target size in portfolio | 40% 20% 40%
If I now want to invest 50 euros (or dollars, or what have you), is there a way to repeatedly determine how much of which stock to buy so that after buying those things, the portfolio is more balanced than before? I'd like to find a way to solve this problem in general, not just solve this particular example.