A Model of Endogenous Loan Quality and the Collapse of the Shadow Banking System