Wall Street stocks stumbled early in the week after China unexpectedly devalued its currency, but steadied thereafter on solid US data.
All three indices ended with gains for the week, with the Dow Jones Industrial Average adding 104.02 points (0.60 percent) to 17,477.40.
The broad-based S&P 500 rose 13.97 (0.67 percent) to 2,091.54, while the tech-rich Nasdaq Composite Index increased 4.70 (0.09 percent) to 5,048.24.
Chris Low, chief economist at FTN Financial, said initial "panic" over the Chinese policy receded as the week wore on.
"People are beginning to realize that perhaps they overreacted, but China has dominated conversations," he said.
The Dow lost more than 200 points on Tuesday after China's central bank devalued its yuan currency by nearly two percent against the US dollar, as authorities said they were seeking to push market reforms, in the context of a slowing economy.
That move and further devaluations in subsequent days raised concerns about a strengthening US dollar and whether the Chinese economy is weaker than thought. Analysts also rued a potential "currency war" if other economies seek to devalue currencies to promote exports.
However, China's central bank soothed markets on Friday by setting the daily reference rate of the yuan against the US dollar marginally higher, ending an almost five percent fall over three days.
"I don't think the threats of a continued decelerating growth environment in China have completely abated, but for now the fears have dissipated somewhat in the short-term," said Michael James, managing director of equity trading at Wedbush Securities.
US data showed a solid gain in industrial production and higher wholesale prices. The most anticipated report, July retail sales, rose 0.6 percent behind large gains in auto purchasing and advances in most other categories.
While retail sales bested analyst expectations, a batch of earnings from large companies in the sector sent conflicting signals.
On the weak end was Macy's, which reported a 25.7 percent drop in second-quarter earnings to $217 million, missing expectations by a wide margin. The company cited "restrained" demand for merchandise and said the strong US dollar had crimped international tourist spending.
Much better were results from the upscale department store chain Nordstrom's, which lifted its 2015 outlook following a 15.3 percent rise in second-quarter earnings to $211 million behind higher sales.
Google announced a new corporate structure in which the search engine company will become part of a larger company that will be called Alphabet.
The shift is intended to let Google pursue new growth businesses such as Google Glass and Google TX without detracting from core revenues.
The week's biggest deal was the purchase by Warren Buffett's Berkshire Hathaway of Precision Castparts, a leading supplier to the aerospace industry, for $37.2 billion, the largest acquisition in the conglomerate's 50-year history.
Next week's calendar includes earnings from retail giants Wal-Mart Stores and Home Depot, as well as minutes from the Federal Reserve's July monetary policy meeting.