Dynamic portfolio optimization with credit risk