I need to display in my system the amount of stocks that I own and the average price it took me to buy them. I am having a problem doing that when I include the selling.

Lets say I bought 4 stocks in 100 usd each.
and I sold 2 stocks for 110 usd each.

Now my position is 2 stocks for what average price ?
Option A: (4 * 110 + 2 * 100)/6 = 106.667
Option B: (4 * 110 - 2 * 100)/2 = 120 (doesnt think so )

If I do go with option A then if I sold 2 more for 110 I would get 0 amount but average (4*100+2*110+2*110)/8 - 105 . 0 stocks for 105 doesnt make any sense. thanks.

  • $\begingroup$ Do you mean you buy 4 shares of company A and then sell 2 of the them (same stock)? $\endgroup$ Apr 13, 2011 at 11:17
  • $\begingroup$ yepp. and then I need to know how much "I am worth". What I would like to do is amount*average $\endgroup$
    – Bick
    Apr 13, 2011 at 12:14
  • 3
    $\begingroup$ I don't really get it. Your average purchase price is still 100. And your current position is worth: current share price * number of shares. Maybe you need to rephrase your question. And BTW, I don't think it's very on topic here in its current form. $\endgroup$ Apr 13, 2011 at 13:30
  • $\begingroup$ Agreed with @Karol. The average price it took me to buy them doesn't depend on the sale price. And this is a very basic question. $\endgroup$ Apr 13, 2011 at 13:40
  • 2
    $\begingroup$ @user722 What data are you trying to show? Cumulative P&L? Transaction cost modeling? The appropriate formula will depend on what you want, which isn't clear from your question. $\endgroup$ Apr 13, 2011 at 14:06

2 Answers 2


I think there are two ways:

1) distinguish sells and purchases and calculate average for each of them; it will be $100$ and $110$ for sells.

2) calculate not average price which took you to buy... but average trading price. Then it will be $106.67$.


The weights are, by definition, positive, and add to do normalization to the total amount the wights are calculated for. The title of the question does not make sense.

However, what it happend in your case is that you have bought 4 and sold 2, and in the end, you have remained with 2 bought ones. Between T0 and T_final you have paid $P&L= -4*100+ 2*120 = -400 + 240 =-160$ and you are left with 2. Therefore their (net) price is $-160/2=-80$.

The question here is more about the fact of selling the TWO actions because you HAD FOUR actions and because you wanted to be left with TWO actions in the end. And selling them at 110 because you have bought them at 100. In practice you have 100=100(4) and 120=120(2) - the number you buy/sell does influence the price. The events are not indipendent, so you can not apply "normal" averaging and weighting, but you have to work with bayesian statistics.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.