Network Theory in Finance: Applications to Financial Contagion Analysis and Portfolio Optimization