Systemic Risk in Endogenous Financial Networks