Global stocks end 2021 with losses after a strong year