Calculating Weighted Average Cost in Excel

Calculating Weighted Average Cost in Excel | WACC Calculator :root { –primary-color: #004a99; –success-color: #28a745; –background-color: #f8f9fa; –text-color: #333; –border-color: #ddd; –card-bg: #fff; –shadow: 0 4px 8px rgba(0,0,0,0.1); } body { font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; background-color: var(–background-color); color: var(–text-color); margin: 0; padding: 0; line-height: 1.6; } .container { max-width: 1000px; margin: 20px auto; padding: 20px; background-color: var(–card-bg); border-radius: 8px; box-shadow: var(–shadow); } header { background-color: var(–primary-color); color: white; padding: 20px; border-radius: 8px 8px 0 0; text-align: center; } header h1 { margin: 0; font-size: 2.2em; } .content-section { padding: 30px 0; border-bottom: 1px solid var(–border-color); } .content-section:last-child { border-bottom: none; } h2, h3 { color: var(–primary-color); margin-bottom: 15px; } .loan-calc-container { background-color: var(–card-bg); padding: 25px; border-radius: 8px; box-shadow: var(–shadow); margin-bottom: 30px; } .input-group { margin-bottom: 20px; text-align: left; } .input-group label { display: block; margin-bottom: 8px; font-weight: bold; color: var(–primary-color); } .input-group input[type="number"], .input-group select { width: calc(100% – 20px); /* Adjust for padding */ padding: 10px; border: 1px solid var(–border-color); border-radius: 4px; font-size: 1em; box-sizing: border-box; } .input-group input[type="number"]:focus, .input-group select:focus { border-color: var(–primary-color); outline: none; box-shadow: 0 0 5px rgba(0, 74, 153, 0.3); } .input-group .helper-text { font-size: 0.85em; color: #666; margin-top: 5px; display: block; } .error-message { color: red; font-size: 0.9em; margin-top: 5px; height: 1.2em; /* Reserve space */ } button { background-color: var(–primary-color); color: white; border: none; padding: 12px 25px; border-radius: 4px; cursor: pointer; font-size: 1em; margin-right: 10px; transition: background-color 0.3s ease; } button:hover { background-color: #003366; } button.reset-button { background-color: #6c757d; } button.reset-button:hover { background-color: #5a6268; } .results-container { margin-top: 30px; padding: 20px; background-color: #eef7ff; border: 1px dashed var(–primary-color); border-radius: 8px; } .results-container h3 { color: var(–primary-color); text-align: center; margin-top: 0; } .primary-result { font-size: 2.5em; font-weight: bold; color: var(–success-color); text-align: center; margin-bottom: 20px; padding: 15px; background-color: #fff; border-radius: 8px; box-shadow: inset 0 0 10px rgba(40, 167, 69, 0.2); } .intermediate-results, .key-assumptions { margin-top: 25px; display: flex; flex-wrap: wrap; justify-content: space-around; gap: 15px; } .intermediate-results div, .key-assumptions div { background-color: var(–card-bg); padding: 15px; border-radius: 8px; box-shadow: var(–shadow); flex: 1; min-width: 150px; text-align: center; } .intermediate-results span, .key-assumptions span { display: block; font-size: 1.8em; font-weight: bold; color: var(–primary-color); } .intermediate-results p, .key-assumptions p { margin: 5px 0 0 0; font-size: 0.95em; color: #555; } .formula-explanation { margin-top: 20px; font-size: 0.95em; color: #555; text-align: center; background-color: #f0f8ff; padding: 15px; border-radius: 4px; } table { width: 100%; margin-top: 20px; border-collapse: collapse; box-shadow: var(–shadow); } th, td { padding: 12px 15px; text-align: left; border: 1px solid var(–border-color); } th { background-color: var(–primary-color); color: white; font-weight: bold; } tr:nth-child(even) { background-color: #f2f2f2; } caption { caption-side: bottom; padding-top: 10px; font-style: italic; color: #666; text-align: center; } .chart-container { text-align: center; margin-top: 30px; padding: 20px; background-color: var(–card-bg); border-radius: 8px; box-shadow: var(–shadow); } canvas { max-width: 100%; height: auto; } .button-group { text-align: center; margin-top: 20px; } .copy-button { background-color: #17a2b8; } .copy-button:hover { background-color: #138496; } .copy-message { font-size: 0.9em; color: var(–success-color); margin-left: 10px; display: inline-block; } /* Article Styling */ main { padding: 20px; } article { background-color: var(–card-bg); padding: 30px; border-radius: 8px; box-shadow: var(–shadow); } article h2 { font-size: 1.8em; margin-top: 30px; border-bottom: 2px solid var(–primary-color); padding-bottom: 5px; } article h3 { font-size: 1.4em; margin-top: 25px; color: #0056b3; /* Darker blue */ } article p, article ul, article ol { margin-bottom: 15px; font-size: 1.05em; } article ul, article ol { padding-left: 30px; } article li { margin-bottom: 10px; } article code { background-color: #eef7ff; padding: 2px 6px; border-radius: 3px; font-family: Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace; } article blockquote { border-left: 5px solid var(–primary-color); padding-left: 15px; margin-left: 0; font-style: italic; color: #555; } .faq-list { list-style: none; padding-left: 0; } .faq-list li { margin-bottom: 15px; border: 1px solid var(–border-color); padding: 15px; border-radius: 5px; background-color: #fdfdfd; } .faq-list li strong { color: var(–primary-color); display: block; margin-bottom: 8px; font-size: 1.1em; } .internal-links { background-color: #eef7ff; padding: 20px; border-radius: 8px; margin-top: 30px; } .internal-links h3 { color: var(–primary-color); margin-top: 0; text-align: center; } .internal-links ul { list-style: none; padding-left: 0; text-align: center; } .internal-links li { margin-bottom: 12px; } .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: #666; }

Weighted Average Cost of Capital (WACC) Calculator

Easily calculate your company's WACC, essential for investment decisions.

WACC Calculation Inputs

The total market value of your company's outstanding shares.
The required rate of return for equity investors (in %).
The total market value of your company's debt.
The effective interest rate on your company's debt (in %).
Your company's effective corporate tax rate (in %).

Your WACC Results

Weight of Equity (We)

Weight of Debt (Wd)

After-Tax Cost of Debt

Total Capital Value

Effective Tax Rate

After-Tax Cost of Equity

Formula Used: WACC = (We * Re) + (Wd * Rd * (1 – Tc))

Where: We = Market Value of Equity / Total Capital Value Wd = Market Value of Debt / Total Capital Value Re = Cost of Equity Rd = Cost of Debt Tc = Corporate Tax Rate

WACC Components Breakdown

Breakdown of WACC by equity and debt financing costs.

Calculation Details

Component Value Weight Cost (Pre-Tax) Cost (After-Tax) Weighted Cost
Detailed breakdown of each component contributing to WACC.

What is Weighted Average Cost of Capital (WACC)?

This section provides a comprehensive overview of the Weighted Average Cost of Capital (WACC), a fundamental metric for financial analysis and investment decisions. We'll explore its definition, its importance, and how it's calculated, particularly in the context of using Excel for financial modeling. Calculating weighted average cost in Excel is a common task for finance professionals.

What is Weighted Average Cost of Capital (WACC)?

The Weighted Average Cost of Capital (WACC) represents a company's blended cost of capital across all sources of financing, including common stock, preferred stock, bonds, and other forms of debt. Essentially, it's the average rate of return a company expects to pay to its security holders to finance its assets. WACC is a critical metric because it reflects the minimum return a company must earn on its existing asset base to satisfy its creditors, owners, and other providers of capital. If a company earns less than its WACC, it's destroying shareholder value. Conversely, if it earns more, it's creating value.

Who Should Use WACC?

WACC is primarily used by:

  • Corporate Finance Managers: To evaluate potential projects and investments. A project's expected return should exceed the company's WACC to be considered value-adding.
  • Investment Analysts: To value companies and assess their investment attractiveness. WACC is often used as the discount rate in discounted cash flow (DCF) models.
  • Investors: To understand the risk profile and expected return hurdles of a company they are considering investing in.
  • Acquirers: In mergers and acquisitions, WACC helps determine the viability and potential synergies of a deal.

Common Misconceptions

A common misunderstanding is that WACC is simply the average of the cost of debt and equity. This is incorrect because it doesn't account for the proportion (weight) of each capital source in the company's structure. Another misconception is that the cost of debt is simply the stated interest rate; however, interest payments are tax-deductible, making the after-tax cost of debt lower and a crucial component of the WACC calculation. Calculating weighted average cost in Excel requires careful consideration of these nuances.

WACC Formula and Mathematical Explanation

The formula for WACC is derived by taking the weighted average of the costs of each component of the company's capital structure. The most common WACC formula is:

WACC = (We * Re) + (Wd * Rd * (1 – Tc))

Let's break down each component:

  • We (Weight of Equity): This represents the proportion of the company's total capital that is financed by equity. It's calculated as the Market Value of Equity (E) divided by the sum of the Market Value of Equity (E) and the Market Value of Debt (D).
  • Re (Cost of Equity): This is the return required by equity investors. It's typically estimated using models like the Capital Asset Pricing Model (CAPM), considering factors like the risk-free rate, beta, and market risk premium. For this calculator, we take it as a direct input.
  • Wd (Weight of Debt): This represents the proportion of the company's total capital that is financed by debt. It's calculated as the Market Value of Debt (D) divided by the sum of the Market Value of Equity (E) and the Market Value of Debt (D).
  • Rd (Cost of Debt): This is the effective interest rate a company pays on its debt. It should reflect the current market rates for the company's level of risk.
  • Tc (Corporate Tax Rate): This is the company's effective corporate tax rate. Interest payments on debt are usually tax-deductible, which reduces the overall cost of debt. The term (1 - Tc) adjusts the cost of debt for this tax shield.

Variable Explanation Table

Here's a detailed look at the variables used in calculating weighted average cost in Excel and this calculator:

Variable Meaning Unit Typical Range / Notes
E (Market Value of Equity) Total market capitalization of the company. Currency (e.g., USD, EUR) Positive value (e.g., $10M – $10B+)
D (Market Value of Debt) Total market value of all outstanding debt. Currency (e.g., USD, EUR) Positive value (e.g., $1M – $5B+)
Re (Cost of Equity) Required rate of return for equity investors. Percentage (%) Typically 8% – 20% (depends on risk)
Rd (Cost of Debt) Interest rate paid on debt before taxes. Percentage (%) Typically 3% – 10% (depends on creditworthiness)
Tc (Corporate Tax Rate) Company's effective income tax rate. Percentage (%) Depends on jurisdiction (e.g., 21% – 35%)
We (Weight of Equity) Proportion of equity in capital structure. Decimal (0 to 1) Calculated (0.5 – 0.9 typical)
Wd (Weight of Debt) Proportion of debt in capital structure. Decimal (0 to 1) Calculated (0.1 – 0.5 typical)
WACC Overall cost of capital for the firm. Percentage (%) Calculated (typically 5% – 15%)

Practical Examples (Real-World Use Cases)

Understanding WACC is crucial for making sound financial decisions. Here are a couple of practical examples demonstrating how calculating weighted average cost in Excel or using a calculator can provide valuable insights.

Example 1: Technology Startup Valuation

A growing tech company, "Innovate Solutions Inc.", has the following financial data:

  • Market Value of Equity (E): $150,000,000
  • Cost of Equity (Re): 18%
  • Market Value of Debt (D): $50,000,000
  • Cost of Debt (Rd): 7%
  • Corporate Tax Rate (Tc): 21%

Calculation:

  • Total Capital (E + D): $150M + $50M = $200,000,000
  • Weight of Equity (We): $150M / $200M = 0.75
  • Weight of Debt (Wd): $50M / $200M = 0.25
  • After-Tax Cost of Debt: 7% * (1 – 0.21) = 5.53%
  • WACC = (0.75 * 18%) + (0.25 * 5.53%)
  • WACC = 13.5% + 1.3825% = 14.8825%

Interpretation: Innovate Solutions Inc. needs to generate a return of at least 14.88% on its investments to satisfy its investors and creditors. This WACC can be used as a hurdle rate for evaluating new projects. Use our WACC calculator to perform this calculation instantly.

Example 2: Manufacturing Company Expansion

A stable manufacturing firm, "Durable Goods Corp.", is considering expanding its operations. Their financial details are:

  • Market Value of Equity (E): $500,000,000
  • Cost of Equity (Re): 11%
  • Market Value of Debt (D): $300,000,000
  • Cost of Debt (Rd): 5%
  • Corporate Tax Rate (Tc): 25%

Calculation:

  • Total Capital (E + D): $500M + $300M = $800,000,000
  • Weight of Equity (We): $500M / $800M = 0.625
  • Weight of Debt (Wd): $300M / $800M = 0.375
  • After-Tax Cost of Debt: 5% * (1 – 0.25) = 3.75%
  • WACC = (0.625 * 11%) + (0.375 * 3.75%)
  • WACC = 6.875% + 1.40625% = 8.28125%

Interpretation: Durable Goods Corp.'s WACC is approximately 8.28%. Any expansion project considered must promise a return significantly higher than this figure to justify the investment and potentially increase shareholder value. This demonstrates the practical application of calculating weighted average cost in Excel-like scenarios.

How to Use This WACC Calculator

Our calculator is designed for simplicity and accuracy. Follow these steps to determine your company's WACC:

  1. Input Equity Market Value (E): Enter the current total market value of your company's outstanding common stock.
  2. Input Cost of Equity (Re): Provide the required rate of return for equity investors, typically derived from CAPM or similar models. Enter this as a percentage (e.g., 12 for 12%).
  3. Input Debt Market Value (D): Enter the current market value of your company's outstanding debt (bonds, loans, etc.).
  4. Input Cost of Debt (Rd): Enter the current average interest rate your company pays on its debt. Enter this as a percentage (e.g., 6 for 6%).
  5. Input Corporate Tax Rate (Tc): Enter your company's effective corporate income tax rate. Enter this as a percentage (e.g., 25 for 25%).
  6. Calculate: Click the "Calculate WACC" button.

The calculator will instantly display:

  • Primary Result (WACC): The overall weighted average cost of capital for your company.
  • Intermediate Values: The calculated Weight of Equity (We), Weight of Debt (Wd), and the After-Tax Cost of Debt.
  • Key Assumptions: Total Capital Value, Effective Tax Rate applied, and After-Tax Cost of Equity (which is just Re in this simplified calculator, but note that in advanced models, this might differ).
  • Detailed Table: A breakdown of the components, weights, costs, and weighted costs.
  • Chart: A visual representation of the WACC components.

Decision-Making Guidance: Use the calculated WACC as a benchmark. If a potential investment's expected rate of return is higher than the WACC, it is generally considered a value-creating project. If it's lower, the project may not be financially viable and could potentially decrease firm value. Always consider qualitative factors alongside quantitative analysis.

Key Factors That Affect WACC Results

Several factors can influence a company's WACC, making it a dynamic metric. Understanding these helps in interpreting the results and managing the company's capital structure effectively. Calculating weighted average cost needs to consider these nuances.

  1. Capital Structure (Weights We and Wd): The mix of debt and equity significantly impacts WACC. A company with more debt will generally have a higher WACC if its cost of debt rises significantly or if its equity holders demand a higher return due to increased financial risk. Adjusting the capital structure is a key lever for managing WACC.
  2. Cost of Equity (Re): Changes in market risk premium, beta (company's systematic risk relative to the market), or the risk-free rate directly affect the cost of equity. Higher perceived risk for the company's stock will increase Re and thus WACC.
  3. Cost of Debt (Rd): A company's credit rating and prevailing interest rates influence its borrowing costs. An upgrade in credit rating can lower Rd, potentially decreasing WACC, while a downgrade increases it. Lenders may demand higher rates if they perceive increased default risk.
  4. Corporate Tax Rate (Tc): The tax deductibility of interest payments reduces the effective cost of debt. Changes in tax laws or the company's effective tax rate will alter the after-tax cost of debt, thus impacting WACC. This is a crucial element when calculating weighted average cost.
  5. Economic Conditions: Broader economic factors like inflation, interest rate movements set by central banks, and overall market sentiment influence both the cost of equity and the cost of debt. In periods of high inflation or rising interest rates, WACC tends to increase.
  6. Company-Specific Risk: Factors unique to the company, such as operational risks, management quality, industry competition, and regulatory changes, can affect the perceived risk by investors, influencing both Re and Rd. A higher perceived risk generally leads to a higher WACC.
  7. Investment Horizon and Project Risk: While WACC represents the firm's overall cost of capital, specific projects may have different risk profiles. Companies often adjust the WACC for project-specific risk, using a higher discount rate for riskier projects and a lower one for less risky ventures.

Frequently Asked Questions (FAQ)

  • Q1: What is the difference between cost of debt and WACC?

    The cost of debt is the interest rate a company pays on its borrowings. WACC is the blended average cost of all capital sources (debt and equity), adjusted for their proportions and the tax deductibility of interest.

  • Q2: Can WACC be negative?

    In theory, it's highly unlikely for WACC to be negative. Both cost of equity and cost of debt are typically positive. Even with tax benefits, the overall cost is expected to be positive, reflecting the minimum required return.

  • Q3: How do I find the market value of equity and debt?

    For publicly traded companies, the market value of equity is the current share price multiplied by the number of outstanding shares (market capitalization). The market value of debt can be more complex, often approximated by the book value if market prices aren't readily available, but ideally, it's the present value of all future debt payments discounted at the current market interest rate for similar debt.

  • Q4: Is WACC the same as the discount rate for all projects?

    Not necessarily. WACC represents the average risk of the company's current assets. For projects with significantly different risk profiles than the company average, a risk-adjusted discount rate should be used instead of the company's WACC.

  • Q5: Why is the cost of debt adjusted for taxes?

    Interest payments on debt are typically tax-deductible expenses for corporations. This tax shield effectively reduces the company's overall cost of borrowing, making the after-tax cost of debt lower than the pre-tax cost of debt. Calculating weighted average cost correctly requires this adjustment.

  • Q6: How often should WACC be recalculated?

    WACC should be recalculated whenever there are significant changes in the company's capital structure, market conditions, risk profile, or tax rates. Annually is a common practice for ongoing monitoring, but ad-hoc recalculations are necessary after major events.

  • Q7: What is the CAPM model, and how does it relate to the cost of equity?

    The Capital Asset Pricing Model (CAPM) is a widely used method to estimate the cost of equity. The formula is: Cost of Equity = Risk-Free Rate + Beta * (Market Risk Premium). Beta measures the stock's volatility relative to the overall market.

  • Q8: Can preferred stock be included in WACC?

    Yes, if a company has preferred stock, its cost and market value should also be included in the WACC calculation. The formula would expand to include a term for preferred equity: WACC = (We * Re) + (Wd * Rd * (1 – Tc)) + (Wp * Rp), where Wp is the weight of preferred stock and Rp is its cost.

© 2023 Your Financial Tools. All rights reserved.

Disclaimer: This calculator and information are for educational purposes only and do not constitute financial advice.

var marketValueEquityInput = document.getElementById('marketValueEquity'); var costOfEquityInput = document.getElementById('costOfEquity'); var marketValueDebtInput = document.getElementById('marketValueDebt'); var costOfDebtInput = document.getElementById('costOfDebt'); var corporateTaxRateInput = document.getElementById('corporateTaxRate'); var marketValueEquityError = document.getElementById('marketValueEquityError'); var costOfEquityError = document.getElementById('costOfEquityError'); var marketValueDebtError = document.getElementById('marketValueDebtError'); var costOfDebtError = document.getElementById('costOfDebtError'); var corporateTaxRateError = document.getElementById('corporateTaxRateError'); var resultsContainer = document.getElementById('resultsContainer'); var primaryResult = document.getElementById('primaryResult'); var weightEquity = document.getElementById('weightEquity'); var weightDebt = document.getElementById('weightDebt'); var afterTaxCostOfDebt = document.getElementById('afterTaxCostOfDebt'); var totalValue = document.getElementById('totalValue'); var effTaxRate = document.getElementById('effTaxRate'); var afterTaxCostOfEquity = document.getElementById('afterTaxCostOfEquity'); var waccChartCanvas = document.getElementById('waccChart').getContext('2d'); var waccTableBody = document.querySelector('#waccTable tbody'); var copyMessage = document.getElementById('copyMessage'); var chartInstance = null; function formatCurrency(value) { return '$' + Number(value).toLocaleString(undefined, { minimumFractionDigits: 0, maximumFractionDigits: 0 }); } function formatPercentage(value) { if (isNaN(value)) return '–'; return value.toFixed(2) + '%'; } function formatNumber(value, decimals = 2) { if (isNaN(value)) return '–'; return Number(value).toLocaleString(undefined, { minimumFractionDigits: decimals, maximumFractionDigits: decimals }); } function updateChart(we, wacc, equityCost, debtCostAfterTax) { if (chartInstance) { chartInstance.destroy(); } var totalCapitalValue = parseFloat(marketValueEquityInput.value) + parseFloat(marketValueDebtInput.value); var weightDebtCalc = (parseFloat(marketValueDebtInput.value) / totalCapitalValue) * 100; var weightEquityCalc = (parseFloat(marketValueEquityInput.value) / totalCapitalValue) * 100; var totalWACC = we + debtCostAfterTax; var equityComponent = we; var debtComponent = debtCostAfterTax; chartInstance = new Chart(waccChartCanvas, { type: 'bar', data: { labels: ['WACC Components'], datasets: [{ label: 'Weighted Cost of Equity', data: [equityComponent], backgroundColor: 'rgba(0, 74, 153, 0.7)', // Primary color borderColor: 'rgba(0, 74, 153, 1)', borderWidth: 1 }, { label: 'Weighted After-Tax Cost of Debt', data: [debtComponent], backgroundColor: 'rgba(40, 167, 69, 0.7)', // Success color borderColor: 'rgba(40, 167, 69, 1)', borderWidth: 1 }] }, options: { responsive: true, maintainAspectRatio: true, scales: { y: { beginAtZero: true, ticks: { callback: function(value) { return formatPercentage(value); } } } }, plugins: { tooltip: { callbacks: { label: function(context) { var label = context.dataset.label || "; if (label) { label += ': '; } if (context.parsed.y !== null) { label += formatPercentage(context.parsed.y); } return label; } } } } } }); } function updateTable(eVal, reVal, dVal, rdVal, tcVal) { waccTableBody.innerHTML = "; // Clear previous rows var totalCapital = eVal + dVal; var we = (totalCapital === 0) ? 0 : eVal / totalCapital; var wd = (totalCapital === 0) ? 0 : dVal / totalCapital; var afterTaxRd = rdVal * (1 – (tcVal / 100)); // Equity Row var rowEq = waccTableBody.insertRow(); rowEq.insertCell(0).textContent = 'Equity'; rowEq.insertCell(1).textContent = formatCurrency(eVal); rowEq.insertCell(2).textContent = formatPercentage(we * 100); rowEq.insertCell(3).textContent = formatPercentage(reVal); rowEq.insertCell(4).textContent = formatPercentage(reVal); // Cost of Equity is already after-tax equivalent rowEq.insertCell(5).textContent = formatPercentage(we * reVal); // Debt Row var rowDebt = waccTableBody.insertRow(); rowDebt.insertCell(0).textContent = 'Debt'; rowDebt.insertCell(1).textContent = formatCurrency(dVal); rowDebt.insertCell(2).textContent = formatPercentage(wd * 100); rowDebt.insertCell(3).textContent = formatPercentage(rdVal); rowDebt.insertCell(4).textContent = formatPercentage(afterTaxRd); rowDebt.insertCell(5).textContent = formatPercentage(wd * afterTaxRd); } function calculateWACC() { var marketValueEquity = parseFloat(marketValueEquityInput.value); var costOfEquity = parseFloat(costOfEquityInput.value); var marketValueDebt = parseFloat(marketValueDebtInput.value); var costOfDebt = parseFloat(costOfDebtInput.value); var corporateTaxRate = parseFloat(corporateTaxRateInput.value); var isValid = true; // Reset errors marketValueEquityError.textContent = "; costOfEquityError.textContent = "; marketValueDebtError.textContent = "; costOfDebtError.textContent = "; corporateTaxRateError.textContent = "; // Input Validation if (isNaN(marketValueEquity) || marketValueEquity < 0) { marketValueEquityError.textContent = 'Please enter a valid non-negative number.'; isValid = false; } if (isNaN(costOfEquity) || costOfEquity 100) { costOfEquityError.textContent = 'Please enter a valid percentage between 0 and 100.'; isValid = false; } if (isNaN(marketValueDebt) || marketValueDebt < 0) { marketValueDebtError.textContent = 'Please enter a valid non-negative number.'; isValid = false; } if (isNaN(costOfDebt) || costOfDebt 100) { costOfDebtError.textContent = 'Please enter a valid percentage between 0 and 100.'; isValid = false; } if (isNaN(corporateTaxRate) || corporateTaxRate 100) { corporateTaxRateError.textContent = 'Please enter a valid percentage between 0 and 100.'; isValid = false; } if (!isValid) { resultsContainer.style.display = 'none'; return; } var totalCapitalValue = marketValueEquity + marketValueDebt; var weightEquityValue = (totalCapitalValue === 0) ? 0 : marketValueEquity / totalCapitalValue; var weightDebtValue = (totalCapitalValue === 0) ? 0 : marketValueDebt / totalCapitalValue; var afterTaxCostOfDebtValue = costOfDebt * (1 – (corporateTaxRate / 100)); var wacc = (weightEquityValue * costOfEquity) + (weightDebtValue * afterTaxCostOfDebtValue); // Display Results primaryResult.textContent = formatPercentage(wacc); weightEquity.textContent = formatPercentage(weightEquityValue * 100); weightDebt.textContent = formatPercentage(weightDebtValue * 100); afterTaxCostOfDebt.textContent = formatPercentage(afterTaxCostOfDebtValue); totalValue.textContent = formatCurrency(totalCapitalValue); effTaxRate.textContent = formatPercentage(corporateTaxRate); afterTaxCostOfEquity.textContent = formatPercentage(costOfEquity); // Simplified: Cost of Equity is already after-tax concept resultsContainer.style.display = 'block'; // Update Table updateTable(marketValueEquity, costOfEquity, marketValueDebt, costOfDebt, corporateTaxRate); // Update Chart updateChart(weightEquityValue * costOfEquity, wacc, costOfEquity, afterTaxCostOfDebtValue); } function resetCalculator() { marketValueEquityInput.value = '100000000'; costOfEquityInput.value = '12'; marketValueDebtInput.value = '50000000'; costOfDebtInput.value = '6'; corporateTaxRateInput.value = '25'; marketValueEquityError.textContent = "; costOfEquityError.textContent = "; marketValueDebtError.textContent = "; costOfDebtError.textContent = "; corporateTaxRateError.textContent = "; resultsContainer.style.display = 'none'; if (chartInstance) { chartInstance.destroy(); chartInstance = null; } waccTableBody.innerHTML = "; copyMessage.textContent = "; } function copyResults() { var equityValue = parseFloat(marketValueEquityInput.value); var costEquity = parseFloat(costOfEquityInput.value); var debtValue = parseFloat(marketValueDebtInput.value); var costDebt = parseFloat(costOfDebtInput.value); var taxRate = parseFloat(corporateTaxRateInput.value); // Re-validate inputs before copying var tempValid = true; if (isNaN(equityValue) || equityValue < 0) { marketValueEquityError.textContent = 'Invalid input'; tempValid = false; } if (isNaN(costEquity) || costEquity 100) { costOfEquityError.textContent = 'Invalid input'; tempValid = false; } if (isNaN(debtValue) || debtValue < 0) { marketValueDebtError.textContent = 'Invalid input'; tempValid = false; } if (isNaN(costDebt) || costDebt 100) { costOfDebtError.textContent = 'Invalid input'; tempValid = false; } if (isNaN(taxRate) || taxRate 100) { corporateTaxRateError.textContent = 'Invalid input'; tempValid = false; } if (!tempValid) { copyMessage.textContent = 'Fix errors before copying.'; copyMessage.style.color = 'red'; return; } var totalCapital = equityValue + debtValue; var weightEquityVal = (totalCapital === 0) ? 0 : equityValue / totalCapital; var weightDebtVal = (totalCapital === 0) ? 0 : debtValue / totalCapital; var afterTaxCostDebtVal = costDebt * (1 – (taxRate / 100)); var waccVal = (weightEquityVal * costEquity) + (weightDebtVal * afterTaxCostDebtVal); var textToCopy = "— WACC Calculation Results —\n\n"; textToCopy += "Key Assumptions:\n"; textToCopy += "Market Value of Equity (E): " + formatCurrency(equityValue) + "\n"; textToCopy += "Cost of Equity (Re): " + formatPercentage(costEquity) + "\n"; textToCopy += "Market Value of Debt (D): " + formatCurrency(debtValue) + "\n"; textToCopy += "Cost of Debt (Rd): " + formatPercentage(costDebt) + "\n"; textToCopy += "Corporate Tax Rate (Tc): " + formatPercentage(taxRate) + "\n"; textToCopy += "\n"; textToCopy += "Calculated Values:\n"; textToCopy += "Total Capital Value: " + formatCurrency(totalCapital) + "\n"; textToCopy += "Weight of Equity (We): " + formatPercentage(weightEquityVal * 100) + "\n"; textToCopy += "Weight of Debt (Wd): " + formatPercentage(weightDebtVal * 100) + "\n"; textToCopy += "After-Tax Cost of Debt: " + formatPercentage(afterTaxCostDebtVal) + "\n"; textToCopy += "\n"; textToCopy += "Primary Result:\n"; textToCopy += "Weighted Average Cost of Capital (WACC): " + formatPercentage(waccVal) + "\n"; // Using a temporary textarea to copy text var textArea = document.createElement("textarea"); textArea.value = textToCopy; textArea.style.position = "fixed"; textArea.style.left = "-9999px"; document.body.appendChild(textArea); textArea.focus(); textArea.select(); try { var successful = document.execCommand('copy'); var msg = successful ? 'Results Copied!' : 'Copy failed'; copyMessage.textContent = msg; copyMessage.style.color = successful ? 'green' : 'red'; } catch (err) { copyMessage.textContent = 'Copy failed'; copyMessage.style.color = 'red'; } document.body.removeChild(textArea); } // Initial calculation on load if inputs have default values document.addEventListener('DOMContentLoaded', function() { resetCalculator(); // Sets defaults calculateWACC(); // Calculates initial values });

Leave a Comment