Calculate the Weighted Average Cost of Capital

Weighted Average Cost of Capital (WACC) Calculator & Guide :root { –primary-color: #004a99; –success-color: #28a745; –background-color: #f8f9fa; –text-color: #333; –secondary-text-color: #666; –border-color: #ddd; –shadow-color: rgba(0, 0, 0, 0.1); –card-background: #fff; –input-border: #ccc; –input-focus-border: var(–primary-color); –result-background: var(–primary-color); –result-text-color: #fff; } body { font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; background-color: var(–background-color); color: var(–text-color); line-height: 1.6; margin: 0; padding: 0; } .container { max-width: 1000px; margin: 20px auto; padding: 20px; background-color: var(–card-background); border-radius: 8px; box-shadow: 0 4px 15px var(–shadow-color); } header { text-align: center; padding-bottom: 20px; border-bottom: 1px solid var(–border-color); margin-bottom: 30px; } h1, h2, h3 { color: var(–primary-color); } h1 { font-size: 2.5em; margin-bottom: 0.5em; } h2 { font-size: 1.8em; margin-top: 1.5em; margin-bottom: 1em; } h3 { font-size: 1.3em; margin-top: 1em; margin-bottom: 0.7em; } .loan-calc-container { background-color: var(–card-background); padding: 30px; border-radius: 8px; box-shadow: 0 2px 10px var(–shadow-color); margin-bottom: 40px; border: 1px solid var(–border-color); } .input-group { margin-bottom: 20px; } .input-group label { display: block; margin-bottom: 8px; font-weight: bold; color: var(–primary-color); } .input-group input[type="number"], .input-group input[type="text"], .input-group select { width: calc(100% – 20px); padding: 12px; border: 1px solid var(–input-border); border-radius: 5px; box-sizing: border-box; font-size: 1em; transition: border-color 0.3s ease; } .input-group input[type="number"]:focus, .input-group input[type="text"]:focus, .input-group select:focus { outline: none; border-color: var(–input-focus-border); box-shadow: 0 0 0 3px rgba(0, 74, 153, 0.2); } .input-group small { display: block; margin-top: 8px; color: var(–secondary-text-color); font-size: 0.9em; } .error-message { color: #dc3545; font-size: 0.9em; margin-top: 5px; display: none; } .btn { display: inline-block; padding: 12px 25px; border: none; border-radius: 5px; font-size: 1em; font-weight: bold; cursor: pointer; text-align: center; transition: background-color 0.3s ease, transform 0.2s ease; margin-right: 10px; color: #fff; } .btn-primary { background-color: var(–primary-color); } .btn-primary:hover { background-color: #003366; transform: translateY(-2px); } .btn-secondary { background-color: var(–border-color); color: var(–text-color); } .btn-secondary:hover { background-color: #ccc; transform: translateY(-2px); } .btn-success { background-color: var(–success-color); } .btn-success:hover { background-color: #218838; transform: translateY(-2px); } #results { margin-top: 30px; padding: 30px; background-color: var(–primary-color); color: var(–result-text-color); border-radius: 8px; box-shadow: 0 2px 10px var(–shadow-color); text-align: center; } #results h3 { color: var(–result-text-color); margin-bottom: 15px; font-size: 1.6em; } #results .result-item { margin-bottom: 15px; } #results .result-label { font-size: 1.1em; opacity: 0.8; display: block; margin-bottom: 5px; } #results .result-value { font-size: 2.2em; font-weight: bold; display: block; } #results .intermediate-value { font-size: 1.4em; font-weight: bold; display: block; margin-top: 10px; } #results .formula-explanation { font-size: 0.95em; margin-top: 20px; padding-top: 15px; border-top: 1px solid rgba(255, 255, 255, 0.2); opacity: 0.9; } .chart-container { margin-top: 40px; padding: 30px; background-color: var(–card-background); border-radius: 8px; box-shadow: 0 2px 10px var(–shadow-color); text-align: center; border: 1px solid var(–border-color); } .chart-container canvas { max-width: 100%; height: auto; } .chart-caption { font-size: 0.9em; color: var(–secondary-text-color); margin-top: 10px; display: block; } .table-container { margin-top: 40px; overflow-x: auto; } table { width: 100%; border-collapse: collapse; border-radius: 8px; box-shadow: 0 2px 10px var(–shadow-color); background-color: var(–card-background); border: 1px solid var(–border-color); } th, td { padding: 15px; text-align: center; border-bottom: 1px solid var(–border-color); } thead th { background-color: var(–primary-color); color: #fff; font-weight: bold; border-top-left-radius: 8px; border-top-right-radius: 8px; } tbody tr:last-child td { border-bottom: none; } tbody td { color: var(–text-color); } .table-caption { font-size: 0.9em; color: var(–secondary-text-color); margin-bottom: 10px; display: block; text-align: center; } article { margin-top: 50px; background-color: var(–card-background); padding: 40px; border-radius: 8px; box-shadow: 0 2px 10px var(–shadow-color); border: 1px solid var(–border-color); } article p { margin-bottom: 1.2em; } article ul { margin-left: 20px; margin-bottom: 1.2em; } article li { margin-bottom: 0.5em; } article a { color: var(–primary-color); text-decoration: none; } article a:hover { text-decoration: underline; } .faq-item { margin-bottom: 20px; padding: 15px; background-color: #f0f5fa; border-left: 5px solid var(–primary-color); border-radius: 5px; } .faq-item strong { display: block; color: var(–primary-color); margin-bottom: 8px; } .internal-links-section { margin-top: 40px; padding: 30px; background-color: var(–card-background); border-radius: 8px; box-shadow: 0 2px 10px var(–shadow-color); border: 1px solid var(–border-color); } .internal-links-section ul { list-style: none; padding: 0; margin: 0; } .internal-links-section li { margin-bottom: 15px; padding-bottom: 15px; border-bottom: 1px solid var(–border-color); } .internal-links-section li:last-child { border-bottom: none; margin-bottom: 0; padding-bottom: 0; } .internal-links-section a { font-weight: bold; } .internal-links-section p { margin-top: 5px; font-size: 0.9em; color: var(–secondary-text-color); } .result-value .currency::after { content: "%"; font-size: 0.7em; margin-left: 2px; } .result-value.percent::after { content: "%"; font-size: 0.7em; margin-left: 2px; } .result-value.currency { font-size: 1.8em; } #calculatorForm input[type="number"] { -moz-appearance: textfield; } #calculatorForm input[type="number"]::-webkit-outer-spin-button, #calculatorForm input[type="number"]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

Weighted Average Cost of Capital (WACC) Calculator

Determine your company's WACC to evaluate investment opportunities and understand your cost of financing.

WACC Input Parameters

Enter the expected rate of return required by equity investors, typically expressed as a percentage.
Enter the total market value of the company's outstanding shares.
Enter the interest rate on the company's debt, expressed as a percentage.
Enter the total market value of the company's outstanding debt.
Enter the company's effective corporate tax rate, expressed as a percentage.

Your WACC Results

Weighted Average Cost of Capital (WACC) –.–%

Weight of Equity (We) –.–%
Weight of Debt (Wd) –.–%
After-Tax Cost of Debt –.–%
The WACC formula is: WACC = (E/V) * Ke + (D/V) * Kd * (1 – t), where V = E + D. This represents the blended cost of capital, considering both equity and debt financing, adjusted for taxes.
WACC Calculation Breakdown
Component Input Value Weight Cost After-Tax Cost
Equity –.–% –.–% –.–%
Debt –.–% –.–% –.–%
Total 100.00% –.–%
Capital Structure & Cost Breakdown

What is Weighted Average Cost of Capital (WACC)?

The Weighted Average Cost of Capital, commonly known as WACC, is a crucial financial metric that represents a company's blended cost of capital. It's calculated by taking the cost of each individual capital component (like equity and debt) and weighting them by their respective proportions in the company's capital structure. WACC signifies the average rate of return a company is expected to pay to all its security holders to finance its assets. Essentially, it's the minimum rate of return a company must earn on its existing asset base to satisfy its creditors, owners, and other capital providers.

Who should use it? WACC is primarily used by financial analysts, corporate finance managers, investors, and business owners. It's indispensable for:

  • Valuation: Discounting future cash flows to determine the present value of a business or project. A higher WACC means lower present values, and vice versa.
  • Investment Decisions: Evaluating potential projects or investments. A project's expected return should exceed the company's WACC to be considered value-adding.
  • Capital Budgeting: Allocating capital efficiently among various potential investments.
  • Performance Measurement: Assessing whether a company is generating returns above its cost of capital.

Common Misconceptions: A frequent misconception is that WACC is simply the average of the cost of debt and cost of equity. This ignores the crucial weighting based on the capital structure and the tax deductibility of interest expenses on debt. Another error is using a company's overall WACC for projects with significantly different risk profiles; specialized discount rates are often more appropriate in such cases. Understanding the nuances of the weighted average cost of capital is key to its effective application.

WACC Formula and Mathematical Explanation

The formula for calculating the Weighted Average Cost of Capital (WACC) is as follows:

WACC = (E / V) * Ke + (D / V) * Kd * (1 – t)

Let's break down each component:

Variable Meaning Unit Typical Range
E Market Value of Equity Currency (e.g., $) Highly variable based on company size and market conditions.
D Market Value of Debt Currency (e.g., $) Variable based on borrowing levels.
V Total Market Value of Capital (E + D) Currency (e.g., $) Sum of E and D.
Ke Cost of Equity Percentage (%) Typically 8% – 15%+, depending on risk.
Kd Cost of Debt Percentage (%) Generally lower than Ke, e.g., 4% – 10%.
t Corporate Tax Rate Percentage (%) Statutory tax rate, e.g., 21% in the US.

Step-by-Step Derivation:

  1. Calculate Total Firm Value (V): Sum the market value of equity (E) and the market value of debt (D). V = E + D.
  2. Determine Weight of Equity (We): Divide the market value of equity (E) by the total firm value (V). We = E / V.
  3. Determine Weight of Debt (Wd): Divide the market value of debt (D) by the total firm value (V). Wd = D / V.
  4. Calculate After-Tax Cost of Debt: Multiply the cost of debt (Kd) by (1 – tax rate (t)). This accounts for the tax shield benefit of interest payments. After-Tax Kd = Kd * (1 - t).
  5. Calculate WACC: Multiply the weight of equity (We) by the cost of equity (Ke), and add it to the product of the weight of debt (Wd) and the after-tax cost of debt. WACC = We * Ke + Wd * After-Tax Kd.

The weighted average cost of capital calculation is fundamental for corporate finance.

Practical Examples (Real-World Use Cases)

Example 1: Technology Startup

A rapidly growing tech company, "Innovate Solutions," has the following capital structure:

  • Market Value of Equity (E): $50,000,000
  • Market Value of Debt (D): $20,000,000
  • Cost of Equity (Ke): 15.0%
  • Cost of Debt (Kd): 7.0%
  • Corporate Tax Rate (t): 25.0%
Calculation:
  • Total Value (V) = $50M + $20M = $70,000,000
  • Weight of Equity (We) = $50M / $70M = 0.7143 or 71.43%
  • Weight of Debt (Wd) = $20M / $70M = 0.2857 or 28.57%
  • After-Tax Cost of Debt = 7.0% * (1 – 0.25) = 7.0% * 0.75 = 5.25%
  • WACC = (71.43% * 15.0%) + (28.57% * 5.25%)
  • WACC = 10.71% + 1.50% = 12.21%
Interpretation: Innovate Solutions needs to achieve an annual return of at least 12.21% on its investments to satisfy its investors and creditors. A new project expected to yield 14% would likely be approved, while one yielding 10% would be rejected. This demonstrates the importance of capital structure and WACC.

Example 2: Mature Manufacturing Firm

A stable manufacturing company, "Durable Goods Inc.," has:

  • Market Value of Equity (E): $200,000,000
  • Market Value of Debt (D): $150,000,000
  • Cost of Equity (Ke): 10.0%
  • Cost of Debt (Kd): 5.0%
  • Corporate Tax Rate (t): 21.0%
Calculation:
  • Total Value (V) = $200M + $150M = $350,000,000
  • Weight of Equity (We) = $200M / $350M = 0.5714 or 57.14%
  • Weight of Debt (Wd) = $150M / $350M = 0.4286 or 42.86%
  • After-Tax Cost of Debt = 5.0% * (1 – 0.21) = 5.0% * 0.79 = 3.95%
  • WACC = (57.14% * 10.0%) + (42.86% * 3.95%)
  • WACC = 5.71% + 1.69% = 7.40%
Interpretation: Durable Goods Inc.'s WACC is 7.40%. This indicates the required rate of return for new projects must exceed this threshold. The company's lower WACC compared to the startup reflects its lower risk profile and stable cash flows, a key aspect of understanding cost of capital analysis.

How to Use This WACC Calculator

Our WACC calculator simplifies the process of determining your company's Weighted Average Cost of Capital. Follow these steps:

  1. Gather Your Data: Before using the calculator, you'll need to know:
    • The total Market Value of Equity (E) for your company.
    • The total Market Value of Debt (D).
    • Your company's Cost of Equity (Ke). This is often estimated using models like the Capital Asset Pricing Model (CAPM).
    • Your company's Cost of Debt (Kd), which is typically your company's current borrowing interest rate.
    • Your company's effective Corporate Tax Rate (t).
  2. Input the Values: Enter each piece of data into the corresponding field in the calculator. Ensure you enter percentages as whole numbers (e.g., 12.5 for 12.5%) and monetary values without commas or currency symbols.
  3. Calculate: Click the "Calculate WACC" button. The calculator will instantly provide your company's WACC.
  4. Interpret the Results:
    • WACC: This is your primary result – the blended cost of capital for your company.
    • Intermediate Values: The calculator also shows the Weight of Equity (We), Weight of Debt (Wd), and the After-Tax Cost of Debt. These provide insights into your capital structure and financing costs.
    • Breakdown Table: This table offers a clear view of how each component contributes to the WACC, including weights and costs.
    • Chart: The chart visually represents the composition of your capital structure and the cost associated with each component.
  5. Decision Making: Use your calculated WACC as a benchmark. Any investment or project undertaken by the company should ideally generate a return higher than the WACC to create shareholder value.
  6. Reset: If you need to start over or adjust inputs, click the "Reset" button to clear the fields and results.
  7. Copy Results: The "Copy Results" button allows you to easily transfer the WACC, intermediate values, and key assumptions to other documents or reports.

Understanding how to use financial analysis tools like this WACC calculator is vital for strategic decision-making.

Key Factors That Affect WACC Results

Several factors can significantly influence a company's Weighted Average Cost of Capital. Understanding these dynamics is crucial for accurate interpretation and strategic financial planning:

  • Market Conditions:
    • Interest Rates: Fluctuations in general market interest rates directly impact the cost of debt (Kd). Higher rates increase Kd, thus increasing WACC.
    • Equity Market Performance: The overall performance and sentiment of the stock market influence the cost of equity (Ke). Bull markets might lower Ke (initially), while bear markets can increase it due to higher perceived risk.
  • Company-Specific Risk:
    • Business Risk: The inherent volatility of a company's operating income. Industries with predictable revenues (e.g., utilities) typically have lower business risk and thus lower WACC than cyclical industries (e.g., construction).
    • Financial Risk: The additional risk placed on common stockholders as a result of the firm's decision to finance with debt. Higher leverage (more debt) increases financial risk, which can increase both Ke and Kd, thereby raising WACC.
  • Capital Structure (E/D Mix): The proportion of debt versus equity significantly impacts WACC. While debt is typically cheaper than equity (especially after-tax), excessive debt increases financial risk, potentially driving up both Kd and Ke. Finding the optimal capital structure is a key financial goal. The weighted average cost of capital calculation directly incorporates this mix.
  • Profitability and Cash Flow Stability: Companies with strong, consistent cash flows and high profitability are generally perceived as less risky. This can lead to lower costs for both debt and equity, reducing the overall WACC. A stable cost of capital is a sign of a healthy company.
  • Tax Rates: The corporate tax rate directly affects the "after-tax cost of debt." A higher tax rate makes the interest tax shield more valuable, reducing the effective cost of debt and thus lowering WACC. Changes in tax policy can therefore impact a company's WACC.
  • Management Quality and Strategy: Effective management that makes sound strategic decisions, maintains operational efficiency, and fosters investor confidence can lead to lower perceived risk and, consequently, a lower WACC. Strategic investment decisions are often guided by WACC.

Frequently Asked Questions (FAQ)

Q1: What is the difference between Cost of Debt (Kd) and the coupon rate?

The coupon rate is the stated interest rate on a bond. The Cost of Debt (Kd) is the effective yield to maturity on the company's debt, reflecting current market rates and the company's credit risk. For publicly traded debt, Kd is the market yield. For private debt, it's the rate the company would pay if it issued new debt today.

Q2: How is the Cost of Equity (Ke) typically calculated?

The most common method is the Capital Asset Pricing Model (CAPM): Ke = Rf + β * (Rm – Rf), where Rf is the risk-free rate, β (beta) measures the stock's volatility relative to the market, and (Rm – Rf) is the market risk premium. Other methods include the Dividend Discount Model (DDM).

Q3: Should I use book values or market values for E and D?

Always use market values for E (Market Capitalization) and D (Market Value of Debt). WACC reflects the current cost of raising capital in the market, so market-based inputs are essential for an accurate representation of the company's current cost structure. Book values represent historical costs.

Q4: Can WACC be negative?

Theoretically, WACC cannot be negative as both the cost of equity and the after-tax cost of debt are positive. A company's cost of capital is always a positive value, representing the minimum return required to compensate capital providers.

Q5: What if a company has preferred stock? How is that included?

If a company has preferred stock, it's included as a third component in the WACC calculation. The formula expands to: WACC = (E/V)*Ke + (D/V)*Kd*(1-t) + (P/V)*Kp, where P is the market value of preferred stock, V is the total value (E+D+P), and Kp is the cost of preferred stock (dividend yield).

Q6: How does WACC relate to a company's discount rate for project evaluation?

WACC is often used as the discount rate for projects that have the same risk profile and capital structure as the company as a whole. However, for projects with significantly different risk levels (higher or lower), a project-specific discount rate adjusted for that risk should be used instead of the generic WACC.

Q7: What are the limitations of using WACC?

Limitations include the difficulty in accurately estimating Ke, the assumption of a constant capital structure, the use of a single WACC for all projects (ignoring differing risk profiles), and the potential for market conditions to change rapidly, making the calculated WACC quickly outdated.

Q8: Is WACC a measure of profitability?

No, WACC is not a measure of profitability. It's a measure of the cost of the capital used to fund operations and investments. Profitability is measured by returns (e.g., ROE, ROA, IRR), and WACC serves as the hurdle rate against which these returns are compared. A company is considered profitable from a shareholder perspective if its returns exceed its WACC.

var costOfEquityInput = document.getElementById("costOfEquity"); var equityMarketValueInput = document.getElementById("equityMarketValue"); var costOfDebtInput = document.getElementById("costOfDebt"); var debtMarketValueInput = document.getElementById("debtMarketValue"); var corporateTaxRateInput = document.getElementById("corporateTaxRate"); var finalWACCDisplay = document.getElementById("finalWACC"); var weightOfEquityDisplay = document.getElementById("weightOfEquity"); var weightOfDebtDisplay = document.getElementById("weightOfDebt"); var afterTaxCostOfDebtDisplay = document.getElementById("afterTaxCostOfDebt"); var tableEquityInput = document.getElementById("tableEquityInput"); var tableEquityWeight = document.getElementById("tableEquityWeight"); var tableEquityCost = document.getElementById("tableEquityCost"); var tableEquityAfterTaxCost = document.getElementById("tableEquityAfterTaxCost"); var tableDebtInput = document.getElementById("tableDebtInput"); var tableDebtWeight = document.getElementById("tableDebtWeight"); var tableDebtCost = document.getElementById("tableDebtCost"); var tableDebtAfterTaxCost = document.getElementById("tableDebtAfterTaxCost"); var tableTotalValue = document.getElementById("tableTotalValue"); var tableTotalAfterTaxCost = document.getElementById("tableTotalAfterTaxCost"); var resultsDiv = document.getElementById("results"); var waccChartCtx = null; var waccChartInstance = null; function formatPercentage(value, decimals = 2) { if (isNaN(value) || value === null) return "–.–%"; return (value * 100).toFixed(decimals) + "%"; } function formatCurrency(value) { if (isNaN(value) || value === null) return "–"; return value.toLocaleString('en-US', { style: 'currency', currency: 'USD' }); } function formatValue(value) { if (isNaN(value) || value === null) return "–"; return value.toLocaleString('en-US'); } function clearError(elementId) { var errorElement = document.getElementById(elementId); if (errorElement) { errorElement.style.display = 'none'; } } function showError(elementId, message) { var errorElement = document.getElementById(elementId); if (errorElement) { errorElement.textContent = message; errorElement.style.display = 'block'; } } function validateInputs() { var isValid = true; clearError("costOfEquityError"); var costOfEquity = parseFloat(costOfEquityInput.value); if (isNaN(costOfEquity) || costOfEquity < 0) { showError("costOfEquityError", "Please enter a valid non-negative number for Cost of Equity."); isValid = false; } clearError("equityMarketValueError"); var equityMarketValue = parseFloat(equityMarketValueInput.value); if (isNaN(equityMarketValue) || equityMarketValue <= 0) { showError("equityMarketValueError", "Please enter a valid positive number for Market Value of Equity."); isValid = false; } clearError("costOfDebtError"); var costOfDebt = parseFloat(costOfDebtInput.value); if (isNaN(costOfDebt) || costOfDebt < 0) { showError("costOfDebtError", "Please enter a valid non-negative number for Cost of Debt."); isValid = false; } clearError("debtMarketValueError"); var debtMarketValue = parseFloat(debtMarketValueInput.value); if (isNaN(debtMarketValue) || debtMarketValue < 0) { showError("debtMarketValueError", "Please enter a valid non-negative number for Market Value of Debt."); isValid = false; } clearError("corporateTaxRateError"); var corporateTaxRate = parseFloat(corporateTaxRateInput.value); if (isNaN(corporateTaxRate) || corporateTaxRate 100) { showError("corporateTaxRateError", "Please enter a valid tax rate between 0 and 100."); isValid = false; } return isValid; } function calculateWACC() { if (!validateInputs()) { resultsDiv.style.display = 'none'; return; } var costOfEquity = parseFloat(costOfEquityInput.value) / 100; var equityMarketValue = parseFloat(equityMarketValueInput.value); var costOfDebt = parseFloat(costOfDebtInput.value) / 100; var debtMarketValue = parseFloat(debtMarketValueInput.value); var corporateTaxRate = parseFloat(corporateTaxRateInput.value) / 100; var totalMarketValue = equityMarketValue + debtMarketValue; if (totalMarketValue === 0) { resultsDiv.style.display = 'none'; return; } var weightOfEquity = equityMarketValue / totalMarketValue; var weightOfDebt = debtMarketValue / totalMarketValue; var afterTaxCostOfDebt = costOfDebt * (1 – corporateTaxRate); var wacc = (weightOfEquity * costOfEquity) + (weightOfDebt * afterTaxCostOfDebt); finalWACCDisplay.textContent = formatPercentage(wacc); weightOfEquityDisplay.textContent = formatPercentage(weightOfEquity); weightOfDebtDisplay.textContent = formatPercentage(weightOfDebt); afterTaxCostOfDebtDisplay.textContent = formatPercentage(afterTaxCostOfDebt); resultsDiv.style.display = 'block'; updateTable(equityMarketValue, costOfEquity, weightOfEquity, debtMarketValue, costOfDebt, weightOfDebt, afterTaxCostOfDebt, totalMarketValue, wacc); updateChart(weightOfEquity, weightOfDebt, costOfEquity, afterTaxCostOfDebt); } function resetForm() { costOfEquityInput.value = "12.5"; equityMarketValueInput.value = "10000000"; costOfDebtInput.value = "5.5"; debtMarketValueInput.value = "5000000"; corporateTaxRateInput.value = "21"; clearError("costOfEquityError"); clearError("equityMarketValueError"); clearError("costOfDebtError"); clearError("debtMarketValueError"); clearError("corporateTaxRateError"); resultsDiv.style.display = 'none'; if (waccChartInstance) { waccChartInstance.destroy(); waccChartInstance = null; } initializeChart(); } function updateTable(E, Ke, We, D, Kd, Wd, AfterTaxKd, V, WACC) { tableEquityInput.textContent = formatCurrency(E); tableEquityWeight.textContent = formatPercentage(We); tableEquityCost.textContent = formatPercentage(Ke); tableEquityAfterTaxCost.textContent = formatPercentage(Ke); // Equity cost isn't taxed tableDebtInput.textContent = formatCurrency(D); tableDebtWeight.textContent = formatPercentage(Wd); tableDebtCost.textContent = formatPercentage(Kd); tableDebtAfterTaxCost.textContent = formatPercentage(AfterTaxKd); tableTotalValue.textContent = formatCurrency(V); tableTotalAfterTaxCost.textContent = formatPercentage(WACC); } function updateChart(weightEquity, weightDebt, costEquity, afterTaxCostDebt) { if (!waccChartCtx) { var canvas = document.getElementById('waccChart'); if (!canvas) return; waccChartCtx = canvas.getContext('2d'); } var chartData = { labels: ['Equity', 'Debt'], datasets: [{ label: 'Weight in Capital Structure', data: [weightEquity, weightDebt], backgroundColor: [ 'rgba(0, 74, 153, 0.6)', // Primary blue for Equity 'rgba(40, 167, 69, 0.6)' // Success green for Debt ], borderColor: [ 'rgba(0, 74, 153, 1)', 'rgba(40, 167, 69, 1)' ], borderWidth: 1, order: 2 // Render weights behind costs }, { label: 'Cost Component (After-Tax)', data: [costEquity, afterTaxCostDebt], backgroundColor: [ 'rgba(0, 74, 153, 0.8)', // Slightly darker blue for Equity cost 'rgba(40, 167, 69, 0.8)' // Slightly darker green for Debt cost ], borderColor: [ 'rgba(0, 74, 153, 1)', 'rgba(40, 167, 69, 1)' ], borderWidth: 1, order: 1 // Render costs on top }] }; var chartOptions = { responsive: true, maintainAspectRatio: true, plugins: { legend: { position: 'top', }, title: { display: true, text: 'Capital Structure and Cost Breakdown', font: { size: 16 } }, tooltip: { callbacks: { label: function(context) { var label = context.dataset.label || "; if (label) { label += ': '; } if (context.dataset.label === 'Weight in Capital Structure') { label += formatPercentage(context.raw); } else { label += formatPercentage(context.raw); } return label; } } } }, scales: { y: { ticks: { callback: function(value) { return formatPercentage(value); } } } } }; // Destroy previous chart instance if it exists if (waccChartInstance) { waccChartInstance.destroy(); } // Create new chart instance waccChartInstance = new Chart(waccChartCtx, { type: 'bar', // Use bar chart for better comparison data: chartData, options: chartOptions }); } function copyResults() { var finalWACC = finalWACCDisplay.textContent; var weightOfEquity = weightOfEquityDisplay.textContent; var weightOfDebt = weightOfDebtDisplay.textContent; var afterTaxCostOfDebt = afterTaxCostOfDebtDisplay.textContent; var equityInputVal = formatCurrency(parseFloat(equityMarketValueInput.value)); var equityCostVal = formatPercentage(parseFloat(costOfEquityInput.value)/100); var debtInputVal = formatCurrency(parseFloat(debtMarketValueInput.value)); var debtCostVal = formatPercentage(parseFloat(costOfDebtInput.value)/100); var taxRateVal = formatPercentage(parseFloat(corporateTaxRateInput.value)/100); var textToCopy = "— WACC Calculation Results —\n\n"; textToCopy += "Weighted Average Cost of Capital (WACC): " + finalWACC + "\n"; textToCopy += "Weight of Equity (We): " + weightOfEquity + "\n"; textToCopy += "Weight of Debt (Wd): " + weightOfDebt + "\n"; textToCopy += "After-Tax Cost of Debt: " + afterTaxCostOfDebt + "\n\n"; textToCopy += "— Key Assumptions —\n"; textToCopy += "Cost of Equity (Ke): " + equityCostVal + "\n"; textToCopy += "Market Value of Equity (E): " + equityInputVal + "\n"; textToCopy += "Cost of Debt (Kd): " + debtCostVal + "\n"; textToCopy += "Market Value of Debt (D): " + debtInputVal + "\n"; textToCopy += "Corporate Tax Rate (t): " + taxRateVal + "\n\n"; textToCopy += "Formula Used: WACC = (E/V) * Ke + (D/V) * Kd * (1 – t)\n"; navigator.clipboard.writeText(textToCopy).then(function() { var copyButton = document.querySelector("#results .btn-success"); var originalText = copyButton.textContent; copyButton.textContent = "Copied!"; copyButton.style.backgroundColor = "#28a745"; // Green setTimeout(function() { copyButton.textContent = originalText; copyButton.style.backgroundColor = "#28a745"; // Reset to original success color }, 2000); }).catch(function(err) { console.error("Failed to copy text: ", err); alert("Failed to copy results. Please copy manually."); }); } // Chart.js initialization (must be included for the chart to work) // Assuming Chart.js library is available globally or included via CDN. // If not, you'd need to add: // or include the Chart.js library directly within the HTML file's or before the script tag. function initializeChart() { if (typeof Chart === 'undefined') { console.error("Chart.js library is not loaded. Please include Chart.js."); return; } var canvas = document.getElementById('waccChart'); if (canvas) { waccChartCtx = canvas.getContext('2d'); // Initialize with default/placeholder values if needed, or wait for first calculation updateChart(0, 0, 0, 0); // Initial call to set up structure } } // Add event listeners for real-time updates if desired, or rely on button click costOfEquityInput.addEventListener('input', calculateWACC); equityMarketValueInput.addEventListener('input', calculateWACC); costOfDebtInput.addEventListener('input', calculateWACC); debtMarketValueInput.addEventListener('input', calculateWACC); corporateTaxRateInput.addEventListener('input', calculateWACC); // Initial setup document.addEventListener('DOMContentLoaded', function() { resetForm(); // Set default values and clear results initializeChart(); // Initialize chart structure });

Leave a Comment