Updated at 4:16 p.m. ET
The Dow Jones industrial average entered positive territory for the year, rising 91 points, or 0.6 percent, to close at 16,652. The Nasdaq composite index gained 45 points, or 1 percent, to 4,434. The S&P 500 also edged up.
"This is a very resilient market," said Uri Landesman, president of Platinum Partners in New York.
Landesman pointed to plenty of reasons for traders to drop stocks this summer, including conflicts in Ukraine and the Middle East. "We're getting through the summer and the market is still pretty close to its high. It shows you the trend is still upward."
The yield on the 10-year Treasury note traded at 2.42 percent, just shy of its low for the year, down from 2.45 percent late Tuesday. U.S. crude oil fell 43 cents to $96.94 a barrel in New York.
Amazon (AMZN) shares surged, rising $6.96, or 2.1 percent, to $326.28. The online retail giant unveiled a payment system for mobile devices, Amazon Local Register. The credit-card processing device is designed to help small businesses accept payments through smartphones and tablets.
Macy's (M) sank after its results fell short of Wall Street's forecasts. The department store chain cut its full-year outlook for sales, saying it couldn't make up from a shortfall at the start of the year when winter storms kept shoppers at home. The company's stock dropped $3.29, or 5.5 percent, to $56.47.
Nearly all of the companies in the S&P 500 have turned in second-quarter results, and seven out of 10 have reported higher profits than analysts projected, according to S&P Capital IQ. Overall second-quarter earnings are on track to climb 10 percent over the year before. That's much better than the 3 percent increase companies reported for the first quarter of 2014.
A closely watched indicator of spending habits by U.S. shoppers was essentially flat in July. The Commerce Department said Wednesday that retail sales edged up by a tiny amount compared with the prior month. A separate report said businesses continued adding to their stockpiles in June. In general, a greater amount of goods on store shelves and warehouses reflects optimism about future demand.
"Recent news on jobs added to the economy and consumer confidence has been favorable, but consumers are still relatively cautious," said Chris Christopher Jr., director of consumer economics with IHS, in a research note.