Introduction
The WACC (Weighted Average Cost of Capital) represents the weighted average cost of a company's financial resources. It is essential for investment project analyses, DCF valuations, and strategic decisions. In 2026, companies face volatile interest rates and increased ESG requirements. Accurately calculating the WACC helps avoid costly valuation errors. This tutorial guides you from data collection to result interpretation with automated tools.
Prerequisites
- Python 3.10+
- Basic knowledge of corporate finance
- Real financial data (balance sheet, stock prices)
- Libraries: pandas, numpy
Installing Dependencies
pip install pandas numpy yfinanceThis command installs the necessary libraries to fetch stock market data and perform numerical calculations.
Fetching Market Data
import yfinance as yf
import pandas as pd
def get_market_data(ticker):
stock = yf.Ticker(ticker)
info = stock.info
return {
'market_cap': info.get('marketCap'),
'beta': info.get('beta'),
'shares': info.get('sharesOutstanding')
}
data = get_market_data('AAPL')
print(data)This script retrieves market capitalization and beta via the Yahoo Finance API to calculate weights.
Calculating Cost of Equity
def cost_of_equity(risk_free_rate, market_return, beta):
return risk_free_rate + beta * (market_return - risk_free_rate)
re = cost_of_equity(0.04, 0.10, 1.2)
print(f"Coût des capitaux propres: {re:.2%}")CAPM model implementation. Beta measures relative volatility and the risk premium is adjusted to 2026 market conditions.
Calculating Cost of Debt
def cost_of_debt(interest_expense, total_debt, tax_rate):
return (interest_expense / total_debt) * (1 - tax_rate)
rd = cost_of_debt(5000000, 100000000, 0.25)
print(f"Coût de la dette après impôt: {rd:.2%}")Cost of debt is adjusted by the tax rate. Use income statement data for accurate calculations.
Final WACC Calculation
def calculate_wacc(equity_value, debt_value, re, rd):
total_value = equity_value + debt_value
wacc = (equity_value / total_value) * re + (debt_value / total_value) * rd
return wacc
wacc_result = calculate_wacc(2500000000, 1000000000, 0.112, 0.0375)
print(f"WACC: {wacc_result:.2%}")Final function that aggregates weights and costs. Ensure values are consistent and up to date.
Best Practices
- Always use up-to-date market data for beta and returns
- Validate risk-free rate sources (government bonds)
- Adjust WACC by business segment
- Document risk premium assumptions
- Perform sensitivity analysis on key inputs
Common Mistakes to Avoid
- Using historical beta without forward-looking adjustments
- Ignoring the target capital structure impact
- Overlooking currency effects for foreign currency debt
- Applying marginal tax rate instead of effective rate
Going Further
Explore advanced WACC models adjusted for ESG projects on our Learni training courses.