rust_finprim/derivatives/wacc.rs
1use crate::FloatLike;
2
3/// WACC'(D/E) - First derivative of WACC with respect to the debt to equity ratio.
4///
5/// # Arguments
6/// * `r_e` - The Cost of Equity
7/// * `r_d` - The Cost of Debt
8/// * `de_ratio` - The Debt to Equity Ratio (market value where D + E = V)
9/// * `tax` - The tax rate
10///
11/// # Returns
12/// * The first derivative of the WACC with respect to the D/E ratio.
13///
14/// # WACC Formula
15/// $$\mathrm{WACC} = R_e (\frac{1}{1+D/E}) + R_d (\frac{D/E}{1+D/E})(1-T_C)$$
16///
17/// Where:
18/// * \\(R_e\\) = Cost of Equity
19/// * \\(R_d\\) = Cost of Debt
20/// * \\(D/E\\) = The Debt to Equity Ratio (market value)
21/// * \\(T_C)\\) = The tax rate
22pub fn wacc_prime_de<T: FloatLike>(r_e: T, r_d: T, de_ratio: T, tax: T) -> T {
23 -(tax * r_d + r_e - r_d) / (de_ratio + T::one()).powf(T::two())
24}
25
26/// WACC''(D/E) - Second derivative of WACC with respect to the debt to equity ratio.
27///
28/// # Arguments
29/// * `r_e` - The Cost of Equity
30/// * `r_d` - The Cost of Debt
31/// * `de_ratio` - The Debt to Equity Ratio (market value where D + E = V)
32/// * `tax` - The tax rate
33///
34/// # Returns
35/// * The first derivative of the WACC with respect to the D/E ratio.
36///
37/// # WACC Formula
38/// $$\mathrm{WACC} = R_e (\frac{1}{1+D/E}) + R_d (\frac{D/E}{1+D/E})(1-T_C)$$
39///
40/// Where:
41/// * \\(R_e\\) = Cost of Equity
42/// * \\(R_d\\) = Cost of Debt
43/// * \\(D/E\\) = The Debt to Equity Ratio
44/// * \\(T_C)\\) = The tax rate
45pub fn wacc_prime2_de<T: FloatLike>(r_e: T, r_d: T, de_ratio: T, tax: T) -> T {
46 T::two() * (tax * r_d + r_e - r_d) / (de_ratio + T::one()).powf(T::from_u16(3u16))
47}
48
49#[cfg(test)]
50mod tests {
51 use super::*;
52 #[cfg(not(feature = "std"))]
53 extern crate std;
54 #[cfg(not(feature = "std"))]
55 use std::assert;
56
57 #[test]
58 fn test_wacc_prime() {
59 let r_e = 0.05;
60 let r_d = 0.07;
61 let de_ratio = 0.7;
62 let tax = 0.25;
63
64 let result = wacc_prime_de(r_e, r_d, de_ratio, tax);
65 let expected: f64 = 0.00086;
66 assert!(
67 (result - expected).abs() < 1e-5,
68 "Failed on case: {}. Expected{}, Result: {}",
69 "Cost of Equity 5%, Cost of Debt 7%, D/E 0.7, Tax Rate 25%",
70 expected,
71 result
72 );
73 }
74}