Enter your stock purchase details below to calculate your average cost per share.
Your Average Cost Per Share:
$0.00
Understanding the Average Cost Stock Calculator
The Average Cost Stock Calculator is a valuable tool for investors who buy shares of the same stock at different times and at different prices. When you make multiple purchases of a stock, each at a unique price, your "average cost per share" represents the weighted average price you paid for all the shares you own. This metric is crucial for several reasons:
Taxation: When you sell shares, the IRS requires you to calculate your capital gains or losses. Your average cost per share is fundamental to this calculation. Knowing your precise average cost helps in accurate tax reporting and potentially minimizing your tax liability.
Performance Tracking: To understand how well your investment is performing, you need a baseline. Your average cost per share provides that baseline. If the current market price is significantly above your average cost, your investment is in profit; if it's below, you're at a loss.
Rebalancing Decisions: When deciding whether to buy more shares or sell existing ones, knowing your average cost helps you assess the potential impact on your overall investment strategy and cost basis.
How the Calculation Works
The average cost per share is calculated using a weighted average formula. It's not a simple average of all the prices; instead, it takes into account the number of shares purchased at each price.
The formula is:
Average Cost Per Share = (Total Cost of All Purchases) / (Total Number of Shares Purchased)
Let's break this down:
Total Cost of All Purchases: For each purchase, you multiply the number of shares bought by the price per share. You then sum up these individual purchase costs to get the total cost.
Formula for one purchase: (Shares Purchased) x (Price Per Share)
Total Number of Shares Purchased: This is the sum of all the shares you've acquired across all your purchases.
For example, imagine you made two purchases of Stock XYZ:
Purchase 1: 100 shares at $50 per share. Cost = 100 * $50 = $5,000
Purchase 2: 200 shares at $55 per share. Cost = 200 * $55 = $11,000
In this scenario:
Total Cost of All Purchases = $5,000 + $11,000 = $16,000
Total Number of Shares Purchased = 100 + 200 = 300 shares
Average Cost Per Share = $16,000 / 300 = $53.33 (approximately)
This calculator automates this process, allowing you to quickly determine your average cost by simply inputting the details of each of your stock acquisitions.
var purchaseCount = 1;
function addPurchase() {
purchaseCount++;
var purchaseDetailsDiv = document.getElementById('purchaseDetails');
var newPurchaseDiv = document.createElement('div');
newPurchaseDiv.className = 'purchase-entry';
newPurchaseDiv.innerHTML = `
`;
purchaseDetailsDiv.appendChild(newPurchaseDiv);
// Update the hidden count input if you were using one, or just rely on var purchaseCount
// document.getElementById('purchases').value = purchaseCount; // Not needed if we use the var directly
}
function calculateAverageCost() {
var totalCost = 0;
var totalShares = 0;
var isValid = true;
var sharesInputs = document.querySelectorAll('.shares-input');
var priceInputs = document.querySelectorAll('.price-input');
if (sharesInputs.length !== priceInputs.length) {
alert("There's a mismatch in the number of shares and price inputs. Please check your entries.");
return;
}
for (var i = 0; i < sharesInputs.length; i++) {
var shares = parseFloat(sharesInputs[i].value);
var price = parseFloat(priceInputs[i].value);
if (isNaN(shares) || isNaN(price) || shares <= 0 || price 0) {
averageCost = totalCost / totalShares;
}
document.getElementById('averageCost').innerText = "$" + averageCost.toFixed(2);
}
}