Equation solving problem
6 views (last 30 days)
Show older comments
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
0 Comments
Accepted Answer
Sargondjani
on 8 Jun 2012
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)
2 Comments
Sargondjani
on 12 Jun 2012
can you explain what you are doing?
as for the rule to determine who gets what. i would do it like this:
-first round down (floor) all the shares each account should get, and give them those shares
-second, order the fractions that every account would get and then allocate shares starting at highest fraction... until all 'remaining' shares are allocated. this would discriminate between equal fractions by being higher in the list. the algorithm would be something like:
X= vector with the number of shares each account should get
N = number of shares you have.
-count number of remaining shares: Rem_N=N - sum(floor(X)):
-order X by their fractions (number after .)
-then round up (ceil) the first Rem_N and round down (floor) the remaining fractions
More Answers (0)
See Also
Categories
Find more on Financial Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!