Chris Macro
Well-known Member
- Joined
- Nov 2, 2011
- Messages
- 1,345
- Office Version
- 365
- Platform
- Windows
My main goal is to calculate a weighted average purchase price that is variable and I not really sure how to tackle this. I have made a simple example and hopefully you all will be able to follow along (let me know if you need more details)
Example: I have 4 types of stock (Financial, Banking, Industrial, Technology) that I may purchase. If I decide to buy/sell these stocks it is recorded in this table:
<b>Excel 2007</b><table cellpadding="2.5px" rules="all" style=";background-color: #FFFFFF;border: 1px solid;border-collapse: collapse; border-color: #A6AAB6"><colgroup><col width="25px" style="background-color: #E0E0F0" /><col /><col /><col /><col /><col /></colgroup><thead><tr style=" background-color: #E0E0F0;text-align: center;color: #161120"><th></th><th>T</th><th>U</th><th>V</th><th>W</th><th>X</th></tr></thead><tbody><tr ><td style="color: #161120;text-align: center;">1</td><td style="text-align: center;color: #FFFFFF;background-color: #1F497D;;">Age</td><td style="text-align: center;color: #FFFFFF;background-color: #1F497D;;">Buy/Sell</td><td style="text-align: center;color: #FFFFFF;background-color: #1F497D;;">Stocks</td><td style="text-align: center;color: #FFFFFF;background-color: #1F497D;;">Quantity</td><td style="text-align: center;color: #FFFFFF;background-color: #1F497D;;"> Purchase Price </td></tr><tr ><td style="color: #161120;text-align: center;">2</td><td style="text-align: center;;">25</td><td style="text-align: center;;">Bought</td><td style=";">Industrial</td><td style="text-align: center;;">10</td><td style="text-align: right;;"> $ 10.00 </td></tr><tr ><td style="color: #161120;text-align: center;">3</td><td style="text-align: center;;">27</td><td style="text-align: center;;">Bought</td><td style=";">industrial</td><td style="text-align: center;;">5</td><td style="text-align: right;;"> $ 6.00 </td></tr><tr ><td style="color: #161120;text-align: center;">4</td><td style="text-align: center;;">27</td><td style="text-align: center;;">Bought</td><td style=";">Financial</td><td style="text-align: center;;">6</td><td style="text-align: right;;"> $ 20.00 </td></tr><tr ><td style="color: #161120;text-align: center;">5</td><td style="text-align: center;;">28</td><td style="text-align: center;;">Sold</td><td style=";">Industrial</td><td style="text-align: center;;">-11</td><td style="text-align: right;;"> $ 12.00 </td></tr></tbody></table><p style="width:4.8em;font-weight:bold;margin:0;padding:0.2em 0.6em 0.2em 0.5em;border: 1px solid #A6AAB6;border-top:none;text-align: center;background-color: #E0E0F0;color: #161120">Player 1</p><br /><br />
If I purchase more of a stock in a different year I want to be able to calculate the weighted average to get a more realistic price. Logic for the first two purchases of Industrial stock would be (10/15)($10) +(5/15)($6) = $8.67. Now if I were to sell 11 shares, I need the logic to determine that my ten $10 shares are gone and that I only have four $6 shares left.
I am assuming I need to start by looking up a stock based on if its a "Bought or Sold" and its name. From there I am not quite sure how to handle coding this. Please let me know if you have any suggestions
Example: I have 4 types of stock (Financial, Banking, Industrial, Technology) that I may purchase. If I decide to buy/sell these stocks it is recorded in this table:
<b>Excel 2007</b><table cellpadding="2.5px" rules="all" style=";background-color: #FFFFFF;border: 1px solid;border-collapse: collapse; border-color: #A6AAB6"><colgroup><col width="25px" style="background-color: #E0E0F0" /><col /><col /><col /><col /><col /></colgroup><thead><tr style=" background-color: #E0E0F0;text-align: center;color: #161120"><th></th><th>T</th><th>U</th><th>V</th><th>W</th><th>X</th></tr></thead><tbody><tr ><td style="color: #161120;text-align: center;">1</td><td style="text-align: center;color: #FFFFFF;background-color: #1F497D;;">Age</td><td style="text-align: center;color: #FFFFFF;background-color: #1F497D;;">Buy/Sell</td><td style="text-align: center;color: #FFFFFF;background-color: #1F497D;;">Stocks</td><td style="text-align: center;color: #FFFFFF;background-color: #1F497D;;">Quantity</td><td style="text-align: center;color: #FFFFFF;background-color: #1F497D;;"> Purchase Price </td></tr><tr ><td style="color: #161120;text-align: center;">2</td><td style="text-align: center;;">25</td><td style="text-align: center;;">Bought</td><td style=";">Industrial</td><td style="text-align: center;;">10</td><td style="text-align: right;;"> $ 10.00 </td></tr><tr ><td style="color: #161120;text-align: center;">3</td><td style="text-align: center;;">27</td><td style="text-align: center;;">Bought</td><td style=";">industrial</td><td style="text-align: center;;">5</td><td style="text-align: right;;"> $ 6.00 </td></tr><tr ><td style="color: #161120;text-align: center;">4</td><td style="text-align: center;;">27</td><td style="text-align: center;;">Bought</td><td style=";">Financial</td><td style="text-align: center;;">6</td><td style="text-align: right;;"> $ 20.00 </td></tr><tr ><td style="color: #161120;text-align: center;">5</td><td style="text-align: center;;">28</td><td style="text-align: center;;">Sold</td><td style=";">Industrial</td><td style="text-align: center;;">-11</td><td style="text-align: right;;"> $ 12.00 </td></tr></tbody></table><p style="width:4.8em;font-weight:bold;margin:0;padding:0.2em 0.6em 0.2em 0.5em;border: 1px solid #A6AAB6;border-top:none;text-align: center;background-color: #E0E0F0;color: #161120">Player 1</p><br /><br />
If I purchase more of a stock in a different year I want to be able to calculate the weighted average to get a more realistic price. Logic for the first two purchases of Industrial stock would be (10/15)($10) +(5/15)($6) = $8.67. Now if I were to sell 11 shares, I need the logic to determine that my ten $10 shares are gone and that I only have four $6 shares left.
I am assuming I need to start by looking up a stock based on if its a "Bought or Sold" and its name. From there I am not quite sure how to handle coding this. Please let me know if you have any suggestions