Hi guys,
I am trying to use a vlookup up to calculate whether a capital gain or loss has been made or lost when selling shares. A major problem I have is; if shares are purchased in two separate lots and at different prices, when I sell a portion of the shares I need to calculate the capital gain or loss on all the first lot of shares, if I sell more shares than I bought in the first lot then I need to move onto the second lot I bough. Then when I sell the rest of the shares at a later date I need to take off from the amount of shares I have left after selling the first lot.
For example, in the table below, 100 units of ANZ were purchased on 20/5/2016 and a further 60 units of ANZ were purchased on 7/7/2016.
140 units of ANZ were then sold on the 5/8/2016 so the capital gain is worked out by Total return-Total Cost=Capital Gain. However, the Total Cost in this case is 100 units at $10 + 40 units at $2 =$1,080. Therefore, the Capital Gain in this case is $1,680-$1,080=$600. When the further 20 ANZ shares are sold the cost will be the remaining amount of shares (40*$2).
BBOZ sale is similar to ANZ. However, the first sale cost comes from the first purchase and the cost of the second sale of BBOZ comes from 10 units in the first buy then the remaining from the second lot.
Keep in mind that another partial lot of shares could be sold but in this example this doesn't occur.
If you need further explanation please let me know.
Thanks for your help!
[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD]Company[/TD]
[TD]Date
[/TD]
[TD]Units Purchased[/TD]
[TD]Purchase Price[/TD]
[TD]Total Cost[/TD]
[TD]Units Sold[/TD]
[TD]Unit price[/TD]
[TD]Total Return
[/TD]
[TD]Capital Gain[/TD]
[/TR]
[TR]
[TD]ANZ
[/TD]
[TD]20/5/2016[/TD]
[TD]100[/TD]
[TD]10[/TD]
[TD]1,000[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]BBOZ[/TD]
[TD]25/5/2016[/TD]
[TD]90[/TD]
[TD]9[/TD]
[TD]810[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]BBOZ[/TD]
[TD]3/6/2016[/TD]
[TD]80[/TD]
[TD]8[/TD]
[TD]640[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]BBUS[/TD]
[TD]5/6/2016[/TD]
[TD]70[/TD]
[TD]7[/TD]
[TD]490[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]ANZ[/TD]
[TD]7/7/2016[/TD]
[TD]60[/TD]
[TD]2[/TD]
[TD]120[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]BBOZ[/TD]
[TD]1/8/2016[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]80[/TD]
[TD]11[/TD]
[TD]880[/TD]
[TD]160[/TD]
[/TR]
[TR]
[TD]ANZ[/TD]
[TD]5/8/2016[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]140[/TD]
[TD]12[/TD]
[TD]1,680[/TD]
[TD]600[/TD]
[/TR]
[TR]
[TD]ANZ[/TD]
[TD]10/8/2016[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]20[/TD]
[TD]13[/TD]
[TD]260[/TD]
[TD]220[/TD]
[/TR]
[TR]
[TD]BBOZ[/TD]
[TD]15/8/2016[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]90[/TD]
[TD]5[/TD]
[TD]450[/TD]
[TD]-280[/TD]
[/TR]
</tbody>[/TABLE]
I am trying to use a vlookup up to calculate whether a capital gain or loss has been made or lost when selling shares. A major problem I have is; if shares are purchased in two separate lots and at different prices, when I sell a portion of the shares I need to calculate the capital gain or loss on all the first lot of shares, if I sell more shares than I bought in the first lot then I need to move onto the second lot I bough. Then when I sell the rest of the shares at a later date I need to take off from the amount of shares I have left after selling the first lot.
For example, in the table below, 100 units of ANZ were purchased on 20/5/2016 and a further 60 units of ANZ were purchased on 7/7/2016.
140 units of ANZ were then sold on the 5/8/2016 so the capital gain is worked out by Total return-Total Cost=Capital Gain. However, the Total Cost in this case is 100 units at $10 + 40 units at $2 =$1,080. Therefore, the Capital Gain in this case is $1,680-$1,080=$600. When the further 20 ANZ shares are sold the cost will be the remaining amount of shares (40*$2).
BBOZ sale is similar to ANZ. However, the first sale cost comes from the first purchase and the cost of the second sale of BBOZ comes from 10 units in the first buy then the remaining from the second lot.
Keep in mind that another partial lot of shares could be sold but in this example this doesn't occur.
If you need further explanation please let me know.
Thanks for your help!
[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD]Company[/TD]
[TD]Date
[/TD]
[TD]Units Purchased[/TD]
[TD]Purchase Price[/TD]
[TD]Total Cost[/TD]
[TD]Units Sold[/TD]
[TD]Unit price[/TD]
[TD]Total Return
[/TD]
[TD]Capital Gain[/TD]
[/TR]
[TR]
[TD]ANZ
[/TD]
[TD]20/5/2016[/TD]
[TD]100[/TD]
[TD]10[/TD]
[TD]1,000[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]BBOZ[/TD]
[TD]25/5/2016[/TD]
[TD]90[/TD]
[TD]9[/TD]
[TD]810[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]BBOZ[/TD]
[TD]3/6/2016[/TD]
[TD]80[/TD]
[TD]8[/TD]
[TD]640[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]BBUS[/TD]
[TD]5/6/2016[/TD]
[TD]70[/TD]
[TD]7[/TD]
[TD]490[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]ANZ[/TD]
[TD]7/7/2016[/TD]
[TD]60[/TD]
[TD]2[/TD]
[TD]120[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]BBOZ[/TD]
[TD]1/8/2016[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]80[/TD]
[TD]11[/TD]
[TD]880[/TD]
[TD]160[/TD]
[/TR]
[TR]
[TD]ANZ[/TD]
[TD]5/8/2016[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]140[/TD]
[TD]12[/TD]
[TD]1,680[/TD]
[TD]600[/TD]
[/TR]
[TR]
[TD]ANZ[/TD]
[TD]10/8/2016[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]20[/TD]
[TD]13[/TD]
[TD]260[/TD]
[TD]220[/TD]
[/TR]
[TR]
[TD]BBOZ[/TD]
[TD]15/8/2016[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]90[/TD]
[TD]5[/TD]
[TD]450[/TD]
[TD]-280[/TD]
[/TR]
</tbody>[/TABLE]