Keeping running total for value of stocks

34 Views Asked by At

This should be pretty simple but I can't think of the best way to do this. Lets say I have the history of some buys and sells for a given stock:

enter image description here

What I want to do is keep a running number to what my accumulated cost per share is. This would be the price to which if I sold my currently owned stocks, I would break even at.

So for the example above, When I get to the third buy in the list, I would have $9$ shares so when I get to the first sell, I would be left with $8$ but those $8$ didn't all get purchased at the same price so how would I keep track of this?

What I have tried

I started with keeping a running total of quantity owned, adding during buys and removing during sells. With this, I keep a running total cost column to which I add on the ($price \ per \ share * number \ of \ shares$) on all buys. If a sell then I don't add anything to the total costs and if the number of shares $= 0$ ever then the running costs become $0$ as well. Then the average cost per share is simply the running total cost column divided by the running total quantity one.

enter image description here

Does this make sense or is that inaccurate to go at it this way?

1

There are 1 best solutions below

0
On

Your first five (non-blank) columns are good details (knowing the value of stocks is good). But it seems to me that you're overthinking the cost/value per share if your goal is just to find out what price you "would break even at."

To figure out the price for breaking even, just ignore how many shares you bought or sold, and just pay attention to your overall cost. How much money have you paid, minus how much of that money have you received back from any sales that you did.

Then just take that number, and divide it by the number of shares that you have.

Some of your analysis seems to be trying to find out something different, like whether a particular purchased stock was a worthwhile purchase (and, in general, understanding how well each individual stock has done). If that's your goal, then please formulate a clear answerable question of exactly what you're looking for. Or maybe you're trying to compare the break-even price to the stock's price at a later time. Such a detail might use the "break even" price at various points in time. Again, to be able to have solid answers you can be confident in, you should have clear mathematical questions so you can recognize a correct answer when you come across it.