Calculating Weighted Average Cost of Capital

Weighted Average Cost of Capital (WACC) Calculator :root { –primary-color: #004a99; –success-color: #28a745; –background-color: #f8f9fa; –text-color: #333; –border-color: #dee2e6; –card-background: #ffffff; –shadow-color: 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); line-height: 1.6; margin: 0; padding: 20px; display: flex; flex-direction: column; align-items: center; } .container { max-width: 1000px; width: 100%; margin: 0 auto; background-color: var(–card-background); padding: 30px; border-radius: 8px; box-shadow: 0 4px 15px var(–shadow-color); margin-bottom: 30px; } header { text-align: center; margin-bottom: 30px; padding-bottom: 20px; border-bottom: 1px solid var(–border-color); } h1 { color: var(–primary-color); margin-bottom: 10px; font-size: 2.5em; } h2, h3 { color: var(–primary-color); margin-top: 25px; margin-bottom: 15px; } .loan-calc-container { margin-bottom: 30px; padding: 25px; border: 1px solid var(–border-color); border-radius: 6px; background-color: #fff; } .input-group { margin-bottom: 20px; text-align: left; } .input-group label { display: block; margin-bottom: 8px; font-weight: bold; color: #555; } .input-group input[type="number"], .input-group select { width: calc(100% – 20px); padding: 12px; border: 1px solid var(–border-color); border-radius: 4px; font-size: 1em; box-sizing: border-box; transition: border-color 0.3s ease; } .input-group input[type="number"]:focus, .input-group select:focus { border-color: var(–primary-color); outline: none; } .input-group .helper-text { font-size: 0.85em; color: #6c757d; margin-top: 5px; display: block; } .error-message { color: red; font-size: 0.85em; margin-top: 5px; display: none; /* Hidden by default */ } .button-group { text-align: center; margin-top: 30px; display: flex; justify-content: center; gap: 15px; flex-wrap: wrap; } button { padding: 12px 25px; border: none; border-radius: 5px; cursor: pointer; font-size: 1em; font-weight: bold; transition: background-color 0.3s ease, transform 0.2s ease; margin-top: 10px; } button.primary { background-color: var(–primary-color); color: white; } button.primary:hover { background-color: #003366; transform: translateY(-2px); } button.secondary { background-color: #6c757d; color: white; } button.secondary:hover { background-color: #5a6268; transform: translateY(-2px); } #results { margin-top: 30px; padding: 25px; border: 1px solid var(–border-color); border-radius: 6px; background-color: #eef5ff; /* Light blue for distinction */ text-align: center; } #results h3 { margin-top: 0; color: var(–primary-color); font-size: 1.8em; } .result-item { margin-bottom: 15px; } .result-item strong { display: block; font-size: 1.2em; color: #444; } .result-item span { display: block; font-size: 1.8em; font-weight: bold; color: var(–primary-color); } .intermediate-results { display: flex; justify-content: space-around; flex-wrap: wrap; margin-top: 20px; gap: 20px; } .intermediate-item { text-align: center; padding: 15px; border: 1px dashed var(–border-color); border-radius: 5px; background-color: #f0f0f0; flex: 1; min-width: 150px; } .intermediate-item strong { display: block; font-size: 1.1em; color: #555; } .intermediate-item span { display: block; font-size: 1.4em; font-weight: bold; color: var(–primary-color); } .formula-explanation { font-size: 0.95em; color: #555; margin-top: 20px; padding: 15px; background-color: #fdfdfd; border-left: 4px solid var(–primary-color); text-align: left; } table { width: 100%; border-collapse: collapse; margin-top: 25px; box-shadow: 0 2px 8px var(–shadow-color); } caption { font-size: 1.2em; font-weight: bold; color: var(–primary-color); margin-bottom: 15px; caption-side: top; text-align: left; } th, td { padding: 12px 15px; border: 1px solid var(–border-color); text-align: right; } th { background-color: #e9ecef; color: #333; font-weight: bold; text-align: center; } td { background-color: #ffffff; } tr:nth-child(even) td { background-color: #f8f9fa; } #chartContainer { width: 100%; max-width: 700px; margin: 30px auto; padding: 20px; background-color: var(–card-background); border-radius: 8px; box-shadow: 0 4px 15px var(–shadow-color); text-align: center; } #chartContainer canvas { max-width: 100%; height: auto; } .chart-legend { margin-top: 15px; font-size: 0.9em; color: #6c757d; } .chart-legend span { margin: 0 10px; display: inline-block; } .chart-legend .equity-color { display: inline-block; width: 12px; height: 12px; background-color: #1f77b4; /* Default color for equity */ margin-right: 5px; vertical-align: middle; } .chart-legend .debt-color { display: inline-block; width: 12px; height: 12px; background-color: #ff7f0e; /* Default color for debt */ margin-right: 5px; vertical-align: middle; } .chart-legend .preferred-color { display: inline-block; width: 12px; height: 12px; background-color: #2ca02c; /* Default color for preferred stock */ margin-right: 5px; vertical-align: middle; } .section { margin-bottom: 40px; padding: 30px; background-color: var(–card-background); border-radius: 8px; box-shadow: 0 4px 15px var(–shadow-color); } .section h2 { text-align: center; margin-bottom: 20px; color: var(–primary-color); font-size: 2em; } .section h3 { text-align: left; color: var(–primary-color); font-size: 1.6em; margin-top: 30px; } .section p { margin-bottom: 15px; text-align: justify; } .section ul, .section ol { margin-left: 20px; margin-bottom: 15px; padding-left: 10px; } .section li { margin-bottom: 8px; } a { color: var(–primary-color); text-decoration: none; transition: color 0.3s ease; } a:hover { color: #003366; text-decoration: underline; } .internal-link-list a { font-weight: bold; } @media (max-width: 768px) { body { padding: 15px; } .container { padding: 20px; } h1 { font-size: 2em; } h2 { font-size: 1.6em; } h3 { font-size: 1.3em; } button { width: 100%; } .intermediate-results { flex-direction: column; } }

Weighted Average Cost of Capital (WACC) Calculator

Calculate your company's WACC to understand the blended cost of its financing sources.

WACC Input Parameters

Enter the total market value of the company's outstanding equity. (e.g., 100,000,000)
Enter the required rate of return for equity investors (%). (e.g., 12 for 12%)
Enter the total market value of the company's debt. (e.g., 50,000,000)
Enter the interest rate on the company's debt (%). (e.g., 6 for 6%)
Enter the company's marginal corporate tax rate (%). (e.g., 25 for 25%)

WACC Calculation Results

Total Capital (V)
Weight of Equity (We)
Weight of Debt (Wd)
After-Tax Cost of Debt
Weighted Average Cost of Capital (WACC)

Formula Used: WACC = (E/V * Re) + (D/V * Rd * (1 – Tc))
Where: E = Market Value of Equity, D = Market Value of Debt, V = E + D, Re = Cost of Equity, Rd = Cost of Debt, Tc = Corporate Tax Rate.

Equity Weight & Cost Debt Weight & After-Tax Cost

WACC Component Contribution vs. Total Capital

WACC Components Breakdown
Component Market Value Weight Cost (Pre-Tax/Required) Cost (After-Tax / Effective) Weighted Cost Contribution
Equity
Debt
Total 100.00%

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 across all sources, including common stock, preferred stock, bonds, and other forms of debt. Essentially, WACC signifies the average rate of return a company expects to pay to its investors (both debt and equity holders) to finance its assets. It's a vital tool for financial analysis, investment appraisal, and corporate valuation. Understanding your company's WACC helps in making informed decisions about which projects to undertake and how to finance them.

Who Should Use It: WACC is primarily used by corporate finance professionals, financial analysts, investors, and business owners. It's indispensable for:

  • Evaluating potential investment projects: Projects should ideally have a return exceeding the WACC.
  • Valuing a company: WACC is often used as the discount rate in discounted cash flow (DCF) analysis.
  • Assessing financial strategy: Understanding the cost of different financing mixes.
  • Comparing investment opportunities: Both within the company and against external benchmarks.

Common Misconceptions:

  • WACC is static: WACC fluctuates with market conditions, interest rates, company risk profile, and capital structure changes.
  • WACC is only about debt: It equally considers the cost of equity, which is often the largest component and typically more expensive than debt.
  • WACC is the target return: While it sets a benchmark, successful projects should aim for returns significantly higher than WACC to create shareholder value.
  • Using book values instead of market values: WACC should always be calculated using the current market values of debt and equity for accurate representation.

WACC Formula and Mathematical Explanation

The Weighted Average Cost of Capital (WACC) formula is designed to calculate the overall cost of a company's financing. It considers the proportion (weight) of each financing source (debt and equity) and their respective costs, adjusted for tax benefits where applicable.

The standard formula for WACC is:

WACC = ( E / V * Re ) + ( D / V * Rd * (1 – Tc) )

Let's break down each component:

  • E (Market Value of Equity): This is the total market value of a company's outstanding shares. It's calculated by multiplying the current share price by the number of outstanding shares. This represents the equity financing portion.
  • D (Market Value of Debt): This is the total market value of all the company's interest-bearing debt (loans, bonds, etc.). For publicly traded debt, this is the market price. For non-traded debt, book value is often used as a proxy if market value is unavailable.
  • V (Total Market Value of Capital): This is the sum of the market value of equity and the market value of debt. V = E + D. It represents the company's total financing from these two primary sources.
  • 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), which considers the risk-free rate, the equity market's expected return, and the company's beta (a measure of its volatility relative to the market).
  • Rd (Cost of Debt): This is the effective interest rate a company pays on its debt. It can be derived from the yield-to-maturity on its outstanding bonds or the interest rates on its loans.
  • Tc (Corporate Tax Rate): This is the company's marginal corporate tax rate. Interest payments on debt are usually tax-deductible, creating a "tax shield" that reduces the effective cost of debt.
  • E/V (Weight of Equity): The proportion of the company's total capital that is financed by equity.
  • D/V (Weight of Debt): The proportion of the company's total capital that is financed by debt.
  • Rd * (1 – Tc) (After-Tax Cost of Debt): This adjusts the cost of debt to reflect the tax savings resulting from interest deductibility.

By weighting the cost of each capital component by its proportion in the company's capital structure and accounting for the tax deductibility of interest, WACC provides a comprehensive measure of the company's overall cost of funding.

Variables Table for WACC Calculation

WACC Formula Variables Explained
Variable Meaning Unit Typical Range / Notes
E Market Value of Equity Currency (e.g., USD) Positive value, depends on company size and stock price.
D Market Value of Debt Currency (e.g., USD) Positive value, depends on debt levels. Book value often used if market value unavailable.
V Total Market Value of Capital Currency (e.g., USD) V = E + D. Positive value.
Re Cost of Equity Percentage (%) Typically 8% – 20%+. Higher for riskier companies. Estimated via CAPM.
Rd Cost of Debt Percentage (%) Typically 3% – 10%+. Based on credit rating and market interest rates.
Tc Corporate Tax Rate Percentage (%) Usually between 15% – 35%. Varies by jurisdiction.
E/V Weight of Equity Proportion / Percentage (%) Between 0% and 100%. Calculated from market values.
D/V Weight of Debt Proportion / Percentage (%) Between 0% and 100%. Calculated from market values.
WACC Weighted Average Cost of Capital Percentage (%) The final calculated rate, generally between Cost of Debt and Cost of Equity.

Practical Examples (Real-World Use Cases)

Understanding WACC isn't just theoretical; it has direct implications for business strategy and investment decisions. Here are a couple of examples illustrating its application:

Example 1: Tech Startup Evaluation

A rapidly growing tech company, "Innovate Solutions," is considering a new R&D project to develop a groundbreaking AI platform. The project requires significant upfront investment. To assess its viability, the management needs to know the company's WACC.

Inputs:
  • Market Value of Equity (E): $200,000,000
  • Cost of Equity (Re): 18% (Reflects high growth and inherent risk)
  • Market Value of Debt (D): $80,000,000 (Senior notes with a 7% coupon)
  • Cost of Debt (Rd): 7%
  • Corporate Tax Rate (Tc): 21%
Calculation:
  • Total Capital (V) = E + D = $200M + $80M = $280,000,000
  • Weight of Equity (We) = E / V = $200M / $280M = 0.7143 or 71.43%
  • Weight of Debt (Wd) = D / V = $80M / $280M = 0.2857 or 28.57%
  • After-Tax Cost of Debt = Rd * (1 – Tc) = 7% * (1 – 0.21) = 7% * 0.79 = 5.53%
  • WACC = (We * Re) + (Wd * Rd * (1 – Tc))
  • WACC = (0.7143 * 18%) + (0.2857 * 5.53%)
  • WACC = 12.86% + 1.58% = 14.44%
Interpretation: Innovate Solutions has a WACC of 14.44%. The new AI platform project must be expected to generate returns greater than 14.44% annually to be considered value-adding for shareholders. The high WACC reflects the significant equity component and the perceived risk of the company. This calculation is crucial for the financial strategy surrounding new investments.

Example 2: Mature Manufacturing Firm

"SolidBuild Manufacturing," a stable, established company, is planning to upgrade its production facilities. They need to determine their WACC for capital budgeting.

Inputs:
  • Market Value of Equity (E): $500,000,000
  • Cost of Equity (Re): 10% (Lower due to stability and lower risk)
  • Market Value of Debt (D): $500,000,000 (Mix of long-term bonds and bank loans at 5%)
  • Cost of Debt (Rd): 5%
  • Corporate Tax Rate (Tc): 30%
Calculation:
  • Total Capital (V) = E + D = $500M + $500M = $1,000,000,000
  • Weight of Equity (We) = E / V = $500M / $1000M = 0.50 or 50%
  • Weight of Debt (Wd) = D / V = $500M / $1000M = 0.50 or 50%
  • After-Tax Cost of Debt = Rd * (1 – Tc) = 5% * (1 – 0.30) = 5% * 0.70 = 3.50%
  • WACC = (We * Re) + (Wd * Rd * (1 – Tc))
  • WACC = (0.50 * 10%) + (0.50 * 3.50%)
  • WACC = 5.00% + 1.75% = 6.75%
Interpretation: SolidBuild Manufacturing has a WACC of 6.75%. This lower WACC compared to the tech startup is due to its stable operations, lower perceived risk (lower Re), and a balanced capital structure with significant debt (which is cheaper after tax). The facility upgrade project should aim for returns above 6.75%. This WACC is critical for their capital budgeting decisions.

How to Use This WACC Calculator

Our WACC calculator is designed for simplicity and accuracy. Follow these steps to calculate your company's Weighted Average Cost of Capital:

  1. Gather Your Financial Data: Before using the calculator, collect the following information:
    • The current total market value of your company's equity (Market Capitalization).
    • The required rate of return for your equity investors (Cost of Equity). This is often calculated using CAPM.
    • The current market value of your company's total debt (including bonds, loans, etc.). If market value isn't readily available for all debt instruments, use the book value as a reasonable proxy.
    • The average interest rate your company pays on its debt (Cost of Debt).
    • Your company's corporate tax rate.
  2. Input Values: Enter each piece of data into the corresponding field in the calculator. Ensure you enter percentages as whole numbers (e.g., 12 for 12%) and monetary values without commas or currency symbols.
    • Market Value of Equity (E)
    • Cost of Equity (Re) %
    • Market Value of Debt (D)
    • Cost of Debt (Rd) %
    • Corporate Tax Rate (Tc) %
    Pay attention to the helper text for guidance on the format expected for each input.
  3. Calculate WACC: Click the "Calculate WACC" button. The calculator will process your inputs instantly.
  4. Review the Results:
    • Primary Result (WACC): The main output shows your company's Weighted Average Cost of Capital as a percentage. This is the minimum rate of return your company should aim to earn on its investments to satisfy its investors.
    • Intermediate Values: You'll see the calculated Total Capital (V), Weight of Equity (We), Weight of Debt (Wd), and the After-Tax Cost of Debt. These provide insight into the composition of your company's financing structure and the effective cost of debt.
    • Table Breakdown: A detailed table breaks down the contribution of equity and debt to the WACC, showing their market values, weights, costs, and weighted contributions.
    • Chart Visualization: The chart visually represents the proportion of equity and debt in your capital structure and their respective costs, offering an intuitive understanding of WACC components.
  5. Interpret and Decide: Use the calculated WACC as a benchmark.
    • Investment Appraisal: Compare the expected returns of new projects against your WACC. Projects with expected returns significantly higher than WACC are generally favorable.
    • Financial Strategy: Analyze how changes in your capital structure (e.g., taking on more debt or issuing more equity) might impact your WACC. This can inform your financial strategy.
    • Valuation: If performing a DCF analysis, your WACC serves as the discount rate to determine the present value of future cash flows.
  6. Reset or Copy:
    • Click "Reset" to clear all fields and return to default values.
    • Click "Copy Results" to copy the main WACC value, intermediate calculations, and key assumptions to your clipboard for use elsewhere.

By accurately calculating and understanding your WACC, you empower your business to make more strategic financial decisions, ultimately aiming to maximize shareholder value.

Key Factors That Affect WACC Results

Several dynamic factors influence a company's Weighted Average Cost of Capital (WACC). Understanding these elements is crucial for accurate calculation and strategic financial management.

  • Capital Structure Mix (Weights of Debt and Equity): This is perhaps the most direct influence. As the proportion of debt (D/V) increases, WACC often decreases, especially if debt is cheaper than equity and tax benefits are significant. Conversely, a heavier reliance on equity (E/V) typically raises WACC. Companies must balance the benefits of cheaper debt against the increased financial risk. This impacts the financial strategy significantly.
  • Cost of Equity (Re): The required return by equity holders is a major driver. Factors like market risk premium, the company's beta (systematic risk), company-specific risks, and investor sentiment directly impact Re. Higher perceived risk leads to a higher Re and thus a higher WACC. Estimating Re accurately is key for any valuation.
  • Cost of Debt (Rd): The interest rate the company pays on its borrowings is critical. This is influenced by prevailing market interest rates, the company's credit rating (which reflects its default risk), and the type and maturity of the debt. Higher interest rates on new debt or a deteriorating credit rating will increase Rd and WACC.
  • Corporate Tax Rate (Tc): The government's corporate tax rate provides a "tax shield" for debt financing because interest payments are tax-deductible. A higher tax rate makes the after-tax cost of debt lower (Rd * (1 – Tc)), thus reducing WACC. Changes in tax policy can directly alter a company's WACC.
  • Overall Market Interest Rates: Broad economic conditions heavily influence interest rates. When central banks raise benchmark rates, the cost of debt (Rd) generally increases for all companies. This, in turn, can indirectly affect the cost of equity (Re) as investors may demand higher returns across the board. Fluctuations in market rates affect the entire discount rate structure.
  • Company-Specific Risk Profile: Beyond market-wide factors, the unique risks associated with a company's industry, operations, management quality, and competitive landscape impact both Re and Rd. Volatile industries or companies with weak competitive positions will likely have higher costs of capital. This is a core consideration in investment appraisal.
  • Economic Conditions and Outlook: Macroeconomic factors like inflation, economic growth, and geopolitical stability affect investor confidence and risk premiums. During economic downturns, investors might demand higher risk premiums, increasing Re and potentially Rd, thereby raising WACC.

Frequently Asked Questions (FAQ)

Q1: What is the ideal WACC?

There is no single "ideal" WACC. The "best" WACC is the one that accurately reflects your company's specific risk and capital structure in the current market environment. A lower WACC is generally desirable as it means a lower cost of funding, potentially allowing more profitable investments. However, a very low WACC achieved by taking on excessive debt can signal high financial risk.

Q2: Should I use book value or market value for debt?

Ideally, you should use the market value of debt. This reflects the current cost at which the company could raise debt or refinance its existing obligations. If market values for all debt instruments are not readily available or practical to obtain (e.g., private loans), the book value is often used as a reasonable proxy, especially for short-term or floating-rate debt.

Q3: How is the Cost of Equity (Re) typically calculated?

The most common method is the Capital Asset Pricing Model (CAPM): Re = Rf + β * (Rm – Rf). Where Rf is the risk-free rate (e.g., yield on long-term government bonds), β (beta) is the stock's volatility relative to the market, and (Rm – Rf) is the equity market risk premium. Other methods exist, like the Dividend Discount Model, but CAPM is widely used for WACC calculations.

Q4: Can WACC be negative?

In standard financial theory, WACC cannot be negative. The cost of equity (Re) is always positive, and while the after-tax cost of debt can be very low, it's typically also positive. A negative WACC would imply the company is being paid to raise capital, which is not economically feasible.

Q5: How often should WACC be recalculated?

WACC should be recalculated whenever there are significant changes in the key inputs. This includes changes in market interest rates, the company's credit rating, its stock price (affecting equity value and potentially beta), its capital structure (e.g., issuing new debt or equity), or the corporate tax rate. Annually is a common practice for stable companies, while more frequent updates might be needed for companies undergoing significant changes or operating in volatile markets.

Q6: What is the difference between Cost of Debt and After-Tax Cost of Debt?

The Cost of Debt (Rd) is the nominal interest rate the company pays on its borrowings. The After-Tax Cost of Debt is Rd adjusted for the tax savings that result from deducting interest payments. Since interest expense reduces taxable income, the effective cost of debt to the company is lower than the stated interest rate. This is calculated as Rd * (1 – Tc).

Q7: How does WACC relate to a company's valuation?

WACC is commonly used as the discount rate in Discounted Cash Flow (DCF) valuation models. It represents the opportunity cost of capital. By discounting projected future free cash flows back to their present value using the WACC, analysts can estimate the intrinsic value of a company or project. A higher WACC results in a lower present value, and vice versa.

Q8: Can preferred stock be included in WACC?

Yes, if a company has preferred stock, it should be included as a separate component in the WACC calculation. The formula would then be: WACC = (E/V * Re) + (D/V * Rd * (1 – Tc)) + (P/V * Rp), where P is the market value of preferred stock, V is the total capital (E + D + P), and Rp is the cost of preferred stock (typically the dividend yield). Our calculator simplifies this by focusing on the two primary components, equity and debt.

Related Tools and Internal Resources

© 2023 Your Company. All rights reserved.

var ctx = null; var myChart = null; function validateInput(id, errorId, minValue = null, maxValue = null) { var input = document.getElementById(id); var errorSpan = document.getElementById(errorId); var value = parseFloat(input.value); var isValid = true; errorSpan.style.display = 'none'; // Hide error by default if (input.value === "") { errorSpan.textContent = "This field cannot be empty."; errorSpan.style.display = 'block'; isValid = false; } else if (isNaN(value)) { errorSpan.textContent = "Please enter a valid number."; errorSpan.style.display = 'block'; isValid = false; } else { if (minValue !== null && value maxValue) { errorSpan.textContent = "Value out of range."; errorSpan.style.display = 'block'; isValid = false; } } return isValid; } function formatCurrency(amount) { if (isNaN(amount) || !isFinite(amount)) return "–"; return '$' + amount.toFixed(2).replace(/\d(?=(\d{3})+\.)/g, '$&,'); } function formatPercentage(percent) { if (isNaN(percent) || !isFinite(percent)) return "–"; return percent.toFixed(2) + '%'; } function calculateWACC() { var marketValueEquity = parseFloat(document.getElementById('marketValueEquity').value); var costOfEquity = parseFloat(document.getElementById('costOfEquity').value); var marketValueDebt = parseFloat(document.getElementById('marketValueDebt').value); var costOfDebt = parseFloat(document.getElementById('costOfDebt').value); var corporateTaxRate = parseFloat(document.getElementById('corporateTaxRate').value); var allValid = true; allValid &= validateInput('marketValueEquity', 'errorMarketValueEquity', 0); allValid &= validateInput('costOfEquity', 'errorCostOfEquity', 0, 100); allValid &= validateInput('marketValueDebt', 'errorMarketValueDebt', 0); allValid &= validateInput('costOfDebt', 'errorCostOfDebt', 0, 100); allValid &= validateInput('corporateTaxRate', 'errorCorporateTaxRate', 0, 100); if (!allValid) { document.getElementById('waccResult').textContent = "Invalid Input"; resetTable(); return; } var totalCapital = marketValueEquity + marketValueDebt; var weightEquity = (totalCapital === 0) ? 0 : marketValueEquity / totalCapital; var weightDebt = (totalCapital === 0) ? 0 : marketValueDebt / totalCapital; var afterTaxCostOfDebt = costOfDebt / 100 * (1 – corporateTaxRate / 100); var wacc = (weightEquity * (costOfEquity / 100)) + (weightDebt * afterTaxCostOfDebt); document.getElementById('totalCapital').textContent = formatCurrency(totalCapital); document.getElementById('weightEquity').textContent = formatPercentage(weightEquity * 100); document.getElementById('weightDebt').textContent = formatPercentage(weightDebt * 100); document.getElementById('afterTaxCostOfDebt').textContent = formatPercentage(afterTaxCostOfDebt * 100); document.getElementById('waccResult').textContent = formatPercentage(wacc * 100); updateTable(marketValueEquity, costOfEquity, marketValueDebt, costOfDebt, corporateTaxRate, totalCapital, weightEquity, weightDebt, afterTaxCostOfDebt, wacc); updateChart(weightEquity, costOfEquity, weightDebt, afterTaxCostOfDebt); } function resetTable() { document.getElementById('tableValEquity').textContent = "–"; document.getElementById('tableWeightEquity').textContent = "–"; document.getElementById('tableCostEquity').textContent = "–"; document.getElementById('tableEffectiveCostEquity').textContent = "–"; document.getElementById('tableWeightedCostEquity').textContent = "–"; document.getElementById('tableValDebt').textContent = "–"; document.getElementById('tableWeightDebt').textContent = "–"; document.getElementById('tableCostDebt').textContent = "–"; document.getElementById('tableEffectiveCostDebt').textContent = "–"; document.getElementById('tableWeightedCostDebt').textContent = "–"; document.getElementById('tableTotalValue').textContent = "–"; document.getElementById('tableTotalWeightedCost').textContent = "–"; } function updateTable(E, Re, D, Rd, Tc, V, We, Wd, AT_Rd, WACC) { var effectiveCostEquity = Re; // Cost of Equity is already the required return var weightedCostEquity = We * (effectiveCostEquity / 100); var effectiveCostDebt = AT_Rd * 100; // Already calculated as after-tax % var weightedCostDebt = Wd * AT_Rd; document.getElementById('tableValEquity').textContent = formatCurrency(E); document.getElementById('tableWeightEquity').textContent = formatPercentage(We * 100); document.getElementById('tableCostEquity').textContent = formatPercentage(Re); document.getElementById('tableEffectiveCostEquity').textContent = formatPercentage(effectiveCostEquity); // Same as cost for equity document.getElementById('tableWeightedCostEquity').textContent = formatPercentage(weightedCostEquity * 100); document.getElementById('tableValDebt').textContent = formatCurrency(D); document.getElementById('tableWeightDebt').textContent = formatPercentage(Wd * 100); document.getElementById('tableCostDebt').textContent = formatPercentage(Rd); document.getElementById('tableEffectiveCostDebt').textContent = formatPercentage(effectiveCostDebt); // This is the after-tax cost % document.getElementById('tableWeightedCostDebt').textContent = formatPercentage(weightedCostDebt * 100); document.getElementById('tableTotalValue').textContent = formatCurrency(V); document.getElementById('tableTotalWeightedCost').textContent = formatPercentage(WACC * 100); } function updateChart(weightEquity, costOfEquity, weightDebt, afterTaxCostOfDebt) { if (!ctx) { var canvas = document.getElementById('waccChart'); ctx = canvas.getContext('2d'); } // Chart data var equityContribution = weightEquity * (costOfEquity / 100); var debtContribution = weightDebt * afterTaxCostOfDebt; var labels = ['Equity', 'Debt']; var data = [equityContribution, debtContribution]; var colors = ['#1f77b4', '#ff7f0e']; // Default chart colors if (myChart) { myChart.destroy(); } myChart = new Chart(ctx, { type: 'bar', data: { labels: labels, datasets: [{ label: 'Weighted Cost Contribution', data: data, backgroundColor: colors, borderColor: colors, borderWidth: 1 }] }, options: { responsive: true, maintainAspectRatio: true, scales: { y: { beginAtZero: true, ticks: { callback: function(value) { return (value * 100).toFixed(1) + '%'; } }, title: { display: true, text: 'Contribution to WACC (%)' } }, x: { title: { display: true, text: 'Capital Component' } } }, plugins: { tooltip: { callbacks: { label: function(context) { var label = context.dataset.label || "; if (label) { label += ': '; } if (context.parsed.y !== null) { label += (context.parsed.y * 100).toFixed(2) + '%'; } return label; } } }, legend: { display: false // Hide default legend, use custom one } } } }); } function resetCalculator() { document.getElementById('marketValueEquity').value = "100000000"; document.getElementById('costOfEquity').value = "12"; document.getElementById('marketValueDebt').value = "50000000"; document.getElementById('costOfDebt').value = "6"; document.getElementById('corporateTaxRate').value = "25"; document.getElementById('totalCapital').textContent = "–"; document.getElementById('weightEquity').textContent = "–"; document.getElementById('weightDebt').textContent = "–"; document.getElementById('afterTaxCostOfDebt').textContent = "–"; document.getElementById('waccResult').textContent = "–"; resetTable(); // Clear chart if exists if (myChart) { myChart.destroy(); myChart = null; } // Reset canvas context for potential redraw var canvas = document.getElementById('waccChart'); if(canvas) { ctx = canvas.getContext('2d'); ctx.clearRect(0, 0, canvas.width, canvas.height); } // Clear error messages var errors = document.querySelectorAll('.error-message'); for (var i = 0; i < errors.length; i++) { errors[i].style.display = 'none'; errors[i].textContent = ''; } } function copyResults() { var waccResult = document.getElementById('waccResult').textContent; var weightEquity = document.getElementById('weightEquity').textContent; var weightDebt = document.getElementById('weightDebt').textContent; var afterTaxCostOfDebt = document.getElementById('afterTaxCostOfDebt').textContent; var totalCapital = document.getElementById('totalCapital').textContent; var assumptions = "Assumptions:\n"; assumptions += "Market Value of Equity (E): " + formatCurrency(parseFloat(document.getElementById('marketValueEquity').value)) + "\n"; assumptions += "Cost of Equity (Re): " + formatPercentage(parseFloat(document.getElementById('costOfEquity').value) / 100) + "\n"; assumptions += "Market Value of Debt (D): " + formatCurrency(parseFloat(document.getElementById('marketValueDebt').value)) + "\n"; assumptions += "Cost of Debt (Rd): " + formatPercentage(parseFloat(document.getElementById('costOfDebt').value) / 100) + "\n"; assumptions += "Corporate Tax Rate (Tc): " + formatPercentage(parseFloat(document.getElementById('corporateTaxRate').value) / 100) + "\n"; var resultsText = "WACC Calculation Results:\n\n"; resultsText += "WACC: " + waccResult + "\n"; resultsText += "Weight of Equity (We): " + weightEquity + "\n"; resultsText += "Weight of Debt (Wd): " + weightDebt + "\n"; resultsText += "After-Tax Cost of Debt: " + afterTaxCostOfDebt + "\n"; resultsText += "Total Capital (V): " + totalCapital + "\n\n"; resultsText += assumptions; navigator.clipboard.writeText(resultsText).then(function() { alert("Results copied to clipboard!"); }).catch(function(err) { console.error("Failed to copy results: ", err); alert("Failed to copy results. Please copy manually."); }); } // Initial calculation on page load if default values are set document.addEventListener('DOMContentLoaded', function() { // Load Chart.js library dynamically if not already present (e.g., from a CDN) var script = document.createElement('script'); script.src = 'https://cdn.jsdelivr.net/npm/chart.js@3.9.1/dist/chart.min.js'; // Using a specific version script.onload = function() { console.log("Chart.js loaded"); calculateWACC(); // Perform initial calculation }; script.onerror = function() { console.error("Failed to load Chart.js library."); alert("Chart functionality requires Chart.js. Please ensure you have an internet connection or the library is available."); }; document.head.appendChild(script); // Add event listeners for input changes to update in real-time var inputs = document.querySelectorAll('.loan-calc-container input[type="number"], .loan-calc-container select'); for (var i = 0; i < inputs.length; i++) { inputs[i].addEventListener('input', calculateWACC); } });

Leave a Comment