Page: https://rpubs.com/staszkiewicz/FM_WACC
Let us calculate WACC for Microsoft Using R and Financial Data
Understanding the Components: To calculate WACC for Microsoft, we need the following:
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.4 ✔ readr 2.1.5
## ✔ forcats 1.0.0 ✔ stringr 1.5.1
## ✔ ggplot2 3.5.1 ✔ tibble 3.2.1
## ✔ lubridate 1.9.3 ✔ tidyr 1.3.1
## ✔ purrr 1.0.2
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(quantmod)
## Ładowanie wymaganego pakietu: xts
## Ładowanie wymaganego pakietu: zoo
##
## Dołączanie pakietu: 'zoo'
##
## Następujące obiekty zostały zakryte z 'package:base':
##
## as.Date, as.Date.numeric
##
##
## ######################### Warning from 'xts' package ##########################
## # #
## # The dplyr lag() function breaks how base R's lag() function is supposed to #
## # work, which breaks lag(my_xts). Calls to lag(my_xts) that you type or #
## # source() into this session won't work correctly. #
## # #
## # Use stats::lag() to make sure you're not using dplyr::lag(), or you can add #
## # conflictRules('dplyr', exclude = 'lag') to your .Rprofile to stop #
## # dplyr from breaking base R's lag() function. #
## # #
## # Code in packages is not affected. It's protected by R's namespace mechanism #
## # Set `options(xts.warn_dplyr_breaks_lag = FALSE)` to suppress this warning. #
## # #
## ###############################################################################
##
## Dołączanie pakietu: 'xts'
##
## Następujące obiekty zostały zakryte z 'package:dplyr':
##
## first, last
##
## Ładowanie wymaganego pakietu: TTR
## Registered S3 method overwritten by 'quantmod':
## method from
## as.zoo.data.frame zoo
getSymbols("MSFT")
## [1] "MSFT"
oustanding_shares<- 30000000
#note: you might use the current volume instant as the instrument for.
market_cap <- last(MSFT$MSFT.Adjusted) * oustanding_shares
cost_of_debt <- 0.03 # 3%
tax_rate <- 0.25 # 25% tax rate
beta <- 1.1 # Beta of Microsoft's stock
risk_free_rate <- 0.02 # 2% risk-free rate
market_risk_premium <- 0.06 # 6% market risk premium
cost_of_equity <- risk_free_rate + beta * market_risk_premium
market_value_of_debt <- 100e9 # $100 billion
total_market_value <- market_cap + market_value_of_debt
weight_of_debt <- market_value_of_debt / total_market_value
weight_of_equity <- market_cap / total_market_value
wacc <- (weight_of_debt * cost_of_debt * (1 - tax_rate)) + (weight_of_equity * cost_of_equity)
cat("WACC for Microsoft:", wacc * 100, "%")
## WACC for Microsoft: 2.957246 %
Comments: