MATLAB: Equation solving problem

equationfinance

HI everybody.
for my job i need to set up and solve an equation. I need to allocate trades to multiple account with the same average buy price. For example.
I bought 100 shares: 2 at 2.50 37 at 2.54 41 at 2.56 and 30 at 2.60. Then i need to allocate, out of the 100 shares, 40 shares to account1, 33 shares to account2, 7 shares to account3 and 20 shares to account4. – all of the account must have the same average buy price (2 to 3 digits must me equal, after it can vary.) – you can not divide a share, so only plain numbers. – all the shares must be allocated. – the algorithm should work with 10+ accounts and 50+ different shares prices.
it's 2 weeks I work on this, have approximate solutions, but the the correct equation and integration in matlab, I don't! see some help!
Thank you
Matgoo

Best Answer

im sure we can help you very well with this
what do you have so far? or which part is difficult for you?
anyway, we have to know what your rule is to determine the allocation of shares. for example, if you have 10 people who should all get 0.6 share, but you have only 6 shares, what are you gonna do? (you have to give some 0 and some 1 share)