Home › Finance › Stock Profit Calculator
Stock Profit Calculator
Computes the profit or loss on a share trade from buy and sell prices, number of shares, commissions on each side and an optional capital-gains tax rate, with the percentage return on the total cost and the sell price needed to break even.
When to use
You want to know what you made (or lost) on a stock sale after fees and tax, or the price at which a position becomes profitable.
Do not use when: You want dividend income or reinvestment (use dividend-yield), an annualized return over the holding period (use roi or cagr), or tax lots with different purchase dates.
Formula
total_cost = buy_price × shares + buy_commission; total_proceeds = sell_price × shares − sell_commission; net_before_tax = total_proceeds − total_cost; tax = max(0, net_before_tax) × capital_gains_tax_percent/100; net_profit = net_before_tax − tax; return = net_profit / total_cost × 100; break_even = (total_cost + sell_commission) / shares
Single lot, no dividends, and a flat tax rate on the gain; actual capital-gains rules (holding period, allowances, loss offsets) vary by country.
Inputs
| Parameter | Type | Unit | Required | Description |
|---|---|---|---|---|
buy_price | number | yes | Purchase price per share. Range: > 0, ≤ 10000000 | |
sell_price | number | yes | Sale price per share. Range: ≥ 0, ≤ 10000000 | |
shares | number | yes | Shares bought and sold (fractional allowed). Range: > 0, ≤ 1000000000000 | |
buy_commission | number | default 0 | Fees paid on the purchase. Range: ≥ 0, ≤ 10000000 | |
sell_commission | number | default 0 | Fees paid on the sale. Range: ≥ 0, ≤ 10000000 | |
capital_gains_tax_percent | number | % | default 0 | Tax rate applied to a positive net gain (0 for none; losses are not taxed). Range: ≥ 0, ≤ 100 |
Outputs
| Output | Type | Unit | Description |
|---|---|---|---|
total_cost | number | buy_price × shares + buy_commission. | |
total_proceeds | number | sell_price × shares − sell_commission. | |
gross_profit | number | (sell_price − buy_price) × shares, before commissions and tax. | |
net_profit_before_tax | number | total_proceeds − total_cost. | |
capital_gains_tax | number | max(0, net_profit_before_tax) × capital_gains_tax_percent / 100. | |
net_profit | number | net_profit_before_tax − capital_gains_tax. | |
return_percent | number | % | net_profit / total_cost × 100. |
break_even_sell_price | number | (total_cost + sell_commission) / shares: the sale price at which net profit before tax is zero. |
Example
100 shares bought at 50, sold at 60, 10 commission each way, 15 % tax: {"buy_price":50,"sell_price":60,"shares":100,"buy_commission":10,"sell_commission":10,"capital_gains_tax_percent":15} → {"total_cost":5010,"total_proceeds":5990,"gross_profit":1000,"net_profit_before_tax":980,"capital_gains_tax":147,"net_profit":833,"return_percent":16.63,"break_even_sell_price":50.2}
50 shares bought at 120, sold at 100, no fees: {"buy_price":120,"sell_price":100,"shares":50} → {"total_cost":6000,"total_proceeds":5000,"gross_profit":-1000,"capital_gains_tax":0,"net_profit":-1000,"return_percent":-16.67,"break_even_sell_price":120}
GET https://tttkmbb.com/api/v1/calculate/stock-profit?buy_price=50&sell_price=60&shares=100&buy_commission=10&sell_commission=10&capital_gains_tax_percent=15
Machine access
- API:
GET https://tttkmbb.com/api/v1/calculate/stock-profit(query parameters) orPOSTwith a JSON body{"inputs": {...}} - Schema: https://tttkmbb.com/api/v1/calculators/stock-profit · Markdown: https://tttkmbb.com/finance/stock-profit.md · JSON definition: https://tttkmbb.com/finance/stock-profit.json
- MCP: server
https://tttkmbb.com/mcp, toolrun_calculator with calculator_id="stock-profit" - OpenAPI operationId:
calculate_stock_profit - Freshness:
static. Authentication: none. Rate limit: fair use (see rate limits).
Sources
- IRS – Topic no. 409, Capital gains and losses (government)
- Investopedia – Capital Gains Tax: What It Is, How It Works and Current Rates (reference)
- Wikipedia – Rate of return (reference)
FAQ
Why is the break-even price above the buy price?
Commissions on both sides must be recovered: with 10 paid to buy and 10 to sell 100 shares bought at 50, the shares must sell at 50.20 just to get the money back.
Which tax rate applies?
In the US, assets held over a year are taxed at long-term rates (0, 15 or 20 % in 2024–2025 depending on income) and shorter holdings at ordinary income rates; other countries have their own rates and allowances.
Related calculators
- ROI Calculator — Annualized return over the holding period.
- Percentage Change Calculator — Percent change between the two prices.
- Dividend Yield Calculator — Income from the shares while held.