Interactive Cost Tracking

Average Cost Basis Visualizer

Track your investment cost basis over time with interactive charts. Enter transactions manually or upload CSV/JSON files to visualize how your average cost changes with each trade.

Position Settings

$

The initial AAPL trades and $185 price are constructed examples, not actual trades or a live quote. Symbol is a label only. USD display; use one currency and one position. Data stays in this page’s memory and is lost on reload; export before leaving. Import replaces all trades after validation.

Add Transaction

Position Summary - AAPL

Total Shares
150
Current position
Average Cost
$151.28704615
Per share
Total Cost Basis
$22,693.05692308
Investment in position
Current Value
$27,750.00
At $185.00/share
Unrealized P&L
+$5,056.94307692
+22.28%
Realized P&L
+$2,468.10692308
From closed trades
Remaining-Basis Price
$151.28704615
Excludes selling fees, tax and prior realized P&L

Cost Basis History

$228.00$171.00$114.00$57.00$0
Current: $185.00
Jan 15Mar 20May 10Jul 25Sep 15
Average Cost
Buy Transaction
Sell Transaction
Current Price

Transaction History

DateTypeSharesPriceFeesTotalAvg Cost AfterAction
2024-01-15BUY100$150.00$9.99-$15,009.99$150.0999
2024-03-20BUY50$165.00$9.99-$8,259.99$155.1332
2024-05-10SELL30$180.00$9.99+$5,390.01$155.1332
2024-07-25BUY75$145.00$9.99-$10,884.99$151.28704615
2024-09-15SELL45$190.00$9.99+$8,540.01$151.28704615

How the moving-average ledger works

This is a single-position, long-only accounting illustration. It pools purchase cost, including buy fees, and removes average basis at each sale. It is not a broker statement, a tax-lot engine or a recommendation about when to trade.

Enter a consistent history

  1. Use one instrument, account and currency. The symbol is a label; changing it does not clear or switch holdings. The dollar sign assumes USD and performs no currency conversion.
  2. Clear the constructed sample and enter complete dated buys and sells, including fees. Same-date order matters: a sale cannot use shares from a later row on that date.
  3. Enter a manual valuation price. Zero is supported; blank, negative or nonfinite values do not become a zero-price loss.
  4. For imports, use the exact headers below or a JSON array with those keys. Fees can be omitted and then default to zero; present blank numeric cells are errors. Import replaces the entire position only after all rows pass validation.
  5. Export before leaving. The page does not save a portfolio or fetch transactions from a brokerage.
date,type,shares,pricePerShare,fees
2024-01-15,buy,100,150,10
2024-03-20,buy,50,165,10
2024-05-10,sell,30,180,10

A constructed calculation

The two example buys cost $15,010 and $8,260, for 150 shares with total basis $23,270 and an unrounded average of $155.133333… . A sale of 30 shares at $180 with $10 selling fees receives $5,390, removes $4,654 of basis and produces $736 of modeled realized P&L. The remaining 120 shares retain $18,616 of basis and the same average cost.

Buying changes the average; a partial sale at that average removes cost proportionally. A complete sale resets remaining shares and cost to zero. The display may round while subsequent calculations and CSV exports preserve numeric precision.

Use each output for its stated purpose

Remaining cost

The cost still assigned to open shares. It is not all money ever deposited and does not include the basis already removed on sales.

Modeled realized P&L

Sale proceeds less sell fees and average basis removed. It is neither taxable gain under every jurisdiction nor a result independently verified against a broker.

Unrealized P&L

Entered price × remaining shares − remaining cost. The percentage divides by positive remaining basis; a zero denominator has no percentage result.

History chart

Equal spacing per transaction shows average cost and trade price. Dates in the table identify the sequence; the line does not represent a continuous market-price series.

Tax methods and adjustments

IRS Publication 550 distinguishes ordinary stock identification from average basis allowed for certain mutual fund or eligible dividend-reinvestment-plan shares. Do not assume that a pooled average shown here is an acceptable tax basis. Specific identification requires the applicable records; when shares cannot be adequately identified, the IRS describes first-acquired shares. This calculator implements neither tax-lot identification nor FIFO.

Reinvested dividends can create additional purchases and tax consequences; cash distributions and basis adjustments require separate records. Splits and other corporate actions are unsupported. Use broker records and the applicable tax rules for reporting.

Frequently Asked Questions

Is average cost valid for all US stock tax reporting?

No. IRS Publication 550 generally does not permit average purchase price to determine gain or loss on ordinary stock sales. Certain mutual fund and eligible dividend-reinvestment-plan shares can use average basis under the applicable conditions and elections. This page does not determine eligibility, holding periods or tax lots.

What do buys and sells do in this model?

A buy adds shares × price + fees to remaining cost. A sell removes the pre-sale average cost for the sold shares; its modeled realized P&L is proceeds minus selling fees minus that removed basis. Selling more than the shares held at that point is rejected, including when an earlier buy is deleted.

How are dates and imports handled?

Use real YYYY-MM-DD dates. Trades are processed chronologically; rows with the same date retain entry or file order. CSV requires date,type,shares,pricePerShare with optional fees; JSON requires an array of the same fields. A valid import replaces all trades; an invalid one preserves the current position. Up to 1,000 rows and 2 MiB are supported.

Can I include dividends, splits and corporate actions?

Reinvestment purchases can be entered as buys, but cash dividend income is not tracked. Splits, return of capital, wash sales, transfers, inherited basis and other corporate actions are not implemented. Do not mix unadjusted pre-split quantities with post-split prices and treat the result as a tax record.

Is the current price live, and is my portfolio saved?

No. Price and ticker are manual inputs; changing the ticker only changes a label and does not select a different account. Transactions are held in page memory, not a saved portfolio. Export each position before clearing or reloading. The CSV contains transactions only, so record the symbol, currency and valuation price separately.

Is the unrealized percentage my total return?

No. It compares the entered valuation with the remaining modeled basis. It excludes cash dividends, prior withdrawals, holding-period timing, taxes and future selling fees. The chart uses equal spacing per transaction, not elapsed-time spacing.

Explore Chart-Based Research

Pineify can help draft Pine Script indicators and strategies for TradingView. This cost ledger is not automatically transferred to a script, and generated code needs review and chart testing.