The S&P 500 posted its first weekly gain since January, rising 1.1% after spending the majority of the week in positive territory.