Investment, credit, and endogenous cycles