Python - Calculate Weighted Average Cost of Capital

by matt392 in Circuits > Software

49 Views, 1 Favorites, 0 Comments

Python - Calculate Weighted Average Cost of Capital

wacc.jpg
print ("This program will calculate the Weighted Average Cost of Capital.")

import math

###  Formula for calculating the Weighted Average Cost of Capital:
#  WeightedAverageCostOfCapital = (((TotalDebt/(TotalDebt + TotalShareholderEquity)) * (CostOfDebt)) +
#  ((TotalShareholderEquity/(TotalDebt+TotalShareholderEquity)) * CostOfEquity)
#                   
###############################################################################

# Enter the TotalDebt, TotalShareholderEquity, CostOfDebt, CostOfEquity

ContinueCalculations = "y"

def CalculateWeightedAverageCostOfCapital():
    print ("Solving for the Weighted Average Cost of Capital.")
    # Enter the TotalDebt
    TotalDebt = float(input("Enter the total debt: ") )
    # Enter the TotalShareholderEquity
    TotalShareholderEquity = float(input("Enter the Total Shareholder Equity: ") )
    # Enter the CostOfDebt
    CostOfDebt = float(input("Enter the cost of debt: ") )
    # Enter the CostOfEquity
    CostOfEquity = float(input("Enter the cost of equity: ") )
    

    # Calculate the left side of the equation
    LeftSideOfEquation = ((TotalDebt/(TotalDebt + TotalShareholderEquity)) * CostOfDebt)
    
    # Calculate the right side of the equation
    RightSideOfEquation = ((TotalShareholderEquity/(TotalDebt + TotalShareholderEquity)) * CostOfEquity)

    # Calculate the Weighted Average Cost of Capital
    WeightedAverageCostOfCapital = LeftSideOfEquation + RightSideOfEquation
    
    print("The Weightd Average Cost of Capital is: ", WeightedAverageCostOfCapital)

while (ContinueCalculations=="y"):
    CalculateWeightedAverageCostOfCapital()
    ContinueCalculations = str(input("Would you like to continue to calculate the weighted average cost of capital? (y/n): "))

print("==================================")
print ("Thank you to www.fxsolver.com for assistance with this formula.")