Add up what you paid in each purchase (quantity × price + fees) and divide by the total quantity. With 100 shares at 15 and 300 at 20, the cost is 1,500 + 6,000 = 7,500 for 400 shares, so the average is 18.75.
Work out the weighted average cost of stocks, REITs, ETFs and crypto across many buys, sells and fees, see realized profit and how many shares to buy to reach the average you want.
Average cost is the acquisition cost per share: everything you paid, fees included, divided by the quantity you hold. Brazil's tax agency (Receita Federal) states that the acquisition cost in the spot market is the weighted average of unit costs (IRPF 2026 questions and answers, item 719) and that brokerage and exchange fees are added to the purchase price and deducted from the sale price (item 708). The agency's own example buys 100 shares at R$ 10.00, 200 at R$ 9.25 and 500 at R$ 7.50: total cost R$ 6,600 for 800 shares, or R$ 8.25 each. A sale of 400 shares at R$ 10.75 yields R$ 1,000.00 of net gain, and the 400 left remain at R$ 8.25. That is where many people go wrong: selling does not change the average cost, it only realizes profit or loss against it. A new purchase does change the average. So the tool reads trades in order and shows the position, average cost and result after each line. The planner solves the inverse problem: to move from R$ 8.25 to R$ 8.00 by buying at R$ 7.00 you need 100 shares. This is a cost calculation, not a tax one: exemptions and rates change and must be checked with the tax agency.
Paste the code into your HTML and the tool shows up on your page, without J-Kit's navigation and ads. It still runs in the browser of whoever visits your site.
<iframe
src="https://jkit.tools/embed/en-US/stock-average-cost-calculator"
width="100%"
height="600"
style="border:0"
loading="lazy"
title="Stock Average Cost Calculator"
></iframe>
<p style="font-size:12px;margin:6px 0 0">Tool by <a href="https://jkit.tools/en/tools/stock-average-cost-calculator">J-Kit</a></p>Using it in a paper, class or post? Copy the link or a ready-made reference. The access date is today's.
<a href="https://jkit.tools/en/tools/stock-average-cost-calculator">Stock Average Cost Calculator</a>
These references help contextualize formulas, standards, APIs and limitations used on this page. They do not replace professional validation when a result has legal, financial, medical or operational impact.
Add up what you paid in each purchase (quantity × price + fees) and divide by the total quantity. With 100 shares at 15 and 300 at 20, the cost is 1,500 + 6,000 = 7,500 for 400 shares, so the average is 18.75.
After 4 trades
Position 100 · average cost R$10.00
Position 300 · average cost R$9.50
Position 800 · average cost R$8.25
Position 400 · average cost R$8.25 · result +R$1,000.00
Buy 100 at R$7.00 each
Amount invested in the order, fee included: R$700.00
You would hold 500 at an average cost of R$8.00
Brokerage and exchange fees are added to the buy cost and deducted from the sale value, as in the Brazilian tax agency example. Enter the total order fee as an amount of money.
This is not investment advice or an income tax calculation. Your data stays in your browser.