Stock Average Calculator

Last updated

Adds up to six purchases into a weighted average cost per share: the total cost, commissions included, divided by the total shares. It values the position at the current price for the gain or loss in money and percent. For a target average it solves n = (S(A − T) + F) ÷ (T − P) for the shares to buy at the current price P with commission F, and explains when no purchase can reach the target.

Average cost per share –
Total shares –
Total invested –
Value at current price –
Gain or loss –
Gain or loss (%) –
Shares to buy for target –
Cost of those shares –
Reaching your target –
Lot by lot at the current price

Enter the shares and price of each purchase, up to six of them, and the price the stock trades at now. The calculator adds the purchases into one average cost per share, values the position at the current price and shows the gain or loss in money and as a percentage, lot by lot and in total. Add a target average and it works out how many shares you would have to buy at the current price to move your average there, and what they would cost, or explains why no number of shares can. Lots 2 to 6 are optional, and fractional shares are fine. The defaults describe 100 shares bought at 50, 50 more at 42 and 75 more at 36, with the stock now at 32 and a target average of 40.

How the average cost is worked out

Each purchase costs its shares times its price, plus the commission. The average is the total cost divided by the total shares:

A = (s1p1 + s2p2 + … + kF) ÷ (s1 + s2 + …)

Here s and p are each lot's shares and price, k is the number of lots and F the commission per trade. This is a weighted average: a lot of 100 shares counts twice as much as a lot of 50. It is the price at which selling everything would break even before selling costs. The gain or loss is the shares times the current price, less the total cost, and the percentage is that gain or loss divided by the total cost, the same simple return on investment you would work out for any holding.

The average is shown to your currency's usual decimals, cents for dollars, and every judgement the page makes about it, such as telling you a target is already met, is made on that rounded figure, so the words always agree with the number beside them.

Averaging down to a target

Buying n more shares at the current price P changes the average from A to

new average = (SA + nP + F) ÷ (S + n)

where S is the shares you hold. Setting that equal to a target T and solving gives the shares to buy:

n = (S(A − T) + F) ÷ (T − P)

Without a commission, the new average always lands between your old average and the price you buy at, and the more you buy the closer it gets to that price without reaching it. So, without one, averaging down works only when the current price is below the target, and averaging up only when it is above. A commission moves the starting point to (SA + F) ÷ S, and the target then has to lie between that figure and the price. As the target nears the current price the shares needed grow without limit, and a target at or past the price is out of reach, which the calculator explains in words. When the answer is fractional, the calculator also gives the next whole number of shares, their cost and the average they leave.

The default example

The three lots cost 5,000, 2,100 and 2,700, a total of 9,800 for 225 shares, so the average is 43.56. At 32 the shares are worth 7,200, a loss of 2,600, or 26.53%.

To bring the average down to 40, the formula gives 225 × (43.56 − 40) ÷ (40 − 32). Worked in exact figures that is 800 ÷ 8 = 100 shares, costing 3,200, which makes 325 shares for 13,000. A target of 38 needs 208.3333 shares costing 6,666.67, or 209 whole shares costing 6,688, which leave an average of 37.99. A target of 30 is impossible at 32, because buying at 32 can only pull the average toward 32.

Averaging up works the same way from the other side. If the stock were at 50, raising the average to 45 would take 65 shares costing 3,250.

Where the idea comes from

Dollar-cost averaging means investing the same amount at regular intervals, so a fixed sum buys more shares when the price is low and fewer when it is high. George Constantinides opened his 1979 paper, A Note on the Suboptimality of Dollar-Cost Averaging as an Investment Policy, by quoting the 1975 edition of Burton Malkiel's A Random Walk Down Wall Street: periodic investments of equal dollar amounts in common stocks "can substantially reduce (but not avoid) the risks of equity investment by insuring that the entire portfolio of stocks will not be purchased at temporarily inflated prices."

Because a fixed sum buys more shares at low prices, the average cost per share always comes out at or below the simple average of the prices paid. Invest 1,000 at 50, at 40 and at 25 and you hold 85 shares at an average of 35.29, against a simple average price of 38.33. At 40, the price of the second purchase, the position is 400 ahead.

Holding back money to average in is another matter. Vanguard's 2023 paper Cost averaging: Invest now or temporarily hold your cash? compared investing a sum at once with splitting it into three equal monthly purchases. Using MSCI World returns for 1976 to 2022 and comparing wealth after a year, investing at once came out ahead 68% of the time, while averaging in still beat leaving the money in cash 69% of the time. For an all-stock portfolio the median outcome was 2.2% more wealth from investing at once, though averaging in came out ahead in the worst outcomes, below the 25th percentile. The paper lists Constantinides among a body of research that generally favors investing the lump sum.

Your average is not always your tax basis

US brokers report the basis of shares they sell for you because of a law of October 3, 2008, the Energy Improvement and Extension Act, which added subsection (g) to section 6045 of the Internal Revenue Code. It covers stock acquired from January 1, 2011, and from January 1, 2012 for stock that may use an average basis. For other stock the broker works first in, first out unless you identify the shares sold.

The regulation behind it, 26 CFR 1.1012-1, sets the same default: if you sell shares bought on different dates or at different prices and don't adequately identify the lot, the sale is charged against the earliest lot you bought. The average basis method, under which each share's basis is the total basis of the shares in the account divided by their number, may be used only for shares of a regulated investment company, such as a mutual fund, and for shares acquired after December 31, 2010 through a dividend reinvestment plan.

So for an ordinary stock the average on this page is a breakeven and performance figure, not necessarily what goes on a tax return. Selling 100 of the default shares at 32 with no identification reports the first lot's loss of 1,800. If you identify the 75 shares bought at 36 and 25 of those bought at 42 instead, the loss is 550. The average would have suggested 1,155.56. Commissions, on the other hand, do belong in the basis: IRS Publication 551 says the basis of stock you buy is generally the purchase price plus costs of purchase, such as commissions and recording or transfer fees.

What the calculator leaves out

It assumes every lot is still held. If you have sold shares, enter the lots you still own. Stock splits change the share count and the price per share in step, so enter lots on a post-split basis. Reinvested dividends are purchases too, and belong in their own lots. Selling costs and taxes are left out of the gain or loss, and the percentage change in the share price since any one purchase is a different figure from the return on the whole position.

Averaging down also has a tax trap. Under the wash sale rule, a loss on shares you sell is not deductible if you bought substantially identical shares within 30 days before or after the sale; the disallowed loss is added to the basis of the new shares instead. And buying more of a falling stock lowers the breakeven price only by putting more money into the same company. The calculator shows what a purchase does to the average, not whether the stock will recover.

These figures are estimates for understanding a position, not tax or investment advice; your broker's records and the method you elect decide your reported basis. See the site disclaimer.

Frequently asked questions

How do you calculate the average price of a stock?

Multiply the shares in each purchase by the price paid, add any commissions, add up the results and divide by the total number of shares. With the defaults, 100 shares at 50, 50 at 42 and 75 at 36 cost 9,800 for 225 shares, an average of 43.56 a share. The simple average of the three prices, 42.67, is wrong because it gives the 50-share lot the same weight as the 100-share lot.

How many shares do I need to buy to average down?

Multiply the shares you hold by the gap between your average and the target, then divide by the gap between the target and the current price. With the defaults and a price of 32, reaching an average of 40 takes 100 shares costing 3,200. Reaching 38 takes 208.3333 shares costing 6,666.67, or 209 whole shares costing 6,688 for an average of 37.99. A target at or below the current price can never be reached.

Is my average price my cost basis for taxes?

For individual stocks in the US, usually not. Unless you identify which shares you sell, the regulations charge a sale against the earliest lot you bought, and the average basis method is allowed only for shares of a regulated investment company, such as a mutual fund, and shares bought through a dividend reinvestment plan after 2010. Selling 100 of the default shares at 32 reports the first lot's loss of 1,800, not the 1,155.56 the average would suggest.

Should I include commissions in my average cost?

Yes. IRS Publication 551 says the basis of stock you buy is generally the purchase price plus costs of purchase such as commissions. A 5 commission on each of the three default purchases raises the average from 43.56 to 43.62, and reaching 40 at a price of 32 then takes 102.5 shares costing 3,285 with the new trade's commission.

Does dollar-cost averaging beat investing a lump sum?

Usually not. Vanguard found in 2023 that investing at once beat splitting the money into three monthly purchases 68% of the time in global stock returns from 1976 to 2022, measured after a year, although splitting beat holding cash 69% of the time. What averaging does do is buy more shares when the price is low: 1,000 a time at 50, 40 and 25 buys 85 shares at an average of 35.29, below the simple average price of 38.33.

Sources

  1. 26 CFR § 1.1012-1 Basis of property, Legal Information Institute, Cornell Law School
  2. Publication 551, Basis of Assets, Internal Revenue Service, 2025
  3. 26 U.S. Code § 6045 Returns of brokers, Legal Information Institute, Cornell Law School
  4. 26 U.S. Code § 1091 Loss from wash sales of stock or securities, Legal Information Institute, Cornell Law School
  5. Cost averaging: Invest now or temporarily hold your cash?, Vanguard, 2023
  6. A Note on the Suboptimality of Dollar-Cost Averaging as an Investment Policy, Journal of Financial and Quantitative Analysis, Cambridge University Press, 1979