Calculator

Stock average calculator

Add the shares, price and commission of each buy to get one average price per share. The arithmetic is exact: no floating point ever touches your numbers.

Calculator

One row per buy. Leave commission empty if there was none. Digits and a decimal point only, no thousands separators.

Paste lots from a spreadsheet or broker CSV

One lot per line: shares, price, commission (commission optional). Comma, tab or semicolon between columns. A header line is skipped. Nothing is uploaded; the text is read in this page.

Average price per share
–
Total shares
–
Total cost, with commissions
–
Of which commissions
–

Arithmetic only. Not tax, financial or investment advice. Nothing you enter leaves your browser.

The formula

average price = (sum of shares × price + sum of commissions) ÷ sum of shares

Commissions are part of what each lot cost, so they are included. To get the average of the prices alone, leave the commission column empty. Total shares is the plain sum, so a fractional share counts as a fraction.

Worked example

Three invented buys of a made-up stock. The "Load the example" button above fills these same rows. Each figure in the table was produced at build time by the function the calculator runs.

Three synthetic buys
LotSharesPriceShares × priceCommission
110048.204820.004.95
25041.752087.504.95
325.539.10997.050.00
Total175.57904.559.90

Total cost is 7904.55 + 9.90 = 7914.45. Divided by 175.5 shares, the average price is 45.0966 per share. Without the commissions it would be 45.0402.

Rounding and exactness

  • Rounding rule: half up. The average price is rounded to 4 decimals; total cost and total commission to 2. Total shares is never rounded.
  • One rounding step per figure. Nothing is rounded along the way, so the average price comes from the exact total cost, not from a rounded one.
  • No floating point. Each number you type is read as exact decimal text and held as a scaled whole number (BigInt). Sums, products and the division are whole-number arithmetic.
  • Input limits. Digits and one decimal point, at most 40 characters per number, shares above zero, price and commission zero or more. Anything else is flagged, never guessed.
  • Tested against a reference. The page's function is run against 35 test vectors (single and many lots, fractional shares, very large numbers, rounding ties, invalid input) computed independently with Python's decimal module.

What it does not do

Every row is treated as a purchase. The calculator does not model sales, stock splits, currency conversion, fees other than the commission you enter, or the rules of any tax authority. A figure from another source may differ if it handles fees or lots differently, so compare the method, not just the number. To see the result of a purchase and a later sale, use the stock profit calculator.

Embed it

You can place this calculator on your own page. Copy the snippet; it loads a small page from this site and keeps the attribution link.

Have 200 rows?

Typing a handful of buys is fine. If the buys sit in a broker statement PDF, Statementizer reads supported broker statements into a spreadsheet and lets you check each row against the page it came from. See what it reads from Interactive Brokers Activity Statements.

See how Statementizer works

Sources

The formula is arithmetic, so there is no regulator or vendor to cite for it. These are the references for how it is implemented and checked.

Verified on 2026-10-16 by the Statementizer Team.