Optimal Capital Structure and Investment with Real Options and Endogenous Debt Costs