Five months ago the U.S. stock market seemed in dire straits, with prices tumbling in response to China's financial woes, low oil prices and an uncertain outlook for interest rates.
Now the market is again setting new highs.
What happened that sent the market back up, except for a sharp, brief pullback June 24 to 27 after the British vote to leave the European Union?
China's markets stabilized. Oil prices rebounded. The Federal Reserve did not raise rates again from their low levels. The U.S. economy maintained at least sluggish growth amid global economic worries. Corporate earnings forecasts improved.
The stock market, which has been on an exceptionally long bull market for the last seven years, also enjoyed the oft-cited benefit of a steep, temporary drop in prices: It gave investors fresh buying opportunities.
The result: The benchmark Standard & Poor's 500 index closed Monday at a record high 2,137.16, up 7.26 points on the day and eclipsing the prior high of 2,130.82 set May 21, 2015.
Other major indexes edged closer to their peaks as well. The blue-chip Dow Jones industrial average gained 80.19 points to 18,226.93, shy of its record high of 18,312.39 set May 19, 2015.
And the tech-heavy Nasdaq composite index gained 31.88 points to 4,988.64. It set a record high of 5,218.86 on July 20, 2015.
Moreover, the S&P 500 has surged 17% since it bottomed at 1,829.08 on Feb. 11. At that point, the index in 2016 already had suffered the textbook 10% plunge that's known as a market "correction."
Now, the market seems poised to extend its gains, even if a host of problems continue to weigh on investors, analysts said.
"The move from the February lows to here was climbing a wall of worry – worried about China, worried about the Fed, worried about Brexit," said Jim Paulsen, chief investment strategist at Wells Capital Management.
"The next pop might have more to do with a breakout of optimism," he said. "Now that we've broken new highs, the headlines are going to get more positive."
But Paulsen and other analysts said any investor optimism is tempered by knowing that the market remains acutely sensitive to any disruption, as the Brexit vote illustrated.
"The Brexit caught markets off guard because very few people thought that would be the outcome," said David Schiegoleit, senior portfolio manager at U.S. Bank Wealth Management. "The vote shocked the market."
Otherwise, the biggest factor behind the stock market's rebound is the continued low level of interest rates in the U.S. and abroad, said Todd Morgan, chairman of Bel Air Investment Advisors in Los Angeles.
After investors sold stocks in the market's rout early this year, they saw returns on short-term government securities and other fixed-income investments remained very low. The yield on the 10-year Treasury note closed Monday at 1.43%.
"You had people who liquidated [stocks] and then realized they needed a return," Morgan said. "So people started to search for alternatives. They slowly put money back into the stock market and, after it didn't collapse, they added more and more."
Schiegoleit said there also has been "a tremendous amount of capital flowing into the U.S. from overseas, where interest rates are negative in some of the largest economies of the world, like Japan and Germany."
"There simply aren't a lot of compelling places to put capital other than stocks," he said.
Josh Brown, chief executive of Ritholtz Wealth Management who runs the Reformed Broker website, has another theory about the market's rebound, revolving around the increasingly popular practice of investing in index funds.
Whereas many individual investors once picked specific stocks, or stock mutual funds, in hopes of beating the market, many now passively invest in index funds that mirror the market, such as through their 401(k) plans, Brown said. That shift partly stemmed from the severe recession that took hold in 2008-09, he said.
"No one wants to do anything fancy now," Brown said. "People are less interested in the daily ups and downs of the stock market.
"The effect of the barrage of money flows toward index products means stocks are bought [by the index-fund firms] when they're up, when they're down, when they flat, and they're bought indiscriminately and dispassionately," he said.
One of the premier index-fund managers, Vanguard Group, had a record $236 billion of net inflows last year for all of its funds, including $166 billion invested in stock-index funds. An additional $82 billion has been plowed into Vanguard's stock-index funds this year.
In any case, stock prices often are driven by corporate profits, and "we believe earnings are going to start to improve," Schiegoleit said. "We've seen four consecutive quarters of earnings declines, but we think those declines are for the most part behind us."
Yet earnings growth and other bullish U.S. economic trends also could disrupt the market's future gains, analysts said.
For instance, the market rallied Friday after Labor Department data showed employers added a surprisingly robust 287,000 jobs in June, topping economists' forecasts. But if that helps the Fed decide later this year that the economy is healthy enough, the central bank might resume lifting interest rates.
The stock market also is getting closer to one of its biggest unknowns in years: The final stages of the race leading up to the presidential election.
"That makes me nervous the next couple of months," Morgan said.
MORE FROM BUSINESS
1:31 p.m.: This article was updated with closing prices.
8:41 a.m.: This article was updated with more recent prices and additional information.