Interbank contagion has become a buzzword in the aftermath of the financial crisis that led to a series of shocks to the interbank market and to periods of pronounced market disruptions. However, little is known about how interbank networks are formed and about their sensitivity to changes in key bank parameters (for example, induced by common exogenous shocks or by regulatory initiatives). This paper aims to shed light on these issues by modelling endogenously the formation of interbank networks, which in turn allows for checking the sensitivity of interbank network structures and hence their underlying contagion risk to changes in market-driven parameters as well as to changes in regulatory measures such as large exposures limits. The sequential network formation mechanism presented in the paper is based on a portfolio optimisation model whereby banks allocate their interbank exposures while balancing the return and risk of counterparty default risk and the placements are accepted taking into account funding diversification benefits. The model offers some interesting insights into how key parameters may affect interbank network structures and can be a valuable tool for analysing the impact of various regulatory policy measures relating to banks' incentives to operate in the interbank market.