How to Calculate Weighted Average Return in Excel

How to Calculate Weighted Average Return in Excel – Your Ultimate Guide :root { –primary-color: #004a99; –success-color: #28a745; –background-color: #f8f9fa; –text-color: #333; –border-color: #ddd; –card-background: #fff; –shadow: 0 2px 5px rgba(0,0,0,0.1); } body { font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; margin: 0; padding: 0; background-color: var(–background-color); color: var(–text-color); line-height: 1.6; } .container { max-width: 1000px; margin: 20px auto; padding: 20px; background-color: var(–card-background); border-radius: 8px; box-shadow: var(–shadow); } header { text-align: center; padding-bottom: 20px; border-bottom: 1px solid var(–border-color); margin-bottom: 20px; } h1, h2, h3 { color: var(–primary-color); } h1 { font-size: 2.2em; margin-bottom: 10px; } h2 { font-size: 1.8em; margin-top: 30px; margin-bottom: 15px; border-bottom: 1px solid var(–border-color); padding-bottom: 5px; } h3 { font-size: 1.4em; margin-top: 20px; margin-bottom: 10px; } .sub-heading { font-size: 1.2em; color: #555; margin-bottom: 30px; } .calculator-wrapper { background-color: var(–card-background); border-radius: 8px; box-shadow: var(–shadow); padding: 25px; margin-bottom: 30px; border: 1px solid var(–border-color); } .loan-calc-container { display: flex; flex-direction: column; gap: 15px; } .input-group { display: flex; flex-direction: column; gap: 8px; } .input-group label { font-weight: bold; color: #444; } .input-group input, .input-group select { padding: 10px; border: 1px solid var(–border-color); border-radius: 4px; font-size: 1em; width: calc(100% – 22px); /* Adjust for padding */ box-sizing: border-box; } .input-group select { appearance: none; /* Remove default arrow */ background-image: url('data:image/svg+xml;charset=US-ASCII,'); background-repeat: no-repeat; background-position: right 10px center; background-size: 16px; padding-right: 30px; } .input-group .helper-text { font-size: 0.85em; color: #666; margin-top: -5px; } .error-message { color: red; font-size: 0.85em; margin-top: 5px; display: none; /* Hidden by default */ } .error-message.visible { display: block; } .button-group { display: flex; gap: 10px; margin-top: 20px; } button { padding: 12px 20px; border: none; border-radius: 4px; cursor: pointer; font-size: 1em; font-weight: bold; transition: background-color 0.3s ease; } button.primary { background-color: var(–primary-color); color: white; } button.primary:hover { background-color: #003366; } button.secondary { background-color: #6c757d; color: white; } button.secondary:hover { background-color: #5a6268; } .results-container { margin-top: 25px; padding: 20px; background-color: #e9ecef; border-radius: 8px; border: 1px solid #dee2e6; } .results-container h3 { margin-top: 0; color: var(–primary-color); } .result-item { margin-bottom: 10px; font-size: 1.1em; } .result-item strong { color: var(–primary-color); min-width: 200px; display: inline-block; } .main-result { font-size: 1.8em; font-weight: bold; color: var(–success-color); background-color: #d4edda; padding: 15px; border-radius: 5px; text-align: center; margin-bottom: 15px; border: 1px solid var(–success-color); } .formula-explanation { font-size: 0.95em; color: #555; margin-top: 15px; padding: 10px; background-color: #f0f0f0; border-radius: 4px; } table { width: 100%; border-collapse: collapse; margin-top: 20px; margin-bottom: 30px; } th, td { padding: 12px; text-align: left; border: 1px solid var(–border-color); } thead { background-color: var(–primary-color); color: white; } tbody tr:nth-child(even) { background-color: #f2f2f2; } canvas { max-width: 100%; height: auto; display: block; margin: 20px auto; border: 1px solid var(–border-color); border-radius: 4px; background-color: var(–card-background); } .chart-caption { text-align: center; font-size: 0.9em; color: #666; margin-top: 5px; } .article-section { margin-top: 40px; } .article-section p, .article-section ul, .article-section ol { margin-bottom: 15px; } .article-section ul, .article-section ol { padding-left: 20px; } .article-section li { margin-bottom: 8px; } .faq-item { margin-bottom: 20px; border-bottom: 1px dashed var(–border-color); padding-bottom: 10px; } .faq-item:last-child { border-bottom: none; } .faq-item strong { display: block; color: var(–primary-color); margin-bottom: 5px; } .internal-links { margin-top: 30px; padding: 15px; background-color: #fff; border: 1px solid var(–border-color); border-radius: 4px; } .internal-links h3 { margin-top: 0; } .internal-links ul { list-style: none; padding: 0; } .internal-links li { margin-bottom: 10px; } .internal-links a { color: var(–primary-color); text-decoration: none; font-weight: bold; } .internal-links a:hover { text-decoration: underline; } .internal-links p { font-size: 0.9em; color: #555; margin-top: 5px; margin-bottom: 0; } footer { text-align: center; margin-top: 40px; padding-top: 20px; border-top: 1px solid var(–border-color); font-size: 0.9em; color: #777; } /* Mobile responsiveness */ @media (max-width: 768px) { .container { margin: 10px; padding: 15px; } h1 { font-size: 1.8em; } h2 { font-size: 1.5em; } .button-group { flex-direction: column; } .results-container { padding: 15px; } .result-item strong { min-width: unset; display: block; margin-bottom: 5px; } }

How to Calculate Weighted Average Return in Excel

Master your investment portfolio's performance with our expert guide and calculator.

Investment Weighted Average Return Calculator

Enter the initial cost or value of the first investment.
Enter the percentage return for the first investment.
Enter the initial cost or value of the second investment.
Enter the percentage return for the second investment.
Enter the initial cost or value of the third investment.
Enter the percentage return for the third investment.

Calculation Results

Formula Used: Weighted Average Return = Σ (Weight of Investment * Return of Investment)

Where: Weight of Investment = (Value of Individual Investment / Total Value of All Investments)
Investment Returns vs. Weights
Investment Details and Weights
Investment Initial Value Return (%) Weight (%) Contribution to Return

What is Weighted Average Return?

The weighted average return is a crucial metric used in finance to understand the overall performance of a diversified investment portfolio. Unlike a simple average, it accounts for the proportion or "weight" that each individual investment holds within the total portfolio. This means larger investments have a greater influence on the overall portfolio return than smaller ones. It provides a more accurate and representative picture of your investment success.

Who should use it: Any investor managing a portfolio with multiple assets – stocks, bonds, mutual funds, real estate, etc. – can benefit from calculating their weighted average return. Financial advisors, portfolio managers, and even individual investors use this metric to gauge performance, compare investment strategies, and make informed decisions about asset allocation.

Common misconceptions: A frequent mistake is to calculate a simple average of all investment returns. This ignores the capital deployed in each asset. For example, a 20% return on a $1,000 investment has a much smaller impact on the overall portfolio than a 10% return on a $100,000 investment. Another misconception is that weighted average return is the same as the total portfolio return; while closely related, weighted average return specifically focuses on the annualized or period return across all holdings, factoring in their size.

Weighted Average Return Formula and Mathematical Explanation

Calculating the weighted average return involves two main steps: determining the weight of each investment in the portfolio and then multiplying each investment's return by its respective weight. The sum of these weighted returns gives you the portfolio's overall weighted average return.

The formula can be broken down as follows:

1. Calculate the Total Value of the Portfolio:
Total Portfolio Value = Sum of the Initial Value (or current market value) of all individual investments.

2. Calculate the Weight of Each Investment:
Weight of Investment (Wi) = (Initial Value of Investment 'i' / Total Portfolio Value)

3. Calculate the Weighted Return for Each Investment:
Weighted Return of Investment 'i' = Weight of Investment (Wi) * Return of Investment 'i' (Ri)

4. Sum the Weighted Returns to get the Weighted Average Return:
Weighted Average Return = Σ (Wi * Ri) for all investments.

Variables Table:

Variable Meaning Unit Typical Range
Wi Weight of Investment 'i' Percentage (%) or Decimal 0% to 100%
Ri Return of Investment 'i' Percentage (%) -100% to theoretically infinite (but practically within market bounds)
Total Portfolio Value Sum of all investment values Currency ($) Positive value
Weighted Average Return Overall portfolio performance Percentage (%) -100% to theoretically infinite

Practical Examples (Real-World Use Cases)

Example 1: A Balanced Portfolio

Sarah has a portfolio with three investments:

  • Investment 1 (Stock): Initial Value = $10,000, Return = 12%
  • Investment 2 (Bond): Initial Value = $15,000, Return = 5%
  • Investment 3 (Real Estate): Initial Value = $25,000, Return = 8.5%

Calculation:

  • Total Portfolio Value = $10,000 + $15,000 + $25,000 = $50,000
  • Weight Stock = $10,000 / $50,000 = 0.20 (20%)
  • Weight Bond = $15,000 / $50,000 = 0.30 (30%)
  • Weight Real Estate = $25,000 / $50,000 = 0.50 (50%)
  • Weighted Return Stock = 0.20 * 12% = 2.4%
  • Weighted Return Bond = 0.30 * 5% = 1.5%
  • Weighted Return Real Estate = 0.50 * 8.5% = 4.25%
  • Weighted Average Return = 2.4% + 1.5% + 4.25% = 8.15%

Interpretation: Sarah's portfolio returned an average of 8.15%. Despite the stock having the highest individual return (12%), its lower weight meant it contributed less to the overall portfolio average compared to the real estate investment, which had a moderate return but a much larger weight.

Example 2: Portfolio with a Large Anchor Investment

David manages a portfolio where one investment dominates:

  • Investment A (Tech Fund): Initial Value = $5,000, Return = 15%
  • Investment B (Index Fund): Initial Value = $95,000, Return = 7%

Calculation:

  • Total Portfolio Value = $5,000 + $95,000 = $100,000
  • Weight Investment A = $5,000 / $100,000 = 0.05 (5%)
  • Weight Investment B = $95,000 / $100,000 = 0.95 (95%)
  • Weighted Return Investment A = 0.05 * 15% = 0.75%
  • Weighted Return Investment B = 0.95 * 7% = 6.65%
  • Weighted Average Return = 0.75% + 6.65% = 7.4%

Interpretation: David's portfolio yielded 7.4%. The large weight of Investment B (95%) means its return heavily dictates the overall portfolio performance, pulling the weighted average very close to its individual return of 7%.

How to Use This Weighted Average Return Calculator

Our calculator is designed to simplify the process of calculating your portfolio's weighted average return. Follow these steps:

  1. Input Investment Details: In the designated fields, enter the name, initial investment value (or cost basis), and the percentage return for each of your investments. You can add or remove investments as needed by adjusting the input fields.
  2. Enter Values: For each investment, input its name, the value of the investment (e.g., original purchase price or current market value), and its specific percentage return. Use positive numbers for gains and negative numbers for losses.
  3. Calculate: Click the "Calculate" button.
  4. Review Results: The calculator will instantly display:
    • Main Result: The overall Weighted Average Return for your entire portfolio.
    • Intermediate Values: The total portfolio value, the weight of each investment, and its individual contribution to the weighted average return.
    • Formula Explanation: A clear breakdown of the formula used.
    • Table: A detailed table summarizing all inputs and calculated weights and contributions.
    • Chart: A visual representation of your investment weights and their contribution to the total return.
  5. Interpret: Understand how each investment contributes to your portfolio's overall performance based on its size and return.
  6. Copy Results: Use the "Copy Results" button to easily transfer the key figures to a report or spreadsheet.
  7. Reset: Click "Reset" to clear all fields and start over with default settings.

Decision-making guidance: A low weighted average return, especially compared to benchmarks or your target return rate, might indicate a need to re-evaluate your asset allocation. If investments with low returns have high weights, consider rebalancing your portfolio. Conversely, if high-return investments have small weights, you might explore increasing your allocation to them, depending on risk tolerance.

Key Factors That Affect Weighted Average Return Results

Several factors can influence the weighted average return of your portfolio. Understanding these is key to effective portfolio management:

  1. Asset Allocation: The proportion of your total investment value allocated to different asset classes (stocks, bonds, real estate, etc.) is the primary driver. A larger allocation to an asset with a high return will significantly boost the weighted average.
  2. Individual Investment Performance: The actual return generated by each asset is critical. A high-performing asset, even with a small weight, contributes positively, while a poor-performing asset, especially with a large weight, can drag down the overall average.
  3. Time Horizon: Returns are typically measured over a specific period. Longer time horizons allow for compounding and can smooth out short-term volatility, potentially leading to different weighted average returns compared to shorter periods. For [long-term investment strategies](http://example.com/long-term-investment), this factor is paramount.
  4. Market Volatility: Fluctuations in market prices directly impact the value of your investments and, consequently, their returns and weights. High volatility can lead to significant swings in the weighted average return over short periods.
  5. Investment Costs and Fees: Management fees, transaction costs, and other expenses reduce the net return of each investment. These costs should be factored into the individual investment return (Ri) to get an accurate weighted average return. Understanding [investment fees](http://example.com/investment-fees) is crucial.
  6. Inflation: While not directly part of the weighted average calculation, inflation erodes the purchasing power of returns. A high weighted average return might still result in a negative real return if inflation is higher than the nominal return.
  7. Currency Exchange Rates: For international investments, currency fluctuations can significantly impact the returns when converted back to your base currency, affecting the final weighted average.
  8. Risk Tolerance: While not a direct input, your risk tolerance influences your asset allocation, which in turn dictates the weights in the weighted average return calculation. Higher-risk assets might offer higher potential returns but also carry greater volatility.

Frequently Asked Questions (FAQ)

Q1: What's the difference between a simple average return and a weighted average return?

A simple average sums all returns and divides by the number of investments. A weighted average return accounts for the proportion (weight) of each investment within the total portfolio value, giving a more accurate picture of overall performance.

Q2: Can the weighted average return be negative?

Yes, if the overall value of the portfolio decreases. This occurs when the weighted losses from underperforming assets outweigh the weighted gains from well-performing assets.

Q3: Should I use the initial investment value or the current market value for weights?

For calculating historical performance over a specific period, using the initial values at the start of the period is common. For current portfolio health, using current market values for weights provides a real-time picture. Our calculator uses the values you input as the basis for weights.

Q4: How often should I calculate my weighted average return?

It's recommended to calculate it at least quarterly or annually for performance reviews. For active traders, calculating it more frequently might be beneficial. Consider it a key metric in your [portfolio rebalancing strategy](http://example.com/portfolio-rebalancing).

Q5: What is a "good" weighted average return?

A "good" return is relative. It depends on your investment goals, risk tolerance, time horizon, and prevailing market conditions. Compare your weighted average return against relevant market benchmarks (like the S&P 500 for US stocks) and your personal financial targets.

Q6: Does the weighted average return account for taxes?

The basic formula does not automatically account for taxes. You would need to calculate the *after-tax* return for each investment and then use those figures in the weighted average calculation to get an after-tax weighted average return.

Q7: How can I calculate weighted average return directly in Excel?

In Excel, you can calculate the total portfolio value, then calculate the weight of each asset (Asset Value / Total Portfolio Value). Finally, use the SUMPRODUCT function: =SUMPRODUCT(Weights_Range, Returns_Range). For example, if weights are in B2:B4 and returns in C2:C4, it would be =SUMPRODUCT(B2:B4, C2:C4).

Q8: What if I have an investment that lost money?

You simply input the negative percentage return (e.g., -10% for a 10% loss). The calculation will correctly factor this negative return into the weighted average, potentially lowering the overall portfolio performance.

Related Tools and Internal Resources

© 2023 Your Financial Website. All rights reserved.

Disclaimer: This calculator and information are for educational purposes only and do not constitute financial advice. Consult with a qualified financial professional before making investment decisions.

var investments = []; // Array to hold investment objects // Function to get input values and perform validation function getInputValues() { var inputs = []; var isValid = true; // Loop through potential investment inputs (up to a reasonable limit, e.g., 10) for (var i = 1; i <= 10; i++) { var nameInput = document.getElementById("investmentName" + i); var valueInput = document.getElementById("investmentValue" + i); var returnInput = document.getElementById("investmentReturn" + i); var valueError = document.getElementById("investmentValue" + i + "Error"); var returnError = document.getElementById("investmentReturn" + i + "Error"); // Only process if the input elements exist if (nameInput && valueInput && returnInput && valueError && returnError) { var name = nameInput.value.trim() || "Investment " + i; var valueStr = valueInput.value; var retStr = returnInput.value; // Reset previous errors valueError.innerText = ""; valueError.classList.remove("visible"); returnError.innerText = ""; returnError.classList.remove("visible"); var value = parseFloat(valueStr); var ret = parseFloat(retStr); // Validation for value if (isNaN(value) || valueStr === "" || value < 0) { valueError.innerText = "Please enter a valid non-negative number for investment value."; valueError.classList.add("visible"); isValid = false; } // Validation for return if (isNaN(ret) || retStr === "" || ret 100) { // Assuming return cannot be less than -100% or excessively high for practical purposes returnError.innerText = "Please enter a valid return percentage between -100% and 100%."; returnError.classList.add("visible"); isValid = false; } if (valueInput.value !== "" && retStr !== "") { // Only add if both have some value to process inputs.push({ id: i, name: name, value: value, ret: ret / 100 // Convert percentage to decimal for calculation }); } } } // Filter out any inputs that were entered but not fully valid (e.g. empty values were checked but not added) inputs = inputs.filter(function(input) { return !isNaN(input.value) && !isNaN(input.ret); }); return { investments: inputs, isValid: isValid }; } // Function to calculate weighted average return function calculateWeightedAverageReturn() { var inputData = getInputValues(); var investments = inputData.investments; var isValid = inputData.isValid; var resultsContainer = document.getElementById("resultsContainer"); var resultsTableBody = document.getElementById("resultsTableBody"); var mainResultElement = document.getElementById("mainResult"); var intermediateResultsElement = document.getElementById("intermediateResults"); var canvas = document.getElementById("returnChart"); var ctx = canvas.getContext("2d"); // Clear previous results and table resultsContainer.style.display = "none"; resultsTableBody.innerHTML = ""; mainResultElement.innerText = ""; intermediateResultsElement.innerText = ""; ctx.clearRect(0, 0, canvas.width, canvas.height); // Clear the canvas if (!isValid || investments.length === 0) { if (investments.length === 0 && isValid) { // Optionally display a message if no investments are entered but inputs were valid } // Errors are displayed inline, no need for alerts return; } var totalPortfolioValue = 0; for (var i = 0; i < investments.length; i++) { totalPortfolioValue += investments[i].value; } if (totalPortfolioValue === 0) { // Handle case where total value is zero to avoid division by zero mainResultElement.innerText = "N/A (Total value is zero)"; resultsContainer.style.display = "block"; return; } var weightedAverageReturn = 0; var tableHtml = ""; var chartDataLabels = []; var chartDataWeights = []; var chartDataContributions = []; for (var i = 0; i < investments.length; i++) { var investment = investments[i]; var weight = investment.value / totalPortfolioValue; var weightedReturn = weight * investment.ret; weightedAverageReturn += weightedReturn; var contribution = weightedReturn * 100; // For display tableHtml += ""; tableHtml += "" + (investment.name || "Investment " + investment.id) + ""; tableHtml += "" + formatCurrency(investment.value) + ""; tableHtml += "" + (investment.ret * 100).toFixed(2) + "%"; tableHtml += "" + (weight * 100).toFixed(2) + "%"; tableHtml += "" + contribution.toFixed(2) + "%"; tableHtml += ""; chartDataLabels.push(investment.name || "Investment " + investment.id); chartDataWeights.push(weight * 100); // For display as percentage chartDataContributions.push(contribution); } // Display results mainResultElement.innerText = (weightedAverageReturn * 100).toFixed(2) + "%"; intermediateResultsElement.innerHTML = "
Total Portfolio Value: " + formatCurrency(totalPortfolioValue) + "
" + "
Number of Investments: " + investments.length + "
"; resultsTableBody.innerHTML = tableHtml; resultsContainer.style.display = "block"; // Draw Chart drawChart(chartDataLabels, chartDataWeights, chartDataContributions); } // Function to draw the chart function drawChart(labels, weights, contributions) { var canvas = document.getElementById("returnChart"); var ctx = canvas.getContext("2d"); var chartWidth = canvas.clientWidth; var chartHeight = 300; // Fixed height for better control canvas.height = chartHeight; // Set canvas height dynamically ctx.clearRect(0, 0, canvas.width, canvas.height); // Clear previous drawing var padding = 50; var chartAreaWidth = chartWidth – 2 * padding; var chartAreaHeight = chartHeight – 2 * padding; // Find max values for scaling var maxWeight = Math.max(…weights, 0); var maxContribution = Math.max(…contributions, 0); var maxValue = Math.max(maxWeight, maxContribution); if (maxValue === 0) maxValue = 1; // Prevent division by zero if all values are 0 var barWidth = chartAreaWidth / (labels.length * 2); // Spacing out bars var gap = barWidth; // Draw X-axis and labels ctx.beginPath(); ctx.moveTo(padding, chartHeight – padding); ctx.lineTo(chartWidth – padding, chartHeight – padding); ctx.strokeStyle = "#ccc"; ctx.stroke(); // Draw Y-axis and labels (for weights) ctx.beginPath(); ctx.moveTo(padding, padding); ctx.lineTo(padding, chartHeight – padding); ctx.strokeStyle = "#ccc"; ctx.stroke(); // Draw Y-axis for contribution (optional, can be complex with two scales) // For simplicity, let's indicate the scale reference in text // Draw bars and labels ctx.fillStyle = var(–primary-color); // Default bar color var colors = ['#004a99', '#007bff', '#6610f2', '#6f42c1', '#d63384', '#dc3545', '#fd7e14', '#ffc107', '#28a745', '#20c997']; var colorIndex = 0; for (var i = 0; i < labels.length; i++) { var label = labels[i]; var weightPercentage = weights[i]; var contributionPercentage = contributions[i]; var weightBarHeight = (weightPercentage / maxValue) * chartAreaHeight; var contributionBarHeight = (contributionPercentage / maxValue) * chartAreaHeight; var xPos = padding + i * (barWidth + gap) + gap / 2; // Draw Weight Bar ctx.fillStyle = colors[colorIndex % colors.length]; ctx.fillRect(xPos, chartHeight – padding – weightBarHeight, barWidth, weightBarHeight); ctx.fillStyle = "#000"; // Text color ctx.textAlign = "center"; ctx.font = "12px Arial"; ctx.fillText(label, xPos + barWidth / 2, chartHeight – padding + 15); // Label below bar ctx.fillText(weightPercentage.toFixed(1) + "% W", xPos + barWidth / 2, chartHeight – padding – weightBarHeight – 5); // Weight indicator // Draw Contribution Bar (slightly offset) ctx.fillStyle = "#28a745"; // Success color for contribution ctx.fillRect(xPos + barWidth + gap/2, chartHeight – padding – contributionBarHeight, barWidth, contributionBarHeight); ctx.fillStyle = "#000"; // Text color ctx.fillText(contributionPercentage.toFixed(1) + "% C", xPos + barWidth + gap/2 + barWidth/2, chartHeight – padding – contributionBarHeight – 5); // Contribution indicator colorIndex++; } // Add legend ctx.fillStyle = "#333"; ctx.textAlign = "left"; ctx.font = "14px Arial"; ctx.fillText("Weight (% of Portfolio)", padding, padding – 10); ctx.fillText("Contribution to Return (%)", padding + chartAreaWidth / 2, padding – 10); // Add value markers on Y axis (simplified) var numTicks = 5; for(var j=0; j <= numTicks; j++) { var tickValue = (maxValue / numTicks) * j; var tickY = chartHeight – padding – (tickValue / maxValue) * chartAreaHeight; ctx.fillText(tickValue.toFixed(1) + "%", padding – 40, tickY); ctx.beginPath(); ctx.moveTo(padding – 5, tickY); ctx.lineTo(padding, tickY); ctx.strokeStyle = "#ccc"; ctx.stroke(); } } // Helper function to format currency function formatCurrency(amount) { return "$" + Number(amount).toFixed(2).replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1,"); } // Function to reset calculator inputs function resetCalculator() { document.getElementById("investmentName1").value = "Stock A"; document.getElementById("investmentValue1").value = "10000"; document.getElementById("investmentReturn1").value = "12"; document.getElementById("investmentName2").value = "Bond B"; document.getElementById("investmentValue2").value = "15000"; document.getElementById("investmentReturn2").value = "5"; document.getElementById("investmentName3").value = "Real Estate C"; document.getElementById("investmentValue3").value = "25000"; document.getElementById("investmentReturn3").value = "8.5"; // Clear any remaining inputs if the calculator had more than 3 initially for (var i = 4; i 0) { // Re-calculate and redraw only if there are investments and calculations have been made var currentLabels = []; var currentWeights = []; var currentContributions = []; // Re-extract data for redrawing var totalPortfolioValue = 0; for (var i = 0; i 0) { for (var i = 0; i < inputData.investments.length; i++) { var investment = inputData.investments[i]; var weight = investment.value / totalPortfolioValue; var weightedReturn = weight * investment.ret; var contribution = weightedReturn * 100; currentLabels.push(investment.name || "Investment " + investment.id); currentWeights.push(weight * 100); currentContributions.push(contribution); } drawChart(currentLabels, currentWeights, currentContributions); } } });

Leave a Comment