Algorithm for fairly distributing shares

41 Views Asked by At

I am working on an algorithm for the following scenario:

X number of investors have a choice of investing in Y different shares. The investors choose their shares upfront by specifying the breakdown of shares that they want.

An example would choice be:

Share A: 50%
Share B: 30%
Share C: 10%
Share D: 10%
Share E: 0%

Now, because the share prices are always changing, the investors portfolio will need to be rebalanced every week. If Share A doubles in value, then the weighting will now look like

 Share A: 66.7%
 Share B: 20%
 Share C: 6.7%
 Share D: 6.7%
 Share E: 0%

To balance this is easy, just sell the correct number of share A and buy the rest of the shares proportionately.

Now, assume all of a sudden, the exchanges which facilitate the trading of shares become unavailable. All X number of investors know each other in real life, and decide to come up with an agreement among one another to trade the shares that they already own.

Since there are now a set number of shares collectively owned by each investor, there is a limited amount of rebalancing that can take place.

Assuming that every week, the investors want to tweak the % of their portfolios, and that amongst each other, shares can be traded at fair value, what type of algorithm could be used to bring the group as close to balanced as possible, as fairly as possible (perfect balance will not be possible without trading on the external exchanges).

An example with two investors and two shares would be:

Investor 1 owns 10 shares in A valued at $10 each
Investor 1 owns 5 shares in B valued at $20 each
Investor 2 owns 20 shares in A valued at $10 each
Investor 2 owns 0 shares in B valued at $20 each

Investor 1 wants a 50/50 split between the shares in $ value
Investor 2 wants a 50/50 split between the shares in $ value

After rebalancing here, both investors would end up with 15 shares of A and 2.5 shares of B and will have maintained their $200 portfolio values. Both would be equally balanced/unbalanced.

Is there a generic algorithm that could achieve this with an arbitrary number of investors, different portfolio values, different target portfolio % weights and an arbitrary number of different shares. I can't find anything similar elsewhere and I have tried for days to come up with a mathematical solution. At this point I am stumped.