In this paper, I incorporate a complex network model into a state of the art stochastic general equilibrium framework with an active interbank market. Banks exchange funds one another generating a complex web of interbanking relations. With the tools of network analysis it is possible to study how contagion spreads between banks and what is the probability and size of a cascade (a sequence of defaults) generated by a single initial episode. Those variables are a key component to understand systemic risk and to assess the stability of the banking system. In extreme scenarios, the system may experience a phase transition when the consequences of one single initial shock affect the entire population. I show that the size and probability of a cascade evolve along the business cycle and how they respond to exogenous shocks. Financial shocks have a larger impact on contagion probability than real shocks that, however, are long lasting. Additionally I find that monetary policy faces a trade off between financial stability and macroeconomic stabilization. Government spending shocks, on the contrary, have smaller effects on both.