What Are Main Elements In Calculating The Cost Of Capital?

What are main elements in calculating the cost of capital? How does an increase in debt affect it? How do you identify an organization’s optimal cost of capital?