"The economic reports ... have been coming out better than expected," said Robert Pavlik, chief market strategist at Banyan Partners. "There's been a shift in the focus of investors away from some of the geopolitical events."
The Standard & Poor's 500 index gained 9.86 points, or 0.5 percent, to 1,981.60. The index is up 1.4 percent for the week and is approaching its record close of 1,987.98 reached July 24. The Dow Jones industrial average rose 80.85 points, or 0.5 percent, to 16,919.59. The Nasdaq composite climbed 19.20 points, or 0.4 percent, to 4,527.51.
TJX, the parent company of T.J. Maxx, Marshalls and other stores, was the biggest gainer in the S&P 500 on Tuesday. The company's stock rose $4.66, or 8.6 percent, to $58.56 after it reported that its quarterly income climbed 8 percent as sales strengthened in the U.S. and abroad. The results beat the estimates of Wall Street analysts. TJX also lifted its full-year earnings forecast.
Home Depot jumped $4.64, or 5.6 percent, to $88.23 after the company said its quarterly income surged 14 percent. Spring is the biggest season for home-improvement retailers as homeowners work on their yards and gardens. Home Depot has also been helped by an improving housing market.
"Home Depot's earnings give you a measure of confidence in housing, to an extent, and a measure of retail confidence," said JJ Kinahan, chief strategist at TD Ameritrade. "Those are two areas where we like to look to see how the consumer is really feeling."
After rising to a record in July, stocks slumped in the first week of August. The S&P 500 index fell as much as 4 percent from its record close to 1,909.57 on August 7, as investors worried about tensions between Russia and the West over Ukraine and the implications for global growth.
A report that showed inflation remains subdued also gave stocks a lift Tuesday.
U.S. consumer prices rose in July at the slowest pace in five months, held back by a drop in gasoline prices. Consumer prices edged up 0.1 percent, after larger gains of 0.3 percent in June and 0.4 percent in May. If inflation remains constrained, investors judge that the Federal Reserve will be able keep its key interest rate low for longer.
The Fed is currently winding down its economic stimulus but hasn't yet said when it will start raising interest rates.
Beauty products company Elizabeth Arden was one of the big losers on Tuesday.
The company slumped after reporting lower sales and a loss that was bigger than analysts' had expected. The company said the decline in sales of celebrity fragrances, particularly the Justin Bieber and Taylor Swift scents, was steeper than had been anticipated. Arden's stock dropped $4.56, or 23 percent, to $15.05.
Benchmark U.S. crude fell $1.93, or 2 percent, to $94.48 a barrel in New York and is now down nearly 4 percent for the month of August as crude supplies remain ample. Bond prices didn't move much. The yield on the 10-year Treasury note was unchanged at 2.40 percent from Tuesday.
In metals trading, gold slipped $2.60 to $1,296.70 an ounce. Silver fell 22 cents to $19.41 an ounce. Copper fell two cents to $3.09 a pound. In currency trading, the dollar rose 0.3 percent to 102.89 yen, while the euro fell 0.3 percent against the U.S. currency to $1.3318.