Ruin probabilities and optimal investment: the case of dependence between financial and insurance risks