Endogenous Credit Cycles