<p>I am a Canadian, and under Canadian tax laws, I think there are at least two ways of determining your cost basis for shares. I am not going to get into the details of tax accounting; please see a qualified tax professional for advice.</p>

<p>However, if you just want to track your profit and loss for analysis purposes, the standard way of determining the book value of your positions is to track the average cost. You track the number of shares you own, and their total cost. </p>

<p>When you buy more shares,</p>

<ul>
<li>the total cost goes up by the total you paid in the transaction (=(# shares in the transaction) * (transaction price)),</li>
<li>the number of shares increases by the amount in the transaction</li>
</ul>

<p>You get the average cost by dividing the total cost by the number of shares.</p>

<p>When you sell, the price you sell at does not matter for the determination of your average cost. You reduce the number of shares by the number of shares in the transaction, and you reduce the total cost by the (average price)*(number of shares in the transaction). This means that selling does not change the average price, just the number of shares.</p>

<p>Your profit on selling is based on comparing the selling price to the average cost. This would be the “cost of goods sold” in inventory accounting. (If you want more details on this subject, you could look for primers on inventory accounting on the internet.)</p>

<p>What you appear to want to do is to roll the profits or losses from a sale into the total cost. That is, if you made a profit, use that to lower the “total cost” of the shares so that you can compare that average of that “total cost” to the market price, and quickly tell if you are profitable.</p>

<p>Although that might be convenient, it probably would not be acceptable under most accounting conventions (so no textbook will tell you to do it that way). It also would give some strange-looking results. If you made \$1 million profit on some shares, and then sold all but one of those shares, you would have a “cost” of about -\$1 million for that one share. Most people would look at you funny if you showed them that number on a spreadsheet.</p>

CC BY-SA 4.0
2021-01-18T10:50:51.753Z
Hi, how to calculate avg. price if you initially short (e.g. via a repo), so -200 @ 120.0 and then +100@110, what would the average price be? The naive formula would give me -110.0. Thanks!
Pontus Hultkrantz
CC BY-SA 4.0
2021-01-18T13:18:34.337Z
The cost basis after the first short is $120, you have negative shares (and a negative payment - you get money). Buying back some shares reduces the amount you are short, but does not change the cost basis under any accepted accounting treatment. The only way to affect the cost basis is have multiple short transactions at different prices, then buy back some shares. In that case, there is a debate what shares to match against the buy back.
Brian Romanchuk
CC BY-SA 3.0
2018-02-07T02:55:32.647Z
2018-02-07T02:55:32.647Z
Brian Romanchuk
<p>Your average price per stock is 2.083$.
don't include sales because you are calculating the amount you spent to buy stock.</p>
<p>Your profit is 4$ on 7 shares sold at the end of the day, if we include sales in the calculation, we reduce the price of the next buy. Which you did in the last calculation of yours.</p>

CC BY-SA 4.0
2020-08-21T13:06:49.277Z
2023-09-17T06:38:00.083Z
2023-09-17T06:38:00.083Z
Cherry
<p>I am not sure that thi is what you want but you must always work on purchases and stock to calculate your average. what I mean is that if you purchased 10 shares at 2.00 and 5 shares at 3 average will be as you calculated 2.33.</p>
<p>Then you have bought 10 @ 2.00 this must go as:</p>
<pre><code>New Waited Average Price =((stok * price) + (10 * 2.00))/(stock + 10) = new1
</code></pre>
<p>Then sold 7 @ 3 so you got a newStock with stock waited average price is still &quot;new1&quot; after that you bought 2 @ 2.50 so waited average price will be now:</p>
<pre><code>New Waited Average Price =((newStok * new1) + (2 * 2.50))/(newStock + 2) = new2
</code></pre>
<p>Hope this help someone.</p>

CC BY-SA 4.0
2020-05-25T20:27:06.347Z
2020-08-22T11:06:08.573Z
2020-08-22T11:06:08.573Z
Sparks
<p>I wanted to get my average buy price for some stocks I bought and see if I made money.</p>
<p>So far, for just buying and then later selling, I have been calculating the average buy price using this formula</p>
<pre><code>((stockamount * price) + (stockamount * price)) / (stockamount + stockamount)
</code></pre>
<p>So if I buy 10 shares at 2.00 and 5 shares at 3, I would get an average buy price of</p>
<pre><code>((10 * 2.00) + (5 * 3.00)) / (10 + 5) = 2.33
</code></pre>
<p>This is how I have calculated the average sell price as well.</p>
<hr />
<p>Recently, I bought some shares, sold them at a higher cost, and then re-bought some when they slightly went under what I sold them at.</p>
<p>I have no idea how to determine my average buy price because I re-bought some.
here is sample data</p>
<pre><code>bought 10 @ 2.00
sold    7 @ 3.00
bought  2 @ 2.50
</code></pre>
<p>I thought maybe doing something like this</p>
<pre><code>((10 * 2.00) - (7 * 3.00) + (2 * 2.50)) / (10 - 7 + 2) = 0.8
</code></pre>
<p>It does not make any sense that my average buy was 0.8</p>
<p>I have searched but can't find the answer to a buy, sell and rebuy. Please let me know if someone knows the correct formula to calculate the average buy price when you buy, sell and rebuy.</p>
<p>Thanks!</p>

<finance><stock-market><financial-markets><price>
How to calculate average buy price when you buy, sell and rebuy
Zacharia Hildreth
# How to calculate average buy price when you buy, sell and rebuy

(Asked by: username_0 on 2018-02-07)

I wanted to get my average buy price for some stocks I bought and see if I made money.
So far, for just buying and then later selling, I have been calculating the average buy price using this formula
((stockamount * price) + (stockamount * price)) / (stockamount + stockamount)

So if I buy 10 shares at 2.00 and 5 shares at 3, I would get an average buy price of
((10 * 2.00) + (5 * 3.00)) / (10 + 5) = 2.33

This is how I have calculated the average sell price as well.

Recently, I bought some shares, sold them at a higher cost, and then re-bought some when they slightly went under what I sold them at.
I have no idea how to determine my average buy price because I re-bought some.
here is sample data
bought 10 @ 2.00
sold    7 @ 3.00
bought  2 @ 2.50

I thought maybe doing something like this
((10 * 2.00) - (7 * 3.00) + (2 * 2.50)) / (10 - 7 + 2) = 0.8

It does not make any sense that my average buy was 0.8
I have searched but can't find the answer to a buy, sell and rebuy. Please let me know if someone knows the correct formula to calculate the average buy price when you buy, sell and rebuy.
Thanks!

**Tags:** finance, stock-market, financial-markets, price

---

## 3 answers

### Answer by username_1 on 2018-02-07. Score: 3

I am a Canadian, and under Canadian tax laws, I think there are at least two ways of determining your cost basis for shares. I am not going to get into the details of tax accounting; please see a qualified tax professional for advice.

However, if you just want to track your profit and loss for analysis purposes, the standard way of determining the book value of your positions is to track the average cost. You track the number of shares you own, and their total cost.

When you buy more shares,

* the total cost goes up by the total you paid in the transaction (=(# shares in the transaction) \* (transaction price)),
* the number of shares increases by the amount in the transaction

You get the average cost by dividing the total cost by the number of shares.

When you sell, the price you sell at does not matter for the determination of your average cost. You reduce the number of shares by the number of shares in the transaction, and you reduce the total cost by the (average price)\*(number of shares in the transaction). This means that selling does not change the average price, just the number of shares.

Your profit on selling is based on comparing the selling price to the average cost. This would be the “cost of goods sold” in inventory accounting. (If you want more details on this subject, you could look for primers on inventory accounting on the internet.)

What you appear to want to do is to roll the profits or losses from a sale into the total cost. That is, if you made a profit, use that to lower the “total cost” of the shares so that you can compare that average of that “total cost” to the market price, and quickly tell if you are profitable.

Although that might be convenient, it probably would not be acceptable under most accounting conventions (so no textbook will tell you to do it that way). It also would give some strange-looking results. If you made \$1 million profit on some shares, and then sold all but one of those shares, you would have a “cost” of about -\$1 million for that one share. Most people would look at you funny if you showed them that number on a spreadsheet.

> **Comments:**
> **username_2**: Hi, how to calculate avg. price if you initially short (e.g. via a repo), so -200 @ 120.0 and then +100@110, what would the average price be? The naive formula would give me -110.0. Thanks!  
> **username_1**: The cost basis after the first short is $120, you have negative shares (and a negative payment - you get money). Buying back some shares reduces the amount you are short, but does not change the cost basis under any accepted accounting treatment. The only way to affect the cost basis is have multiple short transactions at different prices, then buy back some shares. In that case, there is a debate what shares to match against the buy back.  

---

### Answer by username_3 on 2020-08-21. Score: 0

Your average price per stock is 2.083$.
don't include sales because you are calculating the amount you spent to buy stock.

Your profit is 4$ on 7 shares sold at the end of the day, if we include sales in the calculation, we reduce the price of the next buy. Which you did in the last calculation of yours.


---

### Answer by username_4 on 2020-05-25. Score: -1

I am not sure that thi is what you want but you must always work on purchases and stock to calculate your average. what I mean is that if you purchased 10 shares at 2.00 and 5 shares at 3 average will be as you calculated 2.33.
Then you have bought 10 @ 2.00 this must go as:
New Waited Average Price =((stok * price) + (10 * 2.00))/(stock + 10) = new1

Then sold 7 @ 3 so you got a newStock with stock waited average price is still "new1" after that you bought 2 @ 2.50 so waited average price will be now:
New Waited Average Price =((newStok * new1) + (2 * 2.50))/(newStock + 2) = new2

Hope this help someone.


---

