Optimal portfolio in a regime-switching model