Understanding the performance of your portfolio requires more than just looking at the current share price. A true stock return calculation accounts for capital gains, dividends, and the impact of time. This calculator helps you determine both your absolute return and your annualized growth rate.
The Stock Return Formula
The basic formula for total return is:
Total Return = [(Ending Value + Dividends – Commissions) – Initial Investment] / Initial Investment
Components of Your Return
Capital Gains: The difference between what you paid for the stock and what you sold it for.
Dividends: Payments made by the corporation to shareholders, often quarterly. These significantly boost total returns over time.
Commissions: The fees paid to brokers for buying or selling the asset, which reduce your net profit.
CAGR: The Compound Annual Growth Rate represents the mean annual growth rate of an investment over a specified period longer than one year.
Example Calculation
Imagine you bought 50 shares of Company X at $100 per share. After 3 years, you sell them at $130 per share. During that time, you received $5.00 in total dividends per share.
Initial Investment: 50 * $100 = $5,000
Ending Value: 50 * $130 = $6,500
Total Dividends: 50 * $5 = $250
Total Gain: ($6,500 + $250) – $5,000 = $1,750
Total Return: ($1,750 / $5,000) * 100 = 35%
Annualized Return: 10.52%
function calculateStockReturn() {
var buyPrice = parseFloat(document.getElementById('buyPrice').value);
var sellPrice = parseFloat(document.getElementById('sellPrice').value);
var shares = parseFloat(document.getElementById('sharesCount').value);
var dividends = parseFloat(document.getElementById('divPerShare').value) || 0;
var years = parseFloat(document.getElementById('yearsHeld').value);
var fees = parseFloat(document.getElementById('fees').value) || 0;
if (isNaN(buyPrice) || isNaN(sellPrice) || isNaN(shares) || buyPrice <= 0 || shares 0) {
var ratio = netProceeds / totalCost;
if (ratio > 0) {
cagr = (Math.pow(ratio, (1 / years)) – 1) * 100;
} else {
cagr = -100;
}
}
// Display Results
document.getElementById('stockResult').style.display = 'block';
document.getElementById('resTotalInv').innerHTML = '$' + totalCost.toLocaleString(undefined, {minimumFractionDigits: 2, maximumFractionDigits: 2});
document.getElementById('resTotalCash').innerHTML = '$' + netProceeds.toLocaleString(undefined, {minimumFractionDigits: 2, maximumFractionDigits: 2});
var profitElem = document.getElementById('resProfit');
profitElem.innerHTML = '$' + profit.toLocaleString(undefined, {minimumFractionDigits: 2, maximumFractionDigits: 2});
var pctElem = document.getElementById('resReturnPct');
pctElem.innerHTML = returnPercentage.toFixed(2) + '%';
var cagrElem = document.getElementById('resCAGR');
if (years > 0) {
cagrElem.innerHTML = cagr.toFixed(2) + '%';
} else {
cagrElem.innerHTML = 'N/A (Provide Years)';
}
// Color Logic
if (profit >= 0) {
profitElem.className = 'result-value';
pctElem.className = 'result-value';
cagrElem.className = 'result-value';
} else {
profitElem.className = 'result-value loss';
pctElem.className = 'result-value loss';
cagrElem.className = 'result-value loss';
}
}