Real Historical Prices

Free Cost Basis of Stock Calculator

Calculate the true cost basis of any stock using real historical closing prices. Add multiple purchase lots, and instantly see your weighted average cost per share, total investment, and unrealized profit or loss.

Real Stock Prices
Multiple Purchase Lots
100% Free
Purchase #1
Purchase #2

Data sourced from FinancialModelingPrep. Prices are split-adjusted closing prices. Past performance is not indicative of future results.

What Is Cost Basis of a Stock?

Cost basis is the original value of a stock investment for tax purposes. When you purchase shares of a company, the cost basis is typically the price you paid per share multiplied by the number of shares, plus any commissions or transaction fees. This figure is essential because it determines your capital gain or loss when you eventually sell the shares.

For investors who buy shares at different times and prices — through dollar-cost averaging, reinvested dividends, or scaling into positions — the cost basis becomes the weighted average price across all purchase lots. Our cost basis of stock calculator automates this by fetching real historical closing prices for each purchase date, eliminating manual lookups and arithmetic errors.

How to Use This Cost Basis of Stock Calculator

  1. 1

    Search for the Stock

    Type the ticker symbol (e.g., AAPL, TSLA, MSFT) in the search box and select the correct company from the dropdown results.

  2. 2

    Add Your Purchase Lots

    For each purchase, enter the number of shares and the date you bought them. The calculator fetches the actual closing price on that date. You can also enter a manual price if you know the exact price you paid.

  3. 3

    Add More Lots as Needed

    Click "Add Lot" to include additional purchases. There is no limit to the number of lots you can add.

  4. 4

    Review Your Results

    Click "Calculate Cost Basis" to see your weighted average cost per share, total investment, current market value, and unrealized profit or loss — all based on real market data.

Cost Basis Formula

The weighted average cost basis is calculated using this formula:

Total Cost = ∑ (Sharesi × Pricei)

Average Cost Basis = Total Cost / Total Shares

Unrealized P&L = (Current Price − Average Cost) × Total Shares

For example, if you bought 50 shares of AAPL at $150 and later bought 30 more shares at $170, your total cost is (50 × $150) + (30 × $170) = $12,600 for 80 shares. Your average cost basis is $12,600 / 80 = $157.50 per share.

Why Cost Basis Matters for Investors

Tax Reporting

Your cost basis determines the capital gain or loss reported on your tax return. A higher cost basis means a smaller taxable gain (or larger deductible loss) when you sell. Accurate cost basis tracking is required by the IRS.

Break-Even Analysis

Your average cost basis is your break-even price. The stock must trade above this level for your position to be profitable. This is especially important when averaging down into a declining stock.

Dollar-Cost Averaging

If you invest a fixed amount regularly, your cost basis reflects the weighted average of all purchase prices. This strategy reduces the impact of volatility and is widely used in retirement accounts and index fund investing.

Portfolio Performance

Knowing your true cost basis for each holding lets you accurately measure portfolio performance. Without it, you cannot calculate your real return on investment or compare performance across different positions.

Cost Basis Accounting Methods

When you sell only part of your shares, the IRS allows several methods to determine which shares were sold and at what cost basis:

  • Average Cost (this calculator) — Uses the weighted average price of all shares. This is the simplest method and the default for mutual funds.
  • FIFO (First In, First Out) — Assumes the oldest shares are sold first. This is the IRS default method for stocks if you do not specify otherwise.
  • LIFO (Last In, First Out) — Assumes the newest shares are sold first. This can minimize taxes if recent purchases were at higher prices.
  • Specific Identification — You choose exactly which shares to sell. This gives the most control over tax outcomes but requires detailed record-keeping.
  • HIFO (Highest In, First Out) — Sells the highest-cost shares first to minimize capital gains. Often used in tax-loss harvesting strategies.

Events That Adjust Your Cost Basis

Several corporate actions and events can change your cost basis beyond simple purchases:

  • Stock Splits — A 2-for-1 split doubles your shares and halves your cost per share. The total cost basis remains the same. Our calculator uses split-adjusted prices automatically.
  • Reinvested Dividends — Dividends reinvested to buy additional shares increase your total shares and total cost basis. Each reinvestment is a new purchase lot.
  • Return of Capital — Distributions classified as return of capital reduce your cost basis rather than being taxed as income.
  • Wash Sales — If you sell at a loss and repurchase substantially identical securities within 30 days, the disallowed loss is added to the cost basis of the new shares.
  • Mergers & Acquisitions — When companies merge, your cost basis may be allocated across new shares or cash received based on the exchange ratio.

Frequently Asked Questions

What is cost basis of a stock?

Cost basis is the original value of a stock for tax purposes, typically the purchase price plus any commissions or fees. When you buy shares at different times and prices, your cost basis is the weighted average price per share across all purchases. This number determines your capital gain or loss when you sell.

How does this cost basis calculator work?

This calculator fetches real historical closing prices from FinancialModelingPrep for the stock ticker and purchase dates you provide. It calculates the weighted average cost per share across all your purchase lots, then compares it to the current market price to show your unrealized profit or loss.

What is the difference between cost basis and average cost?

They are closely related. Cost basis refers to the total original value of your investment for tax purposes. Average cost (or average cost basis) is your cost basis divided by the total number of shares — giving you the weighted average price per share. This calculator computes both.

How is weighted average cost basis calculated?

Weighted Average Cost Basis = Total Cost of All Purchases / Total Shares Owned. For example, if you bought 50 shares at $100 and 50 shares at $120, your total cost is $11,000 for 100 shares, giving an average cost basis of $110 per share.

Does this calculator account for stock splits?

The historical prices fetched are split-adjusted closing prices. This means if a stock has split since your purchase date, the price shown will reflect the split-adjusted value. For the most accurate results, enter the number of shares you currently hold (post-split).

Can I include commissions and fees in my cost basis?

Yes. Use the manual price override option for any lot and add your per-share commission to the stock price. For example, if you paid $150 per share plus $10 total commission on 10 shares, enter $151 as the manual price.

Why does my purchase date show a different price date?

If your purchase date falls on a weekend or market holiday, the calculator uses the closing price from the most recent prior trading day. This is the same convention brokers use for settlement purposes.

Is this stock cost basis calculator free?

Yes, this calculator is completely free to use with no registration required. It uses real market data to provide accurate cost basis calculations for any publicly traded stock.

Know Your Cost Basis? Now Automate Your Strategy

Turn your investment insights into automated Pine Script strategies with Pineify. Create custom indicators for entry and exit signals, or let our AI Stock Picker surface opportunities for you.