Optimality of Investment under Imperfectly Enforceable Financial Contracts