ForHosting KIT · Finance & money

Stock average calculator

100 shares bought at 10 plus 50 shares at 16 cost 1,800 for 150 shares, an average of 12 per share, because the bigger lot pulls the average toward its own price. Enter each lot and get one cost basis. Free in your browser.

  • Free
  • Runs in your browser
  • No sign-up
  • Your data stays on your device
Use it from WebAPIEmailTelegramApp soon

Average cost per share is the weighted purchase price of a stock position: each lot contributes its cash outlay, and that total cost is divided by the total number of shares you actually hold. Investors, tax notebooks, DRIP trackers, and classroom finance drills need that single figure so a later sale can be marked against one cost basis instead of a messy list of fills. This stock average calculator takes a list of share quantities and purchase prices, multiplies each lot, sums the cash, sums the shares, and returns the weighted average price. A simple mean of the prices would treat a ten-share lot the same as a thousand-share lot; weighting by shares does not. Fractional shares are allowed.

What average cost per share is and why the weights are the shares

The average cost per share of a position is not the arithmetic mean of the prices you paid. It is a share-weighted mean: each purchase contributes cash equal to shares times price, those cash outlays are added, and the sum is divided by the total number of shares from every lot.

A hundred shares bought at ten and fifty shares bought at sixteen cost one thousand plus eight hundred, which is one thousand eight hundred of cash for one hundred fifty shares, so the average is twelve, not the unweighted mean of ten and sixteen which would be thirteen. The larger lot pulls the average toward its own price, which is exactly what a brokerage cost-basis screen does when it reports average cost.

Fractional shares are first-class: a dividend-reinvestment plan that credits a fraction of a share at a printed price is a lot like any other, and it enters the sums at face value. Zero-share lots contribute nothing to either sum; they are allowed as long as some other lot supplies a strictly positive share count. Negative purchase prices are likewise rejected.

The calculator does not download a quote, does not apply wash-sale adjustments, and does not choose between average-cost and specific-identification for you. It only forms the weighted average from the lots you already have.

Where a stock average calculator earns its keep

People who type stock average into a search box already know they want the cost basis of a position from the lots they bought, not a live quote, not a beta against the market, and not a generic weighted-mean statistics tool that asks for abstract values and weights.

A publisher ranking for that query is serving retail investors who dollar-cost-averaged into a ticker over several months, tax-prep notebooks that must print one average cost per share on a disposal worksheet, and engineers who need a deterministic oracle that rejects a zero total share count instead of silently producing Infinity. DRIP and fractional-share brokers credit odd quantities at printed prices; those lots belong in the same sum as whole-share market buys. Failed validation does not consume balance.

Pair this capability with a separate gain-or-loss tool when you later sell; keep this surface focused on the average purchase price that people mean when they search stock average.

Dollar-cost averaging into one ticker

Enter each buy as shares and purchase price to publish one average cost per share instead of averaging the prices as if every lot were the same size.

DRIP and fractional-share ledgers

Include fractional reinvestment lots at their printed prices so the same weighted identity covers whole-share buys and drip credits.

How is average cost per share calculated?

Send purchases as lots of shares and purchase price. Average price equals the sum of shares times price, divided by the sum of shares. Example: 100 shares at 10 and 50 shares at 16 yield average price 12.

What happens if the total number of shares is zero?

Average cost divides by total shares, so a zero (or empty) quantity total is rejected and is not billed.

Why not just average the purchase prices?

A simple mean treats every lot as equal. A hundred-share lot at 10 must weigh twice as much as a fifty-share lot at 16; this calculator weights by shares.

Can I enter fractional shares or a single lot?

Yes. Fractional shares are allowed, and a single lot returns that lot's purchase price as the average. Negative shares or negative prices are rejected.

Does it handle wash sales or pick a cost-basis method for me?

No. It does not apply wash-sale adjustments and does not choose between average cost and specific identification. It only forms the share-weighted average from the lots you enter, and it does not fetch a live quote.

Everything on this page is available programmatically. This section is for teams who want to wire it into their own systems; everyone else can just use the tool above.

POSThttps://api.kit.forhosting.com/fin/stock-average

Prefer to automate it? One authenticated POST creates the task; the result comes back by webhook or a signed link. The same capability also runs here on the web, by email and from Telegram — and soon from our app too.

curl -X POST https://api.kit.forhosting.com/fin/stock-average \
  -H "Authorization: Bearer $KIT_KEY" \
  -H "Content-Type: application/json" \
  -d '{"purchases":[{"shares":100,"price":10},{"shares":50,"price":16}]}'
{
  "purchases": [
    {
      "shares": 100,
      "price": 10
    },
    {
      "shares": 50,
      "price": 16
    }
  ]
}
{
  "task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
  "type": "fin.stock_average",
  "status": "queued",
  "_links": {
    "result": "/tasks/tsk_…/result"
  }
}

The API is asynchronous: the call returns a task_id immediately and the result arrives by webhook. Polling is capped at 1 req/s per task.

Per request$0.002

Published price — no tokens, no invented credits. A failed task is never charged.

max_items10000
HTTPCodeMeaning
401unauthorizedMissing or invalid API key.
402insufficient_balanceYour balance doesn't cover the task price.
404unknown_typeThat task type doesn't exist.
429rate_limitedToo many requests. Use the webhook instead of polling.

If the total number of shares is zero the ratio is undefined and the task fails with invalid_input rather than Infinity. Successful calls are billed at $0.002; invalid input is not charged.

What average cost per share is and why the weights are the shares

Write that identity as average_price equals the sum of shares_i times price_i, divided by the sum of shares_i. When every lot has zero shares there is no denominator, and the calculator rejects the request instead of returning Infinity or a NaN that a downstream tax form would treat as a number. Negative share counts are not a sale in this model; treating a negative quantity as a disposal would silently mix FIFO matching with average-cost accounting, so they are invalid_input.

Input contract, response shape, and validation

Each object carries shares and price as finite numbers. shares is the quantity bought in that lot and must be greater than or equal to zero; fractional shares are allowed. price is the purchase price per share in currency units and must be greater than or equal to zero. A zero total share count would make the denominator zero, so it is a hard failure rather than Infinity. Example: one hundred shares at ten and fifty shares at sixteen yield total shares one hundred fifty, total cost one thousand eight hundred, and average price twelve. POST a JSON body with one required array, purchases, of at least one object. Aliases lots, trades, buys, rows, and fills are accepted so a broker export does not need a rename step. At most ten thousand lots are read; each shares and price value must stay within an absolute value of one trillion so products remain finite IEEE doubles on the Worker and in the browser. Missing purchases, an empty list, non-numeric tokens, NaN, Infinity, a negative share count, a negative purchase price, or a list whose share quantities sum to zero fail with invalid_input naming the problem and are not billed. On success the body returns lot_count, total_shares, total_cost, average_price as their quotient, an echoed lots array with each lot's shares, price, and cost, and a formula string set to average_price equals the sum of shares times price over the sum of shares. Prefer JSON numbers over currency-formatted strings; currency marks and thousands separators are not parsed. Pricing for a successful item is a flat $0.002.

Where a stock average calculator earns its keep

Classroom personal-finance courses assign cost-basis worksheets and need an oracle that marks an empty or all-zero quantity list as invalid_input. Automation pipelines call the same API contract at $0.002 per successful item without standing up a spreadsheet service. Keep requests small, pin the rounded average_price and total_cost in tests, and you get reproducible share-weighted cost basis for widgets, notebooks, and edge workers without standing up a full portfolio ledger.

Tax and cost-basis worksheets

Sum lots into total cost and total shares, then pin average_price on a disposal worksheet. A zero total share count is rejected as invalid_input.

What does the stock average calculator cost?

The browser tool is free. API requests use prepaid KIT balance at $0.002 per successful call; invalid input is not billed.

Read the full KIT documentation →