The gains follow two days of sharp losses.