>>Hi All,
>>
>>I have an interesting debate with some users of ours about how to calculate the average unit price for a stock bought and sold and bought again in various transactions at different price levels. So I put it to the market players in the forum for your input :)
>>
>>When we consider only BUY transactions then the calculation is quite simple: we simply add up the total cost of buying all the shares we have and divide by the total number of shares we have. However, the problem seems to get complicated when in between buying we also sell some shares. Then, later, perhaps even buy some back again. How to calculate the average unit prices now?
>>
>>Some websites indicate that we should sell off those shares that we first bought (first in, first out) and then re-calculate the average unit price based on the BUY transaction left. Each new BUY transaction changes the AUP, and each SELL transaction removes old BUY transactions from consideration as the shares are now sold.
>>
>>Other websites say that only BUY transactions affect the AUP. Simply add up all the costs to buy the shares, subtract the monies received from SELL transactions, and divide the net by whatever number of shares we have left.
>>
>>Below is a simple table of transaction. There are various BUY transactions (denoted by positive shares) and then some SELLS (denoted by negative shares), then some more buying and selling. What do you say the average unit price is at the end of these sequence of transaction and why?
>>
>>
>>Shares bought / sold Buy / Sell Price Shares Running Total
>>
>>3700 1389 3700
>>5000 894 8700
>>5000 810 13700
>>6000 1000 19700
>>4200 1163 23900
>>1100 1182 25000
>>10000 910 35000
>>15000 777 50000
>>20000 856 70000
>>15000 976 85000
>>-35000 813 50000
>>-25000 742 25000
>>25000 833 50000
>>50000 829 100000
>>-50000 572 50000
>>-25000 553 25000
>>
>>
>>
>
>Basically, you should decide which accounting method to use: FIFO or LIFO and use it consistently. The difference between the methods will transpire on the each sell point, i.e. you calculate cost basis either based on first shares bought (historically, eliminated by subsequent sell transaction, FIFO) or last shares bought (before the sale, i.e. reduced in backward direction, LIFO).
Thanks Edward, I have implemented a solution whereby the user can choose FIFO, LIFO, or just flat average of purchase costs divided by shares held.
In the End, we will remember not the words of our enemies, but the silence of our friends - Martin Luther King, Jr.