Wall Street got its mojo back in January after finishing 2018 with its worst December since 1931.
Stocks finished higher Thursday, closing out the month with the best gain for the S&P 500 index since October 2015.
A series of strong corporate earnings helped power the monthlong rally, which followed a dismal December that nearly brought the benchmark index into a bear market, meaning a decline of 20 percent from a recent peak.
Facebook helped drive the market higher on Thursday after reporting solid user metrics. Charter Communications soared after its revenue came in ahead of forecasts. General Electric also climbed. Amazon reported earnings after the close of regular trading that topped Wall Street's forecasts.
Homebuilders surged following new data showing sales of new U.S. homes soared in November.
Strong results and outlooks from big U.S. companies seem to be calming some of the fears investors had that a recession might be looming.
"Overall, we're still encouraged that this earning season is comforting to people," said Ryan Detrick, senior market strategist at LPL Financial.
The S&P 500 index rose 23.05 points, or 0.9 percent, to 2,704.10. It rose 7.9 percent in January. In December, it tumbled 9.2 percent.
The Dow Jones Industrial Average fell 15.19 points, or 0.1 percent, to 24,999.67. The Nasdaq composite climbed 98.66 points, or 1.4 percent, to 7,281.74. The Russell 2000 index of smaller companies picked up 12.48 points, or 0.8 percent, to 1,499.42.
Communications, health care and consumer goods and services stocks powered Thursday's market gain as investors remained focused on corporate earnings, which have been mixed.
Facebook beat Wall Street's profit and revenue forecasts, despite an increase in spending on privacy and security. Its user base grew to 2.32 billion, up 9 percent from a year earlier and higher than analysts' forecasts. The stock gained 10.8 percent to $166.69.
General Electric reported mixed results for the fourth quarter, but revenue and profit were still higher across most of its segments. The industrial conglomerate has been cutting costs and spinning off units for years in a bid to boost its bottom line. The stock climbed 11.6 percent to $10.16.
Microsoft fell 1.8 percent to $104.43 after the technology company swung to a profit in its latest quarter, driven by revenue growth at its cloud-computing platform. The results beat forecasts, but the company's key personal computing segment fell short of estimates.
Homebuilders climbed on new data showing sales of newly built homes soared in November. The Commerce Department said new home sales jumped 16.9 percent in November from the previous month. Despite the healthy gain, sales remain 7.7 percent below the pace from a year earlier. The report was delayed by the 35-day government shutdown. Meritage Homes led the pack, vaulting 10.1 percent to $45.08.
Concerns over the ongoing U.S.-China trade conflict, uncertainty over the path of interest rates and signs of a weakening global economy helped knock the market into a steep slump in December. While concerns over trade and a slowing economy remain, corporate earnings have put investors in a buying mood. And this week, the Federal Reserve sent a strong signal to the markets that it is in no hurry to raise interest rates in coming months, another confidence boost for the market.
Trade talks between the U.S. and China entered a second day Thursday. President Donald Trump voiced optimism before meeting with representatives from China, but noted there would be "no final deal" until he sits down with Chinese President Xi Jinping.
Among the biggest gainers in January were Xerox and Celgene, which climbed 42.8 percent and 38 percent, respectively. General Electric also turned in a big January gain: 34.2 percent.
Boeing notched the biggest January gain in the 30-company Dow, rising 19.6 percent.
U.S. crude oil fell 0.8 percent to settle at $53.79 per barrel in New York. Brent crude, used to price international oils, added 0.4 percent to close at $61.89 per barrel in London.
Bond prices rose. The yield on the 10-year Treasury fell to 2.64 percent from 2.69 percent late Wednesday.
The dollar fell to 108.66 yen from 108.92 yen on Wednesday. The euro weakened versus the dollar to $1.1479 from $1.1492.
Gold rose 0.7 percent to $1,319.70 an ounce. Silver added 0.9 percent to $16.07 an ounce. Copper gained 0.6 percent to $2.78 a pound.
In other energy futures trading, wholesale gasoline fell 1.4 percent to $1.36 a gallon. Heating oil slid 1 percent to $1.88 a gallon. Natural gas dropped 1.4 percent to $2.81 per 1,000 cubic feet.